From 1ecd8daa7c79791ce0d965ced444422019f7160a Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 17 May 2018 21:19:40 +0100 Subject: [PATCH] Implements categories in threads list. --- forum.nim | 22 +++++++++++++++------- frontend/category.nim | 19 ++++++++++++------- frontend/post.nim | 1 - frontend/threadlist.nim | 1 - 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/forum.nim b/forum.nim index 0802078..9ebc960 100644 --- a/forum.nim +++ b/forum.nim @@ -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) diff --git a/frontend/category.nim b/frontend/category.nim index 70c1293..6c20f94 100644 --- a/frontend/category.nim +++ b/frontend/category.nim @@ -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() \ No newline at end of file diff --git a/frontend/post.nim b/frontend/post.nim index c2fda99..dbde4af 100644 --- a/frontend/post.nim +++ b/frontend/post.nim @@ -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 diff --git a/frontend/threadlist.nim b/frontend/threadlist.nim index 482b6e0..f311a0c 100644 --- a/frontend/threadlist.nim +++ b/frontend/threadlist.nim @@ -15,7 +15,6 @@ type creation*: int64 ## Unix timestamp isLocked*: bool isSolved*: bool - isDeleted*: bool ThreadList* = ref object threads*: seq[Thread]