Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 18 | (function () { |
Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 19 | 'use strict'; |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 20 | |
| 21 | var instance; |
| 22 | |
| 23 | // TODO: Commented k2b map and addToggles are not implement in Topo2 yet. |
| 24 | |
| 25 | // key to button mapping data |
| 26 | var k2b = { |
| 27 | O: { id: 'topo2-summary-tog', gid: 'm_summary', isel: true}, |
| 28 | I: { id: 'topo2-instance-tog', gid: 'm_uiAttached', isel: true }, |
| 29 | // D: { id: 'details-tog', gid: 'm_details', isel: true }, |
| 30 | // H: { id: 'hosts-tog', gid: 'm_endstation', isel: false }, |
| 31 | // M: { id: 'offline-tog', gid: 'm_switch', isel: true }, |
| 32 | P: { id: 'topo2-ports-tog', gid: 'm_ports', isel: true }, |
Steven Burrows | 9f7a2d7 | 2017-03-29 13:59:07 +0100 | [diff] [blame] | 33 | B: { id: 'topo2-bkgrnd-tog', gid: 'm_map', isel: true }, |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 34 | |
| 35 | // Z: { id: 'oblique-tog', gid: 'm_oblique', isel: false }, |
| 36 | // N: { id: 'filters-btn', gid: 'm_filters' }, |
| 37 | L: { id: 'topo2-cycleLabels-btn', gid: 'm_cycleLabels' }, |
| 38 | R: { id: 'topo2-resetZoom-btn', gid: 'm_resetZoom' }, |
| 39 | |
| 40 | E: { id: 'topo2-eqMaster-btn', gid: 'm_eqMaster' } |
| 41 | }; |
| 42 | |
| 43 | angular.module('ovTopo2') |
| 44 | .factory('Topo2ToolbarService', [ |
| 45 | 'FnService', 'ToolbarService', 'Topo2KeyCommandService', |
| 46 | function (fs, tbs, t2kcs) { |
| 47 | |
| 48 | var Toolbar = function () { |
| 49 | instance = this; |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | Toolbar.prototype = { |
| 53 | |
| 54 | className: 'topo2-toolbar', |
| 55 | |
| 56 | init: function () { |
Steven Burrows | 9053fdb | 2017-04-12 12:08:16 -0700 | [diff] [blame] | 57 | this.el = tbs.createToolbar(this.className); |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 58 | this.initKeyData(); |
| 59 | this.addFirstRow(); |
| 60 | this.el.addRow(); |
| 61 | this.addSecondRow(); |
| 62 | |
Simon Hunt | 47f8fb7 | 2017-04-11 13:49:31 -0700 | [diff] [blame] | 63 | this.el.hide(); |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 64 | }, |
| 65 | initKeyData: function () { |
| 66 | _.each(k2b, function(value, key) { |
| 67 | var data = t2kcs.getActionEntry(key); |
| 68 | if (data) { |
| 69 | value.cb = data[0]; // on-click callback |
| 70 | value.tt = data[1] + ' (' + key + ')'; // tooltip |
| 71 | } |
| 72 | }); |
| 73 | }, |
| 74 | getKey: function (key) { |
| 75 | return k2b[key]; |
| 76 | }, |
| 77 | keyListener: function (key) { |
| 78 | var v = this.getKey(key); |
| 79 | |
| 80 | if (v && v.tog) { |
| 81 | v.tog.toggleNoCb(); |
| 82 | } |
| 83 | }, |
| 84 | addButton: function (key) { |
| 85 | var v = this.getKey(key); |
| 86 | v.btn = this.el.addButton(v.id, v.gid, v.cb, v.tt); |
| 87 | }, |
| 88 | addToggle: function (key, suppressIfMobile) { |
| 89 | var v = this.getKey(key); |
| 90 | if (suppressIfMobile && fs.isMobile()) { return; } |
| 91 | v.tog = this.el.addToggle(v.id, v.gid, v.isel, v.cb, v.tt); |
| 92 | }, |
| 93 | |
Simon Hunt | 47f8fb7 | 2017-04-11 13:49:31 -0700 | [diff] [blame] | 94 | toggle: function () { |
| 95 | this.el.toggle(); |
| 96 | }, |
| 97 | |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 98 | addFirstRow: function () { |
| 99 | this.addToggle('I'); |
| 100 | this.addToggle('O'); |
| 101 | // this.addToggle('D'); |
| 102 | this.el.addSeparator(); |
| 103 | |
| 104 | // this.addToggle('H'); |
| 105 | // this.addToggle('M'); |
| 106 | this.addToggle('P', true); |
| 107 | this.addToggle('B'); |
| 108 | }, |
| 109 | addSecondRow: function () { |
| 110 | //addToggle('X'); |
| 111 | // this.addToggle('Z'); |
| 112 | // this.addButton('N'); |
| 113 | this.addButton('L'); |
| 114 | this.addButton('R'); |
| 115 | this.el.addSeparator(); |
| 116 | this.addButton('E'); |
| 117 | }, |
| 118 | |
| 119 | destroy: function () { |
| 120 | // TODO: Should the tbs remove button id's in the destroyToolbar method? |
| 121 | // If you go topo2 -> topo -> topo2 there's a button id conflict |
| 122 | tbs.destroyToolbar(this.className); |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | return instance || new Toolbar(); |
| 127 | } |
| 128 | ]); |
Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 129 | }()); |