mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-13 00:45:25 +02:00
fix
This commit is contained in:
parent
fe63c5fbc1
commit
087f0d41bd
@ -96,9 +96,16 @@ func RefBlame(ctx *context.Context) {
|
|||||||
ctx.Data["FileSize"] = fileSize
|
ctx.Data["FileSize"] = fileSize
|
||||||
ctx.Data["FileName"] = blob.Name()
|
ctx.Data["FileName"] = blob.Name()
|
||||||
|
|
||||||
|
var tplName templates.TplName
|
||||||
|
if ctx.FormBool("only_content") {
|
||||||
|
tplName = tplRepoHomeContent
|
||||||
|
} else {
|
||||||
|
tplName = tplRepoHome
|
||||||
|
}
|
||||||
|
|
||||||
if fileSize >= setting.UI.MaxDisplayFileSize {
|
if fileSize >= setting.UI.MaxDisplayFileSize {
|
||||||
ctx.Data["IsFileTooLarge"] = true
|
ctx.Data["IsFileTooLarge"] = true
|
||||||
ctx.HTML(http.StatusOK, tplRepoHome)
|
ctx.HTML(http.StatusOK, tplName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +133,7 @@ func RefBlame(ctx *context.Context) {
|
|||||||
|
|
||||||
renderBlame(ctx, result.Parts, commitNames)
|
renderBlame(ctx, result.Parts, commitNames)
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, tplRepoHome)
|
ctx.HTML(http.StatusOK, tplName)
|
||||||
}
|
}
|
||||||
|
|
||||||
type blameResult struct {
|
type blameResult struct {
|
||||||
|
@ -46,12 +46,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
tplRepoEMPTY templates.TplName = "repo/empty"
|
tplRepoEMPTY templates.TplName = "repo/empty"
|
||||||
tplRepoHome templates.TplName = "repo/home"
|
tplRepoHome templates.TplName = "repo/home"
|
||||||
tplRepoViewList templates.TplName = "repo/view_list"
|
tplRepoHomeContent templates.TplName = "repo/home_content"
|
||||||
tplWatchers templates.TplName = "repo/watchers"
|
tplRepoViewList templates.TplName = "repo/view_list"
|
||||||
tplForks templates.TplName = "repo/forks"
|
tplWatchers templates.TplName = "repo/watchers"
|
||||||
tplMigrating templates.TplName = "repo/migrate/migrating"
|
tplForks templates.TplName = "repo/forks"
|
||||||
|
tplMigrating templates.TplName = "repo/migrate/migrating"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fileInfo struct {
|
type fileInfo struct {
|
||||||
|
@ -379,5 +379,9 @@ func Home(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, tplRepoHome)
|
if ctx.FormBool("only_content") {
|
||||||
|
ctx.HTML(http.StatusOK, tplRepoHomeContent)
|
||||||
|
} else {
|
||||||
|
ctx.HTML(http.StatusOK, tplRepoHome)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@
|
|||||||
|
|
||||||
{{if not $isTreePathRoot}}
|
{{if not $isTreePathRoot}}
|
||||||
{{$treeNameIdxLast := Eval $treeNamesLen "-" 1}}
|
{{$treeNameIdxLast := Eval $treeNamesLen "-" 1}}
|
||||||
<span class="breadcrumb repo-path tw-ml-1">
|
<span id="repo_path" class="breadcrumb repo-path tw-ml-1">
|
||||||
<a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{StringUtils.EllipsisString .Repository.Name 30}}</a>
|
<a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{StringUtils.EllipsisString .Repository.Name 30}}</a>
|
||||||
{{- range $i, $v := .TreeNames -}}
|
{{- range $i, $v := .TreeNames -}}
|
||||||
<span class="breadcrumb-divider">/</span>
|
<span class="breadcrumb-divider">/</span>
|
||||||
@ -122,25 +122,16 @@
|
|||||||
{{template "repo/clone_panel" .}}
|
{{template "repo/clone_panel" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
|
{{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
|
||||||
<a class="ui button" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
|
<a id="path_history" class="ui button" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
|
||||||
{{svg "octicon-history" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_history"}}
|
{{svg "octicon-history" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_history"}}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{if .IsViewFile}}
|
|
||||||
{{template "repo/view_file" .}}
|
<div id="path_content">
|
||||||
{{else if .IsBlame}}
|
{{template "repo/home_content" .}}
|
||||||
{{template "repo/blame" .}}
|
</div>
|
||||||
{{else}}{{/* IsViewDirectory */}}
|
|
||||||
{{if $isTreePathRoot}}
|
|
||||||
{{template "repo/code/upstream_diverging_info" .}}
|
|
||||||
{{end}}
|
|
||||||
{{template "repo/view_list" .}}
|
|
||||||
{{if and .ReadmeExist (or .IsMarkup .IsPlainText)}}
|
|
||||||
{{template "repo/view_file" .}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if $showSidebar}}
|
{{if $showSidebar}}
|
||||||
|
16
templates/repo/home_content.tmpl
Normal file
16
templates/repo/home_content.tmpl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{{$treeNamesLen := len .TreeNames}}
|
||||||
|
{{$isTreePathRoot := eq $treeNamesLen 0}}
|
||||||
|
|
||||||
|
{{if .IsViewFile}}
|
||||||
|
{{template "repo/view_file" .}}
|
||||||
|
{{else if .IsBlame}}
|
||||||
|
{{template "repo/blame" .}}
|
||||||
|
{{else}}{{/* IsViewDirectory */}}
|
||||||
|
{{if $isTreePathRoot}}
|
||||||
|
{{template "repo/code/upstream_diverging_info" .}}
|
||||||
|
{{end}}
|
||||||
|
{{template "repo/view_list" .}}
|
||||||
|
{{if and .ReadmeExist (or .IsMarkup .IsPlainText)}}
|
||||||
|
{{template "repo/view_file" .}}
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
@ -31,13 +31,12 @@ async function toggleSidebar(visibility) {
|
|||||||
async function loadChildren(item, recursive?: boolean) {
|
async function loadChildren(item, recursive?: boolean) {
|
||||||
const el = document.querySelector('#view-file-tree');
|
const el = document.querySelector('#view-file-tree');
|
||||||
const apiBaseUrl = el.getAttribute('data-api-base-url');
|
const apiBaseUrl = el.getAttribute('data-api-base-url');
|
||||||
const response = await GET(`${apiBaseUrl}/tree/${item ? item.path : ''}?recursive=${recursive ?? false}`);
|
const response = await GET(`${apiBaseUrl}/tree/${item ? item.path : ''}?ref=&recursive=${recursive ?? false}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
if (json instanceof Array) {
|
if (json instanceof Array) {
|
||||||
return json.map((i) => ({
|
return json.map((i) => ({
|
||||||
name: i.name,
|
name: i.name,
|
||||||
isFile: i.isFile,
|
isFile: i.isFile,
|
||||||
htmlUrl: i.html_url,
|
|
||||||
path: i.path,
|
path: i.path,
|
||||||
children: i.children,
|
children: i.children,
|
||||||
}));
|
}));
|
||||||
@ -46,7 +45,10 @@ async function loadChildren(item, recursive?: boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadContent(item) {
|
async function loadContent(item) {
|
||||||
document.querySelector('.repo-home-filelist').innerHTML = `load content of ${item.path}`;
|
// todo: change path of `repo_path` `path_history`
|
||||||
|
// load content by path (content based on home_content.tmpl)
|
||||||
|
const response = await GET(`${window.location.href}?only_content=true`);
|
||||||
|
document.querySelector('#path_content').innerHTML = await response.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initViewFileTreeSidebar() {
|
export async function initViewFileTreeSidebar() {
|
||||||
@ -63,13 +65,14 @@ export async function initViewFileTreeSidebar() {
|
|||||||
|
|
||||||
const fileTree = document.querySelector('#view-file-tree');
|
const fileTree = document.querySelector('#view-file-tree');
|
||||||
const treePath = fileTree.getAttribute('data-tree-path');
|
const treePath = fileTree.getAttribute('data-tree-path');
|
||||||
|
const basePath = window.location.href.replace(treePath, '');
|
||||||
const selectedItem = ref(treePath);
|
const selectedItem = ref(treePath);
|
||||||
|
|
||||||
const files = await loadChildren({path: treePath}, true);
|
const files = await loadChildren({path: treePath}, true);
|
||||||
|
|
||||||
fileTree.classList.remove('is-loading');
|
fileTree.classList.remove('is-loading');
|
||||||
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {
|
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {
|
||||||
window.history.pushState(null, null, item.htmlUrl);
|
window.history.pushState(null, null, `${basePath}${item.path}`);
|
||||||
selectedItem.value = item.path;
|
selectedItem.value = item.path;
|
||||||
loadContent(item);
|
loadContent(item);
|
||||||
}});
|
}});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user