blob: 1ae8de43360e5c485550a9f2360d174fb60a44ca [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 Condonaa4366d2018-11-02 14:29:01 +000016import {
17 Component,
18 Input,
19 Output,
Sean Condon058804c2019-04-16 09:41:52 +010020 EventEmitter, OnChanges, SimpleChanges
Sean Condonaa4366d2018-11-02 14:29:01 +000021} from '@angular/core';
Sean Condonf4f54a12018-10-10 23:25:46 +010022import { animate, state, style, transition, trigger } from '@angular/animations';
23import {
24 LogService,
Sean Condonf4f54a12018-10-10 23:25:46 +010025 FnService,
Sean Condonaa4366d2018-11-02 14:29:01 +000026 PanelBaseImpl,
27 IconService,
Sean Condon91481822019-01-01 13:56:14 +000028 SvgUtilService, LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010029} from 'gui2-fw-lib';
30
Sean Condonaa4366d2018-11-02 14:29:01 +000031/**
32 * A model of instance information that drives each panel
33 */
34export 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 Condonf4f54a12018-10-10 23:25:46 +010050 */
51@Component({
52 selector: 'onos-instance',
53 templateUrl: './instance.component.html',
54 styleUrls: [
55 './instance.component.css', './instance.theme.css',
56 '../../topology.common.css',
57 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css'
58 ],
59 animations: [
60 trigger('instancePanelState', [
61 state('true', style({
62 transform: 'translateX(0%)',
Sean Condonaa4366d2018-11-02 14:29:01 +000063 opacity: '1.0'
Sean Condonf4f54a12018-10-10 23:25:46 +010064 })),
65 state('false', style({
66 transform: 'translateX(-100%)',
Sean Condonaa4366d2018-11-02 14:29:01 +000067 opacity: '0.0'
Sean Condonf4f54a12018-10-10 23:25:46 +010068 })),
69 transition('0 => 1', animate('100ms ease-in')),
70 transition('1 => 0', animate('100ms ease-out'))
71 ])
72 ]
73})
Sean Condon058804c2019-04-16 09:41:52 +010074export class InstanceComponent extends PanelBaseImpl implements OnChanges {
75 @Input() onosInstances: Instance[] = [];
Sean Condonaa4366d2018-11-02 14:29:01 +000076 @Input() divTopPx: number = 100;
Sean Condonb2c483c2019-01-16 20:28:55 +000077 @Input() on: boolean = false; // Override the parent class attribute
Sean Condonaa4366d2018-11-02 14:29:01 +000078 @Output() mastershipEvent = new EventEmitter<string>();
Sean Condonff85fbe2019-03-16 14:28:46 +000079 public mastership: string;
Sean Condon91481822019-01-01 13:56:14 +000080 lionFn; // Function
Sean Condonf4f54a12018-10-10 23:25:46 +010081
82 constructor(
83 protected fs: FnService,
84 protected log: LogService,
Sean Condonaa4366d2018-11-02 14:29:01 +000085 protected is: IconService,
Sean Condon91481822019-01-01 13:56:14 +000086 protected sus: SvgUtilService,
87 private lion: LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010088 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010089 super(fs, log);
Sean Condon91481822019-01-01 13:56:14 +000090
91 if (this.lion.ubercache.length === 0) {
92 this.lionFn = this.dummyLion;
93 this.lion.loadCbs.set('topo-inst', () => this.doLion());
94 } else {
95 this.doLion();
96 }
Sean Condonf4f54a12018-10-10 23:25:46 +010097 this.log.debug('InstanceComponent constructed');
98 }
99
Sean Condon058804c2019-04-16 09:41:52 +0100100 ngOnChanges(changes: SimpleChanges): void {
101 if (changes['onosInstances']) {
102 this.onosInstances = <Instance[]>changes['onosInstances'].currentValue;
103 }
104 }
105
Sean Condonaa4366d2018-11-02 14:29:01 +0000106 /**
107 * Get a colour for the banner of the nth panel
108 * @param idx The index of the panel (0-6)
109 */
110 panelColour(idx: number): string {
111 return this.sus.cat7().getColor(idx, false, '');
Sean Condonf4f54a12018-10-10 23:25:46 +0100112 }
113
Sean Condonaa4366d2018-11-02 14:29:01 +0000114 /**
115 * Toggle the display of mastership
116 * If the same instance is clicked a second time then cancel display of mastership
117 * @param instId The instance to display mastership for
118 */
119 chooseMastership(instId: string): void {
120 if (this.mastership === instId) {
Sean Condon058804c2019-04-16 09:41:52 +0100121 this.mastership = undefined;
Sean Condonaa4366d2018-11-02 14:29:01 +0000122 } else {
123 this.mastership = instId;
124 }
125 this.mastershipEvent.emit(this.mastership);
126 this.log.debug('Instance', this.mastership, 'chosen on GUI');
127 }
Sean Condon91481822019-01-01 13:56:14 +0000128
129 /**
130 * Read the LION bundle for Details panel and set up the lionFn
131 */
132 doLion() {
133 this.lionFn = this.lion.bundle('core.view.Topo');
134
135 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100136}