Support for separator specification in CSV now in frontend
This commit is contained in:
parent
e695924149
commit
c16fc1204e
@ -121,6 +121,12 @@
|
||||
<input type="file" name="source" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Separator</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="separator" value="," class="spam1"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">Import »</button>
|
||||
</div>
|
||||
|
||||
@ -127,9 +127,12 @@ function setupLoader(callback) {
|
||||
$('.modal.js-import-dialog-file').modal('hide');
|
||||
var $file = $form.find('input[type="file"]')[0];
|
||||
var file = $file.files[0];
|
||||
var options = {
|
||||
separator : $form.find('input[name="separator"]').val()
|
||||
};
|
||||
recline.Backend.loadFromCSVFile(file, function(dataset) {
|
||||
callback(dataset)
|
||||
});
|
||||
}, options);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ this.recline.Backend = this.recline.Backend || {};
|
||||
var reader = new FileReader();
|
||||
// TODO
|
||||
reader.onload = function(e) {
|
||||
var dataset = my.csvToDataset(e.target.result);
|
||||
var dataset = my.csvToDataset(e.target.result, options);
|
||||
callback(dataset);
|
||||
};
|
||||
reader.onerror = function (e) {
|
||||
@ -20,7 +20,7 @@ this.recline.Backend = this.recline.Backend || {};
|
||||
};
|
||||
|
||||
my.csvToDataset = function(csvString, options) {
|
||||
var out = my.parseCSV(csvString);
|
||||
var out = my.parseCSV(csvString, options);
|
||||
fields = _.map(out[0], function(cell) {
|
||||
return { id: cell, label: cell };
|
||||
});
|
||||
@ -91,7 +91,7 @@ this.recline.Backend = this.recline.Backend || {};
|
||||
|
||||
// If we are at a EOF or EOR
|
||||
if (inQuote === false && (cur === separator || cur === "\n")) {
|
||||
field = processField(field);
|
||||
field = processField(field);
|
||||
// Add the current field to the current row
|
||||
row.push(field);
|
||||
// If this is EOR append row to output and flush row
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user