Added article list for written but non-published articles
This commit is contained in:
72
cmd/ui/articles.go
Normal file
72
cmd/ui/articles.go
Normal file
@ -0,0 +1,72 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/feeds"
|
||||
"streifling.com/jason/cpolis/cmd/data"
|
||||
)
|
||||
|
||||
func WriteArticle() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func FinishArticle(l *data.ArticleList) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
article := data.Article{}
|
||||
var err error
|
||||
|
||||
article.Title, err = data.ConvertToPlain(r.PostFormValue("editor-title"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
article.Desc, err = data.ConvertToPlain(r.PostFormValue("editor-desc"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
article.Content, err = data.ConvertToHTML(r.PostFormValue("editor-text"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
article.Created = time.Now()
|
||||
l.Add(article)
|
||||
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func PublishArticle(f *data.Feed, l *data.ArticleList, i int) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
article, ok := l.Release(i)
|
||||
if !ok {
|
||||
// TODO: Warnung anzeigen
|
||||
// data.Msg = "Alle Felder müssen ausgefüllt werden."
|
||||
// template.Must(template.ParseFiles("web/templates/add-user.html")).ExecuteTemplate(w, "page-content", data)
|
||||
return
|
||||
}
|
||||
|
||||
f.Add(&feeds.Item{
|
||||
Title: article.Title,
|
||||
Created: article.Created,
|
||||
Description: article.Desc,
|
||||
Content: article.Content,
|
||||
})
|
||||
f.Save("rss.gob")
|
||||
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/feeds"
|
||||
"streifling.com/jason/cpolis/cmd/data"
|
||||
)
|
||||
|
||||
func WriteArticle() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func FinishEdit(feed *data.Feed) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
title, err := data.ConvertToPlain(r.PostFormValue("editor-title"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
desc, err := data.ConvertToPlain(r.PostFormValue("editor-desc"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
content, err := data.ConvertToHTML(r.PostFormValue("editor-text"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
feed.Add(&feeds.Item{
|
||||
Title: title,
|
||||
Created: time.Now(),
|
||||
Description: desc,
|
||||
Content: content,
|
||||
})
|
||||
feed.Save("tmp/rss.gob")
|
||||
|
||||
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user