Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Refactoring in Futon to clean up interactions between specific pages …
Browse files Browse the repository at this point in the history
…and the navigation. Also, switched some graphics over to PNGs with alpha-transparency (screw you IE6), and added a button for removing databases from the recent databases list.

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@733104 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cmlenz committed Jan 9, 2009
1 parent af89d8e commit 04ddce3
Show file tree
Hide file tree
Showing 28 changed files with 193 additions and 112 deletions.
45 changes: 0 additions & 45 deletions _sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,3 @@
<span id="version">?</span>
</div>
</div>
<script type="text/javascript">
function updateNavigation(path, queryString) {
function fixupPath(path) { // hack for IE/Win
return (path.charAt(0) != "/") ? ("/" + path) : path;
}
if (!path) {
path = location.pathname;
if (!queryString) {
queryString = location.search;
}
} else if (!queryString) {
queryString = "";
}
var href = fixupPath(path + queryString);
$("#nav li").removeClass("selected");
$("#nav li a").each(function() {
if (fixupPath(this.pathname) + this.search != href) return;
$(this).parent("li").addClass("selected").parents("li").addClass("selected");
});
}

function updateRecentDatabasesList() {
$("#dbs").empty();
var recentDbs = $.cookies.get("recent", "").split(",");
recentDbs.sort();
$.each(recentDbs, function(idx, name) {
if (name) {
$("#dbs").append("<li><a href='database.html?" +
encodeURIComponent(name) + "'>" + name +
"</a></li>");
}
});
}

