blob: 9418d17190e07419200a2ac6cc9f4e4b05b6cc8d [file] [log] [blame]
Thomas Vachuska26be4f32016-03-31 01:10:27 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuska26be4f32016-03-31 01:10:27 -07003 *
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 Map Module.
19 Defines behavior for loading geographical maps into the map layer.
20 */
21
22(function () {
23 'use strict';
24
25 // injected refs
26 var $log, $loc, fs, flash, wss, tds, delegate;
27
28 // constants
29 var mapRequest = 'mapSelectorRequest';
30
31 // internal state
32 var order, maps, map, mapItems, tintCheck, msgHandlers;
33
34 // === ---------------------------
35 // === Helper functions
36
37
38 // === ---------------------------
39 // === Main API functions
40
41 function openMapSelection() {
42 wss.sendEvent(mapRequest);
43 }
44
45 function closeMapSelection() {
46 tds.closeDialog();
47 }
48
49 function start(d) {
50 delegate = d;
51 wss.bindHandlers(msgHandlers);
52 }
53
54 function stop() {
55 wss.unbindHandlers(msgHandlers);
56 }
57
58 function dOk() {
59 var p = {
60 mapid: map.id,
61 mapscale: map.scale,
Steven Burrows3a9a6442016-05-05 15:31:16 +010062 mapfilepath: map.filePath,
Simon Huntf29d8e62016-06-20 11:09:25 -070063 tint: 'off'
64 // tint: tintCheck.property('checked') ? 'on' : 'off'
Thomas Vachuska26be4f32016-03-31 01:10:27 -070065 };
66 setMap(p);
67 $log.debug('Dialog OK button clicked');
68 }
69
70 function dClose() {
71 $log.debug('Dialog Close button clicked (or Esc pressed)');
72 }
73
74 function selectMap() {
75 map = maps[this.options[this.selectedIndex].value];
76 $log.info('Selected map', map);
77 }
78
79 function createListContent() {
80 var content = tds.createDiv('map-list'),
81 form = content.append('form'),
82 current = currentMap();
83 map = maps[current.mapid];
84 mapItems = form.append('select').on('change', selectMap);
85 order.forEach(function (id) {
86 var m = maps[id];
87 mapItems.append('option')
88 .attr('value', m.id)
89 .attr('selected', m.id === current.mapid ? true : null)
90 .text(m.description);
91 });
Simon Huntf29d8e62016-06-20 11:09:25 -070092
93/*
Thomas Vachuska26be4f32016-03-31 01:10:27 -070094 var p = form.append('p');
95 tintCheck = p.append('input').attr('type', 'checkbox').attr('name', 'tint');
96 if (current.tint == 'on') {
97 tintCheck.attr('checked', 'true');
98 }
99 p.append('span').text('Enable map tint');
Simon Huntf29d8e62016-06-20 11:09:25 -0700100*/
101
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700102 return content;
103 }
104
105 function handleMapResponse(data) {
106 $log.info('Got response', data);
107 order = data.order;
108 maps = data.maps;
109 tds.openDialog()
110 .setTitle('Select Map')
111 .addContent(createListContent())
112 .addOk(dOk, 'OK')
113 .addCancel(dClose, 'Close')
114 .bindKeys();
115 }
116
117 function toggleMap() {
118 delegate.toggleMap();
119 }
120
121 function currentMap() {
122 return delegate.currentMap();
123 }
124
125 function setMap(map) {
126 delegate.setMap(map);
127 }
128
129 // === -----------------------------------------------------
130 // === MODULE DEFINITION ===
131
132 angular.module('ovTopo')
133 .factory('TopoMapService',
134 ['$log', '$location', 'FnService', 'FlashService', 'WebSocketService',
135 'TopoDialogService',
136
137 function (_$log_, _$loc_, _fs_, _flash_, _wss_, _tds_) {
138 $log = _$log_;
139 $loc = _$loc_;
140 fs = _fs_;
141 flash = _flash_;
142 wss = _wss_;
143 tds = _tds_;
144
145 msgHandlers = {
146 mapSelectorResponse: handleMapResponse
147 };
148
149 return {
150 toggleMap: toggleMap,
151 currentMap: currentMap,
152 setMap: setMap,
153
154 openMapSelection: openMapSelection,
155 closeMapSelection: closeMapSelection,
156 start: start,
157 stop: stop
158 };
159 }]);
160
161}());