Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryGridController / actionPolicyDictGridController.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 var Actiontype = ["REST"];
24 app.controller('actionPolicyDictGridController', function ($scope, DictionaryService,modalService, $modal, uiGridConstants,Grid, PapUrlService){
25     $( "#dialog" ).hide();
26     $scope.type = Actiontype;
27
28         var papUrl;
29         PapUrlService.getPapUrl().then(function(data) {
30                 var config = data;
31                 papUrl = config.PAP_URL;
32                 console.log(papUrl);
33                 
34             DictionaryService.getActionPolicyDictionaryData(papUrl).then(function (data) {
35                 var j = data;
36                 $scope.data = JSON.parse(j.data);
37                 console.log($scope.data);
38                 $scope.actionPolicyDictionaryDatas = JSON.parse($scope.data.actionPolicyDictionaryDatas);
39                 console.log($scope.actionPolicyDictionaryDatas);
40             }, function (error) {
41                 console.log("failed");
42             });
43             
44         });
45
46     $scope.actionPolicyDictionaryGrid = {
47                 enableFiltering: true,
48                 data: 'actionPolicyDictionaryDatas',
49                 exporterCsvFilename: 'ActionPolicyDictionary.csv',
50                 enableGridMenu: true,
51                 enableSelectAll: true,
52                 columnDefs: [{
53                         field: 'id',
54                         enableFiltering: false,
55                         headerCellTemplate: '' +
56                         '<button id=\'New\' ng-click="grid.appScope.createNewActionPolicyDictWindow()" class="btn btn-success">' + 'Create</button>',
57                         cellTemplate: '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editActionPolicyDictWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
58                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteActionPolicyDict(row.entity)" ><i class="fa fa-trash-o"></i></button> ',
59                         width: '8%'
60                 },
61                 {field: 'attributeName', displayName: 'Attribute Name'},
62                 {field: 'type'},
63                 {field: 'url'},
64                 {field: 'method'},
65                 {field: 'header', displayName: 'Headers'},
66                 {field: 'description'},
67                 {field: 'userCreatedBy.userName', displayName: 'Created By'},
68                 {field: 'userModifiedBy.userName', displayName: 'Modified By'},
69                 {field: 'createdDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''},
70                 {field: 'modifiedDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}
71                 ],
72                 exporterPdfDefaultStyle: {fontSize: 9},
73                 exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
74                 exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
75                 exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
76                 exporterPdfFooter: function ( currentPage, pageCount ) {
77                         return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
78                 },
79                 exporterPdfCustomFormatter: function ( docDefinition ) {
80                         docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
81                         docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
82                         return docDefinition;
83                 },
84                 exporterPdfOrientation: 'portrait',
85                 exporterPdfPageSize: 'LETTER',
86                 exporterPdfMaxGridWidth: 500,
87                 exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
88                 onRegisterApi: function(gridApi){
89                         $scope.gridApi = gridApi;
90                 }
91     };
92
93
94     $scope.editActionPolicyName = null;
95     $scope.createNewActionPolicyDictWindow = function () {
96         $scope.editActionPolicyName = null;
97         var modalInstance = $modal.open({
98                 backdrop: 'static', keyboard: false,
99             templateUrl: 'add_actionPolicyDict_popup.html',
100             controller: 'editActionPolicyDictController',
101             resolve: {
102                 message: function () {
103                     var message = {
104                         actionPolicyDictionaryDatas: $scope.editActionPolicyName
105                     };
106                     return message;
107                 }
108             }
109         });
110         modalInstance.result.then(function (response) {
111             console.log('response', response);
112             $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas;
113         });
114     };
115
116     $scope.editActionPolicyDictWindow = function (actionPolicyDictionaryData) {
117         $scope.editActionPolicyName = actionPolicyDictionaryData;
118         var modalInstance = $modal.open({
119                 backdrop: 'static', keyboard: false,
120             templateUrl: 'add_actionPolicyDict_popup.html',
121             controller: 'editActionPolicyDictController',
122             resolve: {
123                 message: function () {
124                     var message = {
125                         actionPolicyDictionaryData: $scope.editActionPolicyName
126                     };
127                     return message;
128                 }
129             }
130         });
131         modalInstance.result.then(function (response) {
132             console.log('response', response);
133             $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas;
134         });
135     };
136
137     $scope.deleteActionPolicyDict = function (data) {
138         modalService.popupConfirmWin("Confirm", "You are about to delete the Action Policy Dictionary Item  " + data.attributeName + ". Do you want to continue?",
139                         function () {
140                 var uuu = papUrl + "/ecomp/action_dictionary/remove_actionPolicyDict.htm";
141                 var postData = {data: data};
142                 $.ajax({
143                         type: 'POST',
144                         url: uuu,
145                         dataType: 'json',
146                         contentType: 'application/json',
147                         data: JSON.stringify(postData),
148                         success: function (data) {
149                                 $scope.$apply(function () {
150                                         $scope.actionPolicyDictionaryDatas = data.actionPolicyDictionaryDatas;
151                                 });
152                         },
153                         error: function (data) {
154                                 console.log(data);
155                                 modalService.showFailure("Fail", "Error while deleting: " + data.responseText);
156                         }
157                 });
158
159         })
160     };
161 });