organize onts better
Ted Unangst tedu@tedunangst.com
Sun, 13 Oct 2019 01:58:01 -0400
3 files changed,
24 insertions(+),
9 deletions(-)
M
database.go
→
database.go
@@ -610,7 +610,7 @@ var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt -var stmtSelectOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt +var stmtAllOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt var stmtHonksForUserFirstClass, stmtSaveMeta, stmtDeleteMeta, stmtUpdateHonk *sql.Stmt var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt@@ -682,7 +682,7 @@ stmtDeleteXonker = preparetodie(db, "delete from xonkers where name = ? and flavor = ?")
stmtRecentHonkers = preparetodie(db, "select distinct(honker) from honks where userid = ? and honker not in (select xid from honkers where userid = ? and flavor = 'sub') order by honkid desc limit 100") stmtUpdateFlags = preparetodie(db, "update honks set flags = flags | ? where honkid = ?") stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where honkid = ?") - stmtSelectOnts = preparetodie(db, "select distinct(ontology) from onts join honks on onts.honkid = honks.honkid where (honks.userid = ? or honks.whofore = 2)") + stmtAllOnts = preparetodie(db, "select ontology, count(ontology) from onts join honks on onts.honkid = honks.honkid where (honks.userid = ? or honks.whofore = 2) group by ontology") stmtGetFilters = preparetodie(db, "select hfcsid, json from hfcs where userid = ?") stmtSaveFilter = preparetodie(db, "insert into hfcs (userid, json) values (?, ?)") stmtDeleteFilter = preparetodie(db, "delete from hfcs where userid = ? and hfcsid = ?")
M
views/onts.html
→
views/onts.html
@@ -2,9 +2,15 @@ {{ template "header.html" . }}
<main> <div class="info"> <p>ontologies of interest -<p> +{{ $letter := 0 }} +<ul> {{ range .Onts }} -<a href="/o/{{ index . 1 }}">{{ index . 0 }}</a> +{{ if not (eq $letter (index .Name 0)) }} +{{ $letter = (index .Name 0) }} +<li><p> {{ end }} +<a href="/o/{{ .Name }}">#{{ .Name }}</a> ({{ .Count }}) +{{ end }} +</ul> </div> </main>
M
web.go
→
web.go
@@ -654,28 +654,37 @@ templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo) } +type Ont struct { + Name string + Count int64 +} + func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) { u := login.GetUserInfo(r) var userid int64 = -1 if u != nil { userid = u.UserID } - rows, err := stmtSelectOnts.Query(userid) + rows, err := stmtAllOnts.Query(userid) if err != nil { log.Printf("selection error: %s", err) return } defer rows.Close() - var onts [][]string + var onts []Ont for rows.Next() { - var o string - err := rows.Scan(&o) + var o Ont + err := rows.Scan(&o.Name, &o.Count) if err != nil { log.Printf("error scanning ont: %s", err) continue } - onts = append(onts, []string{o, o[1:]}) + o.Name = o.Name[1:] + onts = append(onts, o) } + sort.Slice(onts, func(i, j int) bool { + return onts[i].Name < onts[j].Name + }) if u == nil { w.Header().Set("Cache-Control", "max-age=300") }