Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / MSModelsDictController.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 var editMSModelController =  function ($scope, $modalInstance, message, $http, PapUrlService, UserInfoService, Notification){
24     if(message.microServiceModelsDictionaryData==null)
25         $scope.label='Add Micro Service Model'
26     else{
27         $scope.label='Edit Micro Service Model'
28         $scope.disableCd=true;
29     }
30     
31         var papUrl;
32         PapUrlService.getPapUrl().then(function(data) {
33                 var config = data;
34                 papUrl = config.PAP_URL;
35                 console.log(papUrl);
36                 
37         }); 
38         
39         /*getting user info from session*/
40         var loginId = null;
41         UserInfoService.getFunctionalMenuStaticDetailSession()
42                 .then(function (response) {                     
43                         loginId = response.userid;              
44          });
45         
46     $scope.editMSmodelName = message.microServiceModelsDictionaryData;
47
48     $scope.uploadFile = function(files) {
49         var fd = new FormData();
50         fd.append("file", files[0]);
51         $http.post(papUrl + "/ecomp/ms_dictionary/set_MSModelData.htm", fd, {
52             withCredentials: false,
53             headers: {'Content-Type': undefined },
54             transformRequest: angular.identity
55         }).success().error( );
56
57     };
58     
59     $scope.saveMSModel = function(microServiceModelsDictionaryData) {
60         var uuu = papUrl + "/ecomp/ms_dictionary/save_model.htm";
61         var postData={microServiceModelsDictionaryData: microServiceModelsDictionaryData, loginId: loginId};
62         $.ajax({
63             type : 'POST',
64             url : uuu,
65             dataType: 'json',
66             contentType: 'application/json',
67             data: JSON.stringify(postData),
68             success : function(data){
69                 $scope.$apply(function(){
70                     $scope.microServiceModelsDictionaryDatas=data.microServiceModelsDictionaryDatas;});
71                 if($scope.microServiceModelsDictionaryDatas == "Duplicate"){
72                         Notification.error("MS Models Dictionary exists with Same Model Name.")
73                 }else{      
74                         console.log($scope.microServiceModelsDictionaryDatas);
75                     $modalInstance.close({microServiceModelsDictionaryDatas:$scope.microServiceModelsDictionaryDatas});
76                 }
77             },
78             error : function(data){
79                 alert("Error while saving.");
80             }
81         });
82     };
83
84     $scope.close = function() {
85         $modalInstance.close();
86     };
87 }