Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 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 Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 19 | Functions for creating and interacting with the toolbar. |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | (function () { |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 23 | 'use strict'; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 24 | |
| 25 | // injected references |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 26 | var $log, fs, tbs, ps, tov, tds, api; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 27 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 28 | // API: |
| 29 | // getActionEntry |
| 30 | // setUpKeys |
| 31 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 32 | // internal state |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 33 | var toolbar, keyData, cachedState, thirdRow, ovRset, ovIndex; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 34 | |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 35 | // constants |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 36 | var name = 'topo-tbar', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 37 | cooktag = 'topo_prefs', |
| 38 | soa = 'switchOverlayActions: ', |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 39 | selOver = 'Select overlay here ⇧', |
| 40 | defaultOverlay = 'traffic'; |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 41 | |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 42 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 43 | // key to button mapping data |
| 44 | var k2b = { |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 45 | O: { id: 'summary-tog', gid: 'summary', isel: true}, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 46 | I: { id: 'instance-tog', gid: 'uiAttached', isel: true }, |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 47 | D: { id: 'details-tog', gid: 'details', isel: true }, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 48 | H: { id: 'hosts-tog', gid: 'endstation', isel: false }, |
| 49 | M: { id: 'offline-tog', gid: 'switch', isel: true }, |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 50 | P: { id: 'ports-tog', gid: 'ports', isel: true }, |
Simon Hunt | d0fe66c | 2015-06-10 10:16:36 -0700 | [diff] [blame] | 51 | B: { id: 'bkgrnd-tog', gid: 'map', isel: false }, |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 52 | G: { id: 'bkgrnd-sel', gid: 'filters' }, |
Simon Hunt | 2052e5d | 2015-04-13 17:40:44 -0700 | [diff] [blame] | 53 | S: { id: 'sprite-tog', gid: 'cloud', isel: false }, |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 54 | |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 55 | // TODO: add reset-node-locations button to toolbar |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 56 | //X: { id: 'nodelock-tog', gid: 'lock', isel: false }, |
| 57 | Z: { id: 'oblique-tog', gid: 'oblique', isel: false }, |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 58 | N: { id: 'filters-btn', gid: 'filters' }, |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 59 | L: { id: 'cycleLabels-btn', gid: 'cycleLabels' }, |
| 60 | R: { id: 'resetZoom-btn', gid: 'resetZoom' }, |
| 61 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 62 | E: { id: 'eqMaster-btn', gid: 'eqMaster' } |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 63 | }; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 64 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 65 | var prohibited = [ |
| 66 | 'T', 'backSlash', 'slash', |
| 67 | 'X' // needed until we re-instate X above. |
| 68 | ]; |
| 69 | prohibited = prohibited.concat(d3.map(k2b).keys()); |
| 70 | |
| 71 | |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 72 | // initial toggle state: default settings and tag to key mapping |
| 73 | var defaultPrefsState = { |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 74 | insts: 1, |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 75 | summary: 1, |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 76 | detail: 1, |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 77 | hosts: 0, |
| 78 | offdev: 1, |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 79 | dlbls: 0, |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 80 | porthl: 1, |
Simon Hunt | d0fe66c | 2015-06-10 10:16:36 -0700 | [diff] [blame] | 81 | bg: 0, |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 82 | spr: 0, |
Simon Hunt | d0fe66c | 2015-06-10 10:16:36 -0700 | [diff] [blame] | 83 | toolbar: 0 |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 84 | }, |
| 85 | prefsMap = { |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 86 | summary: 'O', |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 87 | insts: 'I', |
| 88 | detail: 'D', |
| 89 | hosts: 'H', |
| 90 | offdev: 'M', |
| 91 | porthl: 'P', |
| 92 | bg: 'B', |
| 93 | spr: 'S' |
| 94 | // NOTE: toolbar state is handled separately |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 97 | function init(_api_) { |
| 98 | api = _api_; |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 99 | // retrieve initial toggle button settings from user prefs |
| 100 | setInitToggleState(); |
| 101 | } |
| 102 | |
| 103 | function topoDefPrefs() { |
| 104 | return angular.extend({}, defaultPrefsState); |
| 105 | } |
| 106 | |
| 107 | function setInitToggleState() { |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 108 | cachedState = ps.asNumbers(ps.getPrefs(cooktag, defaultPrefsState)); |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 109 | $log.debug('TOOLBAR---- read prefs state:', cachedState); |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 110 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 111 | if (!cachedState) { |
| 112 | cachedState = topoDefPrefs(); |
| 113 | ps.setPrefs(cooktag, cachedState); |
| 114 | $log.debug('TOOLBAR---- Set default prefs state:', cachedState); |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | angular.forEach(prefsMap, function (v, k) { |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 118 | var cfg = k2b[v]; |
| 119 | cfg && (cfg.isel = !!cachedState[k]); |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 120 | }); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 123 | function initKeyData() { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 124 | // TODO: use angular forEach instead of d3.map |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 125 | keyData = d3.map(k2b); |
| 126 | keyData.forEach(function(key, value) { |
| 127 | var data = api.getActionEntry(key); |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame] | 128 | value.cb = data[0]; // on-click callback |
| 129 | value.tt = data[1] + ' (' + key + ')'; // tooltip |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 130 | }); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 133 | function addButton(key) { |
| 134 | var v = keyData.get(key); |
| 135 | v.btn = toolbar.addButton(v.id, v.gid, v.cb, v.tt); |
| 136 | } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 137 | |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 138 | function addToggle(key, suppressIfMobile) { |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 139 | var v = keyData.get(key); |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 140 | if (suppressIfMobile && fs.isMobile()) { return; } |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 141 | v.tog = toolbar.addToggle(v.id, v.gid, v.isel, v.cb, v.tt); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 144 | function addFirstRow() { |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 145 | addToggle('I'); |
Simon Hunt | da2f3cc | 2015-03-19 15:11:57 -0700 | [diff] [blame] | 146 | addToggle('O'); |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 147 | addToggle('D'); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 148 | toolbar.addSeparator(); |
| 149 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 150 | addToggle('H'); |
| 151 | addToggle('M'); |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 152 | addToggle('P', true); |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 153 | addToggle('B'); |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 154 | addButton('G'); |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 155 | addToggle('S', true); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 156 | } |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 157 | |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 158 | function addSecondRow() { |
Bri Prebilic Cole | 7c98051 | 2015-03-25 12:31:29 -0700 | [diff] [blame] | 159 | //addToggle('X'); |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 160 | addToggle('Z'); |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 161 | addButton('N'); |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 162 | addButton('L'); |
| 163 | addButton('R'); |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 164 | toolbar.addSeparator(); |
| 165 | addButton('E'); |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 166 | } |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 167 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 168 | function addOverlays() { |
| 169 | toolbar.addSeparator(); |
| 170 | |
| 171 | // generate radio button set for overlays; start with 'none' |
| 172 | var rset = [{ |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 173 | gid: 'unknown', |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 174 | tooltip: 'No Overlay', |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 175 | cb: function () { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 176 | tov.tbSelection(null, switchOverlayActions); |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 177 | } |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 178 | }]; |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 179 | ovIndex = tov.augmentRbset(rset, switchOverlayActions); |
| 180 | ovRset = toolbar.addRadioSet('topo-overlays', rset); |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 183 | // invoked by overlay service to switch out old buttons and switch in new |
| 184 | function switchOverlayActions(oid, keyBindings) { |
| 185 | var prohibits = [], |
| 186 | kb = fs.isO(keyBindings) || {}, |
| 187 | order = fs.isA(kb._keyOrder) || []; |
| 188 | |
| 189 | if (keyBindings && !keyBindings._keyOrder) { |
| 190 | $log.warn(soa + 'no _keyOrder property defined'); |
| 191 | } else { |
| 192 | // sanity removal of reserved property names |
| 193 | ['esc', '_keyListener', '_helpFormat'].forEach(function (k) { |
| 194 | fs.removeFromArray(k, order); |
| 195 | }); |
| 196 | } |
| 197 | |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 198 | // ensure dialog has closed (if opened by outgoing overlay) |
| 199 | tds.closeDialog(); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 200 | thirdRow.clear(); |
| 201 | |
| 202 | if (!order.length) { |
| 203 | thirdRow.setText(selOver); |
| 204 | thirdRow.classed('right', true); |
| 205 | api.setUpKeys(); // clear previous overlay key bindings |
| 206 | |
| 207 | } else { |
| 208 | thirdRow.classed('right', false); |
| 209 | angular.forEach(order, function (key) { |
| 210 | var value, bid, gid, tt; |
| 211 | |
| 212 | if (prohibited.indexOf(key) > -1) { |
| 213 | prohibits.push(key); |
| 214 | |
| 215 | } else { |
| 216 | value = keyBindings[key]; |
| 217 | bid = oid + '-' + key; |
| 218 | gid = tov.mkGlyphId(oid, value.gid); |
| 219 | tt = value.tt + ' (' + key + ')'; |
| 220 | thirdRow.addButton(bid, gid, value.cb, tt); |
| 221 | } |
| 222 | }); |
| 223 | api.setUpKeys(keyBindings); // add overlay key bindings |
| 224 | } |
| 225 | |
| 226 | if (prohibits.length) { |
| 227 | $log.warn(soa + 'Prohibited key bindings ignored:', prohibits); |
| 228 | } |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 229 | } |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 230 | |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 231 | function createToolbar() { |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 232 | initKeyData(); |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 233 | toolbar = tbs.createToolbar(name); |
Bri Prebilic Cole | 04b4140 | 2015-03-18 17:25:34 -0700 | [diff] [blame] | 234 | addFirstRow(); |
Bri Prebilic Cole | 812f6c0 | 2015-03-24 17:10:33 -0700 | [diff] [blame] | 235 | toolbar.addRow(); |
| 236 | addSecondRow(); |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 237 | addOverlays(); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 238 | thirdRow = toolbar.addRow(); |
| 239 | thirdRow.setText(selOver); |
| 240 | thirdRow.classed('right', true); |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 241 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 242 | if (cachedState.toolbar) { |
| 243 | toolbar.show(); |
| 244 | } else { |
| 245 | toolbar.hide(); |
| 246 | } |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 249 | function destroyToolbar() { |
| 250 | tbs.destroyToolbar(name); |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 251 | tov.resetOnToolbarDestroy(); |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 254 | // allows us to ensure the button states track key strokes |
| 255 | function keyListener(key) { |
| 256 | var v = keyData.get(key); |
| 257 | |
| 258 | if (v) { |
| 259 | // we have a valid button mapping |
| 260 | if (v.tog) { |
| 261 | // it's a toggle button |
| 262 | v.tog.toggleNoCb(); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame] | 267 | function toggleToolbar() { |
| 268 | toolbar.toggle(); |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 269 | var prefs = ps.getPrefs(cooktag, defaultPrefsState); |
| 270 | prefs.toolbar = !prefs.toolbar; |
| 271 | ps.setPrefs('topo_prefs', prefs); |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 274 | function setDefaultOverlay() { |
| 275 | var idx = ovIndex[defaultOverlay] || 0; |
| 276 | ovRset.selectedIndex(idx); |
| 277 | } |
| 278 | |
Simon Hunt | 5b024d7 | 2016-01-29 11:02:43 -0800 | [diff] [blame] | 279 | // an overlay was selected via Function-Key press |
| 280 | function fnkey(idx) { |
| 281 | if (idx < ovRset.size() && idx !== ovRset.selectedIndex()) { |
| 282 | ovRset.selectedIndex(idx); |
| 283 | } |
| 284 | } |
| 285 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 286 | angular.module('ovTopo') |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 287 | .factory('TopoToolbarService', |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 288 | ['$log', 'FnService', 'ToolbarService', 'PrefsService', |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 289 | 'TopoOverlayService', 'TopoDialogService', |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 290 | |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 291 | function (_$log_, _fs_, _tbs_, _ps_, _tov_, _tds_) { |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 292 | $log = _$log_; |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 293 | fs = _fs_; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 294 | tbs = _tbs_; |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 295 | ps = _ps_; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 296 | tov = _tov_; |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 297 | tds = _tds_; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 298 | |
| 299 | return { |
| 300 | init: init, |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 301 | createToolbar: createToolbar, |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 302 | destroyToolbar: destroyToolbar, |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame] | 303 | keyListener: keyListener, |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 304 | toggleToolbar: toggleToolbar, |
Simon Hunt | 5b024d7 | 2016-01-29 11:02:43 -0800 | [diff] [blame] | 305 | setDefaultOverlay: setDefaultOverlay, |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 306 | defaultPrefs: defaultPrefsState, |
Simon Hunt | 5b024d7 | 2016-01-29 11:02:43 -0800 | [diff] [blame] | 307 | fnkey: fnkey |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 308 | }; |
| 309 | }]); |
| 310 | }()); |