Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 17 | import {Component} from '@angular/core'; |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 18 | import {FnService, KeysService, LogService, LionService, WebSocketService, WsOptions} from 'gui2-fw-lib'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 19 | |
| 20 | @Component({ |
| 21 | selector: 'app-root', |
| 22 | templateUrl: './app.component.html', |
| 23 | styleUrls: ['./app.component.css'] |
| 24 | }) |
| 25 | export class AppComponent { |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 26 | title = 'Test app for GUI Framework Library'; |
| 27 | loadingRunning: boolean = false; |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 28 | lionFn; // Function |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 29 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 30 | constructor( |
| 31 | protected fs: FnService, |
| 32 | protected ks: KeysService, |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 33 | protected log: LogService, |
| 34 | protected wss: WebSocketService, |
| 35 | protected lion: LionService |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 36 | ) { |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 37 | this.wss.createWebSocket(<WsOptions>{ wsport: 8181}); |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 38 | this.title = this.fs.cap(this.title); |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 39 | |
| 40 | if (this.lion.ubercache.length === 0) { |
| 41 | this.lionFn = this.dummyLion; |
| 42 | this.lion.loadCbs.set('topo-toolbar', () => this.doLion()); |
| 43 | } else { |
| 44 | this.doLion(); |
| 45 | } |
| 46 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 47 | this.bindCommands(); |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 48 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 49 | this.log.debug('AppComponent constructed'); |
| 50 | } |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 51 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 52 | bindCommands(additional?: any) { |
| 53 | |
| 54 | const am = this.actionMap(); |
| 55 | const add = this.fs.isO(additional); |
| 56 | |
| 57 | this.ks.keyBindings(am); |
| 58 | |
| 59 | this.ks.gestureNotes([ |
| 60 | ['click', 'Select the item and show details'], |
| 61 | ['shift-click', 'Toggle selection state'], |
| 62 | ['drag', 'Reposition (and pin) device / host'], |
| 63 | ['cmd-scroll', 'Zoom in / out'], |
| 64 | ['cmd-drag', 'Pan'], |
| 65 | ]); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | showKeyStroke(letter: string, token?: string) { |
| 70 | this.log.debug('Key pressed', letter); |
| 71 | } |
| 72 | |
| 73 | actionMap() { |
| 74 | return { |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 75 | A: [() => {this.showKeyStroke('A'); }, this.lionFn('tr_btn_monitor_all')], |
| 76 | B: [(token) => {this.showKeyStroke('B'); }, this.lionFn('tbtt_tog_map')], |
| 77 | D: [(token) => {this.showKeyStroke('D'); }, this.lionFn('tbtt_tog_use_detail')], |
| 78 | E: [() => {this.showKeyStroke('E'); }, this.lionFn('tbtt_eq_master')], |
| 79 | H: [() => {this.showKeyStroke('H'); }, this.lionFn('tbtt_tog_host')], |
| 80 | I: [(token) => {this.showKeyStroke('I'); }, this.lionFn('tbtt_tog_instances')], |
| 81 | G: [() => {this.showKeyStroke('G'); }, this.lionFn('tbtt_sel_map')], |
| 82 | L: [() => {this.showKeyStroke('L'); }, this.lionFn('tbtt_cyc_dev_labs')], |
| 83 | M: [() => {this.showKeyStroke('M'); }, this.lionFn('tbtt_tog_offline')], |
| 84 | O: [() => {this.showKeyStroke('O'); }, this.lionFn('tbtt_tog_summary')], |
| 85 | P: [(token) => {this.showKeyStroke('P'); }, this.lionFn('tbtt_tog_porthi')], |
| 86 | Q: [() => {this.showKeyStroke('Q'); }, this.lionFn('tbtt_cyc_grid_display')], |
| 87 | R: [() => {this.showKeyStroke('R'); }, this.lionFn('tbtt_reset_zoom')], |
| 88 | U: [() => {this.showKeyStroke('U'); }, this.lionFn('tbtt_unpin_node')], |
| 89 | X: [() => {this.showKeyStroke('X'); }, this.lionFn('tbtt_reset_loc')], |
| 90 | dot: [() => {this.showKeyStroke('.'); }, this.lionFn('tbtt_tog_toolbar')], |
| 91 | 0: [() => {this.showKeyStroke('0'); }, this.lionFn('tr_btn_cancel_monitoring')], |
| 92 | 'shift-L': [() => {this.showKeyStroke('shift-L'); }, this.lionFn('tbtt_cyc_host_labs')], |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 93 | |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 94 | // -- instance color palette debug |
| 95 | 9: () => { |
| 96 | this.showKeyStroke('9'); |
| 97 | }, |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 98 | |
| 99 | // TODO update after adding in Background Service |
| 100 | // topology overlay selections |
| 101 | // F1: function () { t2tbs.fnKey(0); }, |
| 102 | // F2: function () { t2tbs.fnKey(1); }, |
| 103 | // F3: function () { t2tbs.fnKey(2); }, |
| 104 | // F4: function () { t2tbs.fnKey(3); }, |
| 105 | // F5: function () { t2tbs.fnKey(4); }, |
| 106 | // |
| 107 | // _keyListener: t2tbs.keyListener.bind(t2tbs), |
| 108 | |
| 109 | _helpFormat: [ |
| 110 | ['I', 'O', 'D', 'H', 'M', 'P', 'dash', 'B'], |
| 111 | ['X', 'Z', 'N', 'L', 'shift-L', 'U', 'R', 'E', 'dot'], |
| 112 | [], // this column reserved for overlay actions |
| 113 | ], |
| 114 | }; |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 115 | } |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * Read the LION bundle for Toolbar and set up the lionFn |
| 119 | */ |
| 120 | doLion() { |
| 121 | this.lionFn = this.lion.bundle('core.view.Topo'); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * A dummy implementation of the lionFn until the response is received and the LION |
| 126 | * bundle is received from the WebSocket |
| 127 | */ |
| 128 | dummyLion(key: string): string { |
| 129 | return '%' + key + '%'; |
| 130 | } |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 131 | } |