Skip to content

Commit

Permalink
Merge pull request #30 from austinthedeveloper/accept-type
Browse files Browse the repository at this point in the history
Added an Accept variable to limit file types
  • Loading branch information
bahaaldine committed Nov 26, 2015
2 parents bc3b0b5 + d2aea77 commit 4b5343c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Include the **ng-csv-import** element with its options:
<ng-csv-import content="csv.content"
header="csv.header"
separator="csv.separator"
result="csv.result"></ng-csv-import>
result="csv.result"
accept="csv.accept"></ng-csv-import>
```

- **csv.content**
Expand Down Expand Up @@ -74,3 +75,7 @@ A variable to toggle encoding visibility
- **csv.result**

A variable which will contain the result of the CSV to JSON marshalling.

- **csv.accept**

An optional variable to limit what file types are accepted. Ex. ".csv" to only accept csv file types.
22 changes: 13 additions & 9 deletions dist/angular-csv-import.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*! angular-csv-import - v0.0.20 - 2015-09-22
* Copyright (c) 2015 ; Licensed */
/*! angular-csv-import - v0.0.18 - 2015-09-04
/*! angular-csv-import - v0.0.26 - 2015-11-11
* Copyright (c) 2015 ; Licensed */
'use strict';

Expand All @@ -19,12 +17,18 @@ csvImport.directive('ngCsvImport', function() {
separatorVisible: '=?',
result: '=?',
encoding: '=?',
encodingVisible: '=?'
encodingVisible: '=?',
accept: '=?'
},
template: '<div><div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
template: '<div>'+
'<div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
'<div ng-show="encoding && encodingVisible"><div class="label">Encoding</div><span>{{encoding}}</span></div>'+
'<div ng-show="separator && separatorVisible"><div class="label">Seperator</div><span><input class="separator-input" type="text" ng-change="changeSeparator" ng-model="separator"><span></div>'+
'<div><input class="btn cta gray" type="file"/></div></div>',
'<div ng-show="separator && separatorVisible">'+
'<div class="label">Seperator</div>'+
'<span><input class="separator-input" type="text" ng-change="changeSeparator" ng-model="separator"><span>'+
'</div>'+
'<div><input class="btn cta gray" type="file" multiple accept="{{accept}}"/></div>'+
'</div>',
link: function(scope, element) {
scope.separatorVisible = scope.separatorVisible || false;
scope.headerVisible = scope.headerVisible || false;
Expand Down Expand Up @@ -88,7 +92,7 @@ csvImport.directive('ngCsvImport', function() {
var obj = {};
var currentline=lines[i].split(new RegExp(content.separator+'(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)'));
if ( currentline.length === columnCount ) {
if (content.header) {
if (content.header) {
for (var j=0; j<headers.length; j++) {
obj[headers[j]] = currentline[j];
}
Expand All @@ -104,4 +108,4 @@ csvImport.directive('ngCsvImport', function() {
};
}
};
});
});
4 changes: 2 additions & 2 deletions dist/angular-csv-import.min.js

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

20 changes: 12 additions & 8 deletions lib/angular-csv-import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/*! angular-csv-import - v0.0.18 - 2015-09-04
* Copyright (c) 2015 ; Licensed */
'use strict';

var csvImport = angular.module('ngCsvImport', []);
Expand All @@ -17,12 +15,18 @@ csvImport.directive('ngCsvImport', function() {
separatorVisible: '=?',
result: '=?',
encoding: '=?',
encodingVisible: '=?'
encodingVisible: '=?',
accept: '=?'
},
template: '<div><div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
template: '<div>'+
'<div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
'<div ng-show="encoding && encodingVisible"><div class="label">Encoding</div><span>{{encoding}}</span></div>'+
'<div ng-show="separator && separatorVisible"><div class="label">Seperator</div><span><input class="separator-input" type="text" ng-change="changeSeparator" ng-model="separator"><span></div>'+
'<div><input class="btn cta gray" type="file"/></div></div>',
'<div ng-show="separator && separatorVisible">'+
'<div class="label">Seperator</div>'+
'<span><input class="separator-input" type="text" ng-change="changeSeparator" ng-model="separator"><span>'+
'</div>'+
'<div><input class="btn cta gray" type="file" multiple accept="{{accept}}"/></div>'+
'</div>',
link: function(scope, element) {
scope.separatorVisible = scope.separatorVisible || false;
scope.headerVisible = scope.headerVisible || false;
Expand Down Expand Up @@ -86,7 +90,7 @@ csvImport.directive('ngCsvImport', function() {
var obj = {};
var currentline=lines[i].split(new RegExp(content.separator+'(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)'));
if ( currentline.length === columnCount ) {
if (content.header) {
if (content.header) {
for (var j=0; j<headers.length; j++) {
obj[headers[j]] = currentline[j];
}
Expand All @@ -102,4 +106,4 @@ csvImport.directive('ngCsvImport', function() {
};
}
};
});
});

0 comments on commit 4b5343c

Please sign in to comment.