You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by cm...@apache.org on 2008/04/14 00:54:03 UTC
svn commit: r647638 - in /incubator/couchdb/branches/futon-async/share/www:
browse/database.html script/browse.js script/jquery.couch.js
Author: cmlenz
Date: Sun Apr 13 15:53:50 2008
New Revision: 647638
URL: http://svn.apache.org/viewvc?rev=647638&view=rev
Log:
futon-async branch: migrated most of the database page.
Modified:
incubator/couchdb/branches/futon-async/share/www/browse/database.html
incubator/couchdb/branches/futon-async/share/www/script/browse.js
incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js
Modified: incubator/couchdb/branches/futon-async/share/www/browse/database.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/browse/database.html?rev=647638&r1=647637&r2=647638&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/browse/database.html [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/browse/database.html [utf-8] Sun Apr 13 15:53:50 2008
@@ -21,10 +21,10 @@
<script src="../script/json2.js"></script>
<script src="../script/jquery.js"></script>
<script src="../script/jquery.cookies.js"></script>
+ <script src="../script/jquery.couch.js"></script>
<script src="../script/jquery.dialog.js"></script>
<script src="../script/jquery.resizer.js"></script>
<script src="../script/jquery.suggest.js"></script>
- <script src="../script/couch.js"></script>
<script src="../script/browse.js"></script>
<script src="../script/pprint.js"></script>
<script>
@@ -34,7 +34,7 @@
}
$(document).ready(function() {
- $("h1 strong").text(page.dbName);
+ $("h1 strong").text(page.db.name);
$("#viewcode label").click(function() {
$("#viewcode").toggleClass("expanded");
});
@@ -53,11 +53,11 @@
$("#viewcode textarea").resizable({grippie: $("#viewcode .bottom")});
// Restore preferences/state from cookies
- var query = $.cookies.get(page.dbName + ".query");
+ var query = $.cookies.get(page.db.name + ".query");
if (query) $("#viewcode textarea").val(query);
- var desc = $.cookies.get(page.dbName + ".desc");
+ var desc = $.cookies.get(page.db.name + ".desc");
if (desc) $("#documents thead th.key").addClass("desc");
- var rowsPerPage = $.cookies.get(page.dbName + ".perpage");
+ var rowsPerPage = $.cookies.get(page.db.name + ".perpage");
if (rowsPerPage) $("#perpage").val(rowsPerPage);
page.populateViewsMenu();
@@ -66,8 +66,8 @@
$("#switch select").change(function() {
var viewName = $(this).val();
- if (!viewName) $.cookies.remove(page.dbName + ".view");
- location.href = "?" + page.dbName + (viewName ? "/" + viewName : "");
+ if (!viewName) $.cookies.remove(page.db.name + ".view");
+ location.href = "?" + page.db.name + (viewName ? "/" + viewName : "");
});
$("#documents thead th.key").click(function() {
$(this).toggleClass("desc");
@@ -75,7 +75,7 @@
});
$("#perpage").change(function() {
page.updateDocumentListing();
- $.cookies.set(page.dbName + ".perpage", this.value);
+ $.cookies.set(page.db.name + ".perpage", this.value);
});
$("#toolbar button.add").click(page.addDocument);
$("#toolbar button.compact").click(page.compactDatabase);
@@ -91,7 +91,7 @@
</h1>
<div id="wrap">
<div id="switch">
- <label>Select view: <select>
+ <label>Select view: <select autocomplete="false">
<option value="">All documents</option>
<option value="_design_docs">Design documents</option>
<option value="_temp_view">Custom query…</option>
Modified: incubator/couchdb/branches/futon-async/share/www/script/browse.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/script/browse.js?rev=647638&r1=647637&r2=647638&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/script/browse.js [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/script/browse.js [utf-8] Sun Apr 13 15:53:50 2008
@@ -78,7 +78,7 @@
} else {
viewName = $.cookies.get(dbName + ".view") || "";
}
- var db = new CouchDB(dbName);
+ var db = $.couch.db(dbName);
this.dbName = dbName;
this.viewName = viewName;
@@ -88,99 +88,125 @@
this.addDocument = function() {
$.showDialog("_create_document.html", {
- submit: function(data) {
- try {
- var result = db.save(data.docid ? {_id: data.docid} : {});
- } catch (err) {
- return {docid: err.reason};
- }
- location.href = "document.html?" + dbName + "/" + result.id;
+ submit: function(data, callback) {
+ db.save(data.docid ? {_id: data.docid} : {}, {
+ error: function(error, reason) {
+ callback({docid: reason});
+ },
+ success: function(resp) {
+ location.href = "document.html?" + dbName + "/" + result.id;
+ }
+ });
}
});
}
this.compactDatabase = function() {
$.showDialog("_compact_database.html", {
- submit: function() {
- db.compact();
+ submit: function(data, callback) {
+ db.compact({
+ error: function(error, reason) {
+ alert(reason);
+ },
+ success: function(resp) {
+ callback();
+ }
+ });
}
});
}
this.deleteDatabase = function() {
$.showDialog("_delete_database.html", {
- submit: function() {
- db.deleteDb();
- location.href = "index.html";
- if (window !== null) {
- parent.$("#dbs li").filter(function(index) {
- return $("a", this).text() == dbName;
- }).remove();
- }
+ submit: function(data, callback) {
+ db.drop({
+ success: function(resp) {
+ callback();
+ location.href = "index.html";
+ if (window !== null) {
+ parent.$("#dbs li").filter(function(index) {
+ return $("a", this).text() == dbName;
+ }).remove();
+ }
+ }
+ });
}
});
}
this.populateViewEditor = function() {
if (viewName.match(/^_design\//)) {
- page.revertViewChanges();
- var dirtyTimeout = null;
- function updateDirtyState() {
- clearTimeout(dirtyTimeout);
- dirtyTimeout = setTimeout(function() {
- var buttons = $("#viewcode button.save, #viewcode button.revert");
- page.isDirty = $("#viewcode textarea").val() != page.storedViewCode;
- if (page.isDirty) {
- buttons.removeAttr("disabled");
- } else {
- buttons.attr("disabled", "disabled");
- }
- }, 100);
- }
- $("#viewcode textarea").bind("input", updateDirtyState);
- if ($.browser.msie) { // sorry, browser detection
- $("#viewcode textarea").get(0).onpropertychange = updateDirtyState
- } else if ($.browser.safari) {
- $("#viewcode textarea").bind("paste", updateDirtyState)
- .bind("change", updateDirtyState)
- .bind("keydown", updateDirtyState)
- .bind("keypress", updateDirtyState)
- .bind("keyup", updateDirtyState)
- .bind("textInput", updateDirtyState);
- }
+ page.revertViewChanges(function() {
+ var dirtyTimeout = null;
+ function updateDirtyState() {
+ clearTimeout(dirtyTimeout);
+ dirtyTimeout = setTimeout(function() {
+ var buttons = $("#viewcode button.save, #viewcode button.revert");
+ page.isDirty = $("#viewcode textarea").val() != page.storedViewCode;
+ if (page.isDirty) {
+ buttons.removeAttr("disabled");
+ } else {
+ buttons.attr("disabled", "disabled");
+ }
+ }, 100);
+ }
+ $("#viewcode textarea").bind("input", updateDirtyState);
+ if ($.browser.msie) { // sorry, browser detection
+ $("#viewcode textarea").get(0).onpropertychange = updateDirtyState
+ } else if ($.browser.safari) {
+ $("#viewcode textarea").bind("paste", updateDirtyState)
+ .bind("change", updateDirtyState)
+ .bind("keydown", updateDirtyState)
+ .bind("keypress", updateDirtyState)
+ .bind("keyup", updateDirtyState)
+ .bind("textInput", updateDirtyState);
+ }
+ });
}
}
this.populateViewsMenu = function() {
- var designDocs = db.allDocs({startkey: "_design/", endkey: "_design/ZZZ"});
- $("#switch select").each(function() {
- this.options.length = 3;
- for (var i = 0; i < designDocs.rows.length; i++) {
- var doc = db.open(designDocs.rows[i].id);
- var optGroup = $("<optgroup></optgroup>").attr("label", doc._id.substr(8));
- for (var name in doc.views) {
- if (!doc.views.hasOwnProperty(name)) continue;
- $("<option></option>").attr("value", doc._id + "/" + name).text(name)
- .appendTo(optGroup);
+ var select = $("#switch select");
+ db.allDocs({startkey: "_design/", endkey: "_design/ZZZ",
+ success: function(resp) {
+ select[0].options.length = 3;
+ for (var i = 0; i < resp.rows.length; i++) {
+ db.openDoc(resp.rows[i].id, {
+ success: function(doc) {
+ var optGroup = $("<optgroup></optgroup>").attr("label", doc._id.substr(8));
+ for (var name in doc.views) {
+ if (!doc.views.hasOwnProperty(name)) continue;
+ var option = $("<option></option>").attr("value", doc._id + "/" + name).text(name)
+ .appendTo(optGroup);
+ if (doc._id + "/" + name == viewName) {
+ option[0].selected = true;
+ }
+ }
+ optGroup.appendTo(select);
+ }
+ });
}
- optGroup.appendTo(this);
}
- this.autocomplete = false;
});
}
- this.revertViewChanges = function() {
+ this.revertViewChanges = function(callback) {
if (!page.storedViewCode) {
var viewNameParts = viewName.split("/");
var designDocId = viewNameParts[1];
var localViewName = viewNameParts[2];
- var designDoc = db.open(["_design", designDocId].join("/"));
- if (designDoc) {
- page.storedViewCode = designDoc.views[localViewName];
- }
+ db.openDoc(["_design", designDocId].join("/"), {
+ success: function(resp) {
+ page.storedViewCode = resp.views[localViewName];
+ $("#viewcode textarea").val(page.storedViewCode);
+ callback();
+ }
+ });
+ } else {
+ $("#viewcode textarea").val(page.storedViewCode);
+ page.isDirty = false;
+ callback();
}
- $("#viewcode textarea").val(page.storedViewCode);
- page.isDirty = false;
$("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
}
@@ -249,9 +275,12 @@
var designDoc = db.open(["_design", designDocId].join("/"));
var viewCode = $("#viewcode textarea").val();
designDoc.views[localViewName] = viewCode;
- db.save(designDoc);
- page.isDirty = false;
- $("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
+ db.saveDoc(designDoc, {
+ success: function(resp) {
+ page.isDirty = false;
+ $("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
+ }
+ });
}
this.updateDesignDocLink = function() {
@@ -264,6 +293,7 @@
}
this.updateDocumentListing = function(options) {
+ $(document.body).addClass("loading");
if (options === undefined) options = {};
if (options.count === undefined) {
options.count = parseInt($("#perpage").val(), 10);
@@ -279,99 +309,92 @@
$("#documents tbody.content").empty();
this.updateDesignDocLink();
- var result = null;
+ function handleResults(resp) {
+ if (resp.offset === undefined) {
+ resp.offset = 0;
+ }
+ if (resp.offset > 0) {
+ $("#paging a.prev").attr("href", "#" + (resp.offset - options.count)).click(function() {
+ var firstDoc = resp.rows[0];
+ page.updateDocumentListing({
+ startkey: firstDoc.key !== undefined ? firstDoc.key : null,
+ startkey_docid: firstDoc.id,
+ skip: 1,
+ count: -options.count
+ });
+ return false;
+ });
+ } else {
+ $("#paging a.prev").removeAttr("href");
+ }
+ if (resp.total_rows - resp.offset > options.count) {
+ $("#paging a.next").attr("href", "#" + (resp.offset + options.count)).click(function() {
+ var lastDoc = resp.rows[resp.rows.length - 1];
+ page.updateDocumentListing({
+ startkey: lastDoc.key !== undefined ? lastDoc.key : null,
+ startkey_docid: lastDoc.id,
+ skip: 1,
+ count: options.count
+ });
+ return false;
+ });
+ } else {
+ $("#paging a.next").removeAttr("href");
+ }
+
+ for (var i = 0; i < resp.rows.length; i++) {
+ var row = resp.rows[i];
+ var tr = $("<tr></tr>");
+ var key = row.key;
+ $("<td class='key'><a href='document.html?" + db.name + "/" + row.id + "'>" +
+ "<em></em><br><span class='docid'>ID: " + row.id +
+ "</span></a></td>").find("em").text(
+ key !== null ? prettyPrintJSON(key, 0, "") : "null"
+ ).end().appendTo(tr);
+ var value = row.value;
+ $("<td class='value'></td>").text(
+ value !== null ? prettyPrintJSON(value, 0, "") : "null"
+ ).appendTo(tr).dblclick(function() {
+ location.href = this.previousSibling.firstChild.href;
+ });
+ tr.appendTo("#documents tbody.content");
+ }
+
+ $("#documents tbody tr:odd").addClass("odd");
+ $("#documents tbody.footer td span").text(
+ "Showing " + Math.min(resp.total_rows, resp.offset + 1) + "-" +
+ (resp.offset + resp.rows.length) + " of " + resp.total_rows +
+ " document" + (resp.total_rows != 1 ? "s" : ""));
+ $(document.body).removeClass("loading");
+ }
+ options.success = handleResults;
+ options.error = function(error, reason) {
+ alert(reason);
+ }
+
if (!viewName) {
$("#switch select").get(0).selectedIndex = 0;
- result = db.allDocs(options);
+ db.allDocs(options);
} else {
- $("#switch select").each(function() {
- for (var i = 0; i < this.options.length; i++) {
- if (this.options[i].value == viewName) {
- this.selectedIndex = i;
- break;
- }
- }
- });
- docs = [];
if (viewName == "_temp_view") {
$("#viewcode").show().addClass("expanded");
var query = $("#viewcode textarea").val();
$.cookies.set(db.name + ".query", query);
- try {
- result = db.query(query, options);
- } catch (e) {
- alert(e.reason ? e.reason : e.message);
- return;
- }
+ db.query(query, options);
} else if (viewName == "_design_docs") {
options.startkey = options.descending ? "_design/ZZZZ" : "_design/";
options.endkey = options.descending ? "_design/" : "_design/ZZZZ";
- result = db.allDocs(options);
+ db.allDocs(options);
} else {
$("#viewcode").show();
var currentViewCode = $("#viewcode textarea").val();
if (currentViewCode != page.storedViewCode) {
- result = db.query(currentViewCode, options);
+ db.query(currentViewCode, options);
} else {
- result = db.view(viewName.substr(8), options);
+ db.view(viewName.substr(8), options);
}
}
}
- if (result.offset === undefined) {
- result.offset = 0;
- }
- if (result.offset > 0) {
- $("#paging a.prev").attr("href", "#" + (result.offset - options.count)).click(function() {
- var firstDoc = result.rows[0];
- page.updateDocumentListing({
- startkey: firstDoc.key !== undefined ? firstDoc.key : null,
- startkey_docid: firstDoc.id,
- skip: 1,
- count: -options.count
- });
- return false;
- });
- } else {
- $("#paging a.prev").removeAttr("href");
- }
- if (result.total_rows - result.offset > options.count) {
- $("#paging a.next").attr("href", "#" + (result.offset + options.count)).click(function() {
- var lastDoc = result.rows[result.rows.length - 1];
- page.updateDocumentListing({
- startkey: lastDoc.key !== undefined ? lastDoc.key : null,
- startkey_docid: lastDoc.id,
- skip: 1,
- count: options.count
- });
- return false;
- });
- } else {
- $("#paging a.next").removeAttr("href");
- }
-
- for (var i = 0; i < result.rows.length; i++) {
- var row = result.rows[i];
- var tr = $("<tr></tr>");
- var key = row.key;
- $("<td class='key'><a href='document.html?" + db.name + "/" + row.id + "'>" +
- "<em></em><br><span class='docid'>ID: " + row.id +
- "</span></a></td>").find("em").text(
- key !== null ? prettyPrintJSON(key, 0, "") : "null"
- ).end().appendTo(tr);
- var value = row.value;
- $("<td class='value'></td>").text(
- value !== null ? prettyPrintJSON(value, 0, "") : "null"
- ).appendTo(tr).dblclick(function() {
- location.href = this.previousSibling.firstChild.href;
- });
- tr.appendTo("#documents tbody.content");
- }
-
- $("#documents tbody tr:odd").addClass("odd");
- $("#documents tbody.footer td span").text(
- "Showing " + Math.min(result.total_rows, result.offset + 1) + "-" +
- (result.offset + result.rows.length) + " of " + result.total_rows +
- " document" + (result.total_rows != 1 ? "s" : ""));
}
window.onbeforeunload = function() {
Modified: incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js?rev=647638&r1=647637&r2=647638&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js [utf-8] Sun Apr 13 15:53:50 2008
@@ -23,8 +23,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
@@ -33,6 +35,21 @@
name: name,
uri: "/" + encodeURIComponent(name) + "/",
+ compact: function(options) {
+ $.ajax({
+ type: "POST", url: this.uri + "_compact", dataType: "json",
+ complete: function(req) {
+ var resp = $.httpData(req, "json");
+ if (req.status == 202 && options.success) {
+ options.success(resp);
+ } else if (options.error) {
+ options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
+ }
+ }
+ });
+ },
create: function(options) {
$.ajax({
type: "PUT", url: this.uri, dataType: "json",
@@ -42,8 +59,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
drop: function(options) {
@@ -55,8 +74,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
info: function(options) {
@@ -68,8 +89,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
allDocs: function(options) {
@@ -82,6 +105,8 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
},
});
@@ -97,8 +122,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
saveDoc: function(doc, options) {
@@ -121,8 +148,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
removeDoc: function(doc, options) {
@@ -136,8 +165,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
query: function(fun, options) {
@@ -152,8 +183,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
},
view: function(name, options) {
@@ -166,8 +199,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
}
};
@@ -182,8 +217,10 @@
options.success(resp);
} else if (options.error) {
options.error(resp.error, resp.reason);
+ } else {
+ alert(resp.reason);
}
- },
+ }
});
}
@@ -195,7 +232,7 @@
var buf = []
if (typeof(options) == "object" && options !== null) {
for (var name in options) {
- if (!options.hasOwnProperty(name)) continue;
+ if (name == "error" || name == "success") continue;
var value = options[name];
if (name == "key" || name == "startkey" || name == "endkey") {
value = toJSON(value);