blob: 775228c0a99ae77bdf0956efd9bfe6b99d36be3c [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,
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(),
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 Huntf0c6f542017-03-22 18:31:18 -070076 // Note: Meta data stored in the context of the current layout,
77 // automatically, by the server
Simon Hunt95f4b422017-03-03 13:49:05 -080078
Simon Huntf0c6f542017-03-22 18:31:18 -070079 wss.sendEvent('updateMeta2', {
80 id: 'layoutZoom',
81 memento: metaUi
82 });
Steven Burrows57e24e92016-08-04 18:38:24 +010083 }
84
85 function setUpZoom() {
Simon Hunt95f4b422017-03-03 13:49:05 -080086 zoomLayer = svg.append('g').attr('id', 'topo2-zoomlayer');
Steven Burrows0616e802016-10-06 21:45:07 -050087
88 zoomer = t2zs.createZoomer({
Steven Burrows57e24e92016-08-04 18:38:24 +010089 svg: svg,
90 zoomLayer: zoomLayer,
91 zoomEnabled: zoomEnabled,
92 zoomCallback: zoomCallback
93 });
94 }
95
Simon Huntd5b96732016-07-08 13:22:27 -070096 // === Controller Definition -----------------------------------------
97
98 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
Steven Burrowsaf96a212016-12-28 12:57:02 +000099 .controller('OvTopo2Ctrl', [
Simon Hunt95f4b422017-03-03 13:49:05 -0800100 '$scope', '$log', '$location',
101 'FnService', 'MastService', 'KeyService', 'GlyphService', 'MapService',
102 'SvgUtilService', 'FlashService', 'WebSocketService',
103 'PrefsService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +0100104 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Steven Burrowse3a18842016-09-22 15:33:33 +0100105 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
Simon Hunt95f4b422017-03-03 13:49:05 -0800106 'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService',
Steven Burrowsc8468932017-03-17 16:13:41 +0000107 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2ToolbarService',
Simon Huntd5b96732016-07-08 13:22:27 -0700108
Simon Hunt95f4b422017-03-03 13:49:05 -0800109 function (
110 _$scope_, _$log_, _$loc_,
111 _fs_, _mast_, _ks_, _gs_, _ms_,
112 _sus_, _flash_, _wss_,
113 _ps_, _th_,
114 _t2es_, _t2fs_, _t2is_,
115 _t2bcs_, _t2kcs_, _t2ms_,
116 _t2mcs_, _t2zs_, t2sls,
Steven Burrowsc8468932017-03-17 16:13:41 +0000117 summaryPanel, detailsPanel, t2tbs
Steven Burrows5570d1b2016-09-28 14:21:00 -0700118 ) {
Simon Huntd5b96732016-07-08 13:22:27 -0700119 var params = _$loc_.search(),
Simon Huntd5b96732016-07-08 13:22:27 -0700120 dim,
121 wh,
122 uplink = {
123 // provides function calls back into this space
124 // showNoDevs: showNoDevs,
125 // projection: function () { return projection; },
Steven Burrows9edc7e02016-08-29 11:52:07 +0100126 zoomLayer: function () { return zoomLayer; },
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100127 zoomer: function () { return zoomer; }
Simon Huntd5b96732016-07-08 13:22:27 -0700128 // opacifyMap: opacifyMap,
Simon Huntd5b96732016-07-08 13:22:27 -0700129 };
130
131 $scope = _$scope_;
132 $log = _$log_;
Simon Huntd5b96732016-07-08 13:22:27 -0700133
134 fs = _fs_;
135 mast = _mast_;
136 ks = _ks_;
Simon Huntf0c6f542017-03-22 18:31:18 -0700137 wss = _wss_;
Simon Huntd5b96732016-07-08 13:22:27 -0700138 gs = _gs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700139 sus = _sus_;
Simon Huntd5b96732016-07-08 13:22:27 -0700140 ps = _ps_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100141
Simon Huntd5b96732016-07-08 13:22:27 -0700142 t2es = _t2es_;
143 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100144 t2is = _t2is_;
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100145 t2bcs = _t2bcs_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100146 t2kcs = _t2kcs_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100147 t2ms = _t2ms_;
Steven Burrowse7cc3082016-09-27 11:24:58 -0700148 t2mcs = _t2mcs_;
Steven Burrows0616e802016-10-06 21:45:07 -0500149 t2zs = _t2zs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700150
151 // capture selected intent parameters (if they are set in the
152 // query string) so that the traffic overlay can highlight
153 // the path for that intent
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100154 if (params.intentKey &&
155 params.intentAppId &&
156 params.intentAppName) {
157
Simon Huntd5b96732016-07-08 13:22:27 -0700158 $scope.intentData = {
159 key: params.intentKey,
160 appId: params.intentAppId,
Simon Hunt95f4b422017-03-03 13:49:05 -0800161 appName: params.intentAppName,
162 intentType: params.intentType
Simon Huntd5b96732016-07-08 13:22:27 -0700163 };
164 }
165
166 $scope.notifyResize = function () {
167 svgResized(fs.windowSize(mast.mastHeight()));
168 };
169
170 // Cleanup on destroyed scope..
171 $scope.$on('$destroy', function () {
172 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
173 t2es.stop();
174 ks.unbindKeys();
175 t2fs.destroy();
Steven Burrows7a9d04e2016-09-26 17:05:37 -0700176 t2is.destroy();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500177 summaryPanel.destroy();
178 detailsPanel.destroy();
Simon Huntd5b96732016-07-08 13:22:27 -0700179 });
180
181 // svg layer and initialization of components
182 ovtopo2 = d3.select('#ov-topo2');
183 svg = ovtopo2.select('svg');
184 // set the svg size to match that of the window, less the masthead
185 wh = fs.windowSize(mast.mastHeight());
186 $log.debug('setting topo SVG size to', wh);
187 svg.attr(wh);
188 dim = [wh.width, wh.height];
189
Simon Huntd5b96732016-07-08 13:22:27 -0700190 // set up our keyboard shortcut bindings
191 setUpKeys();
Steven Burrows57e24e92016-08-04 18:38:24 +0100192 setUpZoom();
193 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700194
195 // make sure we can respond to topology events from the server
196 t2es.bindHandlers();
197
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100198 t2bcs.init();
Steven Burrowsc8468932017-03-17 16:13:41 +0000199 t2kcs.init(t2fs, t2tbs);
Steven Burrows57e24e92016-08-04 18:38:24 +0100200 t2is.initInst({ showMastership: t2fs.showMastership });
Steven Burrowsc8468932017-03-17 16:13:41 +0000201 t2fs.init(svg, forceG, uplink, dim, zoomer);
Steven Burrows57e24e92016-08-04 18:38:24 +0100202
Simon Huntd5b96732016-07-08 13:22:27 -0700203 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100204
Simon Huntd5b96732016-07-08 13:22:27 -0700205 // setUpToolbar();
Simon Huntd5b96732016-07-08 13:22:27 -0700206 // setUpNoDevs();
Simon Huntd5b96732016-07-08 13:22:27 -0700207
Simon Huntd5b96732016-07-08 13:22:27 -0700208 // tes.bindHandlers();
209 // setUpSprites();
210
211 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
212 // tfs.initForce(svg, forceG, uplink, dim);
213 // tis.initInst({ showMastership: tfs.showMastership });
214 // tps.initPanels();
215
216 // restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800217 // ttbs.setDefaultOverlay(prefsState.ovid);
Simon Huntd5b96732016-07-08 13:22:27 -0700218
219 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100220
Steven Burrows5570d1b2016-09-28 14:21:00 -0700221 summaryPanel.init();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500222 detailsPanel.init();
Steven Burrows5570d1b2016-09-28 14:21:00 -0700223
Simon Hunt95f4b422017-03-03 13:49:05 -0800224 // Now that we are initialized, ask the server for what we
225 // need to show.
226 t2es.start();
227
Simon Huntd5b96732016-07-08 13:22:27 -0700228 $log.log('OvTopo2Ctrl has been created');
229 }]);
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100230})();