You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/10/23 17:48:40 UTC

[4/4] git commit: updated refs/heads/master to 308b993

Finish view compaction


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

Branch: refs/heads/master
Commit: 308b9937de3a1a46705e2be3ea31828722b1db1b
Parents: 4b5841a
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Oct 22 17:17:58 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Wed Oct 23 17:48:10 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/compaction/base.js       |  2 +
 src/fauxton/app/addons/compaction/resources.js  | 10 ++++
 src/fauxton/app/addons/compaction/routes.js     | 10 ++--
 .../compaction/templates/compact_view.html      | 14 +++++
 .../app/addons/compaction/templates/layout.html |  8 ---
 src/fauxton/app/addons/compaction/views.js      | 57 ++++++++++++++++++--
 src/fauxton/app/modules/documents/views.js      | 22 ++++++--
 .../templates/documents/advanced_options.html   |  2 +-
 src/fauxton/extensions.md                       | 17 ++++++
 9 files changed, 124 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/app/addons/compaction/base.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/compaction/base.js b/src/fauxton/app/addons/compaction/base.js
index 8d93016..de0f124 100644
--- a/src/fauxton/app/addons/compaction/base.js
+++ b/src/fauxton/app/addons/compaction/base.js
@@ -23,6 +23,8 @@ function(app, FauxtonAPI, Compaction) {
       url: "compact", 
       icon: "icon-cogs"
     });
+
+    FauxtonAPI.registerExtension('advancedOptions:ViewButton', new Compaction.CompactView({}));
   };
 
   return Compaction;

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/app/addons/compaction/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/compaction/resources.js b/src/fauxton/app/addons/compaction/resources.js
index e7c97cf..6633677 100644
--- a/src/fauxton/app/addons/compaction/resources.js
+++ b/src/fauxton/app/addons/compaction/resources.js
@@ -34,5 +34,15 @@ function (app, FauxtonAPI) {
     });
   };
 
+
+  Compaction.compactView = function (db, designDoc) {
+    // /some_database/_compact/designname
+    return $.ajax({
+      url: db.url() + '/_compact/' + designDoc.replace('_design/','') ,
+      contentType: 'application/json',
+      type: 'POST'
+    });
+  };
+
   return Compaction;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/app/addons/compaction/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/compaction/routes.js b/src/fauxton/app/addons/compaction/routes.js
