blob: 5ea7d036721505e285f9bf3ec87fd99bc154e189 [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,
Sean Condonf4f54a12018-10-10 23:25:46 +010019 FnService,
Sean Condon91481822019-01-01 13:56:14 +000020 PanelBaseImpl, LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010021} from 'gui2-fw-lib';
Sean Condonb2c483c2019-01-16 20:28:55 +000022
Sean Condon50855cf2018-12-23 15:37:42 +000023import {animate, state, style, transition, trigger} from '@angular/animations';
Sean Condonf4f54a12018-10-10 23:25:46 +010024
Sean Condonb2c483c2019-01-16 20:28:55 +000025export const INSTANCE_TOGGLE = 'instance-tog';
26export const SUMMARY_TOGGLE = 'summary-tog';
27export const DETAILS_TOGGLE = 'details-tog';
28export const HOSTS_TOGGLE = 'hosts-tog';
29export const OFFLINE_TOGGLE = 'offline-tog';
30export const PORTS_TOGGLE = 'ports-tog';
31export const BKGRND_TOGGLE = 'bkgrnd-tog';
Sean Condon0d064ec2019-02-04 21:53:53 +000032export const BKGRND_SELECT = 'bkgrnd-sel';
Sean Condonb2c483c2019-01-16 20:28:55 +000033export const CYCLELABELS_BTN = 'cycleLabels-btn';
34export const CYCLEHOSTLABEL_BTN = 'cycleHostLabel-btn';
Sean Condon71910542019-02-16 18:16:42 +000035export const CYCLEGRIDDISPLAY_BTN = 'cycleGridDisplay-btn';
Sean Condonb2c483c2019-01-16 20:28:55 +000036export 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';
Sean Condon28884332019-03-21 14:07:00 +000041export const LAYOUT_DEFAULT_BTN = 'layout-default-btn';
42export const LAYOUT_ACCESS_BTN = 'layout-access-btn';
Sean Condon590b34b2019-12-04 18:44:37 +000043export const ALARMS_TOGGLE = 'alarms-tog';
Sean Condonb2c483c2019-01-16 20:28:55 +000044
Sean Condonf4f54a12018-10-10 23:25:46 +010045/*
46 ONOS GUI -- Topology Toolbar Module.
47 Defines modeling of ONOS toolbar.
48 */
49@Component({
50 selector: 'onos-toolbar',
51 templateUrl: './toolbar.component.html',
52 styleUrls: [
53 './toolbar.component.css', './toolbar.theme.css',
54 '../../topology.common.css',
Sean Condon91481822019-01-01 13:56:14 +000055 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css',
56 './button.css'
Sean Condon50855cf2018-12-23 15:37:42 +000057 ],
58 animations: [
59 trigger('toolbarState', [
60 state('true', style({
61 transform: 'translateX(0%)',
Sean Condon91481822019-01-01 13:56:14 +000062 // opacity: '1.0'
Sean Condon50855cf2018-12-23 15:37:42 +000063 })),
64 state('false', style({
Sean Condon91481822019-01-01 13:56:14 +000065 transform: 'translateX(-93%)',
66 // opacity: '0.0'
Sean Condon50855cf2018-12-23 15:37:42 +000067 })),
Sean Condon91481822019-01-01 13:56:14 +000068 transition('0 => 1', animate('500ms ease-in')),
69 transition('1 => 0', animate('500ms ease-out'))
Sean Condon50855cf2018-12-23 15:37:42 +000070 ])
Sean Condonf4f54a12018-10-10 23:25:46 +010071 ]
72})
Sean Condonb2c483c2019-01-16 20:28:55 +000073export class ToolbarComponent extends PanelBaseImpl {
74 @Input() on: boolean = false; // Override the parent class attribute
Sean Condon91481822019-01-01 13:56:14 +000075 // deferred localization strings
76 lionFn; // Function
77 // Used to drive the display of the hosts icon - there is also another such variable on the forcesvg
78 @Input() hostsVisible: boolean = false;
79 @Input() instancesVisible: boolean = true;
80 @Input() summaryVisible: boolean = true;
81 @Input() detailsVisible: boolean = true;
82 @Input() backgroundVisible: boolean = false;
83 @Input() portsVisible: boolean = true;
Sean Condon590b34b2019-12-04 18:44:37 +000084 @Input() alarmsVisible: boolean = true;
Sean Condon91481822019-01-01 13:56:14 +000085
86 @Output() buttonEvent = new EventEmitter<string>();
Sean Condonf4f54a12018-10-10 23:25:46 +010087
88 constructor(
89 protected fs: FnService,
90 protected log: LogService,
Sean Condon91481822019-01-01 13:56:14 +000091 private lion: LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010092 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010093 super(fs, log);
Sean Condon91481822019-01-01 13:56:14 +000094
95 if (this.lion.ubercache.length === 0) {
96 this.lionFn = this.dummyLion;
97 this.lion.loadCbs.set('topo-toolbar', () => this.doLion());
98 } else {
99 this.doLion();
100 }
101
Sean Condonf4f54a12018-10-10 23:25:46 +0100102 this.log.debug('ToolbarComponent constructed');
103 }
104
Sean Condon91481822019-01-01 13:56:14 +0000105 /**
106 * Read the LION bundle for Toolbar and set up the lionFn
107 */
108 doLion() {
109 this.lionFn = this.lion.bundle('core.view.Topo');
110 }
111
112 /**
113 * As buttons are clicked on the toolbar, emit events up to the parent
114 *
115 * The toggling of the input variables here is in addition to the control
116 * of these input variables from the parent. This is so that this component
117 * may be reused and is not dependent on a particular parent implementation
118 * to work
119 * @param name The name of button clicked.
120 */
121 buttonClicked(name: string): void {
122 switch (name) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000123 case HOSTS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000124 this.hostsVisible = !this.hostsVisible;
125 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000126 case INSTANCE_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000127 this.instancesVisible = !this.instancesVisible;
128 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000129 case SUMMARY_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000130 this.summaryVisible = !this.summaryVisible;
131 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000132 case DETAILS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000133 this.detailsVisible = !this.detailsVisible;
134 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000135 case BKGRND_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000136 this.backgroundVisible = !this.backgroundVisible;
137 break;
Sean Condon590b34b2019-12-04 18:44:37 +0000138 case ALARMS_TOGGLE:
139 this.alarmsVisible = !this.alarmsVisible;
140 break;
Sean Condon91481822019-01-01 13:56:14 +0000141 default:
Sean Condon91481822019-01-01 13:56:14 +0000142 }
143 // Send a message up to let TopologyComponent know of the event
144 this.buttonEvent.emit(name);
145 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100146}