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, |
Sean Condon | 058804c | 2019-04-16 09:41:52 +0100 | [diff] [blame] | 20 | EventEmitter, OnChanges, SimpleChanges |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 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, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 25 | FnService, |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 26 | PanelBaseImpl, |
| 27 | IconService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 28 | SvgUtilService, LionService |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 29 | } from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 30 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 31 | /** |
| 32 | * A model of instance information that drives each panel |
| 33 | */ |
| 34 | export interface Instance { |
| 35 | id: string; |
| 36 | ip: string; |
| 37 | online: boolean; |
| 38 | ready: boolean; |
| 39 | switches: number; |
| 40 | uiAttached: boolean; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * ONOS GUI -- Topology Instances Panel. |
| 45 | * Displays ONOS instances. The onosInstances Array gets updated by topology.service |
| 46 | * whenever a topo2AllInstances update arrives back on the WebSocket |
| 47 | * |
| 48 | * This emits a mastership event when the user clicks on an instance, to |
| 49 | * see the devices that it has mastership of. |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 50 | */ |
| 51 | @Component({ |
| 52 | selector: 'onos-instance', |
| 53 | templateUrl: './instance.component.html', |
| 54 | styleUrls: [ |
| 55 | './instance.component.css', './instance.theme.css', |
| 56 | '../../topology.common.css', |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 57 | '../../../../gui2-fw-lib/lib/widget/panel.css', |
| 58 | '../../../../gui2-fw-lib/lib/widget/panel-theme.css' |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 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 | 058804c | 2019-04-16 09:41:52 +0100 | [diff] [blame] | 75 | export class InstanceComponent extends PanelBaseImpl implements OnChanges { |
| 76 | @Input() onosInstances: Instance[] = []; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 77 | @Input() divTopPx: number = 100; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 78 | @Input() on: boolean = false; // Override the parent class attribute |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 79 | @Output() mastershipEvent = new EventEmitter<string>(); |
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, |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 86 | protected is: IconService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 87 | protected sus: SvgUtilService, |
| 88 | private lion: LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 89 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 90 | super(fs, log); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 91 | |
| 92 | if (this.lion.ubercache.length === 0) { |
| 93 | this.lionFn = this.dummyLion; |
| 94 | this.lion.loadCbs.set('topo-inst', () => this.doLion()); |
| 95 | } else { |
| 96 | this.doLion(); |
| 97 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 98 | this.log.debug('InstanceComponent constructed'); |
| 99 | } |
| 100 | |
Sean Condon | 058804c | 2019-04-16 09:41:52 +0100 | [diff] [blame] | 101 | ngOnChanges(changes: SimpleChanges): void { |
| 102 | if (changes['onosInstances']) { |
| 103 | this.onosInstances = <Instance[]>changes['onosInstances'].currentValue; |
| 104 | } |
| 105 | } |
| 106 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 107 | /** |
| 108 | * Get a colour for the banner of the nth panel |
| 109 | * @param idx The index of the panel (0-6) |
| 110 | */ |
| 111 | panelColour(idx: number): string { |
| 112 | return this.sus.cat7().getColor(idx, false, ''); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 115 | /** |
| 116 | * Toggle the display of mastership |
| 117 | * If the same instance is clicked a second time then cancel display of mastership |
| 118 | * @param instId The instance to display mastership for |
| 119 | */ |
| 120 | chooseMastership(instId: string): void { |
| 121 | if (this.mastership === instId) { |
Sean Condon | 058804c | 2019-04-16 09:41:52 +0100 | [diff] [blame] | 122 | this.mastership = undefined; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 123 | } else { |
| 124 | this.mastership = instId; |
| 125 | } |
| 126 | this.mastershipEvent.emit(this.mastership); |
| 127 | this.log.debug('Instance', this.mastership, 'chosen on GUI'); |
| 128 | } |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Read the LION bundle for Details panel and set up the lionFn |
| 132 | */ |
| 133 | doLion() { |
| 134 | this.lionFn = this.lion.bundle('core.view.Topo'); |
| 135 | |
| 136 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 137 | } |