[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / ExportPolicyController.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 var app = appDS2;
21 app.controller('exportPolicyController', function ($scope, $window, PolicyAppService, modalService, $modal, Notification){
22     $( "#dialog" ).hide();
23      $scope.linkEnable = true;  
24     $scope.gridOptions = {
25                 data : 'policydatas',
26                  onRegisterApi: function(gridApi) {
27                     $scope.gridPolicyApi = gridApi;
28                 },
29                 enableSorting: true,
30                 enableFiltering: true,
31                 showTreeExpandNoChildren: true,
32                 paginationPageSizes: [10, 20, 50, 100],
33         paginationPageSize: 20,
34         columnDefs: [{name: 'policyName', displayName : 'Policy Name', sort: { direction: 'asc', priority: 0 }}, 
35                              {name: 'activeVersion', displayName : 'Version'}, 
36                              {name: 'modifiedDate', displayName : 'Last Modified',type: 'date', cellFilter: 'date:\'yyyy-MM-dd HH:MM:ss a\'' }]
37    };
38     
39     $scope.files;
40     PolicyAppService.getData('get_AutoPushPoliciesContainerData').then(function (data) {
41         $scope.loading = false;
42         var j = data;
43         $scope.data = JSON.parse(j.data);
44         console.log($scope.data);
45         $scope.policydatas =JSON.parse($scope.data.policydatas);
46         console.log($scope.policydatas);
47     }, function (error) {
48         console.log("failed");
49     });
50     
51     $scope.urlLink;
52     $scope.download = function(){
53          var policySelection = $scope.gridPolicyApi.selection.getSelectedRows();
54          console.log(policySelection);
55         var finalData = {
56             "policyDatas": policySelection
57         };
58         console.log(finalData);
59         var uuu = "policy_download/exportPolicy.htm";
60         var postData={exportData: finalData};
61         $.ajax({
62             type : 'POST',
63             url : uuu,
64             dataType: 'json',
65             contentType: 'application/json',
66             data: JSON.stringify(postData),
67             success : function(data){
68                 $scope.$apply(function(){
69                     $scope.data=data.data;
70                     var url = '../' + $scope.data;
71                     window.location = url;
72                     Notification.success("Policies Exported Successfully");
73                 });
74                 console.log($scope.data);
75             },
76             error : function(data){             
77                 Notification.error("Error Occured while Exporting Policy.");
78             }
79         });
80
81     };
82     
83     $scope.close = function() {
84         $modalInstance.close();
85     }; 
86
87 });