4e6b9696b3a39f0514c05c53ef0cbc816f49e26c
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / MSHeaderDefaultValuesDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2018 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('msHeaderDefaultValuesDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_MicroServiceHeaderDefaultsData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.microServiceHeaderDefaultDatas = JSON.parse($scope.data.microServiceHeaderDefaultDatas);
28         console.log("microServiceHeaderDefaultDatas: " + $scope.microServiceHeaderDefaultDatas);
29     }, function (error) {
30         console.log("failed");
31     });
32
33     PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
34         var j = data;
35         $scope.data = JSON.parse(j.data);
36         console.log($scope.data);
37         $scope.microServiceModelsDictionaryDatas = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
38         console.log($scope.microServiceModelsDictionaryDatas);
39     }, function (error) {
40         console.log("failed");
41     });
42     
43         PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
44                 var j = data;
45                 $scope.data = JSON.parse(j.data);
46                 console.log("riskTypeDictionaryDatas: " + $scope.data);
47                 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
48                 console.log($scope.riskTypeDictionaryDatas);
49         }, function (error) {
50                 console.log("failed");
51         });
52         
53         PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
54                 var j = data;
55                 $scope.data = JSON.parse(j.data);
56                 console.log($scope.data);
57                 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
58                 console.log($scope.onapNameDictionaryDatas);
59         }, function (error) {
60                 console.log("failed");
61         });
62
63         PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
64                 var j = data;
65                 $scope.data = JSON.parse(j.data);
66                 console.log($scope.data);
67                 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
68                 console.log($scope.priorityDatas);
69         }, function (error) {
70                 console.log("failed");
71         });
72         
73     PolicyAppService.getData('get_LockDownData').then(function(data){
74         var j = data;
75         $scope.data = JSON.parse(j.data);
76         $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
77         if($scope.lockdowndata[0].lockdown == true){
78                 $scope.msHeaderDefaultValuesDictionaryGrid.columnDefs[0].visible = false;
79                 $scope.gridApi.grid.refresh();
80         }else{
81                 $scope.msHeaderDefaultValuesDictionaryGrid.columnDefs[0].visible = true;
82                 $scope.gridApi.grid.refresh();
83         }
84     },function(error){
85         console.log("failed");
86     });
87         
88     $scope.msHeaderDefaultValuesDictionaryGrid = {
89         data : 'microServiceHeaderDefaultDatas',
90         enableFiltering: true,
91         columnDefs: [{
92             field: 'id', enableFiltering: false, headerCellTemplate: '' +
93             '<button id=\'New\' ng-click="grid.appScope.createNewModelAttributeWindow()" class="btn btn-success">' + 'Create</button>',
94             cellTemplate:
95             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editModelHeaderDefaultsWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
96             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteModelAttribute(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
97         },{ field: 'modelName', displayName :'MicroService', sort: { direction: 'asc', priority: 0 }},
98             { field: 'guard', displayName :'Guard'}, { field: 'priority', displayName :'Priority'},{ field: 'riskType', displayName :'Risk Type'},{ field: 'riskLevel', displayName :'Risk Level'},{field: 'onapName' , displayName :'Onap Name' }
99         ]
100     };
101
102     $scope.editModelAttribute = null;
103     $scope.createNewModelAttributeWindow = function(){
104         $scope.editModelAttribute = null;
105         var modalInstance = $modal.open({
106                 backdrop: 'static', keyboard: false,
107             templateUrl : 'add_HeaderDefaultValues_popup.html',
108             controller: 'editMSHeaderDefaultValuesController',
109             resolve: {
110                 message: function () {
111                     var message = {
112                                 microServiceAttributeDictionaryDatas: $scope.editModelAttribute
113                     };
114                     return message;
115                 }
116             }
117         });
118         modalInstance.result.then(function(response){
119             console.log('response', response);
120             $scope.microServiceHeaderDefaultDatas=response.microServiceHeaderDefaultDatas;
121         });
122     };
123
124     $scope.editModelHeaderDefaultsWindow = function(modelAttributeDictionaryData) {
125         $scope.editHeaderDefaults = modelAttributeDictionaryData;
126         var modalInstance = $modal.open({
127                 backdrop: 'static', keyboard: false,
128             templateUrl : 'add_HeaderDefaultValues_popup.html',
129             controller: 'editMSHeaderDefaultValuesController',
130             resolve: {
131                 message: function () {
132                     var message = {
133                                 modelAttributeDictionaryData: $scope.editHeaderDefaults
134                     };
135                     return message;
136                 }
137             }
138         });
139         modalInstance.result.then(function(response){
140             console.log('response', response);
141             $scope.modelAttributeDictionaryDataa = response.modelAttributeDictionaryDatas;
142         });
143     };
144
145     $scope.deleteModelAttribute = function(data) {
146         modalService.popupConfirmWin("Confirm","You are about to delete the Header Default Values :  "+data.modelName+". Do you want to continue?",
147             function(){
148                 var uuu =  "deleteDictionary/ms_dictionary/remove_headerDefaults";
149                 var postData={data: data};
150                 $.ajax({
151                     type : 'POST',
152                     url : uuu,
153                     dataType: 'json',
154                     contentType: 'application/json',
155                     data: JSON.stringify(postData),
156                     success : function(data){
157                         $scope.$apply(function(){$scope.microServiceHeaderDefaultDatas=data.microServiceHeaderDefaultDatas;});
158                     },
159                     error : function(data){
160                         console.log(data);
161                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
162                     }
163                 });
164
165             })
166     };
167
168 });