blob: e47fa64807d36df2e39487d8275d12f60ffee27e [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 Condonb2c483c2019-01-16 20:28:55 +000016import {
17 Component,
18 Input,
19 OnDestroy,
20 OnInit,
21 ViewEncapsulation
22} from '@angular/core';
Sean Condonf4f54a12018-10-10 23:25:46 +010023import { animate, state, style, transition, trigger } from '@angular/animations';
Sean Condon55c30532018-10-29 12:26:57 +000024import * as d3 from 'd3';
25import { TopoPanelBaseImpl } from '../topopanel.base';
Sean Condonf4f54a12018-10-10 23:25:46 +010026import {
27 LogService,
Sean Condonf4f54a12018-10-10 23:25:46 +010028 FnService,
Sean Condon55c30532018-10-29 12:26:57 +000029 WebSocketService,
30 GlyphService
Sean Condonf4f54a12018-10-10 23:25:46 +010031} from 'gui2-fw-lib';
32
Sean Condon55c30532018-10-29 12:26:57 +000033export interface SummaryResponse {
34 title: string;
35}
Sean Condonb2c483c2019-01-16 20:28:55 +000036/**
37 * ONOS GUI -- Topology Summary Module.
38 * Defines modeling of ONOS Summary Panel.
39 * Note: This component uses the d3 DOM building technique from the old GUI - this
40 * is not the Angular way of building components and should be avoided generally
41 * See DetailsPanelComponent for a better way of doing this kind of thing
Sean Condonf4f54a12018-10-10 23:25:46 +010042 */
43@Component({
44 selector: 'onos-summary',
45 templateUrl: './summary.component.html',
46 styleUrls: [
47 './summary.component.css',
Sean Condon55c30532018-10-29 12:26:57 +000048 '../../topology.common.css', '../../topology.theme.css',
Sean Condonf4f54a12018-10-10 23:25:46 +010049 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css'
50 ],
Sean Condon55c30532018-10-29 12:26:57 +000051 encapsulation: ViewEncapsulation.None,
Sean Condonf4f54a12018-10-10 23:25:46 +010052 animations: [
53 trigger('summaryPanelState', [
54 state('true', style({
55 transform: 'translateX(0%)',
56 opacity: '100'
57 })),
58 state('false', style({
59 transform: 'translateX(100%)',
60 opacity: '0'
61 })),
62 transition('0 => 1', animate('100ms ease-in')),
63 transition('1 => 0', animate('100ms ease-out'))
64 ])
65 ]
66})
Sean Condon55c30532018-10-29 12:26:57 +000067export class SummaryComponent extends TopoPanelBaseImpl implements OnInit, OnDestroy {
Sean Condonb2c483c2019-01-16 20:28:55 +000068 @Input() on: boolean = false; // Override the parent class attribute
Sean Condon55c30532018-10-29 12:26:57 +000069 private handlers: string[] = [];
70 private resp: string = 'showSummary';
71 private summaryData: SummaryResponse;
Sean Condonf4f54a12018-10-10 23:25:46 +010072
73 constructor(
74 protected fs: FnService,
75 protected log: LogService,
Sean Condon55c30532018-10-29 12:26:57 +000076 protected wss: WebSocketService,
77 protected gs: GlyphService
Sean Condonf4f54a12018-10-10 23:25:46 +010078 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010079 super(fs, log, 'summary');
Sean Condon55c30532018-10-29 12:26:57 +000080 this.summaryData = <SummaryResponse>{};
Sean Condonf4f54a12018-10-10 23:25:46 +010081 this.log.debug('SummaryComponent constructed');
82 }
83
84
85 ngOnInit() {
Sean Condon55c30532018-10-29 12:26:57 +000086 this.wss.bindHandlers(new Map<string, (data) => void>([
87 [this.resp, (data) => this.handleSummaryData(data)]
88 ]));
89 this.handlers.push(this.resp);
90
91 this.init(d3.select('#topo2-p-summary'));
Sean Condon55c30532018-10-29 12:26:57 +000092
93 this.wss.sendEvent('requestSummary', {});
Sean Condonf4f54a12018-10-10 23:25:46 +010094 }
95
Sean Condon55c30532018-10-29 12:26:57 +000096 ngOnDestroy() {
97 this.wss.sendEvent('cancelSummary', {});
98 this.wss.unbindHandlers(this.handlers);
99 }
100
101 handleSummaryData(data: SummaryResponse) {
102 this.summaryData = data;
103 this.render();
Sean Condon55c30532018-10-29 12:26:57 +0000104 }
105
106 private render() {
107 let endedWithSeparator;
108
109 this.emptyRegions();
110
111 const svg = this.appendToHeader('div')
112 .classed('icon', true)
113 .append('svg');
114 const title = this.appendToHeader('h2');
115 const table = this.appendToBody('table');
116 const tbody = table.append('tbody');
117
118 title.text(this.summaryData.title);
119 this.gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
120 endedWithSeparator = this.listProps(tbody, this.summaryData);
121 // TODO : review whether we need to use/store end-with-sep state
122 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100123}