From 8d6380265299c36f6356c746460baa0cfd2ad4e1 Mon Sep 17 00:00:00 2001 From: thuva4 Date: Sat, 31 Mar 2018 10:58:08 +0530 Subject: Remove code duplication in pod page Create a service to map the object field with the data label. Change-Id: I0c3e96dca01a27ec4785c1426d82e115afb6c1df Signed-off-by: thuva4 --- testapi/opnfv_testapi/ui/app.js | 15 +++++++++++ .../opnfv_testapi/ui/components/pods/pod/pod.html | 30 +++------------------- .../ui/components/pods/pod/podController.js | 8 +++--- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/testapi/opnfv_testapi/ui/app.js b/testapi/opnfv_testapi/ui/app.js index b4e8d08..3fb4bc7 100644 --- a/testapi/opnfv_testapi/ui/app.js +++ b/testapi/opnfv_testapi/ui/app.js @@ -62,6 +62,21 @@ } }); + angular + .module('testapiApp') + .service('dataFieldService', function(){ + this.dataFunction = dataFunction + function dataFunction(data, data_field){ + Object.keys(data).forEach(function (key) { + if (typeof data[key] === 'object' && data[key] != null) { + return dataFunction(data[key], data_field); + } + data_field[key] = key.replace(/_/g, " ").trim(); + }); + return data_field; + } + }); + angular .module('testapiApp') .directive('dynamicModel', ['$compile', '$parse', function ($compile, $parse) { diff --git a/testapi/opnfv_testapi/ui/components/pods/pod/pod.html b/testapi/opnfv_testapi/ui/components/pods/pod/pod.html index 6aace92..f9ab7c1 100644 --- a/testapi/opnfv_testapi/ui/components/pods/pod/pod.html +++ b/testapi/opnfv_testapi/ui/components/pods/pod/pod.html @@ -3,33 +3,11 @@
- - - + + + - - - - - - - - - - - - - - - - - - - - - - - +
Id :{{ctrl.data._id}}
{{detail | capitalize}} :{{ctrl.data[index]}}
Name :{{ctrl.data.name}}
Creator :{{ctrl.data.creator}}
Role :{{ctrl.data.role}}
Mode :{{ctrl.data.mode}}
Created at :{{ctrl.data['creation_date']}}
Details :{{ctrl.data.details}}
diff --git a/testapi/opnfv_testapi/ui/components/pods/pod/podController.js b/testapi/opnfv_testapi/ui/components/pods/pod/podController.js index a2e18e8..39ba599 100644 --- a/testapi/opnfv_testapi/ui/components/pods/pod/podController.js +++ b/testapi/opnfv_testapi/ui/components/pods/pod/podController.js @@ -21,7 +21,7 @@ PodController.$inject = [ '$scope', '$http', '$filter', '$state', '$window', '$uibModal', 'testapiApiUrl','raiseAlert', - 'confirmModal' + 'confirmModal', 'dataFieldService' ]; /** @@ -30,11 +30,12 @@ * through pod declared in TestAPI. */ function PodController($scope, $http, $filter, $state, $window, $uibModal, testapiApiUrl, - raiseAlert, confirmModal) { + raiseAlert, confirmModal, dataFieldService) { var ctrl = this; ctrl.url = testapiApiUrl + '/pods'; ctrl.name = $state.params['name']; - ctrl.loadDetails = loadDetails + ctrl.loadDetails = loadDetails; + ctrl.data_field = {}; /** *Contact the testapi and retrevie the pod details @@ -45,6 +46,7 @@ ctrl.podsRequest = $http.get(podUrl).success(function (data) { ctrl.data = data; + ctrl.data_field = dataFieldService.dataFunction(ctrl.data, ctrl.data_field) }).catch(function (error) { ctrl.data = null; ctrl.showError = true; -- cgit 1.2.3-korg