118 lines
3.0 KiB
Plaintext
118 lines
3.0 KiB
Plaintext
package components
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
|
"github.com/LazyBachelor/LazyPM/pkg/web/components/base"
|
|
)
|
|
|
|
type IssueFormProps struct {
|
|
Action string
|
|
Title string
|
|
Description string
|
|
Status string
|
|
Priority int
|
|
IssueType string
|
|
Class string
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
templ IssueForm(props IssueFormProps) {
|
|
<div class={ "w-full max-w-lg mx-auto ", props.Class }>
|
|
<form
|
|
class="form space-y-1"
|
|
hx-post={ props.Action }
|
|
hx-target="#result"
|
|
hx-swap="innerHTML"
|
|
{ props.Attrs... }
|
|
>
|
|
@base.Input(base.InputProps{
|
|
Name: "title",
|
|
Label: "Title",
|
|
Value: props.Title,
|
|
Class: "w-full",
|
|
Required: true,
|
|
})
|
|
@base.Textarea(base.TextareaProps{
|
|
Name: "description",
|
|
Label: "Description",
|
|
Value: props.Description,
|
|
Class: "w-full",
|
|
Required: true,
|
|
})
|
|
@base.Select(base.SelectProps{
|
|
Name: "status",
|
|
Label: "Status",
|
|
Required: true,
|
|
Options: []base.SelectOption{
|
|
{Label: "Open", Value: "open", Selected: props.Status == "open"},
|
|
{Label: "In Progress", Value: "in_progress", Selected: props.Status == "in_progress"},
|
|
{Label: "Closed", Value: "closed", Selected: props.Status == "closed"},
|
|
},
|
|
Size: "md",
|
|
})
|
|
@base.Select(base.SelectProps{
|
|
Name: "issue_type",
|
|
Label: "Issue Type",
|
|
Required: true,
|
|
Options: []base.SelectOption{
|
|
{Label: "Task", Value: "task", Selected: props.IssueType == "task"},
|
|
{Label: "Bug", Value: "bug", Selected: props.IssueType == "bug"},
|
|
{Label: "Feature", Value: "feature", Selected: props.IssueType == "feature"},
|
|
{Label: "Chore", Value: "chore", Selected: props.IssueType == "chore"},
|
|
},
|
|
Size: "md",
|
|
})
|
|
@base.Range(base.RangeProps{
|
|
Name: "priority",
|
|
Label: "Priority",
|
|
Class: "flex-1",
|
|
Min: 0,
|
|
Max: 4,
|
|
Value: props.Priority,
|
|
Step: 1,
|
|
})
|
|
<button type="submit" class="btn btn-primary w-full mt-4">
|
|
Submit Issue
|
|
</button>
|
|
</form>
|
|
<div id="result"></div>
|
|
</div>
|
|
}
|
|
|
|
type IssueTableProps struct {
|
|
Issues []models.Issue
|
|
}
|
|
|
|
templ IssueTable(props IssueTableProps) {
|
|
@base.Table(
|
|
[]templ.Component{
|
|
base.PlainText("ID"),
|
|
base.PlainText("Title"),
|
|
base.PlainText("Status"),
|
|
base.PlainText("Type"),
|
|
base.PlainText("Priority"),
|
|
},
|
|
[]templ.Component{
|
|
IssueRows(props.Issues),
|
|
},
|
|
templ.Attributes{},
|
|
)
|
|
}
|
|
|
|
templ IssueRows(issues []models.Issue) {
|
|
for _, issue := range issues {
|
|
<tr class="hover">
|
|
<td class="px-4 py-2 border">
|
|
<a href={ templ.SafeURL("/issues/" + issue.ID) } class="link link-primary font-mono">{ issue.ID }</a>
|
|
</td>
|
|
<td class="px-4 py-2 border">
|
|
<a href={ templ.SafeURL("/issues/" + issue.ID) } class="hover:text-primary">{ issue.Title }</a>
|
|
</td>
|
|
<td class="px-4 py-2 border">{ string(issue.Status) }</td>
|
|
<td class="px-4 py-2 border">{ string(issue.IssueType) }</td>
|
|
<td class="px-4 py-2 border">{ fmt.Sprintf("P%d", issue.Priority) }</td>
|
|
</tr>
|
|
}
|
|
}
|