blob: 37b7a41f7be823a6b7f256e9ab3dd95a3c55f6ca [file] [log] [blame]
Sean Condon55c30532018-10-29 12:26:57 +00001/*
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 */
16import {
17 FnService,
Sean Condon55c30532018-10-29 12:26:57 +000018 LogService,
19 PanelBaseImpl
Sean Condon3b3fdab2020-04-14 09:25:00 +010020} from 'org_onosproject_onos/web/gui2-fw-lib/public_api';
Sean Condon55c30532018-10-29 12:26:57 +000021
22/**
23 * Base model of panel view - implemented by Topology Panel components
24 */
25export 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 Condon55c30532018-10-29 12:26:57 +000033 protected log: LogService,
34 protected id: string
35 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010036 super(fs, log);
Sean Condon55c30532018-10-29 12:26:57 +000037 }
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
Sean Condon03e5ad92020-05-21 16:14:54 +010081 addCell('label', lab);
Sean Condon55c30532018-10-29 12:26:57 +000082 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}