Compare commits

...

2 Commits

Author SHA1 Message Date
Niko Abeler 70902af7e0 publishing in edit 2023-08-05 10:15:08 +02:00
Niko Abeler 42d960f185 allow draft publish + view drafts as author 2023-08-05 10:14:05 +02:00
6 changed files with 40 additions and 7 deletions

View File

@ -6,6 +6,10 @@
<br>
<br>
<form method="POST" enctype="multipart/form-data">
{{.}}
<input type="submit" value="Submit" />
</form>
{{end}}

View File

@ -6,6 +6,13 @@
<br>
<br>
<form method="POST" enctype="multipart/form-data">
{{.}}
<div class="grid">
<input type="submit" name="action" value="Publish" />
<input class="secondary" type="submit" name="action" value="Save as Draft" />
</div>
</form>
{{end}}

View File

@ -2,6 +2,14 @@
{{define "main"}}
{{ if not .Entry.PublishedAt }}
<mark>
This entry is a draft. It is only visible to logged in authors.
</mark>
<br>
<br>
{{ end }}
<div class="h-entry">
<hgroup>
{{if .Entry.Title}}

View File

@ -75,7 +75,12 @@ func (h *EditorHandler) HandlePostNew(c *fiber.Ctx) error {
// create entry
now := time.Now()
entry.SetMetaData(entryMeta)
entry.SetPublishedAt(&now)
published := c.FormValue("action") == "Publish"
if published {
entry.SetPublishedAt(&now)
} else {
entry.SetPublishedAt(nil)
}
entry.SetAuthorId(c.Locals("author").(string))
err = h.entrySvc.Create(entry)
@ -119,6 +124,13 @@ func (h *EditorHandler) HandlePostEdit(c *fiber.Ctx) error {
return err
}
published := c.FormValue("action") == "Publish"
if !published {
entry.SetPublishedAt(nil)
} else if entry.PublishedAt() == nil || entry.PublishedAt().IsZero() {
now := time.Now()
entry.SetPublishedAt(&now)
}
// update entry
entry.SetMetaData(meta)
err = h.entrySvc.Update(entry)

View File

@ -39,14 +39,18 @@ func NewEntryHandler(
func (h *EntryHandler) Handle(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
loggedIn := c.Locals("author") != nil
entryId := c.Params("post")
entry, err := h.entrySvc.FindById(entryId)
if err != nil {
return err
}
if entry.PublishedAt() == nil || entry.PublishedAt().IsZero() {
return fiber.NewError(fiber.StatusNotFound, "Entry not found")
if !loggedIn {
if entry.PublishedAt() == nil || entry.PublishedAt().IsZero() {
return fiber.NewError(fiber.StatusNotFound, "Entry not found")
}
}
author, err := h.authorSvc.FindByName(entry.AuthorId())
@ -61,7 +65,7 @@ func (h *EntryHandler) Handle(c *fiber.Ctx) error {
entryData{
Entry: entry,
Author: author,
LoggedIn: c.Locals("author") != nil,
LoggedIn: loggedIn,
},
)
}

View File

@ -107,12 +107,10 @@ func (s *Form) HtmlForm() (string, error) {
return "", err
}
html := "<form method=\"POST\" enctype=\"multipart/form-data\">\n"
html := ""
for _, field := range fields {
html += field.Html()
}
html += "<input type=\"submit\" value=\"Submit\" />\n"
html += "</form>\n"
return html, nil
}