2022-01-28 21:00:11 +00:00
|
|
|
import $ from 'jquery';
|
2021-10-16 17:28:04 +00:00
|
|
|
import {initCompReactionSelector} from './comp/ReactionSelector.js';
|
2021-12-06 03:57:51 +00:00
|
|
|
import {initRepoIssueContentHistory} from './repo-issue-content.js';
|
2022-01-05 12:17:25 +00:00
|
|
|
import {validateTextareaNonEmpty} from './comp/EasyMDE.js';
|
2022-01-28 21:00:11 +00:00
|
|
|
|
2021-10-21 07:37:43 +00:00
|
|
|
const {csrfToken} = window.config;
|
2021-10-16 17:28:04 +00:00
|
|
|
|
|
|
|
export function initRepoDiffReviewButton() {
|
|
|
|
$(document).on('click', 'button[name="is_review"]', (e) => {
|
|
|
|
$(e.target).closest('form').append('<input type="hidden" name="is_review" value="true">');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initRepoDiffFileViewToggle() {
|
|
|
|
$('.file-view-toggle').on('click', function () {
|
|
|
|
const $this = $(this);
|
|
|
|
$this.parent().children().removeClass('active');
|
|
|
|
$this.addClass('active');
|
|
|
|
|
2022-01-16 11:19:26 +00:00
|
|
|
const $target = $($this.data('toggle-selector'));
|
2021-10-16 17:28:04 +00:00
|
|
|
$target.parent().children().addClass('hide');
|
|
|
|
$target.removeClass('hide');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initRepoDiffConversationForm() {
|
2021-10-16 20:30:31 +00:00
|
|
|
$(document).on('submit', '.conversation-holder form', async (e) => {
|
2021-10-16 17:28:04 +00:00
|
|
|
e.preventDefault();
|
2022-01-02 22:31:03 +00:00
|
|
|
|
2021-10-16 17:28:04 +00:00
|
|
|
const form = $(e.target);
|
2022-01-02 22:31:03 +00:00
|
|
|
const $textArea = form.find('textarea');
|
2022-01-03 16:53:53 +00:00
|
|
|
if (!validateTextareaNonEmpty($textArea)) {
|
2022-01-02 22:31:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-16 17:28:04 +00:00
|
|
|
const newConversationHolder = $(await $.post(form.attr('action'), form.serialize()));
|
|
|
|
const {path, side, idx} = newConversationHolder.data();
|
|
|
|
|
|
|
|
form.closest('.conversation-holder').replaceWith(newConversationHolder);
|
|
|
|
if (form.closest('tr').data('line-type') === 'same') {
|
2021-11-19 02:28:27 +00:00
|
|
|
$(`[data-path="${path}"] a.add-code-comment[data-idx="${idx}"]`).addClass('invisible');
|
2021-10-16 17:28:04 +00:00
|
|
|
} else {
|
2021-11-19 02:28:27 +00:00
|
|
|
$(`[data-path="${path}"] a.add-code-comment[data-side="${side}"][data-idx="${idx}"]`).addClass('invisible');
|
2021-10-16 17:28:04 +00:00
|
|
|
}
|
|
|
|
newConversationHolder.find('.dropdown').dropdown();
|
|
|
|
initCompReactionSelector(newConversationHolder);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-01-18 17:28:38 +00:00
|
|
|
$(document).on('click', '.resolve-conversation', async function (e) {
|
2021-10-16 17:28:04 +00:00
|
|
|
e.preventDefault();
|
|
|
|
const comment_id = $(this).data('comment-id');
|
|
|
|
const origin = $(this).data('origin');
|
|
|
|
const action = $(this).data('action');
|
|
|
|
const url = $(this).data('update-url');
|
|
|
|
|
2021-10-21 07:37:43 +00:00
|
|
|
const data = await $.post(url, {_csrf: csrfToken, origin, action, comment_id});
|
2021-10-16 17:28:04 +00:00
|
|
|
|
|
|
|
if ($(this).closest('.conversation-holder').length) {
|
|
|
|
const conversation = $(data);
|
|
|
|
$(this).closest('.conversation-holder').replaceWith(conversation);
|
|
|
|
conversation.find('.dropdown').dropdown();
|
|
|
|
initCompReactionSelector(conversation);
|
|
|
|
} else {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initRepoDiffConversationNav() {
|
|
|
|
// Previous/Next code review conversation
|
|
|
|
$(document).on('click', '.previous-conversation', (e) => {
|
|
|
|
const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
|
|
|
|
const $conversations = $('.comment-code-cloud:not(.hide)');
|
|
|
|
const index = $conversations.index($conversation);
|
|
|
|
const previousIndex = index > 0 ? index - 1 : $conversations.length - 1;
|
|
|
|
const $previousConversation = $conversations.eq(previousIndex);
|
|
|
|
const anchor = $previousConversation.find('.comment').first().attr('id');
|
|
|
|
window.location.href = `#${anchor}`;
|
|
|
|
});
|
|
|
|
$(document).on('click', '.next-conversation', (e) => {
|
|
|
|
const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
|
|
|
|
const $conversations = $('.comment-code-cloud:not(.hide)');
|
|
|
|
const index = $conversations.index($conversation);
|
|
|
|
const nextIndex = index < $conversations.length - 1 ? index + 1 : 0;
|
|
|
|
const $nextConversation = $conversations.eq(nextIndex);
|
|
|
|
const anchor = $nextConversation.find('.comment').first().attr('id');
|
|
|
|
window.location.href = `#${anchor}`;
|
|
|
|
});
|
|
|
|
}
|
2021-11-09 09:27:25 +00:00
|
|
|
|
|
|
|
export function initRepoDiffShowMore() {
|
|
|
|
$('#diff-files, #diff-file-boxes').on('click', '#diff-show-more-files, #diff-show-more-files-stats', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if ($(e.target).hasClass('disabled')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('#diff-show-more-files, #diff-show-more-files-stats').addClass('disabled');
|
|
|
|
|
|
|
|
const url = $('#diff-show-more-files, #diff-show-more-files-stats').data('href');
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url,
|
|
|
|
}).done((resp) => {
|
2021-11-21 16:51:08 +00:00
|
|
|
if (!resp) {
|
2021-11-09 09:27:25 +00:00
|
|
|
$('#diff-show-more-files, #diff-show-more-files-stats').removeClass('disabled');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('#diff-too-many-files-stats').remove();
|
|
|
|
$('#diff-files').append($(resp).find('#diff-files li'));
|
|
|
|
$('#diff-incomplete').replaceWith($(resp).find('#diff-file-boxes').children());
|
2021-12-06 03:57:51 +00:00
|
|
|
initRepoIssueContentHistory();
|
2021-11-21 16:51:08 +00:00
|
|
|
}).fail(() => {
|
|
|
|
$('#diff-show-more-files, #diff-show-more-files-stats').removeClass('disabled');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(document).on('click', 'a.diff-show-more-button', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const $target = $(e.target);
|
|
|
|
|
|
|
|
if ($target.hasClass('disabled')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$target.addClass('disabled');
|
|
|
|
|
|
|
|
const url = $target.data('href');
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url,
|
|
|
|
}).done((resp) => {
|
|
|
|
if (!resp) {
|
|
|
|
$target.removeClass('disabled');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$target.parent().replaceWith($(resp).find('#diff-file-boxes .diff-file-body .file-body').children());
|
2021-12-06 03:57:51 +00:00
|
|
|
initRepoIssueContentHistory();
|
2021-11-21 16:51:08 +00:00
|
|
|
}).fail(() => {
|
|
|
|
$target.removeClass('disabled');
|
2021-11-09 09:27:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|