diff options
author | Garren Smith <garren.smith@gmail.com> | 2013-10-22 17:17:58 +0200 |
---|---|---|
committer | Garren Smith <garren.smith@gmail.com> | 2013-10-23 17:48:10 +0200 |
commit | 308b9937de3a1a46705e2be3ea31828722b1db1b (patch) | |
tree | 19595f37712c6bb7709636ee9fa894376f0c758b | |
parent | 4b5841afd9e626b0e04544e3295c8d8dc9ad5500 (diff) | |
download | couchdb-308b9937de3a1a46705e2be3ea31828722b1db1b.tar.gz |
Finish view compaction
-rw-r--r-- | src/fauxton/app/addons/compaction/base.js | 2 | ||||
-rw-r--r-- | src/fauxton/app/addons/compaction/resources.js | 10 | ||||
-rw-r--r-- | src/fauxton/app/addons/compaction/routes.js | 10 | ||||
-rw-r--r-- | src/fauxton/app/addons/compaction/templates/compact_view.html | 14 | ||||
-rw-r--r-- | src/fauxton/app/addons/compaction/templates/layout.html | 8 | ||||
-rw-r--r-- | src/fauxton/app/addons/compaction/views.js | 57 | ||||
-rw-r--r-- | src/fauxton/app/modules/documents/views.js | 22 | ||||
-rw-r--r-- | src/fauxton/app/templates/documents/advanced_options.html | 2 | ||||
-rw-r--r-- | src/fauxton/extensions.md | 17 |
9 files changed, 124 insertions, 18 deletions
diff --git a/src/fauxton/app/addons/compaction/base.js b/src/fauxton/app/addons/compaction/base.js index 8d930166d..de0f124df 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; diff --git a/src/fauxton/app/addons/compaction/resources.js b/src/fauxton/app/addons/compaction/resources.js index e7c97cfb8..663367792 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; }); diff --git a/src/fauxton/app/addons/compaction/routes.js b/src/fauxton/app/addons/compaction/routes.js index e04d38652..b7a2ee309 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" 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 000000000..8a0b7ec7e --- /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 diff --git a/src/fauxton/app/addons/compaction/templates/layout.html b/src/fauxton/app/addons/compaction/templates/layout.html index 08a2078cd..512589252 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> diff --git a/src/fauxton/app/addons/compaction/views.js b/src/fauxton/app/addons/compaction/views.js index ff6037add..06a13003c 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; }); diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js index eaec29673..cf5dd3539 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', diff --git a/src/fauxton/app/templates/documents/advanced_options.html b/src/fauxton/app/templates/documents/advanced_options.html index aee2f652f..c0bf44a49 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> diff --git a/src/fauxton/extensions.md b/src/fauxton/extensions.md new file mode 100644 index 000000000..13fcf8d6e --- /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) |