blob: 3a42a0b8f032749c97842d62c35e5817f4e1d698 [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,
28 LoadingService,
29 FnService,
Sean Condon55c30532018-10-29 12:26:57 +000030 WebSocketService,
31 GlyphService
Sean Condonf4f54a12018-10-10 23:25:46 +010032} from 'gui2-fw-lib';
33
Sean Condon55c30532018-10-29 12:26:57 +000034export interface SummaryResponse {
35 title: string;
36}
Sean Condonb2c483c2019-01-16 20:28:55 +000037/**
38 * ONOS GUI -- Topology Summary Module.
39 * Defines modeling of ONOS Summary Panel.
40 * Note: This component uses the d3 DOM building technique from the old GUI - this
41 * is not the Angular way of building components and should be avoided generally
42 * See DetailsPanelComponent for a better way of doing this kind of thing
Sean Condonf4f54a12018-10-10 23:25:46 +010043 */
44@Component({
45 selector: 'onos-summary',
46 templateUrl: './summary.component.html',
47 styleUrls: [
48 './summary.component.css',
Sean Condon55c30532018-10-29 12:26:57 +000049 '../../topology.common.css', '../../topology.theme.css',
Sean Condonf4f54a12018-10-10 23:25:46 +010050 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css'
51 ],
Sean Condon55c30532018-10-29 12:26:57 +000052 encapsulation: ViewEncapsulation.None,
Sean Condonf4f54a12018-10-10 23:25:46 +010053 animations: [
54 trigger('summaryPanelState', [
55 state('true', style({
56 transform: 'translateX(0%)',
57 opacity: '100'
58 })),
59 state('false', style({
60 transform: 'translateX(100%)',
61 opacity: '0'
62 })),
63 transition('0 => 1', animate('100ms ease-in')),
64 transition('1 => 0', animate('100ms ease-out'))
65 ])
66 ]
67})
Sean Condon55c30532018-10-29 12:26:57 +000068export class SummaryComponent extends TopoPanelBaseImpl implements OnInit, OnDestroy {
Sean Condonb2c483c2019-01-16 20:28:55 +000069 @Input() on: boolean = false; // Override the parent class attribute
Sean Condon55c30532018-10-29 12:26:57 +000070 private handlers: string[] = [];
71 private resp: string = 'showSummary';
72 private summaryData: SummaryResponse;
Sean Condonf4f54a12018-10-10 23:25:46 +010073
74 constructor(
75 protected fs: FnService,
76 protected log: LogService,
77 protected ls: LoadingService,
Sean Condon55c30532018-10-29 12:26:57 +000078 protected wss: WebSocketService,
79 protected gs: GlyphService
Sean Condonf4f54a12018-10-10 23:25:46 +010080 ) {
Sean Condon55c30532018-10-29 12:26:57 +000081 super(fs, ls, log, 'summary');
82 this.summaryData = <SummaryResponse>{};
Sean Condonf4f54a12018-10-10 23:25:46 +010083 this.log.debug('SummaryComponent constructed');
84 }
85
86
87 ngOnInit() {
Sean Condon55c30532018-10-29 12:26:57 +000088 this.wss.bindHandlers(new Map<string, (data) => void>([
89 [this.resp, (data) => this.handleSummaryData(data)]
90 ]));
91 this.handlers.push(this.resp);
92
93 this.init(d3.select('#topo2-p-summary'));
Sean Condon55c30532018-10-29 12:26:57 +000094
95 this.wss.sendEvent('requestSummary', {});
Sean Condonf4f54a12018-10-10 23:25:46 +010096 }
97
Sean Condon55c30532018-10-29 12:26:57 +000098 ngOnDestroy() {
99 this.wss.sendEvent('cancelSummary', {});
100 this.wss.unbindHandlers(this.handlers);
101 }
102
103 handleSummaryData(data: SummaryResponse) {
104 this.summaryData = data;
105 this.render();
Sean Condon55c30532018-10-29 12:26:57 +0000106 }
107
108 private render() {
109 let endedWithSeparator;
110
111 this.emptyRegions();
112
113 const svg = this.appendToHeader('div')
114 .classed('icon', true)
115 .append('svg');
116 const title = this.appendToHeader('h2');
117 const table = this.appendToBody('table');
118 const tbody = table.append('tbody');
119
120 title.text(this.summaryData.title);
121 this.gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
122 endedWithSeparator = this.listProps(tbody, this.summaryData);
123 // TODO : review whether we need to use/store end-with-sep state
124 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100125}