2022-01-28 16:00:11 -05:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
2022-12-23 11:03:11 -05:00
|
|
|
export function initRepoGraphGit() {
|
2020-08-06 03:04:08 -05:00
|
|
|
const graphContainer = document.getElementById('git-graph-container');
|
|
|
|
if (!graphContainer) return;
|
|
|
|
|
|
|
|
$('#flow-color-monochrome').on('click', () => {
|
|
|
|
$('#flow-color-monochrome').addClass('active');
|
|
|
|
$('#flow-color-colored').removeClass('active');
|
|
|
|
$('#git-graph-container').removeClass('colored').addClass('monochrome');
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
params.set('mode', 'monochrome');
|
|
|
|
const queryString = params.toString();
|
|
|
|
if (queryString) {
|
|
|
|
window.history.replaceState({}, '', `?${queryString}`);
|
2020-07-04 20:04:24 -05:00
|
|
|
} else {
|
2020-08-06 03:04:08 -05:00
|
|
|
window.history.replaceState({}, '', window.location.pathname);
|
|
|
|
}
|
|
|
|
$('.pagination a').each((_, that) => {
|
|
|
|
const href = $(that).attr('href');
|
|
|
|
if (!href) return;
|
|
|
|
const url = new URL(href, window.location);
|
|
|
|
const params = url.searchParams;
|
|
|
|
params.set('mode', 'monochrome');
|
|
|
|
url.search = `?${params.toString()}`;
|
|
|
|
$(that).attr('href', url.href);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$('#flow-color-colored').on('click', () => {
|
|
|
|
$('#flow-color-colored').addClass('active');
|
|
|
|
$('#flow-color-monochrome').removeClass('active');
|
|
|
|
$('#git-graph-container').addClass('colored').removeClass('monochrome');
|
|
|
|
$('.pagination a').each((_, that) => {
|
|
|
|
const href = $(that).attr('href');
|
|
|
|
if (!href) return;
|
|
|
|
const url = new URL(href, window.location);
|
|
|
|
const params = url.searchParams;
|
|
|
|
params.delete('mode');
|
|
|
|
url.search = `?${params.toString()}`;
|
|
|
|
$(that).attr('href', url.href);
|
|
|
|
});
|
|
|
|
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);
|
2020-07-04 20:04:24 -05:00
|
|
|
}
|
2019-11-21 18:30:14 -05:00
|
|
|
});
|
2020-11-08 12:21:54 -05:00
|
|
|
const url = new URL(window.location);
|
|
|
|
const params = url.searchParams;
|
2021-11-12 07:37:45 -05:00
|
|
|
const updateGraph = () => {
|
2020-11-08 12:21:54 -05:00
|
|
|
const queryString = params.toString();
|
|
|
|
const ajaxUrl = new URL(url);
|
|
|
|
ajaxUrl.searchParams.set('div-only', 'true');
|
|
|
|
window.history.replaceState({}, '', queryString ? `?${queryString}` : window.location.pathname);
|
|
|
|
$('#pagination').empty();
|
|
|
|
$('#rel-container').addClass('hide');
|
|
|
|
$('#rev-container').addClass('hide');
|
|
|
|
$('#loading-indicator').removeClass('hide');
|
2021-11-12 07:37:45 -05:00
|
|
|
(async () => {
|
|
|
|
const div = $(await $.ajax(String(ajaxUrl)));
|
|
|
|
$('#pagination').html(div.find('#pagination').html());
|
|
|
|
$('#rel-container').html(div.find('#rel-container').html());
|
|
|
|
$('#rev-container').html(div.find('#rev-container').html());
|
|
|
|
$('#loading-indicator').addClass('hide');
|
|
|
|
$('#rel-container').removeClass('hide');
|
|
|
|
$('#rev-container').removeClass('hide');
|
|
|
|
})();
|
2020-11-08 12:21:54 -05:00
|
|
|
};
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#flow-select-refs-dropdown').dropdown('set selected', dropdownSelected);
|
|
|
|
$('#flow-select-refs-dropdown').dropdown({
|
|
|
|
clearable: true,
|
2021-02-15 22:03:32 -05:00
|
|
|
fullTextSeach: 'exact',
|
2020-11-08 12:21:54 -05:00
|
|
|
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();
|
|
|
|
},
|
|
|
|
});
|
2020-08-06 03:04:08 -05:00
|
|
|
$('#git-graph-container').on('mouseenter', '#rev-list li', (e) => {
|
|
|
|
const flow = $(e.currentTarget).data('flow');
|
|
|
|
if (flow === 0) return;
|
|
|
|
$(`#flow-${flow}`).addClass('highlight');
|
|
|
|
$(e.currentTarget).addClass('hover');
|
|
|
|
$(`#rev-list li[data-flow='${flow}']`).addClass('highlight');
|
|
|
|
});
|
|
|
|
$('#git-graph-container').on('mouseleave', '#rev-list li', (e) => {
|
|
|
|
const flow = $(e.currentTarget).data('flow');
|
|
|
|
if (flow === 0) return;
|
|
|
|
$(`#flow-${flow}`).removeClass('highlight');
|
|
|
|
$(e.currentTarget).removeClass('hover');
|
|
|
|
$(`#rev-list li[data-flow='${flow}']`).removeClass('highlight');
|
|
|
|
});
|
|
|
|
$('#git-graph-container').on('mouseenter', '#rel-container .flow-group', (e) => {
|
|
|
|
$(e.currentTarget).addClass('highlight');
|
|
|
|
const flow = $(e.currentTarget).data('flow');
|
|
|
|
$(`#rev-list li[data-flow='${flow}']`).addClass('highlight');
|
|
|
|
});
|
|
|
|
$('#git-graph-container').on('mouseleave', '#rel-container .flow-group', (e) => {
|
|
|
|
$(e.currentTarget).removeClass('highlight');
|
|
|
|
const flow = $(e.currentTarget).data('flow');
|
|
|
|
$(`#rev-list li[data-flow='${flow}']`).removeClass('highlight');
|
|
|
|
});
|
|
|
|
$('#git-graph-container').on('mouseenter', '#rel-container .flow-commit', (e) => {
|
|
|
|
const rev = $(e.currentTarget).data('rev');
|
|
|
|
$(`#rev-list li#commit-${rev}`).addClass('hover');
|
|
|
|
});
|
|
|
|
$('#git-graph-container').on('mouseleave', '#rel-container .flow-commit', (e) => {
|
|
|
|
const rev = $(e.currentTarget).data('rev');
|
|
|
|
$(`#rev-list li#commit-${rev}`).removeClass('hover');
|
|
|
|
});
|
2020-02-07 12:09:30 -05:00
|
|
|
}
|