mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-27 12:16:10 +01:00
2f0e79e639
- Send request to get branch/tag list, use loading icon when waiting for response. - Only fetch when the first time branch/tag list shows. - For backend, removed assignment to `ctx.Data["Branches"]` and `ctx.Data["Tags"]` from `context/repo.go` and passed these data wherever needed. - Changed some `v-if` to `v-show` and used native `svg` as mentioned in https://github.com/go-gitea/gitea/pull/25719#issuecomment-1631712757 to improve perfomance when there are a lot of branches. - Places Used the dropdown component: Repo Home Page <img width="1429" alt="Screen Shot 2023-07-06 at 12 17 51" src="https://github.com/go-gitea/gitea/assets/17645053/6accc7b6-8d37-4e88-ae1a-bd2b3b927ea0"> Commits Page <img width="1431" alt="Screen Shot 2023-07-06 at 12 18 34" src="https://github.com/go-gitea/gitea/assets/17645053/2d0bf306-d1e2-45a8-a784-bc424879f537"> Specific commit -> operations -> cherry-pick <img width="758" alt="Screen Shot 2023-07-06 at 12 23 28" src="https://github.com/go-gitea/gitea/assets/17645053/1e557948-3881-4e45-a625-8ef36d45ae2d"> Release Page <img width="1433" alt="Screen Shot 2023-07-06 at 12 25 05" src="https://github.com/go-gitea/gitea/assets/17645053/3ec82af1-15a4-4162-a50b-04a9502161bb"> - Demo https://github.com/go-gitea/gitea/assets/17645053/d45d266b-3eb0-465a-82f9-57f78dc5f9f3 - Note: UI of dropdown menu could be improved in another PR as it should apply to more dropdown menus. Fix #14180 --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
88 lines
4.1 KiB
Handlebars
88 lines
4.1 KiB
Handlebars
{{/* Attributes:
|
|
* root
|
|
* ContainerClasses
|
|
* (TODO: search "branch_dropdown" in the template direcotry)
|
|
*/}}
|
|
{{$defaultBranch := $.root.BranchName}}
|
|
{{if and .root.IsViewTag (not .noTag)}}
|
|
{{$defaultBranch = .root.TagName}}
|
|
{{end}}
|
|
{{if eq $defaultBranch ""}}
|
|
{{$defaultBranch = $.root.Repository.DefaultBranch}}
|
|
{{end}}
|
|
|
|
{{$type := ""}}
|
|
{{if and .root.IsViewTag (not .noTag)}}
|
|
{{$type = "tag"}}
|
|
{{else if .root.IsViewBranch}}
|
|
{{$type = "branch"}}
|
|
{{else}}
|
|
{{$type = "tree"}}
|
|
{{end}}
|
|
|
|
{{$showBranchesInDropdown := not .root.HideBranchesInDropdown}}
|
|
|
|
<script type="module">
|
|
const data = {
|
|
'textReleaseCompare': {{.root.locale.Tr "repo.release.compare"}},
|
|
'textCreateTag': {{.root.locale.Tr "repo.tag.create_tag"}},
|
|
'textCreateBranch': {{.root.locale.Tr "repo.branch.create_branch"}},
|
|
'textCreateBranchFrom': {{.root.locale.Tr "repo.branch.create_from"}},
|
|
'textBranches': {{.root.locale.Tr "repo.branches"}},
|
|
'textTags': {{.root.locale.Tr "repo.tags"}},
|
|
|
|
'mode': '{{if or .root.IsViewTag .isTag}}tags{{else}}branches{{end}}',
|
|
'showBranchesInDropdown': {{$showBranchesInDropdown}},
|
|
'searchFieldPlaceholder': '{{if $.noTag}}{{.root.locale.Tr "repo.pulls.filter_branch"}}{{else if $showBranchesInDropdown}}{{.root.locale.Tr "repo.filter_branch_and_tag"}}{{else}}{{.root.locale.Tr "repo.find_tag"}}{{end}}...',
|
|
'branchForm': {{$.branchForm}},
|
|
'disableCreateBranch': {{if .disableCreateBranch}}{{.disableCreateBranch}}{{else}}{{not .root.CanCreateBranch}}{{end}},
|
|
'setAction': {{.setAction}},
|
|
'submitForm': {{.submitForm}},
|
|
'viewType': {{$type}},
|
|
'refName': {{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}},
|
|
'commitIdShort': {{ShortSha .root.CommitID}},
|
|
'tagName': {{.root.TagName}},
|
|
'branchName': {{.root.BranchName}},
|
|
'noTag': {{.noTag}},
|
|
'defaultBranch': {{$defaultBranch}},
|
|
'enableFeed': {{.root.EnableFeed}},
|
|
'rssURLPrefix': '{{$.root.RepoLink}}/rss/branch/',
|
|
'branchURLPrefix': '{{if .branchURLPrefix}}{{.branchURLPrefix}}{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{end}}',
|
|
'branchURLSuffix': '{{if .branchURLSuffix}}{{.branchURLSuffix}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}',
|
|
'tagURLPrefix': '{{if .tagURLPrefix}}{{.tagURLPrefix}}{{else if .release}}{{$.root.RepoLink}}/compare/{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/tag/{{end}}',
|
|
'tagURLSuffix': '{{if .tagURLSuffix}}{{.tagURLSuffix}}{{else if .release}}...{{if .release.IsDraft}}{{PathEscapeSegments .release.Target}}{{else}}{{if .release.TagName}}{{PathEscapeSegments .release.TagName}}{{else}}{{PathEscapeSegments .release.Sha1}}{{end}}{{end}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}',
|
|
'repoLink': {{.root.RepoLink}},
|
|
'treePath': {{.root.TreePath}},
|
|
'branchNameSubURL': {{.root.BranchNameSubURL}},
|
|
'noResults': {{.root.locale.Tr "repo.pulls.no_results"}},
|
|
};
|
|
{{if .release}}
|
|
data.release = {
|
|
'tagName': {{.release.TagName}},
|
|
};
|
|
{{end}}
|
|
window.config.pageData.branchDropdownDataList = window.config.pageData.branchDropdownDataList || [];
|
|
window.config.pageData.branchDropdownDataList.push(data);
|
|
</script>
|
|
|
|
<div class="js-branch-tag-selector {{if .ContainerClasses}}{{.ContainerClasses}}{{end}}">
|
|
{{/* show dummy elements before Vue componment is mounted, this code must match the code in BranchTagSelector.vue */}}
|
|
<div class="ui floating filter dropdown custom">
|
|
<button class="branch-dropdown-button gt-ellipsis ui basic small compact button gt-df gt-m-0">
|
|
<span class="text gt-df gt-ac gt-mr-2">
|
|
{{if .release}}
|
|
{{.root.locale.Tr "repo.release.compare"}}
|
|
{{else}}
|
|
{{if eq $type "tag"}}
|
|
{{svg "octicon-tag"}}
|
|
{{else}}
|
|
{{svg "octicon-git-branch"}}
|
|
{{end}}
|
|
<strong ref="dropdownRefName" class="gt-ml-3">{{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}}</strong>
|
|
{{end}}
|
|
</span>
|
|
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
|
</button>
|
|
</div>
|
|
</div>
|