blob: 0c6df5dc1429aba8b8e91063fb694a9137d92479 [file] [log] [blame]
Steven Burrows86af4352016-11-16 18:19:12 -06001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Steven Burrows86af4352016-11-16 18:19:12 -06003 *
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
17/*
18 ONOS GUI -- Widget -- List Service
19 */
20
21(function () {
22 'use strict';
23
24 function addProp(el, label, value) {
25 var tr = el.append('tr'),
26 lab;
27 if (typeof label === 'string') {
28 lab = label.replace(/_/g, ' ');
29 } else {
30 lab = label;
31 }
32
33 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -070034 tr.append('td').attr('class', cls).text(txt);
Steven Burrows86af4352016-11-16 18:19:12 -060035 }
36
37 addCell('label', lab + ' :');
38 addCell('value', value);
39 }
40
41 function addSep(el) {
42 el.append('tr').append('td').attr('colspan', 2).append('hr');
43 }
44
45 function listProps(el, data) {
Simon Hunt3d875ec2017-09-07 16:52:59 -070046 var sepLast = false;
47
48 // note: track whether we end with a separator or not...
Steven Burrows86af4352016-11-16 18:19:12 -060049 data.propOrder.forEach(function (p) {
50 if (p === '-') {
51 addSep(el);
Simon Hunt3d875ec2017-09-07 16:52:59 -070052 sepLast = true;
Steven Burrows86af4352016-11-16 18:19:12 -060053 } else {
Simon Hunt3d875ec2017-09-07 16:52:59 -070054 addProp(el, data.propLabels[p], data.propValues[p]);
55 sepLast = false;
Steven Burrows86af4352016-11-16 18:19:12 -060056 }
57 });
Simon Hunt3d875ec2017-09-07 16:52:59 -070058 return sepLast;
Steven Burrows86af4352016-11-16 18:19:12 -060059 }
60
61 angular.module('onosWidget')
62 .factory('ListService', [
63 function () {
Steven Burrowsaf96a212016-12-28 12:57:02 +000064 return {
Steven Burrows1c2a9682017-07-14 16:52:46 +010065 listProps: listProps,
Steven Burrowsaf96a212016-12-28 12:57:02 +000066 };
Steven Burrows86af4352016-11-16 18:19:12 -060067 }]);
68}());