1
0
Fork 0
compareware/Web/View/Items/Index.hs

44 lines
1.3 KiB
Haskell
Raw Normal View History

2024-04-11 16:25:09 +00:00
module Web.View.Items.Index where
2023-04-16 10:33:20 +00:00
import Web.View.Prelude
2024-04-11 16:25:09 +00:00
data IndexView = IndexView { items :: [Include "tags" Item] }
2023-04-16 10:33:20 +00:00
instance View IndexView where
html IndexView { .. } = [hsx|
2024-04-11 16:25:09 +00:00
<h1>Items<a href={pathTo NewItemAction} class="btn btn-primary ms-4">+ New</a></h1>
2023-04-16 10:33:20 +00:00
<div class="table-responsive">
<table class="table">
<thead>
<tr>
2024-04-11 16:25:09 +00:00
<th>Item</th>
2023-04-16 10:33:20 +00:00
<th></th>
<th></th>
<th></th>
</tr>
</thead>
2024-04-11 16:25:09 +00:00
<tbody>{forEach items renderItem}</tbody>
2023-04-16 10:33:20 +00:00
</table>
</div>
|]
where
breadcrumb = renderBreadcrumb
2024-04-11 16:25:09 +00:00
[ breadcrumbLink "Items" ItemsAction
2023-04-16 10:33:20 +00:00
]
2024-04-11 16:25:09 +00:00
renderItem :: Include "tags" Item -> Html
renderItem item = [hsx|
2023-04-16 10:33:20 +00:00
<tr>
2024-04-11 16:25:09 +00:00
<td>{item.description}</td>
<td>{renderTags item.tags}</td>
<td><a href={ShowItemAction item.id}>Show</a></td>
<td><a href={EditItemAction item.id} class="text-muted">Edit</a></td>
<td><a href={DeleteItemAction item.id} class="js-delete text-muted">Delete</a></td>
2023-04-16 10:33:20 +00:00
</tr>
2023-04-16 13:54:20 +00:00
|]
renderTags :: [Tag] -> Text
renderTags tags =
tags
|> map (.name)
|> intercalate ", "