Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryGridController / MSModelDictGridController.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('msModelsDictGridController', function ($scope, MSDictionaryService,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             MSDictionaryService.getMSModelDictionaryData(papUrl).then(function (data) {
33                 var j = data;
34                 $scope.data = JSON.parse(j.data);
35                 console.log($scope.data);
36                 $scope.microServiceModelsDictionaryDatas = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
37                 console.log($scope.microServiceModelsDictionaryDatas);
38             }, function (error) {
39                 console.log("failed");
40             });
41                 
42         });
43
44     $scope.msModelsDictionaryGrid = {
45         data : 'microServiceModelsDictionaryDatas',
46         enableFiltering: true,
47         columnDefs: [{
48             field: 'id', enableFiltering: false, headerCellTemplate: '' +
49             '<button id=\'New\' ng-click="grid.appScope.createNewMSModelsWindow()" class="btn btn-success">' + 'Create</button>',
50             cellTemplate:
51                 '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteMSModels(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
52         },{ field: 'modelName', displayName : 'Micro Service Model'},
53             { field: 'description' },
54             { field: 'version', displayName : 'Model Version' },
55             {field: 'userCreatedBy.userName', displayName : 'Imported By' }
56         ]
57     };
58     $scope.editMSmodelName = null;
59     $scope.createNewMSModelsWindow = function(){
60         $scope.editMSmodelName = null;
61         var modalInstance = $modal.open({
62                 backdrop: 'static', keyboard: false,
63             templateUrl : 'add_msModel_popup.html',
64             controller: 'editMSModelController',
65             resolve: {
66                 message: function () {
67                     var message = {
68                         microServiceModelsDictionaryDatas: $scope.editMSmodelName
69                     };
70                     return message;
71                 }
72             }
73         });
74         modalInstance.result.then(function(response){
75             console.log('response', response);
76             $scope.microServiceModelsDictionaryDatas=response.microServiceModelsDictionaryDatas;
77         });
78     };
79
80     $scope.editMSModelsWindow = function(microServiceModelsDictionaryData) {
81         $scope.editMSmodelName = microServiceModelsDictionaryData;
82         var modalInstance = $modal.open({
83                 backdrop: 'static', keyboard: false,
84             templateUrl : 'add_msModel_popup.html',
85             controller: 'editMSModelController',
86             resolve: {
87                 message: function () {
88                     var message = {
89                         microServiceModelsDictionaryData: $scope.editMSmodelName
90                     };
91                     return message;
92                 }
93             }
94         });
95         modalInstance.result.then(function(response){
96             console.log('response', response);
97             $scope.microServiceModelsDictionaryDatas = response.microServiceModelsDictionaryDatas;
98         });
99     };
100
101     $scope.deleteMSModels = function(data) {
102         modalService.popupConfirmWin("Confirm","You are about to delete the MicroService Model : "+data.modelName+". Do you want to continue?",
103             function(){
104                 var uuu = papUrl + "/ecomp/ms_dictionary/remove_msModel.htm";
105                 var postData={data: data};
106                 $.ajax({
107                     type : 'POST',
108                     url : uuu,
109                     dataType: 'json',
110                     contentType: 'application/json',
111                     data: JSON.stringify(postData),
112                     success : function(data){
113                         $scope.$apply(function(){$scope.microServiceModelsDictionaryDatas=data.microServiceModelsDictionaryDatas;});
114                     },
115                     error : function(data){
116                         console.log(data);
117                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
118                     }
119                 });
120
121             })
122     };
123
124 });