Skip to content

Commit 9e97700

Browse files
committed
Separate the webhook type selection module into a common template, New webhook page supports quick switching type
1 parent 9631958 commit 9e97700

File tree

8 files changed

+91
-58
lines changed

8 files changed

+91
-58
lines changed

routers/web/repo/setting/webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func WebhooksNew(ctx *context.Context) {
149149
"Username": "Gitea",
150150
}
151151
}
152-
ctx.Data["BaseLink"] = orCtx.LinkNew
152+
ctx.Data["BaseLinkNew"] = orCtx.LinkNew
153153

154154
ctx.HTML(http.StatusOK, orCtx.NewTemplate)
155155
}
@@ -211,7 +211,7 @@ func createWebhook(ctx *context.Context, params webhookParams) {
211211
ctx.ServerError("getOwnerRepoCtx", err)
212212
return
213213
}
214-
ctx.Data["BaseLink"] = orCtx.LinkNew
214+
ctx.Data["BaseLinkNew"] = orCtx.LinkNew
215215

216216
if ctx.HasError() {
217217
ctx.HTML(http.StatusOK, orCtx.NewTemplate)

templates/admin/hook_new.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin settings new webhook")}}
22
<div class="admin-setting-content">
3+
{{$IsNew := false}}
34
{{$CustomHeaderTitle := .locale.Tr "admin.defaulthooks.update_webhook"}}
45
{{if .PageIsAdminDefaultHooksNew}}
6+
{{$IsNew = true}}
57
{{$CustomHeaderTitle = .locale.Tr "admin.defaulthooks.add_webhook"}}
68
{{else if .PageIsAdminSystemHooksNew}}
9+
{{$IsNew = true}}
710
{{$CustomHeaderTitle = .locale.Tr "admin.systemhooks.add_webhook"}}
811
{{else if .Webhook.IsSystemWebhook}}
12+
{{$IsNew = false}}
913
{{$CustomHeaderTitle = .locale.Tr "admin.systemhooks.update_webhook"}}
1014
{{end}}
11-
{{template "webhook/new" (dict "ctxData" . "CustomHeaderTitle" $CustomHeaderTitle)}}
15+
{{template "webhook/form" (dict "ctxData" . "IsNew" $IsNew "CustomHeaderTitle" $CustomHeaderTitle)}}
1216
</div>
1317
{{template "admin/layout_footer" .}}
18+

templates/org/settings/hook_new.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{{template "org/settings/layout_head" (dict "ctxData" . "pageClass" "organization settings new webhook")}}
22
<div class="org-setting-content">
3+
{{$IsNew := false}}
34
{{$CustomHeaderTitle := .locale.Tr "repo.settings.update_webhook"}}
4-
{{if .PageIsSettingsHooksNew}}{{$CustomHeaderTitle = .locale.Tr "repo.settings.add_webhook"}}{{end}}
5-
{{template "webhook/new" (dict "ctxData" . "CustomHeaderTitle" $CustomHeaderTitle)}}
5+
{{if .PageIsSettingsHooksNew}}
6+
{{$IsNew = true}}
7+
{{$CustomHeaderTitle = .locale.Tr "repo.settings.add_webhook"}}
8+
{{end}}
9+
{{template "webhook/form" (dict "ctxData" . "IsNew" $IsNew "CustomHeaderTitle" $CustomHeaderTitle)}}
610
</div>
711
{{template "org/settings/layout_footer" .}}
12+

templates/repo/settings/webhook/base_list.tmpl

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,7 @@
33
<div class="ui right">
44
<div class="ui jump dropdown">
55
<div class="ui primary tiny button">{{.locale.Tr "repo.settings.add_webhook"}}</div>
6-
<div class="menu">
7-
<a class="item" href="{{.BaseLinkNew}}/gitea/new">
8-
{{template "shared/webhook/icon" (dict "HookType" "gitea" "Size" 20)}}
9-
{{.locale.Tr "repo.settings.web_hook_name_gitea"}}
10-
</a>
11-
<a class="item" href="{{.BaseLinkNew}}/gogs/new">
12-
{{template "shared/webhook/icon" (dict "HookType" "gogs" "Size" 20)}}
13-
{{.locale.Tr "repo.settings.web_hook_name_gogs"}}
14-
</a>
15-
<a class="item" href="{{.BaseLinkNew}}/slack/new">
16-
{{template "shared/webhook/icon" (dict "HookType" "slack" "Size" 20)}}
17-
{{.locale.Tr "repo.settings.web_hook_name_slack"}}
18-
</a>
19-
<a class="item" href="{{.BaseLinkNew}}/discord/new">
20-
{{template "shared/webhook/icon" (dict "HookType" "discord" "Size" 20)}}
21-
{{.locale.Tr "repo.settings.web_hook_name_discord"}}
22-
</a>
23-
<a class="item" href="{{.BaseLinkNew}}/dingtalk/new">
24-
{{template "shared/webhook/icon" (dict "HookType" "dingtalk" "Size" 20)}}
25-
{{.locale.Tr "repo.settings.web_hook_name_dingtalk"}}
26-
</a>
27-
<a class="item" href="{{.BaseLinkNew}}/telegram/new">
28-
{{template "shared/webhook/icon" (dict "HookType" "telegram" "Size" 20)}}
29-
{{.locale.Tr "repo.settings.web_hook_name_telegram"}}
30-
</a>
31-
<a class="item" href="{{.BaseLinkNew}}/msteams/new">
32-
{{template "shared/webhook/icon" (dict "HookType" "msteams" "Size" 20)}}
33-
{{.locale.Tr "repo.settings.web_hook_name_msteams"}}
34-
</a>
35-
<a class="item" href="{{.BaseLinkNew}}/feishu/new">
36-
{{template "shared/webhook/icon" (dict "HookType" "feishu" "Size" 20)}}
37-
{{.locale.Tr "repo.settings.web_hook_name_feishu_or_larksuite"}}
38-
</a>
39-
<a class="item" href="{{.BaseLinkNew}}/matrix/new">
40-
{{template "shared/webhook/icon" (dict "HookType" "matrix" "Size" 20)}}
41-
{{.locale.Tr "repo.settings.web_hook_name_matrix"}}
42-
</a>
43-
<a class="item" href="{{.BaseLinkNew}}/wechatwork/new">
44-
{{template "shared/webhook/icon" (dict "HookType" "wechatwork" "Size" 20)}}
45-
{{.locale.Tr "repo.settings.web_hook_name_wechatwork"}}
46-
</a>
47-
<a class="item" href="{{.BaseLinkNew}}/packagist/new">
48-
{{template "shared/webhook/icon" (dict "HookType" "packagist" "Size" 20)}}
49-
{{.locale.Tr "repo.settings.web_hook_name_packagist"}}
50-
</a>
51-
</div>
6+
{{template "webhook/selector" .}}
527
</div>
538
</div>
549
</h4>
@@ -69,3 +24,4 @@
6924
{{end}}
7025
</div>
7126
</div>
27+
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{{template "repo/settings/layout_head" (dict "ctxData" . "pageClass" "repository settings new webhook")}}
22
<div class="repo-setting-content">
3+
{{$IsNew := false}}
34
{{$CustomHeaderTitle := .locale.Tr "repo.settings.update_webhook"}}
4-
{{if .PageIsSettingsHooksNew}}{{$CustomHeaderTitle = .locale.Tr "repo.settings.add_webhook"}}{{end}}
5-
{{template "webhook/new" (dict "ctxData" . "CustomHeaderTitle" $CustomHeaderTitle)}}
5+
{{if .PageIsSettingsHooksNew}}
6+
{{$IsNew = true}}
7+
{{$CustomHeaderTitle = .locale.Tr "repo.settings.add_webhook"}}
8+
{{end}}
9+
{{template "webhook/form" (dict "ctxData" . "IsNew" $IsNew "CustomHeaderTitle" $CustomHeaderTitle)}}
610
</div>
711
{{template "repo/settings/layout_footer" .}}
12+

templates/user/settings/hook_new.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{{template "user/settings/layout_head" (dict "ctxData" . "pageClass" "user settings new webhook")}}
22
<div class="user-setting-content">
3+
{{$IsNew := false}}
34
{{$CustomHeaderTitle := .locale.Tr "repo.settings.update_webhook"}}
4-
{{if .PageIsSettingsHooksNew}}{{$CustomHeaderTitle = .locale.Tr "repo.settings.add_webhook"}}{{end}}
5-
{{template "webhook/new" (dict "ctxData" . "CustomHeaderTitle" $CustomHeaderTitle)}}
5+
{{if .PageIsSettingsHooksNew}}
6+
{{$IsNew = true}}
7+
{{$CustomHeaderTitle = .locale.Tr "repo.settings.add_webhook"}}
8+
{{end}}
9+
{{template "webhook/form" (dict "ctxData" . "IsNew" $IsNew "CustomHeaderTitle" $CustomHeaderTitle)}}
610
</div>
711
{{template "user/settings/layout_footer" .}}
12+

templates/webhook/new.tmpl renamed to templates/webhook/form.tmpl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
<h4 class="ui top attached header">
22
{{.CustomHeaderTitle}}
3-
<div class="ui right">
4-
{{template "shared/webhook/icon" .ctxData}}
5-
</div>
3+
{{if .IsNew}}
4+
<div class="ui right jump dropdown">
5+
<div class="ui primary tiny">
6+
{{template "shared/webhook/icon" .ctxData}}
7+
</div>
8+
{{template "webhook/selector" .ctxData}}
9+
</div>
10+
{{else}}
11+
<div class="ui right">
12+
{{template "shared/webhook/icon" .ctxData}}
13+
</div>
14+
{{end}}
615
</h4>
716
<div class="ui attached segment">
817
{{template "repo/settings/webhook/gitea" .ctxData}}
@@ -18,3 +27,4 @@
1827
{{template "repo/settings/webhook/packagist" .ctxData}}
1928
</div>
2029
{{template "repo/settings/webhook/history" .ctxData}}
30+

templates/webhook/selector.tmpl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<div class="menu">
2+
<a class="item" href="{{.BaseLinkNew}}/gitea/new">
3+
{{template "shared/webhook/icon" (dict "HookType" "gitea" "Size" 20)}}
4+
{{.locale.Tr "repo.settings.web_hook_name_gitea"}}
5+
</a>
6+
<a class="item" href="{{.BaseLinkNew}}/gogs/new">
7+
{{template "shared/webhook/icon" (dict "HookType" "gogs" "Size" 20)}}
8+
{{.locale.Tr "repo.settings.web_hook_name_gogs"}}
9+
</a>
10+
<a class="item" href="{{.BaseLinkNew}}/slack/new">
11+
{{template "shared/webhook/icon" (dict "HookType" "slack" "Size" 20)}}
12+
{{.locale.Tr "repo.settings.web_hook_name_slack"}}
13+
</a>
14+
<a class="item" href="{{.BaseLinkNew}}/discord/new">
15+
{{template "shared/webhook/icon" (dict "HookType" "discord" "Size" 20)}}
16+
{{.locale.Tr "repo.settings.web_hook_name_discord"}}
17+
</a>
18+
<a class="item" href="{{.BaseLinkNew}}/dingtalk/new">
19+
{{template "shared/webhook/icon" (dict "HookType" "dingtalk" "Size" 20)}}
20+
{{.locale.Tr "repo.settings.web_hook_name_dingtalk"}}
21+
</a>
22+
<a class="item" href="{{.BaseLinkNew}}/telegram/new">
23+
{{template "shared/webhook/icon" (dict "HookType" "telegram" "Size" 20)}}
24+
{{.locale.Tr "repo.settings.web_hook_name_telegram"}}
25+
</a>
26+
<a class="item" href="{{.BaseLinkNew}}/msteams/new">
27+
{{template "shared/webhook/icon" (dict "HookType" "msteams" "Size" 20)}}
28+
{{.locale.Tr "repo.settings.web_hook_name_msteams"}}
29+
</a>
30+
<a class="item" href="{{.BaseLinkNew}}/feishu/new">
31+
{{template "shared/webhook/icon" (dict "HookType" "feishu" "Size" 20)}}
32+
{{.locale.Tr "repo.settings.web_hook_name_feishu_or_larksuite"}}
33+
</a>
34+
<a class="item" href="{{.BaseLinkNew}}/matrix/new">
35+
{{template "shared/webhook/icon" (dict "HookType" "matrix" "Size" 20)}}
36+
{{.locale.Tr "repo.settings.web_hook_name_matrix"}}
37+
</a>
38+
<a class="item" href="{{.BaseLinkNew}}/wechatwork/new">
39+
{{template "shared/webhook/icon" (dict "HookType" "wechatwork" "Size" 20)}}
40+
{{.locale.Tr "repo.settings.web_hook_name_wechatwork"}}
41+
</a>
42+
<a class="item" href="{{.BaseLinkNew}}/packagist/new">
43+
{{template "shared/webhook/icon" (dict "HookType" "packagist" "Size" 20)}}
44+
{{.locale.Tr "repo.settings.web_hook_name_packagist"}}
45+
</a>
46+
</div>
47+

0 commit comments

Comments
 (0)