starting to refactor document state logic... wish i had pouchdb right about now
This commit is contained in:
@@ -68,7 +68,8 @@ var costco = function() {
|
|||||||
costco.uploadDocs(toUpdate).then(
|
costco.uploadDocs(toUpdate).then(
|
||||||
function(updatedDocs) {
|
function(updatedDocs) {
|
||||||
util.notify(updatedDocs.length + " documents updated successfully");
|
util.notify(updatedDocs.length + " documents updated successfully");
|
||||||
recline.fetchRows(false, app.offset);
|
recline.initializeTable(app.offset);
|
||||||
|
recline.updateDocCount();
|
||||||
dfd.resolve(updatedDocs);
|
dfd.resolve(updatedDocs);
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
@@ -85,12 +86,16 @@ var costco = function() {
|
|||||||
if(!docs.length) dfd.resolve("Failed: No docs specified");
|
if(!docs.length) dfd.resolve("Failed: No docs specified");
|
||||||
couch.request({url: app.baseURL + "api/_bulk_docs", type: "POST", data: JSON.stringify({docs: docs})})
|
couch.request({url: app.baseURL + "api/_bulk_docs", type: "POST", data: JSON.stringify({docs: docs})})
|
||||||
.then(
|
.then(
|
||||||
dfd.resolve,
|
function(resp) {ensureCommit().then(function() { dfd.resolve(resp) })},
|
||||||
function(err) { dfd.reject(err.responseText) }
|
function(err) { dfd.reject(err.responseText) }
|
||||||
);
|
);
|
||||||
return dfd.promise();
|
return dfd.promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensureCommit() {
|
||||||
|
return couch.request({url: app.baseURL + "api/_ensure_full_commit", type:'POST', data: "''"});
|
||||||
|
}
|
||||||
|
|
||||||
function deleteColumn(name) {
|
function deleteColumn(name) {
|
||||||
var deleteFunc = function(doc) {
|
var deleteFunc = function(doc) {
|
||||||
delete doc[name];
|
delete doc[name];
|
||||||
@@ -105,6 +110,7 @@ var costco = function() {
|
|||||||
mapDocs: mapDocs,
|
mapDocs: mapDocs,
|
||||||
updateDocs: updateDocs,
|
updateDocs: updateDocs,
|
||||||
uploadDocs: uploadDocs,
|
uploadDocs: uploadDocs,
|
||||||
deleteColumn: deleteColumn
|
deleteColumn: deleteColumn,
|
||||||
|
ensureCommit: ensureCommit
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
@@ -40,7 +40,11 @@ var recline = function() {
|
|||||||
function renderRows(response) {
|
function renderRows(response) {
|
||||||
var rows = response.rows;
|
var rows = response.rows;
|
||||||
|
|
||||||
if (rows.length < 1) return;
|
if (rows.length < 1) {
|
||||||
|
util.render('dataTable', 'data-table-container');
|
||||||
|
updateDocCount();
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
var tableRows = [];
|
var tableRows = [];
|
||||||
|
|
||||||
@@ -134,6 +138,16 @@ var recline = function() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateDocCount() {
|
||||||
|
return couch.request({url: app.baseURL + 'api/_all_docs?' + $.param({startkey: '"_design/"', endkey: '"_design0"'})}).then(
|
||||||
|
function ( data ) {
|
||||||
|
var ddocCount = data.rows.length;
|
||||||
|
$('#docCount').text(app.dbInfo.doc_count - ddocCount + " documents");
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function bootstrap() {
|
function bootstrap() {
|
||||||
util.registerEmitter();
|
util.registerEmitter();
|
||||||
util.listenFor(['esc', 'return']);
|
util.listenFor(['esc', 'return']);
|
||||||
@@ -153,12 +167,7 @@ var recline = function() {
|
|||||||
util.render('title', 'project-title', app.dbInfo);
|
util.render('title', 'project-title', app.dbInfo);
|
||||||
util.render( 'generating', 'project-actions' );
|
util.render( 'generating', 'project-actions' );
|
||||||
|
|
||||||
couch.request({url: app.baseURL + 'api/_all_docs?' + $.param({startkey: '"_design/"', endkey: '"_design0"'})}).then(
|
updateDocCount();
|
||||||
function ( data ) {
|
|
||||||
var ddocCount = data.rows.length;
|
|
||||||
$('#docCount').text(app.dbInfo.doc_count - ddocCount + " documents");
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
couch.session().then(function(session) {
|
couch.session().then(function(session) {
|
||||||
if ( session.userCtx.name ) {
|
if ( session.userCtx.name ) {
|
||||||
@@ -169,13 +178,17 @@ var recline = function() {
|
|||||||
util.render('controls', 'project-controls', {text: text});
|
util.render('controls', 'project-controls', {text: text});
|
||||||
})
|
})
|
||||||
|
|
||||||
couch.request({url: app.baseURL + 'api/headers'}).then(function ( headers ) {
|
initializeTable();
|
||||||
app.headers = headers;
|
})
|
||||||
app.csvUrl = app.baseURL + 'api/csv?headers=' + escape(JSON.stringify(headers));
|
}
|
||||||
|
|
||||||
util.render( 'actions', 'project-actions', $.extend({}, app.dbInfo, {url: app.csvUrl}) );
|
function initializeTable(offset) {
|
||||||
fetchRows();
|
couch.request({url: app.baseURL + 'api/headers'}).then(function ( headers ) {
|
||||||
})
|
app.headers = headers;
|
||||||
|
app.csvUrl = app.baseURL + 'api/csv?headers=' + escape(JSON.stringify(headers));
|
||||||
|
|
||||||
|
util.render( 'actions', 'project-actions', $.extend({}, app.dbInfo, {url: app.csvUrl}) );
|
||||||
|
fetchRows(false, offset);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,10 +196,12 @@ var recline = function() {
|
|||||||
formatDiskSize: formatDiskSize,
|
formatDiskSize: formatDiskSize,
|
||||||
handleMenuClick: handleMenuClick,
|
handleMenuClick: handleMenuClick,
|
||||||
showDialog: showDialog,
|
showDialog: showDialog,
|
||||||
|
updateDocCount: updateDocCount,
|
||||||
bootstrap: bootstrap,
|
bootstrap: bootstrap,
|
||||||
fetchRows: fetchRows,
|
fetchRows: fetchRows,
|
||||||
activateControls: activateControls,
|
activateControls: activateControls,
|
||||||
getPageSize: getPageSize,
|
getPageSize: getPageSize,
|
||||||
renderRows: renderRows
|
renderRows: renderRows,
|
||||||
|
initializeTable: initializeTable
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
@@ -55,7 +55,7 @@ app.after = {
|
|||||||
util.notify("Updating row...", {persist: true, loader: true});
|
util.notify("Updating row...", {persist: true, loader: true});
|
||||||
couch.request({type: "PUT", url: app.baseURL + "api/" + doc._id, data: JSON.stringify(doc)}).then(function(response) {
|
couch.request({type: "PUT", url: app.baseURL + "api/" + doc._id, data: JSON.stringify(doc)}).then(function(response) {
|
||||||
util.notify("Row updated successfully");
|
util.notify("Row updated successfully");
|
||||||
recline.fetchRows(false, app.offset);
|
recline.initializeTable();
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
$('.data-table-cell-editor .cancelButton').click(function(e) {
|
$('.data-table-cell-editor .cancelButton').click(function(e) {
|
||||||
@@ -193,7 +193,7 @@ app.after = {
|
|||||||
util.notify("Saving documents...", {persist: true, loader: true});
|
util.notify("Saving documents...", {persist: true, loader: true});
|
||||||
costco.uploadDocs(util.lookupPath(util.selectedTreePath())).then(function(msg) {
|
costco.uploadDocs(util.lookupPath(util.selectedTreePath())).then(function(msg) {
|
||||||
util.notify("Docs saved successfully!");
|
util.notify("Docs saved successfully!");
|
||||||
recline.fetchRows(false, app.offset);
|
recline.initializeTable(app.offset);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -210,7 +210,7 @@ app.after = {
|
|||||||
costco.uploadDocs(docs).then(
|
costco.uploadDocs(docs).then(
|
||||||
function(docs) {
|
function(docs) {
|
||||||
util.notify("Data uploaded successfully!");
|
util.notify("Data uploaded successfully!");
|
||||||
recline.fetchRows(false, app.offset);
|
recline.initializeTable(app.offset);
|
||||||
util.hide('dialog');
|
util.hide('dialog');
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user