blob: 192c18dbea4952313f49f2cf6539cf13d876f5ae [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 () {
23
24 // injected references
Simon Hunt09060142015-03-18 20:23:32 -070025 var $log, tbs, api;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070026
Simon Hunt09060142015-03-18 20:23:32 -070027 // internal state
28 var toolbar, keyData;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070029
Bri Prebilic Coled6219052015-03-19 14:34:02 -070030 // constants
31 var name = 'topo-tbar';
32
Simon Hunt09060142015-03-18 20:23:32 -070033 // key to button mapping data
34 var k2b = {
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070035 O: { id: 'summary-tog', gid: 'summary', isel: true},
Simon Hunt09060142015-03-18 20:23:32 -070036 I: { id: 'instance-tog', gid: 'uiAttached', isel: true },
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070037 D: { id: 'details-tog', gid: 'details', isel: true },
Simon Hunt09060142015-03-18 20:23:32 -070038
39 H: { id: 'hosts-tog', gid: 'endstation', isel: false },
40 M: { id: 'offline-tog', gid: 'switch', isel: true },
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070041 P: { id: 'ports-tog', gid: 'ports', isel: true },
42 B: { id: 'bkgrnd-tog', gid: 'map', isel: true }
Simon Hunt09060142015-03-18 20:23:32 -070043 };
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070044
45 function init(_api_) {
46 api = _api_;
47 }
48
Simon Hunt09060142015-03-18 20:23:32 -070049 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 Cole4db8dce2015-03-18 13:57:24 -070056 }
57
Simon Hunt09060142015-03-18 20:23:32 -070058 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 Cole4db8dce2015-03-18 13:57:24 -070061 }
62
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070063 function addFirstRow() {
Simon Hunt09060142015-03-18 20:23:32 -070064 addToggle('I');
Simon Huntda2f3cc2015-03-19 15:11:57 -070065 addToggle('O');
Simon Hunt09060142015-03-18 20:23:32 -070066 addToggle('D');
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070067 toolbar.addSeparator();
68
Simon Hunt09060142015-03-18 20:23:32 -070069 addToggle('H');
70 addToggle('M');
71 addToggle('P');
72 addToggle('B');
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070073 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070074
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070075 function createToolbar() {
Simon Hunt09060142015-03-18 20:23:32 -070076 initKeyData();
Bri Prebilic Coled6219052015-03-19 14:34:02 -070077 toolbar = tbs.createToolbar(name);
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070078 addFirstRow();
79 toolbar.show();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070080 }
81
Bri Prebilic Coled6219052015-03-19 14:34:02 -070082 function destroyToolbar() {
83 tbs.destroyToolbar(name);
84 }
85
Simon Hunt09060142015-03-18 20:23:32 -070086 // 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 Cole4db8dce2015-03-18 13:57:24 -070099 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 Hunt09060142015-03-18 20:23:32 -0700108 createToolbar: createToolbar,
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700109 destroyToolbar: destroyToolbar,
Simon Hunt09060142015-03-18 20:23:32 -0700110 keyListener: keyListener
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700111 };
112 }]);
113}());