blob: da08d5fcab3f84683f71e2da789122fec3138cd0 [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
Simon Hunt09060142015-03-18 20:23:32 -070030 // key to button mapping data
31 var k2b = {
32 O: { id: 'summary-tog', gid: 'unknown', isel: true},
33 I: { id: 'instance-tog', gid: 'uiAttached', isel: true },
34 D: { id: 'details-tog', gid: 'unknown', isel: true },
35
36 H: { id: 'hosts-tog', gid: 'endstation', isel: false },
37 M: { id: 'offline-tog', gid: 'switch', isel: true },
38 P: { id: 'ports-tog', gid: 'unknown', isel: true },
39 B: { id: 'bkgrnd-tog', gid: 'unknown', isel: true }
40 };
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070041
42 function init(_api_) {
43 api = _api_;
44 }
45
Simon Hunt09060142015-03-18 20:23:32 -070046 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 Cole4db8dce2015-03-18 13:57:24 -070053 }
54
Simon Hunt09060142015-03-18 20:23:32 -070055 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 Cole4db8dce2015-03-18 13:57:24 -070058 }
59
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070060 function addFirstRow() {
Simon Hunt09060142015-03-18 20:23:32 -070061 addToggle('O');
62 addToggle('I');
63 addToggle('D');
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070064 toolbar.addSeparator();
65
Simon Hunt09060142015-03-18 20:23:32 -070066 addToggle('H');
67 addToggle('M');
68 addToggle('P');
69 addToggle('B');
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070070 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070071
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070072 function createToolbar() {
Simon Hunt09060142015-03-18 20:23:32 -070073 initKeyData();
Bri Prebilic Cole04b41402015-03-18 17:25:34 -070074 toolbar = tbs.createToolbar('topo-tbar');
75 addFirstRow();
76 toolbar.show();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070077 }
78
Simon Hunt09060142015-03-18 20:23:32 -070079 // 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 Cole4db8dce2015-03-18 13:57:24 -070092 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 Hunt09060142015-03-18 20:23:32 -0700101 createToolbar: createToolbar,
102 keyListener: keyListener
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700103 };
104 }]);
105}());