ui: Linkify paths on permanode page.

Change-Id: I056896715b174bd3abd91799a86c73f3a8d83d3f
This commit is contained in:
Daniel Erat 2011-07-01 21:31:41 +00:00
parent df7b13578c
commit 5b84668e1d
2 changed files with 36 additions and 7 deletions

View File

@ -38,6 +38,7 @@ import (
"camli/misc/resize"
"camli/misc/vfs" // TODO: ditch this once pkg http gets it
"camli/schema"
"camli/search"
uistatic "camlistore.org/server/uistatic"
)
@ -68,6 +69,7 @@ type UIHandler struct {
Storage blobserver.Storage // of BlobRoot
Cache blobserver.Storage // or nil
Search *search.Handler // or nil
}
func init() {
@ -134,6 +136,11 @@ func newUiFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler,
ui.Cache = bs
}
if ui.SearchRoot != "" {
h, _ := ld.GetHandler(ui.SearchRoot)
ui.Search = h.(*search.Handler)
}
return ui, nil
}
@ -213,11 +220,18 @@ func (ui *UIHandler) serveDiscovery(rw http.ResponseWriter, req *http.Request) {
pubRoots := map[string]interface{}{}
for key, pubh := range ui.PublishRoots {
pubRoots[pubh.RootName] = map[string]interface{}{
m := map[string]interface{}{
"name": pubh.RootName,
"prefix": []string{key},
// TODO: include gpg key id
}
if ui.Search != nil {
pn, err := ui.Search.Index().PermanodeOfSignerAttrValue(ui.Search.Owner(), "camliRoot", pubh.RootName)
if err == nil {
m["currentPermanode"] = pn.String()
}
}
pubRoots[pubh.RootName] = m
}
bytes, _ := json.Marshal(map[string]interface{}{

View File

@ -522,13 +522,28 @@ function buildPathsList() {
var span = document.createElement("span");
li.appendChild(span);
var a = document.createElement("a");
a.href = ".?p=" + path.baseRef;
a.innerText = path.baseRef;
span.appendChild(a);
var blobLink = document.createElement("a");
blobLink.href = ".?p=" + path.baseRef;
blobLink.innerText = path.baseRef;
span.appendChild(blobLink);
var text = document.createTextNode(" - " + path.suffix);
span.appendChild(text);
span.appendChild(document.createTextNode(" - "));
var pathLink = document.createElement("a");
pathLink.href = "";
pathLink.innerText = path.suffix;
for (var key in Camli.config.publishRoots) {
var root = Camli.config.publishRoots[key];
if (root.currentPermanode == path.baseRef) {
// Prefix should include a trailing slash.
pathLink.href = root.prefix[0] + path.suffix;
// TODO: Check if we're the latest permanode
// for this path and display some "old" notice
// if not.
break;
}
}
span.appendChild(pathLink);
var del = document.createElement("span");
del.className = "camli-del";