From 56a89296050096df29d0a653019c194631cc6562 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 21 Jan 2021 14:51:17 +0100 Subject: Comment - Reference in new issue (#14366) * Implemented "Reference in new issue" * Fixed menu style on "pulls/x/files" because "button" has a style. * Added context menu for PR file comments. * Use only a single modal for every comment. * Use current repository as default. Added search filter. * Added suggested changes. * Fixed assignment. Co-authored-by: Andrew Thornton Co-authored-by: 6543 <6543@obermui.de> --- web_src/js/index.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'web_src') diff --git a/web_src/js/index.js b/web_src/js/index.js index f64f9e6ef1..541f32507d 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -932,6 +932,27 @@ async function initRepository() { event.preventDefault(); }); + // Reference issue + $(document).on('click', '.reference-issue', function (event) { + const $this = $(this); + + $this.closest('.dropdown').find('.menu').toggle('visible'); + + const content = $(`#comment-${$this.data('target')}`).text(); + const subject = content.split('\n', 1)[0].slice(0, 255); + + const poster = $this.data('poster'); + const reference = $this.data('reference'); + + const $modal = $($this.data('modal')); + $modal.find('input[name="title"').val(subject); + $modal.find('textarea[name="content"]').val(`${content}\n\n_Originally posted by @${poster} in ${reference}_`); + + $modal.modal('show'); + + event.preventDefault(); + }); + // Edit issue or comment content $(document).on('click', '.edit-content', async function (event) { $(this).closest('.dropdown').find('.menu').toggle('visible'); @@ -2337,6 +2358,31 @@ function initTemplateSearch() { changeOwner(); } +function initIssueReferenceRepositorySearch() { + $('.issue_reference_repository_search') + .dropdown({ + apiSettings: { + url: `${AppSubUrl}/api/v1/repos/search?q={query}&limit=20`, + onResponse(response) { + const filteredResponse = {success: true, results: []}; + $.each(response.data, (_r, repo) => { + filteredResponse.results.push({ + name: htmlEscape(repo.full_name), + value: repo.full_name + }); + }); + return filteredResponse; + }, + cache: false, + }, + onChange(_value, _text, $choice) { + const $form = $choice.closest('form'); + $form.attr('action', `${AppSubUrl}/${_text}/issues/new`); + }, + fullTextSearch: true + }); +} + $(document).ready(async () => { // Show exact time $('.time-since').each(function () { @@ -2553,6 +2599,7 @@ $(document).ready(async () => { initPullRequestReview(); initRepoStatusChecker(); initTemplateSearch(); + initIssueReferenceRepositorySearch(); initContextPopups(); initTableSort(); initNotificationsTable(); -- cgit v1.2.3