From a1c5057fe81c25dfd1777e9625eb5480c45897ea Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 19 Jun 2023 15:46:50 +0800 Subject: [PATCH] Batch delete issue and improve tippy opts (#25253) 1. Add "batch delete" button for selected issues, close #22273 2. Address the review in https://github.com/go-gitea/gitea/pull/25219#discussion_r1229266083 --- modules/context/base.go | 4 +++ options/locale/locale_en-US.ini | 2 ++ routers/web/repo/issue.go | 18 ++++++++++--- routers/web/web.go | 1 + templates/devtest/fetch-action.tmpl | 4 ++- templates/repo/issue/list.tmpl | 10 ++++++-- web_src/js/features/common-global.js | 32 ++++++------------------ web_src/js/features/comp/ConfirmModal.js | 30 ++++++++++++++++++++++ web_src/js/features/repo-issue-list.js | 28 +++++++++++++++++---- web_src/js/modules/tippy.js | 22 ++++++++-------- 10 files changed, 104 insertions(+), 47 deletions(-) create mode 100644 web_src/js/features/comp/ConfirmModal.js diff --git a/modules/context/base.go b/modules/context/base.go index 45f33feb08..839f3e10df 100644 --- a/modules/context/base.go +++ b/modules/context/base.go @@ -140,6 +140,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 +} + func (b *Base) JSONError(msg string) { b.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg}) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 25456d0493..6cab7c0cbb 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -130,6 +130,8 @@ show_timestamps = Show timestamps show_log_seconds = Show seconds show_full_screen = Show full screen +confirm_delete_selected = Confirm to delete all selected items? + [aria] navbar = Navigation Bar footer = Footer diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 9f087edc72..49ba753a7d 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 fae935a507..8ac01f1742 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1024,6 +1024,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 2fb7289ebe..70844a8751 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 5c9a5937a1..12eb31acdc 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -282,9 +282,15 @@ {{if not .Repository.IsArchived}} {{if .IsShowClosed}} - + {{else}} - + + {{end}} + {{if $.IsRepoAdmin}} + {{end}}