blob: 7db2d97f3760865464567d97f8a8f17eddde8351 [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 Scandolo8cf33a32017-11-14 15:52:29 -080019import {IXosGraphStore} from './graph.store';
20
21export interface IXosGraphConfig {
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080022 setupKeyboardShortcuts(): void;
23 toggleFullscreen(): void;
24}
25
26export class XosGraphConfig {
27
28 static $inject = [
29 '$log',
30 '$cookies',
31 '$rootScope',
32 '$timeout',
33 'XosKeyboardShortcut',
34 'XosGraphStore'
35 ];
36
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080037 constructor (
38 private $log: ng.ILogService,
39 private $cookies: ng.cookies.ICookiesService,
40 private $rootScope: ng.IRootScopeService,
41 private $timeout: ng.ITimeoutService,
42 private XosKeyboardShortcut: IXosKeyboardShortcutService,
43 private XosGraphStore: IXosGraphStore
44 ) {
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080045
46 }
47
48 public setupKeyboardShortcuts() {
49
50 this.$log.info(`[XosGraphConfig] Setting up keyboard shortcuts`);
51
52 // Setup keyboard shortcuts
53 this.XosKeyboardShortcut.registerKeyBinding({
54 key: 'f',
55 modifiers: ['shift'],
56 cb: () => {
57 this.toggleFullscreen();
58 },
59 label: 'f',
60 description: 'Toggle graph fullscreen'
61 });
62
63 this.XosKeyboardShortcut.registerKeyBinding({
64 key: 's',
65 modifiers: ['shift'],
66 cb: () => {
67 // NOTE anytime the graph change the observable is updated,
68 // no need to manually retrigger here
69 this.XosGraphStore.toggleServiceInstances();
70 },
71 label: 's',
72 description: 'Toggle ServiceInstances'
73 });
74 }
75
76 public toggleFullscreen() {
77 $('.graph-container').toggleClass('fullscreen');
78 this.$timeout(() => {
79 // NOTE wait for the CSS transition to complete before repositioning
80 this.$rootScope.$broadcast('xos.sg.update');
81 }, 500);
82 }
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080083}