Fixed Sonar issues for Console Logs
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dashboardCRUDController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2018, 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 app.controller('policyDashboardCRUDDataController', function ($scope, PolicyAppService, modalService, $modal){
22     
23     $('#dashBoardAdvanceSearch').hide();
24     
25     $scope.papCRUDTableDatasTemp = [];
26     
27     $scope.dashboardAdsearch = { isDelected: 'both', stage: 'both',  scope: "", ttlDate_after: "", ttlDate_before: ""};
28
29     PolicyAppService.getData('get_DashboardPolicyCRUDData').then(function(data){
30
31         var j = data;
32         $scope.data = JSON.parse(j.data);
33         $scope.papStatusCRUDDatas =JSON.parse($scope.data.papStatusCRUDData);
34         if($scope.papStatusCRUDDatas != null){
35             for(i = 0; i < $scope.papStatusCRUDDatas.length; i++){
36                 $scope.papCRUDTableDatasTemp.push($scope.papStatusCRUDDatas[i].map);
37             }
38             
39             $scope.papCRUDTableDatas = $scope.papCRUDTableDatasTemp;
40         } 
41         
42     });
43
44     $scope.papCRUDStatusDatas = {
45         data : 'papCRUDTableDatas',
46         enableFiltering: true,
47         columnDefs: [{ field: 'id', displayName :'id'},
48                       {field: 'scope', displayName :'Scope'},
49                     {field: 'policyName', displayName :'Policy Name'},
50                     {field: 'version', displayName :'Version'},
51                     {field: 'stage', displayName :'Stage'},
52                     {field: 'createdBy', displayName :'Created By'},
53                     {field: 'deleted', displayName :'Deleted'},
54                     {field: 'deleteReasonCode', displayName :'Deleted Reason'},
55                     {field: 'deletedBy' , displayName :'Deleted By'},
56                     {field: 'modifiedBy' , displayName :'Modified By'},
57                     {field: 'createdDate',  displayName :'Created Date'},
58                     {field: 'modifiedDate',  displayName :'Modified Date'}
59         ],
60         onRegisterApi: function(gridApi){
61             $scope.gridApi = gridApi;
62         }
63     };
64     
65     $('#ttlDate_after').datepicker({
66         dateFormat: 'yy-mm-dd',
67         changeMonth: true,
68         changeYear: true,
69         onSelect: function(date) {
70             angular.element($('#ttlDate_after')).triggerHandler('input');
71         }
72     });
73     
74     $('#ttlDate_before').datepicker({
75         dateFormat: 'yy-mm-dd',
76         changeMonth: true,
77         changeYear: true,
78         onSelect: function(date) {
79             angular.element($('#ttlDate_before')).triggerHandler('input');
80         }
81     });
82     
83     $scope.refresh = function(){
84         $scope.modal('advancedSearch', true);
85         $scope.temp.policy = "";
86     };
87     
88     
89     $scope.advancedSearch = function(){
90
91          $('#dashBoardAdvanceSearch').toggle();
92          if($('#advancedSearchArrow').hasClass('arrowdown')){
93              $('#advancedSearchArrow').removeClass("arrowdown");
94              $('#advancedSearchArrow').addClass("arrowup"); 
95              
96          }else{
97              $('#advancedSearchArrow').removeClass("arrowup");
98              $('#advancedSearchArrow').addClass("arrowdown"); 
99          }
100     }
101     
102    
103     $scope.startAdvancedSearch = function(data){
104         
105          
106          if(data.scope == null){
107              return;
108          }
109          
110        var uuu = "dashboardController/dashboardAdvancedSearch.htm";
111         
112         var postData={policyData: data};
113          $.ajax({
114              type : 'POST',
115              url : uuu,
116              dataType: 'json',
117              contentType: 'application/json',
118              data: JSON.stringify(postData),
119              success : function(data){
120                  
121                  $scope.$apply(function(){  
122                     
123                      var j = data;
124                      $scope.data = JSON.parse(j.data);
125                      $scope.papStatusCRUDDatas =JSON.parse($scope.data.policyStatusCRUDData);
126                      
127                      $scope.papCRUDTableDatasTemp = [];
128                     
129                      for(i = 0; i < $scope.papStatusCRUDDatas.length; i++){
130                          $scope.papCRUDTableDatasTemp.push($scope.papStatusCRUDDatas[i].map);
131                      }
132                      
133                      $scope.papCRUDTableDatas = $scope.papCRUDTableDatasTemp;
134                      
135                     $scope.gridApi.grid.refresh();
136                });
137              },
138              error : function(data){
139              }
140          });
141     };
142
143 });