blob: eb7c0069fd1700cc65719d6b95f402ab0a50f21e [file] [log] [blame]
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -07001/*
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 Hunt09060142015-03-18 20:23:32 -070019 Functions for creating and interacting with the toolbar.
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070020 */
21
22(function () {
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070023 'use strict';
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070024
25 // injected references
Simon Hunt09060142015-03-18 20:23:32 -070026 var $log, tbs, api;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070027
Simon Hunt09060142015-03-18 20:23:32 -070028 // internal state
29 var toolbar, keyData;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070030
Bri Prebilic Coled6219052015-03-19 14:34:02 -070031 // constants
32 var name = 'topo-tbar';
33
Simon Hunt09060142015-03-18 20:23:32 -070034 // key to button mapping data
35 var k2b = {
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070036 O: { id: 'summary-tog', gid: 'summary', isel: true},
Simon Hunt09060142015-03-18 20:23:32 -070037 I: { id: 'instance-tog', gid: 'uiAttached', isel: true },
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070038 D: { id: 'details-tog', gid: 'details', isel: true },
Simon Hunt09060142015-03-18 20:23:32 -070039
40 H: { id: 'hosts-tog', gid: 'endstation', isel: false },
41 M: { id: 'offline-tog', gid: 'switch', isel: true },
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070042 P: { id: 'ports-tog', gid: 'ports', isel: true },
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070043 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 },
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070047 N: { id: 'filters-btn', gid: 'filters' },
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070048 L: { id: 'cycleLabels-btn', gid: 'cycleLabels' },
49 R: { id: 'resetZoom-btn', gid: 'resetZoom' },
50
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070051 V: { id: 'relatedIntents-btn', gid: 'relatedIntents' },
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070052 leftArrow: { id: 'prevIntent-btn', gid: 'prevIntent' },
53 rightArrow: { id: 'nextIntent-btn', gid: 'nextIntent' },
54 W: { id: 'intentTraffic-btn', gid: 'intentTraffic' },
55 A: { id: 'allTraffic-btn', gid: 'allTraffic' },
56 F: { id: 'flows-btn', gid: 'flows' },
57
58 E: { id: 'eqMaster-btn', gid: 'eqMaster' }
Simon Hunt09060142015-03-18 20:23:32 -070059 };
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070060
61 function init(_api_) {
62 api = _api_;
63 }
64
Simon Hunt09060142015-03-18 20:23:32 -070065 function initKeyData() {
66 keyData = d3.map(k2b);
67 keyData.forEach(function(key, value) {
68 var data = api.getActionEntry(key);
Simon Hunt90dcc3e2015-03-25 15:01:27 -070069 value.cb = data[0]; // on-click callback
70 value.tt = data[1] + ' (' + key + ')'; // tooltip
Simon Hunt09060142015-03-18 20:23:32 -070071 });
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070072 }
73
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070074 function addButton(key) {
75 var v = keyData.get(key);
76 v.btn = toolbar.addButton(v.id, v.gid, v.cb, v.tt);
77 }
Simon Hunt09060142015-03-18 20:23:32 -070078 function addToggle(key) {
79 var v = keyData.get(key);
80 v.tog = toolbar.addToggle(v.id, v.gid, v.isel, v.cb, v.tt);
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070081 }
82
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070083 function addFirstRow() {
Simon Hunt09060142015-03-18 20:23:32 -070084 addToggle('I');
Simon Huntda2f3cc2015-03-19 15:11:57 -070085 addToggle('O');
Simon Hunt09060142015-03-18 20:23:32 -070086 addToggle('D');
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070087 toolbar.addSeparator();
88
Simon Hunt09060142015-03-18 20:23:32 -070089 addToggle('H');
90 addToggle('M');
91 addToggle('P');
92 addToggle('B');
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070093 }
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070094 function addSecondRow() {
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070095 //addToggle('X');
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070096 addToggle('Z');
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070097 addButton('N');
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070098 addButton('L');
99 addButton('R');
100 }
101 function addThirdRow() {
102 addButton('V');
103 addButton('leftArrow');
104 addButton('rightArrow');
105 addButton('W');
106 addButton('A');
107 addButton('F');
108 toolbar.addSeparator();
109 addButton('E');
110 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700111
Bri Prebilic Cole04b41402015-03-18 17:25:34 -0700112 function createToolbar() {
Simon Hunt09060142015-03-18 20:23:32 -0700113 initKeyData();
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700114 toolbar = tbs.createToolbar(name);
Bri Prebilic Cole04b41402015-03-18 17:25:34 -0700115 addFirstRow();
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -0700116 toolbar.addRow();
117 addSecondRow();
118 toolbar.addRow();
119 addThirdRow();
Bri Prebilic Cole04b41402015-03-18 17:25:34 -0700120 toolbar.show();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700121 }
122
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700123 function destroyToolbar() {
124 tbs.destroyToolbar(name);
125 }
126
Simon Hunt09060142015-03-18 20:23:32 -0700127 // allows us to ensure the button states track key strokes
128 function keyListener(key) {
129 var v = keyData.get(key);
130
131 if (v) {
132 // we have a valid button mapping
133 if (v.tog) {
134 // it's a toggle button
135 v.tog.toggleNoCb();
136 }
137 }
138 }
139
Simon Hunt90dcc3e2015-03-25 15:01:27 -0700140 function toggleToolbar() {
141 toolbar.toggle();
142 }
143
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700144 angular.module('ovTopo')
145 .factory('TopoToolbarService', ['$log', 'ToolbarService',
146
147 function (_$log_, _tbs_) {
148 $log = _$log_;
149 tbs = _tbs_;
150
151 return {
152 init: init,
Simon Hunt09060142015-03-18 20:23:32 -0700153 createToolbar: createToolbar,
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700154 destroyToolbar: destroyToolbar,
Simon Hunt90dcc3e2015-03-25 15:01:27 -0700155 keyListener: keyListener,
156 toggleToolbar: toggleToolbar
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700157 };
158 }]);
159}());