Skip to content

Commit 58015ba

Browse files
committed
fix
1 parent a43ea22 commit 58015ba

File tree

9 files changed

+90
-33
lines changed

9 files changed

+90
-33
lines changed

modules/context/base.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func (b *Base) JSONRedirect(redirect string) {
136136
b.JSON(http.StatusOK, map[string]any{"redirect": redirect})
137137
}
138138

139+
func (b *Base) JSONOK() {
140+
b.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it
141+
}
142+
139143
// RemoteAddr returns the client machine ip address
140144
func (b *Base) RemoteAddr() string {
141145
return b.Req.RemoteAddr

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,7 @@ issues.filter_sort.fewestforks = Fewest forks
14121412
issues.keyword_search_unavailable = Currently searching by keyword is not available. Please contact your site administrator.
14131413
issues.action_open = Open
14141414
issues.action_close = Close
1415+
issues.action_delete_confirm = Confirm to delete all issues?
14151416
issues.action_label = Label
14161417
issues.action_milestone = Milestone
14171418
issues.action_milestone_no_select = No milestone

routers/web/repo/issue.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,20 @@ func ListIssues(ctx *context.Context) {
27052705
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues))
27062706
}
27072707

2708+
func BatchDeleteIssues(ctx *context.Context) {
2709+
issues := getActionIssues(ctx)
2710+
if ctx.Written() {
2711+
return
2712+
}
2713+
for _, issue := range issues {
2714+
if err := issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
2715+
ctx.ServerError("DeleteIssue", err)
2716+
return
2717+
}
2718+
}
2719+
ctx.JSONOK()
2720+
}
2721+
27082722
// UpdateIssueStatus change issue's status
27092723
func UpdateIssueStatus(ctx *context.Context) {
27102724
issues := getActionIssues(ctx)
@@ -2740,9 +2754,7 @@ func UpdateIssueStatus(ctx *context.Context) {
27402754
}
27412755
}
27422756
}
2743-
ctx.JSON(http.StatusOK, map[string]interface{}{
2744-
"ok": true,
2745-
})
2757+
ctx.JSONOK()
27462758
}
27472759

27482760
// NewComment create a comment for issue

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ func registerRoutes(m *web.Route) {
10291029
m.Post("/request_review", reqRepoIssuesOrPullsReader, repo.UpdatePullReviewRequest)
10301030
m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview)
10311031
m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus)
1032+
m.Post("/delete", reqRepoAdmin, repo.BatchDeleteIssues)
10321033
m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.UpdateResolveConversation)
10331034
m.Post("/attachments", repo.UploadIssueAttachment)
10341035
m.Post("/attachments/remove", repo.DeleteAttachment)

templates/devtest/fetch-action.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
It might be renamed to "link-fetch-action" to match the "form-fetch-action".
99
</div>
1010
<div>
11-
<button class="link-action" data-url="fetch-action-test?k=1">test</button>
11+
<button class="link-action" data-url="fetch-action-test?k=1">test action</button>
12+
<button class="link-action" data-url="fetch-action-test?k=1" data-modal-confirm="confirm?">test with confirm</button>
13+
<button class="ui red button link-action" data-url="fetch-action-test?k=1" data-modal-confirm="confirm?">test with risky confirm</button>
1214
</div>
1315
</div>
1416
<div>

templates/repo/issue/list.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@
285285
{{else}}
286286
<button class="ui red active basic button issue-action gt-ml-auto" data-action="close" data-url="{{$.RepoLink}}/issues/status">{{.locale.Tr "repo.issues.action_close"}}</button>
287287
{{end}}
288+
{{if $.IsRepoAdmin}}
289+
<button class="ui red active basic button issue-action gt-ml-auto"
290+
data-action="delete" data-url="{{$.RepoLink}}/issues/delete"
291+
data-action-delete-confirm="{{.locale.Tr "repo.issues.action_delete_confirm"}}"
292+
>{{.locale.Tr "repo.issues.delete"}}</button>
293+
{{end}}
288294
<!-- Labels -->
289295
<div class="ui {{if not .Labels}}disabled{{end}} dropdown jump item">
290296
<span class="text">

web_src/js/features/common-global.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {svg} from '../svg.js';
88
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
99
import {htmlEscape} from 'escape-goat';
1010
import {createTippy} from '../modules/tippy.js';
11+
import {confirmModal} from "./comp/ConfirmModal.js";
1112

1213
const {appUrl, csrfToken, i18n} = window.config;
1314

@@ -250,7 +251,7 @@ export function initGlobalDropzone() {
250251
}
251252
}
252253

