1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Migrate /remove-media/ to the new template system

Is this path used anywhere?
This commit is contained in:
Timur Ismagilov 2022-09-21 11:22:48 +03:00
parent d6f2599453
commit 9551db6719
5 changed files with 40 additions and 149 deletions

View File

@ -71,12 +71,17 @@ var (
{{define "rename recursively"}}Также переименовать подгифы{{end}} {{define "rename recursively"}}Также переименовать подгифы{{end}}
{{define "rename tip"}}Переименовывайте аккуратно. <a href="/help/en/rename">Документация на английском.</a>{{end}} {{define "rename tip"}}Переименовывайте аккуратно. <a href="/help/en/rename">Документация на английском.</a>{{end}}
{{define "leave redirection"}}Оставить перенаправление{{end}} {{define "leave redirection"}}Оставить перенаправление{{end}}
{{define "remove media from x?"}}Убрать медиа у {{beautifulName .}}?{{end}}
{{define "remove media from [[x]]?"}}Убрать медиа у <a href="/hypha/{{.HyphaName}}">{{beautifulName .HyphaName}}</a>?{{end}}
{{define "remove media for real?"}}Вы точно хотите убрать медиа у гифы «{{beautifulName .HyphaName}}»?{{end}}
` `
chainNaviTitle viewutil.Chain chainNaviTitle viewutil.Chain
chainEditHypha viewutil.Chain chainEditHypha viewutil.Chain
chainEmptyHypha viewutil.Chain chainEmptyHypha viewutil.Chain
chainDeleteHypha viewutil.Chain chainDeleteHypha viewutil.Chain
chainRenameHypha viewutil.Chain chainRenameHypha viewutil.Chain
chainRemoveMedia viewutil.Chain
) )
func Init() { func Init() {
@ -85,6 +90,7 @@ func Init() {
chainEmptyHypha = viewutil.CopyEnRuWith(fs, "view_empty_hypha.html", ruTranslation) chainEmptyHypha = viewutil.CopyEnRuWith(fs, "view_empty_hypha.html", ruTranslation)
chainDeleteHypha = viewutil.CopyEnRuWith(fs, "view_delete.html", ruTranslation) chainDeleteHypha = viewutil.CopyEnRuWith(fs, "view_delete.html", ruTranslation)
chainRenameHypha = viewutil.CopyEnRuWith(fs, "view_rename.html", ruTranslation) chainRenameHypha = viewutil.CopyEnRuWith(fs, "view_rename.html", ruTranslation)
chainRemoveMedia = viewutil.CopyEnRuWith(fs, "view_remove_media.html", ruTranslation)
} }
type editData struct { type editData struct {
@ -126,13 +132,13 @@ func RenameHypha(meta viewutil.Meta, hyphaName string) {
}) })
} }
type deleteData struct { type deleteRemoveMediaData struct {
*viewutil.BaseData *viewutil.BaseData
HyphaName string HyphaName string
} }
func DeleteHypha(meta viewutil.Meta, hyphaName string) { func DeleteHypha(meta viewutil.Meta, hyphaName string) {
viewutil.ExecutePage(meta, chainDeleteHypha, deleteData{ viewutil.ExecutePage(meta, chainDeleteHypha, deleteRemoveMediaData{
BaseData: &viewutil.BaseData{ BaseData: &viewutil.BaseData{
Addr: "/delete/" + hyphaName, Addr: "/delete/" + hyphaName,
}, },
@ -140,6 +146,15 @@ func DeleteHypha(meta viewutil.Meta, hyphaName string) {
}) })
} }
func RemoveMedia(meta viewutil.Meta, hyphaName string) {
viewutil.ExecutePage(meta, chainRemoveMedia, deleteRemoveMediaData{
BaseData: &viewutil.BaseData{
Addr: "/remove-media/" + hyphaName,
},
HyphaName: hyphaName,
})
}
type emptyHyphaData struct { type emptyHyphaData struct {
Meta viewutil.Meta Meta viewutil.Meta
HyphaName string HyphaName string

View File

@ -1,28 +0,0 @@
{% import "fmt" %}
{% import "net/http" %}
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
{% func RemoveMediaAsk(rq *http.Request, hyphaName string) %}
{% code
lc := l18n.FromRequest(rq)
%}
<main class="main-width">
<form class="modal" action="/remove-media/{%s hyphaName %}" method="post">
<fieldset class="modal__fieldset">
<legend class="modal__title">
{%s= fmt.Sprintf(lc.Get("ui.ask_remove_media"), beautifulLink(hyphaName)) %}
</legend>
<p class="modal__confirmation-msg">
{%s= lc.Get("ui.ask_really", &l18n.Replacements{"verb": lc.Get("ui.ask_remove_media_verb"), "name": fmt.Sprintf("<em>%s</em>", hyphaName)}) %}
</p>
<button type="submit" value="Confirm" class="btn" autofocus>
{%s lc.Get("ui.confirm") %}
</button>
<a href="/hypha/{%s hyphaName %}" class="btn btn_weak">
{%s lc.Get("ui.cancel") %}
</a>
</fieldset>
</form>
</main>
{% endfunc %}

View File

@ -1,109 +0,0 @@
// Code generated by qtc from "remove_media.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line hypview/remove_media.qtpl:1
package hypview
//line hypview/remove_media.qtpl:1
import "fmt"
//line hypview/remove_media.qtpl:2
import "net/http"
//line hypview/remove_media.qtpl:3
import "github.com/bouncepaw/mycorrhiza/l18n"
//line hypview/remove_media.qtpl:5
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line hypview/remove_media.qtpl:5
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line hypview/remove_media.qtpl:5
func StreamRemoveMediaAsk(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) {
//line hypview/remove_media.qtpl:5
qw422016.N().S(`
`)
//line hypview/remove_media.qtpl:7
lc := l18n.FromRequest(rq)
//line hypview/remove_media.qtpl:8
qw422016.N().S(`
<main class="main-width">
<form class="modal" action="/remove-media/`)
//line hypview/remove_media.qtpl:10
qw422016.E().S(hyphaName)
//line hypview/remove_media.qtpl:10
qw422016.N().S(`" method="post">
<fieldset class="modal__fieldset">
<legend class="modal__title">
`)
//line hypview/remove_media.qtpl:13
qw422016.N().S(fmt.Sprintf(lc.Get("ui.ask_remove_media"), beautifulLink(hyphaName)))
//line hypview/remove_media.qtpl:13
qw422016.N().S(`
</legend>
<p class="modal__confirmation-msg">
`)
//line hypview/remove_media.qtpl:16
qw422016.N().S(lc.Get("ui.ask_really", &l18n.Replacements{"verb": lc.Get("ui.ask_remove_media_verb"), "name": fmt.Sprintf("<em>%s</em>", hyphaName)}))
//line hypview/remove_media.qtpl:16
qw422016.N().S(`
</p>
<button type="submit" value="Confirm" class="btn" autofocus>
`)
//line hypview/remove_media.qtpl:19
qw422016.E().S(lc.Get("ui.confirm"))
//line hypview/remove_media.qtpl:19
qw422016.N().S(`
</button>
<a href="/hypha/`)
//line hypview/remove_media.qtpl:21
qw422016.E().S(hyphaName)
//line hypview/remove_media.qtpl:21
qw422016.N().S(`" class="btn btn_weak">
`)
//line hypview/remove_media.qtpl:22
qw422016.E().S(lc.Get("ui.cancel"))
//line hypview/remove_media.qtpl:22
qw422016.N().S(`
</a>
</fieldset>
</form>
</main>
`)
//line hypview/remove_media.qtpl:27
}
//line hypview/remove_media.qtpl:27
func WriteRemoveMediaAsk(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) {
//line hypview/remove_media.qtpl:27
qw422016 := qt422016.AcquireWriter(qq422016)
//line hypview/remove_media.qtpl:27
StreamRemoveMediaAsk(qw422016, rq, hyphaName)
//line hypview/remove_media.qtpl:27
qt422016.ReleaseWriter(qw422016)
//line hypview/remove_media.qtpl:27
}
//line hypview/remove_media.qtpl:27
func RemoveMediaAsk(rq *http.Request, hyphaName string) string {
//line hypview/remove_media.qtpl:27
qb422016 := qt422016.AcquireByteBuffer()
//line hypview/remove_media.qtpl:27
WriteRemoveMediaAsk(qb422016, rq, hyphaName)
//line hypview/remove_media.qtpl:27
qs422016 := string(qb422016.B)
//line hypview/remove_media.qtpl:27
qt422016.ReleaseByteBuffer(qb422016)
//line hypview/remove_media.qtpl:27
return qs422016
//line hypview/remove_media.qtpl:27
}

View File

@ -0,0 +1,22 @@
{{define "remove media from x?"}}Remove media from {{beautifulName .}}?{{end}}
{{define "title"}}{{template "remove media from x?" .HyphaName}}{{end}}
{{define "body"}}
<main class="main-width">
<form class="modal" action="/remove-media/{{.HyphaName}}" method="post">
<fieldset class="modal__fieldset">
<legend class="modal__title">
{{block "remove media from [[x]]?" .}}Remove media from <a href="/hypha/{{.HyphaName}}">{{beautifulName .HyphaName}}</a>?{{end}}
</legend>
<p class="modal__confirmation-msg">
{{block "remove media for real?" .}}Do you really want to remove media from hypha {{beautifulName .HyphaName}}?{{end}}
</p>
<button type="submit" value="Confirm" class="btn" autofocus>
{{template "confirm"}}
</button>
<a href="/hypha/{%s hyphaName %}" class="btn btn_weak">
{{template "cancel"}}
</a>
</fieldset>
</form>
</main>
{{end}}

View File

@ -1,7 +1,6 @@
package web package web
import ( import (
"fmt"
"git.sr.ht/~bouncepaw/mycomarkup/v5" "git.sr.ht/~bouncepaw/mycomarkup/v5"
"html/template" "html/template"
"log" "log"
@ -37,7 +36,6 @@ func handlerRemoveMedia(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq) util.PrepareRq(rq)
var ( var (
u = user.FromRequest(rq) u = user.FromRequest(rq)
lc = l18n.FromRequest(rq)
h = hyphae.ByName(util.HyphaNameFromRq(rq, "remove-media")) h = hyphae.ByName(util.HyphaNameFromRq(rq, "remove-media"))
meta = viewutil.MetaFrom(w, rq) meta = viewutil.MetaFrom(w, rq)
) )
@ -46,14 +44,7 @@ func handlerRemoveMedia(w http.ResponseWriter, rq *http.Request) {
return return
} }
if rq.Method == "GET" { if rq.Method == "GET" {
util.HTTP200Page( hypview.RemoveMedia(viewutil.MetaFrom(w, rq), h.CanonicalName())
w,
viewutil.Base(
meta,
fmt.Sprintf(lc.Get("ui.ask_remove_media"), util.BeautifulName(h.CanonicalName())),
hypview.RemoveMediaAsk(rq, h.CanonicalName()),
map[string]string{},
))
return return
} }
switch h := h.(type) { switch h := h.(type) {