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/13 21:59:42 UTC

svn commit: r647619 - in /incubator/couchdb/branches/futon-async/share: ./ www/ www/browse/ www/image/ www/script/ www/style/

Author: cmlenz
Date: Sun Apr 13 12:59:39 2008
New Revision: 647619

URL: http://svn.apache.org/viewvc?rev=647619&view=rev
Log:
futon-async branch: first steps, made database index page async.

Added:
    incubator/couchdb/branches/futon-async/share/www/image/progress.gif
      - copied unchanged from r647572, incubator/couchdb/branches/futon-async/share/www/image/spinner.gif
    incubator/couchdb/branches/futon-async/share/www/image/spinner.gif   (with props)
    incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js   (with props)
Modified:
    incubator/couchdb/branches/futon-async/share/Makefile.am
    incubator/couchdb/branches/futon-async/share/www/browse/index.html
    incubator/couchdb/branches/futon-async/share/www/index.html
    incubator/couchdb/branches/futon-async/share/www/script/browse.js
    incubator/couchdb/branches/futon-async/share/www/script/jquery.dialog.js
    incubator/couchdb/branches/futon-async/share/www/style/layout.css

Modified: incubator/couchdb/branches/futon-async/share/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/Makefile.am?rev=647619&r1=647618&r2=647619&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/Makefile.am (original)
+++ incubator/couchdb/branches/futon-async/share/Makefile.am Sun Apr 13 12:59:39 2008
@@ -39,6 +39,7 @@
     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 \
@@ -58,6 +59,7 @@
     www/script/couch_tests.js \
     www/script/jquery.js \
     www/script/jquery.cookies.js \
+    www/script/jquery.couch.js \
     www/script/jquery.dialog.js \
     www/script/jquery.resizer.js \
     www/script/jquery.suggest.js \

