blob: 1ec3dbbc134375fea684793612f7f746c1c8ba61 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +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 */
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 Condon50855cf2018-12-23 15:37:42 +000023import {animate, state, style, transition, trigger} from '@angular/animations';
Sean Condonf4f54a12018-10-10 23:25:46 +010024
25/*
26 ONOS GUI -- Topology Toolbar Module.
27 Defines modeling of ONOS toolbar.
28 */
29@Component({
30 selector: 'onos-toolbar',
31 templateUrl: './toolbar.component.html',
32 styleUrls: [
33 './toolbar.component.css', './toolbar.theme.css',
34 '../../topology.common.css',
Sean Condon91481822019-01-01 13:56:14 +000035 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css',
36 './button.css'
Sean Condon50855cf2018-12-23 15:37:42 +000037 ],
38 animations: [
39 trigger('toolbarState', [
40 state('true', style({
41 transform: 'translateX(0%)',
Sean Condon91481822019-01-01 13:56:14 +000042 // opacity: '1.0'
Sean Condon50855cf2018-12-23 15:37:42 +000043 })),
44 state('false', style({
Sean Condon91481822019-01-01 13:56:14 +000045 transform: 'translateX(-93%)',
46 // opacity: '0.0'
Sean Condon50855cf2018-12-23 15:37:42 +000047 })),
Sean Condon91481822019-01-01 13:56:14 +000048 transition('0 => 1', animate('500ms ease-in')),
49 transition('1 => 0', animate('500ms ease-out'))
Sean Condon50855cf2018-12-23 15:37:42 +000050 ])
Sean Condonf4f54a12018-10-10 23:25:46 +010051 ]
52})
53export class ToolbarComponent extends PanelBaseImpl implements OnInit {
Sean Condon91481822019-01-01 13:56:14 +000054 // deferred localization strings
55 lionFn; // Function
56 // Used to drive the display of the hosts icon - there is also another such variable on the forcesvg
57 @Input() hostsVisible: boolean = false;
58 @Input() instancesVisible: boolean = true;
59 @Input() summaryVisible: boolean = true;
60 @Input() detailsVisible: boolean = true;
61 @Input() backgroundVisible: boolean = false;
62 @Input() portsVisible: boolean = true;
63
64 @Output() buttonEvent = new EventEmitter<string>();
Sean Condonf4f54a12018-10-10 23:25:46 +010065
66 constructor(
67 protected fs: FnService,
68 protected log: LogService,
69 protected ls: LoadingService,
Sean Condon91481822019-01-01 13:56:14 +000070 private lion: LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010071 ) {
72 super(fs, ls, log);
Sean Condon50855cf2018-12-23 15:37:42 +000073 this.on = false;
Sean Condon91481822019-01-01 13:56:14 +000074
75 if (this.lion.ubercache.length === 0) {
76 this.lionFn = this.dummyLion;
77 this.lion.loadCbs.set('topo-toolbar', () => this.doLion());
78 } else {
79 this.doLion();
80 }
81
Sean Condonf4f54a12018-10-10 23:25:46 +010082 this.log.debug('ToolbarComponent constructed');
83 }
84
85 ngOnInit() {
86 }
87
Sean Condon91481822019-01-01 13:56:14 +000088 /**
89 * Read the LION bundle for Toolbar and set up the lionFn
90 */
91 doLion() {
92 this.lionFn = this.lion.bundle('core.view.Topo');
93 }
94
95 /**
96 * As buttons are clicked on the toolbar, emit events up to the parent
97 *
98 * The toggling of the input variables here is in addition to the control
99 * of these input variables from the parent. This is so that this component
100 * may be reused and is not dependent on a particular parent implementation
101 * to work
102 * @param name The name of button clicked.
103 */
104 buttonClicked(name: string): void {
105 switch (name) {
106 case 'hosts-tog':
107 this.hostsVisible = !this.hostsVisible;
108 break;
109 case 'instance-tog':
110 this.instancesVisible = !this.instancesVisible;
111 break;
112 case 'summary-tog':
113 this.summaryVisible = !this.summaryVisible;
114 break;
115 case 'details-tog':
116 this.detailsVisible = !this.detailsVisible;
117 break;
118 case 'bkgrnd-tog':
119 this.backgroundVisible = !this.backgroundVisible;
120 break;
121 default:
122 this.log.warn('Unhandled toolbar click', name);
123 }
124 // Send a message up to let TopologyComponent know of the event
125 this.buttonEvent.emit(name);
126 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100127}