Browse Source

Bugfixes and freedback addressing 2

master
Gisle Aune 7 years ago
parent
commit
60c6df5bbf
  1. 1
      formparser/parsers.go
  2. 25
      model/header.go
  3. 25
      model/page.go
  4. 1
      model/tag.go
  5. 3
      view/templates/index.tmpl
  6. 8
      view/templates/page/create.tmpl
  7. 8
      view/templates/page/edit.tmpl

1
formparser/parsers.go

@ -45,6 +45,7 @@ func Select(value string, target *string, allowedValues []string, optional bool)
func Date(value string, target *time.Time, optional bool) error {
if value == "" {
if optional {
*target = time.Time{}
return nil
}

25
model/header.go

@ -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 {

25
model/page.go

@ -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
model/tag.go

@ -17,6 +17,7 @@ var TagTypes = []string{
"Organization",
"Source",
"Series",
"Meta",
}
// Tag describes a tag

3
view/templates/index.tmpl

@ -8,10 +8,9 @@
<td class="pl-content">
<div class="plc-title"><a href="/page/{{.ID}}">{{.Name}}</a></div>
<div class="plc-meta">
<div class="plcm-date">{{.PublishDate | formatDate}}</div>
{{ if .Dated }}
<div class="plcm-date">{{.FictionalDate | formatDate}}</div>
{{ else }}
<div class="plcm-date">{{.PublishDate | formatDate}}</div>
{{ end }}
{{ if .PrimaryTag }}
<div class="plcm-tag {{.PrimaryTag.CSSCLass}}">{{.PrimaryTag.Name}}</div>

8
view/templates/page/create.tmpl

@ -5,7 +5,7 @@
<p class="danger">{{$.Error}}</p>
<input class="big" placeholder="Page Name" name="name" type="text" value="{{$.Page.Name}}" />
<textarea class="tall" placeholder="Content" name="source">{{$.Page.Source}}</textarea>
<input placeholder="IC Date" name="fictionalDate" type="text" value="{{if $.Page.FictionalDate.IsZero}}{{else}}{{$.Page.FictionalDate}}{{end}}" />
<input placeholder="IC Date (e.g. 'Oct 27, 2185')" name="fictionalDate" type="text" value="{{if $.Page.FictionalDate.IsZero}}{{else}}{{$.Page.FictionalDate}}{{end}}" />
<div class="group">
{{ range $.Categories }}
<div class="radio-wrapper">
@ -15,15 +15,9 @@
</div>
<textarea name="tags" placeholder="Tags, e.g. 'Location: Miner's Respite'. One per line, topmost is primary tag">{{$.TagInput}}</textarea>
<div class="group">
<div class="radio-wrapper">
<input type="checkbox" name="dated" value="true" {{if $.Page.Dated}}checked{{end}}><b> Dated</b>: The IC date is shown on the page list. It will still be used for sorting if this option is disabled.</input>
</div>
<div class="radio-wrapper">
<input type="checkbox" name="unlisted" value="true" {{if $.Page.Unlisted}}checked{{end}}><b> Unlisted</b>: This page will not show up on page lists, but anyone with a link can view it.</input>
</div>
<div class="radio-wrapper">
<input type="checkbox" name="specific" value="true" {{if $.Page.Specific}}checked{{end}}><b> Specific</b>: This page will only show up on page lists when one of its tags is searched for.</input>
</div>
</div>
<!-- Future option -->

8
view/templates/page/edit.tmpl

@ -5,7 +5,7 @@
<p class="danger">{{$.Error}}</p>
<input class="big" placeholder="Page Name" name="name" type="text" value="{{$.Page.Name}}" />
<textarea class="tall" placeholder="Content" name="source">{{$.Page.Source}}</textarea>
<input placeholder="IC Date" name="fictionalDate" type="text" value="{{if $.Page.FictionalDate.IsZero}}{{else}}{{$.Page.FictionalDate}}{{end}}" />
<input placeholder="IC Date (e.g. 'Oct 27, 2185')" name="fictionalDate" type="text" value="{{if $.Page.FictionalDate.IsZero}}{{else}}{{$.Page.FictionalDate}}{{end}}" />
<div class="group">
{{ range $.Categories }}
<div class="radio-wrapper">
@ -15,15 +15,9 @@
</div>
<textarea name="tags" placeholder="Tags, e.g. 'Location: Miner's Respite'. One per line, topmost is primary tag">{{$.TagInput}}</textarea>
<div class="group">
<div class="radio-wrapper">
<input type="checkbox" name="dated" value="true" {{if $.Page.Dated}}checked{{end}}><b> Dated</b>: The IC date is shown on the page list. It will still be used for sorting if this option is disabled.</input>
</div>
<div class="radio-wrapper">
<input type="checkbox" name="unlisted" value="true" {{if $.Page.Unlisted}}checked{{end}}><b> Unlisted</b>: This page will not show up on page lists, but anyone with a link can view it.</input>
</div>
<div class="radio-wrapper">
<input type="checkbox" name="specific" value="true" {{if $.Page.Specific}}checked{{end}}><b> Specific</b>: This page will only show up on page lists when one of its tags is searched for.</input>
</div>
</div>
<!-- Future option -->

Loading…
Cancel
Save