Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
127 lines (99 sloc) 3.72 KB
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>riak-admin</title>
<script src="jquery-1.4.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="riak.js"></script>
<script type="text/javascript" src="riak-jquery.js"></script>
<link rel="stylesheet" href="rug.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
var db = new Riak();
var bucket = window.location.search.substring(1);
$(function() {
$('#bucket').html(bucket);
db.get(bucket)(function(response) {
$.each(response.keys, function(i, key) {
$('#keys')
.append("<li id=\"" + uniqueId(bucket, key) + "\"><a href='javascript:;' onclick='show(\"" + key + "\")'>" + key + "</a></li>");
});
});
});
function uniqueId(bucket, key) {
return bucket + "-" + key;
}
function cleanDetailPane() {
$('#document').html("");
}
function edit(key) {
var selector = '#' + key + '-object';
selector = selector.replace(/([\.@])/g, '\\$1');
console.log(selector);
var $target = $(selector);
console.log($target);
var $error = $('<div id="error" class="error"></div>');
var $textarea = $("<textarea style='width:90%; height: 300px' />");
$textarea[0].id = $target[0].id;
var $button = $("<button>Save</button>").click(function(e) {
var json = $(selector).val();
db.get(bucket, key)(function() {
try {
db.save(bucket, key, JSON.parse(json), {returnbody: true})(function(doc) {
show(key);
});
} catch (err) {
if (!$('#error').length) {
$error.text(err.message).prependTo($('#document'));
}
}
});
});
$textarea.append($target.html());
var $form = $('<div/>');
$form.append($textarea);
$form.append($button);
$target.replaceWith($form);
}
function del(key) {
db.remove(bucket, key)(function() {
$('#keys > #' + uniqueId(bucket, key)).remove();
});
}
function remove(key) {
if (confirm("Sure you want to delete document " + key + " from bucket " + bucket + "?")) {
del(key);
cleanDetailPane();
}
}
function deleteAll() {
if (confirm("Are you ABSOLUTELY sure you want to delete ALL documents from bucket " + bucket + "?")) {
db.get(bucket)(function(response) {
$.each(response.keys, function(i, key) {
del(key);
});
});
cleanDetailPane();
}
}
function show(key) {
db.get(bucket, key)(function(response) {
$('#document').html("<a href='javascript:;' onclick='edit()'>new</a> | <a href='javascript:;' onclick='remove(\"" + key + "\")'>delete</a> | " +
"<a href='javascript:;' onclick='edit(\"" + key + "\")'>edit</a>");
$('#document').append("<dt>Object<dt><dd><pre id='" + key + "-object'>" + JSON.stringify(response, null, 2) + "</pre></dd>");
});
}
</script>
</head>
<body>
<h3>riak-admin &rarr; <small>bucket <em id="bucket"></em></small></h3>
<div style="float:left; width: 40%">
<ul id="keys"></ul>
<img src="trash.png" /> <small><a href="javascript:;" onclick="deleteAll()">Delete all documents of this bucket</a></small>
</div>
<div style="float:left; width: 60%">
<dl id="document"></dl>
</div>
<div style="clear:both"></div>
<hr/>
</body>
</html>