module Web.View.Requirements.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
data IndexView = IndexView
{ requirements :: ![Requirement]
, candidates :: ![RequirementCandidate]
}
instance View IndexView where
html IndexView { .. } = [hsx|
Requirements
{renderRequirementsSection requirements candidates}
|]
renderRequirementsSection :: [Requirement] -> [RequirementCandidate] -> Html
renderRequirementsSection [] _ = [hsx|No requirements yet. Promote an accepted candidate to create one.
|]
renderRequirementsSection reqs candidates = renderTable reqs candidates
renderTable :: [Requirement] -> [RequirementCandidate] -> Html
renderTable reqs candidates = [hsx|
| Title |
Status |
Source Candidate |
Created |
{forEach reqs (renderRow candidates)}
|]
renderRow :: [RequirementCandidate] -> Requirement -> Html
renderRow candidates req = [hsx|
|
{req.title}
|
" text-xs px-2 py-0.5 rounded font-medium"}>
{req.status}
|
{candidateTitle candidates req.sourceCandidateId}
|
{show req.createdAt} |
|]
candidateTitle :: [RequirementCandidate] -> Id RequirementCandidate -> Text
candidateTitle cs cid =
maybe "(unknown)" (.title) (find (\c -> c.id == cid) cs)
reqStatusClass :: Text -> Text
reqStatusClass "active" = "bg-green-100 text-green-800"
reqStatusClass "superseded" = "bg-yellow-100 text-yellow-800"
reqStatusClass "withdrawn" = "bg-gray-100 text-gray-500"
reqStatusClass _ = "bg-gray-100 text-gray-600"