blob: e443d39f9da9ccbe5d65a196b959fd60c638bbb6 [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
Steven Burrows1c5c8612016-10-05 13:45:13 -050027 var $scope, $log, fs, mast, ks,
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,
35 currentLayoutId = '_default_'; // NOTE: see UiTopoLayoutId.DEFAULT_STR
36
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(),
68 sparse = {};
Steven Burrows57e24e92016-08-04 18:38:24 +010069
Simon Hunt95f4b422017-03-03 13:49:05 -080070 sparse[currentLayoutId] = {
71 zoomScale: sc,
72 zoomPanX: tr[0],
73 zoomPanY: tr[1]
74 };
75
76 ps.mergePrefs('topo2_zoom', sparse);
Steven Burrows57e24e92016-08-04 18:38:24 +010077 }
78
79 function setUpZoom() {
Simon Hunt95f4b422017-03-03 13:49:05 -080080 zoomLayer = svg.append('g').attr('id', 'topo2-zoomlayer');
Steven Burrows0616e802016-10-06 21:45:07 -050081
82 zoomer = t2zs.createZoomer({
Steven Burrows57e24e92016-08-04 18:38:24 +010083 svg: svg,
84 zoomLayer: zoomLayer,
85 zoomEnabled: zoomEnabled,
86 zoomCallback: zoomCallback
87 });
88 }
89
Simon Huntd5b96732016-07-08 13:22:27 -070090 // === Controller Definition -----------------------------------------
91
92 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
Steven Burrowsaf96a212016-12-28 12:57:02 +000093 .controller('OvTopo2Ctrl', [
Simon Hunt95f4b422017-03-03 13:49:05 -080094 '$scope', '$log', '$location',
95 'FnService', 'MastService', 'KeyService', 'GlyphService', 'MapService',
96 'SvgUtilService', 'FlashService', 'WebSocketService',
97 'PrefsService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +010098 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Steven Burrowse3a18842016-09-22 15:33:33 +010099 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
Simon Hunt95f4b422017-03-03 13:49:05 -0800100 'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService',
101 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel',
Simon Huntd5b96732016-07-08 13:22:27 -0700102
Simon Hunt95f4b422017-03-03 13:49:05 -0800103 function (
104 _$scope_, _$log_, _$loc_,
105 _fs_, _mast_, _ks_, _gs_, _ms_,
106 _sus_, _flash_, _wss_,
107 _ps_, _th_,
108 _t2es_, _t2fs_, _t2is_,
109 _t2bcs_, _t2kcs_, _t2ms_,
110 _t2mcs_, _t2zs_, t2sls,
111 summaryPanel, detailsPanel
Steven Burrows5570d1b2016-09-28 14:21:00 -0700112 ) {
Simon Huntd5b96732016-07-08 13:22:27 -0700113 var params = _$loc_.search(),
Simon Huntd5b96732016-07-08 13:22:27 -0700114 dim,
115 wh,
116 uplink = {
117 // provides function calls back into this space
118 // showNoDevs: showNoDevs,
119 // projection: function () { return projection; },
Steven Burrows9edc7e02016-08-29 11:52:07 +0100120 zoomLayer: function () { return zoomLayer; },
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100121 zoomer: function () { return zoomer; }
Simon Huntd5b96732016-07-08 13:22:27 -0700122 // opacifyMap: opacifyMap,
Simon Huntd5b96732016-07-08 13:22:27 -0700123 };
124
125 $scope = _$scope_;
126 $log = _$log_;
Simon Huntd5b96732016-07-08 13:22:27 -0700127
128 fs = _fs_;
129 mast = _mast_;
130 ks = _ks_;
Simon Huntd5b96732016-07-08 13:22:27 -0700131 gs = _gs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700132 sus = _sus_;
Simon Huntd5b96732016-07-08 13:22:27 -0700133 ps = _ps_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100134
Simon Huntd5b96732016-07-08 13:22:27 -0700135 t2es = _t2es_;
136 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100137 t2is = _t2is_;
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100138 t2bcs = _t2bcs_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100139 t2kcs = _t2kcs_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100140 t2ms = _t2ms_;
Steven Burrowse7cc3082016-09-27 11:24:58 -0700141 t2mcs = _t2mcs_;
Steven Burrows0616e802016-10-06 21:45:07 -0500142 t2zs = _t2zs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700143
144 // capture selected intent parameters (if they are set in the
145 // query string) so that the traffic overlay can highlight
146 // the path for that intent
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100147 if (params.intentKey &&
148 params.intentAppId &&
149 params.intentAppName) {
150
Simon Huntd5b96732016-07-08 13:22:27 -0700151 $scope.intentData = {
152 key: params.intentKey,
153 appId: params.intentAppId,
Simon Hunt95f4b422017-03-03 13:49:05 -0800154 appName: params.intentAppName,
155 intentType: params.intentType
Simon Huntd5b96732016-07-08 13:22:27 -0700156 };
157 }
158
159 $scope.notifyResize = function () {
160 svgResized(fs.windowSize(mast.mastHeight()));
161 };
162
163 // Cleanup on destroyed scope..
164 $scope.$on('$destroy', function () {
165 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
166 t2es.stop();
167 ks.unbindKeys();
168 t2fs.destroy();
Steven Burrows7a9d04e2016-09-26 17:05:37 -0700169 t2is.destroy();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500170 summaryPanel.destroy();
171 detailsPanel.destroy();
Simon Huntd5b96732016-07-08 13:22:27 -0700172 });
173
174 // svg layer and initialization of components
175 ovtopo2 = d3.select('#ov-topo2');
176 svg = ovtopo2.select('svg');
177 // set the svg size to match that of the window, less the masthead
178 wh = fs.windowSize(mast.mastHeight());
179 $log.debug('setting topo SVG size to', wh);
180 svg.attr(wh);
181 dim = [wh.width, wh.height];
182
Simon Huntd5b96732016-07-08 13:22:27 -0700183 // set up our keyboard shortcut bindings
184 setUpKeys();
Steven Burrows57e24e92016-08-04 18:38:24 +0100185 setUpZoom();
186 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700187
188 // make sure we can respond to topology events from the server
189 t2es.bindHandlers();
190
Simon Hunt95f4b422017-03-03 13:49:05 -0800191 // Add the map SVG Group, but don't load a map yet...
192 // we will wait until the server tells us whether we should
193 // be loading a geomap or a sprite layer
194 t2ms.init(zoomLayer, zoomer);
Steven Burrowse7cc3082016-09-27 11:24:58 -0700195
Simon Hunt95f4b422017-03-03 13:49:05 -0800196 // TODO: figure out from where to call this code...
197 // we still need to do the equivalent of this when we load
198 // a geo map, just not here.
199 //
200 // ... NOTE: we still have to position the nodes AFTER the map
201 // has loaded and the projection has been established...
202 // maybe another promise ending with a "positionNodes()"
203 // call?
Steven Burrowse7cc3082016-09-27 11:24:58 -0700204
Simon Hunt95f4b422017-03-03 13:49:05 -0800205 // .then(
206 // function (proj) {
207 // var z = ps.getPrefs('topo2_zoom', { tx: 0, ty: 0, sc: 1 });
208 // zoomer.panZoom([z.tx, z.ty], z.sc);
209 //
210 // t2mcs.projection(proj);
211 // $log.debug('** Zoom restored:', z);
212 // $log.debug('** We installed the projection:', proj);
213 //
214 // // Now the map has load and we have a projection we can
215 // // get the info from the server
216 // t2es.start();
217 // }
218 // );
Steven Burrowse3a18842016-09-22 15:33:33 +0100219
Steven Burrows3cc0c372017-02-10 15:15:24 +0000220 t2sls.init(svg, zoomLayer);
Steven Burrows1aa4f582016-12-13 15:05:41 -0500221 t2fs.init(svg, forceG, uplink, dim, zoomer);
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100222 t2bcs.init();
Steven Burrowse3a18842016-09-22 15:33:33 +0100223 t2kcs.init(t2fs);
Steven Burrows57e24e92016-08-04 18:38:24 +0100224 t2is.initInst({ showMastership: t2fs.showMastership });
225
Simon Huntd5b96732016-07-08 13:22:27 -0700226 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100227
Simon Huntd5b96732016-07-08 13:22:27 -0700228 // setUpToolbar();
Simon Huntd5b96732016-07-08 13:22:27 -0700229 // setUpNoDevs();
Simon Huntd5b96732016-07-08 13:22:27 -0700230
Simon Huntd5b96732016-07-08 13:22:27 -0700231 // tes.bindHandlers();
232 // setUpSprites();
233
234 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
235 // tfs.initForce(svg, forceG, uplink, dim);
236 // tis.initInst({ showMastership: tfs.showMastership });
237 // tps.initPanels();
238
239 // restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800240 // ttbs.setDefaultOverlay(prefsState.ovid);
Simon Huntd5b96732016-07-08 13:22:27 -0700241
242 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100243
Steven Burrows5570d1b2016-09-28 14:21:00 -0700244 summaryPanel.init();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500245 detailsPanel.init();
Steven Burrows5570d1b2016-09-28 14:21:00 -0700246
Simon Hunt95f4b422017-03-03 13:49:05 -0800247 // Now that we are initialized, ask the server for what we
248 // need to show.
249 t2es.start();
250
Simon Huntd5b96732016-07-08 13:22:27 -0700251 $log.log('OvTopo2Ctrl has been created');
252 }]);
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100253})();