1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00
mycorrhiza/views/history.qtpl

123 lines
3.6 KiB
Plaintext
Raw Normal View History

2021-07-01 09:37:41 +00:00
{% import "fmt" %}
2021-02-20 16:50:25 +00:00
{% import "net/http" %}
2021-07-01 09:37:41 +00:00
{% import "time" %}
2021-02-20 16:50:25 +00:00
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
2021-09-06 17:46:34 +00:00
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
2021-02-20 16:50:25 +00:00
{% import "github.com/bouncepaw/mycorrhiza/history" %}
2022-03-20 21:24:40 +00:00
{% func PrimitiveDiff(rq *http.Request, h hyphae.ExistingHypha, u *user.User, hash string) %}
{% code
2021-09-06 17:46:34 +00:00
lc := l18n.FromRequest(rq)
2022-02-19 08:26:38 +00:00
text, err := history.PrimitiveDiffAtRevision(h.TextFilePath(), hash)
if err != nil {
text = err.Error()
}
%}
<div class="layout">
<main class="main-width">
<article>
2022-02-03 22:29:01 +00:00
<h1>{%s= lc.Get("ui.diff_title", &l18n.Replacements{"name": beautifulLink(h.CanonicalName()), "rev": hash}) %}</h1>
<pre class="codeblock"><code>{%s text %}</code></pre>
</article>
</main>
</div>
{% endfunc %}
2022-03-20 21:24:40 +00:00
{% func RecentChanges(n int, lc *l18n.Localizer) %}
2021-01-26 05:41:57 +00:00
<div class="layout">
<main class="main-width recent-changes">
2021-09-06 17:46:34 +00:00
<h1>{%s lc.Get("ui.recent_heading") %}</h1>
2020-09-26 18:19:17 +00:00
<nav class="recent-changes__count">
2021-09-06 17:46:34 +00:00
{%s lc.Get("ui.recent_count_pre") %}
2021-07-01 09:37:41 +00:00
{% for i, m := range []int{20, 50, 100} %}
{% if i > 0 %}
2020-09-26 18:19:17 +00:00
<span aria-hidden="true">|</span>
2021-07-01 09:37:41 +00:00
{% endif %}
{% if m == n %}
<b>{%d m %}</b>
{% else %}
2020-09-26 18:19:17 +00:00
<a href="/recent-changes/{%d m %}">{%d m %}</a>
2021-07-01 09:37:41 +00:00
{% endif %}
2020-09-26 18:19:17 +00:00
{% endfor %}
2021-09-06 17:46:34 +00:00
{%s lc.Get("ui.recent_count_post") %}
2020-09-26 18:19:17 +00:00
</nav>
2021-09-06 17:46:34 +00:00
<p><img class="icon" width="20" height="20" src="/static/icon/feed.svg">{%s= lc.Get("ui.recent_subscribe", &l18n.Replacements{"rss": "<a href=\"/recent-changes-rss\">RSS</a>", "atom": "<a href=\"/recent-changes-atom\">Atom</a>", "json": fmt.Sprintf("<a href=\"/recent-changes-json\">%s</a>", lc.Get("ui.recent_subscribe_json"))}) %}</p>
2020-09-26 18:19:17 +00:00
{% comment %}
2021-03-06 09:44:20 +00:00
Here I am, willing to add some accessibility using ARIA. Turns out,
2020-09-26 18:19:17 +00:00
role="feed" is not supported in any screen reader as of September
2020. At least web search says so. Even JAWS doesn't support it!
How come? I'll add the role anyway. -- bouncepaw
{% endcomment %}
2021-07-01 09:37:41 +00:00
{% code
2021-02-20 16:50:25 +00:00
changes := history.RecentChanges(n)
2021-07-01 09:37:41 +00:00
var year, day int
var month time.Month
2021-02-20 16:50:25 +00:00
%}
2020-09-26 18:19:17 +00:00
<section class="recent-changes__list" role="feed">
{% if len(changes) == 0 %}
2021-09-06 17:46:34 +00:00
<p>{%s lc.Get("ui.recent_empty") %}</p>
2020-09-26 18:19:17 +00:00
{% else %}
{% for i, entry := range changes %}
2021-07-01 09:37:41 +00:00
{% code y, m, d := entry.Time.UTC().Date() %}
{% if d != day || m != month || y != year %}
<h2 class="recent-changes__heading">
{%s fmt.Sprintf("%04d-%02d-%02d", y, m, d) %}
</h2>
2021-07-01 09:37:41 +00:00
{% code year, month, day = y, m, d %}
{% endif %}
<div class="recent-changes__entry" role="article"
2020-09-26 18:19:17 +00:00
aria-setsize="{%d n %}" aria-posinset="{%d i %}">
2022-03-20 21:24:40 +00:00
{%s= recentChanges(entry) %}
</div>
2021-07-01 09:37:41 +00:00
2020-09-26 18:19:17 +00:00
{% endfor %}
{% endif %}
</section>
</main>
2021-01-26 05:41:57 +00:00
</div>
2020-09-26 18:19:17 +00:00
{% endfunc %}
2021-02-20 16:50:25 +00:00
2022-03-20 21:24:40 +00:00
{% func recentChanges(rev history.Revision) %}
<div>
<time class="recent-changes__entry__time">
{%s rev.Time.UTC().Format("15:04 UTC") %}
</time>
<span class="recent-changes__entry__message">{%s rev.Hash %}</span>
{% if rev.Username != "anon" %}
<span class="recent-changes__entry__author">
&mdash; <a href="/hypha/{%s cfg.UserHypha %}/{%s rev.Username %}" rel="author">{%s rev.Username %}</a>
</span>
{% endif %}
</div>
<div>
<span class="recent-changes__entry__links">
{%s= rev.HyphaeLinksHTML() %}
</span>
<span class="recent-changes__entry__message">
{%s rev.Message %}
</span>
</div>
2021-02-20 16:50:25 +00:00
{% endfunc %}
2022-03-20 21:24:40 +00:00
{% func History(rq *http.Request, hyphaName, list string, lc *l18n.Localizer) %}
2021-02-20 16:50:25 +00:00
<div class="layout">
<main class="main-width">
<article class="history">
2021-09-06 17:46:34 +00:00
<h1>{%s= fmt.Sprintf(lc.Get("ui.history_title"), beautifulLink(hyphaName)) %}</h1>
2021-02-20 16:50:25 +00:00
{%s= list %}
</article>
</main>
</div>
{% endfunc %}