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

163 lines
5.7 KiB
Plaintext
Raw Normal View History

{% import "net/http" %}
2021-02-24 17:34:42 +00:00
{% import "strings" %}
2020-11-29 11:32:52 +00:00
{% import "path" %}
2021-02-24 17:34:42 +00:00
{% import "os" %}
2021-02-20 16:14:33 +00:00
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
2021-09-06 17:46:34 +00:00
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
2021-02-24 17:34:42 +00:00
{% import "github.com/bouncepaw/mycorrhiza/mimetype" %}
{% import "github.com/bouncepaw/mycorrhiza/tree" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "github.com/bouncepaw/mycorrhiza/util" %}
2021-02-24 17:34:42 +00:00
{% func AttachmentMenuHTML(rq *http.Request, h *hyphae.Hypha, u *user.User) %}
2021-09-06 17:46:34 +00:00
{% code
lc := l18n.FromRequest(rq)
%}
2021-02-24 17:34:42 +00:00
<div class="layout">
<main class="main-width attachment-tab">
2021-09-06 17:46:34 +00:00
<h1>{%s= lc.Get("ui.attach_title", &l18n.Replacements{"name": beautifulLink(h.Name)}) %}</h1>
2021-02-24 17:34:42 +00:00
{% if h.BinaryPath == "" %}
2021-09-06 17:46:34 +00:00
<p class="explanation">{%s lc.Get("ui.attach_empty") %} <a href="/help/{%s lc.Locale %}/attachment" class="shy-link">{%s lc.Get("ui.attach_link") %}</a></p>
2021-02-24 17:34:42 +00:00
{% else %}
2021-09-06 17:46:34 +00:00
<p class="explanation">{%s lc.Get("ui.attach_tip") %} <a href="/help/{%s lc.Locale %}/attachment" class="shy-link">{%s lc.Get("ui.attach_link") %}</a></p>
2021-02-24 17:34:42 +00:00
{% endif %}
<section class="amnt-grid">
{% if h.BinaryPath != "" %}
{% code
mime := mimetype.FromExtension(path.Ext(h.BinaryPath))
fileinfo, err := os.Stat(h.BinaryPath) %}
{% if err == nil %}
<fieldset class="amnt-menu-block">
2021-09-06 17:46:34 +00:00
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_stat") %}</legend>
<p class="modal__confirmation-msg"><b>{%s lc.Get("ui.attach_stat_size") %}</b> {%s lc.GetPlural64("ui.attach_size_value", fileinfo.Size())%}</p>
<p><b>{%s lc.Get("ui.attach_stat_mime") %}</b> {%s mime %}</p>
2021-02-24 17:34:42 +00:00
</fieldset>
{% endif %}
{% if strings.HasPrefix(mime, "image/") %}
<fieldset class="amnt-menu-block">
2021-09-06 17:46:34 +00:00
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_include") %}</legend>
<p class="modal__confirmation-msg">{%s lc.Get("ui.attach_include_tip") %}</p>
<pre class="codeblock"><code>img { {%s h.Name %} }</code></pre>
2021-02-24 17:34:42 +00:00
</fieldset>
{% endif %}
{% endif %}
{% if u.CanProceed("upload-binary") %}
<form action="/upload-binary/{%s h.Name %}"
method="post" enctype="multipart/form-data"
2021-05-25 07:34:04 +00:00
class="upload-binary modal amnt-menu-block">
<fieldset class="modal__fieldset">
2021-09-06 17:46:34 +00:00
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_new") %}</legend>
<p class="modal__confirmation-msg">{%s lc.Get("ui.attach_new_tip") %}</p>
2021-05-25 07:34:04 +00:00
<label for="upload-binary__input"></label>
<input type="file" id="upload-binary__input" name="binary">
2021-09-06 17:46:34 +00:00
<button type="submit" class="btn stick-to-bottom" value="Upload">{%s lc.Get("ui.attach_upload")%}</button>
2021-02-24 17:34:42 +00:00
</fieldset>
</form>
{% endif %}
{% if h.BinaryPath != "" && u.CanProceed("unattach-confirm") %}
<form action="/unattach-confirm/{%s h.Name %}" method="post" class="modal amnt-menu-block">
<fieldset class="modal__fieldset">
2021-09-06 17:46:34 +00:00
<legend class="modal__title modal__title_small">{%s lc.Get("ui.attach_remove") %}</legend>
<p class="modal__confirmation-msg">{%s lc.Get("ui.attach_remove_tip") %}</p>
<button type="submit" class="btn" value="Unattach">{%s lc.Get("ui.attach_remove_button") %}</button>
2021-02-24 17:34:42 +00:00
</fieldset>
</form>
{% endif %}
</section>
</main>
</div>
{% endfunc %}
2020-08-31 17:52:26 +00:00
If `contents` == "", a helpful message is shown instead.
2021-09-23 09:17:50 +00:00
If you rename .prevnext, change the docs too.
2021-09-06 17:46:34 +00:00
{% func HyphaHTML(rq *http.Request, lc *l18n.Localizer, h *hyphae.Hypha, contents string) %}
2021-02-20 16:14:33 +00:00
{% code
2021-07-12 15:23:25 +00:00
siblings, subhyphae, prevHyphaName, nextHyphaName := tree.Tree(h.Name)
u := user.FromRequest(rq)
2021-02-20 16:14:33 +00:00
%}
2021-01-25 18:37:21 +00:00
<div class="layout">
2021-01-26 05:41:57 +00:00
<main class="main-width">
2021-12-30 21:42:21 +00:00
<section id="hypha">
<div class="jump-btn">
<a class="jump-btn__link" href="#hypha-bottom">↓</a>
</div>
{% if u.CanProceed("edit") %}
<div class="btn btn_navititle">
<a class="btn__link_navititle" href="/edit/{%s h.Name %}">{%s lc.Get("ui.edit_link") %}</a>
</div>
{% endif %}
{% if cfg.UseAuth && util.IsProfileName(h.Name) && u.Name == strings.TrimPrefix(h.Name, cfg.UserHypha + "/") %}
<div class="btn btn_navititle">
<a class="btn__link_navititle" href="/logout">{%s lc.Get("ui.logout_link") %}</a>
</div>
{% if u.Group == "admin" %}
<div class="btn btn_navititle">
<a class="btn__link_navititle" href="admin">{%s lc.Get("ui.admin_panel") %}<a>
</div>
{% endif %}
{% endif %}
2021-02-20 16:14:33 +00:00
{%s= NaviTitleHTML(h) %}
{% if h.Exists %}
2021-01-26 05:41:57 +00:00
{%s= contents %}
{% else %}
2021-09-06 17:46:34 +00:00
{%= nonExistentHyphaNotice(h, u, lc) %}
2021-01-26 05:41:57 +00:00
{% endif %}
2021-12-30 21:42:21 +00:00
</section>
2021-01-26 05:41:57 +00:00
<section class="prevnext">
{% if prevHyphaName != "" %}
<a class="prevnext__el prevnext__prev" href="/hypha/{%s prevHyphaName %}" rel="prev">← {%s util.BeautifulName(path.Base(prevHyphaName)) %}</a>
2021-01-26 05:41:57 +00:00
{% endif %}
{% if nextHyphaName != "" %}
<a class="prevnext__el prevnext__next" href="/hypha/{%s nextHyphaName %}" rel="next">{%s util.BeautifulName(path.Base(nextHyphaName)) %} →</a>
2021-01-26 05:41:57 +00:00
{% endif %}
</section>
2021-09-06 17:46:34 +00:00
{%= SubhyphaeHTML(subhyphae, lc) %}
<section id="hypha-bottom">
<div class="jump-btn">
<a class="jump-btn__link" href="#hypha">↑</a>
</div>
{%= hyphaInfo(rq, h) %}
</section>
2021-02-20 16:14:33 +00:00
</main>
2021-09-06 17:46:34 +00:00
{%= siblingHyphaeHTML(siblings, lc) %}
2021-02-20 16:14:33 +00:00
</div>
{%= viewScripts() %}
2021-02-20 16:14:33 +00:00
{% endfunc %}
2021-09-06 17:46:34 +00:00
{% func RevisionHTML(rq *http.Request, lc *l18n.Localizer, h *hyphae.Hypha, contents, revHash string) %}
2021-02-20 16:14:33 +00:00
{% code
2021-07-12 15:23:25 +00:00
siblings, subhyphae, _, _ := tree.Tree(h.Name)
2021-02-20 16:14:33 +00:00
%}
<div class="layout">
<main class="main-width">
2021-12-30 21:42:21 +00:00
<section>
2021-09-27 09:06:25 +00:00
<p>{%s lc.Get("ui.revision_warning") %} <a href="/rev-text/{%s revHash %}/{%s h.Name %}">{%s lc.Get("ui.revision_link") %}</a></p>
2021-02-20 16:14:33 +00:00
{%s= NaviTitleHTML(h) %}
{%s= contents %}
2021-12-30 21:42:21 +00:00
</section>
2021-09-06 17:46:34 +00:00
{%= SubhyphaeHTML(subhyphae, lc) %}
2021-02-20 16:14:33 +00:00
</main>
2021-09-06 17:46:34 +00:00
{%= siblingHyphaeHTML(siblings, lc) %}
2021-02-20 16:14:33 +00:00
</div>
{%= viewScripts() %}
2021-02-20 16:14:33 +00:00
{% endfunc %}
{% func viewScripts() %}
{% for _, scriptPath := range cfg.ViewScripts %}
<script src="{%s scriptPath %}"></script>
{% endfor %}
{% endfunc %}