-
Notifications
You must be signed in to change notification settings - Fork 6
/
views.nim
85 lines (77 loc) · 3 KB
/
views.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import strformat
import karax / [karaxdsl, vdom]
# List all view
proc listView*(rows: seq[seq[string]]): string =
let vnode = buildHtml(html):
head:
link(href="https://unpkg.com/marx-css/css/marx.min.css", rel="stylesheet")
main:
h2: text "List all items"
table:
thead:
tr:
th: text "ID"
th: text "Name"
th: text "Status"
th:
a(href="create"): text "Create new"
tbody:
for row in rows:
tr:
for col in row:
td: text col
td:
a(href="read/" & $row[0]): text "Read"
a(href="update/" & $row[0]): text "Update"
a(href="delete/" & $row[0]): text "Delete"
result = $vnode
# Create view
proc createView*(status: string = "", id: string = ""): string =
let vnode = buildHtml(html):
head:
link(href="https://unpkg.com/marx-css/css/marx.min.css", rel="stylesheet")
main:
h3: text "Create new item:"
br()
if status != "":
pre: text status & " for id " & id
form(action = "/create", `method` = "get"):
label(`for`="task"): text "Enter task name"
input(`type` = "text", minlength = "1", maxlength = "80", name = "task")
br()
input(`type` = "submit", name = "save", value = "save")
a(href="/"): text "cancel"
result = $vnode
# Read view
proc readView*(value: string): string =
let vnode = buildHtml(html):
head:
link(href="https://unpkg.com/marx-css/css/marx.min.css", rel="stylesheet")
main:
h3: text fmt"Read item"
br()
pre: text fmt"{value}"
br()
a(href="/"): text "go back"
result = $vnode
# Update view
proc updateView*(id: int, value: seq[string], status: string = ""): string =
let vnode = buildHtml(html):
head:
link(href="https://unpkg.com/marx-css/css/marx.min.css", rel="stylesheet")
main:
h3: text fmt"Update item with ID {id}"
br()
if status != "":
pre: text status
form(action = fmt"/update/{id}", `method` = "get"):
label(`for`="task"): text "Enter task name"
input(`type` = "text", name = "task", value = value[0], maxlength = "80")
label(`for`="status"): text "Select status"
select(name = "status"):
option: text "open"
option: text "closed"
br()
input(`type` = "submit", name = "save", value = "save")
a(href="/"): text "cancel"
result = $vnode