Matteo Scandolo | c8a58c8 | 2017-08-17 17:14:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
| 17 | // NOTE this component will render the hidden model fields for debug purposes |
| 18 | |
| 19 | import {IXosConfigHelpersService} from '../services/helpers/config.helpers'; |
Matteo Scandolo | a9fe46b | 2018-07-16 14:58:19 -0400 | [diff] [blame] | 20 | import * as _ from 'lodash'; |
Matteo Scandolo | c8a58c8 | 2017-08-17 17:14:38 -0700 | [diff] [blame] | 21 | export class XosDebugModelController { |
| 22 | static $inject = [ |
| 23 | 'ConfigHelpers' |
| 24 | ]; |
| 25 | |
| 26 | public debugFields: string[]; |
| 27 | |
| 28 | constructor( |
| 29 | private ConfigHelpers: IXosConfigHelpersService |
| 30 | ) { |
| 31 | |
| 32 | } |
| 33 | |
| 34 | $onInit() { |
Matteo Scandolo | a9fe46b | 2018-07-16 14:58:19 -0400 | [diff] [blame] | 35 | this.debugFields = _.orderBy(this.ConfigHelpers.form_excluded_fields); |
Matteo Scandolo | c8a58c8 | 2017-08-17 17:14:38 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | public toLabel(string: string): string { |
| 39 | return this.ConfigHelpers.toLabel(string); |
| 40 | } |
| 41 | |
| 42 | // NOTE each field has his own format, so make it human readable |
| 43 | public parseField(fieldName: string, value: any): any { |
| 44 | switch (fieldName) { |
| 45 | case 'created': |
| 46 | case 'updated': |
| 47 | case 'enacted': |
| 48 | case 'policed': |
| 49 | return new Date(parseInt(value, 10) * 1000).toString(); |
| 50 | case 'backend_register': |
| 51 | return JSON.parse(value); |
| 52 | case 'policy_status': |
| 53 | case 'backend_status': |
| 54 | return value |
| 55 | .split(' // ') |
| 56 | .join('\n'); |
| 57 | default: |
| 58 | return value; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | export const xosDebugModel: angular.IComponentOptions = { |
| 64 | template: require('./debug-model.html'), |
| 65 | controllerAs: 'vm', |
| 66 | controller: XosDebugModelController, |
| 67 | bindings: { |
| 68 | ngModel: '=', |
| 69 | } |
| 70 | }; |