blob: c86857e99b5b096c1d886263f3aa7fd64a861de7 [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 },
47 L: { id: 'cycleLabels-btn', gid: 'cycleLabels' },
48 R: { id: 'resetZoom-btn', gid: 'resetZoom' },
49
50 V: { id: 'allIntents-btn', gid: 'allIntents' },
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 Hunt09060142015-03-18 20:23:32 -070058 };
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070059
60 function init(_api_) {
61 api = _api_;
62 }
63
Simon Hunt09060142015-03-18 20:23:32 -070064 function initKeyData() {
65 keyData = d3.map(k2b);
66 keyData.forEach(function(key, value) {
67 var data = api.getActionEntry(key);
68 value.cb = data[0]; // on-click callback
69 value.tt = data[1]; // tooltip
70 });
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070071 }
72
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070073 function addButton(key) {
74 var v = keyData.get(key);
75 v.btn = toolbar.addButton(v.id, v.gid, v.cb, v.tt);
76 }
Simon Hunt09060142015-03-18 20:23:32 -070077 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 Cole4db8dce2015-03-18 13:57:24 -070080 }
81
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070082 function addFirstRow() {
Simon Hunt09060142015-03-18 20:23:32 -070083 addToggle('I');
Simon Huntda2f3cc2015-03-19 15:11:57 -070084 addToggle('O');
Simon Hunt09060142015-03-18 20:23:32 -070085 addToggle('D');
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070086 toolbar.addSeparator();
87
Simon Hunt09060142015-03-18 20:23:32 -070088 addToggle('H');
89 addToggle('M');
90 addToggle('P');
91 addToggle('B');
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070092 }
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -070093 function addSecondRow() {
94 addToggle('Z');
95 addButton('L');
96 addButton('R');
97 }
98 function addThirdRow() {
99 addButton('V');
100 addButton('leftArrow');
101 addButton('rightArrow');
102 addButton('W');
103 addButton('A');
104 addButton('F');
105 toolbar.addSeparator();
106 addButton('E');
107 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700108
Bri Prebilic Cole04b41402015-03-18 17:25:34 -0700109 function createToolbar() {
Simon Hunt09060142015-03-18 20:23:32 -0700110 initKeyData();
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700111 toolbar = tbs.createToolbar(name);
Bri Prebilic Cole04b41402015-03-18 17:25:34 -0700112 addFirstRow();
Bri Prebilic Cole812f6c02015-03-24 17:10:33 -0700113 toolbar.addRow();
114 addSecondRow();
115 toolbar.addRow();
116 addThirdRow();
Bri Prebilic Cole04b41402015-03-18 17:25:34 -0700117 toolbar.show();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700118 }
119
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700120 function destroyToolbar() {
121 tbs.destroyToolbar(name);
122 }
123
Simon Hunt09060142015-03-18 20:23:32 -0700124 // allows us to ensure the button states track key strokes
125 function keyListener(key) {
126 var v = keyData.get(key);
127
128 if (v) {
129 // we have a valid button mapping
130 if (v.tog) {
131 // it's a toggle button
132 v.tog.toggleNoCb();
133 }
134 }
135 }
136
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700137 angular.module('ovTopo')
138 .factory('TopoToolbarService', ['$log', 'ToolbarService',
139
140 function (_$log_, _tbs_) {
141 $log = _$log_;
142 tbs = _tbs_;
143
144 return {
145 init: init,
Simon Hunt09060142015-03-18 20:23:32 -0700146 createToolbar: createToolbar,
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700147 destroyToolbar: destroyToolbar,
Simon Hunt09060142015-03-18 20:23:32 -0700148 keyListener: keyListener
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700149 };
150 }]);
151}());