1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00

Add Edit description

This commit is contained in:
Alex Gu 2021-06-14 03:38:43 +03:00
parent adcb6d5aaf
commit 1c30f82445
5 changed files with 115 additions and 89 deletions

View File

@ -16,14 +16,22 @@ import (
"github.com/bouncepaw/mycorrhiza/user"
)
func UploadText(h *hyphae.Hypha, data []byte, u *user.User) (hop *history.HistoryOp, errtitle string) {
func UploadText(h *hyphae.Hypha, data []byte, message string, u *user.User) (hop *history.HistoryOp, errtitle string) {
hop = history.Operation(history.TypeEditText)
var action string
if h.Exists {
hop.WithMsg(fmt.Sprintf("Edit %s", h.Name))
action = "Edit"
} else {
hop.WithMsg(fmt.Sprintf("Create %s", h.Name))
action = "Create"
}
if message == "" {
hop.WithMsg(fmt.Sprintf("%s %s", action, h.Name))
} else {
hop.WithMsg(fmt.Sprintf("%s %s with message: %s", action, h.Name, message))
}
if err, errtitle := CanEdit(u, h); err != nil {
return hop.WithErrAbort(err), errtitle
}

View File

@ -111,7 +111,7 @@ textarea {font-size:16px; font-family: 'PT Sans', 'Liberation Sans', sans-serif;
.edit__title { margin-top: 0; }
.edit__preview { border: 2px dashed #ddd; }
.edit-form {height:70vh;}
.edit-form textarea {width:100%;height:95%;}
.edit-form textarea {width:100%;height:calc(100% - 6rem);}
.edit-form__save { font-weight: bold; }
.edit-toolbar__buttons, .edit-toolbar__ad { margin: .5rem; }

View File

@ -77,7 +77,10 @@
<form method="post" class="edit-form"
action="/upload-text/{%s hyphaName %}">
<textarea name="text" class="edit-form__textarea" autofocus>{%s textAreaFill %}</textarea>
<br/>
<br/><br/>
<label for="text">Edit description:</label>
<input id="text" type="text" name="message" class="edit-form__message">
<br/><br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/{%s hyphaName %}" class="edit-form__cancel">Cancel</a>
@ -88,7 +91,7 @@
{%= editScripts() %}
{% endfunc %}
{% func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) %}
{% func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, message, warning string, renderedPage string) %}
{%s= NavHTML(rq, hyphaName, "edit") %}
<div class="layout">
<main class="main-width edit edit_with-preview">
@ -97,7 +100,10 @@
<form method="post" class="edit-form"
action="/upload-text/{%s hyphaName %}">
<textarea class="edit-form__textarea" name="text">{%s textAreaFill %}</textarea>
<br/>
<br/><br/>
<label for="text">Edit description:</label>
<input id="text" type="text" name="message" class="edit-form__message" value="{%s message %}">
<br/><br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/{%s hyphaName %}" class="edit-form__cancel">Cancel</a>

View File

@ -204,191 +204,201 @@ func StreamEditHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, text
qw422016.E().S(textAreaFill)
//line views/mutators.qtpl:79
qw422016.N().S(`</textarea>
<br/>
<br/><br/>
<label for="text">Edit description:</label>
<input id="text" type="text" name="message" class="edit-form__message">
<br/><br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/`)
//line views/mutators.qtpl:83
//line views/mutators.qtpl:86
qw422016.E().S(hyphaName)
//line views/mutators.qtpl:83
//line views/mutators.qtpl:86
qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
</form>
</main>
`)
//line views/mutators.qtpl:86
//line views/mutators.qtpl:89
qw422016.N().S(Toolbar(user.FromRequest(rq)))
//line views/mutators.qtpl:86
//line views/mutators.qtpl:89
qw422016.N().S(`
</div>
`)
//line views/mutators.qtpl:88
//line views/mutators.qtpl:91
streameditScripts(qw422016)
//line views/mutators.qtpl:88
//line views/mutators.qtpl:91
qw422016.N().S(`
`)
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
}
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
func WriteEditHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) {
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
StreamEditHTML(qw422016, rq, hyphaName, textAreaFill, warning)
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
}
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) string {
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
WriteEditHTML(qb422016, rq, hyphaName, textAreaFill, warning)
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
qs422016 := string(qb422016.B)
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
return qs422016
//line views/mutators.qtpl:89
//line views/mutators.qtpl:92
}
//line views/mutators.qtpl:91
func StreamPreviewHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
//line views/mutators.qtpl:91
//line views/mutators.qtpl:94
func StreamPreviewHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, message, warning string, renderedPage string) {
//line views/mutators.qtpl:94
qw422016.N().S(`
`)
//line views/mutators.qtpl:92
//line views/mutators.qtpl:95
qw422016.N().S(NavHTML(rq, hyphaName, "edit"))
//line views/mutators.qtpl:92
//line views/mutators.qtpl:95
qw422016.N().S(`
<div class="layout">
<main class="main-width edit edit_with-preview">
<h1>Edit `)
//line views/mutators.qtpl:95
//line views/mutators.qtpl:98
qw422016.E().S(util.BeautifulName(hyphaName))
//line views/mutators.qtpl:95
//line views/mutators.qtpl:98
qw422016.N().S(` (preview)</h1>
`)
//line views/mutators.qtpl:96
//line views/mutators.qtpl:99
qw422016.N().S(warning)
//line views/mutators.qtpl:96
//line views/mutators.qtpl:99
qw422016.N().S(`
<form method="post" class="edit-form"
action="/upload-text/`)
//line views/mutators.qtpl:98
//line views/mutators.qtpl:101
qw422016.E().S(hyphaName)
//line views/mutators.qtpl:98
//line views/mutators.qtpl:101
qw422016.N().S(`">
<textarea class="edit-form__textarea" name="text">`)
//line views/mutators.qtpl:99
//line views/mutators.qtpl:102
qw422016.E().S(textAreaFill)
//line views/mutators.qtpl:99
//line views/mutators.qtpl:102
qw422016.N().S(`</textarea>
<br/>
<br/><br/>
<label for="text">Edit description:</label>
<input id="text" type="text" name="message" class="edit-form__message" value="`)
//line views/mutators.qtpl:105
qw422016.E().S(message)
//line views/mutators.qtpl:105
qw422016.N().S(`">
<br/><br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/`)
//line views/mutators.qtpl:103
//line views/mutators.qtpl:109
qw422016.E().S(hyphaName)
//line views/mutators.qtpl:103
//line views/mutators.qtpl:109
qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
</form>
<p class="warning">Note that the hypha is not saved yet. You can preview the changes </p>
<article class="edit__preview">`)
//line views/mutators.qtpl:106
//line views/mutators.qtpl:112
qw422016.N().S(renderedPage)
//line views/mutators.qtpl:106
//line views/mutators.qtpl:112
qw422016.N().S(`</article>
</main>
`)
//line views/mutators.qtpl:108
//line views/mutators.qtpl:114
qw422016.N().S(Toolbar(user.FromRequest(rq)))
//line views/mutators.qtpl:108
//line views/mutators.qtpl:114
qw422016.N().S(`
</div>
`)
//line views/mutators.qtpl:110
//line views/mutators.qtpl:116
streameditScripts(qw422016)
//line views/mutators.qtpl:110
//line views/mutators.qtpl:116
qw422016.N().S(`
`)
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
}
//line views/mutators.qtpl:111
func WritePreviewHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
func WritePreviewHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, message, warning string, renderedPage string) {
//line views/mutators.qtpl:117
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:111
StreamPreviewHTML(qw422016, rq, hyphaName, textAreaFill, warning, renderedPage)
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
StreamPreviewHTML(qw422016, rq, hyphaName, textAreaFill, message, warning, renderedPage)
//line views/mutators.qtpl:117
qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
}
//line views/mutators.qtpl:111
func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) string {
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, message, warning string, renderedPage string) string {
//line views/mutators.qtpl:117
qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:111
WritePreviewHTML(qb422016, rq, hyphaName, textAreaFill, warning, renderedPage)
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
WritePreviewHTML(qb422016, rq, hyphaName, textAreaFill, message, warning, renderedPage)
//line views/mutators.qtpl:117
qs422016 := string(qb422016.B)
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
return qs422016
//line views/mutators.qtpl:111
//line views/mutators.qtpl:117
}
//line views/mutators.qtpl:113
//line views/mutators.qtpl:119
func streameditScripts(qw422016 *qt422016.Writer) {
//line views/mutators.qtpl:113
//line views/mutators.qtpl:119
qw422016.N().S(`
`)
//line views/mutators.qtpl:114
//line views/mutators.qtpl:120
for _, scriptPath := range cfg.EditScripts {
//line views/mutators.qtpl:114
//line views/mutators.qtpl:120
qw422016.N().S(`
<script src="`)
//line views/mutators.qtpl:115
//line views/mutators.qtpl:121
qw422016.E().S(scriptPath)
//line views/mutators.qtpl:115
//line views/mutators.qtpl:121
qw422016.N().S(`"></script>
`)
//line views/mutators.qtpl:116
//line views/mutators.qtpl:122
}
//line views/mutators.qtpl:116
//line views/mutators.qtpl:122
qw422016.N().S(`
`)
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
}
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
func writeeditScripts(qq422016 qtio422016.Writer) {
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
streameditScripts(qw422016)
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
}
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
func editScripts() string {
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
writeeditScripts(qb422016)
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
qs422016 := string(qb422016.B)
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
return qs422016
//line views/mutators.qtpl:117
//line views/mutators.qtpl:123
}

View File

@ -173,13 +173,14 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
h = hyphae.ByName(hyphaName)
textData = rq.PostFormValue("text")
action = rq.PostFormValue("action")
message = rq.PostFormValue("message")
u = user.FromRequest(rq)
hop *history.HistoryOp
errtitle string
)
if action != "Preview" {
hop, errtitle = shroom.UploadText(h, []byte(textData), u)
hop, errtitle = shroom.UploadText(h, []byte(textData), message, u)
if hop.HasErrors() {
httpErr(w, http.StatusForbidden, hyphaName,
errtitle,
@ -199,6 +200,7 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
rq,
hyphaName,
textData,
message,
"",
mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx))),
u))