Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 1 | /* |
| 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. |
| 19 | Defines functions for manipulating the toolbar. |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | |
| 24 | // injected references |
| 25 | var $log, tbs; |
| 26 | |
| 27 | var api, toolbar; |
| 28 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame^] | 29 | // buttons |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 30 | var togSummary, togInstances, togDetails, |
| 31 | togHosts, togOffline, togPorts, togBackground; |
| 32 | |
| 33 | function init(_api_) { |
| 34 | api = _api_; |
| 35 | } |
| 36 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame^] | 37 | // TODO: fix toggle and radio sets to be selected based on the current state |
| 38 | // current bug: first toggle button, then toggle with key, toggle button doesn't update appearance |
| 39 | |
| 40 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 41 | function getActions() { |
| 42 | togSummary = api.getActionEntry('O'); |
| 43 | togInstances = api.getActionEntry('I'); |
| 44 | togDetails = api.getActionEntry('D'); |
| 45 | |
| 46 | togHosts = api.getActionEntry('H'); |
| 47 | togOffline = api.getActionEntry('M'); |
| 48 | togPorts = api.getActionEntry('P'); |
| 49 | togBackground = api.getActionEntry('B'); |
| 50 | } |
| 51 | |
| 52 | function entryCallback(entry) { |
| 53 | return entry[0]; |
| 54 | } |
| 55 | |
| 56 | function entryToolTip(entry) { |
| 57 | return entry[1]; |
| 58 | } |
| 59 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame^] | 60 | function addFirstRow() { |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 61 | toolbar.addToggle('summary-tog', 'unknown', true, |
| 62 | entryCallback(togSummary), entryToolTip(togSummary)); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame^] | 63 | toolbar.addToggle('instance-tog', 'uiAttached', true, |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 64 | entryCallback(togInstances), entryToolTip(togInstances)); |
| 65 | toolbar.addToggle('details-tog', 'unknown', true, |
| 66 | entryCallback(togDetails), entryToolTip(togDetails)); |
| 67 | toolbar.addSeparator(); |
| 68 | |
| 69 | toolbar.addToggle('hosts-tog', 'endstation', false, |
| 70 | entryCallback(togHosts), entryToolTip(togHosts)); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame^] | 71 | toolbar.addToggle('offline-tog', 'switch', true, |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 72 | entryCallback(togOffline), entryToolTip(togOffline)); |
| 73 | toolbar.addToggle('ports-tog', 'unknown', true, |
| 74 | entryCallback(togPorts), entryToolTip(togPorts)); |
| 75 | toolbar.addToggle('bkgrnd-tog', 'unknown', true, |
| 76 | entryCallback(togBackground), entryToolTip(togBackground)); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame^] | 77 | } |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 78 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame^] | 79 | function createToolbar() { |
| 80 | getActions(); |
| 81 | toolbar = tbs.createToolbar('topo-tbar'); |
| 82 | addFirstRow(); |
| 83 | toolbar.show(); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | angular.module('ovTopo') |
| 87 | .factory('TopoToolbarService', ['$log', 'ToolbarService', |
| 88 | |
| 89 | function (_$log_, _tbs_) { |
| 90 | $log = _$log_; |
| 91 | tbs = _tbs_; |
| 92 | |
| 93 | return { |
| 94 | init: init, |
| 95 | createToolbar: createToolbar |
| 96 | }; |
| 97 | }]); |
| 98 | }()); |