diff options
29 files changed, 203 insertions, 121 deletions
diff --git a/share/Makefile.am b/share/Makefile.am index b2bba8f5..fa7545d2 100644 --- a/share/Makefile.am +++ b/share/Makefile.am @@ -21,25 +21,25 @@ nobase_dist_localdata_DATA = \ www/dialog/_upload_attachment.html \ www/couch_tests.html \ www/favicon.ico \ - www/image/add.gif \ + www/image/add.png \ www/image/apply.gif \ www/image/bg.png \ www/image/cancel.gif \ - www/image/compact.gif \ - www/image/delete-mini.gif \ - www/image/delete.gif \ + www/image/compact.png \ + www/image/delete-mini.png \ + www/image/delete.png \ www/image/grippie.gif \ www/image/hgrad.gif \ - www/image/load.gif \ + www/image/load.png \ www/image/logo.png \ www/image/order-asc.gif \ www/image/order-desc.gif \ www/image/path.gif \ www/image/progress.gif \ - www/image/run-mini.gif \ - www/image/run.gif \ - www/image/running.gif \ - www/image/save.gif \ + www/image/run-mini.png \ + www/image/run.png \ + www/image/running.png \ + www/image/save.png \ www/image/spinner.gif \ www/image/test_failure.gif \ www/image/test_success.gif \ @@ -58,6 +58,7 @@ nobase_dist_localdata_DATA = \ www/script/couch.js \ www/script/couch_tests.js \ www/script/couch_test_runner.js \ + www/script/futon.js \ www/script/jquery.js \ www/script/jquery.cookies.js \ www/script/jquery.couch.js \ diff --git a/share/www/_sidebar.html b/share/www/_sidebar.html index 9bddda37..6ef988b9 100644 --- a/share/www/_sidebar.html +++ b/share/www/_sidebar.html @@ -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> diff --git a/share/www/config.html b/share/www/config.html index 7eab0448..f9b95c1a 100644 --- a/share/www/config.html +++ b/share/www/config.html @@ -22,13 +22,10 @@ specific language governing permissions and limitations under the License. <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) { diff --git a/share/www/couch_tests.html b/share/www/couch_tests.html index de471382..bab4912d 100644 --- a/share/www/couch_tests.html +++ b/share/www/couch_tests.html @@ -23,14 +23,11 @@ specific language governing permissions and limitations under the License. <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() { diff --git a/share/www/database.html b/share/www/database.html index abe9e28c..ec5134d6 100644 --- a/share/www/database.html +++ b/share/www/database.html @@ -25,23 +25,15 @@ specific language governing permissions and limitations under the License. <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() { @@ -91,6 +83,7 @@ specific language governing permissions and limitations under the License. $("#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) : ""); @@ -118,7 +111,7 @@ specific language governing permissions and limitations under the License. <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> diff --git a/share/www/document.html b/share/www/document.html index 3f39cb75..f12adf68 100644 --- a/share/www/document.html +++ b/share/www/document.html @@ -25,20 +25,21 @@ specific language governing permissions and limitations under the License. <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); diff --git a/share/www/image/add.gif b/share/www/image/add.gif Binary files differdeleted file mode 100644 index 9a65fc80..00000000 --- a/share/www/image/add.gif +++ /dev/null diff --git a/share/www/image/add.png b/share/www/image/add.png Binary files differnew file mode 100644 index 00000000..34e8c7d7 --- /dev/null +++ b/share/www/image/add.png diff --git a/share/www/image/compact.gif b/share/www/image/compact.gif Binary files differdeleted file mode 100644 index 21b5762d..00000000 --- a/share/www/image/compact.gif +++ /dev/null diff --git a/share/www/image/compact.png b/share/www/image/compact.png Binary files differnew file mode 100644 index 00000000..ea8985dc --- /dev/null +++ b/share/www/image/compact.png diff --git a/share/www/image/delete-mini.gif b/share/www/image/delete-mini.gif Binary files differdeleted file mode 100644 index b2090067..00000000 --- a/share/www/image/delete-mini.gif +++ /dev/null diff --git a/share/www/image/delete-mini.png b/share/www/image/delete-mini.png Binary files differnew file mode 100644 index 00000000..ad5588d9 --- /dev/null +++ b/share/www/image/delete-mini.png diff --git a/share/www/image/delete.gif b/share/www/image/delete.gif Binary files differdeleted file mode 100644 index 0e58475f..00000000 --- a/share/www/image/delete.gif +++ /dev/null diff --git a/share/www/image/delete.png b/share/www/image/delete.png Binary files differnew file mode 100644 index 00000000..e8384017 --- /dev/null +++ b/share/www/image/delete.png diff --git a/share/www/image/load.gif b/share/www/image/load.gif Binary files differdeleted file mode 100644 index e06762e9..00000000 --- a/share/www/image/load.gif +++ /dev/null diff --git a/share/www/image/load.png b/share/www/image/load.png Binary files differnew file mode 100644 index 00000000..07b4f791 --- /dev/null +++ b/share/www/image/load.png diff --git a/share/www/image/run-mini.gif b/share/www/image/run-mini.gif Binary files differdeleted file mode 100644 index 6256ef1d..00000000 --- a/share/www/image/run-mini.gif +++ /dev/null diff --git a/share/www/image/run-mini.png b/share/www/image/run-mini.png Binary files differnew file mode 100644 index 00000000..b2fcbd82 --- /dev/null +++ b/share/www/image/run-mini.png diff --git a/share/www/image/run.gif b/share/www/image/run.gif Binary files differdeleted file mode 100644 index 386ee04a..00000000 --- a/share/www/image/run.gif +++ /dev/null diff --git a/share/www/image/run.png b/share/www/image/run.png Binary files differnew file mode 100644 index 00000000..a1d79f65 --- /dev/null +++ b/share/www/image/run.png diff --git a/share/www/image/running.gif b/share/www/image/running.gif Binary files differdeleted file mode 100644 index b7924420..00000000 --- a/share/www/image/running.gif +++ /dev/null diff --git a/share/www/image/running.png b/share/www/image/running.png Binary files differnew file mode 100644 index 00000000..9b50cd67 --- /dev/null +++ b/share/www/image/running.png diff --git a/share/www/image/save.gif b/share/www/image/save.gif Binary files differdeleted file mode 100644 index fb713ca7..00000000 --- a/share/www/image/save.gif +++ /dev/null diff --git a/share/www/image/save.png b/share/www/image/save.png Binary files differnew file mode 100644 index 00000000..a04e4bcc --- /dev/null +++ b/share/www/image/save.png diff --git a/share/www/index.html b/share/www/index.html index 07bc63d4..37df0960 100644 --- a/share/www/index.html +++ b/share/www/index.html @@ -23,17 +23,17 @@ specific language governing permissions and limitations under the License. <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() { diff --git a/share/www/replicator.html b/share/www/replicator.html index e5442a02..2637cc1b 100644 --- a/share/www/replicator.html +++ b/share/www/replicator.html @@ -22,13 +22,10 @@ specific language governing permissions and limitations under the License. <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); diff --git a/share/www/script/browse.js b/share/www/script/browse.js index 66acd679..f6aad59f 100644 --- a/share/www/script/browse.js +++ b/share/www/script/browse.js @@ -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); @@ -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); } } }); @@ -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", "") + ); } } @@ -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(); @@ -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) { @@ -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 { diff --git a/share/www/script/futon.js b/share/www/script/futon.js new file mode 100644 index 00000000..bf148189 --- /dev/null +++ b/share/www/script/futon.js @@ -0,0 +1,127 @@ +// 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. + +(function($) { + + function Navigation() { + var nav = this; + this.loaded = false; + this.eventHandlers = { + load: [] + }; + + this.ready = function(callback) { + if (callback) { + if (this.loaded) { + callback.apply(this); + } + this.eventHandlers["load"].push(callback); + } else { + this.loaded = true; + callbacks = this.eventHandlers["load"]; + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].apply(this); + } + } + } + + this.addDatabase = function(name) { + var recentDbs = $.cookies.get("recent", "").split(","); + if ($.inArray(name, recentDbs) == -1) { + recentDbs.unshift(name); + if (recentDbs.length > 10) recentDbs.length = 10; + $.cookies.set("recent", recentDbs.join(",")); + this.updateDatabases(); + } + } + + this.removeDatabase = function(name) { + // remove database from recent databases list + var recentDbs = $.cookies.get("recent", "").split(","); + var recentIdx = $.inArray(name, recentDbs); + if (recentIdx >= 0) { + recentDbs.splice(recentIdx, 1); + $.cookies.set("recent", recentDbs.join(",")); + this.updateDatabases(); + } + } + + this.updateDatabases = function() { + var selection = null; + $("#dbs .selected a").each(function() { + selection = [this.pathname, this.search]; + }); + $("#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 + + "<button class='remove' title='Remove from list' value='" + name + "'></button>" + + "</a></li>"); + } + }); + if (selection) { + this.updateSelection(selection[0], selection[1]); + } + $("#dbs button.remove").click(function() { + nav.removeDatabase(this.value); + return false; + }); + } + + this.updateSelection = function(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"); + }); + } + + } + + $.futon = $.futon || {}; + $.fn.extend($.futon, { + navigation: new Navigation() + }); + + $(function() { + document.title = "Apache CouchDB - Futon: " + document.title; + $.get("_sidebar.html", function(resp) { + $(resp).insertAfter("#wrap"); + + $.futon.navigation.updateDatabases(); + $.futon.navigation.updateSelection(); + $.futon.navigation.ready(); + + $.couch.info({ + success: function(info, status) { + $("#version").text(info.version); + } + }); + }); + }); + +})(jQuery); diff --git a/share/www/style/layout.css b/share/www/style/layout.css index e67fa78a..6e649463 100644 --- a/share/www/style/layout.css +++ b/share/www/style/layout.css @@ -163,6 +163,14 @@ ul.suggest-dropdown li.selected { cursor: pointer; background: Highlight; #nav li li.selected :link:hover, #nav li li.selected :visited:hover { color: #fff; } +#nav li button { background: transparent 0 0 no-repeat; border: none; + cursor: pointer; width: 15px; height: 15px; margin-left: .5em; + vertical-align: top; +} +#nav li li:hover button.remove { + background-image: url(../image/delete-mini.png); +} +#nav li button.remove:hover { background-position: -15px 0; } #footer { background: #ddd; border-top: 1px solid #bbb; color: #000; font-size: 80%; opacity: .7; padding: 5px 10px; position: absolute; right: 0; @@ -185,13 +193,12 @@ ul.suggest-dropdown li.selected { cursor: pointer; background: Highlight; } #toolbar button:hover { background-position: 2px -30px; color: #000; } #toolbar button:active { background-position: 2px -62px; color: #000; } -#toolbar button.add { background-image: url(../image/add.gif); } -#toolbar button.compact { background-image: url(../image/compact.gif); } -#toolbar button.delete { background-image: url(../image/delete.gif); } -#toolbar button.edit { background-image: url(../image/edit.gif); } -#toolbar button.load { background-image: url(../image/load.gif); } -#toolbar button.run { background-image: url(../image/run.gif); } -#toolbar button.save { background-image: url(../image/save.gif); } +#toolbar button.add { background-image: url(../image/add.png); } +#toolbar button.compact { background-image: url(../image/compact.png); } +#toolbar button.delete { background-image: url(../image/delete.png); } +#toolbar button.load { background-image: url(../image/load.png); } +#toolbar button.run { background-image: url(../image/run.png); } +#toolbar button.save { background-image: url(../image/save.png); } /* Dialogs */ @@ -344,7 +351,7 @@ ul.suggest-dropdown li.selected { cursor: pointer; background: Highlight; #fields col.field { width: 33%; } #fields tbody.content th { padding-left: 25px; padding-right: 48px; } #fields tbody.content th button { - background-image: url(../image/delete-mini.gif); + background-image: url(../image/delete-mini.png); } #fields tbody.content th b { display: block; padding: 2px; } #fields tbody.content td { padding-left: 14px; padding-right: 48px; } @@ -421,7 +428,7 @@ ul.suggest-dropdown li.selected { cursor: pointer; background: Highlight; background-position: -15px 0; } #fields tbody.content td ul.attachments li button.delete { - background-image: url(../image/delete-mini.gif); + background-image: url(../image/delete-mini.png); } #fields tbody.source td code { display: block; overflow: auto; white-space: pre-wrap; width: 100%; @@ -437,7 +444,7 @@ ul.suggest-dropdown li.selected { cursor: pointer; background: Highlight; white-space: nowrap; } #tests tbody.content th button { - background-image: url(../image/run-mini.gif); + background-image: url(../image/run-mini.png); } #tests tbody.content td.duration { text-align: right; width: 6em; } #tests tbody.content td.status { background-position: 5px 8px; @@ -454,7 +461,7 @@ ul.suggest-dropdown li.selected { cursor: pointer; background: Highlight; #tests tbody.content td.details ol code { color: #c00; font-size: 100%; } #tests tbody.content td.details ol code.error { white-space: pre; } #tests tbody.content td.running { - background-image: url(../image/running.gif); color: #333; + background-image: url(../image/running.png); color: #333; } #tests tbody.content td.success { background-image: url(../image/test_success.gif); color: #060; |