Modified: incubator/couchdb/branches/futon-async/share/www/browse/index.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/browse/index.html?rev=647619&r1=647618&r2=647619&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/browse/index.html [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/browse/index.html [utf-8] Sun Apr 13 12:59:39 2008
@@ -21,8 +21,8 @@
     <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/couch.js"></script>
     <script src="../script/browse.js"></script>
     <script src="../script/pprint.js"></script>
     <script>

Added: incubator/couchdb/branches/futon-async/share/www/image/spinner.gif
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/image/spinner.gif?rev=647619&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/couchdb/branches/futon-async/share/www/image/spinner.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/couchdb/branches/futon-async/share/www/index.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/index.html?rev=647619&r1=647618&r2=647619&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/index.html [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/index.html [utf-8] Sun Apr 13 12:59:39 2008
@@ -28,16 +28,19 @@
     </style>
     <script src="script/json2.js"></script>
     <script src="script/jquery.js"></script>
-    <script src="script/couch.js"></script>
+    <script src="script/jquery.couch.js"></script>
     <script>
       function updateDatabaseList() {
-        var dbs = CouchDB.allDbs();
-        $("#dbs").empty();
-        for (var i = 0; i < dbs.length; i++) {
-          var dbname = dbs[i];
-          $("#dbs").append("<li><a href='browse/database.html?" + dbname +
-            "' target='content'>" + dbname + "</a></li>");
-        }
+        var list = $("#dbs").empty();
+        var dbs = $.couch.allDbs({
+          success: function(dbs, status) {
+            for (var i = 0; i < dbs.length; i++) {
+              var dbName = dbs[i];
+              list.append("<li><a href='browse/database.html?" + dbName +
+                "' target='content'>" + dbName + "</a></li>");
+            }
+          }
+        });
       }
       function updateNavigation(path, queryString) {
         function fixupPath(path) { // hack for IE/Win
@@ -67,7 +70,11 @@
         });
       }
       $(function() {
-        $("#version").text(CouchDB.getVersion());
+        $.couch.info({
+          success: function(info, status) {
+            $("#version").text(info.version);
+          }
+        });
         updateDatabaseList();
       });
     </script>

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=647619&r1=647618&r2=647619&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 12:59:39 2008
@@ -18,35 +18,49 @@
 
   this.addDatabase = function() {
     $.showDialog("_create_database.html", {
-      submit: function(data) {
+      submit: function(data, callback) {
         if (!data.name || data.name.length == 0) {
-          return {name: "Please enter a name."};
+          callback({name: "Please enter a name."});
+          return;
         }
-        try {
-          new CouchDB(data.name).createDb();
-        } catch (e) {
-          return {name: e.reason};
-        }
-        if (window !== parent) parent.setTimeout("updateDatabaseList()", 500);
-        window.open("database.html?" + data.name, "content");
+        $.couch.db(data.name).create({
+          error: function(id, reason) { callback({name: reason}) },
+          success: function(resp) {
+            if (window !== parent) parent.setTimeout("updateDatabaseList()", 500);
+            window.open("database.html?" + data.name, "content");
+            callback();
+          }
+        });
       }
     });
     return false;
   }
 
   this.updateDatabaseListing = function() {
-    var allDbs = CouchDB.allDbs();
-    for (var i = 0; i < allDbs.length; i++) {
-      var dbName = allDbs[i];
-      var info = new CouchDB(dbName).info();
-      $("#databases tbody.content").append(
-        "<tr><th><a href='database.html?" + dbName + "'>" +
-        dbName + "</a></th><td class='size'>" + prettyPrintSize(info.disk_size) +
-        "</td><td class='count'>" + info.doc_count +
-        "</td><td class='seq'>" + info.update_seq + "</td></tr>");
-      $("#databases tbody tr:odd").addClass("odd");
-      $("#databases tbody.footer tr td").text(allDbs.length + " database(s)");
-    }
+    $(document.body).addClass("loading");
+    $.couch.allDbs({
+      success: function(dbs) {
+        $.each(dbs, function(idx, dbName) {
+          $("#databases tbody.content").append("<tr>" + 
+            "<th><a href='database.html?" + dbName + "'>" + dbName + "</a></th>" +
+            "<td class='size'></td><td class='count'></td>" +
+            "<td class='seq'></td></tr>");
+          $.couch.db(dbName).info({
+            success: function(info) {
+              $("#databases tbody.content tr:eq(" + idx + ")")
+                .find("td.size").text(prettyPrintSize(info.disk_size)).end()
+                .find("td.count").text(info.doc_count).end()
+                .find("td.seq").text(info.update_seq);
+              if (idx == dbs.length - 1) {
+                $(document.body).removeClass("loading");
+              }
+            }
+          });
+        });
+        $("#databases tbody tr:odd").addClass("odd");
+        $("#databases tbody.footer tr td").text(dbs.length + " database(s)");
+      }
+    });
   }
 
 }

Added: 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=647619&view=auto
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js (added)
+++ incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js [utf-8] Sun Apr 13 12:59:39 2008
@@ -0,0 +1,213 @@
+// 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($) {
+  $.couch = $.couch || {}
+  $.fn.extend($.couch, {
+
+    allDbs: function(options) {
+      $.ajax({
+        type: "GET", url: "/_all_dbs",
+        complete: function(req) {
+          var resp = $.httpData(req, "json");
+          if (req.status == 200 && options.success) {
+            options.success(resp);
+          } else if (options.error) {
+            options.error(resp.error, resp.reason);
+          }
+        },
+      });
+    },
+
+    db: function(name) {
+      return {
+        name: name,
+        uri: "/" + encodeURIComponent(name) + "/",
+
+        create: function(options) {
+          $.ajax({
+            type: "PUT", url: this.uri, dataType: "json",
+            complete: function(req) {
+              var resp = $.httpData(req, "json");
+              if (req.status == 201 && options.success) {
+                options.success(resp);
+              } else if (options.error) {
+                options.error(resp.error, resp.reason);
+              }
+            },
+          });
+        },
+        drop: function(options) {
+          $.ajax({
+            type: "DELETE", url: this.uri, 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);
+              }
+            },
+          });
+        },
+        info: function(options) {
+          $.ajax({
+            type: "GET", url: this.uri, dataType: "json",
+            complete: function(req) {
+              var resp = $.httpData(req, "json");
+              if (req.status == 200 && options.success) {
+                options.success(resp);
+              } else  if (options.error) {
+                options.error(resp.error, resp.reason);
+              }
+            },
+          });
+        },
+        allDocs: function(options) {
+          $.ajax({
+            type: "GET", url: this.uri + "_all_docs" + encodeOptions(options),
+            dataType: "json",
+            complete: function(req) {
+              var resp = $.httpData(req, "json");
+              if (req.status == 200 && options.success) {
+                options.success(resp);
+              } else if (options.error) {
+                options.error(resp.error, resp.reason);
+              }
+            },
+          });
+        },
+        openDoc: function(docId, options) {
+          $.ajax({
+            type: "GET",
+            url: this.uri + encodeURIComponent(docId) + encodeOptions(options),
+            dataType: "json",
+            complete: function(req) {
+              var resp = $.httpData(req, "json");
+              if (req.status == 200 && options.success) {
+                options.success(resp);
+              } else if (options.error) {
+                options.error(resp.error, resp.reason);
+              }
+            },
+          });
+        },
+        saveDoc: function(doc, options) {
+          if (doc._id === undefined) {
+            var method = "POST";
+            var uri = this.uri;
+          } else {
+            var method = "PUT";
+            var uri = this.uri  + encodeURIComponent(doc._id);
+          }
+          $.ajax({
+            type: method, url: uri + encodeOptions(options),
+            dataType: "json", data: toJSON(doc),
+            contentType: "application/json",
+            complete: function(req) {
+              var resp = $.httpData(req, "json")
+              doc._id = resp.id;
+              doc._rev = resp.rev;
+              if (req.status == 201 && options.success) {
+                options.success(resp);
+              } else if (options.error) {
+                options.error(resp.error, resp.reason);
+              }
+            },
+          });
+        },
+        removeDoc: function(doc, options) {
+          $.ajax({
+            type: "DELETE",
+            url: this.uri + encodeURIComponent(docId) + encodeOptions({rev: doc._rev}),
+            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);
+              }
+            },
+          });
+        },
+        query: function(fun, options) {
+          if (typeof(fun) != "string")
+            fun = fun.toSource ? fun.toSource() : "(" + fun.toString() + ")";
+          $.ajax({
+            type: "POST", url: this.uri + "_temp_view" + encodeOptions(options),
+            contentType: "text/javascript", data: fun, dataType: "json",
+            complete: function(req) {
+              var resp = $.httpData(req, "json");
+              if (req.status == 200 && options.success) {
+                options.success(resp);
+              } else if (options.error) {
+                options.error(resp.error, resp.reason);
+              }
+            },
+          });
+        },
+        view: function(name, options) {
+          $.ajax({
+            type: "GET", url: this.uri + "_view/" + name + encodeOptions(options),
+            dataType: "json",
+            complete: function(req) {
+              var resp = $.httpData(req, "json");
+              if (req.status == 200 && options.success) {
+                options.success(resp);
+              } else if (options.error) {
+                options.error(resp.error, resp.reason);
+              }
+            },
+          });
+        }
+      };
+    },
+
+    info: function(options) {
+      $.ajax({
+        type: "GET", url: "/", dataType: "json",
+        complete: function(req) {
+          var resp = $.httpData(req, "json");
+          if (req.status == 200 && options.success) {
+            options.success(resp);
+          } else if (options.error) {
+            options.error(resp.error, resp.reason);
+          }
+        },
+      });
+    }
+
+  });
+
+  // Convert a options object to an url query string.
+  // ex: {key:'value',key2:'value2'} becomes '?key="value"&key2="value2"'
+  function encodeOptions(options) {
+    var buf = []
+    if (typeof(options) == "object" && options !== null) {
+      for (var name in options) {
+        if (!options.hasOwnProperty(name)) continue;
+        var value = options[name];
+        if (name == "key" || name == "startkey" || name == "endkey") {
+          value = toJSON(value);
+        }
+        buf.push(encodeURIComponent(name) + "=" + encodeURIComponent(value));
+      }
+    }
+    return buf.length ? "?" + buf.join("&") : "";
+  }
+
+  function toJSON(obj) {
+    return obj !== null ? JSON.stringify(obj) : null;
+  }
+
+})(jQuery);

