blob: 890795298eb6a5a73b9d84272c9d6780e3d87aca [file] [log] [blame]
Matteo Scandolo8cf33a32017-11-14 15:52:29 -08001/*
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
17import * as $ from 'jquery';
18import {IXosKeyboardShortcutService} from '../../core/services/keyboard-shortcut';
Matteo Scandolo5bf51732018-01-10 15:51:33 -080019import {IXosSidePanelService} from '../../core/side-panel/side-panel.service';
Matteo Scandolob8cdf552018-02-12 17:56:26 -080020import {GraphStates, IXosGraphStateMachine} from './graph-state-machine';
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080021
22export interface IXosGraphConfig {
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080023 setupKeyboardShortcuts(): void;
24 toggleFullscreen(): void;
25}
26
27export class XosGraphConfig {
28
29 static $inject = [
30 '$log',
31 '$cookies',
32 '$rootScope',
33 '$timeout',
Matteo Scandolo5bf51732018-01-10 15:51:33 -080034 'XosSidePanel',
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080035 'XosKeyboardShortcut',
Matteo Scandolob8cdf552018-02-12 17:56:26 -080036 'XosGraphStateMachine'
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080037 ];
38
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080039 constructor (
40 private $log: ng.ILogService,
41 private $cookies: ng.cookies.ICookiesService,
42 private $rootScope: ng.IRootScopeService,
43 private $timeout: ng.ITimeoutService,
Matteo Scandolo5bf51732018-01-10 15:51:33 -080044 private XosSidePanel: IXosSidePanelService,
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080045 private XosKeyboardShortcut: IXosKeyboardShortcutService,
Matteo Scandolob8cdf552018-02-12 17:56:26 -080046 private XosGraphStateMachine: IXosGraphStateMachine
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080047 ) {
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080048
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 Scandolo5bf51732018-01-10 15:51:33 -080057 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 Scandolo8cf33a32017-11-14 15:52:29 -080067 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 Scandolob8cdf552018-02-12 17:56:26 -080077 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 Scandolo8cf33a32017-11-14 15:52:29 -080087 key: 's',
88 modifiers: ['shift'],
89 cb: () => {
Matteo Scandolob8cdf552018-02-12 17:56:26 -080090 this.XosGraphStateMachine.go(GraphStates.ServiceInstances);
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080091 },
92 label: 's',
Matteo Scandolob8cdf552018-02-12 17:56:26 -080093 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 Scandolo8cf33a32017-11-14 15:52:29 -0800114 });
Matteo Scandolo1888b2a2018-01-08 16:49:06 -0800115
Matteo Scandolo8cf33a32017-11-14 15:52:29 -0800116 }
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 Scandolo8cf33a32017-11-14 15:52:29 -0800125}