allow draft publish + view drafts as author
This commit is contained in:
parent
9e64672f9c
commit
42d960f185
|
@ -6,6 +6,10 @@
|
|||
<br>
|
||||
<br>
|
||||
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
{{.}}
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
|
||||
|
||||
{{end}}
|
|
@ -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}}
|
|
@ -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}}
|
||||
|
|
|
@ -75,7 +75,12 @@ func (h *EditorHandler) HandlePostNew(c *fiber.Ctx) error {
|
|||
// create entry
|
||||
now := time.Now()
|
||||
entry.SetMetaData(entryMeta)
|
||||
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,11 @@ func (h *EditorHandler) HandlePostEdit(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
published := c.FormValue("action") == "Publish"
|
||||
if !published {
|
||||
entry.SetPublishedAt(nil)
|
||||
}
|
||||
|
||||
// update entry
|
||||
entry.SetMetaData(meta)
|
||||
err = h.entrySvc.Update(entry)
|
||||
|
|
|
@ -39,15 +39,19 @@ 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 !loggedIn {
|
||||
if entry.PublishedAt() == nil || entry.PublishedAt().IsZero() {
|
||||
return fiber.NewError(fiber.StatusNotFound, "Entry not found")
|
||||
}
|
||||
}
|
||||
|
||||
author, err := h.authorSvc.FindByName(entry.AuthorId())
|
||||
if err != nil {
|
||||
|
@ -61,7 +65,7 @@ func (h *EntryHandler) Handle(c *fiber.Ctx) error {
|
|||
entryData{
|
||||
Entry: entry,
|
||||
Author: author,
|
||||
LoggedIn: c.Locals("author") != nil,
|
||||
LoggedIn: loggedIn,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue