diff options
author | Garren Smith <garren.smith@gmail.com> | 2013-10-10 14:46:17 +0200 |
---|---|---|
committer | Garren Smith <garren.smith@gmail.com> | 2013-10-16 10:24:52 +0200 |
commit | 807c4e32fa0e5aa4fd4a74a2338df215ffbe5ac7 (patch) | |
tree | d94f7ef688c64ecc97025f70d65bb1e339a304ba | |
parent | 1cf46213ea1cc204f459e2cb2d5a5d9bca161687 (diff) | |
download | couchdb-807c4e32fa0e5aa4fd4a74a2338df215ffbe5ac7.tar.gz |
Fauxton: Fix correct row number message
Fixes COUCHDB-1760
-rw-r--r-- | src/fauxton/app/modules/documents/resources.js | 17 | ||||
-rw-r--r-- | src/fauxton/app/modules/documents/views.js | 90 | ||||
-rw-r--r-- | src/fauxton/app/modules/fauxton/components.js | 7 | ||||
-rw-r--r-- | src/fauxton/app/templates/documents/all_docs_list.html | 24 | ||||
-rw-r--r-- | src/fauxton/app/templates/documents/all_docs_number.html | 21 |
5 files changed, 113 insertions, 46 deletions
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js index 901ba8396..bad8b776c 100644 --- a/src/fauxton/app/modules/documents/resources.js +++ b/src/fauxton/app/modules/documents/resources.js @@ -268,6 +268,8 @@ function(app, FauxtonAPI) { this.database = options.database; this.params = options.params; this.skipFirstItem = false; + + this.on("remove",this.decrementTotalRows , this); }, url: function(context) { @@ -284,7 +286,13 @@ function(app, FauxtonAPI) { urlNextPage: function (num, lastId) { if (!lastId) { - lastId = this.last().id; + var doc = this.last(); + + if (doc) { + lastId = doc.id; + } else { + lastId = ''; + } } this.params.startkey_docid = '"' + lastId + '"'; @@ -311,6 +319,13 @@ function(app, FauxtonAPI) { return this.viewMeta.total_rows || "unknown"; }, + decrementTotalRows: function () { + if (this.viewMeta.total_rows) { + this.viewMeta.total_rows = this.viewMeta.total_rows -1; + this.trigger('totalRows:decrement'); + } + }, + updateSeq: function() { return this.viewMeta.update_seq || false; }, diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js index 3fd47d42d..376a2ac9e 100644 --- a/src/fauxton/app/modules/documents/views.js +++ b/src/fauxton/app/modules/documents/views.js @@ -362,8 +362,11 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re FauxtonAPI.addNotification({ msg: "Succesfully destroyed your doc" }); - that.$el.fadeOut(); - that.model.collection.remove(that.id); + that.$el.fadeOut(function () { + that.remove(); + }); + + that.model.collection.remove(that.model.id); }, function(resp) { FauxtonAPI.addNotification({ msg: "Failed to destroy your doc!", @@ -377,6 +380,16 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re template: "templates/documents/index_row_docular", tagName: "tr", + events: { + "click button.delete": "destroy" + }, + + destroy: function (event) { + event.preventDefault(); + + window.alert('Cannot delete a document generated from a view.'); + }, + serialize: function() { return { doc: this.model @@ -412,6 +425,38 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re } }); + Views.AllDocsNumber = FauxtonAPI.View.extend({ + template: "templates/documents/all_docs_number", + + initialize: function (options) { + this.newView = options.newView || false; + + this.listenTo(this.collection, 'totalRows:decrement', this.render); + }, + + serialize: function () { + var totalRows = 0, + recordStart = 0, + updateSeq = false; + + if (!this.newView) { + totalRows = this.collection.totalRows(); + updateSeq = this.collection.updateSeq(); + } + + recordStart = this.collection.recordStart(); + + return { + database: this.collection.database.id, + updateSeq: updateSeq, + offset: recordStart, + totalRows: totalRows, + numModels: this.collection.models.length + recordStart - 1, + }; + } + + }); + // TODO: Rename to reflect that this is a list of rows or documents Views.AllDocsList = FauxtonAPI.View.extend({ template: "templates/documents/all_docs_list", @@ -457,32 +502,16 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re }, serialize: function() { - var totalRows = 0, - recordStart = 0, - updateSeq = false; + var requestDuration = false; - if (!this.newView) { - totalRows = this.collection.totalRows(); - updateSeq = this.collection.updateSeq(); + if (this.collection.requestDurationInString) { + requestDuration = this.collection.requestDurationInString(); } - recordStart = this.collection.recordStart(); - - var info = { - database: this.collection.database.id, - updateSeq: updateSeq, - offset: recordStart, - totalRows: totalRows, - numModels: this.collection.models.length + recordStart - 1, + return { viewList: this.viewList, - requestDuration: null + requestDuration: requestDuration }; - - if (this.collection.requestDurationInString) { - info.requestDuration = this.collection.requestDurationInString(); - } - - return info; }, /* @@ -497,7 +526,10 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re bulkDelete: function() { var that = this; // yuck, data binding ftw? - var eles = this.$el.find("input.row-select:checked").parents("tr.all-docs-item").map(function(e) { return $(this).attr("data-id"); }).get(); + var eles = this.$el.find("input.row-select:checked") + .parents("tr.all-docs-item") + .map(function(e) { return $(this).attr("data-id"); }) + .get(); if (!window.confirm("Are you sure you want to delete these " + eles.length + " docs?")) { return false; @@ -507,7 +539,9 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re var model = this.collection.get(ele); model.destroy().then(function(resp) { - that.rows[ele].$el.fadeOut(); + that.rows[ele].$el.fadeOut(function () { + $(this).remove(); + }); model.collection.remove(model.id); that.$('.bulk-delete').addClass('disabled'); @@ -551,6 +585,11 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re }, beforeRender: function() { + this.allDocsNumber = this.setView('#item-numbers', new Views.AllDocsNumber({ + collection: this.collection, + newView: this.newView + })); + this.insertView('#documents-pagination', this.pagination); this.collection.each(function(doc) { this.rows[doc.id] = this.insertView("table.all-docs tbody", new this.nestedView({ @@ -679,7 +718,6 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re this.getDocFromEditor(); notification = FauxtonAPI.addNotification({msg: "Saving document."}); - console.log('save',this.model); this.model.save().then(function () { FauxtonAPI.navigate('/database/' + that.database.id + '/' + that.model.id); diff --git a/src/fauxton/app/modules/fauxton/components.js b/src/fauxton/app/modules/fauxton/components.js index 09dcc51fc..03fea872c 100644 --- a/src/fauxton/app/modules/fauxton/components.js +++ b/src/fauxton/app/modules/fauxton/components.js @@ -73,7 +73,12 @@ function(app, FauxtonAPI) { nextClicked: function (event) { event.preventDefault(); - this.previousIds.push(this.collection.first().id); + var doc = this.collection.first(); + + if (doc) { + this.previousIds.push(doc.id); + } + FauxtonAPI.navigate(this.nextUrlfn(), {trigger: false}); FauxtonAPI.triggerRouteEvent('paginate', 'next'); }, diff --git a/src/fauxton/app/templates/documents/all_docs_list.html b/src/fauxton/app/templates/documents/all_docs_list.html index 43a55328b..dcb8ddad6 100644 --- a/src/fauxton/app/templates/documents/all_docs_list.html +++ b/src/fauxton/app/templates/documents/all_docs_list.html @@ -19,29 +19,17 @@ the License. <button type="button" class="btn all" data-toggle="button">✓ All</button> <button class="btn btn-small disabled bulk-delete"><i class="icon-trash"></i></button> </div> - <!-- TODO::REENABLE - <div class="btn-toolbar pull-right"> - <a href="#new-view-index" class="btn btn-small toggle-edit disabled"><i class="icon-wrench"></i> Edit index</a> - <a href="#params" class="btn btn-small toggle-params"><i class="icon-plus"></i> API preview</a> - </div> - --> </div> <% } %> <p> - <% if (totalRows === "unknown"){ %> - Showing 0 documents. <a href="#/database/<%=database%>/new"> Create your first document.</a> - <% } else { %> - Showing <%=offset%> - <%= numModels %> of <%= totalRows %> rows - <%}%> - <% if (updateSeq) { %> - -- Update Sequence: <%= updateSeq %> - <% } %> - <% if (requestDuration) { %> - <span class="view-request-duration"> + <div id="item-numbers"> </div> + + <% if (requestDuration) { %> + <span class="view-request-duration"> View request duration: <strong> <%= requestDuration %> </strong> - </span> - <% } %> + </span> + <% } %> </p> <table class="all-docs table table-striped table-condensed"> <tbody></tbody> diff --git a/src/fauxton/app/templates/documents/all_docs_number.html b/src/fauxton/app/templates/documents/all_docs_number.html new file mode 100644 index 000000000..c4ea8f64a --- /dev/null +++ b/src/fauxton/app/templates/documents/all_docs_number.html @@ -0,0 +1,21 @@ +<!-- +Licensed under the Apache License, Version 2.0 (the "License"); you may not +use this file except in compliance with the License. You may obtain a copy of +the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +License for the specific language governing permissions and limitations under +the License. +--> +<% if (totalRows === "unknown"){ %> + Showing 0 documents. <a href="#/database/<%=database%>/new"> Create your first document.</a> +<% } else { %> + Showing <%=offset%> - <%= numModels %> of <%= totalRows %> rows +<%}%> +<% if (updateSeq) { %> + -- Update Sequence: <%= updateSeq %> +<% } %> |