You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2014/12/09 22:33:18 UTC

fauxton commit: updated refs/heads/master to 42cdf68

Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 0c46f31b8 -> 42cdf6886


Allow editing documents from view

Closes COUCHDB-2494


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

Branch: refs/heads/master
Commit: 42cdf6886bb2062caa334485cc16b3fd5dcf5030
Parents: 0c46f31
Author: Michelle Phung <mi...@gmail.com>
Authored: Sun Dec 7 12:57:25 2014 -0500
Committer: Benjamin Keen <be...@gmail.com>
Committed: Tue Dec 9 13:31:46 2014 -0800

----------------------------------------------------------------------
 app/addons/documents/resources.js               | 17 ++++++
 app/addons/documents/routes-doc-editor.js       |  8 ++-
 app/addons/documents/routes-documents.js        | 27 +++++++---
 .../documents/templates/all_docs_item.html      | 13 +++--
 .../documents/templates/index_row_docular.html  | 29 -----------
 .../tests/nightwatch/editDocumentsFromView.js   | 55 ++++++++++++++++++++
 app/addons/documents/views-index.js             | 18 ++-----
 app/addons/documents/views.js                   |  6 ++-
 .../custom-commands/clickWhenReady.js           | 12 +++++
 .../custom-commands/createDocument.js           |  8 ++-
 .../custom-commands/populateDatabase.js         |  2 +-
 test/nightwatch_tests/nightwatch_README.md      |  4 +-
 12 files changed, 138 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/resources.js b/app/addons/documents/resources.js
index 1eaa6bb..58c17c6 100644
--- a/app/addons/documents/resources.js
+++ b/app/addons/documents/resources.js
@@ -89,6 +89,14 @@ function(app, FauxtonAPI, PagingCollection) {
       return this.docType() != "reduction";
     },
 
+    isFromView: function(){
+      return !this.id;
+    },
+
+    isReducedShown : function () {
+      return this.collection.params.reduce;
+    },
+
     isDdoc: function() {
       return this.docType() === "design doc";
     },
@@ -271,6 +279,15 @@ function(app, FauxtonAPI, PagingCollection) {
     isEditable: function() {
       return this.docType() != "reduction";
     },
+
+    isFromView: function(){
+      return !this.id;
+    },
+
+    isReducedShown : function () {
+      return this.collection.params.reduce;
+    },
+
     safeID: function() {
       var id = this.id || this.get("id");
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/routes-doc-editor.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes-doc-editor.js b/app/addons/documents/routes-doc-editor.js
index 83cca0b..4efed7c 100644
--- a/app/addons/documents/routes-doc-editor.js
+++ b/app/addons/documents/routes-doc-editor.js
@@ -39,7 +39,8 @@ function(app, FauxtonAPI, Documents, DocEditor, Databases) {
 
     routes: {
       "database/:database/:doc/code_editor": "code_editor",
-      "database/:database/:doc": "code_editor"
+      "database/:database/:doc": "code_editor",
+      "database/:database/_design/:ddoc" :"showDesignDoc"
     },
 
     events: {
@@ -70,6 +71,11 @@ function(app, FauxtonAPI, Documents, DocEditor, Databases) {
         model: this.doc,
         database: this.database
       }));
+
+    },
+
+    showDesignDoc: function (database, ddoc) {
+      this.code_editor(database, '_design/' + ddoc);
     },
 
     reRenderDoc: function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/routes-documents.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes-documents.js b/app/addons/documents/routes-documents.js
index 3b49878..0fd8d9e 100644
--- a/app/addons/documents/routes-documents.js
+++ b/app/addons/documents/routes-documents.js
@@ -353,13 +353,26 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
         return [this.indexedDocs.urlRef("apiurl", urlParams), FauxtonAPI.constants.DOC_URLS.GENERAL];
       };
 
