[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / ExportFileCtrl.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 app.controller('exportCtrl', ['$scope', '$rootScope','exportService','dialogs', function($scope,$rootScope,exportService,dialogs){
25     console.log("exportCtrl");
26         
27         
28 $scope.exportfile = function(format) {
29     console.log("//////////exportfile");
30
31         console.log("exporting data inside exportfile function...."); 
32                 
33                 var formatValue=format;
34                 $rootScope.exportFormat = format;               
35                 var testsetValue=$rootScope.testset;     
36         
37         var exporturl = "/utm-service/testset_export/exportTestSet";
38                 
39         exportService.exportToUrl(testsetValue, formatValue, exporturl)
40         .then(function(results) {
41             console.log("results");
42                 
43                  var sets=results.data;
44                  console.log("Sets value"+sets);            
45              var headerValue=results.headers;
46              var fileName=headerValue.filename;
47              console.log("Filename Server value"+fileName);
48                         
49             
50                                 var hiddenElement = document.createElement('a');
51
52                                 if (angular.equals($rootScope.exportFormat,"Excel")) {
53                                         
54                                         var blob = new Blob([sets], {type: "application/vnd.ms-excel"});
55                             var objectUrl = URL.createObjectURL(blob);
56                                 //alert("EXCEL Format");
57                                 hiddenElement.href = objectUrl;
58                                 hiddenElement.download = fileName;
59                         } else if (angular.equals($rootScope.exportFormat,"NIST")) {
60                                 //alert("NIST Format");
61                         hiddenElement.href = 'data:attachment/nist,' + encodeURI(sets);
62                         hiddenElement.download = fileName;
63                 } else {
64                                 //alert("CSV Format");
65                                 hiddenElement.href = 'data:attachment/csv,' + encodeURI(sets);
66                                 hiddenElement.download = fileName;
67                 }               
68                     
69                     hiddenElement.target = '_blank';
70                     hiddenElement.click();      
71         },
72         function(data) {
73             console.log("data");
74                 //alert("File upload failed and parameters not returned");
75         });
76     };
77     
78    /* $rootScope.exportUTMTestSet = function() {
79         console.log("exportUTMTestSet");
80         
81         
82         var dlg = dialogs.create('partials/portfolios/export_almqc_data.html','exportALMQCCtrl',{},{size:'xlg',keyboard: true,backdrop: true,windowClass: 'my-class'});
83                 dlg.result.then(function(name){
84             console.log("dlg.result");
85                         //$scope.name = name;
86                 },function(){
87                         //if(angular.equals($scope.name,''))
88                                 //$scope.name = 'You did not enter in your name!';
89                 });*/
90         
91
92         /*console.log("exporting data inside exportUTMTestSet function...."); 
93                 
94                                 
95                 var testsetValue=$rootScope.modeltestset;     
96         
97         var exporturl = "/utm-service/testset_export/exportMDTTestSet";
98                 
99         exportService.exportToUTMTestSet(testsetValue, exporturl)
100         .then(function(results) {
101                 
102                  var sets=results.data;
103                  console.log("Sets value"+sets);            
104              var headerValue=results.headers;
105              var fileName="UTMTestSet";
106              //console.log("Filename Server value"+fileName);
107                          var hiddenElement = document.createElement('a');       
108                          var blob = new Blob([sets], {type: "application/vnd.ms-excel"});
109                      var objectUrl = URL.createObjectURL(blob);
110                 //alert("EXCEL Format");
111                  hiddenElement.href = objectUrl;
112                  hiddenElement.download = fileName; 
113                  hiddenElement.target = '_blank';
114                  hiddenElement.click();         
115         },
116         function(data) {
117                 //alert("File upload failed and parameters not returned");
118         });
119     };*/
120     
121 }]);