Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / ExportPolicyController.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 app = angular.module('abs');
24 app.controller('exportPolicyController', function ($scope, $window, ExportPolicyService, modalService, $modal, Notification){
25     $( "#dialog" ).hide();
26      $scope.linkEnable = true;  
27     $scope.gridOptions = {
28                  onRegisterApi: function(gridApi) {
29                     $scope.gridPolicyApi = gridApi;
30                 },
31                 enableSorting: true,
32                 enableFiltering: true,
33                 showTreeExpandNoChildren: true,
34                 paginationPageSizes: [10, 20, 50, 100],
35         paginationPageSize: 20,
36                 columnDefs: [{name: 'name'}, {name: 'version'}, {name: 'dateModified'}]
37    };
38     
39     $scope.files;
40     ExportPolicyService.getAutoPushPoliciesData().then(function (data1) {
41         $scope.loading = false;
42         $scope.files =  data1.data;
43         var data = data1.data;
44          
45         var id=0;
46         var writeoutNode = function(childArray, currentLevel, dataArray){
47           childArray.forEach( function(childNode){
48           if (childNode.files.length > 0){
49               childNode.$$treeLevel = currentLevel;
50               id=childNode.categoryId;
51              if(childNode.categoryId == childNode.parentCategoryId){
52                 childNode.parent='';
53               }
54            }else{
55            if((id!=childNode.parentCategoryId) || (childNode.categoryId == childNode.parentCategoryId)){
56               if(childNode.categoryId == childNode.parentCategoryId){
57                 childNode.parent='';
58               }
59               childNode.$$treeLevel = currentLevel;
60             }
61           }
62             dataArray.push( childNode );
63             writeoutNode( childNode.files, currentLevel + 1, dataArray );
64           });
65           
66         };
67           $scope.gridOptions.data = [];
68           writeoutNode(data, 0, $scope.gridOptions.data);
69     }, function (error) {
70         console.log("failed");
71     });
72     $scope.urlLink;
73     $scope.download = function(){
74          var policySelection = $scope.gridPolicyApi.selection.getSelectedRows();
75          console.log(policySelection);
76         var finalData = {
77             "policyDatas": policySelection
78         };
79         console.log(finalData);
80         var uuu = "policy_download/exportPolicy.htm";
81         var postData={exportData: finalData};
82         $.ajax({
83             type : 'POST',
84             url : uuu,
85             dataType: 'json',
86             contentType: 'application/json',
87             data: JSON.stringify(postData),
88             success : function(data){
89                 $scope.$apply(function(){
90                     $scope.data=data.data;
91                     var url = '../' + $scope.data;
92                     window.location = url;
93                     Notification.success("Policies Exported Successfully");
94                 });
95                 console.log($scope.data);
96             },
97             error : function(data){             
98                 Notification.error("Error Occured while Exporting Policy.");
99             }
100         });
101
102     };
103     
104     $scope.close = function() {
105         $modalInstance.close();
106     }; 
107
108 });