Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 Toolbar Module. |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 19 | Functions for creating and interacting with the toolbar. |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | |
| 24 | // injected references |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 25 | var $log, tbs, api; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 26 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 27 | // internal state |
| 28 | var toolbar, keyData; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 29 | |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame^] | 30 | // constants |
| 31 | var name = 'topo-tbar'; |
| 32 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 33 | // key to button mapping data |
| 34 | var k2b = { |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 35 | O: { id: 'summary-tog', gid: 'summary', isel: true}, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 36 | I: { id: 'instance-tog', gid: 'uiAttached', isel: true }, |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 37 | D: { id: 'details-tog', gid: 'details', isel: true }, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 38 | |
| 39 | H: { id: 'hosts-tog', gid: 'endstation', isel: false }, |
| 40 | M: { id: 'offline-tog', gid: 'switch', isel: true }, |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 41 | P: { id: 'ports-tog', gid: 'ports', isel: true }, |
| 42 | B: { id: 'bkgrnd-tog', gid: 'map', isel: true } |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 43 | }; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 44 | |
| 45 | function init(_api_) { |
| 46 | api = _api_; |
| 47 | } |
| 48 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 49 | function initKeyData() { |
| 50 | keyData = d3.map(k2b); |
| 51 | keyData.forEach(function(key, value) { |
| 52 | var data = api.getActionEntry(key); |
| 53 | value.cb = data[0]; // on-click callback |
| 54 | value.tt = data[1]; // tooltip |
| 55 | }); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 58 | function addToggle(key) { |
| 59 | var v = keyData.get(key); |
| 60 | v.tog = toolbar.addToggle(v.id, v.gid, v.isel, v.cb, v.tt); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 63 | function addFirstRow() { |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 64 | addToggle('O'); |
| 65 | addToggle('I'); |
| 66 | addToggle('D'); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 67 | toolbar.addSeparator(); |
| 68 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 69 | addToggle('H'); |
| 70 | addToggle('M'); |
| 71 | addToggle('P'); |
| 72 | addToggle('B'); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 73 | } |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 74 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 75 | function createToolbar() { |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 76 | initKeyData(); |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame^] | 77 | toolbar = tbs.createToolbar(name); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 78 | addFirstRow(); |
| 79 | toolbar.show(); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame^] | 82 | function destroyToolbar() { |
| 83 | tbs.destroyToolbar(name); |
| 84 | } |
| 85 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 86 | // allows us to ensure the button states track key strokes |
| 87 | function keyListener(key) { |
| 88 | var v = keyData.get(key); |
| 89 | |
| 90 | if (v) { |
| 91 | // we have a valid button mapping |
| 92 | if (v.tog) { |
| 93 | // it's a toggle button |
| 94 | v.tog.toggleNoCb(); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 99 | angular.module('ovTopo') |
| 100 | .factory('TopoToolbarService', ['$log', 'ToolbarService', |
| 101 | |
| 102 | function (_$log_, _tbs_) { |
| 103 | $log = _$log_; |
| 104 | tbs = _tbs_; |
| 105 | |
| 106 | return { |
| 107 | init: init, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 108 | createToolbar: createToolbar, |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame^] | 109 | destroyToolbar: destroyToolbar, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 110 | keyListener: keyListener |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 111 | }; |
| 112 | }]); |
| 113 | }()); |