2011-03-09 16:22:29 -08:00

142 lines
4.4 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CouchDB Data Import/Export</title>
<link rel="stylesheet" href="style/reset.css" media="screen">
<link rel="stylesheet" href="style/demo.css" media="screen">
<link rel="stylesheet" href="style/css3buttons.css" media="screen">
<script type="text/javascript" src="script/jquery-1.5.min.js"></script>
<script type="text/javascript" src="script/jquery.mustache.js"></script>
<script type="text/javascript">
$(function() {
var baseURL = "_rewrite/",
vhost = false;
if ( document.location.pathname.indexOf( "_design" ) == -1 ) {
// in a vhost
vhost = true;
baseURL = "";
}
/** uses $.mustache to render a template out to a target DOM
* template == camelcase ID (minus the word Template) of the DOM object containg your mustache template
* target == ID of the DOM node you wish to render the template into
* data == data object to pass into the mustache template when rendering
*/
function render( template, target, data ) {
if ( !data ) var data = {};
$( "#" + target ).html( $.mustache( $( "#" + template + "Template" ).text(), data ) );
}
function formatDiskSize(bytes) {
return (parseFloat(bytes)/1024/1024).toString().substr(0,4) + "MB"
}
function gotDb( dbInfo ) {
$.extend(dbInfo, {
"host": window.location.host,
"disk_size": formatDiskSize(dbInfo.disk_size)
});
if( vhost ) dbInfo.db_name = 'db';
render( 'db', 'stats', dbInfo );
render( 'bulk', 'bulk', dbInfo );
}
$.getJSON( baseURL + 'db', gotDb );
$( '.csv' ).click( function( e ) {
function gotHeaders( headers ) {
window.location.href = baseURL + 'csv?headers=' + headers;
}
$.get( baseURL + 'headers', gotHeaders );
e.preventDefault();
})
})
</script>
</head>
<body>
<div class="container">
<header>
<h1 id="title">CouchDB Data Import/Export</h1>
</header>
<div id="main">
<section class="odd">
<div id="stats"></div>
<article class="example">
<p>
<h3>Actions</h3>
</p>
<p>
<a href="javascript:void(false)" class="button csv"><span class="downarrow icon"></span>Download DB as CSV</a>
</p>
</article>
<h3>Uploading</h3>
<p>You can bulk upload an array of JSON documents to a Couch via HTTP POST. Make sure that they are formatted one document per line:</p>
<p>
<pre><code> {
"docs": [
{"name": "barry", "type": "human"},
{"name": "carl", "type": "human"},
{"name": "ethel", "type": "robot"}
]
}</code></pre>
</p>
<p>POST to the this URL:</p>
<pre class="code" id="bulk"></pre>
</section>
</div>
<footer>
<a href='https://github.com/maxogden/removalist'>Fork this project on Github</a>. The <a href="http://github.com/michenriksen/css3buttons">pretty CSS3 Buttons</a> were created by <a href="http://michaelhenriksen.dk" title="Website of Michael Henriksen">Michael Henriksen</a>
</footer>
</div>
<script type='text/mustache' id="dbTemplate">
<div id="database" class="single_database">
<div class="group" id="current-head-database">
<table width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr class="database_oneline">
<td class="date">
<nobr>DB:</nobr>
</td>
<td class="author">
<a href="#">{{db_name}}</a>
</td>
<td class="message">
<code><a href="http://{{host}}/{{db_name}}">http://{{host}}/{{db_name}}</a> </code>
</td>
<td class="database">
size&nbsp;<a href="#" hotkey="c">{{disk_size}}</a>
</td>
<td class="tree">
docs&nbsp;<a href="http://{{host}}/{{db_name}}/_all_docs?include_docs=true" hotkey="t">{{doc_count}}</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</script>
<script type='text/mustache' id="bulkTemplate"> http://{{host}}/{{db_name}}/_bulk_docs</script>
</body>
</html>