{{template "repo/header" .}} - {{$showDiffBox := false}} +
-

- {{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}} - {{ctx.Locale.Tr "repo.pulls.compare_changes"}} -
{{ctx.Locale.Tr "repo.pulls.compare_changes_desc"}}
- {{else}} - {{ctx.Locale.Tr "action.compare_commits_general"}} - {{end}} -

- {{$BaseCompareName := $.BaseName -}} - {{- $HeadCompareName := $.HeadRepo.OwnerName -}} - {{- if and (eq $.BaseName $.HeadRepo.OwnerName) (ne $.Repository.Name $.HeadRepo.Name) -}} - {{- $HeadCompareName = printf "%s/%s" $.HeadRepo.OwnerName $.HeadRepo.Name -}} - {{- end -}} - {{- $OwnForkCompareName := "" -}} - {{- if .OwnForkRepo -}} - {{- $OwnForkCompareName = .OwnForkRepo.OwnerName -}} - {{- end -}} - {{- $RootRepoCompareName := "" -}} - {{- if .RootRepo -}} - {{- $RootRepoCompareName = .RootRepo.OwnerName -}} - {{- if eq $.HeadRepo.OwnerName .RootRepo.OwnerName -}} +

+ {{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}} + {{ctx.Locale.Tr "repo.pulls.compare_changes"}} +
{{ctx.Locale.Tr "repo.pulls.compare_changes_desc"}}
+ {{else}} + {{ctx.Locale.Tr "action.compare_commits_general"}} + {{end}} +

+ {{$BaseCompareName := $.BaseName -}} + {{- $HeadCompareName := $.HeadRepo.OwnerName -}} + {{- if and (eq $.BaseName $.HeadRepo.OwnerName) (ne $.Repository.Name $.HeadRepo.Name) -}} {{- $HeadCompareName = printf "%s/%s" $.HeadRepo.OwnerName $.HeadRepo.Name -}} {{- end -}} - {{- end -}} -
- {{svg "octicon-git-compare"}} - - {{svg "octicon-arrow-left" 16}}
{{.CompareSeparator}}
- -
+ {{- $OwnForkCompareName := "" -}} + {{- if .OwnForkRepo -}} + {{- $OwnForkCompareName = .OwnForkRepo.OwnerName -}} + {{- end -}} + {{- $RootRepoCompareName := "" -}} + {{- if .RootRepo -}} + {{- $RootRepoCompareName = .RootRepo.OwnerName -}} + {{- if eq $.HeadRepo.OwnerName .RootRepo.OwnerName -}} + {{- $HeadCompareName = printf "%s/%s" $.HeadRepo.OwnerName $.HeadRepo.Name -}} + {{- end -}} + {{- end -}} - {{if .IsNothingToCompare}} - {{if and $.IsSigned $.AllowEmptyPr (not .Repository.IsArchived) .PageIsComparePull}} -
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}}
-
- -
-
- {{template "repo/issue/new_form" .}} -
- {{else if and .HeadIsBranch .BaseIsBranch}} -
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare"}}
- {{else}} -
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}}
- {{end}} - {{else if and .PageIsComparePull (gt .CommitCount 0)}} - {{if .HasPullRequest}} -
- {{template "shared/issueicon" .}} -
- {{ctx.RenderUtils.RenderIssueTitle .PullRequest.Issue.Title ($.Repository.ComposeMetas ctx)}} - #{{.PullRequest.Issue.Index}} +
+ {{svg "octicon-git-compare"}} + - {{else}} - {{if and $.IsSigned (not .Repository.IsArchived)}} -
- + + {{svg "octicon-arrow-left" 16}}
{{.CompareSeparator}}
+ + +
+ + {{$showDiffBox := and .CommitCount (not .IsNothingToCompare)}} + {{if and .IsSigned .PageIsComparePull}} + {{$allowCreatePR := or $.AllowEmptyPr (not .IsNothingToCompare)}} + {{if .IsNothingToCompare}} +
+ {{if $allowCreatePR}} + {{ctx.Locale.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}} + {{else if and .HeadIsBranch .BaseIsBranch}} + {{ctx.Locale.Tr "repo.pulls.nothing_to_compare"}} + {{else}} + {{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}} + {{end}} +
+ {{end}} + {{if .HasPullRequest}} +
+ {{template "shared/issueicon" .}} +
+ {{ctx.RenderUtils.RenderIssueTitle .PullRequest.Issue.Title ($.Repository.ComposeMetas ctx)}} + #{{.PullRequest.Issue.Index}} +
+ + {{ctx.Locale.Tr "repo.pulls.view"}} +
{{else if .Repository.IsArchived}} -
+
{{if .Repository.ArchivedUnix.IsZero}} {{ctx.Locale.Tr "repo.archive.title"}} {{else}} {{ctx.Locale.Tr "repo.archive.title_date" (DateUtils.AbsoluteLong .Repository.ArchivedUnix)}} {{end}}
- {{end}} - {{if $.IsSigned}} + {{else if $allowCreatePR}} +
+ +
{{template "repo/issue/new_form" .}}
{{end}} - {{$showDiffBox = true}} + {{else}}{{/* not singed-in or not for pull-request */}} + {{if not .CommitCount}} +
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
+ {{end}} {{end}} - {{else if not .IsNothingToCompare}} - {{$showDiffBox = true}} - {{end}}
{{if $showDiffBox}} -
- {{template "repo/commits_table" .}} - {{template "repo/diff/box" .}} -
+
+ {{template "repo/commits_table" .}} + {{template "repo/diff/box" .}} +
{{end}}
{{template "base/footer" .}} diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index d960416b3a..cbf927813e 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -27,7 +27,7 @@ func TestCompareTag(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo1/compare/v1.1...master") resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - selection := htmlDoc.doc.Find(".choose.branch .filter.dropdown") + selection := htmlDoc.doc.Find(".ui.dropdown.select-branch") // A dropdown for both base and head. assert.Lenf(t, selection.Nodes, 2, "The template has changed") @@ -44,7 +44,7 @@ func TestCompareDefault(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo1/compare/v1.1") resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - selection := htmlDoc.doc.Find(".choose.branch .filter.dropdown") + selection := htmlDoc.doc.Find(".ui.dropdown.select-branch") assert.Lenf(t, selection.Nodes, 2, "The template has changed") } diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 65eb3b6cf4..22bbe3cc23 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -825,10 +825,6 @@ td .commit-summary { height: 10px; } -.repository.compare.pull .show-form-container { - text-align: left; -} - .repository .choose.branch { display: flex; align-items: center; @@ -866,11 +862,6 @@ td .commit-summary { margin-top: -8px; } -.repository.compare.pull .pullrequest-form { - margin-top: 16px; - margin-bottom: 16px; -} - .repository.compare.pull .markup { font-size: 14px; } diff --git a/web_src/js/features/repo-issue-sidebar.ts b/web_src/js/features/repo-issue-sidebar.ts index ef2b7d143c..e0f68aa059 100644 --- a/web_src/js/features/repo-issue-sidebar.ts +++ b/web_src/js/features/repo-issue-sidebar.ts @@ -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'); diff --git a/web_src/js/features/repo-legacy.ts b/web_src/js/features/repo-legacy.ts index 04267d1dda..33f02be865 100644 --- a/web_src/js/features/repo-legacy.ts +++ b/web_src/js/features/repo-legacy.ts @@ -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(); }