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