index e04d386..b7a2ee3 100644
--- a/src/fauxton/app/addons/compaction/routes.js
+++ b/src/fauxton/app/addons/compaction/routes.js
@@ -25,9 +25,13 @@ function(app, FauxtonAPI, Compaction, Databases) {
   var  CompactionRouteObject = FauxtonAPI.RouteObject.extend({
     layout: "one_pane",
 
-    crumbs: [
-      {"name": "Compact & Clean", "link": "compact"}
-    ],
+    crumbs: function () {
+      return [
+        {"name": "Databases", "link": "/_all_dbs"},
+        {"name": this.database.id, "link": Databases.databaseUrl(this.database)},
+        {"name": "Compact & Clean", "link": "compact"}
+      ];
+    },
 
     routes: {
       "database/:database/compact": "compaction"

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/app/addons/compaction/templates/compact_view.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/compaction/templates/compact_view.html b/src/fauxton/app/addons/compaction/templates/compact_view.html
new file mode 100644
index 0000000..8a0b7ec
--- /dev/null
+++ b/src/fauxton/app/addons/compaction/templates/compact_view.html
@@ -0,0 +1,14 @@
+<!--
+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.
+-->
+Compact View

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/app/addons/compaction/templates/layout.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/compaction/templates/layout.html b/src/fauxton/app/addons/compaction/templates/layout.html
index 08a2078..5125892 100644
--- a/src/fauxton/app/addons/compaction/templates/layout.html
+++ b/src/fauxton/app/addons/compaction/templates/layout.html
@@ -21,14 +21,6 @@ the License.
 
 <div class="row">
   <div class="span12 compaction-option">
-    <h3> Compact Views </h3>
-    <p>View compaction will affect all views in this design document. This operation may take some time to complete. Your views will still operate normally during compaction.</p>
-    <button id="compact-view" class="btn btn-large btn-primary"> Run </button>
-  </div>
-</div>
-
-<div class="row">
-  <div class="span12 compaction-option">
     <h3> Cleanup Views </h3>
     <p>Cleaning up views in a database removes old view files still stored on the filesystem. It is an irreversible operation.</p>
     <button id="cleanup-views" class="btn btn-large btn-primary"> Run </button>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/app/addons/compaction/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/compaction/views.js b/src/fauxton/app/addons/compaction/views.js
index ff6037a..06a1300 100644
--- a/src/fauxton/app/addons/compaction/views.js
+++ b/src/fauxton/app/addons/compaction/views.js
@@ -49,7 +49,7 @@ function (app, FauxtonAPI, Compaction) {
       Compaction.compactDB(this.model).then(function () {
         FauxtonAPI.addNotification({
           type: 'success',
-          msg: 'Database compaction has started.'
+          msg: 'Database compaction has started. Visit <a href="#activetasks">Active Tasks</a> to view the compaction progress.',
         });
       }, function (xhr, error, reason) {
         console.log(arguments);
@@ -71,10 +71,9 @@ function (app, FauxtonAPI, Compaction) {
       Compaction.cleanupViews(this.model).then(function () {
         FauxtonAPI.addNotification({
           type: 'success',
-          msg: 'View cleanup has started.'
+          msg: 'View cleanup has started. Visit <a href="#activetasks">Active Tasks</a> to view progress.'
         });
       }, function (xhr, error, reason) {
-        console.log(arguments);
         FauxtonAPI.addNotification({
           type: 'error',
           msg: 'Error: ' + JSON.parse(xhr.responseText).reason
@@ -85,5 +84,57 @@ function (app, FauxtonAPI, Compaction) {
     }
   });
 
+  Compaction.CompactView = FauxtonAPI.View.extend({
+    template: 'addons/compaction/templates/compact_view',
+    className: 'btn btn-info btn-large pull-right',
+    tagName: 'button',
+
+    initialize: function () {
+      _.bindAll(this);
+    },
+
+    events: {
+      "click": "compact"
+    },
+
+    disableButton: function () {
+      this.$el.attr('disabled', 'disabled').text('Compacting...');
+    },
+
+    enableButton: function () {
+      this.$el.removeAttr('disabled').text('Compact View');
+    },
+
+
+    update: function (database, designDoc, viewName) {
+      this.database = database;
+      this.designDoc = designDoc;
+      this.viewName = viewName;
+    },
+
+    compact: function (event) {
+      event.preventDefault();
+      var enableButton = this.enableButton;
+
+      this.disableButton();
+
+      Compaction.compactView(this.database, this.designDoc).then(function () {
+        FauxtonAPI.addNotification({
+          type: 'success',
+          msg: 'View compaction has started. Visit <a href="#activetasks">Active Tasks</a> to view progress.'
+        });
+      }, function (xhr, error, reason) {
+        FauxtonAPI.addNotification({
+          type: 'error',
+          msg: 'Error: ' + JSON.parse(xhr.responseText).reason
+        });
+      }).always(function () {
+        enableButton();
+      });
+
+    }
+
+  });
+
   return Compaction;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/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 eaec296..cf5dd35 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -479,7 +479,8 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
         updateViewFn: this.updateView,
         previewFn: this.previewView,
         hasReduce: false,
-        showPreview: false
+        showPreview: false,
+        database: this.database
       }));
 
       this.$('#query').hide();
@@ -970,6 +971,9 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
     className: "advanced-options well",
 
     initialize: function (options) {
+      this.database = options.database;
+      this.ddocName = options.ddocName;
+      this.viewName = options.viewName;
       this.updateViewFn = options.updateViewFn;
       this.previewFn = options.previewFn;
       this.hadReduce = options.hasReduce || true;
@@ -994,6 +998,16 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
       "click button.preview": "previewView"
     },
 
+    beforeRender: function () {
+      if (this.viewName && this.ddocName) {
+        var buttonViews = FauxtonAPI.getExtensions('advancedOptions:ViewButton');
+        _.each(buttonViews, function (view) {
+          this.insertView('#button-options', view);
+          view.update(this.database, this.ddocName, this.viewName);
+        }, this);
+      }
+    },
+
     queryParams: function () {
       var $form = this.$(".view-query-update");
       // Ignore params without a value
@@ -1496,7 +1510,10 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
 
       this.advancedOptions = this.insertView('#query', new Views.AdvancedOptions({
         updateViewFn: this.updateView,
-        previewFn: this.previewView
+        previewFn: this.previewView,
+        database: this.database,
+        viewName: this.viewName,
+        ddocName: this.model.id
       }));
     },
 
@@ -1635,7 +1652,6 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
 
     serialize: function() {
       var docLinks = FauxtonAPI.getExtensions('docLinks');
-      console.log(docLinks);
       return {
         changes_url: '#' + this.database.url('changes'),
         permissions_url: '#' + this.database.url('app') + '/permissions',

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/app/templates/documents/advanced_options.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/advanced_options.html b/src/fauxton/app/templates/documents/advanced_options.html
index aee2f65..c0bf44a 100644
--- a/src/fauxton/app/templates/documents/advanced_options.html
+++ b/src/fauxton/app/templates/documents/advanced_options.html
@@ -81,7 +81,7 @@ the License.
   </div>
   <div class="controls-group">
     <div class="row-fluid">
-      <div class="controls controls-row">
+      <div id="button-options" class="controls controls-row">
         <button type="submit" class="btn btn-primary btn-large">Query</button>
         <% if (showPreview) { %>
         <button class="btn btn-info btn-large preview">Preview</button>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/308b9937/src/fauxton/extensions.md
----------------------------------------------------------------------
diff --git a/src/fauxton/extensions.md b/src/fauxton/extensions.md
new file mode 100644
index 0000000..13fcf8d
--- /dev/null
+++ b/src/fauxton/extensions.md
@@ -0,0 +1,17 @@
+#Extensions
+
+Extensions allow Fauxton views to be have extra functionality.
+
+A module registers an extension by
+
+    FauxtonAPI.registerExtension('extensionName', myObjectToRegister);
+
+Any other module wanting to use that extension can then get 
+all objects registered for an extension by:
+
+    var extensions = FauxtonAPI.getExtensions('extensionName');
+    // extensions will always be an array
+
+The module can then use those extensions to extend its functionality.
+An example of extensions in the compaction module (app/addons/compaction/base.js) 
+and in documents module (app/modules/documents/views line 1003)