blob: c798927733d18f939d576268b781f0bf751562b3 [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
Steven Burrows448468c2017-04-13 16:09:30 -070034 var zoomer;
Simon Huntd5b96732016-07-08 13:22:27 -070035
Steven Burrows57e24e92016-08-04 18:38:24 +010036 // --- Glyphs, Icons, and the like -----------------------------------
37
38 function setUpDefs() {
39 defs = svg.append('defs');
40 gs.loadDefs(defs);
Simon Hunt95f4b422017-03-03 13:49:05 -080041
42 // TODO: consider using something other than the "glow" styles
Steven Burrows57e24e92016-08-04 18:38:24 +010043 sus.loadGlowDefs(defs);
44 }
Simon Huntd5b96732016-07-08 13:22:27 -070045
46 // callback invoked when the SVG view has been resized..
47 function svgResized(s) {
Steven Burrowsec1f45c2016-08-08 16:14:41 +010048 t2fs.newDim([s.width, s.height]);
Simon Huntd5b96732016-07-08 13:22:27 -070049 }
50
Steven Burrows57e24e92016-08-04 18:38:24 +010051 // --- Pan and Zoom --------------------------------------------------
52
53 // zoom enabled predicate. ev is a D3 source event.
54 function zoomEnabled(ev) {
55 return fs.isMobile() || (ev.metaKey || ev.altKey);
56 }
57
58 function zoomCallback() {
59 var sc = zoomer.scale(),
Simon Hunt95f4b422017-03-03 13:49:05 -080060 tr = zoomer.translate(),
Simon Huntf0c6f542017-03-22 18:31:18 -070061 metaUi = isNaN(sc) ? {
62 useCfg: 1
63 } : {
64 scale: sc,
65 offsetX: tr[0],
66 offsetY: tr[1]
67 };
Steven Burrows57e24e92016-08-04 18:38:24 +010068
Simon Huntc43a59d2017-04-05 13:56:13 -070069 // Allow map service to react to change in zoom parameters
70 t2ms.zoomCallback(sc, tr);
71
Simon Huntf0c6f542017-03-22 18:31:18 -070072 // Note: Meta data stored in the context of the current layout,
73 // automatically, by the server
Simon Hunt95f4b422017-03-03 13:49:05 -080074
Simon Huntf0c6f542017-03-22 18:31:18 -070075 wss.sendEvent('updateMeta2', {
76 id: 'layoutZoom',
77 memento: metaUi
78 });
Steven Burrows57e24e92016-08-04 18:38:24 +010079 }
80
81 function setUpZoom() {
Simon Hunt95f4b422017-03-03 13:49:05 -080082 zoomLayer = svg.append('g').attr('id', 'topo2-zoomlayer');
Steven Burrows0616e802016-10-06 21:45:07 -050083
84 zoomer = t2zs.createZoomer({
Steven Burrows57e24e92016-08-04 18:38:24 +010085 svg: svg,
86 zoomLayer: zoomLayer,
87 zoomEnabled: zoomEnabled,
88 zoomCallback: zoomCallback
89 });
90 }
91
Simon Huntd5b96732016-07-08 13:22:27 -070092 // === Controller Definition -----------------------------------------
93
94 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
Steven Burrowsaf96a212016-12-28 12:57:02 +000095 .controller('OvTopo2Ctrl', [
Simon Hunt95f4b422017-03-03 13:49:05 -080096 '$scope', '$log', '$location',
97 'FnService', 'MastService', 'KeyService', 'GlyphService', 'MapService',
98 'SvgUtilService', 'FlashService', 'WebSocketService',
99 'PrefsService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +0100100 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Steven Burrowse3a18842016-09-22 15:33:33 +0100101 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
Simon Hunt95f4b422017-03-03 13:49:05 -0800102 'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService',
Steven Burrowsc8468932017-03-17 16:13:41 +0000103 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2ToolbarService',
Steven Burrows6501de92017-04-12 15:10:34 -0700104 'Topo2NoDevicesConnectedService',
Simon Huntd5b96732016-07-08 13:22:27 -0700105
Simon Hunt95f4b422017-03-03 13:49:05 -0800106 function (
107 _$scope_, _$log_, _$loc_,
108 _fs_, _mast_, _ks_, _gs_, _ms_,
109 _sus_, _flash_, _wss_,
110 _ps_, _th_,
111 _t2es_, _t2fs_, _t2is_,
112 _t2bcs_, _t2kcs_, _t2ms_,
113 _t2mcs_, _t2zs_, t2sls,
Steven Burrows6501de92017-04-12 15:10:34 -0700114 summaryPanel, detailsPanel, t2tbs, t2ndcs
Steven Burrows5570d1b2016-09-28 14:21:00 -0700115 ) {
Simon Huntd5b96732016-07-08 13:22:27 -0700116 var params = _$loc_.search(),
Simon Huntd5b96732016-07-08 13:22:27 -0700117 dim,
118 wh,
119 uplink = {
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 };
123
124 $scope = _$scope_;
125 $log = _$log_;
Simon Huntd5b96732016-07-08 13:22:27 -0700126
127 fs = _fs_;
128 mast = _mast_;
129 ks = _ks_;
Simon Huntf0c6f542017-03-22 18:31:18 -0700130 wss = _wss_;
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
Steven Burrows57e24e92016-08-04 18:38:24 +0100184 setUpZoom();
185 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700186
Steven Burrows6501de92017-04-12 15:10:34 -0700187 t2ndcs.init();
188
Simon Huntd5b96732016-07-08 13:22:27 -0700189 // make sure we can respond to topology events from the server
190 t2es.bindHandlers();
191
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100192 t2bcs.init();
Steven Burrowsc8468932017-03-17 16:13:41 +0000193 t2kcs.init(t2fs, t2tbs);
Steven Burrows57e24e92016-08-04 18:38:24 +0100194 t2is.initInst({ showMastership: t2fs.showMastership });
Steven Burrowsc8468932017-03-17 16:13:41 +0000195 t2fs.init(svg, forceG, uplink, dim, zoomer);
Steven Burrows57e24e92016-08-04 18:38:24 +0100196
Simon Huntd5b96732016-07-08 13:22:27 -0700197 // === ORIGINAL CODE ===
Simon Huntd5b96732016-07-08 13:22:27 -0700198 // restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800199 // ttbs.setDefaultOverlay(prefsState.ovid);
Simon Huntd5b96732016-07-08 13:22:27 -0700200
Steven Burrowsc59481f2017-04-13 10:01:15 -0700201 summaryPanel.init(detailsPanel);
202 detailsPanel.init(summaryPanel);
Steven Burrows5570d1b2016-09-28 14:21:00 -0700203
Simon Hunt95f4b422017-03-03 13:49:05 -0800204 // Now that we are initialized, ask the server for what we
Steven Burrows448468c2017-04-13 16:09:30 -0700205 // need to show.
Simon Hunt95f4b422017-03-03 13:49:05 -0800206 t2es.start();
207
Simon Huntd5b96732016-07-08 13:22:27 -0700208 $log.log('OvTopo2Ctrl has been created');
209 }]);
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100210})();