Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
| 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 Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 16 | import { |
| 17 | Component, |
| 18 | Input, |
| 19 | OnDestroy, |
| 20 | OnInit, |
| 21 | ViewEncapsulation |
| 22 | } from '@angular/core'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 23 | import { animate, state, style, transition, trigger } from '@angular/animations'; |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 24 | import * as d3 from 'd3'; |
| 25 | import { TopoPanelBaseImpl } from '../topopanel.base'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 26 | import { |
| 27 | LogService, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 28 | FnService, |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 29 | WebSocketService, |
| 30 | GlyphService |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 31 | } from '../../../../gui2-fw-lib/public_api'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 32 | |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 33 | export interface SummaryResponse { |
| 34 | title: string; |
| 35 | } |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 36 | /** |
| 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 42 | */ |
| 43 | @Component({ |
| 44 | selector: 'onos-summary', |
| 45 | templateUrl: './summary.component.html', |
| 46 | styleUrls: [ |
| 47 | './summary.component.css', |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 48 | '../../topology.common.css', '../../topology.theme.css', |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 49 | '../../../../gui2-fw-lib/lib/widget/panel.css', |
| 50 | '../../../../gui2-fw-lib/lib/widget/panel-theme.css' |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 51 | ], |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 52 | encapsulation: ViewEncapsulation.None, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 53 | 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 Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 68 | export class SummaryComponent extends TopoPanelBaseImpl implements OnInit, OnDestroy { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 69 | @Input() on: boolean = false; // Override the parent class attribute |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 70 | private handlers: string[] = []; |
| 71 | private resp: string = 'showSummary'; |
| 72 | private summaryData: SummaryResponse; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 73 | |
| 74 | constructor( |
| 75 | protected fs: FnService, |
| 76 | protected log: LogService, |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 77 | protected wss: WebSocketService, |
| 78 | protected gs: GlyphService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 79 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 80 | super(fs, log, 'summary'); |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 81 | this.summaryData = <SummaryResponse>{}; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 82 | this.log.debug('SummaryComponent constructed'); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | ngOnInit() { |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 87 | this.wss.bindHandlers(new Map<string, (data) => void>([ |
| 88 | [this.resp, (data) => this.handleSummaryData(data)] |
| 89 | ])); |
| 90 | this.handlers.push(this.resp); |
| 91 | |
| 92 | this.init(d3.select('#topo2-p-summary')); |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 93 | |
| 94 | this.wss.sendEvent('requestSummary', {}); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 97 | ngOnDestroy() { |
| 98 | this.wss.sendEvent('cancelSummary', {}); |
| 99 | this.wss.unbindHandlers(this.handlers); |
| 100 | } |
| 101 | |
| 102 | handleSummaryData(data: SummaryResponse) { |
| 103 | this.summaryData = data; |
| 104 | this.render(); |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | private render() { |
| 108 | let endedWithSeparator; |
| 109 | |
| 110 | this.emptyRegions(); |
| 111 | |
| 112 | const svg = this.appendToHeader('div') |
| 113 | .classed('icon', true) |
| 114 | .append('svg'); |
| 115 | const title = this.appendToHeader('h2'); |
| 116 | const table = this.appendToBody('table'); |
| 117 | const tbody = table.append('tbody'); |
| 118 | |
| 119 | title.text(this.summaryData.title); |
| 120 | this.gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
| 121 | endedWithSeparator = this.listProps(tbody, this.summaryData); |
| 122 | // TODO : review whether we need to use/store end-with-sep state |
| 123 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 124 | } |