make issue list and issue form
This commit is contained in:
109
pkg/web/components/issue.templ
Normal file
109
pkg/web/components/issue.templ
Normal file
@@ -0,0 +1,109 @@
|
||||
package components
|
||||
|
||||
import (
|
||||
"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-xs 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,
|
||||
Required: true,
|
||||
})
|
||||
@base.Textarea(base.TextareaProps{
|
||||
Name: "description",
|
||||
Label: "Description",
|
||||
Value: props.Description,
|
||||
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",
|
||||
Min: 0,
|
||||
Max: 5,
|
||||
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>
|
||||
<td class="px-4 py-2 border">{ issue.ID }</td>
|
||||
<td class="px-4 py-2 border">{ issue.Title }</td>
|
||||
<td class="px-4 py-2 border">{ issue.Status }</td>
|
||||
<td class="px-4 py-2 border">{ issue.IssueType }</td>
|
||||
<td class="px-4 py-2 border">{ issue.Priority }</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user