Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an Accept variable to limit file types #30

Merged
merged 1 commit into from
Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
};
}
};
});
});