Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
| 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 Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 16 | import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 17 | import { |
| 18 | LogService, |
| 19 | LoadingService, |
| 20 | FnService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 21 | PanelBaseImpl, LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 22 | } from 'gui2-fw-lib'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 23 | import {animate, state, style, transition, trigger} from '@angular/animations'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 24 | |
| 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 Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 35 | '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css', |
| 36 | './button.css' |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 37 | ], |
| 38 | animations: [ |
| 39 | trigger('toolbarState', [ |
| 40 | state('true', style({ |
| 41 | transform: 'translateX(0%)', |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 42 | // opacity: '1.0' |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 43 | })), |
| 44 | state('false', style({ |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 45 | transform: 'translateX(-93%)', |
| 46 | // opacity: '0.0' |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 47 | })), |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 48 | transition('0 => 1', animate('500ms ease-in')), |
| 49 | transition('1 => 0', animate('500ms ease-out')) |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 50 | ]) |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 51 | ] |
| 52 | }) |
| 53 | export class ToolbarComponent extends PanelBaseImpl implements OnInit { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 54 | // 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 65 | |
| 66 | constructor( |
| 67 | protected fs: FnService, |
| 68 | protected log: LogService, |
| 69 | protected ls: LoadingService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 70 | private lion: LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 71 | ) { |
| 72 | super(fs, ls, log); |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 73 | this.on = false; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 74 | |
| 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 82 | this.log.debug('ToolbarComponent constructed'); |
| 83 | } |
| 84 | |
| 85 | ngOnInit() { |
| 86 | } |
| 87 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 88 | /** |
| 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 127 | } |