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 | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 16 | import {Component, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 17 | import { animate, state, style, transition, trigger } from '@angular/animations'; |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 18 | import * as d3 from 'd3'; |
| 19 | import { TopoPanelBaseImpl } from '../topopanel.base'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 20 | import { |
| 21 | LogService, |
| 22 | LoadingService, |
| 23 | FnService, |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 24 | WebSocketService, |
| 25 | GlyphService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 26 | } from 'gui2-fw-lib'; |
| 27 | |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 28 | export interface SummaryResponse { |
| 29 | title: string; |
| 30 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 31 | /* |
| 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 Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 40 | '../../topology.common.css', '../../topology.theme.css', |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 41 | '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css' |
| 42 | ], |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 43 | encapsulation: ViewEncapsulation.None, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 44 | 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 Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 59 | export class SummaryComponent extends TopoPanelBaseImpl implements OnInit, OnDestroy { |
| 60 | private handlers: string[] = []; |
| 61 | private resp: string = 'showSummary'; |
| 62 | private summaryData: SummaryResponse; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 63 | |
| 64 | constructor( |
| 65 | protected fs: FnService, |
| 66 | protected log: LogService, |
| 67 | protected ls: LoadingService, |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 68 | protected wss: WebSocketService, |
| 69 | protected gs: GlyphService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 70 | ) { |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 71 | super(fs, ls, log, 'summary'); |
| 72 | this.summaryData = <SummaryResponse>{}; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 73 | this.log.debug('SummaryComponent constructed'); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | ngOnInit() { |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 78 | 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 89 | 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 Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 97 | } |
| 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 116 | } |