Skip to content

Commit c949f42

Browse files
committed
fix
1 parent ad9b126 commit c949f42

File tree

4 files changed

+111
-139
lines changed

4 files changed

+111
-139
lines changed

templates/repo/home.tmpl

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{{$hasTreeSidebar := not $isTreePathRoot}}
66
{{$showTreeSidebar := .RepoPreferences.ShowFileViewTreeSidebar}}
77
{{$hideTreeSidebar := not $showTreeSidebar}}
8-
{{$hasAndShowTreeSidebar := and $hasTreeSidebar $showTreeSidebar}}
98
<div role="main" aria-label="{{.Title}}" class="page-content repository file list {{if .IsBlame}}blame{{end}}">
109
{{template "repo/header" .}}
1110
<div class="ui container {{if or $hasTreeSidebar .IsBlame}}fluid padded{{end}}">
@@ -29,92 +28,7 @@
2928
{{end}}
3029

3130
<div class="repo-home-filelist">
32-
{{template "repo/sub_menu" .}}
33-
<div class="repo-button-row">
34-
<div class="repo-button-row-left">
35-
{{if $hasTreeSidebar}}
36-
<button class="show-tree-sidebar-button ui compact basic button icon not-mobile {{if $showTreeSidebar}}tw-hidden{{end}}" title="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
37-
{{svg "octicon-sidebar-collapse" 20 "icon"}}
38-
</button>
39-
{{end}}
40-
{{template "repo/home_branch_dropdown" (dict "ctxData" . "containerClasses" (Iif $hasAndShowTreeSidebar "tw-hidden" ""))}}
41-
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
42-
{{$cmpBranch := ""}}
43-
{{if ne .Repository.ID .BaseRepo.ID}}
44-
{{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}}
45-
{{end}}
46-
{{$cmpBranch = print $cmpBranch (.BranchName|PathEscapeSegments)}}
47-
{{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}}
48-
<a id="new-pull-request" role="button" class="ui compact basic button {{if $hasAndShowTreeSidebar}}tw-hidden{{end}}" href="{{$compareLink}}"
49-
data-tooltip-content="{{if .PullRequestCtx.Allowed}}{{ctx.Locale.Tr "repo.pulls.compare_changes"}}{{else}}{{ctx.Locale.Tr "action.compare_branch"}}{{end}}">
50-
{{svg "octicon-git-pull-request"}}
51-
</a>
52-
{{end}}
53-
54-
<!-- Show go to file if on home page -->
55-
{{if $isTreePathRoot}}
56-
<a href="{{.Repository.Link}}/find/{{.BranchNameSubURL}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
57-
{{end}}
58-
59-
{{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}}
60-
<button class="add-file-dropdown ui dropdown basic compact jump button {{if $hasAndShowTreeSidebar}}tw-hidden{{end}}"{{if not .Repository.CanEnableEditor}} disabled{{end}}>
61-
{{ctx.Locale.Tr "repo.editor.add_file"}}
62-
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
63-
<div class="menu">
64-
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
65-
{{ctx.Locale.Tr "repo.editor.new_file"}}
66-
</a>
67-
{{if .RepositoryUploadEnabled}}
68-
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
69-
{{ctx.Locale.Tr "repo.editor.upload_file"}}
70-
</a>
71-
{{end}}
72-
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
73-
{{ctx.Locale.Tr "repo.editor.patch"}}
74-
</a>
75-
</div>
76-
</button>
77-
{{end}}
78-
79-
{{if and $isTreePathRoot .Repository.IsTemplate}}
80-
<a role="button" class="ui primary compact button" href="{{AppSubUrl}}/repo/create?template_id={{.Repository.ID}}">
81-
{{ctx.Locale.Tr "repo.use_template"}}
82-
</a>
83-
{{end}}
84-
85-
{{if not $isTreePathRoot}}
86-
{{$treeNameIdxLast := Eval $treeNamesLen "-" 1}}
87-
<span id="repo_path" class="breadcrumb repo-path tw-ml-1">
88-
<a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{StringUtils.EllipsisString .Repository.Name 30}}</a>
89-
{{- range $i, $v := .TreeNames -}}
90-
<span class="breadcrumb-divider">/</span>
91-
{{- if eq $i $treeNameIdxLast -}}
92-
<span class="active section" title="{{$v}}">{{$v}}</span>
93-
<button class="btn interact-fg tw-mx-1" data-clipboard-text="{{$.TreePath}}" data-tooltip-content="{{ctx.Locale.Tr "copy_path"}}">{{svg "octicon-copy" 14}}</button>
94-
{{- else -}}
95-
{{$p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{$v}}</a></span>
96-
{{- end -}}
97-
{{- end -}}
98-
</span>
99-
{{end}}
100-
</div>
101-
102-
<div class="repo-button-row-right">
103-
<!-- Only show clone panel in repository home page -->
104-
{{if $isTreePathRoot}}
105-
{{template "repo/clone_panel" .}}
106-
{{end}}
107-
{{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
108-
<a id="path_history" class="ui button" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
109-
{{svg "octicon-history" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_history"}}
110-
</a>
111-
{{end}}
112-
</div>
113-
</div>
114-
115-
<div id="path_content">
116-
{{template "repo/home_content" .}}
117-
</div>
31+
{{template "repo/home_content" .}}
11832
</div>
11933

12034
{{if $showSidebar}}

templates/repo/home_content.tmpl

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,92 @@
1+
{{$treeNamesLen := len .TreeNames}}
2+
{{$isTreePathRoot := eq $treeNamesLen 0}}
3+
{{$showSidebar := and $isTreePathRoot (not .HideRepoInfo) (not .IsBlame)}}
4+
{{$hasTreeSidebar := not $isTreePathRoot}}
5+
{{$showTreeSidebar := .RepoPreferences.ShowFileViewTreeSidebar}}
6+
7+
{{template "repo/sub_menu" .}}
8+
<div class="repo-button-row">
9+
<div class="repo-button-row-left">
10+
{{if $hasTreeSidebar}}
11+
<button class="show-tree-sidebar-button ui compact basic button icon not-mobile {{if $showTreeSidebar}}tw-hidden{{end}}" title="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
12+
{{svg "octicon-sidebar-collapse" 20 "icon"}}
13+
</button>
14+
{{end}}
15+
{{template "repo/home_branch_dropdown" (dict "ctxData" .)}}
16+
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
17+
{{$cmpBranch := ""}}
18+
{{if ne .Repository.ID .BaseRepo.ID}}
19+
{{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}}
20+
{{end}}
21+
{{$cmpBranch = print $cmpBranch (.BranchName|PathEscapeSegments)}}
22+
{{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}}
23+
<a id="new-pull-request" role="button" class="ui compact basic button" href="{{$compareLink}}"
24+
data-tooltip-content="{{if .PullRequestCtx.Allowed}}{{ctx.Locale.Tr "repo.pulls.compare_changes"}}{{else}}{{ctx.Locale.Tr "action.compare_branch"}}{{end}}">
25+
{{svg "octicon-git-pull-request"}}
26+
</a>
27+
{{end}}
28+
29+
<!-- Show go to file if on home page -->
30+
{{if $isTreePathRoot}}
31+
<a href="{{.Repository.Link}}/find/{{.BranchNameSubURL}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
32+
{{end}}
33+
34+
{{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}}
35+
<button class="add-file-dropdown ui dropdown basic compact jump button"{{if not .Repository.CanEnableEditor}} disabled{{end}}>
36+
{{ctx.Locale.Tr "repo.editor.add_file"}}
37+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
38+
<div class="menu">
39+
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
40+
{{ctx.Locale.Tr "repo.editor.new_file"}}
41+
</a>
42+
{{if .RepositoryUploadEnabled}}
43+
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
44+
{{ctx.Locale.Tr "repo.editor.upload_file"}}
45+
</a>
46+
{{end}}
47+
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
48+
{{ctx.Locale.Tr "repo.editor.patch"}}
49+
</a>
50+
</div>
51+
</button>
52+
{{end}}
53+
54+
{{if and $isTreePathRoot .Repository.IsTemplate}}
55+
<a role="button" class="ui primary compact button" href="{{AppSubUrl}}/repo/create?template_id={{.Repository.ID}}">
56+
{{ctx.Locale.Tr "repo.use_template"}}
57+
</a>
58+
{{end}}
59+
60+
{{if not $isTreePathRoot}}
61+
{{$treeNameIdxLast := Eval $treeNamesLen "-" 1}}
62+
<span class="breadcrumb repo-path tw-ml-1">
63+
<a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{StringUtils.EllipsisString .Repository.Name 30}}</a>
64+
{{- range $i, $v := .TreeNames -}}
65+
<span class="breadcrumb-divider">/</span>
66+
{{- if eq $i $treeNameIdxLast -}}
67+
<span class="active section" title="{{$v}}">{{$v}}</span>
68+
<button class="btn interact-fg tw-mx-1" data-clipboard-text="{{$.TreePath}}" data-tooltip-content="{{ctx.Locale.Tr "copy_path"}}">{{svg "octicon-copy" 14}}</button>
69+
{{- else -}}
70+
{{$p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{$v}}</a></span>
71+
{{- end -}}
72+
{{- end -}}
73+
</span>
74+
{{end}}
75+
</div>
76+
77+
<div class="repo-button-row-right">
78+
<!-- Only show clone panel in repository home page -->
79+
{{if $isTreePathRoot}}
80+
{{template "repo/clone_panel" .}}
81+
{{end}}
82+
{{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
83+
<a class="ui button" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
84+
{{svg "octicon-history" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_history"}}
85+
</a>
86+
{{end}}
87+
</div>
88+
</div>
89+
190
{{$treeNamesLen := len .TreeNames}}
291
{{$isTreePathRoot := eq $treeNamesLen 0}}
392

templates/repo/view_file_tree_sidebar.tmpl

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,7 @@
1212
</button>
1313
<b> Files</b>
1414
</div>
15-
<div class="sidebar-ref">
16-
{{template "repo/home_branch_dropdown" (dict "ctxData" .)}}
17-
18-
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
19-
{{$cmpBranch := ""}}
20-
{{if ne .Repository.ID .BaseRepo.ID}}
21-
{{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}}
22-
{{end}}
23-
{{$cmpBranch = print $cmpBranch (.BranchName|PathEscapeSegments)}}
24-
{{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}}
25-
<a role="button" class="ui compact basic button" href="{{$compareLink}}"
26-
data-tooltip-content="{{if .PullRequestCtx.Allowed}}{{ctx.Locale.Tr "repo.pulls.compare_changes"}}{{else}}{{ctx.Locale.Tr "action.compare_branch"}}{{end}}">
27-
{{svg "octicon-git-pull-request"}}
28-
</a>
29-
{{end}}
30-
31-
{{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}}
32-
<button class="ui dropdown basic compact jump button"{{if not .Repository.CanEnableEditor}} disabled{{end}}>
33-
{{ctx.Locale.Tr "repo.editor.add_file"}}
34-
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
35-
<div class="menu">
36-
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
37-
{{ctx.Locale.Tr "repo.editor.new_file"}}
38-
</a>
39-
{{if .RepositoryUploadEnabled}}
40-
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
41-
{{ctx.Locale.Tr "repo.editor.upload_file"}}
42-
</a>
43-
{{end}}
44-
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
45-
{{ctx.Locale.Tr "repo.editor.patch"}}
46-
</a>
47-
</div>
48-
</button>
49-
{{end}}
50-
</div>
15+
<!--// TODO: Dynamically move components such as refSelector and createPR here-->
5116
</div>
5217
<div class="view-file-tree-sidebar-bottom">
5318
<div id="view-file-tree" class="is-loading"

web_src/js/features/repo-view-file-tree-sidebar.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@ import {createApp, ref} from 'vue';
22
import {toggleElem} from '../utils/dom.ts';
33
import {GET, PUT} from '../modules/fetch.ts';
44
import ViewFileTree from '../components/ViewFileTree.vue';
5+
import RepoBranchTagSelector from '../components/RepoBranchTagSelector.vue';
6+
import {initGlobalDropdown} from './common-page.ts';
57

68
async function toggleSidebar(visibility) {
79
const sidebarEl = document.querySelector('.repo-view-file-tree-sidebar');
810
const showBtnEl = document.querySelector('.show-tree-sidebar-button');
9-
const refSelectorEl = document.querySelector('.repo-home-filelist .js-branch-tag-selector');
10-
const newPrBtnEl = document.querySelector('.repo-home-filelist #new-pull-request');
11-
const addFileEl = document.querySelector('.repo-home-filelist .add-file-dropdown');
1211
const containerClassList = sidebarEl.parentElement.classList;
1312
containerClassList.toggle('repo-grid-tree-sidebar', visibility);
1413
containerClassList.toggle('repo-grid-filelist-only', !visibility);
1514
toggleElem(sidebarEl, visibility);
1615
toggleElem(showBtnEl, !visibility);
17-
toggleElem(refSelectorEl, !visibility);
18-
toggleElem(newPrBtnEl, !visibility);
19-
if (addFileEl) {
20-
toggleElem(addFileEl, !visibility);
21-
}
2216

2317
// save to session
2418
await PUT('/repo/preferences', {
@@ -46,24 +40,34 @@ async function loadChildren(item, recursive?: boolean) {
4640
return null;
4741
}
4842

49-
async function loadContent(item) {
50-
// todo: change path of `repo_path` `path_history`
43+
async function loadContent() {
5144
// load content by path (content based on home_content.tmpl)
5245
const response = await GET(`${window.location.href}?only_content=true`);
53-
document.querySelector('#path_content').innerHTML = await response.text();
46+
document.querySelector('.repo-home-filelist').innerHTML = await response.text();
47+
reloadContentScript();
48+
}
49+
50+
function reloadContentScript() {
51+
document.querySelector('.repo-home-filelist .show-tree-sidebar-button').addEventListener('click', () => {
52+
toggleSidebar(true);
53+
});
54+
const refSelectorEl = document.querySelector('.repo-home-filelist .js-branch-tag-selector');
55+
if (refSelectorEl) {
56+
createApp(RepoBranchTagSelector, {elRoot: refSelectorEl}).mount(refSelectorEl);
57+
}
58+
initGlobalDropdown();
5459
}
5560

5661
export async function initViewFileTreeSidebar() {
5762
const sidebarElement = document.querySelector('.repo-view-file-tree-sidebar');
5863
if (!sidebarElement) return;
5964

60-
document.querySelector('.show-tree-sidebar-button').addEventListener('click', () => {
61-
toggleSidebar(true);
62-
});
63-
6465
document.querySelector('.hide-tree-sidebar-button').addEventListener('click', () => {
6566
toggleSidebar(false);
6667
});
68+
document.querySelector('.repo-home-filelist .show-tree-sidebar-button').addEventListener('click', () => {
69+
toggleSidebar(true);
70+
});
6771

6872
const fileTree = document.querySelector('#view-file-tree');
6973
const baseUrl = fileTree.getAttribute('data-api-base-url');
@@ -79,7 +83,7 @@ export async function initViewFileTreeSidebar() {
7983
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {
8084
window.history.pushState(null, null, `${baseUrl}/src/${refType}/${refName}/${item.path}`);
8185
selectedItem.value = item.path;
82-
loadContent(item);
86+
loadContent();
8387
}});
8488
fileTreeView.mount(fileTree);
8589
}

0 commit comments

Comments
 (0)