diff --git a/database.go b/database.go index 43f999e..d586ca5 100644 --- a/database.go +++ b/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 @@ func prepareStatements(db *sql.DB) { 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 = ?") diff --git a/views/onts.html b/views/onts.html index 6d07803..202a047 100644 --- a/views/onts.html +++ b/views/onts.html @@ -2,9 +2,15 @@

ontologies of interest -

+{{ $letter := 0 }} +

diff --git a/web.go b/web.go index ff9a320..fb7f416 100644 --- a/web.go +++ b/web.go @@ -654,28 +654,37 @@ func showontology(w http.ResponseWriter, r *http.Request) { 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") }