diff --git a/cmd/view/articles.go b/cmd/view/articles.go index 5626489..dd7ee65 100644 --- a/cmd/view/articles.go +++ b/cmd/view/articles.go @@ -155,6 +155,12 @@ func ShowRejectedArticles(db *model.DB, s *control.CookieStore) http.HandlerFunc func ReviewUnpublishedArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + type htmlData struct { + Article *model.Article + Tags []*model.Tag + } + data := new(htmlData) + id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64) if err != nil { log.Println(err) @@ -162,21 +168,35 @@ func ReviewUnpublishedArticle(db *model.DB, s *control.CookieStore) http.Handler return } - article, err := db.GetArticle(id) + data.Article, err = db.GetArticle(id) if err != nil { - tmpl, err := template.ParseFiles("web/templates/to-be-published.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", article) + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + data.Tags, err = db.GetArticleTags(id) + if err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) return } tmpl, err := template.ParseFiles("web/templates/to-be-published.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", article) + tmpl.ExecuteTemplate(w, "page-content", data) } } func ReviewRejectedArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + type htmlData struct { + Selected map[int64]bool + Article *model.Article + Tags []*model.Tag + } + data := new(htmlData) + id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64) if err != nil { log.Println(err) @@ -184,16 +204,34 @@ func ReviewRejectedArticle(db *model.DB, s *control.CookieStore) http.HandlerFun return } - article, err := db.GetArticle(id) + data.Article, err = db.GetArticle(id) if err != nil { - tmpl, err := template.ParseFiles("web/templates/to-be-published.html") - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", article) + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) return } + data.Tags, err = db.GetTagList() + if err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + selectedTags, err := db.GetArticleTags(id) + if err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + data.Selected = make(map[int64]bool) + for _, tag := range selectedTags { + data.Selected[tag.ID] = true + } + tmpl, err := template.ParseFiles("web/templates/rework-article.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", article) + tmpl.ExecuteTemplate(w, "page-content", data) } } diff --git a/web/templates/rework-article.html b/web/templates/rework-article.html index 2e81a6e..dfd836d 100644 --- a/web/templates/rework-article.html +++ b/web/templates/rework-article.html @@ -1,10 +1,16 @@ {{define "page-content"}}

Editor

- - - - + + + + + + {{range .Tags}} + + + {{end}} +
{{end}} diff --git a/web/templates/to-be-published.html b/web/templates/to-be-published.html index f3c3f46..7b42c70 100644 --- a/web/templates/to-be-published.html +++ b/web/templates/to-be-published.html @@ -1,11 +1,19 @@ {{define "page-content"}}
-

{{.Title}}

-

{{.Description}}

- {{.Content}} - +

{{.Article.Title}}

+

{{.Article.Description}}

+ {{.Article.Content}} + +

+ {{range .Tags}} + {{.Name}} + {{end}} +

+ +
+ {{end}}