From 75d3c39ab462fa42efd4128296c43e5aded86e6e Mon Sep 17 00:00:00 2001 From: Chris Langston Date: Mon, 5 May 2014 22:25:19 -0400 Subject: [PATCH 1/2] give the resolved promises the data that was resolved. --- src/ng-csv/directives/ng-csv.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ng-csv/directives/ng-csv.js b/src/ng-csv/directives/ng-csv.js index cd62fa6..84bf6ce 100644 --- a/src/ng-csv/directives/ng-csv.js +++ b/src/ng-csv/directives/ng-csv.js @@ -55,7 +55,7 @@ angular.module('ngCsv.directives', []). { var csvContent = "data:text/csv;charset=utf-8,"; - $q.when(data).then(function () + $q.when(data).then(function (responseData) { // Check if there's a provided header array if (angular.isDefined($attrs.csvHeader)) @@ -82,10 +82,10 @@ angular.module('ngCsv.directives', []). var arrData; - if (angular.isArray(data)) - arrData = data; + if (angular.isArray(responseData)) + arrData = responseData; else - arrData = data(); + arrData = responseData(); angular.forEach(arrData, function(row, index) { From 7214a68c8de44a27996e23934fb9e8a4e2cf7c5a Mon Sep 17 00:00:00 2001 From: Asaf David Date: Tue, 6 May 2014 18:18:34 +0300 Subject: [PATCH 2/2] Merge Chris's change --- bower.json | 2 +- build/ng-csv.js | 12 +++++++----- build/ng-csv.min.js | 4 ++-- src/ng-csv/directives/ng-csv.js | 12 +++++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bower.json b/bower.json index f1b4cfb..9855e5f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ng-csv", - "version": "0.1.1", + "version": "0.1.2", "main": "build/ng-csv.min.js", "dependencies": { "angular": "~1", diff --git a/build/ng-csv.js b/build/ng-csv.js index 4f97fca..c4dcbae 100644 --- a/build/ng-csv.js +++ b/build/ng-csv.js @@ -82,7 +82,7 @@ angular.module('ngCsv.directives', []). { var csvContent = "data:text/csv;charset=utf-8,"; - $q.when(data).then(function () + $q.when(data).then(function (responseData) { // Check if there's a provided header array if (angular.isDefined($attrs.csvHeader)) @@ -109,10 +109,12 @@ angular.module('ngCsv.directives', []). var arrData; - if (angular.isArray(data)) - arrData = data; - else - arrData = data(); + if (angular.isArray(responseData)) { + arrData = responseData; + } + else { + arrData = responseData(); + } angular.forEach(arrData, function(row, index) { diff --git a/build/ng-csv.min.js b/build/ng-csv.min.js index 423b417..720c051 100644 --- a/build/ng-csv.min.js +++ b/build/ng-csv.min.js @@ -1,2 +1,2 @@ -/*! ngcsv 27-04-2014 */ -!function(){angular.module("ngCsv.config",[]).value("ngCsv.config",{debug:!0}).config(["$compileProvider",function(a){angular.isDefined(a.urlSanitizationWhitelist)?a.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/):a.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/)}]),angular.module("ngCsv.directives",[]),angular.module("ngCsv",["ngCsv.config","ngCsv.directives","ngSanitize"]),angular.module("ngCsv.directives",[]).directive("ngCsv",["$parse","$q",function(a,b){return{restrict:"AC",replace:!0,transclude:!0,scope:{data:"&ngCsv",filename:"@filename",header:"&csvHeader",txtDelim:"@textDelimiter",fieldSep:"@fieldSeparator",lazyLoad:"@lazyLoad",ngClick:"&"},controller:["$scope","$element","$attrs","$transclude",function(a,c,d){var e=function(b){return"string"==typeof b?(b=b.replace(/"/g,'""'),a.txtDelim&&(b=a.txtDelim+b+a.txtDelim),b):"boolean"==typeof b?b?"TRUE":"FALSE":b};a.csv="",angular.isDefined(a.lazyLoad)&&"true"==a.lazyLoad||angular.isArray(a.data)&&a.$watch("data",function(){a.buildCsv(a.data(),function(){})},!0),a.buildCsv=function(c,f){var g="data:text/csv;charset=utf-8,";b.when(c).then(function(){if(angular.isDefined(d.csvHeader)){var b,f,h=a.$eval(a.header);angular.isArray(h)?b=h:(b=[],angular.forEach(h,function(a){this.push(e(a))},b)),f=b.join(a.fieldSep?a.fieldSep:","),g+=f+"\n"}var i;i=angular.isArray(c)?c:c(),angular.forEach(i,function(b,c){var d,f;angular.isArray(b)?f=b:(f=[],angular.forEach(b,function(a){this.push(e(a))},f)),d=f.join(a.fieldSep?a.fieldSep:","),g+=c
',link:function(a,b){function c(){e[0].href="",e[0].click(),e[0].href=a.csv,e[0].click()}var d=angular.element(b.children()[0]),e=angular.element(b.children()[1]);d.bind("click",function(){a.buildCsv(a.data(),function(){c()}),a.ngClick&&a.ngClick()})}}}])}(window,document); \ No newline at end of file +/*! ngcsv 06-05-2014 */ +!function(){angular.module("ngCsv.config",[]).value("ngCsv.config",{debug:!0}).config(["$compileProvider",function(a){angular.isDefined(a.urlSanitizationWhitelist)?a.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/):a.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/)}]),angular.module("ngCsv.directives",[]),angular.module("ngCsv",["ngCsv.config","ngCsv.directives","ngSanitize"]),angular.module("ngCsv.directives",[]).directive("ngCsv",["$parse","$q",function(a,b){return{restrict:"AC",replace:!0,transclude:!0,scope:{data:"&ngCsv",filename:"@filename",header:"&csvHeader",txtDelim:"@textDelimiter",fieldSep:"@fieldSeparator",lazyLoad:"@lazyLoad",ngClick:"&"},controller:["$scope","$element","$attrs","$transclude",function(a,c,d){var e=function(b){return"string"==typeof b?(b=b.replace(/"/g,'""'),a.txtDelim&&(b=a.txtDelim+b+a.txtDelim),b):"boolean"==typeof b?b?"TRUE":"FALSE":b};a.csv="",angular.isDefined(a.lazyLoad)&&"true"==a.lazyLoad||angular.isArray(a.data)&&a.$watch("data",function(){a.buildCsv(a.data(),function(){})},!0),a.buildCsv=function(c,f){var g="data:text/csv;charset=utf-8,";b.when(c).then(function(b){if(angular.isDefined(d.csvHeader)){var c,f,h=a.$eval(a.header);angular.isArray(h)?c=h:(c=[],angular.forEach(h,function(a){this.push(e(a))},c)),f=c.join(a.fieldSep?a.fieldSep:","),g+=f+"\n"}var i;i=angular.isArray(b)?b:b(),angular.forEach(i,function(b,c){var d,f;angular.isArray(b)?f=b:(f=[],angular.forEach(b,function(a){this.push(e(a))},f)),d=f.join(a.fieldSep?a.fieldSep:","),g+=c
',link:function(a,b){function c(){e[0].href="",e[0].click(),e[0].href=a.csv,e[0].click()}var d=angular.element(b.children()[0]),e=angular.element(b.children()[1]);d.bind("click",function(){a.buildCsv(a.data(),function(){c()}),a.ngClick&&a.ngClick()})}}}])}(window,document); \ No newline at end of file diff --git a/src/ng-csv/directives/ng-csv.js b/src/ng-csv/directives/ng-csv.js index 84bf6ce..2d5e963 100644 --- a/src/ng-csv/directives/ng-csv.js +++ b/src/ng-csv/directives/ng-csv.js @@ -55,7 +55,7 @@ angular.module('ngCsv.directives', []). { var csvContent = "data:text/csv;charset=utf-8,"; - $q.when(data).then(function (responseData) + $q.when(data).then(function (responseData) { // Check if there's a provided header array if (angular.isDefined($attrs.csvHeader)) @@ -82,10 +82,12 @@ angular.module('ngCsv.directives', []). var arrData; - if (angular.isArray(responseData)) - arrData = responseData; - else - arrData = responseData(); + if (angular.isArray(responseData)) { + arrData = responseData; + } + else { + arrData = responseData(); + } angular.forEach(arrData, function(row, index) {