Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | import * as $ from 'jquery'; |
| 18 | import {IXosKeyboardShortcutService} from '../../core/services/keyboard-shortcut'; |
Matteo Scandolo | 5bf5173 | 2018-01-10 15:51:33 -0800 | [diff] [blame] | 19 | import {IXosSidePanelService} from '../../core/side-panel/side-panel.service'; |
Matteo Scandolo | b8cdf55 | 2018-02-12 17:56:26 -0800 | [diff] [blame] | 20 | import {GraphStates, IXosGraphStateMachine} from './graph-state-machine'; |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 21 | |
| 22 | export interface IXosGraphConfig { |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 23 | setupKeyboardShortcuts(): void; |
| 24 | toggleFullscreen(): void; |
| 25 | } |
| 26 | |
| 27 | export class XosGraphConfig { |
| 28 | |
| 29 | static $inject = [ |
| 30 | '$log', |
| 31 | '$cookies', |
| 32 | '$rootScope', |
| 33 | '$timeout', |
Matteo Scandolo | 5bf5173 | 2018-01-10 15:51:33 -0800 | [diff] [blame] | 34 | 'XosSidePanel', |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 35 | 'XosKeyboardShortcut', |
Matteo Scandolo | b8cdf55 | 2018-02-12 17:56:26 -0800 | [diff] [blame] | 36 | 'XosGraphStateMachine' |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 37 | ]; |
| 38 | |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 39 | constructor ( |
| 40 | private $log: ng.ILogService, |
| 41 | private $cookies: ng.cookies.ICookiesService, |
| 42 | private $rootScope: ng.IRootScopeService, |
| 43 | private $timeout: ng.ITimeoutService, |
Matteo Scandolo | 5bf5173 | 2018-01-10 15:51:33 -0800 | [diff] [blame] | 44 | private XosSidePanel: IXosSidePanelService, |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 45 | private XosKeyboardShortcut: IXosKeyboardShortcutService, |
Matteo Scandolo | b8cdf55 | 2018-02-12 17:56:26 -0800 | [diff] [blame] | 46 | private XosGraphStateMachine: IXosGraphStateMachine |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 47 | ) { |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 48 | |
| 49 | } |
| 50 | |
| 51 | public setupKeyboardShortcuts() { |
| 52 | |
| 53 | this.$log.info(`[XosGraphConfig] Setting up keyboard shortcuts`); |
| 54 | |
| 55 | // Setup keyboard shortcuts |
| 56 | this.XosKeyboardShortcut.registerKeyBinding({ |
Matteo Scandolo | 5bf5173 | 2018-01-10 15:51:33 -0800 | [diff] [blame] | 57 | key: 'h', |
| 58 | modifiers: ['shift'], |
| 59 | cb: () => { |
| 60 | this.XosSidePanel.toggleComponent('xosServiceGraphLegend'); |
| 61 | }, |
| 62 | label: 'h', |
| 63 | description: 'Toggle Graph Legend' |
| 64 | }); |
| 65 | |
| 66 | this.XosKeyboardShortcut.registerKeyBinding({ |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 67 | key: 'f', |
| 68 | modifiers: ['shift'], |
| 69 | cb: () => { |
| 70 | this.toggleFullscreen(); |
| 71 | }, |
| 72 | label: 'f', |
| 73 | description: 'Toggle graph fullscreen' |
| 74 | }); |
| 75 | |
| 76 | this.XosKeyboardShortcut.registerKeyBinding({ |
Matteo Scandolo | b8cdf55 | 2018-02-12 17:56:26 -0800 | [diff] [blame] | 77 | key: 'c', |
| 78 | modifiers: ['shift'], |
| 79 | cb: () => { |
| 80 | this.XosGraphStateMachine.go(GraphStates.Services); |
| 81 | }, |
| 82 | label: 'c', |
| 83 | description: 'Clean the Service graph' |
| 84 | }); |
| 85 | |
| 86 | this.XosKeyboardShortcut.registerKeyBinding({ |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 87 | key: 's', |
| 88 | modifiers: ['shift'], |
| 89 | cb: () => { |
Matteo Scandolo | b8cdf55 | 2018-02-12 17:56:26 -0800 | [diff] [blame] | 90 | this.XosGraphStateMachine.go(GraphStates.ServiceInstances); |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 91 | }, |
| 92 | label: 's', |
Matteo Scandolo | b8cdf55 | 2018-02-12 17:56:26 -0800 | [diff] [blame] | 93 | description: 'Show ServiceInstances' |
| 94 | }); |
| 95 | |
| 96 | this.XosKeyboardShortcut.registerKeyBinding({ |
| 97 | key: 'i', |
| 98 | modifiers: ['shift'], |
| 99 | cb: () => { |
| 100 | this.XosGraphStateMachine.go(GraphStates.Instances); |
| 101 | }, |
| 102 | label: 'i', |
| 103 | description: 'Show Instances' |
| 104 | }); |
| 105 | |
| 106 | this.XosKeyboardShortcut.registerKeyBinding({ |
| 107 | key: 'n', |
| 108 | modifiers: ['shift'], |
| 109 | cb: () => { |
| 110 | this.XosGraphStateMachine.go(GraphStates.Networks); |
| 111 | }, |
| 112 | label: 'n', |
| 113 | description: 'Show Networks' |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 114 | }); |
Matteo Scandolo | 1888b2a | 2018-01-08 16:49:06 -0800 | [diff] [blame] | 115 | |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | public toggleFullscreen() { |
| 119 | $('.graph-container').toggleClass('fullscreen'); |
| 120 | this.$timeout(() => { |
| 121 | // NOTE wait for the CSS transition to complete before repositioning |
| 122 | this.$rootScope.$broadcast('xos.sg.update'); |
| 123 | }, 500); |
| 124 | } |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 125 | } |