Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 2 | * Copyright 2019-present Open Networking Foundation |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 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, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 19 | FnService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 20 | PanelBaseImpl, LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 21 | } from 'gui2-fw-lib'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 22 | |
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 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 25 | export const INSTANCE_TOGGLE = 'instance-tog'; |
| 26 | export const SUMMARY_TOGGLE = 'summary-tog'; |
| 27 | export const DETAILS_TOGGLE = 'details-tog'; |
| 28 | export const HOSTS_TOGGLE = 'hosts-tog'; |
| 29 | export const OFFLINE_TOGGLE = 'offline-tog'; |
| 30 | export const PORTS_TOGGLE = 'ports-tog'; |
| 31 | export const BKGRND_TOGGLE = 'bkgrnd-tog'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 32 | export const BKGRND_SELECT = 'bkgrnd-sel'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 33 | export const CYCLELABELS_BTN = 'cycleLabels-btn'; |
| 34 | export const CYCLEHOSTLABEL_BTN = 'cycleHostLabel-btn'; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 35 | export const CYCLEGRIDDISPLAY_BTN = 'cycleGridDisplay-btn'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 36 | export const RESETZOOM_BTN = 'resetZoom-btn'; |
| 37 | export const EQMASTER_BTN = 'eqMaster-btn'; |
| 38 | export const CANCEL_TRAFFIC = 'cancel-traffic'; |
| 39 | export const ALL_TRAFFIC = 'all-traffic'; |
| 40 | export const QUICKHELP_BTN = 'quickhelp-btn'; |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 41 | export const LAYOUT_DEFAULT_BTN = 'layout-default-btn'; |
| 42 | export const LAYOUT_ACCESS_BTN = 'layout-access-btn'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 43 | |
| 44 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 45 | /* |
| 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 Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 55 | '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css', |
| 56 | './button.css' |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 57 | ], |
| 58 | animations: [ |
| 59 | trigger('toolbarState', [ |
| 60 | state('true', style({ |
| 61 | transform: 'translateX(0%)', |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 62 | // opacity: '1.0' |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 63 | })), |
| 64 | state('false', style({ |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 65 | transform: 'translateX(-93%)', |
| 66 | // opacity: '0.0' |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 67 | })), |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 68 | transition('0 => 1', animate('500ms ease-in')), |
| 69 | transition('1 => 0', animate('500ms ease-out')) |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 70 | ]) |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 71 | ] |
| 72 | }) |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 73 | export class ToolbarComponent extends PanelBaseImpl { |
| 74 | @Input() on: boolean = false; // Override the parent class attribute |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 75 | // 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; |
| 84 | |
| 85 | @Output() buttonEvent = new EventEmitter<string>(); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 86 | |
| 87 | constructor( |
| 88 | protected fs: FnService, |
| 89 | protected log: LogService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 90 | private lion: LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 91 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 92 | super(fs, log); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 93 | |
| 94 | if (this.lion.ubercache.length === 0) { |
| 95 | this.lionFn = this.dummyLion; |
| 96 | this.lion.loadCbs.set('topo-toolbar', () => this.doLion()); |
| 97 | } else { |
| 98 | this.doLion(); |
| 99 | } |
| 100 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 101 | this.log.debug('ToolbarComponent constructed'); |
| 102 | } |
| 103 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 104 | /** |
| 105 | * Read the LION bundle for Toolbar and set up the lionFn |
| 106 | */ |
| 107 | doLion() { |
| 108 | this.lionFn = this.lion.bundle('core.view.Topo'); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * As buttons are clicked on the toolbar, emit events up to the parent |
| 113 | * |
| 114 | * The toggling of the input variables here is in addition to the control |
| 115 | * of these input variables from the parent. This is so that this component |
| 116 | * may be reused and is not dependent on a particular parent implementation |
| 117 | * to work |
| 118 | * @param name The name of button clicked. |
| 119 | */ |
| 120 | buttonClicked(name: string): void { |
| 121 | switch (name) { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 122 | case HOSTS_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 123 | this.hostsVisible = !this.hostsVisible; |
| 124 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 125 | case INSTANCE_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 126 | this.instancesVisible = !this.instancesVisible; |
| 127 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 128 | case SUMMARY_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 129 | this.summaryVisible = !this.summaryVisible; |
| 130 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 131 | case DETAILS_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 132 | this.detailsVisible = !this.detailsVisible; |
| 133 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 134 | case BKGRND_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 135 | this.backgroundVisible = !this.backgroundVisible; |
| 136 | break; |
| 137 | default: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 138 | } |
| 139 | // Send a message up to let TopologyComponent know of the event |
| 140 | this.buttonEvent.emit(name); |
| 141 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 142 | } |