couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject git commit: updated refs/heads/1760-fauxton-correct-row-message to 4aa8955
Date Thu, 10 Oct 2013 12:46:58 GMT
Updated Branches:
  refs/heads/1760-fauxton-correct-row-message [created] 4aa8955ca


Fauxton: Fix correct row number message


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/4aa8955c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/4aa8955c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/4aa8955c

Branch: refs/heads/1760-fauxton-correct-row-message
Commit: 4aa8955ca631c46a8375c40966c058d06a21141e
Parents: 0192566
Author: Garren Smith <garren.smith@gmail.com>
Authored: Thu Oct 10 14:46:17 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Thu Oct 10 14:46:17 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/modules/documents/resources.js  |  9 ++
 src/fauxton/app/modules/documents/views.js      | 90 ++++++++++++++------
 .../app/templates/documents/all_docs_list.html  | 24 ++----
 .../templates/documents/all_docs_number.html    | 21 +++++
 4 files changed, 100 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/4aa8955c/src/fauxton/app/modules/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index bbacb0f..4f75daa 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -260,6 +260,8 @@ function(app, FauxtonAPI) {
       this.database = options.database;
       this.params = options.params;
       this.skipFirstItem = false;
+
+      this.on("remove",this.decrementTotalRows , this);
     },
 
     url: function(context) {
@@ -304,6 +306,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;
     },

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4aa8955c/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index 3fd47d4..376a2ac 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);

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4aa8955c/src/fauxton/app/templates/documents/all_docs_list.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/all_docs_list.html b/src/fauxton/app/templates/documents/all_docs_list.html
index 43a5532..dcb8dda 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>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4aa8955c/src/fauxton/app/templates/documents/all_docs_number.html
----------------------------------------------------------------------
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 0000000..c4ea8f6
--- /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 %>
+<% } %>


Mime
View raw message