Remove code duplication in pod page 61/54661/1
authorthuva4 <tharma.thuva@gmail.com>
Sat, 31 Mar 2018 05:28:08 +0000 (10:58 +0530)
committerthuva4 <tharma.thuva@gmail.com>
Sat, 31 Mar 2018 05:28:08 +0000 (10:58 +0530)
Create a service to map the object field with
the data label.

Change-Id: I0c3e96dca01a27ec4785c1426d82e115afb6c1df
Signed-off-by: thuva4 <tharma.thuva@gmail.com>
testapi/opnfv_testapi/ui/app.js
testapi/opnfv_testapi/ui/components/pods/pod/pod.html
testapi/opnfv_testapi/ui/components/pods/pod/podController.js

index b4e8d08..3fb4bc7 100644 (file)
             }
         });
 
+    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) {
index 6aace92..f9ab7c1 100644 (file)
@@ -3,33 +3,11 @@
     <div class="table-responsive">
         <table class="table"  ng-data="ctrl.data.pods">
             <tbody>
-                <tr style="padding:9px">
-                    <td class="podsTableTd">Id&nbsp;:</td>
-                    <td class="podsTableLeftTd">{{ctrl.data._id}}</td>
+                <tr ng-repeat-start="(index, detail) in ctrl.data_field"  style="padding:9px">
+                    <td class="podsTableTd">{{detail | capitalize}}&nbsp;:</td>
+                    <td width="90%" class="podsTableLeftTd">{{ctrl.data[index]}}</td>
                 </tr>
-                <tr style="padding:9px">
-                    <td class="podsTableTd">Name&nbsp;:</td>
-                    <td width="90%" class="podsTableLeftTd">{{ctrl.data.name}}</td>
-                </tr>
-                <tr style="padding:9px">
-                    <td class="podsTableTd">Creator&nbsp;:</td>
-                    <td width="90%" class="podsTableLeftTd">{{ctrl.data.creator}}</td>
-                </tr>
-                <tr style="padding:9px">
-                    <td class="podsTableTd">Role&nbsp;:</td>
-                    <td width="90%"  class="podsTableLeftTd">{{ctrl.data.role}}</td>
-                </tr>
-                <tr style="padding:9px">
-                    <td class="podsTableTd">Mode&nbsp;:</td>
-                    <td width="90%" class="podsTableLeftTd">{{ctrl.data.mode}}</td>
-                </tr>
-                <tr style="padding:9px">
-                    <td class="podsTableTd">Created&nbsp;at&nbsp;:</td>
-                    <td width="90%" class="podsTableLeftTd">{{ctrl.data['creation_date']}}</td>
-                </tr>
-                <tr style="padding:9px">
-                    <td class="podsTableTd">Details&nbsp;:</td>
-                    <td  width="90%" class="podsTableLeftTd">{{ctrl.data.details}}</td>
+                <tr ng-repeat-end=>
                 </tr>
             </tbody>
         </table>
index a2e18e8..39ba599 100644 (file)
@@ -21,7 +21,7 @@
 
     PodController.$inject = [
         '$scope', '$http', '$filter', '$state', '$window', '$uibModal', 'testapiApiUrl','raiseAlert',
-        'confirmModal'
+        'confirmModal', 'dataFieldService'
     ];
 
     /**
      * 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;