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( 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)

View file

@ -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()

View file

@ -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

View file

@ -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]