Implements categories in threads list.

This commit is contained in:
Dominik Picheta 2018-05-17 21:19:40 +01:00
commit 1ecd8daa7c
4 changed files with 27 additions and 16 deletions

View file

@ -953,15 +953,19 @@ proc selectThread(threadRow: seq[string]): Thread =
var thread = Thread(
id: threadRow[0].parseInt,
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: @[],
replies: posts[0].parseInt-1,
views: threadRow[2].parseInt,
activity: threadRow[3].parseInt,
creation: posts[1].parseInt,
isLocked: false, # TODO:
isLocked: threadRow[4] == "1",
isSolved: false, # TODO: Add a field to `post` to identify the solution.
isDeleted: false # TODO:
)
# Gather the users list.
@ -1171,8 +1175,10 @@ routes:
count = getInt(@"count", 30)
const threadsQuery =
sql"""select id, name, views, strftime('%s', modified) from thread
where isDeleted = 0
sql"""select t.id, t.name, views, strftime('%s', modified), isLocked,
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 ?, ?;"""
let thrCount = getValue(db, sql"select count(*) from thread;").parseInt()
@ -1195,8 +1201,10 @@ routes:
count = 10
const threadsQuery =
sql"""select id, name, views, strftime('%s', modified) from thread
where id = ? and isDeleted = 0;"""
sql"""select t.id, t.name, views, strftime('%s', modified), isLocked,
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 thread = selectThread(threadRow)

View file

@ -1,7 +1,9 @@
type
Category* = object
id*: string
id*: int
name*: string
description*: string
color*: string
@ -13,11 +15,14 @@ when defined(js):
proc render*(category: Category): VNode =
result = buildHtml():
if category.id.len > 0:
tdiv(class="triangle",
style=style(
(StyleAttr.borderBottom, kstring"0.6rem solid " & category.color)
)):
text category.id
if category.name.len >= 0:
tdiv(class="category",
"data-color"="#" & category.color):
tdiv(class="triangle",
style=style(
(StyleAttr.borderBottom,
kstring"0.6rem solid #" & category.color)
))
text category.name
else:
span()

View file

@ -19,7 +19,6 @@ type
## older versions of the post.
info*: PostInfo
moreBefore*: seq[int]
isDeleted*: bool
replyingTo*: Option[PostLink]
PostLink* = object ## Used by profile

View file

@ -15,7 +15,6 @@ type
creation*: int64 ## Unix timestamp
isLocked*: bool
isSolved*: bool
isDeleted*: bool
ThreadList* = ref object
threads*: seq[Thread]