Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb/pull/221#discussion_r12773464
--- Diff: src/fauxton/app/addons/documents/resources.js ---
@@ -295,6 +295,120 @@ function(app, FauxtonAPI, PagingCollection) {
});
+ Documents.BulkDeleteDoc = FauxtonAPI.Model.extend({
+ idAttribute: "_id"
+ });
+
+ Documents.BulkDeleteDocCollection = FauxtonAPI.Collection.extend({
+
+ model: Documents.BulkDeleteDoc,
+
+ initialize: function (models, options) {
+ this.databaseId = options.databaseId;
+ },
+
+ bulkDelete: function () {
+ var payload = this.createPayload(this.toJSON()),
+ that = this;
+
+ $.ajax({
+ type: 'POST',
+ url: app.host + '/' + this.databaseId + '/_bulk_docs',
+ contentType: 'application/json',
+ dataType: 'json',
+ data: JSON.stringify(payload),
+ })
+ .then(function (res) {
+ that.handleResponse(res);
+ })
+ .fail(function () {
+ var ids = _.reduce(this.toArray(), function (acc, doc) {
+ acc.push(doc.id);
+ return acc;
+ }, []);
+ that.trigger('error', ids);
+ });
+ },
+
+ handleResponse: function (res) {
+ var errorIds = [],
+ successIds = [],
+ doc;
+
+ for (doc in res) {
+ if (res[doc].error) {
+ errorIds.push(res[doc].id);
+ }
+ if (res[doc].ok === true) {
+ successIds.push(res[doc].id);
+ }
+ }
+
+ this.removeDocuments(successIds);
+
+ if (!errorIds.length) {
+ this.clear();
+ } else {
+ this.trigger('error', errorIds);
+ this.save();
+ }
+
+ this.trigger('updated');
+ },
+
+ removeDocuments: function (ids) {
+ _.each(ids, function (id) {
+ if (/_design/.test(id)) {
+ FauxtonAPI.triggerRouteEvent('reloadDesignDocs');
+ }
+
+ this.remove(this.get(id));
+ }, this);
+
+ this.trigger('removed', ids);
+ },
+
+ createList: function (documents) {
+ var documentList = [],
+ id;
+
+ for (id in documents) {
+ documentList.push(documents[id]);
+ }
+
+ return documentList;
+ },
+
+ createPayload: function (documents) {
+ var documentList = this.createList(documents);
+
+ return {
+ docs: documentList
+ };
+ },
+
+ parse: function (resp) {
+ return this.createList(resp);
+ },
+
+ clear: function () {
+ window.sessionStorage.removeItem('couchdb:docsToDelete:' +
this.databaseId);
+ },
+
+ save: function () {
+ var data = JSON.stringify(this.toJSON());
--- End diff --
The idea was to keep the data between full page changes, e.g. after a
switch to the changes-feed.
Turns out, it introduced more complexity/bugs than it would help, removed
it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---