Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryGridController / attributeDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 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 /**
22  */
23 app.controller('attributeDictGridController', function ($scope, DictionaryService, PapUrlService, modalService, $modal){
24     $( "#dialog" ).hide();
25         var papUrl;
26         PapUrlService.getPapUrl().then(function(data) {
27                 var config = data;
28                 papUrl = config.PAP_URL;
29                 console.log(papUrl);
30             DictionaryService.getAttributeDictionaryData(papUrl).then(function (data) {
31                 var j = data;
32                 $scope.data = JSON.parse(j.data);
33                 console.log($scope.data);
34                 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
35                 console.log($scope.attributeDictionaryDatas);
36             }, function (error) {
37                 console.log("failed");
38             });
39         });
40     
41     $scope.exportData = function () {
42         var blob = new Blob([document.getElementById('attributeTable').innerHTML], {
43             type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
44         });
45         saveAs(blob, "Attribute.xls");
46     };
47
48     $scope.attributeDictionaryGrid = {
49         data : 'attributeDictionaryDatas',
50         enableFiltering: true,
51         exporterCsvFilename: 'Attribute.csv',
52         enableGridMenu: true,
53         enableSelectAll: true,
54         columnDefs: [{
55             field: 'id' , enableFiltering: false, headerCellTemplate: '' +
56             '<button id=\'New\' ng-click="grid.appScope.createNewAttributeWindow()" class="btn btn-success">' + 'Create</button>',
57             cellTemplate:
58             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editAttributeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
59             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteAttribute(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
60         },{ field: 'xacmlId', displayName : 'Attribute ID'},
61             { field: 'datatypeBean.shortName', displayName : 'Data Type' },
62             { field: 'attributeValue'},
63             { field: 'description' },
64             { field: 'priority' , displayName : 'Priority'},
65             {field: 'userCreatedBy.userName', displayName : 'Created By' },
66             {field: 'userModifiedBy.userName', displayName : 'Modified By'},
67             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''  },
68             {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''  }
69         ],
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         exporterPdfOrientation: 'portrait',
83         exporterPdfPageSize: 'LETTER',
84         exporterPdfMaxGridWidth: 500,
85         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
86         onRegisterApi: function(gridApi){
87                 $scope.gridApi = gridApi;
88         }
89     };
90
91
92     $scope.editAttributeName = null;
93     $scope.createNewAttributeWindow = function(){
94         $scope.editAttributeName = null;
95         var modalInstance = $modal.open({
96                 backdrop: 'static', keyboard: false,
97             templateUrl : 'add_Attribute_popup.html',
98             controller: 'editAttributeController',
99             resolve: {
100                 message: function () {
101                     var message = {
102                         attributeDictionaryDatas: $scope.editAttributeName
103                     };
104                     return message;
105                 }
106             }
107         });
108         modalInstance.result.then(function(response){
109             console.log('response', response);
110             $scope.attributeDictionaryDatas=response.attributeDictionaryDatas;
111         });
112     };
113
114     $scope.editAttributeWindow = function(attributeDictionaryData) {
115         $scope.editAttributeName = attributeDictionaryData;
116         var modalInstance = $modal.open({
117                 backdrop: 'static', keyboard: false,
118             templateUrl : 'add_Attribute_popup.html',
119             controller: 'editAttributeController',
120             resolve: {
121                 message: function () {
122                     var message = {
123                         attributeDictionaryData: $scope.editAttributeName
124                     };
125                     return message;
126                 }
127             }
128         });
129         modalInstance.result.then(function(response){
130             console.log('response', response);
131             $scope.attributeDictionaryDatas = response.attributeDictionaryDatas;
132         });
133     };
134
135     $scope.deleteAttribute = function(data) {
136         modalService.popupConfirmWin("Confirm","You are about to delete the Attribute Dictionary :  "+data.xacmlId+". \n "+searchString+" \n Do you want to continue?",
137                         function(){
138                 var uuu = papUrl + "/ecomp/attribute_dictionary/remove_attribute.htm";
139                 var postData={data: data};
140                 $.ajax({
141                         type : 'POST',
142                         url : uuu,
143                         dataType: 'json',
144                         contentType: 'application/json',
145                         data: JSON.stringify(postData),
146                         success : function(data){
147                                 $scope.$apply(function(){$scope.attributeDictionaryDatas=data.attributeDictionaryDatas;});
148                         },
149                         error : function(data){
150                                 console.log(data);
151                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
152                         }
153                 });
154
155         })
156     };
157
158
159 });