summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2013-10-15 12:23:00 +0200
committerGarren Smith <garren.smith@gmail.com>2013-10-16 10:24:52 +0200
commit9710834196c59f02ee5fb4df27df4a587cf6c1f1 (patch)
tree2e7439eb7ff41d34a4891cc28b0888602f6a9247
parentbcb4fba312ba2ad74b9f19adcaf9eecbaf1bffe7 (diff)
downloadcouchdb-9710834196c59f02ee5fb4df27df4a587cf6c1f1.tar.gz
Fauxton: Add Verify Install module
Resolves #COUCHDB-1813
-rw-r--r--.gitignore1
-rw-r--r--src/fauxton/app/addons/verifyinstall/assets/less/verifyinstall.less4
-rw-r--r--src/fauxton/app/addons/verifyinstall/base.js31
-rw-r--r--src/fauxton/app/addons/verifyinstall/resources.js174
-rw-r--r--src/fauxton/app/addons/verifyinstall/routes.js37
-rw-r--r--src/fauxton/app/addons/verifyinstall/templates/main.html50
-rw-r--r--src/fauxton/app/addons/verifyinstall/views.js126
-rw-r--r--src/fauxton/app/modules/documents/resources.js1
-rw-r--r--src/fauxton/settings.json.default3
9 files changed, 425 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index cc2398bab..95cf2f3ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -100,6 +100,7 @@ src/fauxton/app/addons/*
!src/fauxton/app/addons/auth
!src/fauxton/app/addons/exampleAuth
!src/fauxton/app/addons/permissions
+!src/fauxton/app/addons/verifyinstall
src/fauxton/settings.json*
!src/fauxton/settings.json.default
src/ibrowse/ibrowse.app
diff --git a/src/fauxton/app/addons/verifyinstall/assets/less/verifyinstall.less b/src/fauxton/app/addons/verifyinstall/assets/less/verifyinstall.less
new file mode 100644
index 000000000..508994b22
--- /dev/null
+++ b/src/fauxton/app/addons/verifyinstall/assets/less/verifyinstall.less
@@ -0,0 +1,4 @@
+#start {
+ margin-bottom: 20px;
+}
+
diff --git a/src/fauxton/app/addons/verifyinstall/base.js b/src/fauxton/app/addons/verifyinstall/base.js
new file mode 100644
index 000000000..d17c3534e
--- /dev/null
+++ b/src/fauxton/app/addons/verifyinstall/base.js
@@ -0,0 +1,31 @@
+// 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.
+
+define([
+ "app",
+ "api",
+ "addons/verifyinstall/routes"
+],
+
+function(app, FauxtonAPI, VerifyInstall) {
+ VerifyInstall.initialize = function () {
+ FauxtonAPI.addHeaderLink({
+ title: "Verify",
+ href: "#verifyinstall",
+ icon: "fonticon-circle-check",
+ bottomNav: true,
+ });
+ };
+
+
+ return VerifyInstall;
+});
diff --git a/src/fauxton/app/addons/verifyinstall/resources.js b/src/fauxton/app/addons/verifyinstall/resources.js
new file mode 100644
index 000000000..f42c020dd
--- /dev/null
+++ b/src/fauxton/app/addons/verifyinstall/resources.js
@@ -0,0 +1,174 @@
+// 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.
+
+define([
+ "app",
+ "api",
+ "modules/databases/resources",
+ "modules/documents/resources"
+],
+
+function (app, FauxtonAPI, Databases, Documents) {
+ var Verifyinstall = FauxtonAPI.addon();
+
+ var db = new Databases.Model({
+ id: 'verifytestdb',
+ name: 'verifytestdb'
+ });
+
+ var dbReplicate = new Databases.Model({
+ id: 'verifytestdb_replicate',
+ name: 'verifytestdb_replicate'
+ });
+
+ var doc, viewDoc;
+
+ Verifyinstall.testProcess = {
+
+ saveDoc: function () {
+ doc = new Documents.Doc({_id: 'test_doc_1', a: 1}, {
+ database: db
+ });
+
+ return doc.save();
+ },
+
+ destroyDoc: function () {
+ return doc.destroy();
+ },
+
+ updateDoc: function () {
+ doc.set({b: "hello"});
+ return doc.save();
+ },
+
+ saveDB: function () {
+ return db.save();
+ },
+
+ setupDB: function (db) {
+ var deferred = FauxtonAPI.Deferred();
+ db.fetch()
+ .then(function () {
+ return db.destroy();
+ }, function (xhr) {
+ deferred.resolve();
+ })
+ .then(function () {
+ deferred.resolve();
+ }, function (xhr, error, reason) {
+ if (reason === "Unauthorized") {
+ deferred.reject(xhr, error, reason);
+ }
+ });
+
+ return deferred;
+ },
+
+ setup: function () {
+ return FauxtonAPI.when([
+ this.setupDB(db),
+ this.setupDB(dbReplicate)
+ ]);
+ },
+
+ testView: function () {
+ var deferred = FauxtonAPI.Deferred();
+ var promise = $.get(viewDoc.url() + '/_view/testview');
+
+ promise.then(function (resp) {
+ var row = JSON.parse(resp).rows[0];
+ if (row.value === 6) {
+ return deferred.resolve();
+ }
+ var reason = {
+ reason: 'Values expect 6, got ' + row.value
+ };
+
+ deferred.reject({responseText: JSON.stringify(reason)});
+ }, deferred.reject);
+
+ return deferred;
+ },
+
+ setupView: function () {
+ var doc1 = new Documents.Doc({_id: 'test_doc10', a: 1}, {
+ database: db
+ });
+
+ var doc2 = new Documents.Doc({_id: 'test_doc_20', a: 2}, {
+ database: db
+ });
+
+ var doc3 = new Documents.Doc({_id: 'test_doc_30', a: 3}, {
+ database: db
+ });
+
+ viewDoc = new Documents.Doc({
+ _id: '_design/view_check',
+ views: {
+ 'testview': {
+ map:'function (doc) { emit(doc._id, doc.a); }',
+ reduce: '_sum'
+ }
+ }
+ },{
+ database: db,
+ });
+
+ return FauxtonAPI.when([doc1.save(),doc2.save(), doc3.save(), viewDoc.save()]);
+ },
+
+ setupReplicate: function () {
+ return $.ajax({
+ url: '/_replicate',
+ contentType: 'application/json',
+ type: 'POST',
+ dataType: 'json',
+ processData: false,
+ data: JSON.stringify({
+ create_target: true,
+ source: 'verifytestdb',
+ target: 'verifytestdb_replicate'
+ }),
+ });
+ },
+
+ testReplicate: function () {
+ var deferred = FauxtonAPI.Deferred();
+ /*var dbReplicate = new Databases.Model({
+ id: 'verifytestdb_replicate',
+ name: 'verifytestdb_replicate'
+ });*/
+
+ var promise = dbReplicate.fetch();
+
+ promise.then(function () {
+ var docCount = dbReplicate.get('doc_count');
+ if ( docCount === 4) {
+ deferred.resolve();
+ return;
+ }
+
+ var reason = {
+ reason: 'Replication Failed, expected 4 docs got ' + docCount
+ };
+
+ deferred.reject({responseText: JSON.stringify(reason)});
+ }, deferred.reject);
+
+ return deferred;
+ }
+ };
+
+ return Verifyinstall;
+});
diff --git a/src/fauxton/app/addons/verifyinstall/routes.js b/src/fauxton/app/addons/verifyinstall/routes.js
new file mode 100644
index 000000000..e5024ba87
--- /dev/null
+++ b/src/fauxton/app/addons/verifyinstall/routes.js
@@ -0,0 +1,37 @@
+// 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.
+
+define([
+ "app",
+ "api",
+ "addons/verifyinstall/views"
+],
+function(app, FauxtonAPI, VerifyInstall) {
+
+ var VerifyRouteObject = FauxtonAPI.RouteObject.extend({
+ layout: 'one_pane',
+
+ routes: {
+ 'verifyinstall': "verifyInstall"
+ },
+ selectedHeader: "Verify",
+
+ verifyInstall: function () {
+ this.setView('#dashboard-content', new VerifyInstall.Main({}));
+ },
+
+ crumbs: [{name: 'Verify Couchdb Installation', link: '#'}]
+ });
+
+ VerifyInstall.RouteObjects = [VerifyRouteObject];
+ return VerifyInstall;
+});
diff --git a/src/fauxton/app/addons/verifyinstall/templates/main.html b/src/fauxton/app/addons/verifyinstall/templates/main.html
new file mode 100644
index 000000000..fa419079c
--- /dev/null
+++ b/src/fauxton/app/addons/verifyinstall/templates/main.html
@@ -0,0 +1,50 @@
+<!--
+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.
+-->
+<button id="start" class="btn btn-large btn-success"> Verify Installation </button>
+<div id="error"> </div>
+
+<table id="test-score" class="table table-striped table-bordered" >
+ <thead>
+ <tr>
+ <th> Test </th>
+ <th> Status </th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td> Create Database </td>
+ <td id="create-database" class="status"> </td>
+ </tr>
+ <tr>
+ <td> Create Document </td>
+ <td id="create-document" class="status"> </td>
+ </tr>
+ <tr>
+ <td> Update Document </td>
+ <td id="update-document" class="status"> </td>
+ </tr>
+ <tr>
+ <td> Delete Document </td>
+ <td id="delete-document" class="status"> </td>
+ </tr>
+ <tr>
+ <td> Create View </td>
+ <td id="create-view" class="status"> </td>
+ </tr>
+ <tr>
+ <td> Replication </td>
+ <td id="replicate" class="status"> </td>
+ </tr>
+ </tbody>
+</table>
diff --git a/src/fauxton/app/addons/verifyinstall/views.js b/src/fauxton/app/addons/verifyinstall/views.js
new file mode 100644
index 000000000..3ad336436
--- /dev/null
+++ b/src/fauxton/app/addons/verifyinstall/views.js
@@ -0,0 +1,126 @@
+// 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.
+
+define([
+ "app",
+ "api",
+ "addons/verifyinstall/resources",
+],
+function(app, FauxtonAPI, VerifyInstall) {
+
+ VerifyInstall.Main = FauxtonAPI.View.extend({
+ template: 'addons/verifyinstall/templates/main',
+
+ events: {
+ "click #start": "startTest"
+ },
+
+ initialize: function (options) {
+ _.bindAll(this);
+ },
+
+ setPass: function (id) {
+ this.$('#' + id).html('&#10003;');
+ },
+
+ setError: function (id, msg) {
+ this.$('#' + id).html('&#x2717;');
+ FauxtonAPI.addNotification({
+ msg: 'Error: ' + msg,
+ type: 'error',
+ selector: '#error'
+ });
+ },
+
+ complete: function () {
+ FauxtonAPI.addNotification({
+ msg: 'Success! You Couchdb install is working. Time to Relax',
+ type: 'success',
+ selector: '#error'
+ });
+ },
+
+ enableButton: function () {
+ this.$('#start').removeAttr('disabled').text('Verify Installation');
+ },
+
+ disableButton: function () {
+ this.$('#start').attr('disabled','disabled').text('Verifying');
+ },
+
+ formatError: function (id) {
+ var enableButton = this.enableButton,
+ setError = this.setError;
+
+ return function (xhr, error, reason) {
+ enableButton();
+
+ if (!xhr) { return; }
+
+ setError(id, JSON.parse(xhr.responseText).reason);
+ };
+ },
+
+
+ startTest: function () {
+ this.disableButton();
+ this.$('.status').text('');
+
+ var testProcess = VerifyInstall.testProcess,
+ setPass = this.setPass,
+ complete = this.complete,
+ setError = this.setError,
+ formatError = this.formatError;
+
+ testProcess.setup()
+ .then(function () {
+ return testProcess.saveDB();
+ }, formatError('create-database'))
+ .then(function () {
+ setPass('create-database');
+ return testProcess.saveDoc();
+ }, formatError('create-document'))
+ .then(function () {
+ setPass('create-document');
+ return testProcess.updateDoc();
+ }, formatError('update-document'))
+ .then(function () {
+ setPass('update-document');
+ return testProcess.destroyDoc();
+ }, formatError('delete-document'))
+ .then(function () {
+ setPass('delete-document');
+ return testProcess.setupView();
+ }, formatError('create-view'))
+ .then(function () {
+ return testProcess.testView();
+ }, formatError('create-view'))
+ .then(function () {
+ setPass('create-view');
+ return testProcess.setupReplicate();
+ }, formatError('create-view'))
+ .then(function () {
+ return testProcess.testReplicate();
+ }, formatError('replicate'))
+ .then(function () {
+ setPass('replicate');
+ complete();
+ }, formatError('replicate'));
+
+ this.enableButton();
+ }
+ });
+
+
+ return VerifyInstall;
+
+});
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index bad8b776c..8df2e6f1a 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -12,7 +12,6 @@
define([
"app",
-
"api"
],
diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default
index 49641352e..ce45e267a 100644
--- a/src/fauxton/settings.json.default
+++ b/src/fauxton/settings.json.default
@@ -8,7 +8,8 @@
{ "name": "plugins" },
{ "name": "contribute" },
{ "name": "permissions" },
- { "name": "auth" }
+ { "name": "auth" },
+ { "name": "verifyinstall" }
],
"template": {
"development": {