blob: f78136432f0bb0d24019d69e3c2e8911660d2bf1 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
Sean Condonb2c483c2019-01-16 20:28:55 +00002 * Copyright 2019-present Open Networking Foundation
Sean Condonf4f54a12018-10-10 23:25:46 +01003 *
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 Condon91481822019-01-01 13:56:14 +000016import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
Sean Condonf4f54a12018-10-10 23:25:46 +010017import {
18 LogService,
19 LoadingService,
20 FnService,
Sean Condon91481822019-01-01 13:56:14 +000021 PanelBaseImpl, LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010022} from 'gui2-fw-lib';
Sean Condonb2c483c2019-01-16 20:28:55 +000023
Sean Condon50855cf2018-12-23 15:37:42 +000024import {animate, state, style, transition, trigger} from '@angular/animations';
Sean Condonf4f54a12018-10-10 23:25:46 +010025
Sean Condonb2c483c2019-01-16 20:28:55 +000026export const INSTANCE_TOGGLE = 'instance-tog';
27export const SUMMARY_TOGGLE = 'summary-tog';
28export const DETAILS_TOGGLE = 'details-tog';
29export const HOSTS_TOGGLE = 'hosts-tog';
30export const OFFLINE_TOGGLE = 'offline-tog';
31export const PORTS_TOGGLE = 'ports-tog';
32export const BKGRND_TOGGLE = 'bkgrnd-tog';
33export const CYCLELABELS_BTN = 'cycleLabels-btn';
34export const CYCLEHOSTLABEL_BTN = 'cycleHostLabel-btn';
35export const RESETZOOM_BTN = 'resetZoom-btn';
36export const EQMASTER_BTN = 'eqMaster-btn';
37export const CANCEL_TRAFFIC = 'cancel-traffic';
38export const ALL_TRAFFIC = 'all-traffic';
39export const QUICKHELP_BTN = 'quickhelp-btn';
40
41
Sean Condonf4f54a12018-10-10 23:25:46 +010042/*
43 ONOS GUI -- Topology Toolbar Module.
44 Defines modeling of ONOS toolbar.
45 */
46@Component({
47 selector: 'onos-toolbar',
48 templateUrl: './toolbar.component.html',
49 styleUrls: [
50 './toolbar.component.css', './toolbar.theme.css',
51 '../../topology.common.css',
Sean Condon91481822019-01-01 13:56:14 +000052 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css',
53 './button.css'
Sean Condon50855cf2018-12-23 15:37:42 +000054 ],
55 animations: [
56 trigger('toolbarState', [
57 state('true', style({
58 transform: 'translateX(0%)',
Sean Condon91481822019-01-01 13:56:14 +000059 // opacity: '1.0'
Sean Condon50855cf2018-12-23 15:37:42 +000060 })),
61 state('false', style({
Sean Condon91481822019-01-01 13:56:14 +000062 transform: 'translateX(-93%)',
63 // opacity: '0.0'
Sean Condon50855cf2018-12-23 15:37:42 +000064 })),
Sean Condon91481822019-01-01 13:56:14 +000065 transition('0 => 1', animate('500ms ease-in')),
66 transition('1 => 0', animate('500ms ease-out'))
Sean Condon50855cf2018-12-23 15:37:42 +000067 ])
Sean Condonf4f54a12018-10-10 23:25:46 +010068 ]
69})
Sean Condonb2c483c2019-01-16 20:28:55 +000070export class ToolbarComponent extends PanelBaseImpl {
71 @Input() on: boolean = false; // Override the parent class attribute
Sean Condon91481822019-01-01 13:56:14 +000072 // deferred localization strings
73 lionFn; // Function
74 // Used to drive the display of the hosts icon - there is also another such variable on the forcesvg
75 @Input() hostsVisible: boolean = false;
76 @Input() instancesVisible: boolean = true;
77 @Input() summaryVisible: boolean = true;
78 @Input() detailsVisible: boolean = true;
79 @Input() backgroundVisible: boolean = false;
80 @Input() portsVisible: boolean = true;
81
82 @Output() buttonEvent = new EventEmitter<string>();
Sean Condonf4f54a12018-10-10 23:25:46 +010083
84 constructor(
85 protected fs: FnService,
86 protected log: LogService,
87 protected ls: LoadingService,
Sean Condon91481822019-01-01 13:56:14 +000088 private lion: LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010089 ) {
90 super(fs, ls, log);
Sean Condon91481822019-01-01 13:56:14 +000091
92 if (this.lion.ubercache.length === 0) {
93 this.lionFn = this.dummyLion;
94 this.lion.loadCbs.set('topo-toolbar', () => this.doLion());
95 } else {
96 this.doLion();
97 }
98
Sean Condonf4f54a12018-10-10 23:25:46 +010099 this.log.debug('ToolbarComponent constructed');
100 }
101
Sean Condon91481822019-01-01 13:56:14 +0000102 /**
103 * Read the LION bundle for Toolbar and set up the lionFn
104 */
105 doLion() {
106 this.lionFn = this.lion.bundle('core.view.Topo');
107 }
108
109 /**
110 * As buttons are clicked on the toolbar, emit events up to the parent
111 *
112 * The toggling of the input variables here is in addition to the control
113 * of these input variables from the parent. This is so that this component
114 * may be reused and is not dependent on a particular parent implementation
115 * to work
116 * @param name The name of button clicked.
117 */
118 buttonClicked(name: string): void {
119 switch (name) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000120 case HOSTS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000121 this.hostsVisible = !this.hostsVisible;
122 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000123 case INSTANCE_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000124 this.instancesVisible = !this.instancesVisible;
125 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000126 case SUMMARY_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000127 this.summaryVisible = !this.summaryVisible;
128 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000129 case DETAILS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000130 this.detailsVisible = !this.detailsVisible;
131 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000132 case BKGRND_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000133 this.backgroundVisible = !this.backgroundVisible;
134 break;
135 default:
Sean Condon91481822019-01-01 13:56:14 +0000136 }
137 // Send a message up to let TopologyComponent know of the event
138 this.buttonEvent.emit(name);
139 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100140}