blob: 05e8768a5b924a0c75dacb7fcb85ef08958e3246 [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,
20 EventEmitter
21} from '@angular/core';
Sean Condonf4f54a12018-10-10 23:25:46 +010022import { animate, state, style, transition, trigger } from '@angular/animations';
23import {
24 LogService,
25 LoadingService,
26 FnService,
Sean Condonaa4366d2018-11-02 14:29:01 +000027 PanelBaseImpl,
28 IconService,
29 SvgUtilService
Sean Condonf4f54a12018-10-10 23:25:46 +010030} from 'gui2-fw-lib';
31
Sean Condonaa4366d2018-11-02 14:29:01 +000032/**
33 * A model of instance information that drives each panel
34 */
35export 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 Condonf4f54a12018-10-10 23:25:46 +010051 */
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 Condonaa4366d2018-11-02 14:29:01 +000064 opacity: '1.0'
Sean Condonf4f54a12018-10-10 23:25:46 +010065 })),
66 state('false', style({
67 transform: 'translateX(-100%)',
Sean Condonaa4366d2018-11-02 14:29:01 +000068 opacity: '0.0'
Sean Condonf4f54a12018-10-10 23:25:46 +010069 })),
70 transition('0 => 1', animate('100ms ease-in')),
71 transition('1 => 0', animate('100ms ease-out'))
72 ])
73 ]
74})
Sean Condonaa4366d2018-11-02 14:29:01 +000075export class InstanceComponent extends PanelBaseImpl {
76 @Input() divTopPx: number = 100;
77 @Output() mastershipEvent = new EventEmitter<string>();
78 public onosInstances: Array<Instance>;
79 protected mastership: string;
Sean Condonf4f54a12018-10-10 23:25:46 +010080
81 constructor(
82 protected fs: FnService,
83 protected log: LogService,
84 protected ls: LoadingService,
Sean Condonaa4366d2018-11-02 14:29:01 +000085 protected is: IconService,
86 protected sus: SvgUtilService
Sean Condonf4f54a12018-10-10 23:25:46 +010087 ) {
88 super(fs, ls, log);
Sean Condonaa4366d2018-11-02 14:29:01 +000089 this.onosInstances = <Array<Instance>>[];
90 this.is.loadIconDef('active');
91 this.is.loadIconDef('uiAttached');
Sean Condonf4f54a12018-10-10 23:25:46 +010092 this.log.debug('InstanceComponent constructed');
93 }
94
Sean Condonaa4366d2018-11-02 14:29:01 +000095 /**
96 * Get a colour for the banner of the nth panel
97 * @param idx The index of the panel (0-6)
98 */
99 panelColour(idx: number): string {
100 return this.sus.cat7().getColor(idx, false, '');
Sean Condonf4f54a12018-10-10 23:25:46 +0100101 }
102
Sean Condonaa4366d2018-11-02 14:29:01 +0000103 /**
104 * Toggle the display of mastership
105 * If the same instance is clicked a second time then cancel display of mastership
106 * @param instId The instance to display mastership for
107 */
108 chooseMastership(instId: string): void {
109 if (this.mastership === instId) {
110 this.mastership = '';
111 } else {
112 this.mastership = instId;
113 }
114 this.mastershipEvent.emit(this.mastership);
115 this.log.debug('Instance', this.mastership, 'chosen on GUI');
116 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100117}