2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2020-04-08 14:13:33 +05:30
|
|
|
import initPopover from '~/blob/suggest_gitlab_ci_yml';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2023-01-13 00:05:48 +05:30
|
|
|
import { setCookie } from '~/lib/utils/common_utils';
|
2020-04-22 19:07:51 +05:30
|
|
|
import Tracking from '~/tracking';
|
2021-03-11 19:13:27 +05:30
|
|
|
import NewCommitForm from '../new_commit_form';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
const initPopovers = () => {
|
|
|
|
const suggestEl = document.querySelector('.js-suggest-gitlab-ci-yml');
|
|
|
|
|
|
|
|
if (suggestEl) {
|
|
|
|
const commitButton = document.querySelector('#commit-changes');
|
|
|
|
|
|
|
|
initPopover(suggestEl);
|
|
|
|
|
|
|
|
if (commitButton) {
|
|
|
|
const { dismissKey, humanAccess } = suggestEl.dataset;
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const mergeRequestPath = urlParams.get('mr_path') || true;
|
|
|
|
|
|
|
|
const commitCookieName = `suggest_gitlab_ci_yml_commit_${dismissKey}`;
|
|
|
|
const commitTrackLabel = 'suggest_gitlab_ci_yml_commit_changes';
|
|
|
|
const commitTrackValue = '20';
|
|
|
|
|
|
|
|
commitButton.addEventListener('click', () => {
|
|
|
|
setCookie(commitCookieName, mergeRequestPath);
|
|
|
|
|
|
|
|
Tracking.event(undefined, 'click_button', {
|
|
|
|
label: commitTrackLabel,
|
|
|
|
property: humanAccess,
|
|
|
|
value: commitTrackValue,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
export default () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const editBlobForm = $('.js-edit-blob-form');
|
|
|
|
|
|
|
|
if (editBlobForm.length) {
|
2018-03-27 19:54:05 +05:30
|
|
|
const urlRoot = editBlobForm.data('relativeUrlRoot');
|
|
|
|
const assetsPath = editBlobForm.data('assetsPrefix');
|
2019-07-07 11:18:12 +05:30
|
|
|
const filePath = `${editBlobForm.data('blobFilename')}`;
|
2018-03-27 19:54:05 +05:30
|
|
|
const currentAction = $('.js-file-title').data('currentAction');
|
2018-12-05 23:21:45 +05:30
|
|
|
const projectId = editBlobForm.data('project-id');
|
2019-02-15 15:39:39 +05:30
|
|
|
const isMarkdown = editBlobForm.data('is-markdown');
|
2021-10-27 15:23:28 +05:30
|
|
|
const previewMarkdownPath = editBlobForm.data('previewMarkdownPath');
|
2019-02-15 15:39:39 +05:30
|
|
|
const commitButton = $('.js-commit-button');
|
2022-10-11 01:57:18 +05:30
|
|
|
const commitButtonLoading = $('.js-commit-button-loading');
|
2022-05-07 20:08:51 +05:30
|
|
|
const cancelLink = $('#cancel-changes');
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
import('./edit_blob')
|
|
|
|
.then(({ default: EditBlob } = {}) => {
|
2023-06-20 00:43:36 +05:30
|
|
|
// eslint-disable-next-line no-new
|
2021-01-03 14:25:43 +05:30
|
|
|
new EditBlob({
|
|
|
|
assetsPath: `${urlRoot}${assetsPath}`,
|
|
|
|
filePath,
|
|
|
|
currentAction,
|
|
|
|
projectId,
|
|
|
|
isMarkdown,
|
2021-10-27 15:23:28 +05:30
|
|
|
previewMarkdownPath,
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
initPopovers();
|
2021-01-03 14:25:43 +05:30
|
|
|
})
|
2021-09-04 01:27:46 +05:30
|
|
|
.catch((e) =>
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2023-03-04 22:38:38 +05:30
|
|
|
message: e.message,
|
2021-09-04 01:27:46 +05:30
|
|
|
}),
|
|
|
|
);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
cancelLink.on('click', () => {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
commitButton.on('click', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
commitButton.addClass('gl-display-none');
|
|
|
|
commitButtonLoading.removeClass('gl-display-none');
|
2019-02-15 15:39:39 +05:30
|
|
|
window.onbeforeunload = null;
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
new NewCommitForm(editBlobForm); // eslint-disable-line no-new
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
// returning here blocks page navigation
|
|
|
|
window.onbeforeunload = () => '';
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
};
|