Skip to content

Commit d2aea77

Browse files
author
Austin Stewart
committed
Added an Accept variable to limit file types
1 parent b6216ae commit d2aea77

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Include the **ng-csv-import** element with its options:
4040
<ng-csv-import content="csv.content"
4141
header="csv.header"
4242
separator="csv.separator"
43-
result="csv.result"></ng-csv-import>
43+
result="csv.result"
44+
accept="csv.accept"></ng-csv-import>
4445
```
4546

4647
- **csv.content**
@@ -74,3 +75,7 @@ A variable to toggle encoding visibility
7475
- **csv.result**
7576

7677
A variable which will contain the result of the CSV to JSON marshalling.
78+
79+
- **csv.accept**
80+
81+
An optional variable to limit what file types are accepted. Ex. ".csv" to only accept csv file types.

dist/angular-csv-import.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/*! angular-csv-import - v0.0.20 - 2015-09-22
2-
* Copyright (c) 2015 ; Licensed */
3-
/*! angular-csv-import - v0.0.18 - 2015-09-04
1+
/*! angular-csv-import - v0.0.26 - 2015-11-11
42
* Copyright (c) 2015 ; Licensed */
53
'use strict';
64

@@ -19,12 +17,18 @@ csvImport.directive('ngCsvImport', function() {
1917
separatorVisible: '=?',
2018
result: '=?',
2119
encoding: '=?',
22-
encodingVisible: '=?'
20+
encodingVisible: '=?',
21+
accept: '=?'
2322
},
24-
template: '<div><div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
23+
template: '<div>'+
24+
'<div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
2525
'<div ng-show="encoding && encodingVisible"><div class="label">Encoding</div><span>{{encoding}}</span></div>'+
26-
'<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>'+
27-
'<div><input class="btn cta gray" type="file"/></div></div>',
26+
'<div ng-show="separator && separatorVisible">'+
27+
'<div class="label">Seperator</div>'+
28+
'<span><input class="separator-input" type="text" ng-change="changeSeparator" ng-model="separator"><span>'+
29+
'</div>'+
30+
'<div><input class="btn cta gray" type="file" multiple accept="{{accept}}"/></div>'+
31+
'</div>',
2832
link: function(scope, element) {
2933
scope.separatorVisible = scope.separatorVisible || false;
3034
scope.headerVisible = scope.headerVisible || false;
@@ -88,7 +92,7 @@ csvImport.directive('ngCsvImport', function() {
8892
var obj = {};
8993
var currentline=lines[i].split(new RegExp(content.separator+'(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)'));
9094
if ( currentline.length === columnCount ) {
91-
if (content.header) {
95+
if (content.header) {
9296
for (var j=0; j<headers.length; j++) {
9397
obj[headers[j]] = currentline[j];
9498
}
@@ -104,4 +108,4 @@ csvImport.directive('ngCsvImport', function() {
104108
};
105109
}
106110
};
107-
});
111+
});

dist/angular-csv-import.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/angular-csv-import.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*! angular-csv-import - v0.0.18 - 2015-09-04
2-
* Copyright (c) 2015 ; Licensed */
31
'use strict';
42

53
var csvImport = angular.module('ngCsvImport', []);
@@ -17,12 +15,18 @@ csvImport.directive('ngCsvImport', function() {
1715
separatorVisible: '=?',
1816
result: '=?',
1917
encoding: '=?',
20-
encodingVisible: '=?'
18+
encodingVisible: '=?',
19+
accept: '=?'
2120
},
22-
template: '<div><div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
21+
template: '<div>'+
22+
'<div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>'+
2323
'<div ng-show="encoding && encodingVisible"><div class="label">Encoding</div><span>{{encoding}}</span></div>'+
24-
'<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>'+
25-
'<div><input class="btn cta gray" type="file"/></div></div>',
24+
'<div ng-show="separator && separatorVisible">'+
25+
'<div class="label">Seperator</div>'+
26+
'<span><input class="separator-input" type="text" ng-change="changeSeparator" ng-model="separator"><span>'+
27+
'</div>'+
28+
'<div><input class="btn cta gray" type="file" multiple accept="{{accept}}"/></div>'+
29+
'</div>',
2630
link: function(scope, element) {
2731
scope.separatorVisible = scope.separatorVisible || false;
2832
scope.headerVisible = scope.headerVisible || false;
@@ -86,7 +90,7 @@ csvImport.directive('ngCsvImport', function() {
8690
var obj = {};
8791
var currentline=lines[i].split(new RegExp(content.separator+'(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)'));
8892
if ( currentline.length === columnCount ) {
89-
if (content.header) {
93+
if (content.header) {
9094
for (var j=0; j<headers.length; j++) {
9195
obj[headers[j]] = currentline[j];
9296
}
@@ -102,4 +106,4 @@ csvImport.directive('ngCsvImport', function() {
102106
};
103107
}
104108
};
105-
});
109+
});

0 commit comments

Comments
 (0)