Propchange: incubator/couchdb/branches/futon-async/share/www/script/jquery.couch.js
------------------------------------------------------------------------------
    svn:mime-type = text/javascript;charset=utf-8

Modified: incubator/couchdb/branches/futon-async/share/www/script/jquery.dialog.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/script/jquery.dialog.js?rev=647619&r1=647618&r2=647619&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/script/jquery.dialog.js [utf-8] (original)
+++ incubator/couchdb/branches/futon-async/share/www/script/jquery.dialog.js [utf-8] Sun Apr 13 12:59:39 2008
@@ -75,14 +75,15 @@
           $.each($("form :input", dialog).serializeArray(), function(i, field) {
             data[field.name] = field.value;
           });
-          var errors = options.submit(data);
-          if (errors == null || errors == {}) {
-            dismiss();
-          } else {
-            for (var name in errors) {
-              showError(name, errors[name]);
+          options.submit(data, function callback(errors) {
+            if (errors == null || errors == {}) {
+              dismiss();
+            } else {
+              for (var name in errors) {
+                showError(name, errors[name]);
+              }
             }
-          }
+          });
           return false;
         });
       });

Modified: incubator/couchdb/branches/futon-async/share/www/style/layout.css
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/futon-async/share/www/style/layout.css?rev=647619&r1=647618&r2=647619&view=diff
==============================================================================
--- incubator/couchdb/branches/futon-async/share/www/style/layout.css (original)
+++ incubator/couchdb/branches/futon-async/share/www/style/layout.css Sun Apr 13 12:59:39 2008
@@ -33,7 +33,10 @@
 h1 :link, h1 :visited { color: #bbb; cursor: pointer;
   text-shadow: #333 2px 2px 1px;
 }
-h1 strong { color: #fff; text-shadow: #000 2px 2px 4px; }
+h1 strong { color: #fff; padding-right: 25px; text-shadow: #000 2px 2px 4px; }
+body.loading h1 strong {
+  background: url(../image/spinner.gif) right center no-repeat;
+}
 
 hr { border: 1px solid #999; border-width: 1px 0 0; }
 dl dt { font-weight: bold; }
@@ -195,7 +198,7 @@
   width: expression(document.body.clientWidth + 'px');
   height: expression(document.body.clientHeight + 'px');
 }
-#dialog { background: #333  url(../image/spinner.gif) 50% 50% no-repeat;
+#dialog { background: #333  url(../image/progress.gif) 50% 50% no-repeat;
   color: #f4f4f4; overflow: hidden; opacity: .95; max-width: 33em;
   padding: 1em 1em 0; -moz-border-radius: 7px; -webkit-border-radius: 7px;
   -webkit-box-shadow: 4px 4px 6px #333;