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":
|
get "/categories.json":
|
||||||
# TODO: Limit this query in the case of many many categories
|
# 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: @[])
|
var list = CategoryList(categories: @[])
|
||||||
for data in getAllRows(db, categoriesQuery):
|
for data in getAllRows(db, categoriesQuery):
|
||||||
let category = Category(
|
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)
|
list.categories.add(category)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ type
|
||||||
name*: string
|
name*: string
|
||||||
description*: string
|
description*: string
|
||||||
color*: string
|
color*: string
|
||||||
|
numTopics*: int
|
||||||
|
|
||||||
CategoryList* = ref object
|
CategoryList* = ref object
|
||||||
categories*: seq[Category]
|
categories*: seq[Category]
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,14 @@ when defined(js):
|
||||||
tr(class=class({"no-border": noBorder})):
|
tr(class=class({"no-border": noBorder})):
|
||||||
td(style=style((StyleAttr.borderLeftColor, kstring("#" & category.color))), class="category"):
|
td(style=style((StyleAttr.borderLeftColor, kstring("#" & category.color))), class="category"):
|
||||||
h4(class="category-title"):
|
h4(class="category-title"):
|
||||||
a(href=makeUri("/c/" & $category.id)):
|
a(href=makeUri("/c/" & $category.id), id="category-" & category.name.slug):
|
||||||
tdiv():
|
tdiv():
|
||||||
tdiv(class="category-name"):
|
tdiv(class="category-name"):
|
||||||
text category.name
|
text category.name
|
||||||
tdiv(class="category-description"):
|
tdiv(class="category-description"):
|
||||||
text category.description
|
text category.description
|
||||||
td(class="topics"):
|
td(class="topics"):
|
||||||
text "Topics"
|
text $category.numTopics
|
||||||
|
|
||||||
proc onCategoriesRetrieved(httpStatus: int, response: kstring) =
|
proc onCategoriesRetrieved(httpStatus: int, response: kstring) =
|
||||||
state.loading = false
|
state.loading = false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue