Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [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 | */ |
| 16 | import { |
| 17 | FnService, |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 18 | LogService, |
| 19 | PanelBaseImpl |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 20 | } from 'gui2-fw-lib/public_api'; |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Base model of panel view - implemented by Topology Panel components |
| 24 | */ |
| 25 | export abstract class TopoPanelBaseImpl extends PanelBaseImpl { |
| 26 | |
| 27 | protected header: any; |
| 28 | protected body: any; |
| 29 | protected footer: any; |
| 30 | |
| 31 | protected constructor( |
| 32 | protected fs: FnService, |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 33 | protected log: LogService, |
| 34 | protected id: string |
| 35 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 36 | super(fs, log); |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | protected init(el: any) { |
| 40 | this.header = el.append('div').classed('header', true); |
| 41 | this.body = el.append('div').classed('body', true); |
| 42 | this.footer = el.append('div').classed('footer', true); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Decode lists of props sent back through Web Socket |
| 47 | * |
| 48 | * Means that panels do not have to know property names in advance |
| 49 | * Driven by PropertyPanel on Server side |
| 50 | */ |
| 51 | listProps(el, data) { |
| 52 | let sepLast: boolean = false; |
| 53 | |
| 54 | // note: track whether we end with a separator or not... |
| 55 | data.propOrder.forEach((p) => { |
| 56 | if (p === '-') { |
| 57 | this.addSep(el); |
| 58 | sepLast = true; |
| 59 | } else { |
| 60 | this.addProp(el, data.propLabels[p], data.propValues[p]); |
| 61 | sepLast = false; |
| 62 | } |
| 63 | }); |
| 64 | return sepLast; |
| 65 | } |
| 66 | |
| 67 | addProp(el, label, value) { |
| 68 | const tr = el.append('tr'); |
| 69 | let lab; |
| 70 | |
| 71 | if (typeof label === 'string') { |
| 72 | lab = label.replace(/_/g, ' '); |
| 73 | } else { |
| 74 | lab = label; |
| 75 | } |
| 76 | |
| 77 | function addCell(cls, txt) { |
| 78 | tr.append('td').attr('class', cls).text(txt); |
| 79 | } |
| 80 | |
| 81 | addCell('label', lab + ' :'); |
| 82 | addCell('value', value); |
| 83 | } |
| 84 | |
| 85 | addSep(el) { |
| 86 | el.append('tr').append('td').attr('colspan', 2).append('hr'); |
| 87 | } |
| 88 | |
| 89 | appendToHeader(x) { |
| 90 | return this.header.append(x); |
| 91 | } |
| 92 | |
| 93 | appendToBody(x) { |
| 94 | return this.body.append(x); |
| 95 | } |
| 96 | |
| 97 | appendToFooter(x) { |
| 98 | return this.footer.append(x); |
| 99 | } |
| 100 | |
| 101 | emptyRegions() { |
| 102 | this.header.selectAll('*').remove(); |
| 103 | this.body.selectAll('*').remove(); |
| 104 | this.footer.selectAll('*').remove(); |
| 105 | } |
| 106 | |
| 107 | } |