1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00
mycorrhiza/views/readers.qtpl

132 lines
4.6 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-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) %}
{%= NavHTML(rq, h.Name, "attachment") %}
<div class="layout">
<main class="main-width attachment-tab">
2021-02-24 17:34:42 +00:00
<h1>Attachment of {%s util.BeautifulName(h.Name) %}</h1>
{% if h.BinaryPath == "" %}
<p class="explanation">This hypha has no attachment, you can upload it here. <a href="/help/en/attachment" class="shy-link">What are attachments?</a></p>
2021-02-24 17:34:42 +00:00
{% else %}
<p class="explanation">You can manage the hypha's attachment on this page. <a href="/help/en/attachment" class="shy-link">What are attachments?</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">
<legend class="modal__title modal__title_small">Stat</legend>
<p class="modal__confirmation-msg"><b>File size:</b> {%dl fileinfo.Size() %} bytes</p>
<p><b>MIME type:</b> {%s mime %}</p>
</fieldset>
{% endif %}
{% if strings.HasPrefix(mime, "image/") %}
<fieldset class="amnt-menu-block">
<legend class="modal__title modal__title_small">Include</legend>
2021-02-24 17:37:34 +00:00
<p class="modal__confirmation-msg">This attachment is an image. To include it n a hypha, use a syntax like this:</p>
2021-02-24 17:34:42 +00:00
<pre class="codebleck"><code>img { {%s h.Name %} }</code></pre>
</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-02-24 17:34:42 +00:00
<legend class="modal__title modal__title_small">Attach</legend>
2021-02-24 17:37:34 +00:00
<p class="modal__confirmation-msg">You can upload a new attachment. Please do not upload too big pictures unless you need to because may not want to wait for big pictures to load.</p>
2021-05-25 07:34:04 +00:00
<label for="upload-binary__input"></label>
<input type="file" id="upload-binary__input" name="binary">
<input type="submit" class="btn stick-to-bottom" value="Upload">
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">
<legend class="modal__title modal__title_small">Unattach</legend>
<p class="modal__confirmation-msg">Please note that you don't have to unattach before uploading a new attachment.</p>
2021-05-25 07:34:04 +00:00
<input type="submit" class="btn" value="Unattach">
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-02-20 16:14:33 +00:00
{% func HyphaHTML(rq *http.Request, h *hyphae.Hypha, contents string) %}
{% 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-06-14 07:13:29 +00:00
{%= NavHTML(rq, h.Name, "hypha") %}
2021-01-25 18:37:21 +00:00
<div class="layout">
2021-01-26 05:41:57 +00:00
<main class="main-width">
<article>
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 %}
{%= nonExistentHyphaNotice(h, u) %}
2021-01-26 05:41:57 +00:00
{% endif %}
</article>
<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-02-20 16:14:33 +00:00
{%= SubhyphaeHTML(subhyphae) %}
</main>
2021-07-12 15:23:25 +00:00
{%= siblingHyphaeHTML(siblings) %}
2021-02-20 16:14:33 +00:00
</div>
{%= viewScripts() %}
2021-02-20 16:14:33 +00:00
{% endfunc %}
{% func RevisionHTML(rq *http.Request, h *hyphae.Hypha, contents, revHash string) %}
{% code
2021-07-12 15:23:25 +00:00
siblings, subhyphae, _, _ := tree.Tree(h.Name)
2021-02-20 16:14:33 +00:00
%}
{%= NavHTML(rq, h.Name, "revision", revHash) %}
<div class="layout">
<main class="main-width">
<article>
<p>Please note that viewing binary parts of hyphae is not supported in history for now.</p>
{%s= NaviTitleHTML(h) %}
{%s= contents %}
</article>
{%= SubhyphaeHTML(subhyphae) %}
</main>
2021-07-12 15:23:25 +00:00
{%= siblingHyphaeHTML(siblings) %}
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 %}