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

44 lines
1.3 KiB
Haskell

module Web.View.Items.Index where
import Web.View.Prelude
data IndexView = IndexView { items :: [Include "tags" Item] }
instance View IndexView where
html IndexView { .. } = [hsx|
<h1>Items<a href={pathTo NewItemAction} class="btn btn-primary ms-4">+ New</a></h1>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Item</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>{forEach items renderItem}</tbody>
</table>
</div>
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbLink "Items" ItemsAction
]
renderItem :: Include "tags" Item -> Html
renderItem item = [hsx|
<tr>
<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>
</tr>
|]
renderTags :: [Tag] -> Text
renderTags tags =
tags
|> map (.name)
|> intercalate ", "