Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryGridController / BRMSParamDictGridController.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('brmsParamDictGridController', function ($scope, DictionaryService,modalService, $modal, PapUrlService){
24     $( "#dialog" ).hide();
25     
26         var papUrl;
27         PapUrlService.getPapUrl().then(function(data) {
28                 var config = data;
29                 papUrl = config.PAP_URL;
30                 console.log(papUrl);
31                 
32             DictionaryService.getBRMSParamDictionaryData(papUrl).then(function (data) {
33                 var j = data;
34                 $scope.data = JSON.parse(j.data);
35                 console.log($scope.data);
36                 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
37                 console.log($scope.brmsParamDictionaryDatas);
38             }, function (error) {
39                 console.log("failed");
40             });
41                 
42         });
43
44     $scope.brmsParamDictionaryGrid = {
45         data : 'brmsParamDictionaryDatas',
46         enableFiltering: true,
47         exporterCsvFilename: 'BRMSParamDictionary.csv',
48         enableGridMenu: true,
49         enableSelectAll: true,
50         columnDefs: [{
51             field: 'id', enableFiltering: false, headerCellTemplate: '' +
52             '<button id=\'New\' ng-click="grid.appScope.createNewBRMSParamWindow()" class="btn btn-success">' + 'Create</button>',
53             cellTemplate:
54                 '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteBRMSParam(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
55         },
56             { field: 'ruleName', displayName : 'Rule Name'},
57             { field: 'description'},
58             {field: 'userCreatedBy.userName', displayName : 'Created By'},
59             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
60         ],
61         exporterPdfDefaultStyle: {fontSize: 9},
62         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
63         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
64         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
65         exporterPdfFooter: function ( currentPage, pageCount ) {
66          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
67         },
68         exporterPdfCustomFormatter: function ( docDefinition ) {
69          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
70          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
71          return docDefinition;
72         },
73         exporterPdfOrientation: 'portrait',
74         exporterPdfPageSize: 'LETTER',
75         exporterPdfMaxGridWidth: 500,
76         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
77         onRegisterApi: function(gridApi){
78                 $scope.gridApi = gridApi;
79         }
80     };
81
82     $scope.editBRMSParam = null;
83     $scope.createNewBRMSParamWindow = function(){
84         $scope.editBRMSParam = null;
85         var modalInstance = $modal.open({
86                 backdrop: 'static', keyboard: false,
87             templateUrl : 'add_brmsParam_popup.html',
88             controller: 'editBRMSParamController',
89             resolve: {
90                 message: function () {
91                     var message = {
92                         brmsParamDictionaryDatas: $scope.editBRMSParam
93                     };
94                     return message;
95                 }
96             }
97         });
98         modalInstance.result.then(function(response){
99             console.log('response', response);
100             $scope.brmsParamDictionaryDatas=response.brmsParamDictionaryDatas;
101         });
102     };
103
104     $scope.deleteBRMSParam = function(data) {
105         modalService.popupConfirmWin("Confirm","You are about to delete the BRMS Param Name  "+data.ruleName+". \n Do you want to continue?",
106                         function(){
107                 var uuu = papUrl + "/ecomp/brms_dictionary/remove_brmsParam.htm";
108                 var postData={data: data};
109                 $.ajax({
110                         type : 'POST',
111                         url : uuu,
112                         dataType: 'json',
113                         contentType: 'application/json',
114                         data: JSON.stringify(postData),
115                         success : function(data){
116                                 $scope.$apply(function(){$scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;});
117                         },
118                         error : function(data){
119                                 console.log(data);
120                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
121                         }
122                 });
123
124         })
125     };
126
127 });