2019-06-26 04:29:23 -04:00
|
|
|
import Sortable from 'sortablejs';
|
|
|
|
import {
|
|
|
|
getBoardSortableDefaultOptions,
|
|
|
|
sortableStart,
|
|
|
|
} from '~/boards/mixins/sortable_default_options';
|
2021-06-04 14:10:08 -04:00
|
|
|
import createFlash from '~/flash';
|
2019-06-26 04:29:23 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { s__ } from '~/locale';
|
2019-06-26 04:29:23 -04:00
|
|
|
|
2022-02-10 16:15:20 -05:00
|
|
|
const updateIssue = (url, { move_before_id, move_after_id }) =>
|
2019-06-26 04:29:23 -04:00
|
|
|
axios
|
|
|
|
.put(`${url}/reorder`, {
|
|
|
|
move_before_id,
|
|
|
|
move_after_id,
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2021-06-04 14:10:08 -04:00
|
|
|
createFlash({
|
|
|
|
message: s__("ManualOrdering|Couldn't save the order of the issues"),
|
|
|
|
});
|
2019-06-26 04:29:23 -04:00
|
|
|
});
|
|
|
|
|
2022-01-07 22:14:00 -05:00
|
|
|
const initManualOrdering = () => {
|
2019-06-26 04:29:23 -04:00
|
|
|
const issueList = document.querySelector('.manual-ordering');
|
|
|
|
|
2019-07-26 04:25:36 -04:00
|
|
|
if (!issueList || !(gon.current_user_id > 0)) {
|
2019-06-26 04:29:23 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sortable.create(
|
|
|
|
issueList,
|
|
|
|
getBoardSortableDefaultOptions({
|
|
|
|
scroll: true,
|
2020-01-27 01:08:57 -05:00
|
|
|
fallbackTolerance: 1,
|
2019-06-26 04:29:23 -04:00
|
|
|
dataIdAttr: 'data-id',
|
|
|
|
fallbackOnBody: false,
|
|
|
|
group: {
|
|
|
|
name: 'issues',
|
|
|
|
},
|
2022-01-07 22:14:00 -05:00
|
|
|
draggable: 'li.issue',
|
2019-06-26 04:29:23 -04:00
|
|
|
onStart: () => {
|
|
|
|
sortableStart();
|
|
|
|
},
|
2020-12-23 16:10:24 -05:00
|
|
|
onUpdate: (event) => {
|
2019-06-26 04:29:23 -04:00
|
|
|
const el = event.item;
|
|
|
|
|
2022-01-07 22:14:00 -05:00
|
|
|
const url = el.getAttribute('url');
|
2019-06-26 04:29:23 -04:00
|
|
|
|
|
|
|
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-02-10 16:15:20 -05:00
|
|
|
updateIssue(url, { move_after_id: afterId, move_before_id: beforeId });
|
2019-06-26 04:29:23 -04:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default initManualOrdering;
|