[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / ModelAttributeDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP 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 app.controller('modelAttributeDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
28         console.log($scope.microServiceAttributeDictionaryDatas);
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('get_LockDownData').then(function(data){
44         var j = data;
45         $scope.data = JSON.parse(j.data);
46         $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
47         if($scope.lockdowndata[0].lockdown == true){
48                 $scope.modelAttributeDictionaryGrid.columnDefs[0].visible = false;
49                 $scope.gridApi.grid.refresh();
50         }else{
51                 $scope.modelAttributeDictionaryGrid.columnDefs[0].visible = true;
52                 $scope.gridApi.grid.refresh();
53         }
54     },function(error){
55         console.log("failed");
56     });
57         
58     $scope.modelAttributeDictionaryGrid = {
59         data : 'microServiceAttributeDictionaryDatas',
60         enableFiltering: true,
61         columnDefs: [{
62             field: 'id', enableFiltering: false, headerCellTemplate: '' +
63             '<button id=\'New\' ng-click="grid.appScope.createNewModelAttributeWindow()" class="btn btn-success">' + 'Create</button>',
64             cellTemplate:
65             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editModelAttributeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
66             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteModelAttribute(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
67         },{ field: 'name', displayName :'Name', sort: { direction: 'asc', priority: 0 }},
68             { field: 'value'}, {field: 'modelName' , displayName :'MicroService' }
69         ]
70     };
71
72     $scope.editModelAttribute = null;
73     $scope.createNewModelAttributeWindow = function(){
74         $scope.editModelAttribute = null;
75         var modalInstance = $modal.open({
76                 backdrop: 'static', keyboard: false,
77             templateUrl : 'add_modelAttribute_popup.html',
78             controller: 'editModelAttributeController',
79             resolve: {
80                 message: function () {
81                     var message = {
82                                 microServiceAttributeDictionaryDatas: $scope.editModelAttribute
83                     };
84                     return message;
85                 }
86             }
87         });
88         modalInstance.result.then(function(response){
89             console.log('response', response);
90             $scope.microServiceAttributeDictionaryDatas=response.microServiceAttributeDictionaryDatas;
91         });
92     };
93
94     $scope.editModelAttributeWindow = function(modelAttributeDictionaryData) {
95         $scope.editModelAttribute = modelAttributeDictionaryData;
96         var modalInstance = $modal.open({
97                 backdrop: 'static', keyboard: false,
98             templateUrl : 'add_modelAttribute_popup.html',
99             controller: 'editModelAttributeController',
100             resolve: {
101                 message: function () {
102                     var message = {
103                                 modelAttributeDictionaryData: $scope.editModelAttribute
104                     };
105                     return message;
106                 }
107             }
108         });
109         modalInstance.result.then(function(response){
110             console.log('response', response);
111             $scope.microServiceAttributeDictionaryDatas = response.microServiceAttributeDictionaryDatas;
112         });
113     };
114
115     $scope.deleteModelAttribute = function(data) {
116         modalService.popupConfirmWin("Confirm","You are about to delete the Model Attribute :  "+data.name+". Do you want to continue?",
117             function(){
118                 var uuu =  "deleteDictionary/ms_dictionary/remove_modelAttribute";
119                 var postData={data: data};
120                 $.ajax({
121                     type : 'POST',
122                     url : uuu,
123                     dataType: 'json',
124                     contentType: 'application/json',
125                     data: JSON.stringify(postData),
126                     success : function(data){
127                         $scope.$apply(function(){$scope.microServiceAttributeDictionaryDatas=data.microServiceAttributeDictionaryDatas;});
128                     },
129                     error : function(data){
130                         console.log(data);
131                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
132                     }
133                 });
134
135             })
136     };
137
138 });