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'; |
| 20 | export class XosDebugModelController { |
| 21 | static $inject = [ |
| 22 | 'ConfigHelpers' |
| 23 | ]; |
| 24 | |
| 25 | public debugFields: string[]; |
| 26 | |
| 27 | constructor( |
| 28 | private ConfigHelpers: IXosConfigHelpersService |
| 29 | ) { |
| 30 | |
| 31 | } |
| 32 | |
| 33 | $onInit() { |
| 34 | this.debugFields = this.ConfigHelpers.form_excluded_fields; |
| 35 | } |
| 36 | |
| 37 | public toLabel(string: string): string { |
| 38 | return this.ConfigHelpers.toLabel(string); |
| 39 | } |
| 40 | |
| 41 | // NOTE each field has his own format, so make it human readable |
| 42 | public parseField(fieldName: string, value: any): any { |
| 43 | switch (fieldName) { |
| 44 | case 'created': |
| 45 | case 'updated': |
| 46 | case 'enacted': |
| 47 | case 'policed': |
| 48 | return new Date(parseInt(value, 10) * 1000).toString(); |
| 49 | case 'backend_register': |
| 50 | return JSON.parse(value); |
| 51 | case 'policy_status': |
| 52 | case 'backend_status': |
| 53 | return value |
| 54 | .split(' // ') |
| 55 | .join('\n'); |
| 56 | default: |
| 57 | return value; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | export const xosDebugModel: angular.IComponentOptions = { |
| 63 | template: require('./debug-model.html'), |
| 64 | controllerAs: 'vm', |
| 65 | controller: XosDebugModelController, |
| 66 | bindings: { |
| 67 | ngModel: '=', |
| 68 | } |
| 69 | }; |