Support sorting for project board issuses (#17152)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Anbraten 2021-12-08 07:57:18 +01:00 committed by GitHub
parent 4cbe792562
commit 0ff18a808c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 115 additions and 58 deletions

View file

@ -1,5 +1,29 @@
const {csrfToken} = window.config;
function moveIssue({item, from, to, oldIndex}) {
const columnCards = to.getElementsByClassName('board-card');
const columnSorting = {
issues: [...columnCards].map((card, i) => ({
issueID: parseInt($(card).attr('data-issue')),
sorting: i
}))
};
$.ajax({
url: `${to.getAttribute('data-url')}/move`,
data: JSON.stringify(columnSorting),
headers: {
'X-Csrf-Token': csrfToken,
},
contentType: 'application/json',
type: 'POST',
error: () => {
from.insertBefore(item, from.children[oldIndex]);
}
});
}
async function initRepoProjectSortable() {
const els = document.querySelectorAll('#project-board > .board');
if (!els.length) return;
@ -40,20 +64,8 @@ async function initRepoProjectSortable() {
group: 'shared',
animation: 150,
ghostClass: 'card-ghost',
onAdd: ({item, from, to, oldIndex}) => {
const url = to.getAttribute('data-url');
const issue = item.getAttribute('data-issue');
$.ajax(`${url}/${issue}`, {
headers: {
'X-Csrf-Token': csrfToken,
},
contentType: 'application/json',
type: 'POST',
error: () => {
from.insertBefore(item, from.children[oldIndex]);
},
});
},
onAdd: moveIssue,
onUpdate: moveIssue,
});
}
}