ce1af6b1a2f0d22993018bf03f5f70d99e75e959
[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 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         console.log("policyDashboardCRUDDataController called");
23         
24         $('#dashBoardAdvanceSearch').hide();
25         
26     $scope.papCRUDTableDatasTemp = [];
27     
28     $scope.dashboardAdsearch = { isDelected: 'both', stage: 'both',  scope: "", ttlDate_after: "", ttlDate_before: ""};
29
30     PolicyAppService.getData('get_DashboardPolicyCRUDData').then(function(data){
31
32                 var j = data;
33                 $scope.data = JSON.parse(j.data);
34                 console.log($scope.data);
35                 $scope.papStatusCRUDDatas =JSON.parse($scope.data.papStatusCRUDData);
36         if($scope.papStatusCRUDDatas != null){
37             for(i = 0; i < $scope.papStatusCRUDDatas.length; i++){
38                 $scope.papCRUDTableDatasTemp.push($scope.papStatusCRUDDatas[i].map);
39             }
40             
41             $scope.papCRUDTableDatas = $scope.papCRUDTableDatasTemp;
42         } 
43                 
44         },function(error){
45                 console.log("failed");
46         });
47
48         $scope.papCRUDStatusDatas = {
49                 data : 'papCRUDTableDatas',
50                 enableFiltering: true,
51                 columnDefs: [{ field: 'id', displayName :'id'},
52                                         {field: 'scope', displayName :'Scope'},
53                                         {field: 'policyName', displayName :'Policy Name'},
54                                         {field: 'version', displayName :'Version'},
55                                         {field: 'stage', displayName :'Stage'},
56                                         {field: 'createdBy', displayName :'Created By'},
57                                         {field: 'deleted', displayName :'Deleted'},
58                                         {field: 'deleteReasonCode', displayName :'Deleted Reason'},
59                                         {field: 'deletedBy' , displayName :'Deleted By'},
60                                         {field: 'modifiedBy' , displayName :'Modified By'},
61                                         {field: 'createdDate',  displayName :'Created Date'},
62                                         {field: 'modifiedDate',  displayName :'Modified Date'}
63                 ],
64         onRegisterApi: function(gridApi){
65                 $scope.gridApi = gridApi;
66         }
67         };
68         
69     $('#ttlDate_after').datepicker({
70         dateFormat: 'yy-mm-dd',
71         changeMonth: true,
72         changeYear: true,
73         onSelect: function(date) {
74                 angular.element($('#ttlDate_after')).triggerHandler('input');
75         }
76     });
77     
78     $('#ttlDate_before').datepicker({
79         dateFormat: 'yy-mm-dd',
80         changeMonth: true,
81         changeYear: true,
82         onSelect: function(date) {
83                 angular.element($('#ttlDate_before')).triggerHandler('input');
84         }
85     });
86     
87     $scope.refresh = function(){
88         $scope.modal('advancedSearch', true);
89         $scope.temp.policy = "";
90     };
91     
92     
93         $scope.advancedSearch = function(){
94
95                  $('#dashBoardAdvanceSearch').toggle();
96                  if($('#advancedSearchArrow').hasClass('arrowdown')){
97                          $('#advancedSearchArrow').removeClass("arrowdown");
98                          $('#advancedSearchArrow').addClass("arrowup"); 
99                          
100                  }else{
101                          $('#advancedSearchArrow').removeClass("arrowup");
102                          $('#advancedSearchArrow').addClass("arrowdown"); 
103                  }
104         }
105         
106    
107     $scope.startAdvancedSearch = function(data){
108         
109                  console.log("startAdvancedSearch called");
110                  console.log(data.isDelected);
111                  console.log(data.stage);
112                  console.log(data.scope);
113                  console.log(data.ttlDate_after);
114                  console.log(data.ttlDate_before);
115                  
116                  if(data.scope == null){
117                          return;
118                  }
119                  
120        var uuu = "dashboardController/dashboardAdvancedSearch.htm";
121         
122         var postData={policyData: data};
123                 $.ajax({
124                         type : 'POST',
125                         url : uuu,
126                         dataType: 'json',
127                         contentType: 'application/json',
128                         data: JSON.stringify(postData),
129                         success : function(data){
130                                  console.log("dashboardAdvancedSearch data returned: " + data);
131                                 
132                  $scope.$apply(function(){  
133                         
134                                 var j = data;
135                                 $scope.data = JSON.parse(j.data);
136                                 console.log($scope.data);
137                                 $scope.papStatusCRUDDatas =JSON.parse($scope.data.policyStatusCRUDData);
138                                 
139                                 $scope.papCRUDTableDatasTemp = [];
140                        
141                     for(i = 0; i < $scope.papStatusCRUDDatas.length; i++){
142                         $scope.papCRUDTableDatasTemp.push($scope.papStatusCRUDDatas[i].map);
143                     }
144                     
145                     $scope.papCRUDTableDatas = $scope.papCRUDTableDatasTemp;
146                     
147                    $scope.gridApi.grid.refresh();
148                });
149                         },
150                         error : function(data){
151                                 console.log("dashboardAdvancedSearch Failed: data returned as " + data);
152                         }
153                 });
154     };
155
156 });