blob: ae1cc90c76e58727a8607ff9ac47d5a7048397c9 [file] [log] [blame]
Simon Hunte6f64612017-04-28 00:01:48 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Simon Hunte6f64612017-04-28 00:01:48 -07003 *
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 = {
Steven Burrows1c2a9682017-07-14 16:52:46 +010027 O: { id: 'topo2-summary-tog', gid: 'm_summary', isel: true },
Steven Burrowsc8468932017-03-17 16:13:41 +000028 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
Steven Burrows1c2a9682017-07-14 16:52:46 +010040 E: { id: 'topo2-eqMaster-btn', gid: 'm_eqMaster' },
Steven Burrowsc8468932017-03-17 16:13:41 +000041 };
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 () {
Steven Burrows1c2a9682017-07-14 16:52:46 +010066 _.each(k2b, function (value, key) {
Steven Burrowsc8468932017-03-17 16:13:41 +000067 var data = t2kcs.getActionEntry(key);
68 if (data) {
Steven Burrows1c2a9682017-07-14 16:52:46 +010069 // on-click callback
70 value.cb = data[0];
71 // tooltip
72 value.tt = data[1] + ' (' + key + ')';
Steven Burrowsc8468932017-03-17 16:13:41 +000073 }
74 });
75 },
76 getKey: function (key) {
77 return k2b[key];
78 },
79 keyListener: function (key) {
80 var v = this.getKey(key);
81
82 if (v && v.tog) {
83 v.tog.toggleNoCb();
84 }
85 },
86 addButton: function (key) {
Steven Burrows1c2a9682017-07-14 16:52:46 +010087 var v = this.getKey(key);
Steven Burrowsc8468932017-03-17 16:13:41 +000088 v.btn = this.el.addButton(v.id, v.gid, v.cb, v.tt);
89 },
90 addToggle: function (key, suppressIfMobile) {
Steven Burrows1c2a9682017-07-14 16:52:46 +010091 var v = this.getKey(key);
Steven Burrowsc8468932017-03-17 16:13:41 +000092 if (suppressIfMobile && fs.isMobile()) { return; }
93 v.tog = this.el.addToggle(v.id, v.gid, v.isel, v.cb, v.tt);
94 },
95
Simon Hunt47f8fb72017-04-11 13:49:31 -070096 toggle: function () {
97 this.el.toggle();
98 },
99
Steven Burrowsc8468932017-03-17 16:13:41 +0000100 addFirstRow: function () {
101 this.addToggle('I');
102 this.addToggle('O');
103 // this.addToggle('D');
104 this.el.addSeparator();
105
106 // this.addToggle('H');
107 // this.addToggle('M');
108 this.addToggle('P', true);
109 this.addToggle('B');
110 },
111 addSecondRow: function () {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100112 // addToggle('X');
Steven Burrowsc8468932017-03-17 16:13:41 +0000113 // this.addToggle('Z');
114 // this.addButton('N');
115 this.addButton('L');
116 this.addButton('R');
117 this.el.addSeparator();
118 this.addButton('E');
119 },
120
121 destroy: function () {
122 // TODO: Should the tbs remove button id's in the destroyToolbar method?
123 // If you go topo2 -> topo -> topo2 there's a button id conflict
124 tbs.destroyToolbar(this.className);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100125 },
Steven Burrowsc8468932017-03-17 16:13:41 +0000126 };
127
128 return instance || new Toolbar();
Steven Burrows1c2a9682017-07-14 16:52:46 +0100129 },
Steven Burrowsc8468932017-03-17 16:13:41 +0000130 ]);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100131}());