Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 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 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 Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 26 | var $log, wss, tds, delegate; |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 27 | |
| 28 | // constants |
| 29 | var mapRequest = 'mapSelectorRequest'; |
| 30 | |
| 31 | // internal state |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 32 | var order, maps, map, mapItems, msgHandlers; |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 33 | |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 34 | // function to be replaced by the localization bundle function |
| 35 | var topoLion = function (x) { |
| 36 | return '#tmap#' + x + '#'; |
| 37 | }; |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 38 | |
| 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 Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 63 | mapfilepath: map.filePath, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 64 | tint: 'off', |
Simon Hunt | f29d8e6 | 2016-06-20 11:09:25 -0700 | [diff] [blame] | 65 | // tint: tintCheck.property('checked') ? 'on' : 'off' |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 66 | }; |
| 67 | setMap(p); |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 68 | // $log.debug('Dialog OK button clicked'); |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | function dClose() { |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 72 | // $log.debug('Dialog Close button clicked (or Esc pressed)'); |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 73 | } |
| 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 Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 84 | |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 85 | 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 Hunt | f29d8e6 | 2016-06-20 11:09:25 -0700 | [diff] [blame] | 94 | |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 95 | 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 Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 103 | .setTitle(topoLion('title_select_map')) |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 104 | .addContent(createListContent()) |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 105 | .addOk(dOk, topoLion('ok')) |
| 106 | .addCancel(dClose, topoLion('close')) |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 107 | .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 Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 122 | // invoked after the localization bundle has been received from the server |
| 123 | function setLionBundle(bundle) { |
| 124 | topoLion = bundle; |
| 125 | } |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 126 | // === ----------------------------------------------------- |
| 127 | // === MODULE DEFINITION === |
| 128 | |
| 129 | angular.module('ovTopo') |
| 130 | .factory('TopoMapService', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 131 | ['$log', 'WebSocketService', 'TopoDialogService', |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 132 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 133 | function (_$log_, _wss_, _tds_) { |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 134 | $log = _$log_; |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 135 | wss = _wss_; |
| 136 | tds = _tds_; |
| 137 | |
| 138 | msgHandlers = { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 139 | mapSelectorResponse: handleMapResponse, |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | return { |
| 143 | toggleMap: toggleMap, |
| 144 | currentMap: currentMap, |
| 145 | setMap: setMap, |
| 146 | |
| 147 | openMapSelection: openMapSelection, |
| 148 | closeMapSelection: closeMapSelection, |
| 149 | start: start, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 150 | stop: stop, |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 151 | |
| 152 | setLionBundle: setLionBundle, |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 153 | }; |
| 154 | }]); |
| 155 | |
| 156 | }()); |