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