Implements categories in threads list.
This commit is contained in:
parent
e34501a61a
commit
1ecd8daa7c
4 changed files with 27 additions and 16 deletions
22
forum.nim
22
forum.nim
|
|
@ -953,15 +953,19 @@ proc selectThread(threadRow: seq[string]): Thread =
|
||||||
var thread = Thread(
|
var thread = Thread(
|
||||||
id: threadRow[0].parseInt,
|
id: threadRow[0].parseInt,
|
||||||
topic: threadRow[1],
|
topic: threadRow[1],
|
||||||
category: Category(id: "", color: "#ff0000"), # TODO
|
category: Category(
|
||||||
|
id: threadRow[5].parseInt,
|
||||||
|
name: threadRow[6],
|
||||||
|
description: threadRow[7],
|
||||||
|
color: threadRow[8]
|
||||||
|
),
|
||||||
users: @[],
|
users: @[],
|
||||||
replies: posts[0].parseInt-1,
|
replies: posts[0].parseInt-1,
|
||||||
views: threadRow[2].parseInt,
|
views: threadRow[2].parseInt,
|
||||||
activity: threadRow[3].parseInt,
|
activity: threadRow[3].parseInt,
|
||||||
creation: posts[1].parseInt,
|
creation: posts[1].parseInt,
|
||||||
isLocked: false, # TODO:
|
isLocked: threadRow[4] == "1",
|
||||||
isSolved: false, # TODO: Add a field to `post` to identify the solution.
|
isSolved: false, # TODO: Add a field to `post` to identify the solution.
|
||||||
isDeleted: false # TODO:
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Gather the users list.
|
# Gather the users list.
|
||||||
|
|
@ -1171,8 +1175,10 @@ routes:
|
||||||
count = getInt(@"count", 30)
|
count = getInt(@"count", 30)
|
||||||
|
|
||||||
const threadsQuery =
|
const threadsQuery =
|
||||||
sql"""select id, name, views, strftime('%s', modified) from thread
|
sql"""select t.id, t.name, views, strftime('%s', modified), isLocked,
|
||||||
where isDeleted = 0
|
c.id, c.name, c.description, c.color
|
||||||
|
from thread t, category c
|
||||||
|
where isDeleted = 0 and category = c.id
|
||||||
order by modified desc limit ?, ?;"""
|
order by modified desc limit ?, ?;"""
|
||||||
|
|
||||||
let thrCount = getValue(db, sql"select count(*) from thread;").parseInt()
|
let thrCount = getValue(db, sql"select count(*) from thread;").parseInt()
|
||||||
|
|
@ -1195,8 +1201,10 @@ routes:
|
||||||
count = 10
|
count = 10
|
||||||
|
|
||||||
const threadsQuery =
|
const threadsQuery =
|
||||||
sql"""select id, name, views, strftime('%s', modified) from thread
|
sql"""select t.id, t.name, views, strftime('%s', modified), isLocked,
|
||||||
where id = ? and isDeleted = 0;"""
|
c.id, c.name, c.description, c.color
|
||||||
|
from thread t, category c
|
||||||
|
where t.id = ? and isDeleted = 0 and category = c.id;"""
|
||||||
|
|
||||||
let threadRow = getRow(db, threadsQuery, id)
|
let threadRow = getRow(db, threadsQuery, id)
|
||||||
let thread = selectThread(threadRow)
|
let thread = selectThread(threadRow)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
|
|
||||||
type
|
type
|
||||||
Category* = object
|
Category* = object
|
||||||
id*: string
|
id*: int
|
||||||
|
name*: string
|
||||||
|
description*: string
|
||||||
color*: string
|
color*: string
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,11 +15,14 @@ when defined(js):
|
||||||
|
|
||||||
proc render*(category: Category): VNode =
|
proc render*(category: Category): VNode =
|
||||||
result = buildHtml():
|
result = buildHtml():
|
||||||
if category.id.len > 0:
|
if category.name.len >= 0:
|
||||||
tdiv(class="triangle",
|
tdiv(class="category",
|
||||||
style=style(
|
"data-color"="#" & category.color):
|
||||||
(StyleAttr.borderBottom, kstring"0.6rem solid " & category.color)
|
tdiv(class="triangle",
|
||||||
)):
|
style=style(
|
||||||
text category.id
|
(StyleAttr.borderBottom,
|
||||||
|
kstring"0.6rem solid #" & category.color)
|
||||||
|
))
|
||||||
|
text category.name
|
||||||
else:
|
else:
|
||||||
span()
|
span()
|
||||||
|
|
@ -19,7 +19,6 @@ type
|
||||||
## older versions of the post.
|
## older versions of the post.
|
||||||
info*: PostInfo
|
info*: PostInfo
|
||||||
moreBefore*: seq[int]
|
moreBefore*: seq[int]
|
||||||
isDeleted*: bool
|
|
||||||
replyingTo*: Option[PostLink]
|
replyingTo*: Option[PostLink]
|
||||||
|
|
||||||
PostLink* = object ## Used by profile
|
PostLink* = object ## Used by profile
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ type
|
||||||
creation*: int64 ## Unix timestamp
|
creation*: int64 ## Unix timestamp
|
||||||
isLocked*: bool
|
isLocked*: bool
|
||||||
isSolved*: bool
|
isSolved*: bool
|
||||||
isDeleted*: bool
|
|
||||||
|
|
||||||
ThreadList* = ref object
|
ThreadList* = ref object
|
||||||
threads*: seq[Thread]
|
threads*: seq[Thread]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue