module Web.View.StewardshipRoles.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data IndexView = IndexView
{ roles :: ![StewardshipRole]
, hubs :: ![Hub]
}
instance View IndexView where
html IndexView { .. } = [hsx|
{if null roles
then [hsx|No stewardship roles assigned yet.
|]
else [hsx|
{forEach hubGroups renderHubGroup}
|]}
|]
where
hubName hid = maybe (show hid) (.name) (find (\h -> h.id == hid) hubs)
hubGroups = groupByHub hubs roles
groupByHub :: [Hub] -> [StewardshipRole] -> [(Hub, [StewardshipRole])]
groupByHub hs rs =
[ (h, filter (\r -> r.hubId == h.id) rs)
| h <- hs
, any (\r -> r.hubId == h.id) rs
]
renderHubGroup :: (Hub, [StewardshipRole]) -> Html
renderHubGroup (hub, hubRoles) = [hsx|
{hub.name}
| Role |
Assigned To |
Granted |
Status |
|
{forEach hubRoles renderRoleRow}
|]
renderRoleRow :: StewardshipRole -> Html
renderRoleRow r = [hsx|
| {r.roleName} |
{r.assignedTo} |
{show r.grantedAt} |
{if isNothing r.revokedAt
then [hsx|active|]
else [hsx|revoked|]}
|
View
|
|]