1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-05 17:40:26 +00:00

Refactor history views

This commit is contained in:
bouncepaw 2021-02-20 21:50:25 +05:00
parent 9f1eadcec4
commit 4798d94a94
10 changed files with 344 additions and 263 deletions

View File

@ -10,7 +10,6 @@ import (
"strings"
"time"
"github.com/bouncepaw/mycorrhiza/user"
"github.com/bouncepaw/mycorrhiza/util"
)
@ -77,8 +76,8 @@ func (rev Revision) TimeString() string {
return rev.Time.Format(time.RFC822)
}
// HyphaeLinks returns a comma-separated list of hyphae that were affected by this revision as HTML string.
func (rev Revision) HyphaeLinks() (html string) {
// HyphaeLinksHTML returns a comma-separated list of hyphae that were affected by this revision as HTML string.
func (rev Revision) HyphaeLinksHTML() (html string) {
hyphae := rev.hyphaeAffected()
for i, hyphaName := range hyphae {
if i > 0 {
@ -92,7 +91,7 @@ func (rev Revision) HyphaeLinks() (html string) {
func (rev *Revision) descriptionForFeed() (html string) {
return fmt.Sprintf(
`<p>%s</p>
<p><b>Hyphae affected:</b> %s</p>`, rev.Message, rev.HyphaeLinks())
<p><b>Hyphae affected:</b> %s</p>`, rev.Message, rev.HyphaeLinksHTML())
}
// Try and guess what link is the most important by looking at the message.
@ -111,23 +110,6 @@ func (rev *Revision) bestLink() string {
}
}
func (rev Revision) RecentChangesEntry() (html string) {
if user.AuthUsed && rev.Username != "anon" {
return fmt.Sprintf(`
<li class="rc-entry__time"><time>%[1]s</time></li>
<li class="rc-entry__hash">%[2]s</li>
<li class="rc-entry__links">%[5]s</li>
<li class="rc-entry__msg">%[6]s <span class="rc-entry__author">by <a href="/page/%[3]s/%[4]s" rel="author">%[4]s</a></span></li>
`, rev.TimeString(), rev.Hash, util.UserHypha, rev.Username, rev.HyphaeLinks(), rev.Message)
}
return fmt.Sprintf(`
<li class="rc-entry__time"><time>%[1]s</time></li>
<li class="rc-entry__hash">%[2]s</li>
<li class="rc-entry__links">%[3]s</li>
<li class="rc-entry__msg">%[4]s</li>
`, rev.TimeString(), rev.Hash, rev.HyphaeLinks(), rev.Message)
}
// Path to git executable. Set at init()
var gitpath string

View File

@ -9,7 +9,6 @@ import (
"strings"
"time"
"github.com/bouncepaw/mycorrhiza/templates"
"github.com/bouncepaw/mycorrhiza/util"
"github.com/gorilla/feeds"
)
@ -61,7 +60,7 @@ func RecentChangesJSON() (string, error) {
return recentChangesFeed().ToJSON()
}
func RecentChanges(n int) string {
func RecentChanges(n int) []Revision {
var (
out, err = gitsh(
"log", "--oneline", "--no-merges",
@ -75,11 +74,7 @@ func RecentChanges(n int) string {
revs = append(revs, parseRevisionLine(line))
}
}
entries := make([]string, len(revs))
for i, rev := range revs {
entries[i] = rev.RecentChangesEntry()
}
return templates.RecentChangesHTML(entries, n)
return revs
}
// FileChanged tells you if the file has been changed.

View File

@ -46,7 +46,7 @@ func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) {
n, err = strconv.Atoi(noPrefix)
)
if err == nil && n < 101 {
util.HTTP200Page(w, base(strconv.Itoa(n)+" recent changes", history.RecentChanges(n), user.FromRequest(rq)))
util.HTTP200Page(w, base(strconv.Itoa(n)+" recent changes", views.RecentChangesHTML(n), user.FromRequest(rq)))
} else {
http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther)
}

View File

@ -151,10 +151,10 @@ figcaption { padding-bottom: .5rem; }
#new-name {width:100%;}
.rc-entry { display: grid; list-style-type: none; padding: .25rem; grid-template-columns: 1fr 1fr; }
.rc-entry { display: grid; list-style-type: none; padding: .25rem; grid-template-columns: 1fr 1fr; border-radius: .25rem; }
.rc-entry__time { font-style: italic; }
.rc-entry__hash { font-style: italic; text-align: right; }
.rc-entry__links { grid-column: 1 / span 2; }
.rc-entry__links, .rc-entry__msg { grid-column: 1 / span 2; }
.rc-entry__author { font-style: italic; }
.prevnext__el { display: block-inline; min-width: 40%; padding: .5rem; margin-bottom: .25rem; text-decoration: none; border-radius: .25rem; }

View File

@ -126,10 +126,10 @@ figcaption { padding-bottom: .5rem; }
#new-name {width:100%;}
.rc-entry { display: grid; list-style-type: none; padding: .25rem; grid-template-columns: 1fr 1fr; }
.rc-entry { display: grid; list-style-type: none; padding: .25rem; grid-template-columns: 1fr 1fr; border-radius: .25rem; }
.rc-entry__time { font-style: italic; }
.rc-entry__hash { font-style: italic; text-align: right; }
.rc-entry__links { grid-column: 1 / span 2; }
.rc-entry__links, .rc-entry__msg { grid-column: 1 / span 2; }
.rc-entry__author { font-style: italic; }
.prevnext__el { display: block-inline; min-width: 40%; padding: .5rem; margin-bottom: .25rem; text-decoration: none; border-radius: .25rem; }

View File

@ -1,161 +0,0 @@
// Code generated by qtc from "recent_changes.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line templates/recent_changes.qtpl:1
package templates
//line templates/recent_changes.qtpl:1
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line templates/recent_changes.qtpl:1
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line templates/recent_changes.qtpl:1
func StreamRecentChangesHTML(qw422016 *qt422016.Writer, changes []string, n int) {
//line templates/recent_changes.qtpl:1
qw422016.N().S(`
<div class="layout">
<main class="main-width recent-changes">
<h1>Recent Changes</h1>
<p><a href="/"> Back</a></p>
<nav class="recent-changes__count">
See
`)
//line templates/recent_changes.qtpl:9
for _, m := range []int{20, 0, 50, 0, 100} {
//line templates/recent_changes.qtpl:9
qw422016.N().S(`
`)
//line templates/recent_changes.qtpl:10
switch m {
//line templates/recent_changes.qtpl:11
case 0:
//line templates/recent_changes.qtpl:11
qw422016.N().S(`
<span aria-hidden="true">|</span>
`)
//line templates/recent_changes.qtpl:13
case n:
//line templates/recent_changes.qtpl:13
qw422016.N().S(`
<b>`)
//line templates/recent_changes.qtpl:14
qw422016.N().D(n)
//line templates/recent_changes.qtpl:14
qw422016.N().S(`</b>
`)
//line templates/recent_changes.qtpl:15
default:
//line templates/recent_changes.qtpl:15
qw422016.N().S(`
<a href="/recent-changes/`)
//line templates/recent_changes.qtpl:16
qw422016.N().D(m)
//line templates/recent_changes.qtpl:16
qw422016.N().S(`">`)
//line templates/recent_changes.qtpl:16
qw422016.N().D(m)
//line templates/recent_changes.qtpl:16
qw422016.N().S(`</a>
`)
//line templates/recent_changes.qtpl:17
}
//line templates/recent_changes.qtpl:17
qw422016.N().S(`
`)
//line templates/recent_changes.qtpl:18
}
//line templates/recent_changes.qtpl:18
qw422016.N().S(`
recent changes
</nav>
<p><img class="icon" width="20" height="20" src="https://upload.wikimedia.org/wikipedia/commons/4/46/Generic_Feed-icon.svg">Subscribe via <a href="/recent-changes-rss">RSS</a>, <a href="/recent-changes-atom">Atom</a> or <a href="/recent-changes-json">JSON feed</a>.</p>
`)
//line templates/recent_changes.qtpl:29
qw422016.N().S(`
<section class="recent-changes__list" role="feed">
`)
//line templates/recent_changes.qtpl:32
if len(changes) == 0 {
//line templates/recent_changes.qtpl:32
qw422016.N().S(`
<p>Could not find any recent changes.</p>
`)
//line templates/recent_changes.qtpl:34
} else {
//line templates/recent_changes.qtpl:34
qw422016.N().S(`
`)
//line templates/recent_changes.qtpl:35
for i, entry := range changes {
//line templates/recent_changes.qtpl:35
qw422016.N().S(`
<ul class="recent-changes__entry rc-entry" role="article"
aria-setsize="`)
//line templates/recent_changes.qtpl:37
qw422016.N().D(n)
//line templates/recent_changes.qtpl:37
qw422016.N().S(`" aria-posinset="`)
//line templates/recent_changes.qtpl:37
qw422016.N().D(i)
//line templates/recent_changes.qtpl:37
qw422016.N().S(`">
`)
//line templates/recent_changes.qtpl:38
qw422016.N().S(entry)
//line templates/recent_changes.qtpl:38
qw422016.N().S(`
</ul>
`)
//line templates/recent_changes.qtpl:40
}
//line templates/recent_changes.qtpl:40
qw422016.N().S(`
`)
//line templates/recent_changes.qtpl:41
}
//line templates/recent_changes.qtpl:41
qw422016.N().S(`
</section>
</main>
</div>
`)
//line templates/recent_changes.qtpl:45
}
//line templates/recent_changes.qtpl:45
func WriteRecentChangesHTML(qq422016 qtio422016.Writer, changes []string, n int) {
//line templates/recent_changes.qtpl:45
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/recent_changes.qtpl:45
StreamRecentChangesHTML(qw422016, changes, n)
//line templates/recent_changes.qtpl:45
qt422016.ReleaseWriter(qw422016)
//line templates/recent_changes.qtpl:45
}
//line templates/recent_changes.qtpl:45
func RecentChangesHTML(changes []string, n int) string {
//line templates/recent_changes.qtpl:45
qb422016 := qt422016.AcquireByteBuffer()
//line templates/recent_changes.qtpl:45
WriteRecentChangesHTML(qb422016, changes, n)
//line templates/recent_changes.qtpl:45
qs422016 := string(qb422016.B)
//line templates/recent_changes.qtpl:45
qt422016.ReleaseByteBuffer(qb422016)
//line templates/recent_changes.qtpl:45
return qs422016
//line templates/recent_changes.qtpl:45
}

View File

@ -1,4 +1,9 @@
{% func RecentChangesHTML(changes []string, n int) %}
{% import "net/http" %}
{% import "github.com/bouncepaw/mycorrhiza/util" %}
{% import "github.com/bouncepaw/mycorrhiza/history" %}
{% func RecentChangesHTML(n int) %}
<div class="layout">
<main class="main-width recent-changes">
<h1>Recent Changes</h1>
@ -28,6 +33,9 @@
How come? I'll add the role anyway. -- bouncepaw
{% endcomment %}
{% code
changes := history.RecentChanges(n)
%}
<section class="recent-changes__list" role="feed">
{% if len(changes) == 0 %}
<p>Could not find any recent changes.</p>
@ -35,7 +43,7 @@
{% for i, entry := range changes %}
<ul class="recent-changes__entry rc-entry" role="article"
aria-setsize="{%d n %}" aria-posinset="{%d i %}">
{%s= entry %}
{%s= recentChangesEntry(entry) %}
</ul>
{% endfor %}
{% endif %}
@ -43,3 +51,22 @@
</main>
</div>
{% endfunc %}
{% func recentChangesEntry(rev history.Revision) %}
<li class="rc-entry__time"><time>{%s rev.TimeString() %}</time></li>
<li class="rc-entry__hash">{%s rev.Hash %}</li>
<li class="rc-entry__links">{%s= rev.HyphaeLinksHTML() %}</li>
<li class="rc-entry__msg">{%s rev.Message %} {% if rev.Username != "anon" %}<span class="rc-entry__author">by <a href="/hypha/{%s util.UserHypha %}/{%s rev.Username %}" rel="author">{%s rev.Username %}</a></span>{% endif %}</li>
{% endfunc %}
{% func HistoryHTML(rq *http.Request, hyphaName, list string) %}
{%= NavHTML(rq, hyphaName, "history") %}
<div class="layout">
<main class="main-width">
<article class="history">
<h1>History of {%s util.BeautifulName(hyphaName) %}</h1>
{%s= list %}
</article>
</main>
</div>
{% endfunc %}

305
views/history.qtpl.go Normal file
View File

@ -0,0 +1,305 @@
// 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 "net/http"
//line views/history.qtpl:3
import "github.com/bouncepaw/mycorrhiza/util"
//line views/history.qtpl:4
import "github.com/bouncepaw/mycorrhiza/history"
//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 StreamRecentChangesHTML(qw422016 *qt422016.Writer, n int) {
//line views/history.qtpl:6
qw422016.N().S(`
<div class="layout">
<main class="main-width recent-changes">
<h1>Recent Changes</h1>
<p><a href="/"> Back</a></p>
<nav class="recent-changes__count">
See
`)
//line views/history.qtpl:14
for _, m := range []int{20, 0, 50, 0, 100} {
//line views/history.qtpl:14
qw422016.N().S(`
`)
//line views/history.qtpl:15
switch m {
//line views/history.qtpl:16
case 0:
//line views/history.qtpl:16
qw422016.N().S(`
<span aria-hidden="true">|</span>
`)
//line views/history.qtpl:18
case n:
//line views/history.qtpl:18
qw422016.N().S(`
<b>`)
//line views/history.qtpl:19
qw422016.N().D(n)
//line views/history.qtpl:19
qw422016.N().S(`</b>
`)
//line views/history.qtpl:20
default:
//line views/history.qtpl:20
qw422016.N().S(`
<a href="/recent-changes/`)
//line views/history.qtpl:21
qw422016.N().D(m)
//line views/history.qtpl:21
qw422016.N().S(`">`)
//line views/history.qtpl:21
qw422016.N().D(m)
//line views/history.qtpl:21
qw422016.N().S(`</a>
`)
//line views/history.qtpl:22
}
//line views/history.qtpl:22
qw422016.N().S(`
`)
//line views/history.qtpl:23
}
//line views/history.qtpl:23
qw422016.N().S(`
recent changes
</nav>
<p><img class="icon" width="20" height="20" src="https://upload.wikimedia.org/wikipedia/commons/4/46/Generic_Feed-icon.svg">Subscribe via <a href="/recent-changes-rss">RSS</a>, <a href="/recent-changes-atom">Atom</a> or <a href="/recent-changes-json">JSON feed</a>.</p>
`)
//line views/history.qtpl:34
qw422016.N().S(`
`)
//line views/history.qtpl:37
changes := history.RecentChanges(n)
//line views/history.qtpl:38
qw422016.N().S(`
<section class="recent-changes__list" role="feed">
`)
//line views/history.qtpl:40
if len(changes) == 0 {
//line views/history.qtpl:40
qw422016.N().S(`
<p>Could not find any recent changes.</p>
`)
//line views/history.qtpl:42
} else {
//line views/history.qtpl:42
qw422016.N().S(`
`)
//line views/history.qtpl:43
for i, entry := range changes {
//line views/history.qtpl:43
qw422016.N().S(`
<ul class="recent-changes__entry rc-entry" role="article"
aria-setsize="`)
//line views/history.qtpl:45
qw422016.N().D(n)
//line views/history.qtpl:45
qw422016.N().S(`" aria-posinset="`)
//line views/history.qtpl:45
qw422016.N().D(i)
//line views/history.qtpl:45
qw422016.N().S(`">
`)
//line views/history.qtpl:46
qw422016.N().S(recentChangesEntry(entry))
//line views/history.qtpl:46
qw422016.N().S(`
</ul>
`)
//line views/history.qtpl:48
}
//line views/history.qtpl:48
qw422016.N().S(`
`)
//line views/history.qtpl:49
}
//line views/history.qtpl:49
qw422016.N().S(`
</section>
</main>
</div>
`)
//line views/history.qtpl:53
}
//line views/history.qtpl:53
func WriteRecentChangesHTML(qq422016 qtio422016.Writer, n int) {
//line views/history.qtpl:53
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/history.qtpl:53
StreamRecentChangesHTML(qw422016, n)
//line views/history.qtpl:53
qt422016.ReleaseWriter(qw422016)
//line views/history.qtpl:53
}
//line views/history.qtpl:53
func RecentChangesHTML(n int) string {
//line views/history.qtpl:53
qb422016 := qt422016.AcquireByteBuffer()
//line views/history.qtpl:53
WriteRecentChangesHTML(qb422016, n)
//line views/history.qtpl:53
qs422016 := string(qb422016.B)
//line views/history.qtpl:53
qt422016.ReleaseByteBuffer(qb422016)
//line views/history.qtpl:53
return qs422016
//line views/history.qtpl:53
}
//line views/history.qtpl:55
func streamrecentChangesEntry(qw422016 *qt422016.Writer, rev history.Revision) {
//line views/history.qtpl:55
qw422016.N().S(`
<li class="rc-entry__time"><time>`)
//line views/history.qtpl:56
qw422016.E().S(rev.TimeString())
//line views/history.qtpl:56
qw422016.N().S(`</time></li>
<li class="rc-entry__hash">`)
//line views/history.qtpl:57
qw422016.E().S(rev.Hash)
//line views/history.qtpl:57
qw422016.N().S(`</li>
<li class="rc-entry__links">`)
//line views/history.qtpl:58
qw422016.N().S(rev.HyphaeLinksHTML())
//line views/history.qtpl:58
qw422016.N().S(`</li>
<li class="rc-entry__msg">`)
//line views/history.qtpl:59
qw422016.E().S(rev.Message)
//line views/history.qtpl:59
qw422016.N().S(` `)
//line views/history.qtpl:59
if rev.Username != "anon" {
//line views/history.qtpl:59
qw422016.N().S(`<span class="rc-entry__author">by <a href="/hypha/`)
//line views/history.qtpl:59
qw422016.E().S(util.UserHypha)
//line views/history.qtpl:59
qw422016.N().S(`/`)
//line views/history.qtpl:59
qw422016.E().S(rev.Username)
//line views/history.qtpl:59
qw422016.N().S(`" rel="author">`)
//line views/history.qtpl:59
qw422016.E().S(rev.Username)
//line views/history.qtpl:59
qw422016.N().S(`</a></span>`)
//line views/history.qtpl:59
}
//line views/history.qtpl:59
qw422016.N().S(`</li>
`)
//line views/history.qtpl:60
}
//line views/history.qtpl:60
func writerecentChangesEntry(qq422016 qtio422016.Writer, rev history.Revision) {
//line views/history.qtpl:60
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/history.qtpl:60
streamrecentChangesEntry(qw422016, rev)
//line views/history.qtpl:60
qt422016.ReleaseWriter(qw422016)
//line views/history.qtpl:60
}
//line views/history.qtpl:60
func recentChangesEntry(rev history.Revision) string {
//line views/history.qtpl:60
qb422016 := qt422016.AcquireByteBuffer()
//line views/history.qtpl:60
writerecentChangesEntry(qb422016, rev)
//line views/history.qtpl:60
qs422016 := string(qb422016.B)
//line views/history.qtpl:60
qt422016.ReleaseByteBuffer(qb422016)
//line views/history.qtpl:60
return qs422016
//line views/history.qtpl:60
}
//line views/history.qtpl:62
func StreamHistoryHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, list string) {
//line views/history.qtpl:62
qw422016.N().S(`
`)
//line views/history.qtpl:63
StreamNavHTML(qw422016, rq, hyphaName, "history")
//line views/history.qtpl:63
qw422016.N().S(`
<div class="layout">
<main class="main-width">
<article class="history">
<h1>History of `)
//line views/history.qtpl:67
qw422016.E().S(util.BeautifulName(hyphaName))
//line views/history.qtpl:67
qw422016.N().S(`</h1>
`)
//line views/history.qtpl:68
qw422016.N().S(list)
//line views/history.qtpl:68
qw422016.N().S(`
</article>
</main>
</div>
`)
//line views/history.qtpl:72
}
//line views/history.qtpl:72
func WriteHistoryHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, list string) {
//line views/history.qtpl:72
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/history.qtpl:72
StreamHistoryHTML(qw422016, rq, hyphaName, list)
//line views/history.qtpl:72
qt422016.ReleaseWriter(qw422016)
//line views/history.qtpl:72
}
//line views/history.qtpl:72
func HistoryHTML(rq *http.Request, hyphaName, list string) string {
//line views/history.qtpl:72
qb422016 := qt422016.AcquireByteBuffer()
//line views/history.qtpl:72
WriteHistoryHTML(qb422016, rq, hyphaName, list)
//line views/history.qtpl:72
qs422016 := string(qb422016.B)
//line views/history.qtpl:72
qt422016.ReleaseByteBuffer(qb422016)
//line views/history.qtpl:72
return qs422016
//line views/history.qtpl:72
}

