157 lines
5.3 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() {
function inVhost() {
var vhost = false;
if ( document.location.pathname.indexOf( "_design" ) === -1 ) {
vhost = true;
}
return vhost;
}
var config = {
db: "api" // relative vhost links defined in rewrites.json
, design: "ddoc"
, vhost: true
, baseURL: "/"
, host: window.location.href.split( "/" )[ 2 ]
}
if ( !inVhost() ) {
config.vhost = false
config.db = document.location.href.split( '/' )[ 3 ];
config.design = unescape( document.location.href ).split( '/' )[ 5 ];
config.baseURL = "/" + config.db + "/_design/" + config.design + "/_rewrite/";
}
var csvUrl;
/** 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( config.vhost ) dbInfo.db_name = "api";
render( 'db', 'stats', dbInfo );
render( 'bulk', 'bulk', dbInfo );
render( 'generating', 'download' );
function gotHeaders( headers ) {
csvUrl = config.baseURL + 'csv?headers=' + headers;
render( 'actions', 'actions', $.extend(dbInfo, {url: csvUrl}) );
}
$.get( config.baseURL + 'headers', gotHeaders );
}
$.getJSON( config.baseURL + "api", gotDb );
$( '.csv' ).live('click', ( function( e ) {
window.location.href = csvUrl;
e.preventDefault();
}))
})
</script>
</head>
<body>
<div class="container">
<header>
<h1 id="title">CouchDB Data Import/Export</h1>
</header>
<div id="main">
<section class="odd">
<p>
<div id="stats"></div>
</p>
<h3>Downloading</h3>
<div id="actions"><p><div class="loading">Preprocessing CSV - Please wait...</div></p></div>
<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 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 action">
<td class="date">
<nobr>db</nobr>
</td>
<td class="message">
<code><a href="http://{{host}}/{{db_name}}">http://{{host}}/<strong>{{db_name}}</strong></a> </code>
</td>
<td class="database">
size&nbsp;{{disk_size}}
</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="actionsTemplate">
<p><a href="javascript:void(false)" class="primary button csv"><span class="downarrow icon"></span>Download CSV</a></p>
<p>Or use this URL to get a CSV:</p>
<p><pre class="code" id="download">http://{{host}}{{url}}</pre></p>
</script>
<script type='text/mustache' id="bulkTemplate">http://{{host}}/{{db_name}}/_bulk_docs</script>
<script type='text/mustache' id="generatingTemplate"><div class="loading">Precomputing CSV...</div></script>
</body>
</html>