mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	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 <lauris@nix.lv> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
		@@ -781,6 +781,7 @@ func NewIssue(ctx *context.Context) {
 | 
				
			|||||||
	ctx.Data["TitleQuery"] = title
 | 
						ctx.Data["TitleQuery"] = title
 | 
				
			||||||
	body := ctx.Query("body")
 | 
						body := ctx.Query("body")
 | 
				
			||||||
	ctx.Data["BodyQuery"] = body
 | 
						ctx.Data["BodyQuery"] = body
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects)
 | 
						ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects)
 | 
				
			||||||
	ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
 | 
						ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
 | 
				
			||||||
	upload.AddUploadContext(ctx, "comment")
 | 
						upload.AddUploadContext(ctx, "comment")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,8 @@
 | 
				
			|||||||
<div class="field">
 | 
					<div class="field">
 | 
				
			||||||
	<div class="ui bottom active tab" data-tab="write">
 | 
						<div class="ui bottom active tab" data-tab="write">
 | 
				
			||||||
	 	<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}}">
 | 
						 	<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}}">
 | 
				
			||||||
{{if .BodyQuery}}{{.BodyQuery}}{{else if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end}}</textarea>
 | 
								{{- if .BodyQuery}}{{.BodyQuery}}{{else if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end -}}
 | 
				
			||||||
 | 
							</textarea>
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
	<div class="ui bottom tab markdown" data-tab="preview">
 | 
						<div class="ui bottom tab markdown" data-tab="preview">
 | 
				
			||||||
		{{.i18n.Tr "loading"}}
 | 
							{{.i18n.Tr "loading"}}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -111,6 +111,15 @@
 | 
				
			|||||||
						{{end}}
 | 
											{{end}}
 | 
				
			||||||
					</tbody>
 | 
										</tbody>
 | 
				
			||||||
				</table>
 | 
									</table>
 | 
				
			||||||
 | 
									<div class="code-view-menu-list ui fluid popup transition hidden">
 | 
				
			||||||
 | 
										<div class="ui column relaxed equal height">
 | 
				
			||||||
 | 
											<div class="column">
 | 
				
			||||||
 | 
												<div class="ui link list">
 | 
				
			||||||
 | 
													<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>
 | 
				
			||||||
 | 
												</div>
 | 
				
			||||||
 | 
											</div>
 | 
				
			||||||
 | 
										</div>
 | 
				
			||||||
 | 
									</div>
 | 
				
			||||||
				{{end}}
 | 
									{{end}}
 | 
				
			||||||
			{{end}}
 | 
								{{end}}
 | 
				
			||||||
		</div>
 | 
							</div>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2167,6 +2167,45 @@ function searchRepositories() {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function showCodeViewMenu() {
 | 
				
			||||||
 | 
					  // Get clicked tr
 | 
				
			||||||
 | 
					  const $code_tr = $('.code-view td.lines-code.active').parent();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Reset code line marker
 | 
				
			||||||
 | 
					  $('.code-view-menu-list').appendTo($('.code-view'));
 | 
				
			||||||
 | 
					  $('.code-line-marker').remove();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Generate new one
 | 
				
			||||||
 | 
					  const icon_wrap = $('<div>', {
 | 
				
			||||||
 | 
					    class: 'code-line-marker'
 | 
				
			||||||
 | 
					  }).prependTo($code_tr.find('td:eq(0)').get(0)).hide();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const a_wrap = $('<a>', {
 | 
				
			||||||
 | 
					    class: 'code-line-link'
 | 
				
			||||||
 | 
					  }).appendTo(icon_wrap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $('<i>', {
 | 
				
			||||||
 | 
					    class: 'dropdown icon',
 | 
				
			||||||
 | 
					    style: 'margin: 0px;'
 | 
				
			||||||
 | 
					  }).appendTo(a_wrap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  icon_wrap.css({
 | 
				
			||||||
 | 
					    left: '-7px',
 | 
				
			||||||
 | 
					    display: 'block',
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $('.code-view-menu-list').css({
 | 
				
			||||||
 | 
					    'min-width': '220px',
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Popup the menu
 | 
				
			||||||
 | 
					  $('.code-line-link').popup({
 | 
				
			||||||
 | 
					    popup: $('.code-view-menu-list'),
 | 
				
			||||||
 | 
					    on: 'click',
 | 
				
			||||||
 | 
					    lastResort: 'bottom left',
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function initCodeView() {
 | 
					function initCodeView() {
 | 
				
			||||||
  if ($('.code-view .lines-num').length > 0) {
 | 
					  if ($('.code-view .lines-num').length > 0) {
 | 
				
			||||||
    $(document).on('click', '.lines-num span', function (e) {
 | 
					    $(document).on('click', '.lines-num span', function (e) {
 | 
				
			||||||
@@ -2179,6 +2218,9 @@ function initCodeView() {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      selectRange($list, $list.filter(`[rel=${$select.attr('id')}]`), (e.shiftKey ? $list.filter('.active').eq(0) : null));
 | 
					      selectRange($list, $list.filter(`[rel=${$select.attr('id')}]`), (e.shiftKey ? $list.filter('.active').eq(0) : null));
 | 
				
			||||||
      deSelect();
 | 
					      deSelect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // show code view menu marker
 | 
				
			||||||
 | 
					      showCodeViewMenu();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $(window).on('hashchange', () => {
 | 
					    $(window).on('hashchange', () => {
 | 
				
			||||||
@@ -2193,6 +2235,10 @@ function initCodeView() {
 | 
				
			|||||||
      if (m) {
 | 
					      if (m) {
 | 
				
			||||||
        $first = $list.filter(`[rel=${m[1]}]`);
 | 
					        $first = $list.filter(`[rel=${m[1]}]`);
 | 
				
			||||||
        selectRange($list, $first, $list.filter(`[rel=${m[2]}]`));
 | 
					        selectRange($list, $first, $list.filter(`[rel=${m[2]}]`));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // show code view menu marker
 | 
				
			||||||
 | 
					        showCodeViewMenu();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $('html, body').scrollTop($first.offset().top - 200);
 | 
					        $('html, body').scrollTop($first.offset().top - 200);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -2200,6 +2246,10 @@ function initCodeView() {
 | 
				
			|||||||
      if (m) {
 | 
					      if (m) {
 | 
				
			||||||
        $first = $list.filter(`[rel=L${m[2]}]`);
 | 
					        $first = $list.filter(`[rel=L${m[2]}]`);
 | 
				
			||||||
        selectRange($list, $first);
 | 
					        selectRange($list, $first);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // show code view menu marker
 | 
				
			||||||
 | 
					        showCodeViewMenu();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $('html, body').scrollTop($first.offset().top - 200);
 | 
					        $('html, body').scrollTop($first.offset().top - 200);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }).trigger('hashchange');
 | 
					    }).trigger('hashchange');
 | 
				
			||||||
@@ -2752,11 +2802,30 @@ function selectRange($list, $select, $from) {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      $list.filter(classes.join(',')).addClass('active');
 | 
					      $list.filter(classes.join(',')).addClass('active');
 | 
				
			||||||
      changeHash(`#L${a}-L${b}`);
 | 
					      changeHash(`#L${a}-L${b}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // add hashchange to permalink
 | 
				
			||||||
 | 
					      const $issue = $('a.ref-in-new-issue');
 | 
				
			||||||
 | 
					      const matched = $issue.attr('href').match(/%23L\d+$|%23L\d+-L\d+$/);
 | 
				
			||||||
 | 
					      if (matched) {
 | 
				
			||||||
 | 
					        $issue.attr('href', $issue.attr('href').replace($issue.attr('href').substr(matched.index), `%23L${a}-L${b}`));
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        $issue.attr('href', `${$issue.attr('href')}%23L${a}-L${b}`);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  $select.addClass('active');
 | 
					  $select.addClass('active');
 | 
				
			||||||
  changeHash(`#${$select.attr('rel')}`);
 | 
					  changeHash(`#${$select.attr('rel')}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // add hashchange to permalink
 | 
				
			||||||
 | 
					  const $issue = $('a.ref-in-new-issue');
 | 
				
			||||||
 | 
					  const matched = $issue.attr('href').match(/%23L\d+$|%23L\d+-L\d+$/);
 | 
				
			||||||
 | 
					  if (matched) {
 | 
				
			||||||
 | 
					    $issue.attr('href', $issue.attr('href').replace($issue.attr('href').substr(matched.index), `%23${$select.attr('rel')}`));
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    $issue.attr('href', `${$issue.attr('href')}%23${$select.attr('rel')}`);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(() => {
 | 
					$(() => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3145,3 +3145,10 @@ td.blob-excerpt {
 | 
				
			|||||||
  transform: scale(105%);
 | 
					  transform: scale(105%);
 | 
				
			||||||
  box-shadow: 0 .5rem 1rem var(--color-shadow) !important;
 | 
					  box-shadow: 0 .5rem 1rem var(--color-shadow) !important;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.code-line-marker {
 | 
				
			||||||
 | 
					  width: 13px;
 | 
				
			||||||
 | 
					  height: 20px;
 | 
				
			||||||
 | 
					  background-color: rgb(34 36 38 / 15%);
 | 
				
			||||||
 | 
					  position: absolute;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user