blob: 1dff053c27a7041e37a626041d7982a803136361 [file] [log] [blame]
Matteo Scandoloc8a58c82017-08-17 17:14:38 -07001/*
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
19import {IXosConfigHelpersService} from '../services/helpers/config.helpers';
Matteo Scandoloa9fe46b2018-07-16 14:58:19 -040020import * as _ from 'lodash';
Matteo Scandoloc8a58c82017-08-17 17:14:38 -070021export 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 Scandoloa9fe46b2018-07-16 14:58:19 -040035 this.debugFields = _.orderBy(this.ConfigHelpers.form_excluded_fields);
Matteo Scandoloc8a58c82017-08-17 17:14:38 -070036 }
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
63export const xosDebugModel: angular.IComponentOptions = {
64 template: require('./debug-model.html'),
65 controllerAs: 'vm',
66 controller: XosDebugModelController,
67 bindings: {
68 ngModel: '=',
69 }
70};