2023-03-17 16:20:25 +05:30
|
|
|
/* eslint-disable class-methods-use-this */
|
2021-03-11 19:13:27 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
import Vue from 'vue';
|
2022-11-25 23:54:43 +05:30
|
|
|
import { createAlert } from '~/flash';
|
2022-05-07 20:08:51 +05:30
|
|
|
import { getCookie, isMetaClick, parseBoolean, scrollToElement } from '~/lib/utils/common_utils';
|
|
|
|
import { parseUrlPathname } from '~/lib/utils/url_utility';
|
2020-05-24 23:13:21 +05:30
|
|
|
import createEventHub from '~/helpers/event_hub_factory';
|
2023-03-04 22:38:38 +05:30
|
|
|
import { renderGFM } from '~/behaviors/markdown/render_gfm';
|
2017-08-17 22:00:37 +05:30
|
|
|
import BlobForkSuggestion from './blob/blob_fork_suggestion';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Diff from './diff';
|
2021-11-11 11:23:49 +05:30
|
|
|
import { initDiffStatsDropdown } from './init_diff_stats_dropdown';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from './lib/utils/axios_utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
import { localTimeAgo } from './lib/utils/datetime_utility';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { isInVueNoteablePage } from './lib/utils/dom_utils';
|
2019-09-04 21:01:54 +05:30
|
|
|
import { __ } from './locale';
|
2021-03-11 19:13:27 +05:30
|
|
|
import syntaxHighlight from './syntax_highlight';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
// MergeRequestTabs
|
|
|
|
//
|
|
|
|
// Handles persisting and restoring the current tab selection and lazily-loading
|
|
|
|
// content on the MergeRequests#show page.
|
|
|
|
//
|
|
|
|
// ### Example Markup
|
|
|
|
//
|
|
|
|
// <ul class="nav-links merge-request-tabs">
|
|
|
|
// <li class="notes-tab active">
|
2020-03-13 15:44:24 +05:30
|
|
|
// <a data-action="notes" data-target="#notes" data-toggle="tab" href="/foo/bar/-/merge_requests/1">
|
2016-09-29 09:46:39 +05:30
|
|
|
// Discussion
|
|
|
|
// </a>
|
|
|
|
// </li>
|
|
|
|
// <li class="commits-tab">
|
2020-03-13 15:44:24 +05:30
|
|
|
// <a data-action="commits" data-target="#commits" data-toggle="tab" href="/foo/bar/-/merge_requests/1/commits">
|
2016-09-29 09:46:39 +05:30
|
|
|
// Commits
|
|
|
|
// </a>
|
|
|
|
// </li>
|
|
|
|
// <li class="diffs-tab">
|
2020-03-13 15:44:24 +05:30
|
|
|
// <a data-action="diffs" data-target="#diffs" data-toggle="tab" href="/foo/bar/-/merge_requests/1/diffs">
|
2016-09-29 09:46:39 +05:30
|
|
|
// Diffs
|
|
|
|
// </a>
|
|
|
|
// </li>
|
|
|
|
// </ul>
|
|
|
|
//
|
|
|
|
// <div class="tab-content">
|
|
|
|
// <div class="notes tab-pane active" id="notes">
|
|
|
|
// Notes Content
|
|
|
|
// </div>
|
|
|
|
// <div class="commits tab-pane" id="commits">
|
|
|
|
// Commits Content
|
|
|
|
// </div>
|
|
|
|
// <div class="diffs tab-pane" id="diffs">
|
|
|
|
// Diffs Content
|
|
|
|
// </div>
|
|
|
|
// </div>
|
|
|
|
//
|
|
|
|
// <div class="mr-loading-status">
|
|
|
|
// <div class="loading">
|
|
|
|
// Loading Animation
|
|
|
|
// </div>
|
|
|
|
// </div>
|
|
|
|
//
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
// <100ms is typically indistinguishable from "instant" for users, but allows for re-rendering
|
|
|
|
const FAST_DELAY_FOR_RERENDER = 75;
|
2018-03-17 18:26:18 +05:30
|
|
|
// Store the `location` object, allowing for easier stubbing in tests
|
2018-11-08 19:23:39 +05:30
|
|
|
let { location } = window;
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
function scrollToContainer(container) {
|
|
|
|
if (location.hash) {
|
|
|
|
const $el = $(`${container} ${location.hash}:not(.match)`);
|
|
|
|
|
|
|
|
if ($el.length) {
|
|
|
|
scrollToElement($el[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function computeTopOffset(tabs) {
|
|
|
|
const navbar = document.querySelector('.navbar-gitlab');
|
|
|
|
const peek = document.getElementById('js-peek');
|
|
|
|
let stickyTop;
|
|
|
|
|
|
|
|
stickyTop = navbar ? navbar.offsetHeight : 0;
|
|
|
|
stickyTop = peek ? stickyTop + peek.offsetHeight : stickyTop;
|
|
|
|
stickyTop = tabs ? stickyTop + tabs.offsetHeight : stickyTop;
|
|
|
|
|
|
|
|
return stickyTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mountPipelines() {
|
|
|
|
const pipelineTableViewEl = document.querySelector('#commit-pipeline-table-view');
|
|
|
|
const { mrWidgetData } = gl;
|
|
|
|
const table = new Vue({
|
|
|
|
components: {
|
|
|
|
CommitPipelinesTable: () => import('~/commit/pipelines/pipelines_table.vue'),
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
artifactsEndpoint: pipelineTableViewEl.dataset.artifactsEndpoint,
|
|
|
|
artifactsEndpointPlaceholder: pipelineTableViewEl.dataset.artifactsEndpointPlaceholder,
|
|
|
|
targetProjectFullPath: mrWidgetData?.target_project_full_path || '',
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('commit-pipelines-table', {
|
|
|
|
props: {
|
|
|
|
endpoint: pipelineTableViewEl.dataset.endpoint,
|
|
|
|
emptyStateSvgPath: pipelineTableViewEl.dataset.emptyStateSvgPath,
|
|
|
|
errorStateSvgPath: pipelineTableViewEl.dataset.errorStateSvgPath,
|
|
|
|
canCreatePipelineInTargetProject: Boolean(
|
|
|
|
mrWidgetData?.can_create_pipeline_in_target_project,
|
|
|
|
),
|
|
|
|
sourceProjectFullPath: mrWidgetData?.source_project_full_path || '',
|
|
|
|
targetProjectFullPath: mrWidgetData?.target_project_full_path || '',
|
|
|
|
projectId: pipelineTableViewEl.dataset.projectId,
|
|
|
|
mergeRequestId: mrWidgetData ? mrWidgetData.iid : null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
// $mount(el) replaces the el with the new rendered component. We need it in order to mount
|
|
|
|
// it everytime this tab is clicked - https://vuejs.org/v2/api/#vm-mount
|
|
|
|
pipelineTableViewEl.appendChild(table.$el);
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
function destroyPipelines(app) {
|
|
|
|
if (app && app.$destroy) {
|
|
|
|
app.$destroy();
|
|
|
|
|
|
|
|
document.querySelector('#commit-pipeline-table-view').innerHTML = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
function loadDiffs({ url, sticky, tabs }) {
|
|
|
|
return axios.get(url).then(({ data }) => {
|
2022-05-07 20:08:51 +05:30
|
|
|
const $container = $('#diffs');
|
|
|
|
$container.html(data.html);
|
|
|
|
initDiffStatsDropdown(sticky);
|
|
|
|
|
|
|
|
localTimeAgo(document.querySelectorAll('#diffs .js-timeago'));
|
|
|
|
syntaxHighlight($('#diffs .js-syntax-highlight'));
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
tabs.createDiff();
|
|
|
|
tabs.setHubToDiff();
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
scrollToContainer('#diffs');
|
|
|
|
|
|
|
|
$('.diff-file').each((i, el) => {
|
|
|
|
new BlobForkSuggestion({
|
|
|
|
openButtons: $(el).find('.js-edit-blob-link-fork-toggler'),
|
|
|
|
forkButtons: $(el).find('.js-fork-suggestion-button'),
|
|
|
|
cancelButtons: $(el).find('.js-cancel-fork-suggestion-button'),
|
|
|
|
suggestionSections: $(el).find('.js-file-fork-suggestion-section'),
|
|
|
|
actionTextPieces: $(el).find('.js-file-fork-suggestion-section-action'),
|
|
|
|
}).init();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleLoader(state) {
|
|
|
|
$('.mr-loading-status .loading').toggleClass('hide', !state);
|
|
|
|
}
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
function getActionFromHref(href) {
|
|
|
|
let action = new URL(href).pathname.match(/\/(commits|diffs|pipelines).*$/);
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
action = action[0].replace(/(^\/|\.html)/g, '');
|
|
|
|
} else {
|
|
|
|
action = 'show';
|
|
|
|
}
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
const pageBundles = {
|
|
|
|
show: () => import(/* webpackPrefetch: true */ '~/mr_notes/init_notes'),
|
|
|
|
diffs: () => import(/* webpackPrefetch: true */ '~/diffs'),
|
|
|
|
};
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
export default class MergeRequestTabs {
|
|
|
|
constructor({ action, setUrl, stubLocation } = {}) {
|
2018-11-08 19:23:39 +05:30
|
|
|
this.mergeRequestTabs = document.querySelector('.merge-request-tabs-container');
|
|
|
|
this.mergeRequestTabsAll =
|
|
|
|
this.mergeRequestTabs && this.mergeRequestTabs.querySelectorAll
|
|
|
|
? this.mergeRequestTabs.querySelectorAll('.merge-request-tabs li')
|
|
|
|
: null;
|
|
|
|
this.mergeRequestTabPanes = document.querySelector('#diff-notes-app');
|
|
|
|
this.mergeRequestTabPanesAll =
|
|
|
|
this.mergeRequestTabPanes && this.mergeRequestTabPanes.querySelectorAll
|
|
|
|
? this.mergeRequestTabPanes.querySelectorAll('.tab-pane')
|
|
|
|
: null;
|
2021-10-27 15:23:28 +05:30
|
|
|
this.navbar = document.querySelector('.navbar-gitlab');
|
|
|
|
this.peek = document.getElementById('js-peek');
|
2022-07-16 23:28:13 +05:30
|
|
|
this.sidebar = document.querySelector('.js-right-sidebar');
|
|
|
|
this.pageLayout = document.querySelector('.layout-page');
|
2022-08-13 15:12:31 +05:30
|
|
|
this.expandSidebar = document.querySelectorAll('.js-expand-sidebar, .js-sidebar-toggle');
|
2021-10-27 15:23:28 +05:30
|
|
|
this.paddingTop = 16;
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
this.scrollPositions = {};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
this.commitsTab = document.querySelector('.tab-content .commits.tab-pane');
|
|
|
|
|
|
|
|
this.currentTab = null;
|
2018-03-17 18:26:18 +05:30
|
|
|
this.diffsLoaded = false;
|
2023-03-17 16:20:25 +05:30
|
|
|
this.diffsClass = null;
|
2018-03-17 18:26:18 +05:30
|
|
|
this.commitsLoaded = false;
|
|
|
|
this.fixedLayoutPref = null;
|
2020-05-24 23:13:21 +05:30
|
|
|
this.eventHub = createEventHub();
|
2023-03-04 22:38:38 +05:30
|
|
|
this.loadedPages = { [action]: true };
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
this.setUrl = setUrl !== undefined ? setUrl : true;
|
|
|
|
this.setCurrentAction = this.setCurrentAction.bind(this);
|
2023-03-17 16:20:25 +05:30
|
|
|
this.switchViewType = this.switchViewType.bind(this);
|
2018-03-17 18:26:18 +05:30
|
|
|
this.tabShown = this.tabShown.bind(this);
|
2018-11-08 19:23:39 +05:30
|
|
|
this.clickTab = this.clickTab.bind(this);
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if (stubLocation) {
|
|
|
|
location = stubLocation;
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
this.bindEvents();
|
2022-05-07 20:08:51 +05:30
|
|
|
this.mergeRequestTabs?.querySelector(`a[data-action='${action}']`)?.click?.();
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
bindEvents() {
|
2018-11-08 19:23:39 +05:30
|
|
|
$('.merge-request-tabs a[data-toggle="tabvue"]').on('click', this.clickTab);
|
2023-03-04 22:38:38 +05:30
|
|
|
window.addEventListener('popstate', () => {
|
|
|
|
const action = getActionFromHref(location.href);
|
|
|
|
|
|
|
|
this.tabShown(action, location.href);
|
|
|
|
this.eventHub.$emit('MergeRequestTabChange', action);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
2023-03-17 16:20:25 +05:30
|
|
|
this.eventHub.$on('diff:switch-view-type', this.switchViewType);
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
// Used in tests
|
|
|
|
unbindEvents() {
|
2018-11-08 19:23:39 +05:30
|
|
|
$('.merge-request-tabs a[data-toggle="tabvue"]').off('click', this.clickTab);
|
2023-03-17 16:20:25 +05:30
|
|
|
this.eventHub.$off('diff:switch-view-type', this.switchViewType);
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
storeScroll() {
|
|
|
|
if (this.currentTab) {
|
|
|
|
this.scrollPositions[this.currentTab] = document.documentElement.scrollTop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recallScroll(action) {
|
|
|
|
const storedPosition = this.scrollPositions[action];
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
window.scrollTo({
|
|
|
|
top: storedPosition && storedPosition > 0 ? storedPosition : 0,
|
|
|
|
left: 0,
|
|
|
|
behavior: 'auto',
|
|
|
|
});
|
|
|
|
}, FAST_DELAY_FOR_RERENDER);
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
clickTab(e) {
|
2018-11-08 19:23:39 +05:30
|
|
|
if (e.currentTarget) {
|
2018-03-17 18:26:18 +05:30
|
|
|
e.stopImmediatePropagation();
|
2017-08-17 22:00:37 +05:30
|
|
|
e.preventDefault();
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
this.storeScroll();
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
const { action } = e.currentTarget.dataset || {};
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
if (isMetaClick(e)) {
|
2018-11-08 19:23:39 +05:30
|
|
|
const targetLink = e.currentTarget.getAttribute('href');
|
|
|
|
window.open(targetLink, '_blank');
|
2019-09-04 21:01:54 +05:30
|
|
|
} else if (action) {
|
|
|
|
const href = e.currentTarget.getAttribute('href');
|
|
|
|
this.tabShown(action, href);
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
tabShown(action, href, shouldScroll = true) {
|
2023-03-04 22:38:38 +05:30
|
|
|
toggleLoader(false);
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if (action !== this.currentTab && this.mergeRequestTabs) {
|
|
|
|
this.currentTab = action;
|
2023-03-04 22:38:38 +05:30
|
|
|
if (this.setUrl) {
|
|
|
|
this.setCurrentAction(action);
|
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
if (this.mergeRequestTabPanesAll) {
|
2021-03-08 18:12:59 +05:30
|
|
|
this.mergeRequestTabPanesAll.forEach((el) => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const tabPane = el;
|
|
|
|
tabPane.style.display = 'none';
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
if (this.mergeRequestTabsAll) {
|
2021-03-08 18:12:59 +05:30
|
|
|
this.mergeRequestTabsAll.forEach((el) => {
|
2018-11-08 19:23:39 +05:30
|
|
|
el.classList.remove('active');
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
const tabPane = this.mergeRequestTabPanes.querySelector(`#${action}`);
|
|
|
|
if (tabPane) tabPane.style.display = 'block';
|
|
|
|
const tab = this.mergeRequestTabs.querySelector(`.${action}-tab`);
|
|
|
|
if (tab) tab.classList.add('active');
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
if (!this.loadedPages[action] && action in pageBundles) {
|
|
|
|
toggleLoader(true);
|
|
|
|
pageBundles[action]()
|
|
|
|
.then(({ default: init }) => {
|
|
|
|
toggleLoader(false);
|
|
|
|
init();
|
|
|
|
this.loadedPages[action] = true;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
toggleLoader(false);
|
|
|
|
createAlert({ message: __('MergeRequest|Failed to load the page') });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
if (window.gon?.features?.movedMrSidebar) {
|
|
|
|
this.expandSidebar?.forEach((el) =>
|
|
|
|
el.classList.toggle('gl-display-none!', action !== 'show'),
|
|
|
|
);
|
|
|
|
}
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if (action === 'commits') {
|
2023-01-13 00:05:48 +05:30
|
|
|
if (!this.commitsLoaded) {
|
|
|
|
this.loadCommits(href);
|
|
|
|
}
|
2022-07-16 23:28:13 +05:30
|
|
|
// this.hideSidebar();
|
2018-11-08 19:23:39 +05:30
|
|
|
this.resetViewContainer();
|
2022-05-07 20:08:51 +05:30
|
|
|
this.commitPipelinesTable = destroyPipelines(this.commitPipelinesTable);
|
2018-11-08 19:23:39 +05:30
|
|
|
} else if (action === 'new') {
|
2018-03-17 18:26:18 +05:30
|
|
|
this.expandView();
|
2018-11-08 19:23:39 +05:30
|
|
|
this.resetViewContainer();
|
2022-05-07 20:08:51 +05:30
|
|
|
this.commitPipelinesTable = destroyPipelines(this.commitPipelinesTable);
|
2018-11-08 19:23:39 +05:30
|
|
|
} else if (this.isDiffAction(action)) {
|
|
|
|
if (!isInVueNoteablePage()) {
|
2021-11-11 11:23:49 +05:30
|
|
|
/*
|
|
|
|
for pages where we have not yet converted to the new vue
|
|
|
|
implementation we load the diff tab content the old way,
|
|
|
|
inserting html rendered by the backend.
|
|
|
|
|
|
|
|
in practice, this only occurs when comparing commits in
|
|
|
|
the new merge request form page.
|
|
|
|
*/
|
2023-03-17 16:20:25 +05:30
|
|
|
this.loadDiff({ endpoint: href, strip: true });
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
2022-07-16 23:28:13 +05:30
|
|
|
// this.hideSidebar();
|
2018-12-05 23:21:45 +05:30
|
|
|
this.expandViewContainer();
|
2022-05-07 20:08:51 +05:30
|
|
|
this.commitPipelinesTable = destroyPipelines(this.commitPipelinesTable);
|
2018-11-08 19:23:39 +05:30
|
|
|
this.commitsTab.classList.remove('active');
|
|
|
|
} else if (action === 'pipelines') {
|
2022-07-16 23:28:13 +05:30
|
|
|
// this.hideSidebar();
|
2018-11-08 19:23:39 +05:30
|
|
|
this.resetViewContainer();
|
|
|
|
this.mountPipelinesView();
|
|
|
|
} else {
|
2021-11-11 11:23:49 +05:30
|
|
|
const notesTab = this.mergeRequestTabs.querySelector('.notes-tab');
|
|
|
|
const notesPane = this.mergeRequestTabPanes.querySelector('#notes');
|
|
|
|
if (notesPane) {
|
|
|
|
notesPane.style.display = 'block';
|
|
|
|
}
|
|
|
|
if (notesTab) {
|
|
|
|
notesTab.classList.add('active');
|
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
// this.showSidebar();
|
2018-11-08 19:23:39 +05:30
|
|
|
this.resetViewContainer();
|
2022-05-07 20:08:51 +05:30
|
|
|
this.commitPipelinesTable = destroyPipelines(this.commitPipelinesTable);
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
renderGFM(document.querySelector('.detail-page-description'));
|
2021-11-11 11:23:49 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
if (shouldScroll) this.recallScroll(action);
|
2019-02-15 15:39:39 +05:30
|
|
|
} else if (action === this.currentAction) {
|
|
|
|
// ContentTop is used to handle anything at the top of the page before the main content
|
|
|
|
const mainContentContainer = document.querySelector('.content-wrapper');
|
|
|
|
const tabContentContainer = document.querySelector('.tab-content');
|
|
|
|
|
|
|
|
if (mainContentContainer && tabContentContainer) {
|
|
|
|
const mainContentTop = mainContentContainer.getBoundingClientRect().top;
|
|
|
|
const tabContentTop = tabContentContainer.getBoundingClientRect().top;
|
|
|
|
|
|
|
|
// 51px is the height of the navbar buttons, e.g. `Discussion | Commits | Changes`
|
|
|
|
const scrollDestination = tabContentTop - mainContentTop - 51;
|
|
|
|
|
|
|
|
// scrollBehavior is only available in browsers that support scrollToOptions
|
2023-01-13 00:05:48 +05:30
|
|
|
if ('scrollBehavior' in document.documentElement.style && shouldScroll) {
|
2019-02-15 15:39:39 +05:30
|
|
|
window.scrollTo({
|
|
|
|
top: scrollDestination,
|
|
|
|
behavior: 'smooth',
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
window.scrollTo(0, scrollDestination);
|
|
|
|
}
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
this.eventHub.$emit('MergeRequestTabChange', action);
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
// Replaces the current merge request-specific action in the URL with a new one
|
2018-03-17 18:26:18 +05:30
|
|
|
//
|
|
|
|
// If the action is "notes", the URL is reset to the standard
|
|
|
|
// `MergeRequests#show` route.
|
|
|
|
//
|
|
|
|
// Examples:
|
|
|
|
//
|
2020-03-13 15:44:24 +05:30
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1"
|
2018-03-17 18:26:18 +05:30
|
|
|
// setCurrentAction('diffs')
|
2020-03-13 15:44:24 +05:30
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/diffs"
|
2018-03-17 18:26:18 +05:30
|
|
|
//
|
2020-03-13 15:44:24 +05:30
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/diffs"
|
2018-03-17 18:26:18 +05:30
|
|
|
// setCurrentAction('show')
|
2020-03-13 15:44:24 +05:30
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1"
|
2018-03-17 18:26:18 +05:30
|
|
|
//
|
2020-03-13 15:44:24 +05:30
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/diffs"
|
2018-03-17 18:26:18 +05:30
|
|
|
// setCurrentAction('commits')
|
2020-03-13 15:44:24 +05:30
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/commits"
|
2018-03-17 18:26:18 +05:30
|
|
|
//
|
|
|
|
// Returns the new URL String
|
|
|
|
setCurrentAction(action) {
|
|
|
|
this.currentAction = action;
|
|
|
|
|
|
|
|
// Remove a trailing '/commits' '/diffs' '/pipelines'
|
|
|
|
let newState = location.pathname.replace(/\/(commits|diffs|pipelines)(\.html)?\/?$/, '');
|
|
|
|
|
|
|
|
// Append the new action if we're on a tab other than 'notes'
|
|
|
|
if (this.currentAction !== 'show' && this.currentAction !== 'new') {
|
|
|
|
newState += `/${this.currentAction}`;
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
// Ensure parameters and hash come along for the ride
|
|
|
|
newState += location.search + location.hash;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
if (window.location.pathname !== newState) {
|
2020-06-23 00:09:42 +05:30
|
|
|
window.history.pushState(
|
|
|
|
{
|
|
|
|
url: newState,
|
|
|
|
action: this.currentAction,
|
|
|
|
},
|
|
|
|
document.title,
|
|
|
|
newState,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
window.history.replaceState(
|
|
|
|
{
|
|
|
|
url: window.location.href,
|
|
|
|
action,
|
|
|
|
},
|
|
|
|
document.title,
|
|
|
|
window.location.href,
|
|
|
|
);
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return newState;
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
getCurrentAction() {
|
|
|
|
return this.currentAction;
|
|
|
|
}
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
loadCommits(source, page = 1) {
|
2022-05-07 20:08:51 +05:30
|
|
|
toggleLoader(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
axios
|
2023-01-13 00:05:48 +05:30
|
|
|
.get(`${source}.json`, { params: { page, per_page: 100 } })
|
2018-03-17 18:26:18 +05:30
|
|
|
.then(({ data }) => {
|
2023-01-13 00:05:48 +05:30
|
|
|
toggleLoader(false);
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
const commitsDiv = document.querySelector('div#commits');
|
2022-10-11 01:57:18 +05:30
|
|
|
// eslint-disable-next-line no-unsanitized/property
|
2023-01-13 00:05:48 +05:30
|
|
|
commitsDiv.innerHTML += data.html;
|
2021-09-30 23:02:18 +05:30
|
|
|
localTimeAgo(commitsDiv.querySelectorAll('.js-timeago'));
|
2018-03-17 18:26:18 +05:30
|
|
|
this.commitsLoaded = true;
|
2022-05-07 20:08:51 +05:30
|
|
|
scrollToContainer('#commits');
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
const loadMoreButton = document.querySelector('.js-load-more-commits');
|
|
|
|
|
|
|
|
if (loadMoreButton) {
|
|
|
|
loadMoreButton.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
loadMoreButton.remove();
|
|
|
|
this.loadCommits(source, loadMoreButton.dataset.nextPage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data.next_page) {
|
|
|
|
return import('./add_context_commits_modal');
|
|
|
|
}
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
return null;
|
2018-03-17 18:26:18 +05:30
|
|
|
})
|
2023-01-13 00:05:48 +05:30
|
|
|
.then((m) => m?.default())
|
2018-03-17 18:26:18 +05:30
|
|
|
.catch(() => {
|
2022-05-07 20:08:51 +05:30
|
|
|
toggleLoader(false);
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2021-09-30 23:02:18 +05:30
|
|
|
message: __('An error occurred while fetching this tab.'),
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
mountPipelinesView() {
|
2022-05-07 20:08:51 +05:30
|
|
|
this.commitPipelinesTable = mountPipelines();
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
// load the diff tab content from the backend
|
2023-03-17 16:20:25 +05:30
|
|
|
loadDiff({ endpoint, strip = true }) {
|
2018-03-17 18:26:18 +05:30
|
|
|
if (this.diffsLoaded) {
|
|
|
|
document.dispatchEvent(new CustomEvent('scroll'));
|
|
|
|
return;
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
// We extract pathname for the current Changes tab anchor href
|
|
|
|
// some pages like MergeRequestsController#new has query parameters on that anchor
|
|
|
|
const diffUrl = strip ? `${parseUrlPathname(endpoint)}.json${location.search}` : endpoint;
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
loadDiffs({
|
2023-03-17 16:20:25 +05:30
|
|
|
url: diffUrl,
|
2022-05-07 20:08:51 +05:30
|
|
|
sticky: computeTopOffset(this.mergeRequestTabs),
|
2023-03-17 16:20:25 +05:30
|
|
|
tabs: this,
|
2022-05-07 20:08:51 +05:30
|
|
|
})
|
|
|
|
.then(() => {
|
2018-12-05 23:21:45 +05:30
|
|
|
if (this.isDiffAction(this.currentAction)) {
|
2018-03-17 18:26:18 +05:30
|
|
|
this.expandViewContainer();
|
|
|
|
}
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
this.diffsLoaded = true;
|
2018-03-17 18:26:18 +05:30
|
|
|
})
|
|
|
|
.catch(() => {
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2021-09-30 23:02:18 +05:30
|
|
|
message: __('An error occurred while fetching this tab.'),
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2023-03-17 16:20:25 +05:30
|
|
|
switchViewType({ source }) {
|
|
|
|
this.diffsLoaded = false;
|
|
|
|
|
|
|
|
this.loadDiff({ endpoint: source, strip: false });
|
|
|
|
}
|
|
|
|
createDiff() {
|
|
|
|
if (!this.diffsClass) {
|
|
|
|
this.diffsClass = new Diff({ mergeRequestEventHub: this.eventHub });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setHubToDiff() {
|
|
|
|
if (this.diffsClass) {
|
|
|
|
this.diffsClass.mrHub = this.eventHub;
|
|
|
|
}
|
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
diffViewType() {
|
2019-03-02 22:35:43 +05:30
|
|
|
return $('.js-diff-view-buttons button.active').data('viewType');
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
isDiffAction(action) {
|
|
|
|
return action === 'diffs' || action === 'new/diffs';
|
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expandViewContainer(removeLimited = true) {
|
2018-03-17 18:26:18 +05:30
|
|
|
const $wrapper = $('.content-wrapper .container-fluid').not('.breadcrumbs');
|
|
|
|
if (this.fixedLayoutPref === null) {
|
|
|
|
this.fixedLayoutPref = $wrapper.hasClass('container-limited');
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2018-12-05 23:21:45 +05:30
|
|
|
if (this.diffViewType() === 'parallel' || removeLimited) {
|
|
|
|
$wrapper.removeClass('container-limited');
|
|
|
|
} else {
|
|
|
|
$wrapper.toggleClass('container-limited', this.fixedLayoutPref);
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
resetViewContainer() {
|
|
|
|
if (this.fixedLayoutPref !== null) {
|
2018-05-09 12:01:36 +05:30
|
|
|
$('.content-wrapper .container-fluid').toggleClass('container-limited', this.fixedLayoutPref);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
// Expand the issuable sidebar unless the user explicitly collapsed it
|
|
|
|
expandView() {
|
2022-04-04 11:22:00 +05:30
|
|
|
if (parseBoolean(getCookie('collapsed_gutter'))) {
|
2018-03-17 18:26:18 +05:30
|
|
|
return;
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2021-01-03 14:25:43 +05:30
|
|
|
const $gutterBtn = $('.js-sidebar-toggle');
|
|
|
|
const $collapseSvg = $gutterBtn.find('.js-sidebar-collapse');
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
// Wait until listeners are set
|
|
|
|
setTimeout(() => {
|
|
|
|
// Only when sidebar is collapsed
|
2021-01-03 14:25:43 +05:30
|
|
|
if ($collapseSvg.length && !$collapseSvg.hasClass('hidden')) {
|
|
|
|
$gutterBtn.trigger('click', [true]);
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
}, 0);
|
|
|
|
}
|
2022-07-16 23:28:13 +05:30
|
|
|
|
|
|
|
hideSidebar() {
|
|
|
|
if (!isInVueNoteablePage() || this.cachedPageLayoutClasses) return;
|
|
|
|
|
|
|
|
this.cachedPageLayoutClasses = this.pageLayout.className;
|
|
|
|
this.pageLayout.classList.remove(
|
|
|
|
'right-sidebar-collapsed',
|
|
|
|
'right-sidebar-expanded',
|
|
|
|
'page-with-icon-sidebar',
|
|
|
|
);
|
|
|
|
this.sidebar.style.width = '0px';
|
|
|
|
}
|
|
|
|
|
|
|
|
showSidebar() {
|
|
|
|
if (!isInVueNoteablePage() || !this.cachedPageLayoutClasses) return;
|
|
|
|
|
|
|
|
this.pageLayout.className = this.cachedPageLayoutClasses;
|
|
|
|
this.sidebar.style.width = '';
|
|
|
|
delete this.cachedPageLayoutClasses;
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|