Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Laboratory |
| 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 | |
| 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) { |
| 34 | tr.append('td').attr('class', cls).html(txt); |
| 35 | } |
| 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) { |
| 46 | data.propOrder.forEach(function (p) { |
| 47 | if (p === '-') { |
| 48 | addSep(el); |
| 49 | } else { |
| 50 | addProp(el, p, data.props[p]); |
| 51 | } |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | angular.module('onosWidget') |
| 56 | .factory('ListService', [ |
| 57 | function () { |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 58 | return { |
| 59 | listProps: listProps |
| 60 | }; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 61 | }]); |
| 62 | }()); |