2022-01-28 13:00:11 -08:00
|
|
|
import $ from 'jquery';
|
2021-10-17 01:28:04 +08:00
|
|
|
import {updateIssuesMeta} from './repo-issue.js';
|
2023-02-19 12:06:14 +08:00
|
|
|
import {toggleElem} from '../utils/dom.js';
|
2021-10-17 01:28:04 +08:00
|
|
|
|
|
|
|
|
export function initCommonIssue() {
|
2023-03-30 17:02:47 +02:00
|
|
|
const $issueSelectAll = $('.issue-checkbox-all');
|
|
|
|
|
const $issueCheckboxes = $('.issue-checkbox');
|
2022-07-28 18:25:18 +08:00
|
|
|
|
|
|
|
|
const syncIssueSelectionState = () => {
|
|
|
|
|
const $checked = $issueCheckboxes.filter(':checked');
|
|
|
|
|
const anyChecked = $checked.length !== 0;
|
|
|
|
|
const allChecked = anyChecked && $checked.length === $issueCheckboxes.length;
|
|
|
|
|
|
|
|
|
|
if (allChecked) {
|
|
|
|
|
$issueSelectAll.prop({'checked': true, 'indeterminate': false});
|
|
|
|
|
} else if (anyChecked) {
|
|
|
|
|
$issueSelectAll.prop({'checked': false, 'indeterminate': true});
|
2021-10-17 01:28:04 +08:00
|
|
|
} else {
|
2022-07-28 18:25:18 +08:00
|
|
|
$issueSelectAll.prop({'checked': false, 'indeterminate': false});
|
2021-10-17 01:28:04 +08:00
|
|
|
}
|
2022-07-28 18:25:18 +08:00
|
|
|
// if any issue is selected, show the action panel, otherwise show the filter panel
|
2023-02-19 12:06:14 +08:00
|
|
|
toggleElem($('#issue-filters'), !anyChecked);
|
|
|
|
|
toggleElem($('#issue-actions'), anyChecked);
|
2022-07-28 18:25:18 +08:00
|
|
|
// there are two panels but only one select-all checkbox, so move the checkbox to the visible panel
|
2023-03-30 17:02:47 +02:00
|
|
|
$('#issue-filters, #issue-actions').filter(':visible').find('.column:first').prepend($issueSelectAll);
|
2022-07-28 18:25:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$issueCheckboxes.on('change', syncIssueSelectionState);
|
|
|
|
|
|
|
|
|
|
$issueSelectAll.on('change', () => {
|
|
|
|
|
$issueCheckboxes.prop('checked', $issueSelectAll.is(':checked'));
|
|
|
|
|
syncIssueSelectionState();
|
2021-10-17 01:28:04 +08:00
|
|
|
});
|
|
|
|
|
|
2023-02-18 20:17:39 +01:00
|
|
|
$('.issue-action').on('click', async function (e) {
|
2023-03-14 04:34:09 +01:00
|
|
|
e.preventDefault();
|
2021-11-22 09:19:01 +01:00
|
|
|
let action = this.getAttribute('data-action');
|
|
|
|
|
let elementId = this.getAttribute('data-element-id');
|
|
|
|
|
const url = this.getAttribute('data-url');
|
2023-03-30 17:02:47 +02:00
|
|
|
const issueIDs = $('.issue-checkbox:checked').map((_, el) => {
|
2021-11-22 09:19:01 +01:00
|
|
|
return el.getAttribute('data-issue-id');
|
2021-10-17 01:28:04 +08:00
|
|
|
}).get().join(',');
|
2022-02-18 07:50:36 +01:00
|
|
|
if (elementId === '0' && url.slice(-9) === '/assignee') {
|
2021-10-17 01:28:04 +08:00
|
|
|
elementId = '';
|
|
|
|
|
action = 'clear';
|
|
|
|
|
}
|
2023-02-18 20:17:39 +01:00
|
|
|
if (action === 'toggle' && e.altKey) {
|
|
|
|
|
action = 'toggle-alt';
|
|
|
|
|
}
|
2021-11-22 09:19:01 +01:00
|
|
|
updateIssuesMeta(
|
|
|
|
|
url,
|
|
|
|
|
action,
|
|
|
|
|
issueIDs,
|
|
|
|
|
elementId
|
2021-12-03 22:43:14 -08:00
|
|
|
).then(() => {
|
2021-10-17 01:28:04 +08:00
|
|
|
window.location.reload();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|