blob: ca2408c3f2f96bb42a4df6b8a578b423951156eb [file] [log] [blame]
Sean Condonb2c483c2019-01-16 20:28:55 +00001/*
2 * Copyright 2019-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 */
Sean Condonbed2e032019-04-17 22:22:49 +010016import {Component, OnInit} from '@angular/core';
Sean Condonb2c483c2019-01-16 20:28:55 +000017import {animate, state, style, transition, trigger} from '@angular/animations';
18import {LogService} from '../../log.service';
19import {FnService} from '../../util/fn.service';
20import {KeysService} from '../../util/keys.service';
21import {LionService} from '../../util/lion.service';
22
Sean Condonbed2e032019-04-17 22:22:49 +010023export interface KeyEntry {
24 keystroke: string;
25 text: string;
26}
Sean Condonb2c483c2019-01-16 20:28:55 +000027
28@Component({
29 selector: 'onos-quickhelp',
30 templateUrl: './quickhelp.component.html',
31 styleUrls: ['./quickhelp.component.css'],
32 animations: [
33 trigger('quickHelpState', [
34 state('true', style({
35 opacity: '1.0',
36 })),
37 state('false', style({
38 opacity: '0.0',
39 })),
40 transition('0 => 1', animate('500ms ease-in')),
41 transition('1 => 0', animate('500ms ease-out'))
42 ])
43 ]
44})
Sean Condonbed2e032019-04-17 22:22:49 +010045export class QuickhelpComponent implements OnInit {
Sean Condonb2c483c2019-01-16 20:28:55 +000046 lionFn; // Function
Sean Condonb0a196a2019-04-19 09:50:44 +010047 lionFnTopo; // Function
Sean Condonb2c483c2019-01-16 20:28:55 +000048
Sean Condonbed2e032019-04-17 22:22:49 +010049 dialogKeys: Object;
50 globalKeys: Object[];
51 maskedKeys: Object;
52 viewGestures: Object;
53 viewKeys: KeyEntry[][];
54
55 private static extractKeyEntry(viewKeyObj: Object, log: LogService): KeyEntry {
Sean Condon98b6ddb2019-12-24 08:07:40 +000056 const subParts = (<any>Object).values(viewKeyObj[1]);
Sean Condonbed2e032019-04-17 22:22:49 +010057 return <KeyEntry>{
58 keystroke: <string>viewKeyObj[0],
59 text: <string>subParts[1]
60 };
61 }
62
Sean Condonb2c483c2019-01-16 20:28:55 +000063 constructor(
64 private log: LogService,
65 private fs: FnService,
66 public ks: KeysService,
67 private lion: LionService
68 ) {
69 if (this.lion.ubercache.length === 0) {
70 this.lionFn = this.dummyLion;
Sean Condonb0a196a2019-04-19 09:50:44 +010071 this.lionFnTopo = this.dummyLion;
Sean Condonb2c483c2019-01-16 20:28:55 +000072 this.lion.loadCbs.set('quickhelp', () => this.doLion());
73 } else {
74 this.doLion();
75 }
Sean Condonbed2e032019-04-17 22:22:49 +010076 this.globalKeys = [];
77 this.viewKeys = [[], [], [], [], [], [], [], [], []];
Sean Condonb2c483c2019-01-16 20:28:55 +000078
Sean Condonbed2e032019-04-17 22:22:49 +010079 this.log.debug('QuickhelpComponent constructed');
Sean Condonb2c483c2019-01-16 20:28:55 +000080 }
81
Sean Condonbed2e032019-04-17 22:22:49 +010082 ngOnInit(): void {
Sean Condon98b6ddb2019-12-24 08:07:40 +000083 (<any>Object).entries(this.ks.keyHandler.viewKeys)
Sean Condonb0a196a2019-04-19 09:50:44 +010084 .filter((vk) => vk[0] !== '_helpFormat' && vk[0] !== '9' && vk[0] !== 'esc')
Sean Condonbed2e032019-04-17 22:22:49 +010085 .forEach((vk, idx) => {
86 const ke = QuickhelpComponent.extractKeyEntry(vk, this.log);
87 this.viewKeys[Math.floor(idx / 3)][idx % 3] = ke;
88 });
89 this.log.debug('QuickhelpComponent initialized');
90 this.log.debug('view keys retrieved', this.ks.keyHandler.globalKeys);
91 }
92
93
Sean Condonb2c483c2019-01-16 20:28:55 +000094 /**
95 * Read the LION bundle for Toolbar and set up the lionFn
96 */
97 doLion() {
98 this.lionFn = this.lion.bundle('core.fw.QuickHelp');
Sean Condonb0a196a2019-04-19 09:50:44 +010099 this.lionFnTopo = this.lion.bundle('core.view.Topo');
Sean Condonb2c483c2019-01-16 20:28:55 +0000100 }
101
102 /**
103 * A dummy implementation of the lionFn until the response is received and the LION
104 * bundle is received from the WebSocket
105 */
106 dummyLion(key: string): string {
107 return '%' + key + '%';
108 }
109}