2022-01-28 22:00:11 +01:00
|
|
|
import $ from 'jquery';
|
2022-08-09 14:37:34 +02:00
|
|
|
import {createTippy} from '../modules/tippy.js';
|
2023-02-19 05:06:14 +01:00
|
|
|
import {toggleElem} from '../utils/dom.js';
|
2022-01-28 22:00:11 +01:00
|
|
|
|
2021-11-09 10:27:25 +01:00
|
|
|
const {csrfToken} = window.config;
|
|
|
|
|
2021-11-23 03:44:38 +01:00
|
|
|
export function initRepoEllipsisButton() {
|
2023-07-27 12:47:41 +02:00
|
|
|
$('.js-toggle-commit-body').on('click', function (e) {
|
2021-10-16 19:28:04 +02:00
|
|
|
e.preventDefault();
|
2021-11-23 03:44:38 +01:00
|
|
|
const expanded = $(this).attr('aria-expanded') === 'true';
|
2023-02-19 05:06:14 +01:00
|
|
|
toggleElem($(this).parent().find('.commit-body'));
|
2021-11-23 03:44:38 +01:00
|
|
|
$(this).attr('aria-expanded', String(!expanded));
|
2021-10-16 19:28:04 +02:00
|
|
|
});
|
|
|
|
}
|
2021-11-09 10:27:25 +01:00
|
|
|
|
|
|
|
export function initRepoCommitLastCommitLoader() {
|
2024-02-21 01:05:17 +01:00
|
|
|
const notReadyEls = document.querySelectorAll('table#repo-files-table tr.notready');
|
|
|
|
if (!notReadyEls.length) return;
|
2021-11-09 10:27:25 +01:00
|
|
|
|
2024-02-21 01:05:17 +01:00
|
|
|
const entryMap = {};
|
|
|
|
const entries = [];
|
|
|
|
for (const el of notReadyEls) {
|
|
|
|
const entryname = el.getAttribute('data-entryname');
|
|
|
|
entryMap[entryname] = $(el);
|
|
|
|
entries.push(entryname);
|
2021-11-09 10:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');
|
|
|
|
|
|
|
|
if (entries.length > 200) {
|
|
|
|
$.post(lastCommitLoaderURL, {
|
|
|
|
_csrf: csrfToken,
|
|
|
|
}, (data) => {
|
|
|
|
$('table#repo-files-table').replaceWith(data);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.post(lastCommitLoaderURL, {
|
|
|
|
_csrf: csrfToken,
|
|
|
|
'f': entries,
|
|
|
|
}, (data) => {
|
|
|
|
$(data).find('tr').each((_, row) => {
|
|
|
|
if (row.className === 'commit-list') {
|
|
|
|
$('table#repo-files-table .commit-list').replaceWith(row);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-17 11:44:35 +02:00
|
|
|
// 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).attr('data-entryname');
|
|
|
|
if (entryName) {
|
|
|
|
entryMap[entryName].replaceWith(row);
|
|
|
|
}
|
2021-11-09 10:27:25 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-04-26 21:09:46 +02:00
|
|
|
|
|
|
|
export function initCommitStatuses() {
|
2023-02-20 09:43:04 +01:00
|
|
|
$('[data-tippy="commit-statuses"]').each(function () {
|
2022-08-09 23:55:29 +02:00
|
|
|
const top = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0;
|
2022-08-09 14:37:34 +02:00
|
|
|
|
|
|
|
createTippy(this, {
|
2022-08-10 06:08:06 +02:00
|
|
|
content: this.nextElementSibling,
|
2022-08-09 23:55:29 +02:00
|
|
|
placement: top ? 'top-start' : 'bottom-start',
|
2022-08-09 14:37:34 +02:00
|
|
|
interactive: true,
|
2023-06-15 10:09:16 +02:00
|
|
|
role: 'dialog',
|
2023-11-02 15:49:02 +01:00
|
|
|
theme: 'box-with-header',
|
2022-08-09 14:37:34 +02:00
|
|
|
});
|
2022-04-26 21:09:46 +02:00
|
|
|
});
|
|
|
|
}
|