From 5b84668e1d771b02d6f0379a97813b8e9bd24651 Mon Sep 17 00:00:00 2001 From: Daniel Erat Date: Fri, 1 Jul 2011 21:31:41 +0000 Subject: [PATCH] ui: Linkify paths on permanode page. Change-Id: I056896715b174bd3abd91799a86c73f3a8d83d3f --- server/go/camlistored/ui.go | 16 +++++++++++++++- server/go/camlistored/ui/permanode.js | 27 +++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/server/go/camlistored/ui.go b/server/go/camlistored/ui.go index 2e9f4e778..1756132ee 100644 --- a/server/go/camlistored/ui.go +++ b/server/go/camlistored/ui.go @@ -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{}{ diff --git a/server/go/camlistored/ui/permanode.js b/server/go/camlistored/ui/permanode.js index f8ce1f5f3..7cb58fac6 100644 --- a/server/go/camlistored/ui/permanode.js +++ b/server/go/camlistored/ui/permanode.js @@ -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";