2019-09-30 21:07:59 +05:30
|
|
|
import Sortable from 'sortablejs';
|
|
|
|
import {
|
|
|
|
getBoardSortableDefaultOptions,
|
|
|
|
sortableStart,
|
|
|
|
} from '~/boards/mixins/sortable_default_options';
|
2021-09-04 01:27:46 +05:30
|
|
|
import createFlash from '~/flash';
|
2019-09-30 21:07:59 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { s__ } from '~/locale';
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const updateIssue = (url, { move_before_id, move_after_id }) =>
|
2019-09-30 21:07:59 +05:30
|
|
|
axios
|
|
|
|
.put(`${url}/reorder`, {
|
|
|
|
move_before_id,
|
|
|
|
move_after_id,
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2021-09-04 01:27:46 +05:30
|
|
|
createFlash({
|
|
|
|
message: s__("ManualOrdering|Couldn't save the order of the issues"),
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
const initManualOrdering = () => {
|
2019-09-30 21:07:59 +05:30
|
|
|
const issueList = document.querySelector('.manual-ordering');
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
if (!issueList || !(gon.current_user_id > 0)) {
|
2019-09-30 21:07:59 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sortable.create(
|
|
|
|
issueList,
|
|
|
|
getBoardSortableDefaultOptions({
|
|
|
|
scroll: true,
|
2020-03-13 15:44:24 +05:30
|
|
|
fallbackTolerance: 1,
|
2019-09-30 21:07:59 +05:30
|
|
|
dataIdAttr: 'data-id',
|
|
|
|
fallbackOnBody: false,
|
|
|
|
group: {
|
|
|
|
name: 'issues',
|
|
|
|
},
|
2022-03-02 08:16:31 +05:30
|
|
|
draggable: 'li.issue',
|
2019-09-30 21:07:59 +05:30
|
|
|
onStart: () => {
|
|
|
|
sortableStart();
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
onUpdate: (event) => {
|
2019-09-30 21:07:59 +05:30
|
|
|
const el = event.item;
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
const url = el.getAttribute('url');
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
const prev = el.previousElementSibling;
|
|
|
|
const next = el.nextElementSibling;
|
|
|
|
|
|
|
|
const beforeId = prev && parseInt(prev.dataset.id, 10);
|
|
|
|
const afterId = next && parseInt(next.dataset.id, 10);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
updateIssue(url, { move_after_id: afterId, move_before_id: beforeId });
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default initManualOrdering;
|