Skip to content

Commit

Permalink
Version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
asafdav committed Oct 10, 2015
1 parent 0ef8feb commit 6ad5e86
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-csv",
"version": "0.3.5",
"version": "0.3.6",
"main": "build/ng-csv.min.js",
"dependencies": {
"angular": "~1",
Expand Down
21 changes: 18 additions & 3 deletions build/ng-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ angular.module('ngCsv.services').
arrData = responseData();
}

// Check if using keys as labels
if (angular.isDefined(options.label) && options.label && typeof options.label === 'boolean') {
var labelArray, labelString;

labelArray = [];
angular.forEach(arrData[0], function(value, label) {
this.push(that.stringifyField(label, options));
}, labelArray);
labelString = labelArray.join(options.fieldSep ? options.fieldSep : ",");
csvContent += labelString + EOL;
}

angular.forEach(arrData, function (oldRow, index) {
var row = angular.copy(arrData[index]);
var dataString, infoArray;
Expand Down Expand Up @@ -208,7 +220,8 @@ angular.module('ngCsv.directives').
lazyLoad: '@lazyLoad',
addByteOrderMarker: "@addBom",
ngClick: '&',
charset: '@charset'
charset: '@charset',
label: '&csvLabel'
},
controller: [
'$scope',
Expand Down Expand Up @@ -239,6 +252,7 @@ angular.module('ngCsv.directives').
};
if (angular.isDefined($attrs.csvHeader)) options.header = $scope.$eval($scope.header);
if (angular.isDefined($attrs.csvColumnOrder)) options.columnOrder = $scope.$eval($scope.columnOrder);
if (angular.isDefined($attrs.csvLabel)) options.label = $scope.$eval($scope.label);

options.fieldSep = $scope.fieldSep ? $scope.fieldSep : ",";

Expand Down Expand Up @@ -279,12 +293,13 @@ angular.module('ngCsv.directives').
navigator.msSaveBlob(blob, scope.getFilename());
} else {

var downloadLink = angular.element('<a></a>');
var downloadContainer = angular.element('<div data-tap-disabled="true"><a></a></div>');
var downloadLink = angular.element(downloadContainer.children()[0]);
downloadLink.attr('href', window.URL.createObjectURL(blob));
downloadLink.attr('download', scope.getFilename());
downloadLink.attr('target', '_blank');

$document.find('body').append(downloadLink);
$document.find('body').append(downloadContainer);
$timeout(function () {
downloadLink[0].click();
downloadLink.remove();
Expand Down
4 changes: 2 additions & 2 deletions build/ng-csv.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-csv",
"version": "0.3.5",
"version": "0.3.6",
"main": "build/ng-csv.min.js",
"description": "Simple directive that turns arrays and objects into downloadable CSV files",
"repository": {
Expand Down
10 changes: 5 additions & 5 deletions src/ng-csv/services/csv-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ angular.module('ngCsv.services').

// Check if using keys as labels
if (angular.isDefined(options.label) && options.label && typeof options.label === 'boolean') {
var encodingArray, labelString;
encodingArray = [];
var labelArray, labelString;

labelArray = [];
angular.forEach(arrData[0], function(value, label) {
this.push(that.stringifyField(label, options));
}, encodingArray);
labelString = encodingArray.join(options.fieldSep ? options.fieldSep : ",");
}, labelArray);
labelString = labelArray.join(options.fieldSep ? options.fieldSep : ",");
csvContent += labelString + EOL;
}

Expand Down

0 comments on commit 6ad5e86

Please sign in to comment.