gitea源码

repo-settings-branches.ts 1.0KB

123456789101112131415161718192021222324252627282930313233
  1. import {createSortable} from '../modules/sortable.ts';
  2. import {POST} from '../modules/fetch.ts';
  3. import {showErrorToast} from '../modules/toast.ts';
  4. import {queryElemChildren} from '../utils/dom.ts';
  5. export function initRepoSettingsBranchesDrag() {
  6. const protectedBranchesList = document.querySelector('#protected-branches-list');
  7. if (!protectedBranchesList) return;
  8. createSortable(protectedBranchesList, {
  9. handle: '.drag-handle',
  10. animation: 150,
  11. onEnd: () => {
  12. (async () => {
  13. const itemElems = queryElemChildren(protectedBranchesList, '.item[data-id]');
  14. const itemIds = Array.from(itemElems, (el) => parseInt(el.getAttribute('data-id')));
  15. try {
  16. await POST(protectedBranchesList.getAttribute('data-update-priority-url'), {
  17. data: {
  18. ids: itemIds,
  19. },
  20. });
  21. } catch (err) {
  22. const errorMessage = String(err);
  23. showErrorToast(`Failed to update branch protection rule priority:, error: ${errorMessage}`);
  24. }
  25. })();
  26. },
  27. });
  28. }