-      this.rightHeader.showQueryOptions();
-      this.rightHeader.resetQueryOptions({
-        queryParams: urlParams,
-        showStale: true,
-        hasReduce: true,
-        viewName: viewName,
-        ddocName: ddoc
+      this.showQueryOptions(urlParams, ddoc, viewName);
+    },
+
+    showQueryOptions: function (urlParams, ddoc, viewName) {
+      var promise = this.designDocs.fetch({reset: true}),
+          that = this,
+          hasReduceFunction;
+
+      promise.then(function(resp) {
+        var design = _.findWhere(that.designDocs.models, {id: '_design/'+ddoc}); 
+        !_.isUndefined(hasReduceFunction = design.attributes.doc.views[viewName].reduce);
+
+        that.rightHeader.showQueryOptions();
+        that.rightHeader.resetQueryOptions({
+          queryParams: urlParams,
+          showStale: true,
+          hasReduce: hasReduceFunction,
+          viewName: viewName,
+          ddocName: ddoc
+        });
       });
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/templates/all_docs_item.html
----------------------------------------------------------------------
diff --git a/app/addons/documents/templates/all_docs_item.html b/app/addons/documents/templates/all_docs_item.html
index e0c62fc..78a9b35 100644
--- a/app/addons/documents/templates/all_docs_item.html
+++ b/app/addons/documents/templates/all_docs_item.html
@@ -20,15 +20,18 @@ the License.
 </div>
 <div class="doc-item">
   <header>
-    <span class="header-keylabel"><%- doc.isEditable() ? 'id' : 'key' %></span> <span class="header-doc-id">"<%- docIdentifier %>"</span>
-
-  <% if (doc.isEditable()) { %>
+    <span class="header-keylabel"><%- doc.isFromView() ? 'key' : 'id' %></span> <span class="header-doc-id">"<%- docIdentifier %>"</span>
+    <% if (!doc.isReducedShown()) { %>
     <div class="doc-edit-symbol pull-right">
-      <a href="#<%- doc.url('web-index') %>">
+    <% if (doc.isFromView()) { %>
+      <a href="#<%- doc.url('app') %>">
+    <% } else {  %>
+      <a href="#<%- doc.url('web-index')%>">
+    <% } %>
         <i class="fonticon-pencil"></i>
       </a>
     </div>
-  <% } %>
+    <% }; %>
   </header>
   <div class="doc-data">
     <pre class="prettyprint"><%- doc.prettyJSON() %></pre>

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/templates/index_row_docular.html
----------------------------------------------------------------------
diff --git a/app/addons/documents/templates/index_row_docular.html b/app/addons/documents/templates/index_row_docular.html
deleted file mode 100644
index e8973ad..0000000
--- a/app/addons/documents/templates/index_row_docular.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<!--
-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 (doc.isEditable()) { %>
-  <td class="select"><input type="checkbox"></td>
-<% } %>
-<td>
-  <div>
-    <pre class="prettyprint"><%- doc.prettyJSON() %></pre>
-
-      <div class="btn-group">
-        <a href="#<%= url %>" class="btn btn-small edits">Edit <%= doc.docType() %></a>
-        <% if (doc.isEditable()) { %>
-          <button href="#" class="btn btn-small btn-danger delete" title="Delete this document."><i class="icon icon-trash"></i></button>
-        <% } %>
-      </div>
-
-  </div>
-</td>

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/tests/nightwatch/editDocumentsFromView.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/nightwatch/editDocumentsFromView.js b/app/addons/documents/tests/nightwatch/editDocumentsFromView.js
new file mode 100644
index 0000000..8ab9bcd
--- /dev/null
+++ b/app/addons/documents/tests/nightwatch/editDocumentsFromView.js
@@ -0,0 +1,55 @@
+// 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.
+
+module.exports = {
+  'Edit is allowed from default Map Views' : function (client) {
+    var newDatabaseName = client.globals.testDatabaseName,
+        newDocumentName = '_design/abc',
+        baseUrl = client.globals.test_settings.launch_url,
+        ddocContents = {
+          "views": {
+            "evens": {
+              "map": "function (doc) { if (doc.number%2 === 0){ emit(doc._id, doc.number); } }",
+              "reduce" : "_count"
+            }
+          },
+          "language": "javascript"
+        };
+    
+    client
+      .loginToGUI()
+      .createDocument(newDocumentName, newDatabaseName, ddocContents )
+      .populateDatabase(newDatabaseName)
+
+      //navigate to 'evens' view (declared above), then click on first document's pencil icon
+      .clickWhenReady('#dashboard-content a[href="#/database/' + newDatabaseName + '/_all_docs"]')
+      .clickWhenReady('#nav-header-abc')
+      .clickWhenReady('#nav-design-function-abcviews')
+      .clickWhenReady('#abc_evens')
+      .pause(1000) //why?
+      .clickWhenReady('a[href=\'#/database/fauxton-selenium-tests/document_10\']')
+
+      //navigated to editor
+      .waitForElementVisible('#editor-container', 10000, false)
+      .verify.urlContains('#/database/' + newDatabaseName +'/document_10');
+  },
+
+  'Edit is not allowed for Map Views where reduce is checked' : function (client) {
+    client
+      .clickWhenReady('#doc-actions .cancel-button')
+      .clickWhenReady('#toggle-query')
+      .clickWhenReady('#query-options-tray label[for="qoReduce"]')
+      .clickWhenReady('#button-options button[type="submit"]')
+      .waitForElementNotPresent('i.fonticon-pencil',10000)
+    .end();
+  }
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/views-index.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views-index.js b/app/addons/documents/views-index.js
index 6fda62c..b726e0c 100644
--- a/app/addons/documents/views-index.js
+++ b/app/addons/documents/views-index.js
@@ -33,16 +33,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, QueryOption
 
   var Views = {};
 
-
-  // this is a temporary workaround until I hear of a better on. The problem is that on initial page load (i.e. a refresh
-  // of the View page) the afterRender() functions calls a FauxtonAPI.triggerRouteEvent(). That causes this View to be
-  // rendered twice (at least, the afterRender() function then gets called twice) - and that causes the header content to
-  // disappear. This var tracks whether the View has been rendered and if not, doesn't call the triggerRouteEvent. btw,
-  // the reason the triggerRouteEvent('resetQueryOptions') code is there is that it ensures the Query Options tray shows
-  // the appropriate content for the current View (i.e. hasReduce or not)
-  var hasRenderedOnce = false;
-
-
   Views.ViewEditor = FauxtonAPI.View.extend({
     template: "addons/documents/templates/view_editor",
     builtinReduces: ['_sum', '_count', '_stats'],
@@ -454,7 +444,11 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, QueryOption
     },
 
     afterRender: function() {
-      if (this.params && !this.newView && hasRenderedOnce) {
+
+      var queryOptionsMissing = $("#query-options").html() === "";
+      
+      if (this.params && !this.newView && queryOptionsMissing) {
+
         FauxtonAPI.triggerRouteEvent('resetQueryOptions', {
           queryParams: this.params,
           hasReduce: this.hasReduce(),
@@ -473,8 +467,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, QueryOption
         this.$('#index-nav').parent().removeClass('active');
       }
 
-      // note that this View has been rendered
-      hasRenderedOnce = true;
     },
 
     showEditors: function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js
index 06d092c..a4dd5a5 100644
--- a/app/addons/documents/views.js
+++ b/app/addons/documents/views.js
@@ -196,7 +196,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions)
     },
 
     events: {
-      "dblclick pre.prettyprint": "edit"
+      "dblclick .doc-item": "edit"
     },
 
     attributes: function() {
@@ -219,7 +219,9 @@ function(app, FauxtonAPI, Components, Documents, Databases, Views, QueryOptions)
 
     edit: function(event) {
       event.preventDefault();
-      FauxtonAPI.navigate("#" + this.model.url('web-index'));
+      if (!this.model.isReducedShown()) {
+        FauxtonAPI.navigate(this.model.url('app'));
+      }
     }
   });
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/test/nightwatch_tests/custom-commands/clickWhenReady.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/clickWhenReady.js b/test/nightwatch_tests/custom-commands/clickWhenReady.js
new file mode 100644
index 0000000..cae33e8
--- /dev/null
+++ b/test/nightwatch_tests/custom-commands/clickWhenReady.js
@@ -0,0 +1,12 @@
+exports.command = function (element, waitTime) {
+
+  if(waitTime === undefined){
+    waitTime = 10000;
+  }
+
+  this
+    .waitForElementVisible(element, waitTime, false)
+    .click(element)
+
+  return this;
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/test/nightwatch_tests/custom-commands/createDocument.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/createDocument.js b/test/nightwatch_tests/custom-commands/createDocument.js
index 388dc5a..4d08505 100644
--- a/test/nightwatch_tests/custom-commands/createDocument.js
+++ b/test/nightwatch_tests/custom-commands/createDocument.js
@@ -9,12 +9,16 @@ function CreateDocument () {
 // inherit from node's event emitter
 util.inherits(CreateDocument, events.EventEmitter);
 
-CreateDocument.prototype.command = function (documentName, databaseName) {
+CreateDocument.prototype.command = function (documentName, databaseName, docContents) {
   var that = this,
       nano = helpers.getNanoInstance(),
       database = nano.use(databaseName);
 
-  database.insert({ dummyKey: "testingValue" }, documentName, function (err, body, header) {
+  if (docContents === undefined) {
+    docContents = { dummyKey: "testingValue" }; 
+  }
+
+  database.insert(docContents, documentName, function (err, body, header) {
   
     if (err) {
       console.log('Error in nano CreateDocument Function: '+documentName+', in database: '+databaseName, err.message);

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/test/nightwatch_tests/custom-commands/populateDatabase.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/populateDatabase.js b/test/nightwatch_tests/custom-commands/populateDatabase.js
index ea1cbf8..bf01c97 100644
--- a/test/nightwatch_tests/custom-commands/populateDatabase.js
+++ b/test/nightwatch_tests/custom-commands/populateDatabase.js
@@ -19,7 +19,7 @@ PopulateDatabase.prototype.command = function (databaseName) {
     function () { return i < 20; },
     function (cb) {
         i++;
-        var document_id = 'document_ '+ i;
+        var document_id = 'document_'+ i;
         database.insert({ number: i }, document_id, cb);
     },
     function (err) {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/42cdf688/test/nightwatch_tests/nightwatch_README.md
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/nightwatch_README.md b/test/nightwatch_tests/nightwatch_README.md
index a18d6a7..761d6f8 100644
--- a/test/nightwatch_tests/nightwatch_README.md
+++ b/test/nightwatch_tests/nightwatch_README.md
@@ -51,8 +51,10 @@ has failed, and will not exit or skip subsequent tests.
 3. `.waitForElementNotPresent()`, `.waitForElementNotVisible()`, `.waitForElementPresent()`, `.waitForElementVisible()`, 
 will exit testing by default if the Element is not found. There is a third argument, 'abortOnFailure', if you set this 
 to 'false', the rest of the tests will continue even if this assertion fails.
+> there is a custom function called clickWhenReady which will wait for an element to visible, then click on it
+
 4. Sometimes `.click()` doesn't work reliably (most likely if the element you are clicking on doesn't have an 
-individual ID selector). You can use jquery to simulate a click by using `.execute($("#CSS Selector.HERE").click();)`
+individual ID selector). You can use jquery to simulate a click by using `.execute('$("#CSS Selector.HERE").click();')`.  
 5. The function `.pause(time)` is sometimes necessary, although we have tried to avoid excessive use of a hard coded 
 pausing. Instead try and make use of the `.waitForElement` functions instead of `.pause(time)`.