2016-12-02 18:43:20 -05:00
|
|
|
/* eslint-disable no-new, class-methods-use-this */
|
2019-12-20 16:08:00 -05:00
|
|
|
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import $ from 'jquery';
|
2017-03-11 01:45:34 -05:00
|
|
|
import Cookies from 'js-cookie';
|
2021-02-16 19:09:19 -05:00
|
|
|
import Vue from 'vue';
|
2020-05-18 05:08:12 -04:00
|
|
|
import createEventHub from '~/helpers/event_hub_factory';
|
2017-04-22 01:54:03 -04:00
|
|
|
import BlobForkSuggestion from './blob/blob_fork_suggestion';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Diff from './diff';
|
2021-06-18 02:10:20 -04:00
|
|
|
import createFlash from './flash';
|
2021-09-08 14:11:23 -04:00
|
|
|
import { initDiffStatsDropdown } from './init_diff_stats_dropdown';
|
2021-02-14 13:09:20 -05:00
|
|
|
import axios from './lib/utils/axios_utils';
|
2018-11-21 10:20:32 -05:00
|
|
|
import {
|
|
|
|
parseUrlPathname,
|
|
|
|
isMetaClick,
|
|
|
|
parseBoolean,
|
2020-12-30 04:10:10 -05:00
|
|
|
scrollToElement,
|
2018-11-21 10:20:32 -05:00
|
|
|
} from './lib/utils/common_utils';
|
2017-12-13 04:37:07 -05:00
|
|
|
import { localTimeAgo } from './lib/utils/datetime_utility';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { isInVueNoteablePage } from './lib/utils/dom_utils';
|
2019-05-03 09:00:44 -04:00
|
|
|
import { __ } from './locale';
|
2021-02-14 13:09:20 -05:00
|
|
|
import syntaxHighlight from './syntax_highlight';
|
2017-10-07 00:25:17 -04:00
|
|
|
|
2016-07-26 23:32:10 -04:00
|
|
|
// 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-01-20 19:08:46 -05:00
|
|
|
// <a data-action="notes" data-target="#notes" data-toggle="tab" href="/foo/bar/-/merge_requests/1">
|
2016-07-26 23:32:10 -04:00
|
|
|
// Discussion
|
|
|
|
// </a>
|
|
|
|
// </li>
|
|
|
|
// <li class="commits-tab">
|
2020-01-20 19:08:46 -05:00
|
|
|
// <a data-action="commits" data-target="#commits" data-toggle="tab" href="/foo/bar/-/merge_requests/1/commits">
|
2016-07-26 23:32:10 -04:00
|
|
|
// Commits
|
|
|
|
// </a>
|
|
|
|
// </li>
|
|
|
|
// <li class="diffs-tab">
|
2020-01-20 19:08:46 -05:00
|
|
|
// <a data-action="diffs" data-target="#diffs" data-toggle="tab" href="/foo/bar/-/merge_requests/1/diffs">
|
2016-07-26 23:32:10 -04:00
|
|
|
// 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-10-27 16:32:30 -04:00
|
|
|
|
2021-08-24 14:10:53 -04:00
|
|
|
// <100ms is typically indistinguishable from "instant" for users, but allows for re-rendering
|
|
|
|
const FAST_DELAY_FOR_RERENDER = 75;
|
2017-12-15 04:31:58 -05:00
|
|
|
// Store the `location` object, allowing for easier stubbing in tests
|
2018-06-16 17:50:13 -04:00
|
|
|
let { location } = window;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
export default class MergeRequestTabs {
|
|
|
|
constructor({ action, setUrl, stubLocation } = {}) {
|
2018-06-30 09:17:46 -04:00
|
|
|
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-08-02 05:10:09 -04:00
|
|
|
this.navbar = document.querySelector('.navbar-gitlab');
|
|
|
|
this.peek = document.getElementById('js-peek');
|
|
|
|
this.paddingTop = 16;
|
2018-06-30 09:17:46 -04:00
|
|
|
|
2021-08-24 14:10:53 -04:00
|
|
|
this.scrollPositions = {};
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.commitsTab = document.querySelector('.tab-content .commits.tab-pane');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-06-30 09:17:46 -04:00
|
|
|
this.currentTab = null;
|
2017-12-15 04:31:58 -05:00
|
|
|
this.diffsLoaded = false;
|
|
|
|
this.pipelinesLoaded = false;
|
|
|
|
this.commitsLoaded = false;
|
|
|
|
this.fixedLayoutPref = null;
|
2020-05-18 05:08:12 -04:00
|
|
|
this.eventHub = createEventHub();
|
2017-01-31 04:14:22 -05:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
this.setUrl = setUrl !== undefined ? setUrl : true;
|
|
|
|
this.setCurrentAction = this.setCurrentAction.bind(this);
|
|
|
|
this.tabShown = this.tabShown.bind(this);
|
2018-06-30 09:17:46 -04:00
|
|
|
this.clickTab = this.clickTab.bind(this);
|
2017-01-31 04:14:22 -05:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
if (stubLocation) {
|
|
|
|
location = stubLocation;
|
2016-10-25 02:27:21 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
this.bindEvents();
|
2018-06-30 09:17:46 -04:00
|
|
|
if (
|
|
|
|
this.mergeRequestTabs &&
|
|
|
|
this.mergeRequestTabs.querySelector(`a[data-action='${action}']`) &&
|
|
|
|
this.mergeRequestTabs.querySelector(`a[data-action='${action}']`).click
|
2018-09-19 18:42:20 -04:00
|
|
|
) {
|
2018-06-30 09:17:46 -04:00
|
|
|
this.mergeRequestTabs.querySelector(`a[data-action='${action}']`).click();
|
2018-09-19 18:42:20 -04:00
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2017-04-07 08:11:42 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
bindEvents() {
|
2018-06-30 09:17:46 -04:00
|
|
|
$('.merge-request-tabs a[data-toggle="tabvue"]').on('click', this.clickTab);
|
2020-12-23 16:10:24 -05:00
|
|
|
window.addEventListener('popstate', (event) => {
|
2020-06-02 08:08:33 -04:00
|
|
|
if (event.state && event.state.action) {
|
|
|
|
this.tabShown(event.state.action, event.target.location);
|
|
|
|
this.currentAction = event.state.action;
|
|
|
|
this.eventHub.$emit('MergeRequestTabChange', this.getCurrentAction());
|
|
|
|
}
|
|
|
|
});
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
// Used in tests
|
|
|
|
unbindEvents() {
|
2018-06-30 09:17:46 -04:00
|
|
|
$('.merge-request-tabs a[data-toggle="tabvue"]').off('click', this.clickTab);
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
destroyPipelinesView() {
|
|
|
|
if (this.commitPipelinesTable) {
|
|
|
|
this.commitPipelinesTable.$destroy();
|
|
|
|
this.commitPipelinesTable = null;
|
|
|
|
|
|
|
|
document.querySelector('#commit-pipeline-table-view').innerHTML = '';
|
2017-01-31 04:14:22 -05:00
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2017-01-31 04:14:22 -05:00
|
|
|
|
2021-08-24 14:10:53 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
clickTab(e) {
|
2018-06-30 09:17:46 -04:00
|
|
|
if (e.currentTarget) {
|
2017-12-15 04:31:58 -05:00
|
|
|
e.stopImmediatePropagation();
|
|
|
|
e.preventDefault();
|
2018-06-30 09:17:46 -04:00
|
|
|
|
2021-08-24 14:10:53 -04:00
|
|
|
this.storeScroll();
|
|
|
|
|
2019-06-11 16:40:57 -04:00
|
|
|
const { action } = e.currentTarget.dataset || {};
|
2018-06-30 09:17:46 -04:00
|
|
|
|
2019-06-11 16:40:57 -04:00
|
|
|
if (isMetaClick(e)) {
|
2018-06-30 09:17:46 -04:00
|
|
|
const targetLink = e.currentTarget.getAttribute('href');
|
|
|
|
window.open(targetLink, '_blank');
|
2019-06-11 16:40:57 -04:00
|
|
|
} else if (action) {
|
|
|
|
const href = e.currentTarget.getAttribute('href');
|
|
|
|
this.tabShown(action, href);
|
2020-06-02 08:08:33 -04:00
|
|
|
|
|
|
|
if (this.setUrl) {
|
|
|
|
this.setCurrentAction(action);
|
|
|
|
}
|
2018-06-30 09:17:46 -04:00
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
|
|
|
}
|
2017-10-07 00:25:17 -04:00
|
|
|
|
2018-06-30 09:17:46 -04:00
|
|
|
tabShown(action, href) {
|
|
|
|
if (action !== this.currentTab && this.mergeRequestTabs) {
|
|
|
|
this.currentTab = action;
|
|
|
|
|
|
|
|
if (this.mergeRequestTabPanesAll) {
|
2020-12-23 16:10:24 -05:00
|
|
|
this.mergeRequestTabPanesAll.forEach((el) => {
|
2018-06-30 09:17:46 -04:00
|
|
|
const tabPane = el;
|
|
|
|
tabPane.style.display = 'none';
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2018-06-30 09:17:46 -04:00
|
|
|
|
|
|
|
if (this.mergeRequestTabsAll) {
|
2020-12-23 16:10:24 -05:00
|
|
|
this.mergeRequestTabsAll.forEach((el) => {
|
2018-06-30 09:17:46 -04:00
|
|
|
el.classList.remove('active');
|
|
|
|
});
|
2016-08-17 23:51:49 -04:00
|
|
|
}
|
2018-06-30 09:17:46 -04:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
if (action === 'commits') {
|
|
|
|
this.loadCommits(href);
|
2017-12-15 04:31:58 -05:00
|
|
|
this.expandView();
|
2018-06-30 09:17:46 -04:00
|
|
|
this.resetViewContainer();
|
|
|
|
this.destroyPipelinesView();
|
|
|
|
} else if (action === 'new') {
|
|
|
|
this.expandView();
|
|
|
|
this.resetViewContainer();
|
|
|
|
this.destroyPipelinesView();
|
|
|
|
} else if (this.isDiffAction(action)) {
|
|
|
|
if (!isInVueNoteablePage()) {
|
2021-08-19 08:08:53 -04:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2018-06-30 09:17:46 -04:00
|
|
|
this.loadDiff(href);
|
|
|
|
}
|
2019-12-20 16:08:00 -05:00
|
|
|
if (bp.getBreakpointSize() !== 'xl') {
|
2018-06-30 09:17:46 -04:00
|
|
|
this.shrinkView();
|
|
|
|
}
|
2018-10-03 05:05:43 -04:00
|
|
|
this.expandViewContainer();
|
2018-06-30 09:17:46 -04:00
|
|
|
this.destroyPipelinesView();
|
|
|
|
this.commitsTab.classList.remove('active');
|
|
|
|
} else if (action === 'pipelines') {
|
|
|
|
this.resetViewContainer();
|
|
|
|
this.mountPipelinesView();
|
|
|
|
} else {
|
2021-08-24 14:10:53 -04:00
|
|
|
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-06-30 09:17:46 -04:00
|
|
|
|
|
|
|
if (bp.getBreakpointSize() !== 'xs') {
|
|
|
|
this.expandView();
|
|
|
|
}
|
|
|
|
this.resetViewContainer();
|
|
|
|
this.destroyPipelinesView();
|
|
|
|
}
|
2020-06-22 14:08:47 -04:00
|
|
|
|
|
|
|
$('.detail-page-description').renderGFM();
|
2021-08-24 14:10:53 -04:00
|
|
|
|
|
|
|
this.recallScroll(action);
|
2018-11-27 13:05:16 -05:00
|
|
|
} 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
|
|
|
|
if ('scrollBehavior' in document.documentElement.style) {
|
|
|
|
window.scrollTo({
|
|
|
|
top: scrollDestination,
|
|
|
|
behavior: 'smooth',
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
window.scrollTo(0, scrollDestination);
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2020-08-10 08:09:55 -04:00
|
|
|
|
|
|
|
this.eventHub.$emit('MergeRequestTabChange', action);
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2020-12-30 04:10:10 -05:00
|
|
|
scrollToContainerElement(container) {
|
2017-12-15 04:31:58 -05:00
|
|
|
if (location.hash) {
|
|
|
|
const $el = $(`${container} ${location.hash}:not(.match)`);
|
2020-12-30 04:10:10 -05:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
if ($el.length) {
|
2020-12-30 04:10:10 -05:00
|
|
|
scrollToElement($el[0]);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2016-10-25 11:42:25 -04:00
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
|
|
|
|
2021-04-08 11:09:06 -04:00
|
|
|
// Replaces the current merge request-specific action in the URL with a new one
|
2017-12-15 04:31:58 -05:00
|
|
|
//
|
|
|
|
// If the action is "notes", the URL is reset to the standard
|
|
|
|
// `MergeRequests#show` route.
|
|
|
|
//
|
|
|
|
// Examples:
|
|
|
|
//
|
2020-01-20 19:08:46 -05:00
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1"
|
2017-12-15 04:31:58 -05:00
|
|
|
// setCurrentAction('diffs')
|
2020-01-20 19:08:46 -05:00
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/diffs"
|
2017-12-15 04:31:58 -05:00
|
|
|
//
|
2020-01-20 19:08:46 -05:00
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/diffs"
|
2017-12-15 04:31:58 -05:00
|
|
|
// setCurrentAction('show')
|
2020-01-20 19:08:46 -05:00
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1"
|
2017-12-15 04:31:58 -05:00
|
|
|
//
|
2020-01-20 19:08:46 -05:00
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/diffs"
|
2017-12-15 04:31:58 -05:00
|
|
|
// setCurrentAction('commits')
|
2020-01-20 19:08:46 -05:00
|
|
|
// location.pathname # => "/namespace/project/-/merge_requests/1/commits"
|
2017-12-15 04:31:58 -05:00
|
|
|
//
|
|
|
|
// 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}`;
|
2016-10-25 11:42:25 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
// Ensure parameters and hash come along for the ride
|
|
|
|
newState += location.search + location.hash;
|
2016-10-25 14:33:03 -04:00
|
|
|
|
2020-06-02 08:08:33 -04:00
|
|
|
if (window.history.state && window.history.state.url && window.location.pathname !== newState) {
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
}
|
2016-10-25 14:33:03 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
return newState;
|
|
|
|
}
|
2016-10-25 11:42:25 -04:00
|
|
|
|
2018-02-27 19:10:43 -05:00
|
|
|
getCurrentAction() {
|
|
|
|
return this.currentAction;
|
|
|
|
}
|
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
loadCommits(source) {
|
|
|
|
if (this.commitsLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-30 12:23:27 -05:00
|
|
|
|
2018-01-31 04:27:30 -05:00
|
|
|
this.toggleLoading(true);
|
2018-01-30 12:23:27 -05:00
|
|
|
|
2018-04-13 03:44:35 -04:00
|
|
|
axios
|
|
|
|
.get(`${source}.json`)
|
2018-01-30 12:23:27 -05:00
|
|
|
.then(({ data }) => {
|
2021-07-14 02:09:45 -04:00
|
|
|
const commitsDiv = document.querySelector('div#commits');
|
|
|
|
commitsDiv.innerHTML = data.html;
|
|
|
|
localTimeAgo(commitsDiv.querySelectorAll('.js-timeago'));
|
2017-12-15 04:31:58 -05:00
|
|
|
this.commitsLoaded = true;
|
2020-12-30 04:10:10 -05:00
|
|
|
this.scrollToContainerElement('#commits');
|
2018-01-30 12:23:27 -05:00
|
|
|
|
|
|
|
this.toggleLoading(false);
|
2021-07-09 08:08:17 -04:00
|
|
|
|
|
|
|
return import('./add_context_commits_modal');
|
2018-01-30 12:23:27 -05:00
|
|
|
})
|
2021-07-09 08:08:17 -04:00
|
|
|
.then((m) => m.default())
|
2018-02-02 11:33:38 -05:00
|
|
|
.catch(() => {
|
|
|
|
this.toggleLoading(false);
|
2021-06-18 02:10:20 -04:00
|
|
|
createFlash({
|
|
|
|
message: __('An error occurred while fetching this tab.'),
|
|
|
|
});
|
2018-02-02 11:33:38 -05:00
|
|
|
});
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2017-01-13 16:54:16 -05:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
mountPipelinesView() {
|
|
|
|
const pipelineTableViewEl = document.querySelector('#commit-pipeline-table-view');
|
2021-02-16 19:09:19 -05:00
|
|
|
const { mrWidgetData } = gl;
|
|
|
|
|
|
|
|
this.commitPipelinesTable = new Vue({
|
2021-07-09 08:08:17 -04:00
|
|
|
components: {
|
|
|
|
CommitPipelinesTable: () => import('~/commit/pipelines/pipelines_table.vue'),
|
|
|
|
},
|
2020-11-27 07:09:14 -05:00
|
|
|
provide: {
|
2021-05-05 17:09:59 -04:00
|
|
|
artifactsEndpoint: pipelineTableViewEl.dataset.artifactsEndpoint,
|
|
|
|
artifactsEndpointPlaceholder: pipelineTableViewEl.dataset.artifactsEndpointPlaceholder,
|
2020-11-27 07:09:14 -05:00
|
|
|
targetProjectFullPath: mrWidgetData?.target_project_full_path || '',
|
|
|
|
},
|
2021-02-16 19:09:19 -05:00
|
|
|
render(createElement) {
|
2021-07-09 08:08:17 -04:00
|
|
|
return createElement('commit-pipelines-table', {
|
2021-02-16 19:09:19 -05:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2017-12-15 04:31:58 -05:00
|
|
|
}).$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(this.commitPipelinesTable.$el);
|
|
|
|
}
|
2016-10-25 11:42:25 -04:00
|
|
|
|
2021-08-19 08:08:53 -04:00
|
|
|
// load the diff tab content from the backend
|
2017-12-15 04:31:58 -05:00
|
|
|
loadDiff(source) {
|
|
|
|
if (this.diffsLoaded) {
|
|
|
|
document.dispatchEvent(new CustomEvent('scroll'));
|
|
|
|
return;
|
2016-10-25 11:42:25 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
// We extract pathname for the current Changes tab anchor href
|
|
|
|
// some pages like MergeRequestsController#new has query parameters on that anchor
|
|
|
|
const urlPathname = parseUrlPathname(source);
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
this.toggleLoading(true);
|
|
|
|
|
2018-04-13 03:44:35 -04:00
|
|
|
axios
|
|
|
|
.get(`${urlPathname}.json${location.search}`)
|
2018-01-30 12:23:27 -05:00
|
|
|
.then(({ data }) => {
|
2017-12-15 04:31:58 -05:00
|
|
|
const $container = $('#diffs');
|
|
|
|
$container.html(data.html);
|
2021-09-08 14:11:23 -04:00
|
|
|
initDiffStatsDropdown(this.stickyTop);
|
2017-03-22 22:39:09 -04:00
|
|
|
|
2021-07-14 02:09:45 -04:00
|
|
|
localTimeAgo(document.querySelectorAll('#diffs .js-timeago'));
|
2017-12-15 04:31:58 -05:00
|
|
|
syntaxHighlight($('#diffs .js-syntax-highlight'));
|
2016-08-11 03:00:17 -04:00
|
|
|
|
2018-10-03 05:05:43 -04:00
|
|
|
if (this.isDiffAction(this.currentAction)) {
|
2017-12-15 04:31:58 -05:00
|
|
|
this.expandViewContainer();
|
|
|
|
}
|
|
|
|
this.diffsLoaded = true;
|
|
|
|
|
|
|
|
new Diff();
|
2020-12-30 04:10:10 -05:00
|
|
|
this.scrollToContainerElement('#diffs');
|
2017-12-15 04:31:58 -05:00
|
|
|
|
|
|
|
$('.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'),
|
2018-04-13 03:44:35 -04:00
|
|
|
}).init();
|
2017-12-15 04:31:58 -05:00
|
|
|
});
|
|
|
|
|
2018-01-30 12:23:27 -05:00
|
|
|
this.toggleLoading(false);
|
|
|
|
})
|
2018-02-02 11:33:38 -05:00
|
|
|
.catch(() => {
|
|
|
|
this.toggleLoading(false);
|
2021-06-18 02:10:20 -04:00
|
|
|
createFlash({
|
|
|
|
message: __('An error occurred while fetching this tab.'),
|
|
|
|
});
|
2018-02-02 11:33:38 -05:00
|
|
|
});
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2017-05-12 06:19:32 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
// Show or hide the loading spinner
|
|
|
|
//
|
|
|
|
// status - Boolean, true to show, false to hide
|
|
|
|
toggleLoading(status) {
|
2018-06-13 10:39:03 -04:00
|
|
|
$('.mr-loading-status .loading').toggleClass('hide', !status);
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2016-07-25 17:14:14 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
diffViewType() {
|
2019-01-24 09:48:03 -05:00
|
|
|
return $('.js-diff-view-buttons button.active').data('viewType');
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
isDiffAction(action) {
|
|
|
|
return action === 'diffs' || action === 'new/diffs';
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-10-03 05:05:43 -04:00
|
|
|
expandViewContainer(removeLimited = true) {
|
2017-12-15 04:31:58 -05:00
|
|
|
const $wrapper = $('.content-wrapper .container-fluid').not('.breadcrumbs');
|
|
|
|
if (this.fixedLayoutPref === null) {
|
|
|
|
this.fixedLayoutPref = $wrapper.hasClass('container-limited');
|
2016-10-25 11:42:25 -04:00
|
|
|
}
|
2018-10-03 05:05:43 -04:00
|
|
|
if (this.diffViewType() === 'parallel' || removeLimited) {
|
|
|
|
$wrapper.removeClass('container-limited');
|
|
|
|
} else {
|
2018-10-19 05:37:42 -04:00
|
|
|
$wrapper.toggleClass('container-limited', this.fixedLayoutPref);
|
2018-10-03 05:05:43 -04:00
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2016-08-11 03:00:17 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
resetViewContainer() {
|
|
|
|
if (this.fixedLayoutPref !== null) {
|
2018-04-13 03:44:35 -04:00
|
|
|
$('.content-wrapper .container-fluid').toggleClass('container-limited', this.fixedLayoutPref);
|
2016-10-25 11:42:25 -04:00
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
2016-09-19 19:02:52 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
shrinkView() {
|
2020-10-16 11:08:46 -04:00
|
|
|
const $gutterBtn = $('.js-sidebar-toggle:visible');
|
|
|
|
const $expandSvg = $gutterBtn.find('.js-sidebar-expand');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
// Wait until listeners are set
|
|
|
|
setTimeout(() => {
|
|
|
|
// Only when sidebar is expanded
|
2020-10-16 11:08:46 -04:00
|
|
|
if ($expandSvg.length && $expandSvg.hasClass('hidden')) {
|
|
|
|
$gutterBtn.trigger('click', [true]);
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}
|
2016-10-25 11:42:25 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
// Expand the issuable sidebar unless the user explicitly collapsed it
|
|
|
|
expandView() {
|
2018-11-21 10:20:32 -05:00
|
|
|
if (parseBoolean(Cookies.get('collapsed_gutter'))) {
|
2017-12-15 04:31:58 -05:00
|
|
|
return;
|
2016-10-25 11:42:25 -04:00
|
|
|
}
|
2020-10-16 11:08:46 -04:00
|
|
|
const $gutterBtn = $('.js-sidebar-toggle');
|
|
|
|
const $collapseSvg = $gutterBtn.find('.js-sidebar-collapse');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
// Wait until listeners are set
|
|
|
|
setTimeout(() => {
|
|
|
|
// Only when sidebar is collapsed
|
2020-10-16 11:08:46 -04:00
|
|
|
if ($collapseSvg.length && !$collapseSvg.hasClass('hidden')) {
|
|
|
|
$gutterBtn.trigger('click', [true]);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}, 0);
|
|
|
|
}
|
2021-08-02 05:10:09 -04:00
|
|
|
|
|
|
|
get stickyTop() {
|
|
|
|
let stickyTop = this.navbar ? this.navbar.offsetHeight : 0;
|
|
|
|
|
|
|
|
if (this.peek) {
|
|
|
|
stickyTop += this.peek.offsetHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mergeRequestTabs) {
|
|
|
|
stickyTop += this.mergeRequestTabs.offsetHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stickyTop;
|
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|