$(function() {
document.title = "Apache CouchDB - Futon: " + document.title;
$.couch.info({
success: function(info, status) {
$("#version").text(info.version);
}
});
updateRecentDatabasesList();
updateNavigation();
});
</script>
5 changes: 1 addition & 4 deletions config.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
<script src="script/jquery.js?1.2.6"></script>
<script src="script/jquery.cookies.js?0.9.0"></script>
<script src="script/jquery.couch.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/pprint.js?0.9.0"></script>
<script>
$(document).ready(function() {
$.get("_sidebar.html", function(resp) {
$(resp).insertAfter("#wrap");
});

$(document.body).addClass("loading");
$.couch.config({
success: function(resp) {
Expand Down
5 changes: 1 addition & 4 deletions couch_tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
<script src="script/jquery.cookies.js?0.9.0"></script>
<script src="script/jquery.couch.js?0.9.0"></script>
<script src="script/couch.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/pprint.js?0.9.0"></script>
<script src="script/couch_test_runner.js"></script>
<script>
$(function() {
$.get("_sidebar.html", function(resp) {
$(resp).insertAfter("#wrap");
});

updateTestsListing();
$("#toolbar button.run").click(runAllTests);
$("#toolbar button.load").click(function() {
Expand Down
19 changes: 6 additions & 13 deletions database.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,15 @@
<script src="script/jquery.dialog.js?0.9.0"></script>
<script src="script/jquery.resizer.js?0.9.0"></script>
<script src="script/jquery.suggest.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/browse.js?0.9.0"></script>
<script src="script/pprint.js?0.9.0"></script>
<script>
var page = new CouchDatabasePage();

$.get("_sidebar.html", function(resp) {
$(resp).insertAfter("#wrap");

var recentDbs = $.cookies.get("recent", "").split(",");
if ($.inArray(page.db.name, recentDbs) == -1) {
recentDbs.unshift(page.db.name);
if (recentDbs.length > 10) recentDbs.length = 10;
$.cookies.set("recent", recentDbs.join(","));
updateRecentDatabasesList();
}

updateNavigation(location.pathname, "?" + page.db.name);
$.futon.navigation.ready(function() {
this.addDatabase(page.db.name);
this.updateSelection(location.pathname, "?" + page.db.name);
});

$(function() {
Expand Down Expand Up @@ -91,6 +83,7 @@

$("#switch select").change(function() {
var viewName = $(this).val();
console.log(viewName);
if (!viewName) $.cookies.remove(page.db.name + ".view");
location.href = "?" + encodeURIComponent(page.db.name) +
(viewName ? "/" + encodeURIComponent(viewName) : "");
Expand Down Expand Up @@ -118,7 +111,7 @@ <h1>
<div id="content">
<div id="switch">
<label>Select view: <select autocomplete="false">
<option value="">All documents</option>
<option value="_all_docs">All documents</option>
<option value="_design_docs">Design documents</option>
<option value="_slow_view">Custom query…</option>
</select></label>
Expand Down
17 changes: 9 additions & 8 deletions document.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@
<script src="script/jquery.dialog.js?0.9.0"></script>
<script src="script/jquery.form.js?0.9.0"></script>
<script src="script/jquery.resizer.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/browse.js?0.9.0"></script>
<script src="script/pprint.js?0.9.0"></script>
<script>
var page = new CouchDocumentPage();

$(function() {
$.get("_sidebar.html", function(resp) {
$(resp).insertAfter("#wrap");

updateNavigation(
location.pathname.replace(/document\.html/, "database.html"),
"?" + page.db.name);
});
$.futon.navigation.ready(function() {
this.addDatabase(page.db.name);
this.updateSelection(
location.pathname.replace(/document\.html/, "database.html"),
"?" + page.db.name
);
});

$(function() {
$("h1 a.dbname").text(page.dbName)
.attr("href", "database.html?" + encodeURIComponent(page.db.name));
$("h1 strong").text(page.docId);
Expand Down
Binary file removed image/add.gif
Binary file not shown.
Binary file added image/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/compact.gif
Binary file not shown.
Binary file added image/compact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/delete-mini.gif
Binary file not shown.
Binary file added image/delete-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/delete.gif
Binary file not shown.
Binary file added image/delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/load.gif
Binary file not shown.
Binary file added image/load.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/run-mini.gif
Binary file not shown.
Binary file added image/run-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/run.gif
Binary file not shown.
Binary file added image/run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/running.gif
Binary file not shown.
Binary file added image/running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/save.gif
Binary file not shown.
Binary file added image/save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
<script src="script/jquery.cookies.js?0.9.0"></script>
<script src="script/jquery.couch.js?0.9.0"></script>
<script src="script/jquery.dialog.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/browse.js?0.9.0"></script>
<script src="script/pprint.js?0.9.0"></script>
<script>
var page = new CouchIndexPage();
$(document).ready(function() {
$.get("_sidebar.html", function(resp) {
$(resp).insertAfter("#wrap");
if (!/index\.html$/.test(location.pathname)) {
updateNavigation(location.pathname + "index.html");
}
});
if (!/index\.html$/.test(location.pathname)) {
$.futon.navigation.ready(function() {
this.updateSelection(location.pathname + "index.html");
});
}
var dbsPerPage = $.cookies.get("perpage");
if (dbsPerPage) $("#perpage").val(dbsPerPage);
$("#perpage").change(function() {
Expand Down
5 changes: 1 addition & 4 deletions replicator.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
<script src="script/jquery.js?1.2.6"></script>
<script src="script/jquery.cookies.js?0.9.0"></script>
<script src="script/jquery.couch.js?0.9.0"></script>
<script src="script/futon.js?0.9.0"></script>
<script src="script/pprint.js?0.9.0"></script>
<script>
$(document).ready(function() {
$.get("_sidebar.html", function(resp) {
$(resp).insertAfter("#wrap");
});

$("fieldset input[type=radio]").click(function() {
var radio = this;
var fieldset = $(this).parents("fieldset").get(0);
Expand Down
41 changes: 24 additions & 17 deletions script/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ function CouchDatabasePage() {
viewName = decodeURIComponent(viewName);
$.cookies.set(dbName + ".view", viewName);
} else {
viewName = $.cookies.get(dbName + ".view") || "";
viewName = $.cookies.get(dbName + ".view", "");
if (viewName) {
location.href = "database.html?" + dbName + "/" + viewName;
}
}
var db = $.couch.db(dbName);

Expand Down Expand Up @@ -157,15 +160,7 @@ function CouchDatabasePage() {
$("#dbs li").filter(function(index) {
return $("a", this).text() == dbName;
}).remove();

// remove database from recent databases list
var recentDbs = $.cookies.get("recent", "").split(",");
var recentIdx = $.inArray(db.name, recentDbs)
if (recentIdx >= 0) {
recentDbs.splice(recentIdx, 1);
$.cookies.set("recent", recentDbs.join(","));
updateRecentDatabasesList();
}
$.futon.navigation.removeDatabase(dbName);
}
}
});
Expand Down Expand Up @@ -200,6 +195,11 @@ function CouchDatabasePage() {
.bind("textInput", updateDirtyState);
}
});
} else if (viewName == "_slow_view") {
page.updateViewEditor(
$.cookies.get(db.name + ".map"),
$.cookies.get(db.name + ".reduce", "")
);
}
}

Expand Down Expand Up @@ -252,11 +252,7 @@ function CouchDatabasePage() {
},
success: function(resp) {
var viewCode = resp.views[localViewName];
$("#viewcode_map").val(viewCode.map);
$("#viewcode_reduce").val(viewCode.reduce || "");
var lines = Math.max(viewCode.map.split("\n").length,
(viewCode.reduce ? viewCode.reduce.split("\n").length : 1));
$("#viewcode textarea").attr("rows", Math.min(15, Math.max(3, lines)));
page.updateViewEditor(viewCode.map, viewCode.reduce || "");
$("#viewcode button.revert, #viewcode button.save").attr("disabled", "disabled");
page.storedViewCode = viewCode;
if (callback) callback();
Expand All @@ -271,13 +267,24 @@ function CouchDatabasePage() {
}
}

this.updateViewEditor = function(mapFun, reduceFun) {
if (!mapFun) return;
$("#viewcode_map").val(mapFun);
$("#viewcode_reduce").val(reduceFun);
var lines = Math.max(
mapFun.split("\n").length,
reduceFun.split("\n").length
);
$("#viewcode textarea").attr("rows", Math.min(15, Math.max(3, lines)));
}

this.saveViewAs = function() {
if (viewName && /^_design/.test(viewName)) {
var viewNameParts = viewName.split("/");
var designDocId = viewNameParts[1];
var localViewName = viewNameParts[2];
} else {
var designDocId = "", localViewName = ""
var designDocId = "", localViewName = "";
}
$.showDialog("dialog/_save_view_as.html", {
load: function(elem) {
Expand Down Expand Up @@ -496,7 +503,7 @@ function CouchDatabasePage() {
$(document.body).removeClass("loading");
}

if (!viewName) {
if (!viewName || viewName == "_all_docs") {
$("#switch select")[0].selectedIndex = 0;
db.allDocs(options);
} else {
Expand Down
Loading

0 comments on commit 04ddce3

Please sign in to comment.