add events page
This commit is contained in:
parent
2bfd2f97c2
commit
4740bb815c
31
database.go
31
database.go
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -119,6 +120,33 @@ func getpublichonks() []*Honk {
|
||||||
rows, err := stmtPublicHonks.Query(dt)
|
rows, err := stmtPublicHonks.Query(dt)
|
||||||
return getsomehonks(rows, err)
|
return getsomehonks(rows, err)
|
||||||
}
|
}
|
||||||
|
func geteventhonks(userid int64) []*Honk {
|
||||||
|
rows, err := stmtEventHonks.Query(userid)
|
||||||
|
honks := getsomehonks(rows, err)
|
||||||
|
sort.Slice(honks, func(i, j int) bool {
|
||||||
|
var t1, t2 time.Time
|
||||||
|
if honks[i].Time == nil {
|
||||||
|
t1 = honks[i].Date
|
||||||
|
} else {
|
||||||
|
t1 = honks[i].Time.StartTime
|
||||||
|
}
|
||||||
|
if honks[j].Time == nil {
|
||||||
|
t2 = honks[j].Date
|
||||||
|
} else {
|
||||||
|
t2 = honks[j].Time.StartTime
|
||||||
|
}
|
||||||
|
return t1.After(t2)
|
||||||
|
})
|
||||||
|
now := time.Now().Add(-24 * time.Hour)
|
||||||
|
for i, h := range honks {
|
||||||
|
if h.Time.StartTime.Before(now) {
|
||||||
|
honks = honks[:i]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reversehonks(honks)
|
||||||
|
return honks
|
||||||
|
}
|
||||||
func gethonksbyuser(name string, includeprivate bool) []*Honk {
|
func gethonksbyuser(name string, includeprivate bool) []*Honk {
|
||||||
dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat)
|
dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat)
|
||||||
whofore := 2
|
whofore := 2
|
||||||
|
@ -572,7 +600,7 @@ var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateHonker
|
||||||
var stmtAnyXonk, stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt
|
var stmtAnyXonk, stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt
|
||||||
var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt
|
var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt
|
||||||
var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtWhatAbout *sql.Stmt
|
var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtWhatAbout *sql.Stmt
|
||||||
var stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt
|
var stmtEventHonks, stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt
|
||||||
var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt
|
var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt
|
||||||
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt
|
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt
|
||||||
var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt
|
var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt
|
||||||
|
@ -604,6 +632,7 @@ func prepareStatements(db *sql.DB) {
|
||||||
stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? order by honks.honkid asc")
|
stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? order by honks.honkid asc")
|
||||||
stmtOneBonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ? and what = 'bonk' and whofore = 2")
|
stmtOneBonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ? and what = 'bonk' and whofore = 2")
|
||||||
stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+limit)
|
stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+limit)
|
||||||
|
stmtEventHonks = preparetodie(db, selecthonks+"where (whofore = 2 or honks.userid = ?) and what = 'event'"+limit)
|
||||||
stmtUserHonks = preparetodie(db, selecthonks+"where (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit)
|
stmtUserHonks = preparetodie(db, selecthonks+"where (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit)
|
||||||
stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and honker in (select xid from honkers where userid = ? and flavor = 'sub' and combos not like '% - %')"+butnotthose+limit)
|
stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and honker in (select xid from honkers where userid = ? and flavor = 'sub' and combos not like '% - %')"+butnotthose+limit)
|
||||||
stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and (what <> 'tonk') and honker in (select xid from honkers where userid = ? and flavor = 'sub' and combos not like '% - %')"+butnotthose+limit)
|
stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and (what <> 'tonk') and honker in (select xid from honkers where userid = ? and flavor = 'sub' and combos not like '% - %')"+butnotthose+limit)
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
<li><a href="/o">tags</a>
|
<li><a href="/o">tags</a>
|
||||||
<li><a href="/about">about</a>
|
<li><a href="/about">about</a>
|
||||||
<li><a href="/front">front</a>
|
<li><a href="/front">front</a>
|
||||||
|
<li><a href="/events">events</a>
|
||||||
<li><a href="/xzone">xzone</a>
|
<li><a href="/xzone">xzone</a>
|
||||||
<li><a href="/hfcs">hfcs</a>
|
<li><a href="/hfcs">hfcs</a>
|
||||||
<li><a href="/funzone">funzone</a>
|
<li><a href="/funzone">funzone</a>
|
||||||
|
@ -50,6 +51,7 @@
|
||||||
<p></p>
|
<p></p>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<span><a id="homelink" href="/">home</a></span>
|
<span><a id="homelink" href="/">home</a></span>
|
||||||
|
<span><a href="/events">events</a></span>
|
||||||
<span><a href="/about">about</a></span>
|
<span><a href="/about">about</a></span>
|
||||||
{{ if .ShowRSS }}
|
{{ if .ShowRSS }}
|
||||||
<span><a href="/rss">rss</a></span>
|
<span><a href="/rss">rss</a></span>
|
||||||
|
|
26
web.go
26
web.go
|
@ -83,18 +83,33 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
||||||
u := login.GetUserInfo(r)
|
u := login.GetUserInfo(r)
|
||||||
var honks []*Honk
|
var honks []*Honk
|
||||||
var userid int64 = -1
|
var userid int64 = -1
|
||||||
if r.URL.Path == "/front" || u == nil {
|
|
||||||
|
templinfo["ServerMessage"] = serverMsg
|
||||||
|
if u == nil {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/events":
|
||||||
|
honks = geteventhonks(userid)
|
||||||
|
templinfo["ServerMessage"] = "some recent and upcoming events"
|
||||||
|
default:
|
||||||
|
templinfo["ShowRSS"] = true
|
||||||
honks = getpublichonks()
|
honks = getpublichonks()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
userid = u.UserID
|
userid = u.UserID
|
||||||
if r.URL.Path == "/atme" {
|
switch r.URL.Path {
|
||||||
|
case "/atme":
|
||||||
templinfo["PageName"] = "atme"
|
templinfo["PageName"] = "atme"
|
||||||
honks = gethonksforme(userid)
|
honks = gethonksforme(userid)
|
||||||
} else if r.URL.Path == "/first" {
|
case "/events":
|
||||||
|
templinfo["ServerMessage"] = "some recent and upcoming events"
|
||||||
|
templinfo["PageName"] = "events"
|
||||||
|
honks = geteventhonks(userid)
|
||||||
|
honks = osmosis(honks, userid)
|
||||||
|
case "/first":
|
||||||
templinfo["PageName"] = "first"
|
templinfo["PageName"] = "first"
|
||||||
honks = gethonksforuser(userid)
|
honks = gethonksforuser(userid)
|
||||||
honks = osmosis(honks, userid)
|
honks = osmosis(honks, userid)
|
||||||
} else {
|
default:
|
||||||
templinfo["PageName"] = "home"
|
templinfo["PageName"] = "home"
|
||||||
honks = gethonksforuser(userid)
|
honks = gethonksforuser(userid)
|
||||||
honks = osmosis(honks, userid)
|
honks = osmosis(honks, userid)
|
||||||
|
@ -102,8 +117,6 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
||||||
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
|
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
templinfo["ShowRSS"] = true
|
|
||||||
templinfo["ServerMessage"] = serverMsg
|
|
||||||
honkpage(w, u, honks, templinfo)
|
honkpage(w, u, honks, templinfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1642,6 +1655,7 @@ func serve() {
|
||||||
getters.HandleFunc("/", homepage)
|
getters.HandleFunc("/", homepage)
|
||||||
getters.HandleFunc("/home", homepage)
|
getters.HandleFunc("/home", homepage)
|
||||||
getters.HandleFunc("/front", homepage)
|
getters.HandleFunc("/front", homepage)
|
||||||
|
getters.HandleFunc("/events", homepage)
|
||||||
getters.HandleFunc("/robots.txt", nomoroboto)
|
getters.HandleFunc("/robots.txt", nomoroboto)
|
||||||
getters.HandleFunc("/rss", showrss)
|
getters.HandleFunc("/rss", showrss)
|
||||||
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
|
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
|
||||||
|
|
Loading…
Reference in New Issue