mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Refactor pull-request compare&create page (#33071)
The old code is unnecessarily complex.
This commit is contained in:
		| @@ -5,7 +5,7 @@ import {initIssueSidebarComboList} from './repo-issue-sidebar-combolist.ts'; | ||||
|  | ||||
| function initBranchSelector() { | ||||
|   // TODO: RemoveIssueRef: see "repo/issue/branch_selector_field.tmpl" | ||||
|   const elSelectBranch = document.querySelector('.ui.dropdown.select-branch'); | ||||
|   const elSelectBranch = document.querySelector('.ui.dropdown.select-branch.branch-selector-dropdown'); | ||||
|   if (!elSelectBranch) return; | ||||
|  | ||||
|   const urlUpdateIssueRef = elSelectBranch.getAttribute('data-url-update-issueref'); | ||||
|   | ||||
| @@ -1,4 +1,3 @@ | ||||
| import $ from 'jquery'; | ||||
| import { | ||||
|   initRepoCommentFormAndSidebar, | ||||
|   initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, initRepoIssueCommentDelete, | ||||
| @@ -15,7 +14,7 @@ import {initCompReactionSelector} from './comp/ReactionSelector.ts'; | ||||
| import {initRepoSettings} from './repo-settings.ts'; | ||||
| import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.ts'; | ||||
| import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.ts'; | ||||
| import {hideElem, queryElemChildren, showElem} from '../utils/dom.ts'; | ||||
| import {hideElem, queryElemChildren, queryElems, showElem} from '../utils/dom.ts'; | ||||
| import {initRepoIssueCommentEdit} from './repo-issue-edit.ts'; | ||||
| import {initRepoMilestone} from './repo-milestone.ts'; | ||||
| import {initRepoNew} from './repo-new.ts'; | ||||
| @@ -29,47 +28,20 @@ function initRepoBranchTagSelector(selector: string) { | ||||
| } | ||||
|  | ||||
| export function initBranchSelectorTabs() { | ||||
|   const elSelectBranch = document.querySelector('.ui.dropdown.select-branch'); | ||||
|   if (!elSelectBranch) return; | ||||
|  | ||||
|   $(elSelectBranch).find('.reference.column').on('click', function () { | ||||
|     hideElem($(elSelectBranch).find('.scrolling.reference-list-menu')); | ||||
|     showElem(this.getAttribute('data-target')); | ||||
|     queryElemChildren(this.parentNode, '.branch-tag-item', (el) => el.classList.remove('active')); | ||||
|     this.classList.add('active'); | ||||
|     return false; | ||||
|   }); | ||||
| } | ||||
|  | ||||
| function initRepoCommonBranchOrTagDropdown(selector: string) { | ||||
|   $(selector).each(function () { | ||||
|     const $dropdown = $(this); | ||||
|     $dropdown.find('.reference.column').on('click', function () { | ||||
|       hideElem($dropdown.find('.scrolling.reference-list-menu')); | ||||
|       showElem($($(this).data('target'))); | ||||
|       return false; | ||||
|     }); | ||||
|   }); | ||||
| } | ||||
|  | ||||
| function initRepoCommonFilterSearchDropdown(selector: string) { | ||||
|   const $dropdown = $(selector); | ||||
|   if (!$dropdown.length) return; | ||||
|  | ||||
|   $dropdown.dropdown({ | ||||
|     fullTextSearch: 'exact', | ||||
|     selectOnKeydown: false, | ||||
|     onChange(_text, _value, $choice) { | ||||
|       if ($choice[0].getAttribute('data-url')) { | ||||
|         window.location.href = $choice[0].getAttribute('data-url'); | ||||
|       } | ||||
|     }, | ||||
|     message: {noResults: $dropdown[0].getAttribute('data-no-results')}, | ||||
|   }); | ||||
|   const elSelectBranches = document.querySelectorAll('.ui.dropdown.select-branch'); | ||||
|   for (const elSelectBranch of elSelectBranches) { | ||||
|     queryElems(elSelectBranch, '.reference.column', (el) => el.addEventListener('click', () => { | ||||
|       hideElem(elSelectBranch.querySelectorAll('.scrolling.reference-list-menu')); | ||||
|       showElem(el.getAttribute('data-target')); | ||||
|       queryElemChildren(el.parentNode, '.branch-tag-item', (el) => el.classList.remove('active')); | ||||
|       el.classList.add('active'); | ||||
|     })); | ||||
|   } | ||||
| } | ||||
|  | ||||
| export function initRepository() { | ||||
|   if (!$('.page-content.repository').length) return; | ||||
|   const pageContent = document.querySelector('.page-content.repository'); | ||||
|   if (!pageContent) return; | ||||
|  | ||||
|   initRepoBranchTagSelector('.js-branch-tag-selector'); | ||||
|   initRepoCommentFormAndSidebar(); | ||||
| @@ -79,19 +51,12 @@ export function initRepository() { | ||||
|   initRepoMilestone(); | ||||
|   initRepoNew(); | ||||
|  | ||||
|   // Compare or pull request | ||||
|   const $repoDiff = $('.repository.diff'); | ||||
|   if ($repoDiff.length) { | ||||
|     initRepoCommonBranchOrTagDropdown('.choose.branch .dropdown'); | ||||
|     initRepoCommonFilterSearchDropdown('.choose.branch .dropdown'); | ||||
|   } | ||||
|  | ||||
|   initRepoCloneButtons(); | ||||
|   initCitationFileCopyContent(); | ||||
|   initRepoSettings(); | ||||
|  | ||||
|   // Issues | ||||
|   if ($('.repository.view.issue').length > 0) { | ||||
|   if (pageContent.matches('.page-content.repository.view.issue')) { | ||||
|     initRepoIssueCommentEdit(); | ||||
|  | ||||
|     initRepoIssueBranchSelect(); | ||||
| @@ -112,18 +77,5 @@ export function initRepository() { | ||||
|     initRepoPullRequestCommitStatus(); | ||||
|   } | ||||
|  | ||||
|   // Pull request | ||||
|   const $repoComparePull = $('.repository.compare.pull'); | ||||
|   if ($repoComparePull.length > 0) { | ||||
|     // show pull request form | ||||
|     $repoComparePull.find('button.show-form').on('click', function (e) { | ||||
|       e.preventDefault(); | ||||
|       hideElem($(this).parent()); | ||||
|  | ||||
|       const $form = $repoComparePull.find('.pullrequest-form'); | ||||
|       showElem($form); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   initUnicodeEscapeButton(); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user