Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 1 | /* |
| 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 Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 16 | import {Component, OnInit} from '@angular/core'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 17 | import {animate, state, style, transition, trigger} from '@angular/animations'; |
| 18 | import {LogService} from '../../log.service'; |
| 19 | import {FnService} from '../../util/fn.service'; |
| 20 | import {KeysService} from '../../util/keys.service'; |
| 21 | import {LionService} from '../../util/lion.service'; |
| 22 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 23 | export interface KeyEntry { |
| 24 | keystroke: string; |
| 25 | text: string; |
| 26 | } |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 27 | |
| 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 Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 45 | export class QuickhelpComponent implements OnInit { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 46 | lionFn; // Function |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 47 | lionFnTopo; // Function |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 48 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 49 | 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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 56 | const subParts = (<any>Object).values(viewKeyObj[1]); |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 57 | return <KeyEntry>{ |
| 58 | keystroke: <string>viewKeyObj[0], |
| 59 | text: <string>subParts[1] |
| 60 | }; |
| 61 | } |
| 62 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 63 | 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 Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 71 | this.lionFnTopo = this.dummyLion; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 72 | this.lion.loadCbs.set('quickhelp', () => this.doLion()); |
| 73 | } else { |
| 74 | this.doLion(); |
| 75 | } |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 76 | this.globalKeys = []; |
| 77 | this.viewKeys = [[], [], [], [], [], [], [], [], []]; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 78 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 79 | this.log.debug('QuickhelpComponent constructed'); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 82 | ngOnInit(): void { |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 83 | (<any>Object).entries(this.ks.keyHandler.viewKeys) |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 84 | .filter((vk) => vk[0] !== '_helpFormat' && vk[0] !== '9' && vk[0] !== 'esc') |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 85 | .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 Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 94 | /** |
| 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 Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 99 | this.lionFnTopo = this.lion.bundle('core.view.Topo'); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 100 | } |
| 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 | } |