blob: ed9e2eeb80c5c058becfbf376dd267e0aa917ee3 [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';
Sean Condon0d064ec2019-02-04 21:53:53 +000033export const BKGRND_SELECT = 'bkgrnd-sel';
Sean Condonb2c483c2019-01-16 20:28:55 +000034export const CYCLELABELS_BTN = 'cycleLabels-btn';
35export const CYCLEHOSTLABEL_BTN = 'cycleHostLabel-btn';
36export const RESETZOOM_BTN = 'resetZoom-btn';
37export const EQMASTER_BTN = 'eqMaster-btn';
38export const CANCEL_TRAFFIC = 'cancel-traffic';
39export const ALL_TRAFFIC = 'all-traffic';
40export const QUICKHELP_BTN = 'quickhelp-btn';
41
42
Sean Condonf4f54a12018-10-10 23:25:46 +010043/*
44 ONOS GUI -- Topology Toolbar Module.
45 Defines modeling of ONOS toolbar.
46 */
47@Component({
48 selector: 'onos-toolbar',
49 templateUrl: './toolbar.component.html',
50 styleUrls: [
51 './toolbar.component.css', './toolbar.theme.css',
52 '../../topology.common.css',
Sean Condon91481822019-01-01 13:56:14 +000053 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css',
54 './button.css'
Sean Condon50855cf2018-12-23 15:37:42 +000055 ],
56 animations: [
57 trigger('toolbarState', [
58 state('true', style({
59 transform: 'translateX(0%)',
Sean Condon91481822019-01-01 13:56:14 +000060 // opacity: '1.0'
Sean Condon50855cf2018-12-23 15:37:42 +000061 })),
62 state('false', style({
Sean Condon91481822019-01-01 13:56:14 +000063 transform: 'translateX(-93%)',
64 // opacity: '0.0'
Sean Condon50855cf2018-12-23 15:37:42 +000065 })),
Sean Condon91481822019-01-01 13:56:14 +000066 transition('0 => 1', animate('500ms ease-in')),
67 transition('1 => 0', animate('500ms ease-out'))
Sean Condon50855cf2018-12-23 15:37:42 +000068 ])
Sean Condonf4f54a12018-10-10 23:25:46 +010069 ]
70})
Sean Condonb2c483c2019-01-16 20:28:55 +000071export class ToolbarComponent extends PanelBaseImpl {
72 @Input() on: boolean = false; // Override the parent class attribute
Sean Condon91481822019-01-01 13:56:14 +000073 // deferred localization strings
74 lionFn; // Function
75 // Used to drive the display of the hosts icon - there is also another such variable on the forcesvg
76 @Input() hostsVisible: boolean = false;
77 @Input() instancesVisible: boolean = true;
78 @Input() summaryVisible: boolean = true;
79 @Input() detailsVisible: boolean = true;
80 @Input() backgroundVisible: boolean = false;
81 @Input() portsVisible: boolean = true;
82
83 @Output() buttonEvent = new EventEmitter<string>();
Sean Condonf4f54a12018-10-10 23:25:46 +010084
85 constructor(
86 protected fs: FnService,
87 protected log: LogService,
88 protected ls: LoadingService,
Sean Condon91481822019-01-01 13:56:14 +000089 private lion: LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010090 ) {
91 super(fs, ls, log);
Sean Condon91481822019-01-01 13:56:14 +000092
93 if (this.lion.ubercache.length === 0) {
94 this.lionFn = this.dummyLion;
95 this.lion.loadCbs.set('topo-toolbar', () => this.doLion());
96 } else {
97 this.doLion();
98 }
99
Sean Condonf4f54a12018-10-10 23:25:46 +0100100 this.log.debug('ToolbarComponent constructed');
101 }
102
Sean Condon91481822019-01-01 13:56:14 +0000103 /**
104 * Read the LION bundle for Toolbar and set up the lionFn
105 */
106 doLion() {
107 this.lionFn = this.lion.bundle('core.view.Topo');
108 }
109
110 /**
111 * As buttons are clicked on the toolbar, emit events up to the parent
112 *
113 * The toggling of the input variables here is in addition to the control
114 * of these input variables from the parent. This is so that this component
115 * may be reused and is not dependent on a particular parent implementation
116 * to work
117 * @param name The name of button clicked.
118 */
119 buttonClicked(name: string): void {
120 switch (name) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000121 case HOSTS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000122 this.hostsVisible = !this.hostsVisible;
123 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000124 case INSTANCE_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000125 this.instancesVisible = !this.instancesVisible;
126 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000127 case SUMMARY_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000128 this.summaryVisible = !this.summaryVisible;
129 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000130 case DETAILS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000131 this.detailsVisible = !this.detailsVisible;
132 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000133 case BKGRND_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000134 this.backgroundVisible = !this.backgroundVisible;
135 break;
136 default:
Sean Condon91481822019-01-01 13:56:14 +0000137 }
138 // Send a message up to let TopologyComponent know of the event
139 this.buttonEvent.emit(name);
140 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100141}