View File

@ -67,15 +67,3 @@ If `contents` == "", a helpful message is shown instead.
{%= RelativeHyphaeHTML(relatives) %}
</div>
{% endfunc %}
{% func HistoryHTML(rq *http.Request, hyphaName, list string) %}
{%= NavHTML(rq, hyphaName, "history") %}
<div class="layout">
<main class="main-width">
<article class="history">
<h1>History of {%s hyphaName %}</h1>
{%s= list %}
</article>
</main>
</div>
{% endfunc %}

View File

@ -281,58 +281,3 @@ func RevisionHTML(rq *http.Request, h *hyphae.Hypha, contents, revHash string) s
return qs422016
//line views/readers.qtpl:69
}
//line views/readers.qtpl:71
func StreamHistoryHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, list string) {
//line views/readers.qtpl:71
qw422016.N().S(`
`)
//line views/readers.qtpl:72
StreamNavHTML(qw422016, rq, hyphaName, "history")
//line views/readers.qtpl:72
qw422016.N().S(`
<div class="layout">
<main class="main-width">
<article class="history">
<h1>History of `)
//line views/readers.qtpl:76
qw422016.E().S(hyphaName)
//line views/readers.qtpl:76
qw422016.N().S(`</h1>
`)
//line views/readers.qtpl:77
qw422016.N().S(list)
//line views/readers.qtpl:77
qw422016.N().S(`
</article>
</main>
</div>
`)
//line views/readers.qtpl:81
}
//line views/readers.qtpl:81
func WriteHistoryHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, list string) {
//line views/readers.qtpl:81
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/readers.qtpl:81
StreamHistoryHTML(qw422016, rq, hyphaName, list)
//line views/readers.qtpl:81
qt422016.ReleaseWriter(qw422016)
//line views/readers.qtpl:81
}
//line views/readers.qtpl:81
func HistoryHTML(rq *http.Request, hyphaName, list string) string {
//line views/readers.qtpl:81
qb422016 := qt422016.AcquireByteBuffer()
//line views/readers.qtpl:81
WriteHistoryHTML(qb422016, rq, hyphaName, list)
//line views/readers.qtpl:81
qs422016 := string(qb422016.B)
//line views/readers.qtpl:81
qt422016.ReleaseByteBuffer(qb422016)
//line views/readers.qtpl:81
return qs422016
//line views/readers.qtpl:81
}