blob: e60fc6dc85a2c0f6631de91328108c7692e834b0 [file] [log] [blame]
Sean Condon5ca00262018-09-06 17:55:25 +01001/*
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 Condon95fb5742019-04-02 12:16:55 +010017import {Component} from '@angular/core';
Sean Condondfc6dba2019-11-09 11:50:23 +000018import {FnService, KeysService, LogService, LionService, WebSocketService, WsOptions} from '../../projects/gui2-fw-lib/src/public_api';
Sean Condon5ca00262018-09-06 17:55:25 +010019
20@Component({
21 selector: 'app-root',
22 templateUrl: './app.component.html',
23 styleUrls: ['./app.component.css']
24})
25export class AppComponent {
Sean Condonbed2e032019-04-17 22:22:49 +010026 title = 'Test app for GUI Framework Library';
27 loadingRunning: boolean = false;
Sean Condonb0a196a2019-04-19 09:50:44 +010028 lionFn; // Function
Sean Condon5ca00262018-09-06 17:55:25 +010029
Sean Condonbed2e032019-04-17 22:22:49 +010030 constructor(
31 protected fs: FnService,
32 protected ks: KeysService,
Sean Condonb0a196a2019-04-19 09:50:44 +010033 protected log: LogService,
34 protected wss: WebSocketService,
35 protected lion: LionService
Sean Condonbed2e032019-04-17 22:22:49 +010036 ) {
Sean Condonb0a196a2019-04-19 09:50:44 +010037 this.wss.createWebSocket(<WsOptions>{ wsport: 8181});
Sean Condonbed2e032019-04-17 22:22:49 +010038 this.title = this.fs.cap(this.title);
Sean Condonb0a196a2019-04-19 09:50:44 +010039
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 Condonbed2e032019-04-17 22:22:49 +010047 this.bindCommands();
Sean Condonb0a196a2019-04-19 09:50:44 +010048
Sean Condonbed2e032019-04-17 22:22:49 +010049 this.log.debug('AppComponent constructed');
50 }
Sean Condon95fb5742019-04-02 12:16:55 +010051
Sean Condonbed2e032019-04-17 22:22:49 +010052 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 Condonb0a196a2019-04-19 09:50:44 +010075 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 Condonbed2e032019-04-17 22:22:49 +010093
Sean Condonb0a196a2019-04-19 09:50:44 +010094 // -- instance color palette debug
95 9: () => {
96 this.showKeyStroke('9');
97 },
Sean Condonbed2e032019-04-17 22:22:49 +010098
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 Condon95fb5742019-04-02 12:16:55 +0100115 }
Sean Condonb0a196a2019-04-19 09:50:44 +0100116
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 Condon5ca00262018-09-06 17:55:25 +0100131}