blob: 95082f1677496ab1a7f1ce27809c6389f18f1fe1 [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';
Steven Burrows46c5f102017-07-14 16:52:46 +010025
Simon Huntd5b96732016-07-08 13:22:27 -070026 // references to injected services
Simon Huntf0c6f542017-03-22 18:31:18 -070027 var $scope, $log, fs, mast, ks, wss,
Steven Burrows46c5f102017-07-14 16:52:46 +010028 gs, sus, t2es, t2fs, t2is, t2bcs, t2kcs, t2ms, 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) ? {
Steven Burrows46c5f102017-07-14 16:52:46 +010062 useCfg: 1,
Simon Huntf0c6f542017-03-22 18:31:18 -070063 } : {
64 scale: sc,
65 offsetX: tr[0],
Steven Burrows46c5f102017-07-14 16:52:46 +010066 offsetY: tr[1],
Simon Huntf0c6f542017-03-22 18:31:18 -070067 };
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',
Steven Burrows46c5f102017-07-14 16:52:46 +010077 memento: metaUi,
Simon Huntf0c6f542017-03-22 18:31:18 -070078 });
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,
Steven Burrows46c5f102017-07-14 16:52:46 +010088 zoomCallback: zoomCallback,
Steven Burrows57e24e92016-08-04 18:38:24 +010089 });
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',
Steven Burrows46c5f102017-07-14 16:52:46 +010098 'SvgUtilService', 'FlashService', 'WebSocketService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +010099 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Steven Burrowse3a18842016-09-22 15:33:33 +0100100 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
Steven Burrows46c5f102017-07-14 16:52:46 +0100101 'Topo2ZoomService', 'Topo2SpriteLayerService',
Steven Burrowsc8468932017-03-17 16:13:41 +0000102 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2ToolbarService',
Simon Hunte6f64612017-04-28 00:01:48 -0700103 'Topo2NoDevicesConnectedService', 'Topo2OverlayService',
Simon Huntd5b96732016-07-08 13:22:27 -0700104
Simon Hunt95f4b422017-03-03 13:49:05 -0800105 function (
106 _$scope_, _$log_, _$loc_,
107 _fs_, _mast_, _ks_, _gs_, _ms_,
Steven Burrows46c5f102017-07-14 16:52:46 +0100108 _sus_, _flash_, _wss_, _th_,
Simon Hunt95f4b422017-03-03 13:49:05 -0800109 _t2es_, _t2fs_, _t2is_,
110 _t2bcs_, _t2kcs_, _t2ms_,
Steven Burrows46c5f102017-07-14 16:52:46 +0100111 _t2zs_, t2sls,
Simon Hunte6f64612017-04-28 00:01:48 -0700112 summaryPanel, detailsPanel, t2tbs, t2ndcs, t2os
Steven Burrows5570d1b2016-09-28 14:21:00 -0700113 ) {
Simon Huntd5b96732016-07-08 13:22:27 -0700114 var params = _$loc_.search(),
Simon Huntd5b96732016-07-08 13:22:27 -0700115 dim,
116 wh,
117 uplink = {
Steven Burrows9edc7e02016-08-29 11:52:07 +0100118 zoomLayer: function () { return zoomLayer; },
Steven Burrows46c5f102017-07-14 16:52:46 +0100119 zoomer: function () { return zoomer; },
Simon Huntd5b96732016-07-08 13:22:27 -0700120 };
121
122 $scope = _$scope_;
123 $log = _$log_;
Simon Huntd5b96732016-07-08 13:22:27 -0700124
125 fs = _fs_;
126 mast = _mast_;
127 ks = _ks_;
Simon Huntf0c6f542017-03-22 18:31:18 -0700128 wss = _wss_;
Simon Huntd5b96732016-07-08 13:22:27 -0700129 gs = _gs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700130 sus = _sus_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100131
Simon Huntd5b96732016-07-08 13:22:27 -0700132 t2es = _t2es_;
133 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100134 t2is = _t2is_;
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100135 t2bcs = _t2bcs_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100136 t2kcs = _t2kcs_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100137 t2ms = _t2ms_;
Steven Burrows0616e802016-10-06 21:45:07 -0500138 t2zs = _t2zs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700139
140 // capture selected intent parameters (if they are set in the
141 // query string) so that the traffic overlay can highlight
142 // the path for that intent
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100143 if (params.intentKey &&
144 params.intentAppId &&
145 params.intentAppName) {
146
Simon Huntd5b96732016-07-08 13:22:27 -0700147 $scope.intentData = {
148 key: params.intentKey,
149 appId: params.intentAppId,
Simon Hunt95f4b422017-03-03 13:49:05 -0800150 appName: params.intentAppName,
Steven Burrows46c5f102017-07-14 16:52:46 +0100151 intentType: params.intentType,
Simon Huntd5b96732016-07-08 13:22:27 -0700152 };
153 }
154
155 $scope.notifyResize = function () {
156 svgResized(fs.windowSize(mast.mastHeight()));
157 };
158
159 // Cleanup on destroyed scope..
160 $scope.$on('$destroy', function () {
161 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
162 t2es.stop();
163 ks.unbindKeys();
164 t2fs.destroy();
Steven Burrows7a9d04e2016-09-26 17:05:37 -0700165 t2is.destroy();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500166 summaryPanel.destroy();
167 detailsPanel.destroy();
Simon Huntd5b96732016-07-08 13:22:27 -0700168 });
169
170 // svg layer and initialization of components
171 ovtopo2 = d3.select('#ov-topo2');
172 svg = ovtopo2.select('svg');
173 // set the svg size to match that of the window, less the masthead
174 wh = fs.windowSize(mast.mastHeight());
175 $log.debug('setting topo SVG size to', wh);
176 svg.attr(wh);
177 dim = [wh.width, wh.height];
178
Simon Huntd5b96732016-07-08 13:22:27 -0700179 // set up our keyboard shortcut bindings
Steven Burrows57e24e92016-08-04 18:38:24 +0100180 setUpZoom();
181 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700182
Steven Burrows6501de92017-04-12 15:10:34 -0700183 t2ndcs.init();
184
Simon Huntd5b96732016-07-08 13:22:27 -0700185 // make sure we can respond to topology events from the server
186 t2es.bindHandlers();
187
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100188 t2bcs.init();
Steven Burrowsc8468932017-03-17 16:13:41 +0000189 t2kcs.init(t2fs, t2tbs);
Steven Burrows57e24e92016-08-04 18:38:24 +0100190 t2is.initInst({ showMastership: t2fs.showMastership });
Steven Burrowsc8468932017-03-17 16:13:41 +0000191 t2fs.init(svg, forceG, uplink, dim, zoomer);
Steven Burrows57e24e92016-08-04 18:38:24 +0100192
Simon Huntd5b96732016-07-08 13:22:27 -0700193 // === ORIGINAL CODE ===
Simon Huntd5b96732016-07-08 13:22:27 -0700194 // restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800195 // ttbs.setDefaultOverlay(prefsState.ovid);
Simon Huntd5b96732016-07-08 13:22:27 -0700196
Simon Hunte6f64612017-04-28 00:01:48 -0700197 // ++ TEMPORARY HARD-CODE TRAFFIC OVERLAY ++
198 t2os.setOverlay('traffic-2-overlay');
199
Steven Burrowsc59481f2017-04-13 10:01:15 -0700200 summaryPanel.init(detailsPanel);
201 detailsPanel.init(summaryPanel);
Steven Burrows5570d1b2016-09-28 14:21:00 -0700202
Simon Hunt95f4b422017-03-03 13:49:05 -0800203 // Now that we are initialized, ask the server for what we
Steven Burrows448468c2017-04-13 16:09:30 -0700204 // need to show.
Simon Hunt95f4b422017-03-03 13:49:05 -0800205 t2es.start();
206
Simon Huntd5b96732016-07-08 13:22:27 -0700207 $log.log('OvTopo2Ctrl has been created');
208 }]);
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100209})();