blob: 4e1b9f0f43aed812893f9674927d39b3481a2efd [file] [log] [blame]
Thomas Vachuska26be4f32016-03-31 01:10:27 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
Steven Burrows1c2a9682017-07-14 16:52:46 +010026 var $log, wss, tds, delegate;
Thomas Vachuska26be4f32016-03-31 01:10:27 -070027
28 // constants
29 var mapRequest = 'mapSelectorRequest';
30
31 // internal state
Steven Burrows1c2a9682017-07-14 16:52:46 +010032 var order, maps, map, mapItems, msgHandlers;
Thomas Vachuska26be4f32016-03-31 01:10:27 -070033
Simon Hunt1603c692017-08-10 19:53:35 -070034 // function to be replaced by the localization bundle function
35 var topoLion = function (x) {
36 return '#tmap#' + x + '#';
37 };
Thomas Vachuska26be4f32016-03-31 01:10:27 -070038
39 // === ---------------------------
40 // === Main API functions
41
42 function openMapSelection() {
43 wss.sendEvent(mapRequest);
44 }
45
46 function closeMapSelection() {
47 tds.closeDialog();
48 }
49
50 function start(d) {
51 delegate = d;
52 wss.bindHandlers(msgHandlers);
53 }
54
55 function stop() {
56 wss.unbindHandlers(msgHandlers);
57 }
58
59 function dOk() {
60 var p = {
61 mapid: map.id,
62 mapscale: map.scale,
Steven Burrows3a9a6442016-05-05 15:31:16 +010063 mapfilepath: map.filePath,
Steven Burrows1c2a9682017-07-14 16:52:46 +010064 tint: 'off',
Simon Huntf29d8e62016-06-20 11:09:25 -070065 // tint: tintCheck.property('checked') ? 'on' : 'off'
Thomas Vachuska26be4f32016-03-31 01:10:27 -070066 };
67 setMap(p);
Simon Hunt1603c692017-08-10 19:53:35 -070068 // $log.debug('Dialog OK button clicked');
Thomas Vachuska26be4f32016-03-31 01:10:27 -070069 }
70
71 function dClose() {
Simon Hunt1603c692017-08-10 19:53:35 -070072 // $log.debug('Dialog Close button clicked (or Esc pressed)');
Thomas Vachuska26be4f32016-03-31 01:10:27 -070073 }
74
75 function selectMap() {
76 map = maps[this.options[this.selectedIndex].value];
77 $log.info('Selected map', map);
78 }
79
80 function createListContent() {
81 var content = tds.createDiv('map-list'),
82 form = content.append('form'),
83 current = currentMap();
Simon Hunt1603c692017-08-10 19:53:35 -070084
Thomas Vachuska26be4f32016-03-31 01:10:27 -070085 map = maps[current.mapid];
86 mapItems = form.append('select').on('change', selectMap);
87 order.forEach(function (id) {
88 var m = maps[id];
89 mapItems.append('option')
90 .attr('value', m.id)
91 .attr('selected', m.id === current.mapid ? true : null)
92 .text(m.description);
93 });
Simon Huntf29d8e62016-06-20 11:09:25 -070094
Thomas Vachuska26be4f32016-03-31 01:10:27 -070095 return content;
96 }
97
98 function handleMapResponse(data) {
99 $log.info('Got response', data);
100 order = data.order;
101 maps = data.maps;
102 tds.openDialog()
Simon Hunt1603c692017-08-10 19:53:35 -0700103 .setTitle(topoLion('title_select_map'))
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700104 .addContent(createListContent())
Simon Hunt1603c692017-08-10 19:53:35 -0700105 .addOk(dOk, topoLion('ok'))
106 .addCancel(dClose, topoLion('close'))
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700107 .bindKeys();
108 }
109
110 function toggleMap() {
111 delegate.toggleMap();
112 }
113
114 function currentMap() {
115 return delegate.currentMap();
116 }
117
118 function setMap(map) {
119 delegate.setMap(map);
120 }
121
Simon Hunt1603c692017-08-10 19:53:35 -0700122 // invoked after the localization bundle has been received from the server
123 function setLionBundle(bundle) {
124 topoLion = bundle;
125 }
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700126 // === -----------------------------------------------------
127 // === MODULE DEFINITION ===
128
129 angular.module('ovTopo')
130 .factory('TopoMapService',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100131 ['$log', 'WebSocketService', 'TopoDialogService',
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700132
Steven Burrows1c2a9682017-07-14 16:52:46 +0100133 function (_$log_, _wss_, _tds_) {
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700134 $log = _$log_;
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700135 wss = _wss_;
136 tds = _tds_;
137
138 msgHandlers = {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100139 mapSelectorResponse: handleMapResponse,
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700140 };
141
142 return {
143 toggleMap: toggleMap,
144 currentMap: currentMap,
145 setMap: setMap,
146
147 openMapSelection: openMapSelection,
148 closeMapSelection: closeMapSelection,
149 start: start,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100150 stop: stop,
Simon Hunt1603c692017-08-10 19:53:35 -0700151
152 setLionBundle: setLionBundle,
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700153 };
154 }]);
155
156}());