From 84447df4d366324ab81894b028b00fd66be85caf Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 2 Sep 2022 15:58:49 +0800 Subject: Support Issue forms and PR forms (#20987) * feat: extend issue template for yaml * feat: support yaml template * feat: render form to markdown * feat: support yaml template for pr * chore: rename to Fields * feat: template unmarshal * feat: split template * feat: render to markdown * feat: use full name as template file name * chore: remove useless file * feat: use dropdown of fomantic ui * feat: update input style * docs: more comments * fix: render text without render * chore: fix lint error * fix: support use description as about in markdown * fix: add field class in form * chore: generate swagger * feat: validate template * feat: support is_nummber and regex * test: fix broken unit tests * fix: ignore empty body of md template * fix: make multiple easymde editors work in one page * feat: better UI * fix: js error in pr form * chore: generate swagger * feat: support regex validation * chore: generate swagger * fix: refresh each markdown editor * chore: give up required validation * fix: correct issue template candidates * fix: correct checkboxes style * chore: ignore .hugo_build.lock in docs * docs: separate out a new doc for merge templates * docs: introduce syntax of yaml template * feat: show a alert for invalid templates * test: add case for a valid template * fix: correct attributes of required checkbox * fix: add class not-under-easymde for dropzone * fix: use more back-quotes * chore: remove translation in zh-CN * fix EasyMDE statusbar margin * fix: remove repeated blocks * fix: reuse regex for quotes Co-authored-by: wxiaoguang --- templates/base/alert.tmpl | 5 ++++ templates/repo/diff/compare.tmpl | 8 +++++++ templates/repo/issue/choose.tmpl | 1 + templates/repo/issue/comment_tab.tmpl | 37 +++++++++++++++++++++-------- templates/repo/issue/fields/checkboxes.tmpl | 12 ++++++++++ templates/repo/issue/fields/dropdown.tmpl | 14 +++++++++++ templates/repo/issue/fields/header.tmpl | 6 +++++ templates/repo/issue/fields/input.tmpl | 4 ++++ templates/repo/issue/fields/markdown.tmpl | 3 +++ templates/repo/issue/fields/textarea.tmpl | 6 +++++ templates/repo/issue/new.tmpl | 8 +++++++ templates/swagger/v1_json.tmpl | 36 ++++++++++++++++++++++++++++ 12 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 templates/repo/issue/fields/checkboxes.tmpl create mode 100644 templates/repo/issue/fields/dropdown.tmpl create mode 100644 templates/repo/issue/fields/header.tmpl create mode 100644 templates/repo/issue/fields/input.tmpl create mode 100644 templates/repo/issue/fields/markdown.tmpl create mode 100644 templates/repo/issue/fields/textarea.tmpl (limited to 'templates') diff --git a/templates/base/alert.tmpl b/templates/base/alert.tmpl index cf886f529c..b8a04b89a9 100644 --- a/templates/base/alert.tmpl +++ b/templates/base/alert.tmpl @@ -13,3 +13,8 @@

{{.Flash.InfoMsg | Str2html}}

{{end}} +{{if .Flash.WarningMsg}} +
+

{{.Flash.WarningMsg | Str2html}}

+
+{{end}} diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 5875efaac3..e9f2fc3b60 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -11,6 +11,14 @@ {{.locale.Tr "action.compare_commits_general"}} {{end}} + {{if .Flash.WarningMsg}} + {{/* + There's alreay a importing of alert.tmpl in new_form.tmpl, + but only the negative message will be displayed within forms for some reasons, see semantic.css:10659. + To avoid repeated negative messages, the importing here if for .Flash.WarningMsg only. + */}} + {{template "base/alert" .}} + {{end}} {{$BaseCompareName := $.BaseName -}} {{- $HeadCompareName := $.HeadRepo.OwnerName -}} {{- if and (eq $.BaseName $.HeadRepo.OwnerName) (ne $.Repository.Name $.HeadRepo.Name) -}} diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl index bbddd6d9a6..609cd48436 100644 --- a/templates/repo/issue/choose.tmpl +++ b/templates/repo/issue/choose.tmpl @@ -2,6 +2,7 @@
{{template "repo/header" .}}
+ {{template "base/alert" .}} diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl index c1ca69dfb3..b70433a966 100644 --- a/templates/repo/issue/comment_tab.tmpl +++ b/templates/repo/issue/comment_tab.tmpl @@ -1,17 +1,34 @@ - -
-
+{{if .Fields}} + + {{range .Fields}} + {{if eq .Type "input"}} + {{template "repo/issue/fields/input" .}} + {{else if eq .Type "markdown"}} + {{template "repo/issue/fields/markdown" .}} + {{else if eq .Type "textarea"}} + {{template "repo/issue/fields/textarea" .}} + {{else if eq .Type "dropdown"}} + {{template "repo/issue/fields/dropdown" .}} + {{else if eq .Type "checkboxes"}} + {{template "repo/issue/fields/checkboxes" .}} + {{end}} + {{end}} +{{else}} + +
+
+
+
+ {{.locale.Tr "loading"}} +
-
- {{.locale.Tr "loading"}} -
-
+{{end}} {{if .IsAttachmentEnabled}}
{{template "repo/upload" .}} diff --git a/templates/repo/issue/fields/checkboxes.tmpl b/templates/repo/issue/fields/checkboxes.tmpl new file mode 100644 index 0000000000..b70334681f --- /dev/null +++ b/templates/repo/issue/fields/checkboxes.tmpl @@ -0,0 +1,12 @@ +
+ {{template "repo/issue/fields/header" .}} + {{$field := .}} + {{range $i, $opt := .Attributes.options}} +
+
+ + +
+
+ {{end}} +
diff --git a/templates/repo/issue/fields/dropdown.tmpl b/templates/repo/issue/fields/dropdown.tmpl new file mode 100644 index 0000000000..83c2bb4aac --- /dev/null +++ b/templates/repo/issue/fields/dropdown.tmpl @@ -0,0 +1,14 @@ +
+ {{template "repo/issue/fields/header" .}} + {{/* FIXME: required validation */}} + +
diff --git a/templates/repo/issue/fields/header.tmpl b/templates/repo/issue/fields/header.tmpl new file mode 100644 index 0000000000..fb8511b4f0 --- /dev/null +++ b/templates/repo/issue/fields/header.tmpl @@ -0,0 +1,6 @@ +{{if .Attributes.label}} +

{{.Attributes.label}}{{if .Validations.required}}{{end}}

+{{end}} +{{if .Attributes.description}} + {{RenderMarkdownToHtml .Attributes.description}} +{{end}} diff --git a/templates/repo/issue/fields/input.tmpl b/templates/repo/issue/fields/input.tmpl new file mode 100644 index 0000000000..d73354f6d3 --- /dev/null +++ b/templates/repo/issue/fields/input.tmpl @@ -0,0 +1,4 @@ +
+ {{template "repo/issue/fields/header" .}} + +
diff --git a/templates/repo/issue/fields/markdown.tmpl b/templates/repo/issue/fields/markdown.tmpl new file mode 100644 index 0000000000..8236171523 --- /dev/null +++ b/templates/repo/issue/fields/markdown.tmpl @@ -0,0 +1,3 @@ +
+
{{RenderMarkdownToHtml .Attributes.value}}
+
diff --git a/templates/repo/issue/fields/textarea.tmpl b/templates/repo/issue/fields/textarea.tmpl new file mode 100644 index 0000000000..5ad82e2460 --- /dev/null +++ b/templates/repo/issue/fields/textarea.tmpl @@ -0,0 +1,6 @@ +
+ {{template "repo/issue/fields/header" .}} + {{/* FIXME: preview markdown result */}} + {{/* FIXME: required validation for markdown editor */}} + +
diff --git a/templates/repo/issue/new.tmpl b/templates/repo/issue/new.tmpl index f8929b375d..9f46f8fddc 100644 --- a/templates/repo/issue/new.tmpl +++ b/templates/repo/issue/new.tmpl @@ -6,6 +6,14 @@ {{template "repo/issue/navbar" .}}
+ {{if .Flash.WarningMsg}} + {{/* + There's alreay a importing of alert.tmpl in new_form.tmpl, + but only the negative message will be displayed within forms for some reasons, see semantic.css:10659. + To avoid repeated negative messages, the importing here if for .Flash.WarningMsg only. + */}} + {{template "base/alert" .}} + {{end}} {{template "repo/issue/new_form" .}}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index cc6399cab4..63b124bd9e 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -16584,6 +16584,35 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "IssueFormField": { + "description": "IssueFormField represents a form field", + "type": "object", + "properties": { + "attributes": { + "type": "object", + "additionalProperties": {}, + "x-go-name": "Attributes" + }, + "id": { + "type": "string", + "x-go-name": "ID" + }, + "type": { + "$ref": "#/definitions/IssueFormFieldType" + }, + "validations": { + "type": "object", + "additionalProperties": {}, + "x-go-name": "Validations" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, + "IssueFormFieldType": { + "type": "string", + "title": "IssueFormFieldType defines issue form field type, can be \"markdown\", \"textarea\", \"input\", \"dropdown\" or \"checkboxes\"", + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "IssueLabelsOption": { "description": "IssueLabelsOption a collection of labels", "type": "object", @@ -16608,6 +16637,13 @@ "type": "string", "x-go-name": "About" }, + "body": { + "type": "array", + "items": { + "$ref": "#/definitions/IssueFormField" + }, + "x-go-name": "Fields" + }, "content": { "type": "string", "x-go-name": "Content" -- cgit v1.2.3