blob: 29139533b491dbd2843e6cb0b025accc5beb787f [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',
Steven Burrows6501de92017-04-12 15:10:34 -0700111 'Topo2NoDevicesConnectedService',
Simon Huntd5b96732016-07-08 13:22:27 -0700112
Simon Hunt95f4b422017-03-03 13:49:05 -0800113 function (
114 _$scope_, _$log_, _$loc_,
115 _fs_, _mast_, _ks_, _gs_, _ms_,
116 _sus_, _flash_, _wss_,
117 _ps_, _th_,
118 _t2es_, _t2fs_, _t2is_,
119 _t2bcs_, _t2kcs_, _t2ms_,
120 _t2mcs_, _t2zs_, t2sls,
Steven Burrows6501de92017-04-12 15:10:34 -0700121 summaryPanel, detailsPanel, t2tbs, t2ndcs
Steven Burrows5570d1b2016-09-28 14:21:00 -0700122 ) {
Simon Huntd5b96732016-07-08 13:22:27 -0700123 var params = _$loc_.search(),
Simon Huntd5b96732016-07-08 13:22:27 -0700124 dim,
125 wh,
126 uplink = {
127 // provides function calls back into this space
128 // showNoDevs: showNoDevs,
129 // projection: function () { return projection; },
Steven Burrows9edc7e02016-08-29 11:52:07 +0100130 zoomLayer: function () { return zoomLayer; },
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100131 zoomer: function () { return zoomer; }
Simon Huntd5b96732016-07-08 13:22:27 -0700132 // opacifyMap: opacifyMap,
Simon Huntd5b96732016-07-08 13:22:27 -0700133 };
134
135 $scope = _$scope_;
136 $log = _$log_;
Simon Huntd5b96732016-07-08 13:22:27 -0700137
138 fs = _fs_;
139 mast = _mast_;
140 ks = _ks_;
Simon Huntf0c6f542017-03-22 18:31:18 -0700141 wss = _wss_;
Simon Huntd5b96732016-07-08 13:22:27 -0700142 gs = _gs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700143 sus = _sus_;
Simon Huntd5b96732016-07-08 13:22:27 -0700144 ps = _ps_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100145
Simon Huntd5b96732016-07-08 13:22:27 -0700146 t2es = _t2es_;
147 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100148 t2is = _t2is_;
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100149 t2bcs = _t2bcs_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100150 t2kcs = _t2kcs_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100151 t2ms = _t2ms_;
Steven Burrowse7cc3082016-09-27 11:24:58 -0700152 t2mcs = _t2mcs_;
Steven Burrows0616e802016-10-06 21:45:07 -0500153 t2zs = _t2zs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700154
155 // capture selected intent parameters (if they are set in the
156 // query string) so that the traffic overlay can highlight
157 // the path for that intent
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100158 if (params.intentKey &&
159 params.intentAppId &&
160 params.intentAppName) {
161
Simon Huntd5b96732016-07-08 13:22:27 -0700162 $scope.intentData = {
163 key: params.intentKey,
164 appId: params.intentAppId,
Simon Hunt95f4b422017-03-03 13:49:05 -0800165 appName: params.intentAppName,
166 intentType: params.intentType
Simon Huntd5b96732016-07-08 13:22:27 -0700167 };
168 }
169
170 $scope.notifyResize = function () {
171 svgResized(fs.windowSize(mast.mastHeight()));
172 };
173
174 // Cleanup on destroyed scope..
175 $scope.$on('$destroy', function () {
176 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
177 t2es.stop();
178 ks.unbindKeys();
179 t2fs.destroy();
Steven Burrows7a9d04e2016-09-26 17:05:37 -0700180 t2is.destroy();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500181 summaryPanel.destroy();
182 detailsPanel.destroy();
Simon Huntd5b96732016-07-08 13:22:27 -0700183 });
184
185 // svg layer and initialization of components
186 ovtopo2 = d3.select('#ov-topo2');
187 svg = ovtopo2.select('svg');
188 // set the svg size to match that of the window, less the masthead
189 wh = fs.windowSize(mast.mastHeight());
190 $log.debug('setting topo SVG size to', wh);
191 svg.attr(wh);
192 dim = [wh.width, wh.height];
193
Simon Huntd5b96732016-07-08 13:22:27 -0700194 // set up our keyboard shortcut bindings
195 setUpKeys();
Steven Burrows57e24e92016-08-04 18:38:24 +0100196 setUpZoom();
197 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700198
Steven Burrows6501de92017-04-12 15:10:34 -0700199 t2ndcs.init();
200
Simon Huntd5b96732016-07-08 13:22:27 -0700201 // make sure we can respond to topology events from the server
202 t2es.bindHandlers();
203
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100204 t2bcs.init();
Steven Burrowsc8468932017-03-17 16:13:41 +0000205 t2kcs.init(t2fs, t2tbs);
Steven Burrows57e24e92016-08-04 18:38:24 +0100206 t2is.initInst({ showMastership: t2fs.showMastership });
Steven Burrowsc8468932017-03-17 16:13:41 +0000207 t2fs.init(svg, forceG, uplink, dim, zoomer);
Steven Burrows57e24e92016-08-04 18:38:24 +0100208
Simon Huntd5b96732016-07-08 13:22:27 -0700209 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100210
Simon Huntd5b96732016-07-08 13:22:27 -0700211 // setUpToolbar();
Simon Huntd5b96732016-07-08 13:22:27 -0700212 // setUpNoDevs();
Simon Huntd5b96732016-07-08 13:22:27 -0700213
Simon Huntd5b96732016-07-08 13:22:27 -0700214 // tes.bindHandlers();
215 // setUpSprites();
216
217 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
218 // tfs.initForce(svg, forceG, uplink, dim);
219 // tis.initInst({ showMastership: tfs.showMastership });
220 // tps.initPanels();
221
222 // restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800223 // ttbs.setDefaultOverlay(prefsState.ovid);
Simon Huntd5b96732016-07-08 13:22:27 -0700224
225 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100226
Steven Burrows5570d1b2016-09-28 14:21:00 -0700227 summaryPanel.init();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500228 detailsPanel.init();
Steven Burrows5570d1b2016-09-28 14:21:00 -0700229
Simon Hunt95f4b422017-03-03 13:49:05 -0800230 // Now that we are initialized, ask the server for what we
231 // need to show.
232 t2es.start();
233
Simon Huntd5b96732016-07-08 13:22:27 -0700234 $log.log('OvTopo2Ctrl has been created');
235 }]);
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100236})();