prep for saving post
This commit is contained in:
parent
9ca8deed23
commit
f7b74041d7
|
@ -120,17 +120,22 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
re := regexp.MustCompile("< *[Tt][Ii][Tt][Ll][Ee] *>(.*)</ *[Tt][Ii][Tt][Ll][Ee] *>")
|
re := regexp.MustCompile("< *[Tt][Ii][Tt][Ll][Ee] *>(.*)</ *[Tt][Ii][Tt][Ll][Ee] *>")
|
||||||
title := re.FindStringSubmatch(string(body))
|
title := re.FindStringSubmatch(string(body))
|
||||||
if title != nil {
|
if title != nil {
|
||||||
ShowTemplate("add", w, map[string]interface{}{"user": user, "link": url, "tags": tags.Tags, "title": strings.TrimSpace(title[1])})
|
ShowTemplate("add", w, map[string]interface{}{"user": user, "link": url, "tags": tags.TagsTree, "title": strings.TrimSpace(title[1])})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowTemplate("add", w, map[string]interface{}{"user": user, "link": url, "tags": tags.Tags})
|
ShowTemplate("add", w, map[string]interface{}{"user": user, "link": url, "tags": tags.TagsTree})
|
||||||
}
|
}
|
||||||
|
|
||||||
func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
|
|
||||||
|
//.Name = r.FormValue("name")
|
||||||
|
//desc := r.FormValue("desc")
|
||||||
|
//pid, perr := strconv.Atoi(r.FormValue("pid"))
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
|
|
19
tags/tags.go
19
tags/tags.go
|
@ -13,18 +13,19 @@ type Tag struct {
|
||||||
Children []*Tag
|
Children []*Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
var Tags []*Tag
|
var TagsTree []*Tag
|
||||||
|
var TagsFlat map[int]*Tag
|
||||||
|
|
||||||
|
// Cavet: slight cheat. All parents must have tag_id < their children.
|
||||||
func LoadTags(db *sql.DB) {
|
func LoadTags(db *sql.DB) {
|
||||||
Tags = []*Tag{}
|
TagsTree = []*Tag{}
|
||||||
//rows, err := db.Query("select tags.tag_id, tags.name, tags.parent_id, array_agg(distinct(parent_of.tag_id)) as children from tags left join tags as parent_of on parent_of.parent_id=tags.tag_id group by tags.tag_id")
|
TagsFlat = make(map[int]*Tag)
|
||||||
|
|
||||||
rows, err := db.Query("select tags.tag_id, tags.name, tags.parent_id from tags order by tag_id,tags.parent_id desc")
|
rows, err := db.Query("select tags.tag_id, tags.name, tags.parent_id from tags order by tag_id,tags.parent_id desc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("DB Error loading tags:", err)
|
fmt.Println("DB Error loading tags:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var flatMap map[int]*Tag = make(map[int]*Tag)
|
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
tag := &Tag{Children: []*Tag{}}
|
tag := &Tag{Children: []*Tag{}}
|
||||||
|
@ -34,13 +35,13 @@ func LoadTags(db *sql.DB) {
|
||||||
fmt.Println("tags DB Error: ", err)
|
fmt.Println("tags DB Error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flatMap[tag.Id] = tag
|
TagsFlat[tag.Id] = tag
|
||||||
|
|
||||||
if tag.Parent.Valid {
|
if tag.Parent.Valid {
|
||||||
pid := int(tag.Parent.Int64)
|
pid := int(tag.Parent.Int64)
|
||||||
flatMap[pid].Children = append(flatMap[pid].Children, tag)
|
TagsFlat[pid].Children = append(TagsFlat[pid].Children, tag)
|
||||||
} else {
|
} else {
|
||||||
Tags = append(Tags, tag)
|
TagsTree = append(TagsTree, tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue