diff options
-rw-r--r-- | options/locale/locale_en-US.ini | 2 | ||||
-rw-r--r-- | templates/repo/diff/box.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/view_content.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/issue/view_content/context_menu.tmpl | 13 | ||||
-rw-r--r-- | templates/repo/issue/view_content/reference_issue_dialog.tmpl | 30 | ||||
-rw-r--r-- | web_src/js/index.js | 47 |
6 files changed, 92 insertions, 6 deletions
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 142f3049f3..c950591d76 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1068,6 +1068,7 @@ issues.commented_at = `commented <a href="#%s">%s</a>` issues.delete_comment_confirm = Are you sure you want to delete this comment? issues.context.copy_link = Copy Link issues.context.quote_reply = Quote Reply +issues.context.reference_issue = Reference in new issue issues.context.edit = Edit issues.context.delete = Delete issues.no_content = There is no content yet. @@ -1225,6 +1226,7 @@ issues.review.resolve_conversation = Resolve conversation issues.review.un_resolve_conversation = Unresolve conversation issues.review.resolved_by = marked this conversation as resolved issues.assignee.error = Not all assignees was added due to an unexpected error. +issues.reference_issue.body = Body pulls.desc = Enable pull requests and code reviews. pulls.new = New Pull Request diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 8533f9b910..f01795ad15 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -164,6 +164,8 @@ </div> {{end}} + {{template "repo/issue/view_content/reference_issue_dialog" .}} + {{if .IsSplitStyle}} <script> document.addEventListener('DOMContentLoaded', () => { diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 37628a74e8..0119c12cd8 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -52,7 +52,7 @@ </div> {{end}} {{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index)}} - {{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" .Issue "delete" false "diff" false "IsCommentPoster" $.IsIssuePoster}} + {{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" .Issue "delete" false "issue" true "diff" false "IsCommentPoster" $.IsIssuePoster}} {{end}} </div> </div> @@ -210,6 +210,8 @@ </div> </div> +{{template "repo/issue/view_content/reference_issue_dialog" .}} + <div class="hide" id="no-content"> <span class="no-content">{{.i18n.Tr "repo.issues.no_content"}}</span> </div> diff --git a/templates/repo/issue/view_content/context_menu.tmpl b/templates/repo/issue/view_content/context_menu.tmpl index 41786242ba..f5a965b8a9 100644 --- a/templates/repo/issue/view_content/context_menu.tmpl +++ b/templates/repo/issue/view_content/context_menu.tmpl @@ -4,12 +4,15 @@ {{svg "octicon-kebab-horizontal"}} </a> <div class="menu"> - {{if .issue}} - <div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/issues/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div> - {{else}} - <div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div> - {{end}} + {{ $referenceUrl := "" }} + {{ if .issue }} + {{ $referenceUrl = Printf "%s%s/issues/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }} + {{ else }} + {{ $referenceUrl = Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }} + {{ end }} + <div class="item context clipboard" data-clipboard-text="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div> <div class="item context quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.ID}}">{{.ctx.i18n.Tr "repo.issues.context.quote_reply"}}</div> + <div class="item context reference-issue" data-target="{{.item.ID}}" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-reference="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.reference_issue"}}</div> {{if or .ctx.Permission.IsAdmin .IsCommentPoster .ctx.HasIssuesOrPullsWritePermission}} <div class="divider"></div> <div class="item context edit-content">{{.ctx.i18n.Tr "repo.issues.context.edit"}}</div> diff --git a/templates/repo/issue/view_content/reference_issue_dialog.tmpl b/templates/repo/issue/view_content/reference_issue_dialog.tmpl new file mode 100644 index 0000000000..2133df520a --- /dev/null +++ b/templates/repo/issue/view_content/reference_issue_dialog.tmpl @@ -0,0 +1,30 @@ +<div class="ui small modal" id="reference-issue-modal"> + <div class="header"> + {{.i18n.Tr "repo.issues.context.reference_issue"}} + </div> + <div class="content" style="text-align:left"> + <form class="ui form" action="{{ Printf "%s/issues/new" .Repository.Link }}" method="post"> + {{.CsrfTokenHtml}} + <div class="ui segment content"> + <div class="field"> + <span class="text"><strong>{{.i18n.Tr "repository"}}</strong></span> + <div class="ui search normal selection dropdown issue_reference_repository_search"> + <div class="default text">{{.Repository.FullName}}</div> + <div class="menu"></div> + </div> + </div> + <div class="field"> + <span class="text"><strong>{{.i18n.Tr "repo.milestones.title"}}</strong></span> + <input name="title" value="" autofocus required maxlength="255" autocomplete="off"> + </div> + <div class="field"> + <span class="text"><strong>{{.i18n.Tr "repo.issues.reference_issue.body"}}</strong></span> + <textarea name="content" class="form-control"></textarea> + </div> + <div class="text right"> + <button class="ui green button">{{.i18n.Tr "repo.issues.create"}}</button> + </div> + </div> + </form> + </div> +</div> 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(); |