From 58015babdd3f9be7e457c0c40abb4afb7e3705ae Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 14 Jun 2023 17:27:26 +0800 Subject: [PATCH 1/8] fix --- modules/context/base.go | 4 +++ options/locale/locale_en-US.ini | 1 + routers/web/repo/issue.go | 18 ++++++++++--- routers/web/web.go | 1 + templates/devtest/fetch-action.tmpl | 4 ++- templates/repo/issue/list.tmpl | 6 +++++ web_src/js/features/common-global.js | 32 ++++++------------------ web_src/js/features/comp/ConfirmModal.js | 29 +++++++++++++++++++++ web_src/js/features/repo-issue-list.js | 28 +++++++++++++++++---- 9 files changed, 90 insertions(+), 33 deletions(-) create mode 100644 web_src/js/features/comp/ConfirmModal.js diff --git a/modules/context/base.go b/modules/context/base.go index 5ae5e65d3ed41..81fd92fd7e61b 100644 --- a/modules/context/base.go +++ b/modules/context/base.go @@ -136,6 +136,10 @@ func (b *Base) JSONRedirect(redirect string) { b.JSON(http.StatusOK, map[string]any{"redirect": redirect}) } +func (b *Base) JSONOK() { + b.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it +} + // RemoteAddr returns the client machine ip address func (b *Base) RemoteAddr() string { return b.Req.RemoteAddr diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index db5a45f6127c6..bc72cdc1034e0 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1412,6 +1412,7 @@ issues.filter_sort.fewestforks = Fewest forks issues.keyword_search_unavailable = Currently searching by keyword is not available. Please contact your site administrator. issues.action_open = Open issues.action_close = Close +issues.action_delete_confirm = Confirm to delete all issues? issues.action_label = Label issues.action_milestone = Milestone issues.action_milestone_no_select = No milestone diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 5ab8db2e057fe..b40fe662c7040 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2705,6 +2705,20 @@ func ListIssues(ctx *context.Context) { ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues)) } +func BatchDeleteIssues(ctx *context.Context) { + issues := getActionIssues(ctx) + if ctx.Written() { + return + } + for _, issue := range issues { + if err := issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil { + ctx.ServerError("DeleteIssue", err) + return + } + } + ctx.JSONOK() +} + // UpdateIssueStatus change issue's status func UpdateIssueStatus(ctx *context.Context) { issues := getActionIssues(ctx) @@ -2740,9 +2754,7 @@ func UpdateIssueStatus(ctx *context.Context) { } } } - ctx.JSON(http.StatusOK, map[string]interface{}{ - "ok": true, - }) + ctx.JSONOK() } // NewComment create a comment for issue diff --git a/routers/web/web.go b/routers/web/web.go index 8683ef221dd97..37ebbaebe4388 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1029,6 +1029,7 @@ func registerRoutes(m *web.Route) { m.Post("/request_review", reqRepoIssuesOrPullsReader, repo.UpdatePullReviewRequest) m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview) m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus) + m.Post("/delete", reqRepoAdmin, repo.BatchDeleteIssues) m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.UpdateResolveConversation) m.Post("/attachments", repo.UploadIssueAttachment) m.Post("/attachments/remove", repo.DeleteAttachment) diff --git a/templates/devtest/fetch-action.tmpl b/templates/devtest/fetch-action.tmpl index 2fb7289ebe9a7..70844a8751ab3 100644 --- a/templates/devtest/fetch-action.tmpl +++ b/templates/devtest/fetch-action.tmpl @@ -8,7 +8,9 @@ It might be renamed to "link-fetch-action" to match the "form-fetch-action".
- + + +
diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 3323bf893e047..6a62167b14efe 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -285,6 +285,12 @@ {{else}} {{end}} + {{if $.IsRepoAdmin}} + + {{end}}