blob: fc7d9ae3284e1a4e197d1f5b07b12b2c657f3fba [file] [log] [blame]
Simon Huntd5b96732016-07-08 13:22:27 -07001/*
Steven Burrows57e24e92016-08-04 18:38:24 +01002* Copyright 2016-present Open Networking Laboratory
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
Simon Huntd5b96732016-07-08 13:22:27 -070016
17/*
Simon Hunt95f4b422017-03-03 13:49:05 -080018 ONOS GUI -- Topology (2) View Module
Simon Huntd5b96732016-07-08 13:22:27 -070019
20 NOTE: currently under development to support Regions.
21 */
22
23(function () {
24 'use strict';
25
26 // references to injected services
Simon Huntf0c6f542017-03-22 18:31:18 -070027 var $scope, $log, fs, mast, ks, wss,
Steven Burrows0616e802016-10-06 21:45:07 -050028 gs, sus, ps, t2es, t2fs, t2is, t2bcs, t2kcs, t2ms, t2mcs, t2zs;
Simon Huntd5b96732016-07-08 13:22:27 -070029
30 // DOM elements
Steven Burrowsdfa52b02016-09-02 13:50:43 +010031 var ovtopo2, svg, defs, zoomLayer, forceG;
Simon Huntd5b96732016-07-08 13:22:27 -070032
33 // Internal state
Simon Hunt95f4b422017-03-03 13:49:05 -080034 var zoomer,
Simon Huntb3656d42017-04-07 18:15:35 -070035 currentLayoutId = 'root'; // NOTE: see UiTopoLayoutId.DEFAULT_STR
Simon Hunt95f4b422017-03-03 13:49:05 -080036
Simon Huntd5b96732016-07-08 13:22:27 -070037
Steven Burrows57e24e92016-08-04 18:38:24 +010038 // --- Glyphs, Icons, and the like -----------------------------------
39
40 function setUpDefs() {
41 defs = svg.append('defs');
42 gs.loadDefs(defs);
Simon Hunt95f4b422017-03-03 13:49:05 -080043
44 // TODO: consider using something other than the "glow" styles
Steven Burrows57e24e92016-08-04 18:38:24 +010045 sus.loadGlowDefs(defs);
46 }
Simon Huntd5b96732016-07-08 13:22:27 -070047
48 // callback invoked when the SVG view has been resized..
49 function svgResized(s) {
Steven Burrows57e24e92016-08-04 18:38:24 +010050 $log.debug('topo2 view resized', s);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010051 t2fs.newDim([s.width, s.height]);
Simon Huntd5b96732016-07-08 13:22:27 -070052 }
53
54 function setUpKeys(overlayKeys) {
55 $log.debug('topo2: set up keys....');
56 }
57
Steven Burrows57e24e92016-08-04 18:38:24 +010058 // --- Pan and Zoom --------------------------------------------------
59
60 // zoom enabled predicate. ev is a D3 source event.
61 function zoomEnabled(ev) {
62 return fs.isMobile() || (ev.metaKey || ev.altKey);
63 }
64
65 function zoomCallback() {
66 var sc = zoomer.scale(),
Simon Hunt95f4b422017-03-03 13:49:05 -080067 tr = zoomer.translate(),
Simon Huntf0c6f542017-03-22 18:31:18 -070068 metaUi = isNaN(sc) ? {
69 useCfg: 1
70 } : {
71 scale: sc,
72 offsetX: tr[0],
73 offsetY: tr[1]
74 };
Steven Burrows57e24e92016-08-04 18:38:24 +010075
Simon Huntc43a59d2017-04-05 13:56:13 -070076 // Allow map service to react to change in zoom parameters
77 t2ms.zoomCallback(sc, tr);
78
Simon Huntf0c6f542017-03-22 18:31:18 -070079 // Note: Meta data stored in the context of the current layout,
80 // automatically, by the server
Simon Hunt95f4b422017-03-03 13:49:05 -080081
Simon Huntf0c6f542017-03-22 18:31:18 -070082 wss.sendEvent('updateMeta2', {
83 id: 'layoutZoom',
84 memento: metaUi
85 });
Steven Burrows57e24e92016-08-04 18:38:24 +010086 }
87
88 function setUpZoom() {
Simon Hunt95f4b422017-03-03 13:49:05 -080089 zoomLayer = svg.append('g').attr('id', 'topo2-zoomlayer');
Steven Burrows0616e802016-10-06 21:45:07 -050090
91 zoomer = t2zs.createZoomer({
Steven Burrows57e24e92016-08-04 18:38:24 +010092 svg: svg,
93 zoomLayer: zoomLayer,
94 zoomEnabled: zoomEnabled,
95 zoomCallback: zoomCallback
96 });
97 }
98
Simon Huntd5b96732016-07-08 13:22:27 -070099 // === Controller Definition -----------------------------------------
100
101 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
Steven Burrowsaf96a212016-12-28 12:57:02 +0000102 .controller('OvTopo2Ctrl', [
Simon Hunt95f4b422017-03-03 13:49:05 -0800103 '$scope', '$log', '$location',
104 'FnService', 'MastService', 'KeyService', 'GlyphService', 'MapService',
105 'SvgUtilService', 'FlashService', 'WebSocketService',
106 'PrefsService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +0100107 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Steven Burrowse3a18842016-09-22 15:33:33 +0100108 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
Simon Hunt95f4b422017-03-03 13:49:05 -0800109 'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService',
Steven Burrowsc8468932017-03-17 16:13:41 +0000110 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2ToolbarService',
Simon Huntd5b96732016-07-08 13:22:27 -0700111
Simon Hunt95f4b422017-03-03 13:49:05 -0800112 function (
113 _$scope_, _$log_, _$loc_,
114 _fs_, _mast_, _ks_, _gs_, _ms_,
115 _sus_, _flash_, _wss_,
116 _ps_, _th_,
117 _t2es_, _t2fs_, _t2is_,
118 _t2bcs_, _t2kcs_, _t2ms_,
119 _t2mcs_, _t2zs_, t2sls,
Steven Burrowsc8468932017-03-17 16:13:41 +0000120 summaryPanel, detailsPanel, t2tbs
Steven Burrows5570d1b2016-09-28 14:21:00 -0700121 ) {
Simon Huntd5b96732016-07-08 13:22:27 -0700122 var params = _$loc_.search(),
Simon Huntd5b96732016-07-08 13:22:27 -0700123 dim,
124 wh,
125 uplink = {
126 // provides function calls back into this space
127 // showNoDevs: showNoDevs,
128 // projection: function () { return projection; },
Steven Burrows9edc7e02016-08-29 11:52:07 +0100129 zoomLayer: function () { return zoomLayer; },
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100130 zoomer: function () { return zoomer; }
Simon Huntd5b96732016-07-08 13:22:27 -0700131 // opacifyMap: opacifyMap,
Simon Huntd5b96732016-07-08 13:22:27 -0700132 };
133
134 $scope = _$scope_;
135 $log = _$log_;
Simon Huntd5b96732016-07-08 13:22:27 -0700136
137 fs = _fs_;
138 mast = _mast_;
139 ks = _ks_;
Simon Huntf0c6f542017-03-22 18:31:18 -0700140 wss = _wss_;
Simon Huntd5b96732016-07-08 13:22:27 -0700141 gs = _gs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700142 sus = _sus_;
Simon Huntd5b96732016-07-08 13:22:27 -0700143 ps = _ps_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100144
Simon Huntd5b96732016-07-08 13:22:27 -0700145 t2es = _t2es_;
146 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100147 t2is = _t2is_;
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100148 t2bcs = _t2bcs_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100149 t2kcs = _t2kcs_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100150 t2ms = _t2ms_;
Steven Burrowse7cc3082016-09-27 11:24:58 -0700151 t2mcs = _t2mcs_;
Steven Burrows0616e802016-10-06 21:45:07 -0500152 t2zs = _t2zs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700153
154 // capture selected intent parameters (if they are set in the
155 // query string) so that the traffic overlay can highlight
156 // the path for that intent
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100157 if (params.intentKey &&
158 params.intentAppId &&
159 params.intentAppName) {
160
Simon Huntd5b96732016-07-08 13:22:27 -0700161 $scope.intentData = {
162 key: params.intentKey,
163 appId: params.intentAppId,
Simon Hunt95f4b422017-03-03 13:49:05 -0800164 appName: params.intentAppName,
165 intentType: params.intentType
Simon Huntd5b96732016-07-08 13:22:27 -0700166 };
167 }
168
169 $scope.notifyResize = function () {
170 svgResized(fs.windowSize(mast.mastHeight()));
171 };
172
173 // Cleanup on destroyed scope..
174 $scope.$on('$destroy', function () {
175 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
176 t2es.stop();
177 ks.unbindKeys();
178 t2fs.destroy();
Steven Burrows7a9d04e2016-09-26 17:05:37 -0700179 t2is.destroy();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500180 summaryPanel.destroy();
181 detailsPanel.destroy();
Simon Huntd5b96732016-07-08 13:22:27 -0700182 });
183
184 // svg layer and initialization of components
185 ovtopo2 = d3.select('#ov-topo2');
186 svg = ovtopo2.select('svg');
187 // set the svg size to match that of the window, less the masthead
188 wh = fs.windowSize(mast.mastHeight());
189 $log.debug('setting topo SVG size to', wh);
190 svg.attr(wh);
191 dim = [wh.width, wh.height];
192
Simon Huntd5b96732016-07-08 13:22:27 -0700193 // set up our keyboard shortcut bindings
194 setUpKeys();
Steven Burrows57e24e92016-08-04 18:38:24 +0100195 setUpZoom();
196 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700197
198 // make sure we can respond to topology events from the server
199 t2es.bindHandlers();
200
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100201 t2bcs.init();
Steven Burrowsc8468932017-03-17 16:13:41 +0000202 t2kcs.init(t2fs, t2tbs);
Steven Burrows57e24e92016-08-04 18:38:24 +0100203 t2is.initInst({ showMastership: t2fs.showMastership });
Steven Burrowsc8468932017-03-17 16:13:41 +0000204 t2fs.init(svg, forceG, uplink, dim, zoomer);
Steven Burrows57e24e92016-08-04 18:38:24 +0100205
Simon Huntd5b96732016-07-08 13:22:27 -0700206 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100207
Simon Huntd5b96732016-07-08 13:22:27 -0700208 // setUpToolbar();
Simon Huntd5b96732016-07-08 13:22:27 -0700209 // setUpNoDevs();
Simon Huntd5b96732016-07-08 13:22:27 -0700210
Simon Huntd5b96732016-07-08 13:22:27 -0700211 // tes.bindHandlers();
212 // setUpSprites();
213
214 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
215 // tfs.initForce(svg, forceG, uplink, dim);
216 // tis.initInst({ showMastership: tfs.showMastership });
217 // tps.initPanels();
218
219 // restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800220 // ttbs.setDefaultOverlay(prefsState.ovid);
Simon Huntd5b96732016-07-08 13:22:27 -0700221
222 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100223
Steven Burrows5570d1b2016-09-28 14:21:00 -0700224 summaryPanel.init();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500225 detailsPanel.init();
Steven Burrows5570d1b2016-09-28 14:21:00 -0700226
Simon Hunt95f4b422017-03-03 13:49:05 -0800227 // Now that we are initialized, ask the server for what we
228 // need to show.
229 t2es.start();
230
Simon Huntd5b96732016-07-08 13:22:27 -0700231 $log.log('OvTopo2Ctrl has been created');
232 }]);
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100233})();