Added ability to reject and rework article
This commit is contained in:
parent
a1a6b6c29f
commit
f10220f936
@ -8,15 +8,15 @@ import (
|
|||||||
"streifling.com/jason/cpolis/cmd/model"
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetChannel(db *model.DB, title, link, desc string) (*rss.Channel, error) {
|
func GetChannel(db *model.DB, title, link, description string) (*rss.Channel, error) {
|
||||||
channel := &rss.Channel{
|
channel := &rss.Channel{
|
||||||
Title: title,
|
Title: title,
|
||||||
Link: link,
|
Link: link,
|
||||||
Description: desc,
|
Description: description,
|
||||||
Items: make([]*rss.Item, 0),
|
Items: make([]*rss.Item, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
articles, err := db.GetCertainArticles(true)
|
articles, err := db.GetCertainArticles(true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error fetching published articles: %v", err)
|
return nil, fmt.Errorf("error fetching published articles: %v", err)
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ func GetChannel(db *model.DB, title, link, desc string) (*rss.Channel, error) {
|
|||||||
Title: article.Title,
|
Title: article.Title,
|
||||||
Author: user.FirstName + user.LastName,
|
Author: user.FirstName + user.LastName,
|
||||||
PubDate: article.Created.Format(time.RFC1123Z),
|
PubDate: article.Created.Format(time.RFC1123Z),
|
||||||
Description: article.Desc,
|
Description: article.Description,
|
||||||
Content: &rss.Content{Value: article.Content},
|
Content: &rss.Content{Value: article.Content},
|
||||||
Categories: tagNames,
|
Categories: tagNames,
|
||||||
})
|
})
|
||||||
|
10
cmd/main.go
10
cmd/main.go
@ -47,7 +47,8 @@ func main() {
|
|||||||
|
|
||||||
mux.HandleFunc("GET /create-tag/", view.CreateTag)
|
mux.HandleFunc("GET /create-tag/", view.CreateTag)
|
||||||
mux.HandleFunc("GET /create-user/", view.CreateUser)
|
mux.HandleFunc("GET /create-user/", view.CreateUser)
|
||||||
mux.HandleFunc("GET /hub/", view.ShowHub(store))
|
mux.HandleFunc("GET /hub/", view.ShowHub(db, store))
|
||||||
|
mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(db, store))
|
||||||
mux.HandleFunc("GET /rss/", view.ShowRSS(
|
mux.HandleFunc("GET /rss/", view.ShowRSS(
|
||||||
db,
|
db,
|
||||||
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
||||||
@ -59,10 +60,13 @@ func main() {
|
|||||||
|
|
||||||
mux.HandleFunc("POST /add-tag/", view.AddTag(db, store))
|
mux.HandleFunc("POST /add-tag/", view.AddTag(db, store))
|
||||||
mux.HandleFunc("POST /add-user/", view.AddUser(db, store))
|
mux.HandleFunc("POST /add-user/", view.AddUser(db, store))
|
||||||
mux.HandleFunc("POST /finish-article/", view.FinishArticle(db, store))
|
|
||||||
mux.HandleFunc("POST /login/", view.Login(db, store))
|
mux.HandleFunc("POST /login/", view.Login(db, store))
|
||||||
mux.HandleFunc("POST /review-article/", view.ReviewArticle(db, store))
|
|
||||||
mux.HandleFunc("POST /publish-article/", view.PublishArticle(db, store))
|
mux.HandleFunc("POST /publish-article/", view.PublishArticle(db, store))
|
||||||
|
mux.HandleFunc("POST /reject-article/", view.RejectArticle(db, store))
|
||||||
|
mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(db, store))
|
||||||
|
mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(db, store))
|
||||||
|
mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(db, store))
|
||||||
|
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(db, store))
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,13 @@ import (
|
|||||||
func (db *DB) AddArticle(a *Article) (int64, error) {
|
func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO articles
|
INSERT INTO articles
|
||||||
(title, description, content, published, author_id)
|
(title, description, content, published, rejected, author_id)
|
||||||
VALUES
|
VALUES
|
||||||
(?, ?, ?, ?, ?)
|
(?, ?, ?, ?, ?, ?)
|
||||||
`
|
`
|
||||||
|
|
||||||
result, err := db.Exec(query, a.Title, a.Desc, a.Content, a.Published, a.AuthorID)
|
result, err := db.Exec(query, a.Title, a.Description, a.Content, a.Published,
|
||||||
|
a.Rejected, a.AuthorID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("error inserting article into DB: %v", err)
|
return 0, fmt.Errorf("error inserting article into DB: %v", err)
|
||||||
}
|
}
|
||||||
@ -37,7 +38,7 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
|||||||
var created []byte
|
var created []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err := row.Scan(&article.Title, &created, &article.Desc,
|
if err := row.Scan(&article.Title, &created, &article.Description,
|
||||||
&article.Content, &article.Published, &article.AuthorID); err != nil {
|
&article.Content, &article.Published, &article.AuthorID); err != nil {
|
||||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||||
}
|
}
|
||||||
@ -51,13 +52,14 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
|||||||
return article, nil
|
return article, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetCertainArticles(published bool) ([]*Article, error) {
|
func (db *DB) GetCertainArticles(published, rejected bool) ([]*Article, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT id, title, created, description, content, author_id
|
SELECT id, title, created, description, content, author_id
|
||||||
FROM articles
|
FROM articles
|
||||||
WHERE published = ?
|
WHERE published = ?
|
||||||
|
AND rejected = ?
|
||||||
`
|
`
|
||||||
rows, err := db.Query(query, published)
|
rows, err := db.Query(query, published, rejected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error querying articles: %v", err)
|
return nil, fmt.Errorf("error querying articles: %v", err)
|
||||||
}
|
}
|
||||||
@ -67,7 +69,7 @@ func (db *DB) GetCertainArticles(published bool) ([]*Article, error) {
|
|||||||
article := new(Article)
|
article := new(Article)
|
||||||
var created []byte
|
var created []byte
|
||||||
|
|
||||||
if err = rows.Scan(&article.ID, &article.Title, &created, &article.Desc,
|
if err = rows.Scan(&article.ID, &article.Title, &created, &article.Description,
|
||||||
&article.Content, &article.AuthorID); err != nil {
|
&article.Content, &article.AuthorID); err != nil {
|
||||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -79,14 +80,28 @@ func OpenDB(dbName string) (*DB, error) {
|
|||||||
return &db, nil
|
return &db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) UpdateAttribute(table string, id int64, attribute string, val interface{}) error {
|
func (db *DB) UpdateAttributes(a ...*Attribute) error {
|
||||||
query := fmt.Sprintf(`
|
tx, err := db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, attribute := range a {
|
||||||
|
query := fmt.Sprintf(`
|
||||||
UPDATE %s
|
UPDATE %s
|
||||||
SET %s = ?
|
SET %s = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`, table, attribute)
|
`, attribute.Table, attribute.AttName)
|
||||||
if _, err := db.Exec(query, val, id); err != nil {
|
if _, err := tx.Exec(query, attribute.Value, attribute.ID); err != nil {
|
||||||
return fmt.Errorf("error updating article in DB: %v", err)
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
log.Fatalf("error: transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("error updating article in DB: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("error committing transaction: %v", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
UserName string
|
UserName string
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
RejectedArticles []*Article
|
ID int64
|
||||||
ID int64
|
Role int
|
||||||
Role int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
@ -25,11 +24,19 @@ type Tag struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Article struct {
|
type Article struct {
|
||||||
Title string
|
Title string
|
||||||
Created time.Time
|
Created time.Time
|
||||||
Desc string
|
Description string
|
||||||
Content string
|
Content string
|
||||||
Published bool
|
Published bool
|
||||||
ID int64
|
Rejected bool
|
||||||
AuthorID int64
|
ID int64
|
||||||
|
AuthorID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Attribute struct {
|
||||||
|
Value interface{}
|
||||||
|
Table string
|
||||||
|
AttName string
|
||||||
|
ID int64
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"streifling.com/jason/cpolis/cmd/model"
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ShowHub(s *control.CookieStore) http.HandlerFunc {
|
func ShowHub(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -20,7 +20,7 @@ func ShowHub(s *control.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"])
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,32 +38,8 @@ func WriteArticle(db *model.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FinishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
func SubmitArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
article := new(model.Article)
|
|
||||||
var err error
|
|
||||||
|
|
||||||
article.Title, err = control.ConvertToPlain(r.PostFormValue("editor-title"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
article.Desc, err = control.ConvertToPlain(r.PostFormValue("editor-desc"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
article.Content, err = control.ConvertToHTML(r.PostFormValue("editor-text"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||||
@ -71,7 +47,15 @@ func FinishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
article.AuthorID = session.Values["id"].(int64)
|
article := &model.Article{
|
||||||
|
Title: r.PostFormValue("article-title"),
|
||||||
|
Description: r.PostFormValue("article-description"),
|
||||||
|
Content: r.PostFormValue("article-content"),
|
||||||
|
Published: false,
|
||||||
|
Rejected: false,
|
||||||
|
AuthorID: session.Values["id"].(int64),
|
||||||
|
}
|
||||||
|
|
||||||
article.ID, err = db.AddArticle(article)
|
article.ID, err = db.AddArticle(article)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -102,20 +86,74 @@ func FinishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowUnpublishedArticles(db *model.DB) http.HandlerFunc {
|
func ResubmitArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
articles, err := db.GetCertainArticles(false)
|
id, err := strconv.ParseInt(r.PostFormValue("article-id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tmpl, err := template.ParseFiles("web/templates/unpublished-articles.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles)
|
title := r.PostFormValue("article-title")
|
||||||
|
description := r.PostFormValue("article-description")
|
||||||
|
content := r.PostFormValue("article-content")
|
||||||
|
|
||||||
|
if err := db.UpdateAttributes(
|
||||||
|
&model.Attribute{Table: "articles", ID: id, AttName: "title", Value: title},
|
||||||
|
&model.Attribute{Table: "articles", ID: id, AttName: "description", Value: description},
|
||||||
|
&model.Attribute{Table: "articles", ID: id, AttName: "content", Value: content},
|
||||||
|
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
||||||
|
); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session, err := s.Get(r, "cookie")
|
||||||
|
if err != nil {
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||||
|
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
||||||
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReviewArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
func ShowUnpublishedArticles(db *model.DB) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
unpublishedArticles, err := db.GetCertainArticles(false, false)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/unpublished-articles.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", unpublishedArticles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShowRejectedArticles(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
rejectedArticles, err := db.GetCertainArticles(false, true)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/rejected-articles.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", rejectedArticles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReviewUnpublishedArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -131,19 +169,34 @@ func ReviewArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// session, err := s.Get(r, "cookie")
|
|
||||||
// if err != nil {
|
|
||||||
// tmpl, err := template.ParseFiles("web/templates/login.html")
|
|
||||||
// msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
|
||||||
// template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
|
||||||
// }
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/to-be-published.html")
|
tmpl, err := template.ParseFiles("web/templates/to-be-published.html")
|
||||||
tmpl = template.Must(tmpl, err)
|
tmpl = template.Must(tmpl, err)
|
||||||
tmpl.ExecuteTemplate(w, "page-content", article)
|
tmpl.ExecuteTemplate(w, "page-content", article)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReviewRejectedArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/rework-article.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", article)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func PublishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
func PublishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
||||||
@ -160,7 +213,36 @@ func PublishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.UpdateAttribute("articles", id, "published", true)
|
db.UpdateAttributes(
|
||||||
|
&model.Attribute{Table: "articles", ID: id, AttName: "published", Value: true},
|
||||||
|
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
|
||||||
|
)
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RejectArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session, err := s.Get(r, "cookie")
|
||||||
|
if err != nil {
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||||
|
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
||||||
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
db.UpdateAttributes(
|
||||||
|
&model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: true},
|
||||||
|
)
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
tmpl = template.Must(tmpl, err)
|
tmpl = template.Must(tmpl, err)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.streifling.com/jason/rss"
|
"git.streifling.com/jason/rss"
|
||||||
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
"streifling.com/jason/cpolis/cmd/model"
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ func ShowRSS(db *model.DB, title, link, desc string) http.HandlerFunc {
|
|||||||
Items: make([]*rss.Item, 0),
|
Items: make([]*rss.Item, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
articles, err := db.GetCertainArticles(true)
|
articles, err := db.GetCertainArticles(true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
@ -45,12 +46,33 @@ func ShowRSS(db *model.DB, title, link, desc string) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
articleTitle, err := control.ConvertToPlain(article.Title)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
articleDescription, err := control.ConvertToPlain(article.Description)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
articleContent, err := control.ConvertToHTML(article.Content)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
channel.Items = append(channel.Items, &rss.Item{
|
channel.Items = append(channel.Items, &rss.Item{
|
||||||
Title: article.Title,
|
Title: articleTitle,
|
||||||
Author: user.FirstName + user.LastName,
|
Author: user.FirstName + user.LastName,
|
||||||
PubDate: article.Created.Format(time.RFC1123Z),
|
PubDate: article.Created.Format(time.RFC1123Z),
|
||||||
Description: article.Desc,
|
Description: articleDescription,
|
||||||
Content: &rss.Content{Value: article.Content},
|
Content: &rss.Content{Value: articleContent},
|
||||||
Categories: tagNames,
|
Categories: tagNames,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Editor</h2>
|
<h2>Editor</h2>
|
||||||
<form>
|
<form>
|
||||||
<input name="editor-title" placeholder="Titel" type="text" />
|
<input name="article-title" placeholder="Titel" type="text" />
|
||||||
<textarea name="editor-desc" placeholder="Beschreibung"></textarea>
|
<textarea name="article-description" placeholder="Beschreibung"></textarea>
|
||||||
<textarea name="editor-text" placeholder="Artikel"></textarea>
|
<textarea name="article-content" placeholder="Artikel"></textarea>
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<input id="{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" />
|
<input id="{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" />
|
||||||
<label for="{{.Name}}">{{.Name}}</label>
|
<label for="{{.Name}}">{{.Name}}</label>
|
||||||
{{end}}
|
{{end}}
|
||||||
<input type="submit" value="Senden" hx-post="/finish-article/" hx-target="#page-content" />
|
<input type="submit" value="Senden" hx-post="/submit-article/" hx-target="#page-content" />
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "html-result"}}
|
|
||||||
{{.}}
|
|
||||||
{{end}}
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Hub</h2>
|
<h2>Hub</h2>
|
||||||
<button hx-get="/write-article/" hx-target="#page-content">Artikel schreiben</button>
|
<button hx-get="/write-article/" hx-target="#page-content">Artikel schreiben</button>
|
||||||
|
<button hx-get="/rejected-articles/" hx-target="#page-content">Abgelehnte Artikel</button>
|
||||||
<button hx-get="/rss/" hx-target="#page-content">RSS Feed</button>
|
<button hx-get="/rss/" hx-target="#page-content">RSS Feed</button>
|
||||||
{{if lt . 2}}
|
{{if lt . 2}}
|
||||||
<button hx-get="/unpublished-articles/" hx-target="#page-content">Unveröffentlichte Artikel</button>
|
<button hx-get="/unpublished-articles/" hx-target="#page-content">Unveröffentlichte Artikel</button>
|
||||||
|
10
web/templates/rejected-articles.html
Normal file
10
web/templates/rejected-articles.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<form>
|
||||||
|
{{range .}}
|
||||||
|
<input required id="{{.ID}}" name="id" type="radio" value="{{.ID}}" />
|
||||||
|
<label for="{{.ID}}">{{.Title}}</label>
|
||||||
|
{{end}}
|
||||||
|
<input type="submit" value="Auswählen" hx-post="/review-rejected-article/" hx-target="#page-content" />
|
||||||
|
</form>
|
||||||
|
<button hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
||||||
|
{{end}}
|
10
web/templates/rework-article.html
Normal file
10
web/templates/rework-article.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<h2>Editor</h2>
|
||||||
|
<form>
|
||||||
|
<input name="article-title" placeholder="Titel" type="text" value="{{.Title}}" />
|
||||||
|
<textarea name="article-description" placeholder="Beschreibung">{{.Description}}</textarea>
|
||||||
|
<textarea name="article-content" placeholder="Artikel">{{.Content}}</textarea>
|
||||||
|
<input name="article-id" type="hidden" value="{{.ID}}" />
|
||||||
|
<input type="submit" value="Senden" hx-post="/resubmit-article/" hx-target="#page-content" />
|
||||||
|
</form>
|
||||||
|
{{end}}
|
@ -1,8 +1,8 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<form>
|
<form>
|
||||||
<h2>{{.Title}}</h2>
|
<h2>{{.Title}}</h2>
|
||||||
<p>{{.Desc}}</p>
|
<p>{{.Description}}</p>
|
||||||
<span>{{.Content}}</span>
|
{{.Content}}
|
||||||
<input name="id" type="hidden" value="{{.ID}}" />
|
<input name="id" type="hidden" value="{{.ID}}" />
|
||||||
<input type="submit" value="Veröffentlichen" hx-post="/publish-article/" hx-target="#page-content" />
|
<input type="submit" value="Veröffentlichen" hx-post="/publish-article/" hx-target="#page-content" />
|
||||||
<input type="submit" value="Ablehnen" hx-post="/reject-article/" hx-target="#page-content" />
|
<input type="submit" value="Ablehnen" hx-post="/reject-article/" hx-target="#page-content" />
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<input required id="{{.ID}}" name="id" type="radio" value="{{.ID}}" />
|
<input required id="{{.ID}}" name="id" type="radio" value="{{.ID}}" />
|
||||||
<label for="{{.ID}}">{{.Title}}</label>
|
<label for="{{.ID}}">{{.Title}}</label>
|
||||||
{{end}}
|
{{end}}
|
||||||
<input type="submit" value="Auswählen" hx-post="/review-article/" hx-target="#page-content" />
|
<input type="submit" value="Auswählen" hx-post="/review-unpublished-article/" hx-target="#page-content" />
|
||||||
</form>
|
</form>
|
||||||
<button hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
<button hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user