Skip to content

Commit 16b245c

Browse files
committed
refactor
1 parent fcb9ef8 commit 16b245c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+744
-820
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@citation-js/plugin-csl": "0.6.7",
1313
"@citation-js/plugin-software-formats": "0.6.0",
1414
"@claviska/jquery-minicolors": "2.3.6",
15+
"@github/markdown-toolbar-element": "2.1.1",
1516
"@mcaptcha/vanilla-glue": "0.1.0-alpha-3",
1617
"@primer/octicons": "18.2.0",
1718
"@vue/compiler-sfc": "3.2.47",

routers/web/devtest/devtest.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package devtest
5+
6+
import (
7+
"net/http"
8+
"path"
9+
"strings"
10+
11+
"code.gitea.io/gitea/modules/base"
12+
"code.gitea.io/gitea/modules/context"
13+
"code.gitea.io/gitea/modules/templates"
14+
)
15+
16+
// List all devtest templates, they will be used for e2e tests for the UI components
17+
func List(ctx *context.Context) {
18+
templateNames := templates.GetTemplateAssetNames()
19+
var subNames []string
20+
const prefix = "templates/devtest/"
21+
for _, tmplName := range templateNames {
22+
if strings.HasPrefix(tmplName, prefix) {
23+
subName := strings.TrimSuffix(strings.TrimPrefix(tmplName, prefix), ".tmpl")
24+
if subName != "list" {
25+
subNames = append(subNames, subName)
26+
}
27+
}
28+
}
29+
ctx.Data["SubNames"] = subNames
30+
ctx.HTML(http.StatusOK, "devtest/list")
31+
}
32+
33+
func Tmpl(ctx *context.Context) {
34+
ctx.HTML(http.StatusOK, base.TplName("devtest"+path.Clean("/"+ctx.Params("sub"))))
35+
}

