blob: 1edcdff25b95dd6e8a4a0a1032890fd9c5b0c04a [file] [log] [blame]
Simon Hunte6f64612017-04-28 00:01:48 -07001/*
2 * Copyright 2017-present 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
Steven Burrowsc8468932017-03-17 16:13:41 +000018(function () {
Simon Hunte6f64612017-04-28 00:01:48 -070019 'use strict';
Steven Burrowsc8468932017-03-17 16:13:41 +000020
21 var instance;
22
23 // TODO: Commented k2b map and addToggles are not implement in Topo2 yet.
24
25 // key to button mapping data
26 var k2b = {
27 O: { id: 'topo2-summary-tog', gid: 'm_summary', isel: true},
28 I: { id: 'topo2-instance-tog', gid: 'm_uiAttached', isel: true },
29 // D: { id: 'details-tog', gid: 'm_details', isel: true },
30 // H: { id: 'hosts-tog', gid: 'm_endstation', isel: false },
31 // M: { id: 'offline-tog', gid: 'm_switch', isel: true },
32 P: { id: 'topo2-ports-tog', gid: 'm_ports', isel: true },
Steven Burrows9f7a2d72017-03-29 13:59:07 +010033 B: { id: 'topo2-bkgrnd-tog', gid: 'm_map', isel: true },
Steven Burrowsc8468932017-03-17 16:13:41 +000034
35 // Z: { id: 'oblique-tog', gid: 'm_oblique', isel: false },
36 // N: { id: 'filters-btn', gid: 'm_filters' },
37 L: { id: 'topo2-cycleLabels-btn', gid: 'm_cycleLabels' },
38 R: { id: 'topo2-resetZoom-btn', gid: 'm_resetZoom' },
39
40 E: { id: 'topo2-eqMaster-btn', gid: 'm_eqMaster' }
41 };
42
43 angular.module('ovTopo2')
44 .factory('Topo2ToolbarService', [
45 'FnService', 'ToolbarService', 'Topo2KeyCommandService',
46 function (fs, tbs, t2kcs) {
47
48 var Toolbar = function () {
49 instance = this;
Steven Burrowsc8468932017-03-17 16:13:41 +000050 };
51
52 Toolbar.prototype = {
53
54 className: 'topo2-toolbar',
55
56 init: function () {
Steven Burrows9053fdb2017-04-12 12:08:16 -070057 this.el = tbs.createToolbar(this.className);
Steven Burrowsc8468932017-03-17 16:13:41 +000058 this.initKeyData();
59 this.addFirstRow();
60 this.el.addRow();
61 this.addSecondRow();
62
Simon Hunt47f8fb72017-04-11 13:49:31 -070063 this.el.hide();
Steven Burrowsc8468932017-03-17 16:13:41 +000064 },
65 initKeyData: function () {
66 _.each(k2b, function(value, key) {
67 var data = t2kcs.getActionEntry(key);
68 if (data) {
69 value.cb = data[0]; // on-click callback
70 value.tt = data[1] + ' (' + key + ')'; // tooltip
71 }
72 });
73 },
74 getKey: function (key) {
75 return k2b[key];
76 },
77 keyListener: function (key) {
78 var v = this.getKey(key);
79
80 if (v && v.tog) {
81 v.tog.toggleNoCb();
82 }
83 },
84 addButton: function (key) {
85 var v = this.getKey(key);
86 v.btn = this.el.addButton(v.id, v.gid, v.cb, v.tt);
87 },
88 addToggle: function (key, suppressIfMobile) {
89 var v = this.getKey(key);
90 if (suppressIfMobile && fs.isMobile()) { return; }
91 v.tog = this.el.addToggle(v.id, v.gid, v.isel, v.cb, v.tt);
92 },
93
Simon Hunt47f8fb72017-04-11 13:49:31 -070094 toggle: function () {
95 this.el.toggle();
96 },
97
Steven Burrowsc8468932017-03-17 16:13:41 +000098 addFirstRow: function () {
99 this.addToggle('I');
100 this.addToggle('O');
101 // this.addToggle('D');
102 this.el.addSeparator();
103
104 // this.addToggle('H');
105 // this.addToggle('M');
106 this.addToggle('P', true);
107 this.addToggle('B');
108 },
109 addSecondRow: function () {
110 //addToggle('X');
111 // this.addToggle('Z');
112 // this.addButton('N');
113 this.addButton('L');
114 this.addButton('R');
115 this.el.addSeparator();
116 this.addButton('E');
117 },
118
119 destroy: function () {
120 // TODO: Should the tbs remove button id's in the destroyToolbar method?
121 // If you go topo2 -> topo -> topo2 there's a button id conflict
122 tbs.destroyToolbar(this.className);
123 }
124 };
125
126 return instance || new Toolbar();
127 }
128 ]);
Simon Hunte6f64612017-04-28 00:01:48 -0700129}());