Skip to content

Commit 656b8dc

Browse files
committed
Fix(CSV Report): Fix converting to object
- Fix Create CSV report after PDF - add param for PDF view (landscape| portrait)
1 parent 3671879 commit 656b8dc

File tree

4 files changed

+77
-73
lines changed

4 files changed

+77
-73
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-export-button",
33
"description": "Angular Export Button - AngularJS directive for creating reports in csv and pdf",
4-
"version": "0.0.5",
4+
"version": "0.0.6",
55
"keywords": [
66
"angular",
77
"csv",

dist/export-dropdown.js

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,101 @@
1-
(function(window, document) {
1+
(function (window, document) {
22
angular.module('ngExportButton', ['ngExportButton.directive']);
33

44
angular.module('ngExportButton.directive', ['mgcrea.ngStrap', 'ngCsv', 'ngSanitize']);
55

6-
angular.module('ngExportButton.directive').
7-
directive('exportButton',['$modal',
8-
function($modal) {
6+
angular.module('ngExportButton.directive').directive('exportButton', ['$modal',
7+
function ($modal) {
98

10-
var linker = function(scope, element, attrs) {
9+
var linker = function (scope, element, attrs) {
1110

12-
//Init modal window instance
13-
var fileNameModal = $modal({scope: scope, template: 'templates/fileName-modal.tpl.html', show: false});
11+
//Init modal window instance
12+
var fileNameModal = $modal({scope: scope, template: 'templates/fileName-modal.tpl.html', show: false});
1413

15-
//function that open modal window
16-
scope.showModal = function() {
17-
fileNameModal.$promise.then(fileNameModal.show);
18-
};
14+
//function that open modal window
15+
scope.showModal = function () {
16+
fileNameModal.$promise.then(fileNameModal.show);
17+
};
18+
19+
20+
scope.CSVheaders = angular.copy(scope.headers);
1921

20-
//function that create and return data for csv report.
21-
scope.getSCVArray = function() {
22-
var data = [];
23-
angular.forEach(scope.resources, function(resource) {
24-
var tmp = {}
25-
angular.forEach(scope.fields, function (field) {
26-
tmp[field] = resource[field];
27-
});
28-
data.push(tmp);
22+
//function that create and return data for csv report.
23+
scope.getSCVArray = function () {
24+
var data = [];
25+
angular.forEach(scope.resources, function (resource) {
26+
var tmp = {}
27+
angular.forEach(scope.fields, function (field) {
28+
tmp[field] = resource[field];
2929
});
30-
return data;
31-
};
30+
data.push(tmp);
31+
});
32+
return data;
33+
};
34+
35+
//function that create and return data for pdf table report.
36+
scope.getPDFDef = function () {
3237

33-
//function that create and return data for pdf table report.
34-
scope.getPDFDef = function(){
35-
36-
var data = [];
37-
data.push(scope.headers);
38-
angular.forEach(scope.resources, function(resource) {
39-
var tmp = []
40-
angular.forEach(scope.fields, function (field) {
41-
tmp.push(resource[field]);
42-
});
43-
data.push(tmp);
38+
var data = [];
39+
data.push(scope.headers);
40+
angular.forEach(scope.resources, function (resource) {
41+
var tmp = []
42+
angular.forEach(scope.fields, function (field) {
43+
tmp.push(resource[field]);
4444
});
45+
data.push(tmp);
46+
});
4547

4648

47-
var pdf ={
48-
content: [
49-
{
50-
table: {
51-
headerRows: 1,
52-
width: [ 'auto', 'auto', 'auto' ],
53-
body: data
54-
}
49+
var pdf = {
50+
content: [
51+
{
52+
table: {
53+
headerRows: 1,
54+
width: ['auto', 'auto', 'auto'],
55+
body: data
5556
}
56-
]
57-
};
58-
59-
return pdf;
57+
}
58+
],
59+
pageOrientation: scope.pageOrientation
6060
};
6161

62-
//function that download pdf file
63-
scope.downloadPDF = function(filename) {
62+
return pdf;
63+
};
6464

65-
var documentDef = scope.getPDFDef();
65+
//function that download pdf file
66+
scope.downloadPDF = function (filename) {
6667

67-
pdfMake.createPdf(documentDef).download(filename+'.pdf');
68+
var documentDef = scope.getPDFDef();
6869

69-
};
70+
pdfMake.createPdf(documentDef).download(filename + '.pdf');
7071

71-
//function that open pdf print dialog
72-
scope.printPDF = function() {
72+
};
7373

74-
var documentDef = scope.getPDFDef();
74+
//function that open pdf print dialog
75+
scope.printPDF = function () {
7576

76-
pdfMake.createPdf(documentDef).print();
77-
};
77+
var documentDef = scope.getPDFDef();
7878

79+
pdfMake.createPdf(documentDef).print();
7980
};
8081

81-
return {
82-
restrict: 'AE',
83-
scope: {
84-
fileName : '=exportFileName',
85-
resources : '=resources',
86-
fields : '=fields',
87-
headers : '=headers'
88-
},
89-
link: linker,
90-
transclude: true,
91-
templateUrl: 'templates/export-button.tpl.html'
92-
93-
};
94-
}
95-
]);
82+
};
83+
84+
return {
85+
restrict: 'AE',
86+
scope: {
87+
fileName: '=exportFileName',
88+
resources: '=resources',
89+
fields: '=fields',
90+
headers: '=headers',
91+
pageOrientation: '=pageOrientation'
92+
},
93+
link: linker,
94+
transclude: true,
95+
templateUrl: 'templates/export-button.tpl.html'
96+
97+
};
98+
}
99+
]);
96100

97101
})(window, document);

dist/export-dropdown.tpl.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/templates/fileName-modal.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h4 class="modal-title">Please select the file name</h4>
1313
<input type="text" class="form-control" placeholder="filename" data-ng-model="fileName">
1414
</div>
1515
<div class="modal-footer">
16-
<button type="button" class="btn btn-success" ng-csv="getSCVArray()" csv-header="headers" filename="{{ fileName }}.csv" >Download CSV</button>
16+
<button type="button" class="btn btn-success" ng-csv="getSCVArray()" csv-header="CSVheaders" filename="{{ fileName }}.csv" >Download CSV</button>
1717
<button type="button" class="btn btn-success" data-ng-click="downloadPDF(fileName)" >Download PDF</button>
1818
<button type="button" class="btn btn-default" ng-click="$hide()">Close</button>
1919
</div>

0 commit comments

Comments
 (0)