routers/web/misc/markup.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,6 @@ import (
1515

1616
// Markup render markup document to HTML
1717
func Markup(ctx *context.Context) {
18-
// swagger:operation POST /markup miscellaneous renderMarkup
19-
// ---
20-
// summary: Render a markup document as HTML
21-
// parameters:
22-
// - name: body
23-
// in: body
24-
// schema:
25-
// "$ref": "#/definitions/MarkupOption"
26-
// consumes:
27-
// - application/json
28-
// produces:
29-
// - text/html
30-
// responses:
31-
// "200":
32-
// "$ref": "#/responses/MarkupRender"
33-
// "422":
34-
// "$ref": "#/responses/validationError"
35-
3618
form := web.GetForm(ctx).(*api.MarkupOption)
3719

3820
if ctx.HasAPIError() {

routers/web/org/setting.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ func Labels(ctx *context.Context) {
246246
ctx.Data["Title"] = ctx.Tr("repo.labels")
247247
ctx.Data["PageIsOrgSettings"] = true
248248
ctx.Data["PageIsOrgSettingsLabels"] = true
249-
ctx.Data["RequireTribute"] = true
250249
ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
251250
ctx.HTML(http.StatusOK, tplSettingsLabels)
252251
}

routers/web/repo/commit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ func FileHistory(ctx *context.Context) {
253253
// Diff show different from current commit to previous commit
254254
func Diff(ctx *context.Context) {
255255
ctx.Data["PageIsDiff"] = true
256-
ctx.Data["RequireTribute"] = true
257256

258257
userName := ctx.Repo.Owner.Name
259258
repoName := ctx.Repo.Repository.Name

routers/web/repo/compare.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ func CompareDiff(ctx *context.Context) {
781781

782782
ctx.Data["IsRepoToolbarCommits"] = true
783783
ctx.Data["IsDiffCompare"] = true
784-
ctx.Data["RequireTribute"] = true
785784
templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates)
786785

787786
if len(templateErrs) > 0 {

routers/web/repo/editor.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ func DeleteFilePost(ctx *context.Context) {
538538
// UploadFile render upload file page
539539
func UploadFile(ctx *context.Context) {
540540
ctx.Data["PageIsUpload"] = true
541-
ctx.Data["RequireTribute"] = true
542541
upload.AddUploadContext(ctx, "repo")
543542
canCommit := renderCommitRights(ctx)
544543
treePath := cleanUploadFileName(ctx.Repo.TreePath)
@@ -573,7 +572,6 @@ func UploadFile(ctx *context.Context) {
573572
func UploadFilePost(ctx *context.Context) {
574573
form := web.GetForm(ctx).(*forms.UploadRepoFileForm)
575574
ctx.Data["PageIsUpload"] = true
576-
ctx.Data["RequireTribute"] = true
577575
upload.AddUploadContext(ctx, "repo")
578576
canCommit := renderCommitRights(ctx)
579577

routers/web/repo/issue.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,6 @@ func NewIssue(ctx *context.Context) {
849849
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
850850
ctx.Data["PageIsIssueList"] = true
851851
ctx.Data["NewIssueChooseTemplate"] = ctx.HasIssueTemplatesOrContactLinks()
852-
ctx.Data["RequireTribute"] = true
853852
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
854853
title := ctx.FormString("title")
855854
ctx.Data["TitleQuery"] = title
@@ -1295,7 +1294,6 @@ func ViewIssue(ctx *context.Context) {
12951294
ctx.Data["IssueType"] = "all"
12961295
}
12971296

1298-
ctx.Data["RequireTribute"] = true
12991297
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects)
13001298
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
13011299
upload.AddUploadContext(ctx, "comment")

routers/web/repo/issue_label.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func Labels(ctx *context.Context) {
2828
ctx.Data["Title"] = ctx.Tr("repo.labels")
2929
ctx.Data["PageIsIssueList"] = true
3030
ctx.Data["PageIsLabels"] = true
31-
ctx.Data["RequireTribute"] = true
3231
ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
3332
ctx.HTML(http.StatusOK, tplLabels)
3433
}

routers/web/repo/pull.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,6 @@ func ViewPullFiles(ctx *context.Context) {
791791

792792
setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
793793

794-
ctx.Data["RequireTribute"] = true
795794
if ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository); err != nil {
796795
ctx.ServerError("GetAssignees", err)
797796
return
@@ -1160,7 +1159,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
11601159
ctx.Data["PageIsComparePull"] = true
11611160
ctx.Data["IsDiffCompare"] = true
11621161
ctx.Data["IsRepoToolbarCommits"] = true
1163-
ctx.Data["RequireTribute"] = true
11641162
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
11651163
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
11661164
upload.AddUploadContext(ctx, "comment")

routers/web/repo/release.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ func LatestRelease(ctx *context.Context) {
308308
func NewRelease(ctx *context.Context) {
309309
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
310310
ctx.Data["PageIsReleaseList"] = true
311-
ctx.Data["RequireTribute"] = true
312311
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
313312
if tagName := ctx.FormString("tag"); len(tagName) > 0 {
314313
rel, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName)
@@ -351,7 +350,6 @@ func NewReleasePost(ctx *context.Context) {
351350
form := web.GetForm(ctx).(*forms.NewReleaseForm)
352351
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
353352
ctx.Data["PageIsReleaseList"] = true
354-
ctx.Data["RequireTribute"] = true
355353

356354
if ctx.HasError() {
357355
ctx.HTML(http.StatusOK, tplReleaseNew)
@@ -469,7 +467,6 @@ func EditRelease(ctx *context.Context) {
469467
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
470468
ctx.Data["PageIsReleaseList"] = true
471469
ctx.Data["PageIsEditRelease"] = true
472-
ctx.Data["RequireTribute"] = true
473470
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
474471
upload.AddUploadContext(ctx, "release")
475472

@@ -514,7 +511,6 @@ func EditReleasePost(ctx *context.Context) {
514511
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
515512
ctx.Data["PageIsReleaseList"] = true
516513
ctx.Data["PageIsEditRelease"] = true
517-
ctx.Data["RequireTribute"] = true
518514

519515
tagName := ctx.Params("*")
520516
rel, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName)

routers/web/web.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"code.gitea.io/gitea/modules/web/routing"
2828
"code.gitea.io/gitea/routers/web/admin"
2929
"code.gitea.io/gitea/routers/web/auth"
30+
"code.gitea.io/gitea/routers/web/devtest"
3031
"code.gitea.io/gitea/routers/web/events"
3132
"code.gitea.io/gitea/routers/web/explore"
3233
"code.gitea.io/gitea/routers/web/feed"
@@ -1491,6 +1492,12 @@ func RegisterRoutes(m *web.Route) {
14911492
if setting.API.EnableSwagger {
14921493
m.Get("/swagger.v1.json", SwaggerV1Json)
14931494
}
1495+
1496+
if !setting.IsProd {
1497+
m.Any("/devtest", devtest.List)
1498+
m.Any("/devtest/{sub}", devtest.Tmpl)
1499+
}
1500+
14941501
m.NotFound(func(w http.ResponseWriter, req *http.Request) {
14951502
ctx := context.GetContext(req)
14961503
ctx.NotFound("", nil)

templates/base/head_script.tmpl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,19 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
1515
useServiceWorker: {{UseServiceWorker}},
1616
csrfToken: '{{.CsrfToken}}',
1717
pageData: {{.PageData}},
18-
requireTribute: {{.RequireTribute}},
1918
notificationSettings: {{NotificationSettings}}, {{/*a map provided by NewFuncMap in helper.go*/}}
2019
enableTimeTracking: {{EnableTimetracking}},
21-
{{if .RequireTribute}}
20+
{{if or .Participants .Assignees .MentionableTeams}}
2221
tributeValues: Array.from(new Map([
23-
{{range .Participants}}
24-
['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}',
25-
name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.AvatarLink $.Context}}'}],
26-
{{end}}
27-
{{range .Assignees}}
28-
['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}',
29-
name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.AvatarLink $.Context}}'}],
30-
{{end}}
31-
{{range .MentionableTeams}}
32-
['{{$.MentionableTeamsOrg}}/{{.Name}}', {key: '{{$.MentionableTeamsOrg}}/{{.Name}}', value: '{{$.MentionableTeamsOrg}}/{{.Name}}',
33-
name: '{{$.MentionableTeamsOrg}}/{{.Name}}', avatar: '{{$.MentionableTeamsOrgAvatar}}'}],
34-
{{end}}
22+
{{- range .Participants -}}
23+
['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}', name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.AvatarLink $.Context}}'}],
24+
{{- end -}}
25+
{{- range .Assignees -}}
26+
['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}', name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.AvatarLink $.Context}}'}],
27+
{{- end -}}
28+
{{- range .MentionableTeams -}}
29+
['{{$.MentionableTeamsOrg}}/{{.Name}}', {key: '{{$.MentionableTeamsOrg}}/{{.Name}}', value: '{{$.MentionableTeamsOrg}}/{{.Name}}', name: '{{$.MentionableTeamsOrg}}/{{.Name}}', avatar: '{{$.MentionableTeamsOrgAvatar}}'}],
30+
{{- end -}}
3531
]).values()),
3632
{{end}}
3733
mermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}},

templates/devtest/gitea-ui.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{template "base/head" .}}
2+
3+
<div class="page-content devtest">
4+
5+
<div>
6+
<gitea-origin-url data-url="test/url"></gitea-origin-url>
7+
<gitea-origin-url data-url="/test/url"></gitea-origin-url>
8+
</div>
9+
10+
<div>
11+
<span data-tooltip-content="test tooltip">text with tooltip</span>
12+
</div>
13+
14+
{{template "shared/combomarkdowneditor" .}}
15+
16+
</div>
17+
18+
{{template "base/footer" .}}

templates/devtest/list.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul>
2+
{{range .SubNames}}
3+
<li><a href="{{AppSubUrl}}/devtest/{{.}}">{{.}}</a></li>
4+
{{end}}
5+
</ul>

templates/repo/diff/box.tmpl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,21 @@
198198
</div>
199199

200200
{{if not $.Repository.IsArchived}}
201-
<div class="gt-hidden" id="edit-content-form">
201+
<template id="issue-comment-editor-template">
202202
<div class="ui comment form">
203-
<div class="ui top attached tabular menu">
204-
<a class="active write item">{{$.locale.Tr "write"}}</a>
205-
<a class="preview item" data-url="{{$.Repository.Link}}/markup" data-context="{{$.RepoLink}}">{{$.locale.Tr "preview"}}</a>
206-
</div>
207-
<div class="ui bottom attached active write tab segment">
208-
<textarea class="review-textarea js-quick-submit" tabindex="1" name="content"></textarea>
209-
</div>
210-
<div class="ui bottom attached tab preview segment markup">
211-
{{$.locale.Tr "loading"}}
212-
</div>
203+
{{template "shared/combomarkdowneditor" (dict
204+
"locale" $.locale
205+
"MarkdownPreviewUrl" (print $.Repository.Link "/markup")
206+
"MarkdownPreviewContext" $.RepoLink
207+
"TextareaName" "content"
208+
"DropzoneParentContainer" ".ui.form"
209+
)}}
213210
<div class="text right edit buttons">
214211
<button class="ui basic primary cancel button" tabindex="3">{{.locale.Tr "repo.issues.cancel"}}</button>
215212
<button class="ui green save button" tabindex="2">{{.locale.Tr "repo.issues.save"}}</button>
216213
</div>
217214
</div>
218-
</div>
215+
</template>
219216
{{end}}
220217

221218
{{template "repo/issue/view_content/reference_issue_dialog" .}}

templates/repo/diff/comment_form.tmpl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
<input type="hidden" name="diff_start_cid">
1010
<input type="hidden" name="diff_end_cid">
1111
<input type="hidden" name="diff_base_cid">
12-
<div class="ui top tabular menu" data-write="write" data-preview="preview">
13-
<a class="active item" data-tab="write">{{$.root.locale.Tr "write"}}</a>
14-
<a class="item" data-tab="preview" data-url="{{$.root.Repository.Link}}/markup" data-context="{{$.root.RepoLink}}">{{$.root.locale.Tr "preview"}}</a>
15-
</div>
16-
<div class="field">
17-
<div class="ui active tab" data-tab="write">
18-
<textarea name="content" placeholder="{{$.root.locale.Tr "repo.diff.comment.placeholder"}}"></textarea>
19-
</div>
20-
<div class="ui tab markup" data-tab="preview">
21-
{{.locale.Tr "loading"}}
22-
</div>
23-
</div>
12+
13+
{{template "shared/combomarkdowneditor" (dict
14+
"locale" $.root.locale
15+
"MarkdownPreviewUrl" (print $.root.Repository.Link "/markup")
16+
"MarkdownPreviewContext" $.root.RepoLink
17+
"TextareaName" "content"
18+
"TextareaPlaceholder" ($.locale.Tr "repo.diff.comment.placeholder")
19+
"DropzoneParentContainer" "form"
20+
)}}
21+
2422
<div class="field footer gt-mx-3">
2523
<span class="markup-info">{{svg "octicon-markup"}} {{$.root.locale.Tr "repo.diff.comment.markdown_info"}}</span>
2624
<div class="ui right">

templates/repo/diff/new_review.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
<div class="review-box-panel tippy-target">
88
<div class="ui segment">
99
<form class="ui form" action="{{.Link}}/reviews/submit" method="post">
10-
{{.CsrfTokenHtml}}
10+
{{.CsrfTokenHtml}}
1111
<input type="hidden" name="commit_id" value="{{.AfterCommitID}}">
1212
<div class="header gt-df gt-ac gt-pb-3">
1313
<div class="gt-f1">{{$.locale.Tr "repo.diff.review.header"}}</div>
1414
<a class="muted close gt-px-3">{{svg "octicon-x" 16}}</a>
1515
</div>
1616
<div class="ui field">
17-
<textarea name="content" tabindex="0" rows="2" placeholder="{{$.locale.Tr "repo.diff.review.placeholder"}}"></textarea>
17+
{{template "shared/combomarkdowneditor" (dict
18+
"locale" $.locale
19+
"TextareaName" "content"
20+
"TextareaPlaceholder" ($.locale.Tr "repo.diff.review.placeholder")
21+
"DropzoneParentContainer" "form"
22+
)}}
1823
</div>
1924
{{if .IsAttachmentEnabled}}
2025
<div class="field">

templates/repo/issue/comment_tab.tmpl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<div class="ui top tabular menu" data-write="write" data-preview="preview">
2-
<a class="active item" data-tab="write">{{.locale.Tr "write"}}</a>
3-
<a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}">{{.locale.Tr "preview"}}</a>
4-
</div>
5-
<div class="field">
6-
<div class="ui bottom active tab" data-tab="write">
7-
<textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{.Repository.Link}}/markup" data-context="{{.Repo.RepoLink}}">
8-
{{- if .BodyQuery}}{{.BodyQuery}}{{else if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end -}}
9-
</textarea>
10-
</div>
11-
<div class="ui bottom tab markup" data-tab="preview">
12-
{{.locale.Tr "loading"}}
13-
</div>
14-
</div>
1+
{{$textareaContent := .BodyQuery}}
2+
{{if not $textareaContent}}{{$textareaContent = .IssueTemplate}}{{end}}
3+
{{if not $textareaContent}}{{$textareaContent = .PullRequestTemplate}}{{end}}
4+
{{if not $textareaContent}}{{$textareaContent = .content}}{{end}}
5+
6+
{{template "shared/combomarkdowneditor" (dict
7+
"locale" $.locale
8+
"MarkdownPreviewUrl" (print .Repository.Link "/markup")
9+
"MarkdownPreviewContext" .RepoLink
10+
"TextareaName" "content"
11+
"TextareaContent" $textareaContent
12+
"DropzoneParentContainer" "form, .ui.form"
13+
)}}
14+
1515
{{if .IsAttachmentEnabled}}
1616
<div class="field">
1717
{{template "repo/upload" .}}

0 commit comments

Comments
 (0)