2024-11-03 12:00:12 +01:00
|
|
|
import $ from 'jquery';
|
|
|
|
import {POST} from '../modules/fetch.ts';
|
2024-11-10 09:26:42 +01:00
|
|
|
import {queryElems, toggleElem} from '../utils/dom.ts';
|
2024-11-10 21:07:54 +01:00
|
|
|
import {initIssueSidebarComboList} from './repo-issue-sidebar-combolist.ts';
|
2024-11-03 12:00:12 +01:00
|
|
|
|
|
|
|
function initBranchSelector() {
|
|
|
|
const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
|
|
|
|
if (!elSelectBranch) return;
|
|
|
|
|
|
|
|
const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref');
|
|
|
|
const $selectBranch = $(elSelectBranch);
|
|
|
|
const $branchMenu = $selectBranch.find('.reference-list-menu');
|
|
|
|
$branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
const selectedValue = this.getAttribute('data-id'); // eg: "refs/heads/my-branch"
|
|
|
|
const selectedText = this.getAttribute('data-name'); // eg: "my-branch"
|
|
|
|
if (urlUpdateIssueRef) {
|
|
|
|
// for existing issue, send request to update issue ref, and reload page
|
|
|
|
try {
|
|
|
|
await POST(urlUpdateIssueRef, {data: new URLSearchParams({ref: selectedValue})});
|
|
|
|
window.location.reload();
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// for new issue, only update UI&form, do not send request/reload
|
|
|
|
const selectedHiddenSelector = this.getAttribute('data-id-selector');
|
2024-11-10 09:26:42 +01:00
|
|
|
document.querySelector<HTMLInputElement>(selectedHiddenSelector).value = selectedValue;
|
2024-11-03 12:00:12 +01:00
|
|
|
elSelectBranch.querySelector('.text-branch-name').textContent = selectedText;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-05 08:46:40 +01:00
|
|
|
function initRepoIssueDue() {
|
|
|
|
const form = document.querySelector<HTMLFormElement>('.issue-due-form');
|
|
|
|
if (!form) return;
|
|
|
|
const deadline = form.querySelector<HTMLInputElement>('input[name=deadline]');
|
|
|
|
document.querySelector('.issue-due-edit')?.addEventListener('click', () => {
|
|
|
|
toggleElem(form);
|
|
|
|
});
|
|
|
|
document.querySelector('.issue-due-remove')?.addEventListener('click', () => {
|
|
|
|
deadline.value = '';
|
|
|
|
form.dispatchEvent(new Event('submit', {cancelable: true, bubbles: true}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-03 12:00:12 +01:00
|
|
|
export function initRepoIssueSidebar() {
|
|
|
|
initBranchSelector();
|
2024-11-05 08:46:40 +01:00
|
|
|
initRepoIssueDue();
|
2024-11-03 12:00:12 +01:00
|
|
|
|
2024-11-10 09:26:42 +01:00
|
|
|
// init the combo list: a dropdown for selecting items, and a list for showing selected items and related actions
|
|
|
|
queryElems<HTMLElement>(document, '.issue-sidebar-combo', (el) => initIssueSidebarComboList(el));
|
2024-11-03 12:00:12 +01:00
|
|
|
}
|