mirror of https://github.com/perkeep/perkeep.git
UI: for publishing: let your create root path claims.
Change-Id: Icbe64995d3123190b1679583b8dff9b8427d4f10
This commit is contained in:
parent
bf28e7e6e5
commit
47000868f5
|
@ -213,8 +213,9 @@ func (ui *UIHandler) serveDiscovery(rw http.ResponseWriter, req *http.Request) {
|
|||
|
||||
pubRoots := map[string]interface{}{}
|
||||
for key, pubh := range ui.PublishRoots {
|
||||
pubRoots[key] = map[string]interface{}{
|
||||
pubRoots[pubh.RootName] = map[string]interface{}{
|
||||
"name": pubh.RootName,
|
||||
"prefix": []string{key},
|
||||
// TODO: include gpg key id
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,26 @@ function camliDescribeBlob(blobref, opts) {
|
|||
xhr.send();
|
||||
}
|
||||
|
||||
function makeURL(base, map) {
|
||||
for (var key in map) {
|
||||
if (base.indexOf("?") == -1) {
|
||||
base += "?";
|
||||
} else {
|
||||
base += "&";
|
||||
}
|
||||
base += key + "=" + encodeURIComponent(map[key]);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
function camliPermanodeOfSignerAttrValue(signer, attr, value, opts) {
|
||||
var xhr = camliJsonXhr("camliPermanodeOfSignerAttrValue", opts);
|
||||
var path = makeURL(Camli.config.searchRoot + "camli/search/signerattrvalue",
|
||||
{ signer: signer, attr: attr, value: value });
|
||||
xhr.open("GET", path, true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function camliGetPermanodeClaims(permanode, opts) {
|
||||
var xhr = camliJsonXhr("camliGetPermanodeClaims", opts);
|
||||
var path = Camli.config.searchRoot + "camli/search/claims?permanode=" +
|
||||
|
|
|
@ -35,14 +35,6 @@
|
|||
<input type="submit" id="btnAddTag" value="Add Tag(s)">
|
||||
</form>
|
||||
|
||||
<form id="formUrlPath">
|
||||
<p>
|
||||
<label for="inputUrlPath">URL:</label>
|
||||
http://<span id="urlHostName">(loading)</span>/<input id="inputUrlPath" size="50" disabled="disabled">
|
||||
<input type="submit" id="btnSetUrlPath" value="Save path" disabled="disabled">
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<form id="formAccess">
|
||||
<p>Access:
|
||||
<select id="selectAccess" disabled="disabled">
|
||||
|
@ -52,7 +44,7 @@
|
|||
<input type="submit" id="btnSaveAccess" value="Save" disabled="disabled">
|
||||
|
||||
... with URL: <select id="selectPublishRoot">
|
||||
<option value="">(unpublished)</option>
|
||||
<option value=""></option>
|
||||
</select>
|
||||
<input type="text" id="publishSuffix" size="40">
|
||||
<input type="submit" id="btnSavePublish" value="Set URL">
|
||||
|
|
|
@ -412,44 +412,85 @@ function onBlobDescribed(jres) {
|
|||
btnSaveAccess.disabled = false;
|
||||
}
|
||||
|
||||
function handleFormUrlPathSubmit(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
var inputUrlPath = document.getElementById("inputUrlPath");
|
||||
if (!inputUrlPath.value) {
|
||||
alert("Please specify a mount path like '/foo/bar/stuff'");
|
||||
return;
|
||||
function setupRootsDropdown() {
|
||||
var selRoots = document.getElementById("selectPublishRoot");
|
||||
if (!Camli.config.publishRoots) {
|
||||
console.log("no publish roots");
|
||||
return;
|
||||
}
|
||||
|
||||
// var btnSaveUrlPath = document.getElementById("btnSaveUrlPath");
|
||||
// btnSaveUrlPath.disabled = true;
|
||||
// btnSaveUrlPath.disabled = true;
|
||||
|
||||
// TODO(bslatkin): Finish this function. Need to call
|
||||
// camliNewSetAttributeClaim() here with the root node for the
|
||||
// server specified as the target of the claim. See
|
||||
// lib/go/camli/search/search.go:FindPermanode for the general
|
||||
// approach for finding the root permanode by name.
|
||||
|
||||
// camliNewSetAttributeClaim(
|
||||
// getPermanodeParam(),
|
||||
// "mount:" + inputUrlPath.value,
|
||||
// ,
|
||||
// {
|
||||
// success: oneDone,
|
||||
// fail: function(msg) {
|
||||
// alert(msg);
|
||||
// oneDone();
|
||||
// }
|
||||
// });
|
||||
for (var rootName in Camli.config.publishRoots) {
|
||||
var opt = document.createElement("option");
|
||||
opt.setAttribute("value", rootName);
|
||||
opt.appendChild(document.createTextNode(Camli.config.publishRoots[rootName].prefix[0]));
|
||||
selRoots.appendChild(opt);
|
||||
}
|
||||
document.getElementById("btnSavePublish").addEventListener("click", onBtnSavePublish);
|
||||
}
|
||||
|
||||
function setupUrlPathHandler() {
|
||||
var hostName = document.getElementById("urlHostName");
|
||||
hostName.innerHTML = window.location.host;
|
||||
var formUrlPath = document.getElementById("formUrlPath");
|
||||
formUrlPath.addEventListener("submit", handleFormUrlPathSubmit);
|
||||
function onBtnSavePublish(e) {
|
||||
var selRoots = document.getElementById("selectPublishRoot");
|
||||
var suffix = document.getElementById("publishSuffix");
|
||||
|
||||
var ourPermanode = getPermanodeParam();
|
||||
if (!ourPermanode) {
|
||||
return;
|
||||
}
|
||||
|
||||
var publishRoot = selRoots.value;
|
||||
if (!publishRoot) {
|
||||
alert("no publish root selected");
|
||||
return;
|
||||
}
|
||||
var pathSuffix = suffix.value;
|
||||
if (!pathSuffix) {
|
||||
alert("no path suffix specified");
|
||||
return;
|
||||
}
|
||||
|
||||
selRoots.disabled = true;
|
||||
suffix.disabled = true;
|
||||
|
||||
var enabled = function() {
|
||||
selRoots.disabled = false;
|
||||
suffix.disabled = false;
|
||||
};
|
||||
|
||||
// Step 1: resolve selRoots.value -> blobref of the root's permanode.
|
||||
// Step 2: set attribute on the root's permanode, or a sub-permanode
|
||||
// if multiple path components in suffix:
|
||||
// "camliPath:<suffix>" => permanode-of-ourselves
|
||||
|
||||
var sigcb = {};
|
||||
sigcb.success = function(sigconf) {
|
||||
var savcb = {};
|
||||
savcb.success = function(pnres) {
|
||||
if (!pnres.permanode) {
|
||||
alert("failed to publish root's permanode");
|
||||
enabled();
|
||||
return;
|
||||
}
|
||||
var attrcb = {};
|
||||
attrcb.success = function() {
|
||||
console.log("success.");
|
||||
enabled();
|
||||
};
|
||||
attrcb.fail = function() {
|
||||
alert("failed to set attribute");
|
||||
enabled();
|
||||
};
|
||||
camliNewSetAttributeClaim(pnres.permanode, "camliPath:" + pathSuffix, ourPermanode, attrcb);
|
||||
};
|
||||
savcb.fail = function() {
|
||||
alert("failed to find publish root's permanode");
|
||||
enabled();
|
||||
};
|
||||
camliPermanodeOfSignerAttrValue(sigconf.publicKeyBlobRef, "camliRoot", publishRoot, savcb);
|
||||
};
|
||||
sigcb.fail = function() {
|
||||
alert("sig disco failed");
|
||||
enabled();
|
||||
}
|
||||
camliSigDiscovery(sigcb);
|
||||
}
|
||||
|
||||
function permanodePageOnLoad(e) {
|
||||
|
@ -469,11 +510,11 @@ function permanodePageOnLoad(e) {
|
|||
var selectType = document.getElementById("type");
|
||||
selectType.addEventListener("change", onTypeChange);
|
||||
|
||||
setupRootsDropdown();
|
||||
|
||||
setupFilesHandlers();
|
||||
|
||||
buildPermanodeUi();
|
||||
|
||||
setupUrlPathHandler();
|
||||
}
|
||||
|
||||
window.addEventListener("load", permanodePageOnLoad);
|
||||
|
|
Loading…
Reference in New Issue