blob: ce90af66ccd0493b7162f17b92094eec253eada6 [file] [log] [blame]
Simon Huntd5b96732016-07-08 13:22:27 -07001/*
2 * 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 */
16
17/*
18 ONOS GUI -- Topology View Module
19
20 NOTE: currently under development to support Regions.
21 */
22
23(function () {
24 'use strict';
25
26 // references to injected services
27 var $scope, $log, $loc,
28 fs, mast, ks, zs,
29 gs, ms, sus, flash,
30 wss, ps, th,
31 t2es, t2fs;
32
33 // DOM elements
34 var ovtopo2, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer;
35
36 // Internal state
37 var zoomer, actionMap;
38
39
40 // === Helper Functions
41
42 // callback invoked when the SVG view has been resized..
43 function svgResized(s) {
44 $log.debug("topo2 view resized", s);
45 }
46
47 function setUpKeys(overlayKeys) {
48 $log.debug('topo2: set up keys....');
49 }
50
51 // === Controller Definition -----------------------------------------
52
53 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
54 .controller('OvTopo2Ctrl',
55 ['$scope', '$log', '$location',
56 'FnService', 'MastService', 'KeyService', 'ZoomService',
57 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
58 'WebSocketService', 'PrefsService', 'ThemeService',
59 'Topo2EventService', 'Topo2ForceService',
60
61 function (_$scope_, _$log_, _$loc_,
62 _fs_, _mast_, _ks_, _zs_,
63 _gs_, _ms_, _sus_, _flash_,
64 _wss_, _ps_, _th_,
65 _t2es_, _t2fs_) {
66
67 var params = _$loc_.search(),
68 projection,
69 dim,
70 wh,
71 uplink = {
72 // provides function calls back into this space
73 // showNoDevs: showNoDevs,
74 // projection: function () { return projection; },
75 // zoomLayer: function () { return zoomLayer; },
76 // zoomer: function () { return zoomer; },
77 // opacifyMap: opacifyMap,
78 // topoStartDone: topoStartDone
79 };
80
81 $scope = _$scope_;
82 $log = _$log_;
83 $loc = _$loc_;
84
85 fs = _fs_;
86 mast = _mast_;
87 ks = _ks_;
88 zs = _zs_;
89
90 gs = _gs_;
91 ms = _ms_;
92 sus = _sus_;
93 flash = _flash_;
94
95 wss = _wss_;
96 ps = _ps_;
97 th = _th_;
98
99 t2es = _t2es_;
100 t2fs = _t2fs_;
101
102 // capture selected intent parameters (if they are set in the
103 // query string) so that the traffic overlay can highlight
104 // the path for that intent
105 if (params.intentKey && params.intentAppId && params.intentAppName) {
106 $scope.intentData = {
107 key: params.intentKey,
108 appId: params.intentAppId,
109 appName: params.intentAppName
110 };
111 }
112
113 $scope.notifyResize = function () {
114 svgResized(fs.windowSize(mast.mastHeight()));
115 };
116
117 // Cleanup on destroyed scope..
118 $scope.$on('$destroy', function () {
119 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
120 t2es.stop();
121 ks.unbindKeys();
122 t2fs.destroy();
123 });
124
125 // svg layer and initialization of components
126 ovtopo2 = d3.select('#ov-topo2');
127 svg = ovtopo2.select('svg');
128 // set the svg size to match that of the window, less the masthead
129 wh = fs.windowSize(mast.mastHeight());
130 $log.debug('setting topo SVG size to', wh);
131 svg.attr(wh);
132 dim = [wh.width, wh.height];
133
134
135 // set up our keyboard shortcut bindings
136 setUpKeys();
137
138 // make sure we can respond to topology events from the server
139 t2es.bindHandlers();
140
141 // initialize the force layout, ready to render the topology
142 t2fs.init();
143
144
145 // =-=-=-=-=-=-=-=-
146 // TODO: in future, we will load background map data
147 // asynchronously (hence the promise) and then chain off
148 // there to send the topo2start event to the server.
149 // For now, we'll send the event inline...
150 t2es.start();
151
152
153 // === ORIGINAL CODE ===
154
155 // setUpKeys();
156 // setUpToolbar();
157 // setUpDefs();
158 // setUpZoom();
159 // setUpNoDevs();
160 /*
161 setUpMap().then(
162 function (proj) {
163 var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 });
164 zoomer.panZoom([z.tx, z.ty], z.sc);
165 $log.debug('** Zoom restored:', z);
166
167 projection = proj;
168 $log.debug('** We installed the projection:', proj);
169 flash.enable(false);
170 toggleMap(prefsState.bg);
171 flash.enable(true);
172 mapShader(true);
173
174 // now we have the map projection, we are ready for
175 // the server to send us device/host data...
176 tes.start();
177 // need to do the following so we immediately get
178 // the summary panel data back from the server
179 restoreSummaryFromPrefs();
180 }
181 );
182 */
183 // tes.bindHandlers();
184 // setUpSprites();
185
186 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
187 // tfs.initForce(svg, forceG, uplink, dim);
188 // tis.initInst({ showMastership: tfs.showMastership });
189 // tps.initPanels();
190
191 // restoreConfigFromPrefs();
192 // ttbs.setDefaultOverlay(prefsState.ovidx);
193
194 // $log.debug('registered overlays...', tov.list());
195
196 $log.log('OvTopo2Ctrl has been created');
197 }]);
198}());