CLAMP Model policy creation support
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / MSModelDictionaryDataController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2019 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('MSModelDictionaryDataController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_MicroServiceDictData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.microServiceDictionaryDatas = JSON.parse($scope.data.microServiceDictionaryDatas);
28         console.log($scope.microServiceDictionaryDatas);
29     }, function (error) {
30         console.log("failed");
31     });
32     
33     PolicyAppService.getData('get_LockDownData').then(function(data){
34         var j = data;
35         $scope.data = JSON.parse(j.data);
36         $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
37         $scope.msModelsDictionaryDataGrid.columnDefs[0].visible = !$scope.lockdowndata[0].lockdown;
38                 $scope.gridApi.grid.refresh();
39     },function(error){
40         console.log("failed");
41     });
42         
43     $scope.msModelsDictionaryDataGrid = {
44             data : 'microServiceDictionaryDatas',
45             enableFiltering: true,
46             columnDefs: [{
47                 field: 'id', enableFiltering: false, headerCellTemplate: '' +
48                 '<button id=\'New\' ng-click="grid.appScope.createNewMSDictNameWindow()" class="btn btn-success">' + 'Create</button>',
49                 cellTemplate:
50                 '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editMSDictNameWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
51                 '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteMSDictName(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
52             },{ field: 'dictionaryName', displayName : 'Dictionary Name', sort: { direction: 'asc', priority: 0 }},
53                 { field: 'dictionaryUrl', displayName : 'URL' },
54                 {field: 'dictionaryDataByName', displayName : 'Dictionary Data Name'}
55             ],
56             onRegisterApi: function(gridApi){
57                                 $scope.gridApi = gridApi;
58                         }
59         };
60
61     $scope.editMSDictData = null;
62     $scope.createNewMSDictNameWindow = function(){
63         $scope.editMSDictData = null;
64         var modalInstance = $modal.open({
65                 backdrop: 'static', keyboard: false,
66             templateUrl : 'add_dictionaryData_popup.html',
67             controller: 'editMSDictController',
68             resolve: {
69                 message: function () {
70                     var message = {
71                                 microServiceDictionaryDatas: $scope.editMSDictData
72                     };
73                     return message;
74                 }
75             }
76         });
77         modalInstance.result.then(function(response){
78             console.log('response', response);
79             $scope.microServiceDictionaryDatas=response.microServiceDictionaryDatas;
80         });
81     };
82
83     $scope.editMSDictNameWindow = function(microServiceDictionaryDatas) {
84         $scope.editMSDictData = microServiceDictionaryDatas;
85         var modalInstance = $modal.open({
86                 backdrop: 'static', keyboard: false,
87             templateUrl : 'add_dictionaryData_popup.html',
88             controller: 'editMSDictController',
89             resolve: {
90                 message: function () {
91                     var message = {
92                                 microServiceDictionaryDatas: $scope.editMSDictData
93                     };
94                     return message;
95                 }
96             }
97         });
98         modalInstance.result.then(function(response){
99             console.log('response', response);
100             $scope.microServiceDictionaryDatas = response.microServiceDictionaryDatas;
101         });
102     };
103
104     $scope.deleteMSDictName = function(data) {
105         modalService.popupConfirmWin("Confirm","You are about to delete the Micro Service Config Name  "+data.name+". Do you want to continue?",
106             function(){
107                 var uuu = "deleteDictionary/ms_dictionary/remove_msDictionaryData";
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.microServiceDictionaryDatas=data.microServiceDictionaryDatas;});
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 });