253-
function linkAction(e) {
254+
async function linkAction(e) {
254255
e.preventDefault();
255256

256257
// A "link-action" can post AJAX request to its "data-url"
@@ -277,33 +278,16 @@ function linkAction(e) {
277278
});
278279
};
279280

280-
const modalConfirmHtml = htmlEscape($this.attr('data-modal-confirm') || '');
281-
if (!modalConfirmHtml) {
281+
const modalConfirmContent = htmlEscape($this.attr('data-modal-confirm') || '');
282+
if (!modalConfirmContent) {
282283
doRequest();
283284
return;
284285
}
285286

286-
const okButtonColor = $this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative') ? 'orange' : 'green';
287-
288-
const $modal = $(`
289-
<div class="ui g-modal-confirm modal">
290-
<div class="content">${modalConfirmHtml}</div>
291-
<div class="actions">
292-
<button class="ui basic cancel button">${svg('octicon-x')} ${i18n.modal_cancel}</button>
293-
<button class="ui ${okButtonColor} ok button">${svg('octicon-check')} ${i18n.modal_confirm}</button>
294-
</div>
295-
</div>
296-
`);
297-
298-
$modal.appendTo(document.body);
299-
$modal.modal({
300-
onApprove() {
301-
doRequest();
302-
},
303-
onHidden() {
304-
$modal.remove();
305-
},
306-
}).modal('show');
287+
const isRisky = $this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative');
288+
if (await confirmModal({content: modalConfirmContent, buttonColor: isRisky ? 'orange' : 'green'})) {
289+
doRequest();
290+
}
307291
}
308292

309293
export function initGlobalLinkActions() {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import $ from 'jquery';
2+
import {svg} from '../../svg.js';
3+
import {htmlEscape} from 'escape-goat';
4+
5+
export async function confirmModal(opts = {content: '', buttonColor: 'green'}) {
6+
return new Promise((resolve) => {
7+
const i18n = window.config.i18n;
8+
const $modal = $(`
9+
<div class="ui g-modal-confirm modal">
10+
<div class="content">${htmlEscape(opts.content)}</div>
11+
<div class="actions">
12+
<button class="ui basic cancel button">${svg('octicon-x')} ${i18n.modal_cancel}</button>
13+
<button class="ui ${opts.buttonColor || 'green'} ok button">${svg('octicon-check')} ${i18n.modal_confirm}</button>
14+
</div>
15+
</div>
16+
`);
17+
18+
$modal.appendTo(document.body);
19+
$modal.modal({
20+
onApprove() {
21+
resolve(true);
22+
},
23+
onHidden() {
24+
$modal.remove();
25+
resolve(false);
26+
},
27+
}).modal('show');
28+
});
29+
}

web_src/js/features/repo-issue-list.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {updateIssuesMeta} from './repo-issue.js';
33
import {toggleElem} from '../utils/dom.js';
44
import {htmlEscape} from 'escape-goat';
55
import {Sortable} from 'sortablejs';
6+
import {confirmModal} from "./comp/ConfirmModal.js";
67

78
function initRepoIssueListCheckboxes() {
89
const $issueSelectAll = $('.issue-checkbox-all');
@@ -36,19 +37,36 @@ function initRepoIssueListCheckboxes() {
3637

3738
$('.issue-action').on('click', async function (e) {
3839
e.preventDefault();
40+
41+
const url = this.getAttribute('data-url');
3942
let action = this.getAttribute('data-action');
4043
let elementId = this.getAttribute('data-element-id');
41-
const url = this.getAttribute('data-url');
42-
const issueIDs = $('.issue-checkbox:checked').map((_, el) => {
43-
return el.getAttribute('data-issue-id');
44-
}).get().join(',');
45-
if (elementId === '0' && url.slice(-9) === '/assignee') {
44+
let issueIDs = [];
45+
for (const el of document.querySelectorAll('.issue-checkbox:checked')) {
46+
issueIDs.push(el.getAttribute('data-issue-id'));
47+
}
48+
issueIDs = issueIDs.join(',');
49+
if (!issueIDs) return;
50+
51+
// for assignee
52+
if (elementId === '0' && url.endsWith('/assignee')) {
4653
elementId = '';
4754
action = 'clear';
4855
}
56+
57+
// for toggle
4958
if (action === 'toggle' && e.altKey) {
5059
action = 'toggle-alt';
5160
}
61+
62+
// for delete
63+
if (action === 'delete') {
64+
const confirmText = e.target.getAttribute('data-action-delete-confirm');
65+
if (!await confirmModal({content: confirmText, buttonColor: 'orange'})) {
66+
return;
67+
}
68+
}
69+
5270
updateIssuesMeta(
5371
url,
5472
action,

0 commit comments

Comments
 (0)