Fixed SonarIssues Alerts to Bootstrap Notification
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / CLSiteDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 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 app.controller('siteDictGridController', function ($scope, PolicyAppService, modalService, $modal, Notification){
21         $( "#dialog" ).hide();
22
23         PolicyAppService.getData('getDictionary/get_ClosedLoopSiteData').then(function (data) {
24                 var j = data;
25                 $scope.data = JSON.parse(j.data);
26                 console.log($scope.data);
27                 $scope.closedLoopSiteDictionaryDatas = JSON.parse($scope.data.closedLoopSiteDictionaryDatas);
28                 console.log($scope.closedLoopSiteDictionaryDatas);
29         }, function (error) {
30                 console.log("failed");
31         });
32
33         PolicyAppService.getData('get_LockDownData').then(function(data){
34                 var j = data;
35                 $scope.data = JSON.parse(j.data);
36                 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
37                 if($scope.lockdowndata[0].lockdown == true){
38                         $scope.siteDictionaryGrid.columnDefs[0].visible = false;
39                         $scope.gridApi.grid.refresh();
40                 }else{
41                         $scope.siteDictionaryGrid.columnDefs[0].visible = true;
42                         $scope.gridApi.grid.refresh();
43                 }
44         },function(error){
45                 console.log("failed");
46         });
47
48         $scope.siteDictionaryGrid = {
49                         data : 'closedLoopSiteDictionaryDatas',
50                         enableFiltering: true,
51                         exporterCsvFilename: 'ClosedLoopSite.csv',
52                         enableGridMenu: true,
53                         enableSelectAll: true,
54                         columnDefs: [{
55                                 field: 'id', enableFiltering: false, headerCellTemplate: '' +
56                                 '<button id=\'New\' ng-click="grid.appScope.createNewSiteDictWindow()" class="btn btn-success">' + 'Create</button>',
57                                 cellTemplate:
58                                         '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editSiteDictWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
59                                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteSiteDict(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
60                         },
61                         { field: 'siteName', displayName : 'Site Name', sort: { direction: 'asc', priority: 0 }},
62                         { field: 'description'},
63                         {field: 'userCreatedBy.userName', displayName : 'Created By'},
64                         {field: 'userModifiedBy.userName', displayName : 'Modified By'},
65                         {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' },
66                         {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
67                         ],
68                         exporterMenuPdf: false,
69                         exporterPdfDefaultStyle: {fontSize: 9},
70                         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
71                         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
72                         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
73                         exporterPdfFooter: function ( currentPage, pageCount ) {
74                                 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
75                         },
76                         exporterPdfCustomFormatter: function ( docDefinition ) {
77                                 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
78                                 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
79                                 return docDefinition;
80                         },
81                         exporterFieldCallback: function(grid, row, col, input) {
82                  if( col.name == 'createdDate' || col.name == 'modifiedDate') {
83                          var date = new Date(input);
84                          return date.toString("yyyy-MM-dd HH:MM:ss a");
85                  } else {
86                          return input;
87                  }
88             },
89                         exporterPdfOrientation: 'portrait',
90                         exporterPdfPageSize: 'LETTER',
91                         exporterPdfMaxGridWidth: 500,
92                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
93                         onRegisterApi: function(gridApi){
94                                 $scope.gridApi = gridApi;
95                         }
96         };
97
98         $scope.editCLSite = null;
99         $scope.createNewSiteDictWindow = function(){
100                 $scope.editCLSite = null;
101                 var modalInstance = $modal.open({
102                         backdrop: 'static', keyboard: false,
103                         templateUrl : 'add_CLSite_popup.html',
104                         controller: 'editCLSiteController',
105                         resolve: {
106                                 message: function () {
107                                         var message = {
108                                                         closedLoopSiteDictionaryDatas: $scope.editCLSite
109                                         };
110                                         return message;
111                                 }
112                         }
113                 });
114                 modalInstance.result.then(function(response){
115                         console.log('response', response);
116                         $scope.closedLoopSiteDictionaryDatas=response.closedLoopSiteDictionaryDatas;
117                 });
118         };
119
120         $scope.editSiteDictWindow = function(closedLoopSiteDictionaryData) {
121                 $scope.editCLSite = closedLoopSiteDictionaryData;
122                 var modalInstance = $modal.open({
123                         backdrop: 'static', keyboard: false,
124                         templateUrl : 'add_CLSite_popup.html',
125                         controller: 'editCLSiteController',
126                         resolve: {
127                                 message: function () {
128                                         var message = {
129                                                         closedLoopSiteDictionaryData: $scope.editCLSite
130                                         };
131                                         return message;
132                                 }
133                         }
134                 });
135                 modalInstance.result.then(function(response){
136                         console.log('response', response);
137                         $scope.closedLoopSiteDictionaryDatas = response.closedLoopSiteDictionaryDatas;
138                 });
139         };
140
141         $scope.deleteSiteDict = function(data) {
142                 var uuu = "searchDictionary";
143                 var postData={data: data, type: "clSite"};
144                 var searchString = "\n";
145                 $.ajax({
146                         type : 'POST',
147                         url : uuu,
148                         dataType: 'json',
149                         contentType: 'application/json',
150                         data: JSON.stringify(postData),
151                         success : function(resultList){
152                                 $scope.$apply(function(){
153                                         $scope.list =resultList.result;});
154                                 $scope.searchData = JSON.stringify(resultList.result);
155                                 $scope.searchDatas = JSON.parse($scope.searchData);        
156                                 $scope.success = true;
157                                 var i;
158                                 if($scope.searchDatas.length > 0){
159                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
160                                                 searchString += $scope.searchDatas[i] + "\n";
161                                         }       
162                                 }else{
163                                         searchString += "No Policies is Using this Value"
164                                 }
165
166                                 console.log($scope.list);
167                                 if($scope.success){
168                                         modalService.popupConfirmWin("Confirm","You are about to delete the Site Dictionary :  "+data.siteName+". \n "+searchString+" \n Do you want to continue?",
169                                                         function(){
170                                                 var uuu =  "deleteDictionary/cl_dictionary/remove_site";
171                                                 var postData={data: data};
172                                                 $.ajax({
173                                                         type : 'POST',
174                                                         url : uuu,
175                                                         dataType: 'json',
176                                                         contentType: 'application/json',
177                                                         data: JSON.stringify(postData),
178                                                         success : function(data){
179                                                                 $scope.$apply(function(){$scope.closedLoopSiteDictionaryDatas=data.closedLoopSiteDictionaryDatas;});
180                                                         },
181                                                         error : function(data){
182                                                                 console.log(data);
183                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
184                                                         }
185                                                 });
186
187                                         })}
188                         },
189                         error : function(data){
190                                 Notification.error("Error while Searching.");
191                         }
192                 });
193         };
194
195
196 });