Merge "create permanodes from the filetree browser + ui details"

This commit is contained in:
Brad Fitzpatrick 2011-07-24 19:45:17 +00:00 committed by Gerrit Code Review
commit 4fa27ed9cd
5 changed files with 85 additions and 17 deletions

View File

@ -14,6 +14,7 @@
<span id="editspan" class="camli-nav" style="display: none;"><a href="#" id="editlink">edit</a></span>
<span id="blobdownload" class="camli-nav"></span>
<span id="blobdescribe" class="camli-nav"></span>
<span id="blobbrowse" class="camli-nav"></span>
<pre id="blobdata"></pre>

View File

@ -41,6 +41,12 @@ function blobInfoUpdate(bmap) {
{
success: function(data) {
document.getElementById("blobdata").innerHTML = linkifyBlobRefs(data);
var bb = document.getElementById('blobbrowse');
if (binfo.camliType != "directory") {
bb.style.visibility = 'hidden';
} else {
bb.innerHTML = "<a href='?d=" + blobref + "'>browse</a>";
}
if (binfo.camliType == "file") {
try {
finfo = JSON.parse(data);

View File

@ -31,6 +31,13 @@ body {
margin-left: .4em;
font-size: 80%;
}
.camli-newp {
text-decoration: underline;
cursor: pointer;
color: darkgreen;
margin-left: .4em;
font-size: 80%;
}
.camli-tag-c {
margin-right: .5em;
}

View File

@ -12,12 +12,7 @@
</head>
<body class="camli-ui-permanode">
<div class="camli-nav"><a href="./">Home</a></div>
<h1>FileTree</h1>
<p>
Blob:
<span id="permanodeBlob" class="camli-nav"></span>
</p>
<h1>FileTree for <span id="curDir" class="camli-nav"></span> </h1>
<div id="children"></div>

View File

@ -24,6 +24,27 @@ function getPermanodeParam() {
return (blobRef && isPlausibleBlobRef(blobRef)) ? blobRef : null;
}
function newPermWithContent(content) {
return function(e) {
var cnpcb = {};
cnpcb.success = function(permanode) {
var naaccb = {};
naaccb.success = function() {
alert("permanode created");
}
naaccb.fail = function(msg) {
//TODO(mpl): remove newly created permanode then?
alert("set permanode content failed: " + msg);
}
camliNewAddAttributeClaim(permanode, "camliContent", content, naaccb);
}
cnpcb.fail = function(msg) {
alert("create permanode failed: " + msg);
}
camliCreateNewPermanode(cnpcb);
}
}
function getFileTree(blobref, opts) {
var xhr = camliJsonXhr("getFileTree", opts);
var path = "./tree/" + blobref
@ -33,7 +54,8 @@ function getFileTree(blobref, opts) {
function insertAfter( referenceNode, newNode )
{
referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
// nextSibling X2 because of the "P" span
referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling.nextSibling );
}
function unFold(blobref, depth) {
@ -51,7 +73,8 @@ function unFold(blobref, depth) {
function fold(nodeid, depth) {
var node = document.getElementById(nodeid);
node.parentNode.removeChild(node.nextSibling);
// nextSibling X2 because of the "P" span
node.parentNode.removeChild(node.nextSibling.nextSibling);
node.onclick = Function("unFold('" + nodeid + "' , " + depth + "); return false;");
}
@ -63,43 +86,79 @@ function onChildrenFound(div, depth, jres) {
var pdiv = document.createElement("div");
var alink = document.createElement("a");
alink.style.paddingLeft=indent + "px"
alink.id = children[i].blobRef;
switch (children[i].type) {
case 'directory':
alink.innerText = "+ " + children[i].name;
alink.id = children[i].blobRef;
alink.href = "./?d=" + alink.id;
alink.onclick = Function("unFold('" + alink.id + "', " + depth + "); return false;");
break;
case 'file':
alink.innerText = " " + children[i].name;
alink.href = "./?b=" + children[i].blobRef;
alink.href = "./?b=" + alink.id;
break;
default:
alert("not a file or dir");
break;
}
var newPerm = document.createElement("span");
newPerm.className = "camli-newp";
newPerm.innerText = "P";
newPerm.addEventListener("click", newPermWithContent(alink.id));
pdiv.appendChild(alink);
pdiv.appendChild(newPerm);
div.appendChild(pdiv);
}
}
function buildTree() {
var permanode = getPermanodeParam();
var blobref = getPermanodeParam();
var div = document.getElementById("children");
var gftcb = {};
gftcb.success = function(jres) { onChildrenFound(div, 0, jres); }
gftcb.fail = function() { alert("fail"); }
getFileTree(permanode, gftcb)
getFileTree(blobref, gftcb)
}
function treePageOnLoad(e) {
var permanode = getPermanodeParam();
if (permanode) {
document.getElementById('permanodeBlob').innerHTML = "<a href='./?b=" + permanode + "'>" + permanode + "</a>";
var blobref = getPermanodeParam();
if (blobref) {
var dbcb = {};
dbcb.success = function(bmap) {
var binfo = bmap[blobref];
if (!binfo) {
alert("Error describing blob " + blobref);
return;
}
if (binfo.camliType != "directory") {
alert("Does not contain a directory");
return;
}
var gbccb = {};
gbccb.success = function(data) {
try {
finfo = JSON.parse(data);
var fileName = finfo.fileName;
var curDir = document.getElementById('curDir');
curDir.innerHTML = "<a href='./?b=" + blobref + "'>" + fileName + "</a>";
CamliFileTree.indentStep = 20;
buildTree();
} catch(x) {
alert(x);
return;
}
}
gbccb.fail = function() {
alert("failed to get blobcontents");
}
camliGetBlobContents(blobref, gbccb);
}
dbcb.fail = function(msg) {
alert("Error describing blob " + blobref + ": " + msg);
}
camliDescribeBlob(blobref, dbcb);
}
CamliFileTree.indentStep = 20
buildTree();
}
window.addEventListener("load", treePageOnLoad);