Files
LazyPM/pkg/web/routes/dashboard.templ
Ine Maria Nilssen Aanonsen 68054f7409 TASK BACKLOG REFINEMENT ISSUE
2026-03-06 12:52:13 +01:00

145 lines
3.5 KiB
Plaintext

package routes
import (
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/pkg/web/components"
"github.com/LazyBachelor/LazyPM/pkg/web/components/base"
)
type DashboardProps struct {
Issues []*models.Issue
SelectedIssue *models.Issue
BaseURL string
QueryParam string
EmptyText string
}
templ Dashboard(props DashboardProps) {
@BaseLayout() {
@DashboardContent(props)
}
}
templ DashboardContent(props DashboardProps) {
<div class="flex flex-row mx-auto">
<div class="w-full flex flex-col border-r border-base-200 overflow-auto">
<div class="flex p-2 border-b border-base-200 justify-between items-center gap-2">
<div class="w-full">
@components.SearchForm(components.SearchFormProps{
RootURL: props.BaseURL,
SearchQuery: props.QueryParam,
Target: "#issue-list-container",
})
</div>
<button
class="btn btn-primary"
hx-get="/issues/create"
hx-target="#modal-container"
hx-swap="innerHTML"
>
New Issue
</button>
</div>
<div id="issue-list-container" class="p-2">
@DashboardIssueList(props.Issues, props.SelectedIssue.ID)
</div>
</div>
<div class="w-full p-2 max-[770px]:hidden">
if props.SelectedIssue != nil {
<button
type="button"
class="btn btn-primary btn-sm"
hx-get={ "/issues/" + props.SelectedIssue.ID + "/edit" }
hx-target="#modal-container"
hx-swap="innerHTML"
>
Edit
</button>
if props.SelectedIssue.Status != "closed" {
<button
type="button"
class="btn btn-warning btn-sm btn-outline"
hx-get={ "/issues/" + props.SelectedIssue.ID + "/close" }
hx-target="#modal-container"
hx-swap="innerHTML"
>
Close issue
</button>
}
<button
type="button"
class="btn btn-error btn-sm btn-outline"
hx-delete={ "/issues/" + props.SelectedIssue.ID }
hx-confirm="Are you sure you want to delete this issue? This action cannot be undone."
hx-target="body"
>
Delete issue
</button>
<button
class="btn btn-sm fixed right-3"
hx-get={ "/issues/" + props.SelectedIssue.ID }
hx-target="main"
hx-swap="innerHTML"
hx-push-url="true"
>Details</button>
<div id="issue-detail-container">
@components.IssueDetail(components.IssueDetailProps{
Issue: props.SelectedIssue,
})
</div>
}
</div>
</div>
}
templ DashboardIssueList(issues []*models.Issue, selectedID string) {
<section class="flex">
@base.Table(
[]templ.Component{
base.PlainText("ID"),
base.PlainText("Title"),
base.PlainText("Status"),
base.PlainText("Type"),
base.PlainText("Priority"),
},
[]templ.Component{
DashboardIssueRows(issues, selectedID),
},
templ.Attributes{},
)
</section>
}
templ DashboardIssueRows(issues []*models.Issue, selectedID string) {
if len(issues) == 0 {
<tr><td colspan="5" class="text-center py-4">No issues</td></tr>
}
for _, issue := range issues {
{{
var active string
if selectedID == issue.ID {
active = "bg-primary/10"
}
}}
<tr
hx-get="/"
class={ "hover cursor-pointer min-h-full w-full", active }
hx-target="main"
hx-vals={ `{"selected-issue": "` + issue.ID + `"}` }
hx-swap="innerHTML"
>
<td class="min-w-20 truncate">{ issue.ID }</td>
<td class="truncate max-w-60">{ issue.Title }</td>
<td>
@components.StatusBadge(issue.Status)
</td>
<td>
@components.TypeBadge(issue.IssueType)
</td>
<td>
@components.PriorityBadge(issue.Priority)
</td>
</tr>
}
}