mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-04 18:19:54 +00:00
History: Isolate /history/
This commit is contained in:
parent
fe7c1c482f
commit
2b8ffc69bd
@ -10,6 +10,7 @@ import (
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||
"github.com/gorilla/mux"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -21,9 +22,11 @@ func InitHandlers(rtr *mux.Router) {
|
||||
rtr.HandleFunc("/recent-changes/", func(w http.ResponseWriter, rq *http.Request) {
|
||||
http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther)
|
||||
})
|
||||
rtr.PathPrefix("/history/").HandlerFunc(handlerHistory)
|
||||
|
||||
chainPrimitiveDiff = viewutil.CopyEnRuWith(fs, "view_primitive_diff.html", ruTranslation)
|
||||
chainRecentChanges = viewutil.CopyEnRuWith(fs, "view_recent_changes.html", ruTranslation)
|
||||
chainHistory = viewutil.CopyEnRuWith(fs, "view_history.html", ruTranslation)
|
||||
}
|
||||
|
||||
func handlerPrimitiveDiff(w http.ResponseWriter, rq *http.Request) {
|
||||
@ -65,6 +68,21 @@ func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) {
|
||||
recentChanges(viewutil.MetaFrom(w, rq), editCount, history.RecentChanges(editCount))
|
||||
}
|
||||
|
||||
// handlerHistory lists all revisions of a hypha.
|
||||
func handlerHistory(w http.ResponseWriter, rq *http.Request) {
|
||||
hyphaName := util.HyphaNameFromRq(rq, "history")
|
||||
var list string
|
||||
|
||||
// History can be found for files that do not exist anymore.
|
||||
revs, err := history.Revisions(hyphaName)
|
||||
if err == nil {
|
||||
list = history.WithRevisions(hyphaName, revs)
|
||||
}
|
||||
log.Println("Found", len(revs), "revisions for", hyphaName)
|
||||
|
||||
historyView(viewutil.MetaFrom(w, rq), hyphaName, list)
|
||||
}
|
||||
|
||||
var (
|
||||
//go:embed *.html
|
||||
fs embed.FS
|
||||
@ -79,8 +97,7 @@ var (
|
||||
{{define "n recent changes"}}{{.}} недавн{{if eq . 1}}ее изменение{{else if le . 4}}недавних изменения{{else}}недавних изменений{{end}}{{end}}
|
||||
{{define "recent empty"}}Правки не найдены.{{end}}
|
||||
`
|
||||
chainPrimitiveDiff viewutil.Chain
|
||||
chainRecentChanges viewutil.Chain
|
||||
chainPrimitiveDiff, chainRecentChanges, chainHistory viewutil.Chain
|
||||
)
|
||||
|
||||
type recentChangesData struct {
|
||||
@ -116,3 +133,19 @@ func primitiveDiff(meta viewutil.Meta, h hyphae.ExistingHypha, hash, text string
|
||||
Text: text,
|
||||
})
|
||||
}
|
||||
|
||||
type historyData struct {
|
||||
*viewutil.BaseData
|
||||
HyphaName string
|
||||
Contents string
|
||||
}
|
||||
|
||||
func historyView(meta viewutil.Meta, hyphaName, contents string) {
|
||||
viewutil.ExecutePage(meta, chainHistory, historyData{
|
||||
BaseData: &viewutil.BaseData{
|
||||
Addr: "/history/" + util.CanonicalName(hyphaName),
|
||||
},
|
||||
HyphaName: hyphaName,
|
||||
Contents: contents,
|
||||
})
|
||||
}
|
||||
|
9
history/histview/view_history.html
Normal file
9
history/histview/view_history.html
Normal file
@ -0,0 +1,9 @@
|
||||
{{define "history of title"}}History of {{.}}{{end}}
|
||||
{{define "body"}}
|
||||
<main class="main-width">
|
||||
<article class="history">
|
||||
<h1>{{block "history of heading" .HyphaName}}History of <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}}</h1>
|
||||
{{.Contents}}
|
||||
</article>
|
||||
</main>
|
||||
{{end}}
|
@ -1,13 +0,0 @@
|
||||
{% import "fmt" %}
|
||||
{% import "net/http" %}
|
||||
|
||||
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
||||
|
||||
{% func History(rq *http.Request, hyphaName, list string, lc *l18n.Localizer) %}
|
||||
<main class="main-width">
|
||||
<article class="history">
|
||||
<h1>{%s= fmt.Sprintf(lc.Get("ui.history_title"), beautifulLink(hyphaName)) %}</h1>
|
||||
{%s= list %}
|
||||
</article>
|
||||
</main>
|
||||
{% endfunc %}
|
@ -1,75 +0,0 @@
|
||||
// Code generated by qtc from "history.qtpl". DO NOT EDIT.
|
||||
// See https://github.com/valyala/quicktemplate for details.
|
||||
|
||||
//line views/history.qtpl:1
|
||||
package views
|
||||
|
||||
//line views/history.qtpl:1
|
||||
import "fmt"
|
||||
|
||||
//line views/history.qtpl:2
|
||||
import "net/http"
|
||||
|
||||
//line views/history.qtpl:4
|
||||
import "github.com/bouncepaw/mycorrhiza/l18n"
|
||||
|
||||
//line views/history.qtpl:6
|
||||
import (
|
||||
qtio422016 "io"
|
||||
|
||||
qt422016 "github.com/valyala/quicktemplate"
|
||||
)
|
||||
|
||||
//line views/history.qtpl:6
|
||||
var (
|
||||
_ = qtio422016.Copy
|
||||
_ = qt422016.AcquireByteBuffer
|
||||
)
|
||||
|
||||
//line views/history.qtpl:6
|
||||
func StreamHistory(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, list string, lc *l18n.Localizer) {
|
||||
//line views/history.qtpl:6
|
||||
qw422016.N().S(`
|
||||
<main class="main-width">
|
||||
<article class="history">
|
||||
<h1>`)
|
||||
//line views/history.qtpl:9
|
||||
qw422016.N().S(fmt.Sprintf(lc.Get("ui.history_title"), beautifulLink(hyphaName)))
|
||||
//line views/history.qtpl:9
|
||||
qw422016.N().S(`</h1>
|
||||
`)
|
||||
//line views/history.qtpl:10
|
||||
qw422016.N().S(list)
|
||||
//line views/history.qtpl:10
|
||||
qw422016.N().S(`
|
||||
</article>
|
||||
</main>
|
||||
`)
|
||||
//line views/history.qtpl:13
|
||||
}
|
||||
|
||||
//line views/history.qtpl:13
|
||||
func WriteHistory(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, list string, lc *l18n.Localizer) {
|
||||
//line views/history.qtpl:13
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line views/history.qtpl:13
|
||||
StreamHistory(qw422016, rq, hyphaName, list, lc)
|
||||
//line views/history.qtpl:13
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line views/history.qtpl:13
|
||||
}
|
||||
|
||||
//line views/history.qtpl:13
|
||||
func History(rq *http.Request, hyphaName, list string, lc *l18n.Localizer) string {
|
||||
//line views/history.qtpl:13
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line views/history.qtpl:13
|
||||
WriteHistory(qb422016, rq, hyphaName, list, lc)
|
||||
//line views/history.qtpl:13
|
||||
qs422016 := string(qb422016.B)
|
||||
//line views/history.qtpl:13
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line views/history.qtpl:13
|
||||
return qs422016
|
||||
//line views/history.qtpl:13
|
||||
}
|
@ -2,45 +2,19 @@ package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||
"github.com/gorilla/mux"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/history"
|
||||
"github.com/bouncepaw/mycorrhiza/l18n"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
"github.com/bouncepaw/mycorrhiza/views"
|
||||
)
|
||||
|
||||
func initHistory(r *mux.Router) {
|
||||
r.PathPrefix("/history/").HandlerFunc(handlerHistory)
|
||||
|
||||
r.HandleFunc("/recent-changes-rss", handlerRecentChangesRSS)
|
||||
r.HandleFunc("/recent-changes-atom", handlerRecentChangesAtom)
|
||||
r.HandleFunc("/recent-changes-json", handlerRecentChangesJSON)
|
||||
}
|
||||
|
||||
// handlerHistory lists all revisions of a hypha.
|
||||
func handlerHistory(w http.ResponseWriter, rq *http.Request) {
|
||||
hyphaName := util.HyphaNameFromRq(rq, "history")
|
||||
var list string
|
||||
|
||||
// History can be found for files that do not exist anymore.
|
||||
revs, err := history.Revisions(hyphaName)
|
||||
if err == nil {
|
||||
list = history.WithRevisions(hyphaName, revs)
|
||||
}
|
||||
log.Println("Found", len(revs), "revisions for", hyphaName)
|
||||
|
||||
var lc = l18n.FromRequest(rq)
|
||||
util.HTTP200Page(w, views.Base(
|
||||
viewutil.MetaFrom(w, rq),
|
||||
fmt.Sprintf(lc.Get("ui.history_title"), util.BeautifulName(hyphaName)),
|
||||
views.History(rq, hyphaName, list, lc),
|
||||
))
|
||||
}
|
||||
|
||||
// genericHandlerOfFeeds is a helper function for the web feed handlers.
|
||||
func genericHandlerOfFeeds(w http.ResponseWriter, rq *http.Request, f func(history.FeedOptions) (string, error), name string, contentType string) {
|
||||
opts, err := history.ParseFeedOptions(rq.URL.Query())
|
||||
|
Loading…
Reference in New Issue
Block a user