blob: c1c41f89aa8d1a3289f42c861bbc44468b63f7b0 [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 Condon55c30532018-10-29 12:26:57 +000016import {Component, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core';
Sean Condonf4f54a12018-10-10 23:25:46 +010017import { animate, state, style, transition, trigger } from '@angular/animations';
Sean Condon55c30532018-10-29 12:26:57 +000018import * as d3 from 'd3';
19import { TopoPanelBaseImpl } from '../topopanel.base';
Sean Condonf4f54a12018-10-10 23:25:46 +010020import {
21 LogService,
22 LoadingService,
23 FnService,
Sean Condon55c30532018-10-29 12:26:57 +000024 WebSocketService,
25 GlyphService
Sean Condonf4f54a12018-10-10 23:25:46 +010026} from 'gui2-fw-lib';
27
Sean Condon55c30532018-10-29 12:26:57 +000028export interface SummaryResponse {
29 title: string;
30}
Sean Condonf4f54a12018-10-10 23:25:46 +010031/*
32 ONOS GUI -- Topology Summary Module.
33 Defines modeling of ONOS Summary Panel.
34 */
35@Component({
36 selector: 'onos-summary',
37 templateUrl: './summary.component.html',
38 styleUrls: [
39 './summary.component.css',
Sean Condon55c30532018-10-29 12:26:57 +000040 '../../topology.common.css', '../../topology.theme.css',
Sean Condonf4f54a12018-10-10 23:25:46 +010041 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css'
42 ],
Sean Condon55c30532018-10-29 12:26:57 +000043 encapsulation: ViewEncapsulation.None,
Sean Condonf4f54a12018-10-10 23:25:46 +010044 animations: [
45 trigger('summaryPanelState', [
46 state('true', style({
47 transform: 'translateX(0%)',
48 opacity: '100'
49 })),
50 state('false', style({
51 transform: 'translateX(100%)',
52 opacity: '0'
53 })),
54 transition('0 => 1', animate('100ms ease-in')),
55 transition('1 => 0', animate('100ms ease-out'))
56 ])
57 ]
58})
Sean Condon55c30532018-10-29 12:26:57 +000059export class SummaryComponent extends TopoPanelBaseImpl implements OnInit, OnDestroy {
60 private handlers: string[] = [];
61 private resp: string = 'showSummary';
62 private summaryData: SummaryResponse;
Sean Condonf4f54a12018-10-10 23:25:46 +010063
64 constructor(
65 protected fs: FnService,
66 protected log: LogService,
67 protected ls: LoadingService,
Sean Condon55c30532018-10-29 12:26:57 +000068 protected wss: WebSocketService,
69 protected gs: GlyphService
Sean Condonf4f54a12018-10-10 23:25:46 +010070 ) {
Sean Condon55c30532018-10-29 12:26:57 +000071 super(fs, ls, log, 'summary');
72 this.summaryData = <SummaryResponse>{};
Sean Condonf4f54a12018-10-10 23:25:46 +010073 this.log.debug('SummaryComponent constructed');
74 }
75
76
77 ngOnInit() {
Sean Condon55c30532018-10-29 12:26:57 +000078 this.wss.bindHandlers(new Map<string, (data) => void>([
79 [this.resp, (data) => this.handleSummaryData(data)]
80 ]));
81 this.handlers.push(this.resp);
82
83 this.init(d3.select('#topo2-p-summary'));
84 this.on = true;
85
86 this.wss.sendEvent('requestSummary', {});
Sean Condonf4f54a12018-10-10 23:25:46 +010087 }
88
Sean Condon55c30532018-10-29 12:26:57 +000089 ngOnDestroy() {
90 this.wss.sendEvent('cancelSummary', {});
91 this.wss.unbindHandlers(this.handlers);
92 }
93
94 handleSummaryData(data: SummaryResponse) {
95 this.summaryData = data;
96 this.render();
Sean Condon55c30532018-10-29 12:26:57 +000097 }
98
99 private render() {
100 let endedWithSeparator;
101
102 this.emptyRegions();
103
104 const svg = this.appendToHeader('div')
105 .classed('icon', true)
106 .append('svg');
107 const title = this.appendToHeader('h2');
108 const table = this.appendToBody('table');
109 const tbody = table.append('tbody');
110
111 title.text(this.summaryData.title);
112 this.gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
113 endedWithSeparator = this.listProps(tbody, this.summaryData);
114 // TODO : review whether we need to use/store end-with-sep state
115 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100116}