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 () { |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 23 | 'use strict'; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 24 | |
| 25 | // injected references |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 26 | var $log, tbs, api; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 27 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 28 | // internal state |
| 29 | var toolbar, keyData; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 30 | |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 31 | // constants |
| 32 | var name = 'topo-tbar'; |
| 33 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 34 | // key to button mapping data |
| 35 | var k2b = { |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 36 | O: { id: 'summary-tog', gid: 'summary', isel: true}, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 37 | I: { id: 'instance-tog', gid: 'uiAttached', isel: true }, |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 38 | D: { id: 'details-tog', gid: 'details', isel: true }, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 39 | |
| 40 | H: { id: 'hosts-tog', gid: 'endstation', isel: false }, |
| 41 | M: { id: 'offline-tog', gid: 'switch', isel: true }, |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 42 | P: { id: 'ports-tog', gid: 'ports', isel: true }, |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 43 | B: { id: 'bkgrnd-tog', gid: 'map', isel: true }, |
| 44 | |
| 45 | //X: { id: 'nodelock-tog', gid: 'lock', isel: false }, |
| 46 | Z: { id: 'oblique-tog', gid: 'oblique', isel: false }, |
| 47 | L: { id: 'cycleLabels-btn', gid: 'cycleLabels' }, |
| 48 | R: { id: 'resetZoom-btn', gid: 'resetZoom' }, |
| 49 | |
Bri Prebilic Cole | 7c98051 | 2015-03-25 12:31:29 -0700 | [diff] [blame] | 50 | V: { id: 'relatedIntents-btn', gid: 'relatedIntents' }, |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 51 | leftArrow: { id: 'prevIntent-btn', gid: 'prevIntent' }, |
| 52 | rightArrow: { id: 'nextIntent-btn', gid: 'nextIntent' }, |
| 53 | W: { id: 'intentTraffic-btn', gid: 'intentTraffic' }, |
| 54 | A: { id: 'allTraffic-btn', gid: 'allTraffic' }, |
| 55 | F: { id: 'flows-btn', gid: 'flows' }, |
| 56 | |
| 57 | E: { id: 'eqMaster-btn', gid: 'eqMaster' } |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 58 | }; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 59 | |
| 60 | function init(_api_) { |
| 61 | api = _api_; |
| 62 | } |
| 63 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 64 | function initKeyData() { |
| 65 | keyData = d3.map(k2b); |
| 66 | keyData.forEach(function(key, value) { |
| 67 | var data = api.getActionEntry(key); |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame^] | 68 | value.cb = data[0]; // on-click callback |
| 69 | value.tt = data[1] + ' (' + key + ')'; // tooltip |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 70 | }); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 73 | function addButton(key) { |
| 74 | var v = keyData.get(key); |
| 75 | v.btn = toolbar.addButton(v.id, v.gid, v.cb, v.tt); |
| 76 | } |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 77 | function addToggle(key) { |
| 78 | var v = keyData.get(key); |
| 79 | 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] | 80 | } |
| 81 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 82 | function addFirstRow() { |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 83 | addToggle('I'); |
Simon Hunt | da2f3cc | 2015-03-19 15:11:57 -0700 | [diff] [blame] | 84 | addToggle('O'); |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 85 | addToggle('D'); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 86 | toolbar.addSeparator(); |
| 87 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 88 | addToggle('H'); |
| 89 | addToggle('M'); |
| 90 | addToggle('P'); |
| 91 | addToggle('B'); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 92 | } |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 93 | function addSecondRow() { |
Bri Prebilic Cole | 7c98051 | 2015-03-25 12:31:29 -0700 | [diff] [blame] | 94 | //addToggle('X'); |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 95 | addToggle('Z'); |
| 96 | addButton('L'); |
| 97 | addButton('R'); |
| 98 | } |
| 99 | function addThirdRow() { |
| 100 | addButton('V'); |
| 101 | addButton('leftArrow'); |
| 102 | addButton('rightArrow'); |
| 103 | addButton('W'); |
| 104 | addButton('A'); |
| 105 | addButton('F'); |
| 106 | toolbar.addSeparator(); |
| 107 | addButton('E'); |
| 108 | } |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 109 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 110 | function createToolbar() { |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 111 | initKeyData(); |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 112 | toolbar = tbs.createToolbar(name); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 113 | addFirstRow(); |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 114 | toolbar.addRow(); |
| 115 | addSecondRow(); |
| 116 | toolbar.addRow(); |
| 117 | addThirdRow(); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 118 | toolbar.show(); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 121 | function destroyToolbar() { |
| 122 | tbs.destroyToolbar(name); |
| 123 | } |
| 124 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 125 | // allows us to ensure the button states track key strokes |
| 126 | function keyListener(key) { |
| 127 | var v = keyData.get(key); |
| 128 | |
| 129 | if (v) { |
| 130 | // we have a valid button mapping |
| 131 | if (v.tog) { |
| 132 | // it's a toggle button |
| 133 | v.tog.toggleNoCb(); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame^] | 138 | function toggleToolbar() { |
| 139 | toolbar.toggle(); |
| 140 | } |
| 141 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 142 | angular.module('ovTopo') |
| 143 | .factory('TopoToolbarService', ['$log', 'ToolbarService', |
| 144 | |
| 145 | function (_$log_, _tbs_) { |
| 146 | $log = _$log_; |
| 147 | tbs = _tbs_; |
| 148 | |
| 149 | return { |
| 150 | init: init, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 151 | createToolbar: createToolbar, |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 152 | destroyToolbar: destroyToolbar, |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame^] | 153 | keyListener: keyListener, |
| 154 | toggleToolbar: toggleToolbar |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 155 | }; |
| 156 | }]); |
| 157 | }()); |