Add number of topics to category list
This commit is contained in:
parent
da7045ecca
commit
70ad45d8f6
3 changed files with 11 additions and 4 deletions
|
|
@ -791,12 +791,18 @@ routes:
|
|||
|
||||
get "/categories.json":
|
||||
# TODO: Limit this query in the case of many many categories
|
||||
const categoriesQuery = sql"""select * from category;"""
|
||||
const categoriesQuery =
|
||||
sql"""
|
||||
select c.*, count(thread.category)
|
||||
from category c
|
||||
left join thread on c.id == thread.category
|
||||
group by c.id;
|
||||
"""
|
||||
|
||||
var list = CategoryList(categories: @[])
|
||||
for data in getAllRows(db, categoriesQuery):
|
||||
let category = Category(
|
||||
id: data[0].getInt, name: data[1], description: data[2], color: data[3]
|
||||
id: data[0].getInt, name: data[1], description: data[2], color: data[3], numTopics: data[4].parseInt
|
||||
)
|
||||
list.categories.add(category)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ type
|
|||
name*: string
|
||||
description*: string
|
||||
color*: string
|
||||
numTopics*: int
|
||||
|
||||
CategoryList* = ref object
|
||||
categories*: seq[Category]
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@ when defined(js):
|
|||
tr(class=class({"no-border": noBorder})):
|
||||
td(style=style((StyleAttr.borderLeftColor, kstring("#" & category.color))), class="category"):
|
||||
h4(class="category-title"):
|
||||
a(href=makeUri("/c/" & $category.id)):
|
||||
a(href=makeUri("/c/" & $category.id), id="category-" & category.name.slug):
|
||||
tdiv():
|
||||
tdiv(class="category-name"):
|
||||
text category.name
|
||||
tdiv(class="category-description"):
|
||||
text category.description
|
||||
td(class="topics"):
|
||||
text "Topics"
|
||||
text $category.numTopics
|
||||
|
||||
proc onCategoriesRetrieved(httpStatus: int, response: kstring) =
|
||||
state.loading = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue