aboutsummaryrefslogtreecommitdiff
path: root/views/nodes.templ
diff options
context:
space:
mode:
Diffstat (limited to 'views/nodes.templ')
-rw-r--r--views/nodes.templ99
1 files changed, 0 insertions, 99 deletions
diff --git a/views/nodes.templ b/views/nodes.templ
deleted file mode 100644
index e6a120c..0000000
--- a/views/nodes.templ
+++ /dev/null
@@ -1,99 +0,0 @@
-package views
-
-import (
- "fmt"
- "gitrepo.ru/neonxp/gorum/models"
- "gitrepo.ru/neonxp/gorum/utils"
- "strconv"
-)
-
-templ Node(node *models.Node, topics []*models.Node, nodes []*models.Node) {
- @Layout(node.Parent) {
- switch node.Type {
- case models.TopicType:
- <h1>{ node.Text }</h1>
- <div>
- <a href={ templ.URL(fmt.Sprintf("/t/%d/new", node.ID)) }>Новая подтема</a>
- </div>
- case models.PostType:
- <h1>Пост</h1>
- @Post(node, 0, false)
- }
- if len(topics) != 0 {
- <table>
- <thead>
- <tr>
- <th>Тема</th>
- <th>Тем/Ответов</th>
- <th>Дата</th>
- <th>Автор</th>
- </tr>
- </thead>
- <tbody>
- for _, n := range topics {
- @Topic(n)
- }
- </tbody>
- </table>
- }
- if len(nodes) == 0 {
- <strong>Постов нет</strong>
- }
- for _, n := range nodes {
- @Post(n, level(node), true)
- }
- if isAuthorized(ctx) {
- @NewPostForm(node)
- } else {
- <a href="/login">Войдите</a> чтобы ответить в тему.
- }
- }
-}
-
-templ Topic(n *models.Node) {
- <tr>
- <td>
- <a href={ templ.URL(fmt.Sprintf("/t/%d", n.ID)) }>{ n.Text }</a>
- </td>
- <td>
- { strconv.Itoa(len(n.Children)) }
- </td>
- <td>
- { utils.FormatDate(n.CreatedAt) }
- </td>
- <td>
- { n.Author.Username }
- </td>
- </tr>
-}
-
-css levelStyle(level int) {
- margin-left: { fmt.Sprintf("%dem", level) };
-}
-
-templ Post(n *models.Node, level int, withFooter bool) {
- <article id={ fmt.Sprintf("post%d", n.ID) } class={ levelStyle(level) }>
- <header class="post-header">
- <span>
- { n.Author.Username }
- </span>
- <span>
- { utils.FormatDate(n.CreatedAt) }
- </span>
- </header>
- @templ.Raw(utils.MarkdownToHTML(n.Text))
- if withFooter {
- <footer class="post-header">
- <a href={ templ.URL(fmt.Sprintf("/p/%d/new", n.ID)) }>Ответить</a>
- <a href={ templ.URL(fmt.Sprintf("/p/%d", n.ID)) }>Ответов: { strconv.Itoa(len(n.Children)) }</a>
- </footer>
- }
- </article>
-}
-
-func level(node *models.Node) int {
- if node.Type == models.PostType {
- return 1
- }
- return 0
-}