implement json copypaste bulk uploader
This commit is contained in:
@@ -284,10 +284,16 @@
|
|||||||
|
|
||||||
<script type='text/mustache' class="pasteImportTemplate">
|
<script type='text/mustache' class="pasteImportTemplate">
|
||||||
<div class="dialog-header">
|
<div class="dialog-header">
|
||||||
Import raw copy & pasted data
|
Import raw copy & pasted JSON
|
||||||
</div>
|
</div>
|
||||||
<div class="dialog-body">
|
<div class="dialog-body">
|
||||||
<div class="grid-layout layout-tight layout-full">
|
<div class="grid-layout layout-tight layout-full">
|
||||||
|
<p class="info">
|
||||||
|
Paste in an array of JSON objects representing the documents that you would like to insert into the database.
|
||||||
|
</p>
|
||||||
|
<p class="info">
|
||||||
|
<code>[{woo: pizza}]</code>
|
||||||
|
</p>
|
||||||
<div class="menu-container data-table-cell-editor">
|
<div class="menu-container data-table-cell-editor">
|
||||||
<textarea class="data-table-cell-copypaste-editor" bind="textarea">{{value}}</textarea>
|
<textarea class="data-table-cell-copypaste-editor" bind="textarea">{{value}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ var recline = function() {
|
|||||||
function renderRows(response) {
|
function renderRows(response) {
|
||||||
var rows = response.rows;
|
var rows = response.rows;
|
||||||
|
|
||||||
|
if (rows.length < 1) return;
|
||||||
|
|
||||||
var tableRows = [];
|
var tableRows = [];
|
||||||
|
|
||||||
rows.map(function(row) {
|
rows.map(function(row) {
|
||||||
|
|||||||
@@ -185,6 +185,33 @@ app.after = {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
pasteImport: function() {
|
||||||
|
$('.dialog-content .okButton').click(function(e) {
|
||||||
|
util.notify("Uploading documents...", {persist: true, loader: true});
|
||||||
|
try {
|
||||||
|
var docs = JSON.parse($('.data-table-cell-copypaste-editor').val());
|
||||||
|
} catch(e) {
|
||||||
|
util.notify("JSON parse error: " + e);
|
||||||
|
}
|
||||||
|
if (docs) {
|
||||||
|
if(_.isArray(docs)) {
|
||||||
|
costco.uploadDocs(docs).then(
|
||||||
|
function(docs) {
|
||||||
|
util.notify("Data uploaded successfully!");
|
||||||
|
recline.fetchRows(false, app.offset);
|
||||||
|
util.hide('dialog');
|
||||||
|
},
|
||||||
|
function (err) {
|
||||||
|
util.hide('dialog');
|
||||||
|
util.notify("Error uploading: " + err.responseText);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
util.notify("Error: JSON must be an array of objects");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user