couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [1/2] git commit: updated refs/heads/fauxton-view-improvements to 4470dfa
Date Thu, 16 May 2013 15:44:50 GMT
Updated Branches:
  refs/heads/fauxton-view-improvements [created] 4470dfa15


initial investigation


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

Branch: refs/heads/fauxton-view-improvements
Commit: 82951f5d4c3973cfdfa004a099d35529ae5a8561
Parents: c8bbd09
Author: Garren Smith <garren.smith@gmail.com>
Authored: Thu May 16 08:34:54 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Thu May 16 09:50:55 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/api.js                             |    3 +-
 src/fauxton/app/modules/documents/resources.js     |   14 ++++++
 src/fauxton/app/modules/documents/routes.js        |   12 ++++-
 src/fauxton/app/modules/documents/views.js         |   37 +++++++++++----
 .../app/templates/documents/view_editor.html       |   15 ++++--
 5 files changed, 64 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/82951f5d/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index 67c3863..40fb4cd 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -32,7 +32,8 @@ function(app, Fauxton) {
   // List of JSHINT errors to ignore
   // Gets around problem of anonymous functions not being a valid statement
   FauxtonAPI.excludedViewErrors = [
-    "Missing name in function declaration."
+    "Missing name in function declaration.",
+    "['{a}'] is better written in dot notation."
   ];
 
   FauxtonAPI.isIgnorableError = function(msg) {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/82951f5d/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 f1a07c3..d231f67 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -74,6 +74,20 @@ function(app, FauxtonAPI, Views) {
       return doc.views[view];
     },
 
+    setDdocView: function (view, map, reduce) {
+      if (!this.isDdoc()) return false;
+      var doc = this.get('doc');
+
+      if (!doc.views) { doc.views = {}; }
+
+      doc.views[view] = {
+        map: map,
+        reduce: reduce
+      };
+
+      return true;
+    },
+
     viewHasReduce: function(viewName) {
       var view = this.getDdocView(viewName);
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/82951f5d/src/fauxton/app/modules/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index bb8b193..6f16896 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -272,10 +272,18 @@ function(app, FauxtonAPI, Documents, Databases) {
     },
 
     newViewEditor: function (event) {
-      // TODO: Get this working
+      this.data.indexedDocs = new Documents.IndexCollection(null, {
+        database: this.data.database
+      /*  design: ddoc,
+        view: view,
+        params: params*/
+      });
+
       this.setView("#dashboard-content", new Documents.Views.ViewEditor({
         model: this.data.database,
-        ddocs: this.data.designDocs
+        ddocs: this.data.designDocs,
+        viewCollection: this.data.indexedDocs,
+        newView: true
       }));
 
       this.sidebar.setSelectedTab('new-view');

http://git-wip-us.apache.org/repos/asf/couchdb/blob/82951f5d/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 17bf9af..199b551 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -666,10 +666,15 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
     defaultLang: "javascript",
 
     initialize: function(options) {
+      this.newView = options.newView || false;
       this.ddocs = options.ddocs;
+      console.log('DDOC', this.ddocs);
       this.viewCollection = options.viewCollection;
-      this.reduceFunStr = this.model.viewHasReduce(this.viewCollection.view);
-      this.newView = false;
+      if (this.newView) {
+
+      } else {
+        this.reduceFunStr = this.model.viewHasReduce(this.viewCollection.view);
+      } 
     },
 
     updateValues: function() {
@@ -700,6 +705,7 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
     },
 
     previewView: function(event) {
+      event.preventDefault();
       FauxtonAPI.addNotification({
         msg: "<strong>Warning!</strong> Preview executes the Map/Reduce functions
in your browser, and may behave differently from CouchDB.",
         type: "warning",
@@ -715,22 +721,33 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
 
     saveView: function(event) {
       var json, notification;
+
+      event.preventDefault();
+
       if (this.hasValidCode()) {
-        var mapVal = this.mapEditor.getValue();
-        var reduceVal = this.reduceEditor.getValue();
+        var mapVal = this.mapEditor.getValue(), 
+            reduceVal = this.reduceEditor.getValue(),
+            viewName = this.$('#index-name').val(),
+            ddocName = this.$('#ddoc :selected').val();
+
+         var ddoc = this.ddocs.find(function (ddoc) {
+           return ddoc.id === ddocName;
+         });
+         console.log('found ddoc', ddocName, ddoc);
         /*
         notification = FauxtonAPI.addNotification({
           msg: "Saving document.",
           selector: "#define-view .errors-container"
         });
         */
+        ddoc.setDdocView(viewName, mapVal, reduceVal);
         FauxtonAPI.addNotification({
           msg: "Save Functionality Coming Soon",
           type: "warning",
           selector: "#define-view .errors-container"
         });
-        /*
-        this.model.save().error(function(xhr) {
+        
+        ddoc.save().fail(function(xhr) {
           var responseText = JSON.parse(xhr.responseText).reason;
           notification = FauxtonAPI.addNotification({
             msg: "Save failed: " + responseText,
@@ -738,10 +755,9 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
             clear: true
           });
         });
-        */
       } else {
         notification = FauxtonAPI.addNotification({
-          msg: "Please fix the JSON errors and try again.",
+          msg: "Please fix the Javascript errors and try again.",
           type: "error",
           selector: "#define-view .errors-container"
         });
@@ -765,7 +781,7 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
         } else {
           // By default CouchDB view functions don't pass lint
           return _.every(JSHINT.errors, function(error) {
-            return FauxtonAPI.isIgnorableError(error.reason);
+            return FauxtonAPI.isIgnorableError(error.raw);
           });
         }
       }, this);
@@ -807,7 +823,8 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
         viewCollection: this.viewCollection,
         reduceFunStr: this.reduceFunStr,
         isCustomReduce: this.hasCustomReduce(),
-        newView: this.newView
+        newView: this.newView,
+        langTemplates: this.langTemplates.javascript
       };
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/82951f5d/src/fauxton/app/templates/documents/view_editor.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/view_editor.html b/src/fauxton/app/templates/documents/view_editor.html
index 4a8668e..6fbc71a 100644
--- a/src/fauxton/app/templates/documents/view_editor.html
+++ b/src/fauxton/app/templates/documents/view_editor.html
@@ -19,7 +19,7 @@ the License.
         <i class="icon-wrench"></i> Edit Index
       </a>
     </div>
-    <div id="collapse-edit-index" class="accordion-body collapse">
+    <div id="collapse-edit-index" class="accordion-body">
       <div class="accordion-inner">
         <div id="define-view" class="ddoc-alert well">
           <div class="errors-container"></div>
@@ -38,7 +38,6 @@ the License.
                         <option><%= ddoc.id %></option>
                       <% } %>
                     <% }); %>
-                    <option selected="selected">_design/views101</option>
                   </optgroup>
                 </select>
               </div>
@@ -52,7 +51,11 @@ the License.
             <div class="control-group">
               <label class="control-label" for="map-function">Map function <a target="_couch_docs"
href="http://docs.couchdb.org/en/latest/ddocs/#map-functions"><i class="icon-question-sign"></i></a></label>
               <div class="controls">
-                <textarea class="js-editor" id="map-function"><%= ddoc.get('doc').views[viewCollection.view].map
%></textarea>
+                <% if (newView) { %>
+                  <textarea class="js-editor" id="map-function"><%= langTemplates.map
%></textarea>
+                <% } else { %>
+                  <textarea class="js-editor" id="map-function"><%= ddoc.get('doc').views[viewCollection.view].map
%></textarea>
+                <% } %>
               </div>
             </div>
             <div class="control-group">
@@ -71,7 +74,11 @@ the License.
             <div class="control-group reduce-function">
               <label class="control-label" for="reduce-function">Custom Reduce</label>
               <div class="controls">
-                <textarea class="js-editor" id="reduce-function"><%= ddoc.get('doc').views[viewCollection.view].reduce
%></textarea>
+                <% if (newView) { %>
+                  <textarea class="js-editor" id="reduce-function"><%= langTemplates.reduce
%></textarea>
+                <% } else { %>
+                  <textarea class="js-editor" id="reduce-function"><%= ddoc.get('doc').views[viewCollection.view].reduce
%></textarea>
+                <% } %>
               </div>
             </div>
             <div class="control-group">


Mime
View raw message