Massive overhaul, fixing menus and changing template engine. Added /month/ and /author/ filters
This commit is contained in:
+6
-5
@@ -9,6 +9,7 @@ type PageCategory struct {
|
||||
Key string
|
||||
Plural string
|
||||
Icon string
|
||||
Path string
|
||||
Info string
|
||||
}
|
||||
|
||||
@@ -22,12 +23,12 @@ func (category *PageCategory) URLRoot() string {
|
||||
// or the database, but for now I think this list is pretty fixed
|
||||
var PageCategories = []PageCategory{
|
||||
//{"OoC", "OoC", "O", "OoC content is for announcements, scheduling, general information, or anything that is not in-universe"},
|
||||
{"Info", "Info", "i", "Information relevant to RP that might be something looked for in IRC logs"},
|
||||
{"News", "News", "N", "News stories that might be pertinent to ongoing plots"},
|
||||
{"Info", "Info", "i", "/info/", "Information relevant to RP that might be something looked for in IRC logs"},
|
||||
{"News", "News", "N", "/news/", "News stories that might be pertinent to ongoing plots"},
|
||||
//{"Item", "Items", "I", "Items relevant to plots, that is more than just a document saved on a character's own omni-tool"},
|
||||
{"Document", "Documents", "D", "Data files, shadow broker dossiers, and other data that is not inside an item"},
|
||||
{"Background", "Background", "B", "Rumors, suspicious persons, or inter-RP occurences that may be noticed"},
|
||||
{"Story", "Stories", "S", "Background stories and inter-RP character intearactions"},
|
||||
{"Document", "Documents", "D", "/documents/", "Data files, shadow broker dossiers, and other data that is not inside an item"},
|
||||
{"Background", "Background", "B", "/background/", "Rumors, suspicious persons, or inter-RP occurences that may be noticed"},
|
||||
{"Story", "Stories", "S", "/stories/", "Background stories and inter-RP character intearactions"},
|
||||
}
|
||||
var pageCategories []string
|
||||
|
||||
|
||||
+73
-1
@@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/AiteRP/aitestory/server"
|
||||
@@ -34,7 +35,12 @@ func (header *Header) CategoryInfo() PageCategory {
|
||||
}
|
||||
}
|
||||
|
||||
return PageCategory{"Unknown", "Unknown", "?", ""}
|
||||
return PageCategory{"Unknown", "Unknown", "?", "/", ""}
|
||||
}
|
||||
|
||||
// Path returns the path for viewing the page
|
||||
func (header *Header) Path() string {
|
||||
return fmt.Sprintf("/page/%s", header.ID)
|
||||
}
|
||||
|
||||
// ListHeaders grabs all the general pages from
|
||||
@@ -104,6 +110,72 @@ func ListHeadersByCategory(category string) ([]Header, error) {
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// ListHeadersByAuthor grabs all the pages by the given author
|
||||
func ListHeadersByAuthor(author string) ([]Header, error) {
|
||||
const query = `
|
||||
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.author = ?
|
||||
ORDER BY page.publish_date DESC
|
||||
`
|
||||
|
||||
db := server.Main.DB
|
||||
|
||||
rows, err := db.Query(query, author)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
results := make([]Header, 0, 64)
|
||||
header := Header{}
|
||||
for rows.Next() {
|
||||
err := parseHeader(&header, rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results = append(results, header)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// ListHeadersByMonth grabs all the pages within the given month
|
||||
func ListHeadersByMonth(year int, month int) ([]Header, error) {
|
||||
const query = `
|
||||
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 YEAR(fictional_date) = ? AND MONTH(fictional_date) = ?
|
||||
ORDER BY page.publish_date DESC
|
||||
`
|
||||
|
||||
db := server.Main.DB
|
||||
|
||||
rows, err := db.Query(query, year, month)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
results := make([]Header, 0, 64)
|
||||
header := Header{}
|
||||
for rows.Next() {
|
||||
err := parseHeader(&header, rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results = append(results, header)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// ListHeadersByTag lists all headers that has the tag. Leave the category empty
|
||||
// to not filter by it
|
||||
func ListHeadersByTag(category string, tag *Tag) ([]Header, error) {
|
||||
|
||||
+6
-1
@@ -139,7 +139,7 @@ func (page *Page) Update() error {
|
||||
}
|
||||
|
||||
// Stop now if the tages haven't changed
|
||||
if len(page.prevTags) == len(page.Tags) {
|
||||
if len(page.Tags) > 0 && len(page.prevTags) == len(page.Tags) {
|
||||
change := false
|
||||
|
||||
for i, tag := range page.prevTags {
|
||||
@@ -265,6 +265,11 @@ func (page *Page) ParseForm(form url.Values) []error {
|
||||
return errors
|
||||
}
|
||||
|
||||
// OpPath gets a path associated with a specific operation on this page.
|
||||
func (page *Page) OpPath(op string) string {
|
||||
return fmt.Sprintf("/page/%s/%s", op, page.ID)
|
||||
}
|
||||
|
||||
// Standardize page ID generation
|
||||
func (page *Page) generateID() {
|
||||
page.ID = generate.FriendlyID(16)
|
||||
|
||||
+17
-4
@@ -18,6 +18,15 @@ var TagTypes = []string{
|
||||
"Series",
|
||||
}
|
||||
|
||||
// TagTitles are the titles to use when listing tags
|
||||
var TagTitles = map[string]string{
|
||||
"Location": "Locations",
|
||||
"Character": "Characters",
|
||||
"Event": "Plots & Events",
|
||||
"Organization": "Organizations",
|
||||
"Series": "Series",
|
||||
}
|
||||
|
||||
// Tag describes a tag
|
||||
type Tag struct {
|
||||
ID string
|
||||
@@ -121,10 +130,14 @@ func (tag *Tag) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Hook returns the url friendly name, which is pretty much just
|
||||
// adding underscores to it.
|
||||
func (tag Tag) Hook() string {
|
||||
return strings.Replace(tag.Name, " ", "_", -1)
|
||||
// Path returns a path used for the tag's list page
|
||||
func (tag Tag) Path() string {
|
||||
return fmt.Sprintf("/%s/%s", strings.ToLower(tag.Type), strings.Replace(tag.Name, " ", "_", -1))
|
||||
}
|
||||
|
||||
// CSSClass gets the tag's css class, which determines its color.
|
||||
func (tag Tag) CSSClass() string {
|
||||
return fmt.Sprintf("ttype-%s", strings.ToLower(tag.Type))
|
||||
}
|
||||
|
||||
// FindTag finds a tag by ID. Leave tagtype blank to ignore it. Both key and
|
||||
|
||||
Reference in New Issue
Block a user