mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
6.2 KiB
156 lines
6.2 KiB
3 years ago
|
import $ from 'jquery';
|
||
5 months ago
|
import {hideElem, showElem} from '../utils/dom.ts';
|
||
|
import {GET} from '../modules/fetch.ts';
|
||
3 years ago
|
|
||
2 years ago
|
export function initRepoGraphGit() {
|
||
6 months ago
|
const graphContainer = document.querySelector('#git-graph-container');
|
||
4 years ago
|
if (!graphContainer) return;
|
||
|
|
||
6 months ago
|
document.querySelector('#flow-color-monochrome')?.addEventListener('click', () => {
|
||
|
document.querySelector('#flow-color-monochrome').classList.add('active');
|
||
|
document.querySelector('#flow-color-colored')?.classList.remove('active');
|
||
7 months ago
|
graphContainer.classList.remove('colored');
|
||
|
graphContainer.classList.add('monochrome');
|
||
4 years ago
|
const params = new URLSearchParams(window.location.search);
|
||
|
params.set('mode', 'monochrome');
|
||
|
const queryString = params.toString();
|
||
|
if (queryString) {
|
||
|
window.history.replaceState({}, '', `?${queryString}`);
|
||
4 years ago
|
} else {
|
||
4 years ago
|
window.history.replaceState({}, '', window.location.pathname);
|
||
|
}
|
||
7 months ago
|
for (const link of document.querySelectorAll('.pagination a')) {
|
||
|
const href = link.getAttribute('href');
|
||
|
if (!href) continue;
|
||
4 years ago
|
const url = new URL(href, window.location);
|
||
|
const params = url.searchParams;
|
||
|
params.set('mode', 'monochrome');
|
||
|
url.search = `?${params.toString()}`;
|
||
7 months ago
|
link.setAttribute('href', url.href);
|
||
|
}
|
||
4 years ago
|
});
|
||
7 months ago
|
|
||
6 months ago
|
document.querySelector('#flow-color-colored')?.addEventListener('click', () => {
|
||
|
document.querySelector('#flow-color-colored').classList.add('active');
|
||
|
document.querySelector('#flow-color-monochrome')?.classList.remove('active');
|
||
7 months ago
|
graphContainer.classList.add('colored');
|
||
|
graphContainer.classList.remove('monochrome');
|
||
|
for (const link of document.querySelectorAll('.pagination a')) {
|
||
|
const href = link.getAttribute('href');
|
||
|
if (!href) continue;
|
||
4 years ago
|
const url = new URL(href, window.location);
|
||
|
const params = url.searchParams;
|
||
|
params.delete('mode');
|
||
|
url.search = `?${params.toString()}`;
|
||
7 months ago
|
link.setAttribute('href', url.href);
|
||
|
}
|
||
4 years ago
|
const params = new URLSearchParams(window.location.search);
|
||
|
params.delete('mode');
|
||
|
const queryString = params.toString();
|
||
|
if (queryString) {
|
||
|
window.history.replaceState({}, '', `?${queryString}`);
|
||
|
} else {
|
||
|
window.history.replaceState({}, '', window.location.pathname);
|
||
4 years ago
|
}
|
||
5 years ago
|
});
|
||
4 years ago
|
const url = new URL(window.location);
|
||
|
const params = url.searchParams;
|
||
3 years ago
|
const updateGraph = () => {
|
||
4 years ago
|
const queryString = params.toString();
|
||
|
const ajaxUrl = new URL(url);
|
||
|
ajaxUrl.searchParams.set('div-only', 'true');
|
||
|
window.history.replaceState({}, '', queryString ? `?${queryString}` : window.location.pathname);
|
||
6 months ago
|
document.querySelector('#pagination').innerHTML = '';
|
||
7 months ago
|
hideElem('#rel-container');
|
||
|
hideElem('#rev-container');
|
||
|
showElem('#loading-indicator');
|
||
3 years ago
|
(async () => {
|
||
9 months ago
|
const response = await GET(String(ajaxUrl));
|
||
|
const html = await response.text();
|
||
7 months ago
|
const div = document.createElement('div');
|
||
|
div.innerHTML = html;
|
||
6 months ago
|
document.querySelector('#pagination').innerHTML = div.querySelector('#pagination').innerHTML;
|
||
|
document.querySelector('#rel-container').innerHTML = div.querySelector('#rel-container').innerHTML;
|
||
|
document.querySelector('#rev-container').innerHTML = div.querySelector('#rev-container').innerHTML;
|
||
7 months ago
|
hideElem('#loading-indicator');
|
||
|
showElem('#rel-container');
|
||
|
showElem('#rev-container');
|
||
3 years ago
|
})();
|
||
4 years ago
|
};
|
||
|
const dropdownSelected = params.getAll('branch');
|
||
|
if (params.has('hide-pr-refs') && params.get('hide-pr-refs') === 'true') {
|
||
|
dropdownSelected.splice(0, 0, '...flow-hide-pr-refs');
|
||
|
}
|
||
|
|
||
6 months ago
|
const flowSelectRefsDropdown = document.querySelector('#flow-select-refs-dropdown');
|
||
7 months ago
|
$(flowSelectRefsDropdown).dropdown('set selected', dropdownSelected);
|
||
|
$(flowSelectRefsDropdown).dropdown({
|
||
4 years ago
|
clearable: true,
|
||
4 years ago
|
fullTextSeach: 'exact',
|
||
4 years ago
|
onRemove(toRemove) {
|
||
|
if (toRemove === '...flow-hide-pr-refs') {
|
||
|
params.delete('hide-pr-refs');
|
||
|
} else {
|
||
|
const branches = params.getAll('branch');
|
||
|
params.delete('branch');
|
||
|
for (const branch of branches) {
|
||
|
if (branch !== toRemove) {
|
||
|
params.append('branch', branch);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
updateGraph();
|
||
|
},
|
||
|
onAdd(toAdd) {
|
||
|
if (toAdd === '...flow-hide-pr-refs') {
|
||
|
params.set('hide-pr-refs', true);
|
||
|
} else {
|
||
|
params.append('branch', toAdd);
|
||
|
}
|
||
|
updateGraph();
|
||
|
},
|
||
|
});
|
||
7 months ago
|
|
||
|
graphContainer.addEventListener('mouseenter', (e) => {
|
||
|
if (e.target.matches('#rev-list li')) {
|
||
|
const flow = e.target.getAttribute('data-flow');
|
||
|
if (flow === '0') return;
|
||
6 months ago
|
document.querySelector(`#flow-${flow}`)?.classList.add('highlight');
|
||
7 months ago
|
e.target.classList.add('hover');
|
||
|
for (const item of document.querySelectorAll(`#rev-list li[data-flow='${flow}']`)) {
|
||
|
item.classList.add('highlight');
|
||
|
}
|
||
|
} else if (e.target.matches('#rel-container .flow-group')) {
|
||
|
e.target.classList.add('highlight');
|
||
|
const flow = e.target.getAttribute('data-flow');
|
||
|
for (const item of document.querySelectorAll(`#rev-list li[data-flow='${flow}']`)) {
|
||
|
item.classList.add('highlight');
|
||
|
}
|
||
|
} else if (e.target.matches('#rel-container .flow-commit')) {
|
||
|
const rev = e.target.getAttribute('data-rev');
|
||
|
document.querySelector(`#rev-list li#commit-${rev}`)?.classList.add('hover');
|
||
|
}
|
||
4 years ago
|
});
|
||
7 months ago
|
|
||
|
graphContainer.addEventListener('mouseleave', (e) => {
|
||
|
if (e.target.matches('#rev-list li')) {
|
||
|
const flow = e.target.getAttribute('data-flow');
|
||
|
if (flow === '0') return;
|
||
6 months ago
|
document.querySelector(`#flow-${flow}`)?.classList.remove('highlight');
|
||
7 months ago
|
e.target.classList.remove('hover');
|
||
|
for (const item of document.querySelectorAll(`#rev-list li[data-flow='${flow}']`)) {
|
||
|
item.classList.remove('highlight');
|
||
|
}
|
||
|
} else if (e.target.matches('#rel-container .flow-group')) {
|
||
|
e.target.classList.remove('highlight');
|
||
|
const flow = e.target.getAttribute('data-flow');
|
||
|
for (const item of document.querySelectorAll(`#rev-list li[data-flow='${flow}']`)) {
|
||
|
item.classList.remove('highlight');
|
||
|
}
|
||
|
} else if (e.target.matches('#rel-container .flow-commit')) {
|
||
|
const rev = e.target.getAttribute('data-rev');
|
||
|
document.querySelector(`#rev-list li#commit-${rev}`)?.classList.remove('hover');
|
||
|
}
|
||
4 years ago
|
});
|
||
5 years ago
|
}
|