Bugfixes and freedback addressing 2

This commit is contained in:
2017-10-11 08:14:17 +02:00
parent e31d994d4b
commit 60c6df5bbf
7 changed files with 32 additions and 39 deletions
+14 -11
View File
@@ -19,10 +19,13 @@ type Header struct {
FictionalDate time.Time `json:"fictionalDate"`
PublishDate time.Time `json:"publishDate"`
EditDate time.Time `json:"editDate"`
Dated bool `json:"dated"`
PrimaryTag *Tag `json:"primaryTag"`
}
func (header *Header) Dated() bool {
return !header.FictionalDate.IsZero()
}
// CategoryInfo gets information about the category
func (header *Header) CategoryInfo() PageCategory {
for _, category := range PageCategories {
@@ -38,12 +41,12 @@ func (header *Header) CategoryInfo() PageCategory {
// the database to list them
func ListHeaders() ([]Header, error) {
const query = `
SELECT page.id,page.name,author,category,fictional_date,publish_date,edit_date,dated,tag.id,tag.type,tag.name
SELECT page.id,page.name,author,category,fictional_date,publish_date,edit_date,tag.id,tag.type,tag.name
FROM page
LEFT JOIN page_tag ON (page.id = page_tag.page_id AND page_tag.primary = true)
LEFT JOIN tag ON (tag.id = page_tag.tag_id)
WHERE page.specific=false AND page.published=true AND page.unlisted=false
ORDER BY page.fictional_date DESC
ORDER BY page.publish_date DESC
`
db := server.Main.DB
@@ -71,12 +74,12 @@ func ListHeaders() ([]Header, error) {
// ListHeadersByCategory grabs all the pages in the given category
func ListHeadersByCategory(category string) ([]Header, error) {
const query = `
SELECT page.id,page.name,author,category,fictional_date,publish_date,edit_date,dated,tag.id,tag.type,tag.name
SELECT page.id,page.name,author,category,fictional_date,publish_date,edit_date,tag.id,tag.type,tag.name
FROM page
LEFT JOIN page_tag ON (page.id = page_tag.page_id AND page_tag.primary = true)
LEFT JOIN tag ON (tag.id = page_tag.tag_id)
WHERE page.specific=false AND page.published=true AND page.unlisted=false AND page.category = ?
ORDER BY page.fictional_date DESC
ORDER BY page.publish_date DESC
`
db := server.Main.DB
@@ -105,22 +108,22 @@ func ListHeadersByCategory(category string) ([]Header, error) {
// to not filter by it
func ListHeadersByTag(category string, tag *Tag) ([]Header, error) {
const query1 = `
SELECT page.id,page.name,page.author,page.category,page.fictional_date,page.publish_date,page.edit_date,page.dated,tag.id,tag.type,tag.name
SELECT page.id,page.name,page.author,page.category,page.fictional_date,page.publish_date,page.edit_date,tag.id,tag.type,tag.name
FROM page_tag
RIGHT JOIN page ON page.id = page_tag.page_id
LEFT JOIN (page_tag AS pt2) ON (page.id = pt2.page_id AND pt2.primary = true)
LEFT JOIN (tag AS tag) ON (tag.id = pt2.tag_id)
WHERE page_tag.tag_id=? AND page.unlisted=false AND page.published=true
ORDER BY page.fictional_date DESC
ORDER BY page.publish_date DESC
`
const query2 = `
SELECT page.id,page.name,page.author,page.category,page.fictional_date,page.publish_date,page.edit_date,page.dated,tag.id,tag.type,tag.name
SELECT page.id,page.name,page.author,page.category,page.fictional_date,page.publish_date,page.edit_date,tag.id,tag.type,tag.name
FROM page_tag
RIGHT JOIN page ON page.id = page_tag.page_id
LEFT JOIN (page_tag AS pt2) ON (page.id = pt2.page_id AND pt2.primary = true)
LEFT JOIN (tag AS tag) ON (tag.id = pt2.tag_id)
WHERE page_tag.tag_id=? AND page.category=? AND page.unlisted=false AND page.published=true
ORDER BY page.fictional_date DESC
ORDER BY page.publish_date DESC
`
if tag == nil {
@@ -203,7 +206,7 @@ func parseHeader(header *Header, rows *sql.Rows) error {
var fictionalDate, publishDate, editDate string
var err error
rows.Scan(&header.ID, &header.Name, &header.Author, &header.Category, &fictionalDate, &publishDate, &editDate, &header.Dated, &tagID, &tagType, &tagName)
rows.Scan(&header.ID, &header.Name, &header.Author, &header.Category, &fictionalDate, &publishDate, &editDate, &tagID, &tagType, &tagName)
if tagID != "" {
header.PrimaryTag = &Tag{tagID, tagType, tagName}
} else {
@@ -212,7 +215,7 @@ func parseHeader(header *Header, rows *sql.Rows) error {
header.FictionalDate, err = time.Parse("2006-01-02 15:04:05", fictionalDate)
if err != nil {
return err
header.FictionalDate = time.Time{}
}
header.PublishDate, err = time.Parse("2006-01-02 15:04:05", publishDate)
if err != nil {
+13 -12
View File
@@ -35,7 +35,6 @@ type Page struct {
FictionalDate time.Time `json:"fictionalDate"`
PublishDate time.Time `json:"publishDate"`
EditDate time.Time `json:"editDate"`
Dated bool `json:"dated"`
Published bool `json:"published"`
Unlisted bool `json:"unlisted"`
Specific bool `json:"specific"`
@@ -50,11 +49,14 @@ type Page struct {
primaryTag *Tag
}
func (page *Page) Dated() bool {
return !page.FictionalDate.IsZero()
}
// Defaults fills in the default details for a page, suited for populating a form
func (page *Page) Defaults() {
page.Category = PageCategories[0].Key
page.Dated = true
page.Published = true
page.Unlisted = false
page.Specific = false
@@ -70,9 +72,9 @@ func (page *Page) Insert() error {
const insertPage = `
INSERT INTO page (
id, name, author, category, fictional_date,
publish_date, edit_date, dated, published,
publish_date, edit_date, published,
unlisted, page.specific, indexed, type, source
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
`
const insertTag = `INSERT INTO page_tag (page_id,tag_id,page_tag.primary) VALUES (?, ?, ?)`
@@ -85,7 +87,7 @@ func (page *Page) Insert() error {
// Do the thing
_, err := db.Exec(insertPage,
page.ID, page.Name, page.Author, page.Category, page.FictionalDate, page.PublishDate,
page.EditDate, page.Dated, page.Published, page.Unlisted, page.Specific, page.Indexed,
page.EditDate, page.Published, page.Unlisted, page.Specific, page.Indexed,
page.Type, page.Source,
)
if err != nil {
@@ -113,7 +115,7 @@ func (page *Page) Update() error {
const updatePage = `
UPDATE page SET
name=?,category=?,fictional_date=?,publish_date=?,
edit_date=?,dated=?,published=?,unlisted=?,page.specific=?,
edit_date=?,published=?,unlisted=?,page.specific=?,
indexed=?,type=?,source=?
WHERE id=?
`
@@ -129,7 +131,7 @@ func (page *Page) Update() error {
// Do the thing
_, err := db.Exec(updatePage,
page.Name, page.Category, page.FictionalDate, page.PublishDate,
page.EditDate, page.Dated, page.Published, page.Unlisted, page.Specific, page.Indexed,
page.EditDate, page.Published, page.Unlisted, page.Specific, page.Indexed,
page.Type, page.Source, page.ID,
)
if err != nil {
@@ -231,12 +233,11 @@ func (page *Page) ParseForm(form url.Values) []error {
errors = append(errors, fmt.Errorf("Category: %s", err))
}
err = formparser.Date(form.Get("fictionalDate"), &page.FictionalDate, !page.FictionalDate.IsZero())
err = formparser.Date(form.Get("fictionalDate"), &page.FictionalDate, true)
if err != nil {
errors = append(errors, fmt.Errorf("Fictonal Date: %s", err))
}
page.Dated = form.Get("dated") != ""
page.Published = form.Get("published") != ""
page.Unlisted = form.Get("unlisted") != ""
page.Specific = form.Get("specific") != ""
@@ -273,7 +274,7 @@ func (page *Page) generateID() {
// listning pages
func FindPage(id string) (*Page, error) {
const selectPage = `
SELECT id,name,author,category,fictional_date,publish_date,edit_date,dated,published,
SELECT id,name,author,category,fictional_date,publish_date,edit_date,published,
unlisted,page.specific,indexed,type,source,background_url
FROM page
WHERE id=?
@@ -331,7 +332,7 @@ func parsePage(page *Page, rows *sql.Rows) error {
err := rows.Scan(
&page.ID, &page.Name, &page.Author, &page.Category, &fictionalDate,
&publishDate, &editDate, &page.Dated, &page.Published, &page.Unlisted,
&publishDate, &editDate, &page.Published, &page.Unlisted,
&page.Specific, &page.Indexed, &page.Type, &page.Source, &bgURL,
)
if err != nil {
@@ -344,7 +345,7 @@ func parsePage(page *Page, rows *sql.Rows) error {
page.FictionalDate, err = time.Parse("2006-01-02 15:04:05", fictionalDate)
if err != nil {
return err
page.FictionalDate = time.Time{}
}
page.PublishDate, err = time.Parse("2006-01-02 15:04:05", publishDate)
if err != nil {
+1
View File
@@ -17,6 +17,7 @@ var TagTypes = []string{
"Organization",
"Source",
"Series",
"Meta",
}
// Tag describes a tag