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