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/09/16 22:24:48 UTC

svn commit: r696041 - in /incubator/couchdb/trunk: share/www/config.html share/www/index.html share/www/script/jquery.couch.js share/www/style/layout.css src/couchdb/couch_config.erl src/couchdb/couch_httpd.erl

Author: cmlenz
Date: Tue Sep 16 13:24:48 2008
New Revision: 696041

URL: http://svn.apache.org/viewvc?rev=696041&view=rev
Log:
Add HTTP API for getting the complete config, and add a page to Futon that displays the configuration.

Added:
    incubator/couchdb/trunk/share/www/config.html   (with props)
Modified:
    incubator/couchdb/trunk/share/www/index.html
    incubator/couchdb/trunk/share/www/script/jquery.couch.js
    incubator/couchdb/trunk/share/www/style/layout.css
    incubator/couchdb/trunk/src/couchdb/couch_config.erl
    incubator/couchdb/trunk/src/couchdb/couch_httpd.erl

Added: incubator/couchdb/trunk/share/www/config.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/config.html?rev=696041&view=auto
==============================================================================
--- incubator/couchdb/trunk/share/www/config.html (added)
+++ incubator/couchdb/trunk/share/www/config.html Tue Sep 16 13:24:48 2008
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<!--
+
+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.
+
+-->
+<html lang="en">
+  <head>
+    <title>Configuration</title>
+    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+    <link rel="stylesheet" href="style/layout.css?0.8.0" type="text/css">
+    <script src="script/json2.js"></script>
+    <script src="script/jquery.js?1.2.6"></script>
+    <script src="script/jquery.couch.js?0.8.0"></script>
+    <script src="script/pprint.js?0.8.0"></script>
+    <script>
+      $(document).ready(function() {
+        if (window !== parent) parent.updateNavigation();
+
+        $(document.body).addClass("loading");
+        $.couch.config({
+          success: function(resp) {
+            var sections = [];
+            for (var sectionName in resp) {
+              sections.push(sectionName);
+            }
+            sections.sort();
+            $.each(sections, function(idx, sectionName) {
+              var row = $("<tr><th></th></tr>")
+                .find("th").text(sectionName).end()
+                .appendTo("#config tbody.content");
+              var section = resp[sectionName]
+              var options = [];
+              for (var option in section) {
+                options.push(option);
+              }
+              options = options.sort();
+              var prev = null;
+              $.each(options, function(idx, optionName) {
+                var cur = idx == 0 ? row : $("<tr></tr>");
+                $("<td class='name'></td>").text(optionName).appendTo(cur);
+                $("<td class='value'></td>").text(section[optionName]).appendTo(cur);
+                if (cur !== row) cur.insertAfter(prev);
+                prev = cur;
+              });
+              row.find("th").attr("rowspan", options.length);
+            });
+            $("#config tbody tr").removeClass("odd").filter(":odd").addClass("odd");
+            $(document.body).removeClass("loading");
+          }
+        });
+      });
+    </script>
+  </head>
+  <body>
+    <h1>
+      <a href="browse/index.html">Overview</a>
+      <strong>Configuration</strong>
+    </h1>
+    <div id="wrap">
+
+      <table id="config" class="listing">
+        <caption>Configuration</caption>
+        <thead><tr>
+          <th>Section</th>
+          <th>Option</th>
+          <th>Value</th>
+        </tr></thead>
+        <tbody class="content"></tbody>
+      </table>
+
+    </div>
+    <div id="dump"></div>
+  </body>
+</html>

