117 lines
3.3 KiB
Plaintext

package component
import (
"forge.cadoles.com/wpetit/clearcase/internal/core/model"
"forge.cadoles.com/wpetit/clearcase/internal/http/form"
common "forge.cadoles.com/wpetit/clearcase/internal/http/handler/webui/common/component"
)
type IssuePageVModel struct {
SummaryForm *form.Form
IssueForm *form.Form
Projects []*model.Project
SelectedProjectID string
}
func NewIssueSummaryForm() *form.Form {
return form.New(
form.NewField(
"project",
form.Attrs{},
form.NonEmpty("This field should not be empty"),
),
form.NewField(
"summary",
form.Attrs{
"type": "textarea",
"rows": "20",
"placeholder": "Write a rapid description of the issue here...",
},
form.NonEmpty("This field should not be empty"),
),
)
}
func NewIssueForm() *form.Form {
return form.New(
form.NewField(
"content",
form.Attrs{
"type": "textarea",
"rows": "25",
},
form.NonEmpty("This field should not be empty"),
),
)
}
templ IssuePage(vmodel IssuePageVModel) {
@common.Page(common.WithTitle("New issue")) {
<div class="container is-fluid">
<section class="section">
<div class="buttons is-right">
<a class="button is-medium" href={ common.BaseURL(ctx, common.WithPath("/auth/logout")) }>Logout</a>
</div>
<div class="columns">
<div class="column">
<form id="summary-form" action={ common.CurrentURL(ctx) } method="post" hx-disabled-elt="#summary-form textarea, #summary-form select, #summary-form button" hx-indicator="#generation-progress">
<div class="level">
<div class="level-left">
<h2 class="title is-size-2 level-item">Describe your request</h2>
</div>
<div class="level-right">
<div class="buttons is-right level-item">
<button type="submit" class="button is-primary is-large">
<span class="icon">
<i class="fa fa-robot"></i>
</span>
<span>Generate</span>
</button>
</div>
</div>
</div>
<progress id="generation-progress" class="htmx-indicator progress"></progress>
@common.FormSelect(
vmodel.SummaryForm, "issue-project", "project", "Project",
common.WithOptions(projectsToOptions(vmodel.Projects)...),
common.WithAttrs(
"hx-get", string(common.CurrentURL(ctx, common.WithoutValues("project", "*"))),
"hx-target", "body",
"hx-push-url", "true",
),
)
@common.FormTextarea(vmodel.SummaryForm, "issue-summary", "summary", "Summary")
</form>
</div>
<div class="column">
<div class="level">
<div class="level-left">
<h2 class="title is-size-2">Generated issue</h2>
</div>
<div class="level-right">
<div class="buttons is-right">
<button disabled type="submit" class="button is-primary is-large">
<span class="icon">
<i class="fa fa-rocket"></i>
</span>
<span>Create issue</span>
</button>
</div>
</div>
</div>
@common.FormTextarea(vmodel.IssueForm, "issue-content", "content", "")
</div>
</div>
</section>
</div>
}
}
func projectsToOptions(projects []*model.Project) []string {
options := make([]string, 0, len(projects)*2)
for _, p := range projects {
options = append(options, p.Label, p.ID)
}
return options
}