2022-08-09 08:37:34 -04:00
|
|
|
import {createTippy} from '../modules/tippy.js';
|
2023-02-18 23:06:14 -05:00
|
|
|
import {toggleElem} from '../utils/dom.js';
|
2024-02-22 12:13:25 -05:00
|
|
|
import {parseDom} from '../utils.js';
|
|
|
|
import {POST} from '../modules/fetch.js';
|
2021-11-09 04:27:25 -05:00
|
|
|
|
2021-11-22 21:44:38 -05:00
|
|
|
export function initRepoEllipsisButton() {
|
2024-02-22 12:13:25 -05:00
|
|
|
for (const button of document.querySelectorAll('.js-toggle-commit-body')) {
|
|
|
|
button.addEventListener('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
const expanded = this.getAttribute('aria-expanded') === 'true';
|
|
|
|
toggleElem(this.parentElement.querySelector('.commit-body'));
|
|
|
|
this.setAttribute('aria-expanded', String(!expanded));
|
|
|
|
});
|
|
|
|
}
|
2021-10-16 13:28:04 -04:00
|
|
|
}
|
2021-11-09 04:27:25 -05:00
|
|
|
|
2024-02-22 12:13:25 -05:00
|
|
|
export async function initRepoCommitLastCommitLoader() {
|
2024-02-20 19:05:17 -05:00
|
|
|
const entryMap = {};
|
2024-02-22 12:13:25 -05:00
|
|
|
|
|
|
|
const entries = Array.from(document.querySelectorAll('table#repo-files-table tr.notready'), (el) => {
|
|
|
|
const entryName = el.getAttribute('data-entryname');
|
|
|
|
entryMap[entryName] = el;
|
|
|
|
return entryName;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (entries.length === 0) {
|
|
|
|
return;
|
2021-11-09 04:27:25 -05:00
|
|
|
}
|
|
|
|
|
2024-02-22 12:13:25 -05:00
|
|
|
const lastCommitLoaderURL = document.querySelector('table#repo-files-table').getAttribute('data-last-commit-loader-url');
|
2021-11-09 04:27:25 -05:00
|
|
|
|
|
|
|
if (entries.length > 200) {
|
2024-02-22 12:13:25 -05:00
|
|
|
// For more than 200 entries, replace the entire table
|
|
|
|
const response = await POST(lastCommitLoaderURL);
|
|
|
|
const data = await response.text();
|
|
|
|
document.querySelector('table#repo-files-table').outerHTML = data;
|
2021-11-09 04:27:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-22 12:13:25 -05:00
|
|
|
// For fewer entries, update individual rows
|
|
|
|
const response = await POST(lastCommitLoaderURL, {data: {'f': entries}});
|
|
|
|
const data = await response.text();
|
|
|
|
const doc = parseDom(data, 'text/html');
|
|
|
|
for (const row of doc.querySelectorAll('tr')) {
|
|
|
|
if (row.className === 'commit-list') {
|
|
|
|
document.querySelector('table#repo-files-table .commit-list')?.replaceWith(row);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// there are other <tr> rows in response (eg: <tr class="has-parent">)
|
|
|
|
// at the moment only the "data-entryname" rows should be processed
|
|
|
|
const entryName = row.getAttribute('data-entryname');
|
|
|
|
if (entryName) {
|
|
|
|
entryMap[entryName]?.replaceWith(row);
|
|
|
|
}
|
|
|
|
}
|
2021-11-09 04:27:25 -05:00
|
|
|
}
|
2022-04-26 15:09:46 -04:00
|
|
|
|
|
|
|
export function initCommitStatuses() {
|
2024-02-22 12:13:25 -05:00
|
|
|
for (const element of document.querySelectorAll('[data-tippy="commit-statuses"]')) {
|
|
|
|
const top = document.querySelector('.repository.file.list') || document.querySelector('.repository.diff');
|
2022-08-09 08:37:34 -04:00
|
|
|
|
2024-02-22 12:13:25 -05:00
|
|
|
createTippy(element, {
|
|
|
|
content: element.nextElementSibling,
|
2022-08-09 17:55:29 -04:00
|
|
|
placement: top ? 'top-start' : 'bottom-start',
|
2022-08-09 08:37:34 -04:00
|
|
|
interactive: true,
|
2023-06-15 04:09:16 -04:00
|
|
|
role: 'dialog',
|
2023-11-02 10:49:02 -04:00
|
|
|
theme: 'box-with-header',
|
2022-08-09 08:37:34 -04:00
|
|
|
});
|
2024-02-22 12:13:25 -05:00
|
|
|
}
|
2022-04-26 15:09:46 -04:00
|
|
|
}
|