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