Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame^] | 1 | /* |
| 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 Force Module. |
| 19 | Visualization of the topology in an SVG layer, using a D3 Force Layout. |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // Injected |
| 26 | var $log, wss, t2ds; |
| 27 | |
| 28 | // Constants |
| 29 | var mapRequest = 'mapSelectorRequest'; |
| 30 | |
| 31 | // State |
| 32 | var order, maps, map, mapItems; |
| 33 | |
| 34 | var Dialog = function (options) { |
| 35 | |
| 36 | this.okHandlerCallback = options.okHandler; |
| 37 | this.closeHandlerCallback = options.closeHandler; |
| 38 | |
| 39 | wss.bindHandlers({ |
| 40 | mapSelectorResponse: this.handleMapResponse.bind(this) |
| 41 | }); |
| 42 | }; |
| 43 | |
| 44 | Dialog.prototype = { |
| 45 | handleMapResponse: function (data) { |
| 46 | $log.info('Got response', data); |
| 47 | order = data.order; |
| 48 | maps = data.maps; |
| 49 | |
| 50 | t2ds.openDialog() |
| 51 | .setTitle('Select Map') |
| 52 | .addContent(this.render.bind(this)()) |
| 53 | .addOk(this.okHandler.bind(this), 'OK') |
| 54 | .addCancel(this.closeHandler.bind(this), 'Close') |
| 55 | .bindKeys(); |
| 56 | }, |
| 57 | |
| 58 | open: function () { |
| 59 | wss.sendEvent(mapRequest); |
| 60 | }, |
| 61 | close: function () { |
| 62 | wss.unbindHandlers({ |
| 63 | mapSelectorResponse: this.handleMapResponse.bind(this) |
| 64 | }); |
| 65 | }, |
| 66 | |
| 67 | selectedMap: function () { |
| 68 | map = maps[this.options[this.selectedIndex].value]; |
| 69 | $log.info('Selected map', map); |
| 70 | }, |
| 71 | |
| 72 | okHandler: function () { |
| 73 | |
| 74 | var p = { |
| 75 | mapid: map.id, |
| 76 | mapscale: map.scale, |
| 77 | mapfilepath: map.filePath, |
| 78 | tint: 'off' |
| 79 | // tint: tintCheck.property('checked') ? 'on' : 'off' |
| 80 | }; |
| 81 | |
| 82 | if (this.okHandlerCallback) { |
| 83 | this.okHandlerCallback(p); |
| 84 | } |
| 85 | |
| 86 | this.close(); |
| 87 | }, |
| 88 | closeHandler: function () { |
| 89 | |
| 90 | if (this.closeHandlerCallback) { |
| 91 | this.closeHandlerCallback(); |
| 92 | } |
| 93 | |
| 94 | this.close(); |
| 95 | }, |
| 96 | |
| 97 | render: function () { |
| 98 | |
| 99 | var content = t2ds.createDiv('map-list'), |
| 100 | form = content.append('form'), |
| 101 | current = this.currentMap(); |
| 102 | |
| 103 | map = maps[current.mapid]; |
| 104 | mapItems = form.append('select').on('change', this.selectedMap); |
| 105 | |
| 106 | order.forEach(function (id) { |
| 107 | var m = maps[id]; |
| 108 | mapItems.append('option') |
| 109 | .attr('value', m.id) |
| 110 | .attr('selected', m.id === current.mapid ? true : null) |
| 111 | .text(m.description); |
| 112 | }); |
| 113 | |
| 114 | return content; |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | angular.module('ovTopo2') |
| 119 | .factory('Topo2MapDialog', [ |
| 120 | '$log', 'WebSocketService', 'Topo2DialogService', |
| 121 | function (_$log_, _wss_, _t2ds_) { |
| 122 | |
| 123 | $log = _$log_; |
| 124 | wss = _wss_; |
| 125 | t2ds = _t2ds_; |
| 126 | |
| 127 | return Dialog; |
| 128 | } |
| 129 | ]); |
| 130 | })(); |