Propchange: incubator/couchdb/trunk/share/www/config.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/couchdb/trunk/share/www/index.html
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/index.html?rev=696041&r1=696040&r2=696041&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/index.html [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/index.html [utf-8] Tue Sep 16 13:24:48 2008
@@ -88,6 +88,7 @@
       <li><span>Tools</span><ul>
         <li><a href="browse/index.html" target="content">Overview</a></li>
         <li><a href="replicator.html" target="content">Replicator</a></li>
+        <li><a href="config.html" target="content">Configuration</a></li>
         <li><a href="couch_tests.html" target="content">Test Suite</a></li>
       </ul></li>
       <li><span>Databases</span>

Modified: incubator/couchdb/trunk/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/jquery.couch.js?rev=696041&r1=696040&r2=696041&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/jquery.couch.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/jquery.couch.js [utf-8] Tue Sep 16 13:24:48 2008
@@ -32,6 +32,23 @@
       });
     },
 
+    config: function(options, section, option, value) {
+      $.ajax({
+        type: "GET", url: "/_config/",
+        complete: function(req) {
+          var resp = $.httpData(req, "json");
+          if (req.status == 200) {
+            if (options.success) options.success(resp);
+          } else if (options.error) {
+            options.error(req.status, resp.error, resp.reason);
+          } else {
+            alert("An error occurred retrieving the server configuration: " +
+              resp.reason);
+          }
+        }
+      });
+    },
+
     db: function(name) {
       return {
         name: name,

Modified: incubator/couchdb/trunk/share/www/style/layout.css
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/style/layout.css?rev=696041&r1=696040&r2=696041&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/style/layout.css (original)
+++ incubator/couchdb/trunk/share/www/style/layout.css Tue Sep 16 13:24:48 2008
@@ -459,6 +459,18 @@
   background-image: url(../image/test_failure.gif); color: #c00;
 }
 
+/* Configuration */
+
+table#config tbody th { background: #e6e6e6; border-right: none;
+  border-top: 1px solid #d9d9d9;
+}
+table#config tbody td.name { border-left: 1px solid #d9d9d9; color: #333;
+  font-weight: bold;
+}
+table#config tbody td.value {
+  font-family: "DejaVu Sans Mono",Monaco,monospace;
+}
+
 /* Replication */
 
 form#replicator { background: #f4f4f4; border: 1px solid;

Modified: incubator/couchdb/trunk/src/couchdb/couch_config.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_config.erl?rev=696041&r1=696040&r2=696041&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_config.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_config.erl Tue Sep 16 13:24:48 2008
@@ -158,4 +158,4 @@
 terminate(_Reason, _State) -> ok.
 
 %% @doc Unused
-code_change(_OldVersion, State, _Extra) -> {ok, State}.
\ No newline at end of file
+code_change(_OldVersion, State, _Extra) -> {ok, State}.

Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=696041&r1=696040&r2=696041&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Tue Sep 16 13:24:48 2008
@@ -207,10 +207,14 @@
             couch_db:close(Db),
             send_json(Req, 201, {[{ok, true}]});
         {error, database_already_exists} ->
-            Msg = io_lib:format("Database ~p already exists.", [DbName]),
+            Msg = io_lib:format("Database ~p already exists.", [
+                binary_to_list(DbName)
+            ]),
             throw({database_already_exists, Msg});
         Error ->
-            Msg = io_lib:format("Error creating database ~p: ~p", [DbName, Error]),
+            Msg = io_lib:format("Error creating database ~p: ~p", [
+                binary_to_list(DbName), Error
+            ]),
             throw({unknown_error, Msg})
     end;
 
@@ -805,6 +809,22 @@
     Parts = string:tokens(Config, "/"),
     handle_config_request(_Req, Method, {Parts});
 
+% GET /_config
+handle_config_request(Req, 'GET', {[]}) ->
+    send_json(Req, 200, {dict:to_list(dict:map(
+        fun(_, Value) -> {Value} end,
+        lists:foldl(
+            fun({{Section, Option}, Value}, Acc) ->
+                SecBin = list_to_binary(Section),
+                OptBin = list_to_binary(Option),
+                ValBin = list_to_binary(Value),
+                dict:append(SecBin, {OptBin, ValBin}, Acc)
+            end,
+            dict:new(),
+            couch_config:all()
+        )
+    ))});
+
 % GET /_config/Section
 handle_config_request(Req, 'GET', {[Section]}) ->
     KVs = [