Skip to content

Commit 119d2cb

Browse files
rogerluo410lafriks6543
authored
Create new issue from code (#14863)
* Feat: add reference in new issue with permalink menu for code view. * Fix: recover index.js file. * Add comments and redo ci. * Fix code convention * Fix code. Co-authored-by: Lauris BH <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 03e99f8 commit 119d2cb

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

routers/repo/issue.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ func NewIssue(ctx *context.Context) {
781781
ctx.Data["TitleQuery"] = title
782782
body := ctx.Query("body")
783783
ctx.Data["BodyQuery"] = body
784+
784785
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects)
785786
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
786787
upload.AddUploadContext(ctx, "comment")

templates/repo/issue/comment_tab.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
</div>
55
<div class="field">
66
<div class="ui bottom active tab" data-tab="write">
7-
<textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{.Repository.APIURL}}/markdown" data-context="{{.Repo.RepoLink}}">
8-
{{if .BodyQuery}}{{.BodyQuery}}{{else if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end}}</textarea>
7+
<textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{.Repository.APIURL}}/markdown" data-context="{{.Repo.RepoLink}}">
8+
{{- if .BodyQuery}}{{.BodyQuery}}{{else if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end -}}
9+
</textarea>
910
</div>
1011
<div class="ui bottom tab markdown" data-tab="preview">
1112
{{.i18n.Tr "loading"}}

templates/repo/view_file.tmpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@
111111
{{end}}
112112
</tbody>
113113
</table>
114+
<div class="code-view-menu-list ui fluid popup transition hidden">
115+
<div class="ui column relaxed equal height">
116+
<div class="column">
117+
<div class="ui link list">
118+
<a class="item ref-in-new-issue" href="{{.RepoLink}}/issues/new?body={{URLJoin AppUrl .RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.issues.context.reference_issue"}}</a>
119+
</div>
120+
</div>
121+
</div>
122+
</div>
114123
{{end}}
115124
{{end}}
116125
</div>

web_src/js/index.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,45 @@ function searchRepositories() {
21672167
});
21682168
}
21692169

2170+
function showCodeViewMenu() {
2171+
// Get clicked tr
2172+
const $code_tr = $('.code-view td.lines-code.active').parent();
2173+
2174+
// Reset code line marker
2175+
$('.code-view-menu-list').appendTo($('.code-view'));
2176+
$('.code-line-marker').remove();
2177+
2178+
// Generate new one
2179+
const icon_wrap = $('<div>', {
2180+
class: 'code-line-marker'
2181+
}).prependTo($code_tr.find('td:eq(0)').get(0)).hide();
2182+
2183+
const a_wrap = $('<a>', {
2184+
class: 'code-line-link'
2185+
}).appendTo(icon_wrap);
2186+
2187+
$('<i>', {
2188+
class: 'dropdown icon',
2189+
style: 'margin: 0px;'
2190+
}).appendTo(a_wrap);
2191+
2192+
icon_wrap.css({
2193+
left: '-7px',
2194+
display: 'block',
2195+
});
2196+
2197+
$('.code-view-menu-list').css({
2198+
'min-width': '220px',
2199+
});
2200+
2201+
// Popup the menu
2202+
$('.code-line-link').popup({
2203+
popup: $('.code-view-menu-list'),
2204+
on: 'click',
2205+
lastResort: 'bottom left',
2206+
});
2207+
}
2208+
21702209
function initCodeView() {
21712210
if ($('.code-view .lines-num').length > 0) {
21722211
$(document).on('click', '.lines-num span', function (e) {
@@ -2179,6 +2218,9 @@ function initCodeView() {
21792218
}
21802219
selectRange($list, $list.filter(`[rel=${$select.attr('id')}]`), (e.shiftKey ? $list.filter('.active').eq(0) : null));
21812220
deSelect();
2221+
2222+
// show code view menu marker
2223+
showCodeViewMenu();
21822224
});
21832225

21842226
$(window).on('hashchange', () => {
@@ -2193,13 +2235,21 @@ function initCodeView() {
21932235
if (m) {
21942236
$first = $list.filter(`[rel=${m[1]}]`);
21952237
selectRange($list, $first, $list.filter(`[rel=${m[2]}]`));
2238+
2239+
// show code view menu marker
2240+
showCodeViewMenu();
2241+
21962242
$('html, body').scrollTop($first.offset().top - 200);
21972243
return;
21982244
}
21992245
m = window.location.hash.match(/^#(L|n)(\d+)$/);
22002246
if (m) {
22012247
$first = $list.filter(`[rel=L${m[2]}]`);
22022248
selectRange($list, $first);
2249+
2250+
// show code view menu marker
2251+
showCodeViewMenu();
2252+
22032253
$('html, body').scrollTop($first.offset().top - 200);
22042254
}
22052255
}).trigger('hashchange');
@@ -2752,11 +2802,30 @@ function selectRange($list, $select, $from) {
27522802
}
27532803
$list.filter(classes.join(',')).addClass('active');
27542804
changeHash(`#L${a}-L${b}`);
2805+
2806+
// add hashchange to permalink
2807+
const $issue = $('a.ref-in-new-issue');
2808+
const matched = $issue.attr('href').match(/%23L\d+$|%23L\d+-L\d+$/);
2809+
if (matched) {
2810+
$issue.attr('href', $issue.attr('href').replace($issue.attr('href').substr(matched.index), `%23L${a}-L${b}`));
2811+
} else {
2812+
$issue.attr('href', `${$issue.attr('href')}%23L${a}-L${b}`);
2813+
}
2814+
27552815
return;
27562816
}
27572817
}
27582818
$select.addClass('active');
27592819
changeHash(`#${$select.attr('rel')}`);
2820+
2821+
// add hashchange to permalink
2822+
const $issue = $('a.ref-in-new-issue');
2823+
const matched = $issue.attr('href').match(/%23L\d+$|%23L\d+-L\d+$/);
2824+
if (matched) {
2825+
$issue.attr('href', $issue.attr('href').replace($issue.attr('href').substr(matched.index), `%23${$select.attr('rel')}`));
2826+
} else {
2827+
$issue.attr('href', `${$issue.attr('href')}%23${$select.attr('rel')}`);
2828+
}
27602829
}
27612830

27622831
$(() => {

web_src/less/_repository.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,3 +3145,10 @@ td.blob-excerpt {
31453145
transform: scale(105%);
31463146
box-shadow: 0 .5rem 1rem var(--color-shadow) !important;
31473147
}
3148+
3149+
.code-line-marker {
3150+
width: 13px;
3151+
height: 20px;
3152+
background-color: rgb(34 36 38 / 15%);
3153+
position: absolute;
3154+
}

0 commit comments

Comments
 (0)