// Code generated by templ - DO NOT EDIT. // templ: version: v0.3.819 package component //lint:file-ignore SA4006 This context is only used if a nested component is present. import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" import ( "bytes" "context" "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" "github.com/pkg/errors" "github.com/yuin/goldmark" "log/slog" "strings" ) type IssuePageVModel struct { IssueURL string SummaryForm *form.Form IssueForm *form.Form IssueTips string Projects []*model.Project SelectedProjectID string } const summaryPlaceholder = ` Décrivez rapidement le sujet du problème rencontré ou de l'évolution souhaitée, ClearCase utilisera le modèle de demande présent dans le dépôt (ou un modèle par défaut) afin de générer une version mise en forme et complétée. Afin de fournir plus d'information de contexte au LLM, vous pouvez faire référence à d'autres tickets du dépôt via un ou plusieurs '#' et/ou des chemins vers des fichiers présents dans celui ci. ` const bodyPlaceholder = ` Une fois votre demande générée, vous pourrez l'éditer puis la créer directement en cliquant sur le bouton 'Créer' ci-dessous. ` func NewIssueSummaryForm() *form.Form { return form.New( form.NewField( "project", form.Attrs{}, form.NonEmpty("Ce champs ne doit pas être vide."), ), form.NewField( "summary", form.Attrs{ "type": "textarea", "rows": "20", "placeholder": strings.TrimSpace(summaryPlaceholder), }, form.NonEmpty("Ce champ ne doit pas être vide."), ), ) } func NewIssueForm() *form.Form { return form.New( form.NewField( "title", form.Attrs{ "type": "text", "placeholder": "Écrivez le résumé de votre demande et cliquez sur 'Générer' pour remplir automatiquement ces champs.", }, form.NonEmpty("Ce champ ne doit pas être vide."), ), form.NewField( "body", form.Attrs{ "type": "textarea", "rows": "20", "placeholder": strings.TrimSpace(bodyPlaceholder), }, form.NonEmpty("Ce champ ne doit pas être vide."), ), ) } func IssuePage(vmodel IssuePageVModel) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { return templ_7745c5c3_CtxErr } templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { defer func() { templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) if templ_7745c5c3_Err == nil { templ_7745c5c3_Err = templ_7745c5c3_BufErr } }() } ctx = templ.InitializeContext(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx) if templ_7745c5c3_Var1 == nil { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { defer func() { templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) if templ_7745c5c3_Err == nil { templ_7745c5c3_Err = templ_7745c5c3_BufErr } }() } ctx = templ.InitializeContext(ctx) templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "

ClearCase

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if vmodel.IssueURL != "" { templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "

Demande créée !

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templ.JSFuncCall("clearSummary", vmodel.SelectedProjectID).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templ.JSFuncCall("openIssue", vmodel.IssueURL).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "

Résumé de la demande

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = common.FormSelect( vmodel.SummaryForm, "issue-project", "project", "Projet", common.WithOptions(projectsToOptions(vmodel.Projects)...), common.WithAttrs( "hx-get", string(common.CurrentURL(ctx, common.WithoutValues("project", "*"))), "hx-target", "body", "hx-push-url", "true", ), ).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = common.FormTextarea( vmodel.SummaryForm, "issue-summary", "summary", "Résumé", common.WithTextareaAttrs( "hx-on:change", "onSummaryChange(event)", ), ).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "

Votre demande

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = common.FormField(vmodel.IssueForm, "issue-title", "title", "Titre").Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = common.FormTextarea(vmodel.IssueForm, "issue-body", "body", "Corps").Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if vmodel.IssueTips != "" { html := markdownToHTML(ctx, vmodel.IssueTips) if html != "" { templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "

Suggestions

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templ.Raw(html).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } } templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) templ_7745c5c3_Err = common.Page(common.WithTitle("Nouvelle demande")).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) } func projectsToOptions(projects []*model.Project) []string { options := make([]string, 0, len(projects)*2) for _, p := range projects { options = append(options, p.Name, p.ID) } return options } func markdownToHTML(ctx context.Context, text string) string { var buff bytes.Buffer if err := goldmark.Convert([]byte(text), &buff); err != nil { slog.ErrorContext(ctx, "could not convert markdown to html", slog.Any("error", errors.WithStack(err))) return "" } return buff.String() } var _ = templruntime.GeneratedTemplate