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 | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 16 | import { |
| 17 | Component, |
| 18 | Input, |
| 19 | Output, |
| 20 | EventEmitter |
| 21 | } from '@angular/core'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 22 | import { animate, state, style, transition, trigger } from '@angular/animations'; |
| 23 | import { |
| 24 | LogService, |
| 25 | LoadingService, |
| 26 | FnService, |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 27 | PanelBaseImpl, |
| 28 | IconService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 29 | SvgUtilService, LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 30 | } from 'gui2-fw-lib'; |
| 31 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 32 | /** |
| 33 | * A model of instance information that drives each panel |
| 34 | */ |
| 35 | export interface Instance { |
| 36 | id: string; |
| 37 | ip: string; |
| 38 | online: boolean; |
| 39 | ready: boolean; |
| 40 | switches: number; |
| 41 | uiAttached: boolean; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * ONOS GUI -- Topology Instances Panel. |
| 46 | * Displays ONOS instances. The onosInstances Array gets updated by topology.service |
| 47 | * whenever a topo2AllInstances update arrives back on the WebSocket |
| 48 | * |
| 49 | * This emits a mastership event when the user clicks on an instance, to |
| 50 | * see the devices that it has mastership of. |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 51 | */ |
| 52 | @Component({ |
| 53 | selector: 'onos-instance', |
| 54 | templateUrl: './instance.component.html', |
| 55 | styleUrls: [ |
| 56 | './instance.component.css', './instance.theme.css', |
| 57 | '../../topology.common.css', |
| 58 | '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css' |
| 59 | ], |
| 60 | animations: [ |
| 61 | trigger('instancePanelState', [ |
| 62 | state('true', style({ |
| 63 | transform: 'translateX(0%)', |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 64 | opacity: '1.0' |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 65 | })), |
| 66 | state('false', style({ |
| 67 | transform: 'translateX(-100%)', |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 68 | opacity: '0.0' |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 69 | })), |
| 70 | transition('0 => 1', animate('100ms ease-in')), |
| 71 | transition('1 => 0', animate('100ms ease-out')) |
| 72 | ]) |
| 73 | ] |
| 74 | }) |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 75 | export class InstanceComponent extends PanelBaseImpl { |
| 76 | @Input() divTopPx: number = 100; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 77 | @Input() on: boolean = false; // Override the parent class attribute |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 78 | @Output() mastershipEvent = new EventEmitter<string>(); |
| 79 | public onosInstances: Array<Instance>; |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 80 | public mastership: string; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 81 | lionFn; // Function |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 82 | |
| 83 | constructor( |
| 84 | protected fs: FnService, |
| 85 | protected log: LogService, |
| 86 | protected ls: LoadingService, |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 87 | protected is: IconService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 88 | protected sus: SvgUtilService, |
| 89 | private lion: LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 90 | ) { |
| 91 | super(fs, ls, log); |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 92 | this.onosInstances = <Array<Instance>>[]; |
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-inst', () => this.doLion()); |
| 97 | } else { |
| 98 | this.doLion(); |
| 99 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 100 | this.log.debug('InstanceComponent constructed'); |
| 101 | } |
| 102 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 103 | /** |
| 104 | * Get a colour for the banner of the nth panel |
| 105 | * @param idx The index of the panel (0-6) |
| 106 | */ |
| 107 | panelColour(idx: number): string { |
| 108 | return this.sus.cat7().getColor(idx, false, ''); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 111 | /** |
| 112 | * Toggle the display of mastership |
| 113 | * If the same instance is clicked a second time then cancel display of mastership |
| 114 | * @param instId The instance to display mastership for |
| 115 | */ |
| 116 | chooseMastership(instId: string): void { |
| 117 | if (this.mastership === instId) { |
| 118 | this.mastership = ''; |
| 119 | } else { |
| 120 | this.mastership = instId; |
| 121 | } |
| 122 | this.mastershipEvent.emit(this.mastership); |
| 123 | this.log.debug('Instance', this.mastership, 'chosen on GUI'); |
| 124 | } |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * Read the LION bundle for Details panel and set up the lionFn |
| 128 | */ |
| 129 | doLion() { |
| 130 | this.lionFn = this.lion.bundle('core.view.Topo'); |
| 131 | |
| 132 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 133 | } |