-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-tree-sidebar-2-file-view' into add-file-tree-to-fil…
…e-view-page
- Loading branch information
Showing
12 changed files
with
436 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2014 The Gogs Authors. All rights reserved. | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/models/unit" | ||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/services/context" | ||
files_service "code.gitea.io/gitea/services/repository/files" | ||
) | ||
|
||
// canReadFiles returns true if repository is readable and user has proper access level. | ||
func canReadFiles(r *context.Repository) bool { | ||
return r.Permission.CanRead(unit.TypeCode) | ||
} | ||
|
||
// GetContents Get the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir | ||
func GetContents(ctx *context.Context) { | ||
if !canReadFiles(ctx.Repo) { | ||
ctx.NotFound("Invalid FilePath", nil) | ||
return | ||
} | ||
|
||
treePath := ctx.PathParam("*") | ||
ref := ctx.FormTrim("ref") | ||
|
||
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil { | ||
if git.IsErrNotExist(err) { | ||
ctx.NotFound("GetContentsOrList", err) | ||
return | ||
} | ||
ctx.ServerError("Repo.GitRepo.GetCommit", err) | ||
} else { | ||
ctx.JSON(http.StatusOK, fileList) | ||
} | ||
} | ||
|
||
// GetContentsList Get the metadata of all the entries of the root dir | ||
func GetContentsList(ctx *context.Context) { | ||
GetContents(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<div class="view-file-tree-sidebar-top"> | ||
<div class="sidebar-header"> | ||
<button class="hide-tree-sidebar-button ui compact basic button icon" title="{{ctx.Locale.Tr "repo.diff.hide_file_tree"}}"> | ||
{{svg "octicon-sidebar-expand" 20 "icon"}} | ||
</button> | ||
<b> Files</b> | ||
</div> | ||
<div class="sidebar-ref"> | ||
{{$branchDropdownCurrentRefType := "branch"}} | ||
{{$branchDropdownCurrentRefShortName := .BranchName}} | ||
{{if .IsViewTag}} | ||
{{$branchDropdownCurrentRefType = "tag"}} | ||
{{$branchDropdownCurrentRefShortName = .TagName}} | ||
{{end}} | ||
{{template "repo/branch_dropdown" dict | ||
"Repository" .Repository | ||
"ShowTabBranches" true | ||
"ShowTabTags" true | ||
"CurrentRefType" $branchDropdownCurrentRefType | ||
"CurrentRefShortName" $branchDropdownCurrentRefShortName | ||
"CurrentTreePath" .TreePath | ||
"RefLinkTemplate" "{RepoLink}/src/{RefType}/{RefShortName}/{TreePath}" | ||
"AllowCreateNewRef" .CanCreateBranch | ||
"ShowViewAllRefsEntry" true | ||
}} | ||
|
||
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}} | ||
{{$cmpBranch := ""}} | ||
{{if ne .Repository.ID .BaseRepo.ID}} | ||
{{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}} | ||
{{end}} | ||
{{$cmpBranch = print $cmpBranch (.BranchName|PathEscapeSegments)}} | ||
{{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}} | ||
<a role="button" class="ui compact basic button" href="{{$compareLink}}" | ||
data-tooltip-content="{{if .PullRequestCtx.Allowed}}{{ctx.Locale.Tr "repo.pulls.compare_changes"}}{{else}}{{ctx.Locale.Tr "action.compare_branch"}}{{end}}"> | ||
{{svg "octicon-git-pull-request"}} | ||
</a> | ||
{{end}} | ||
|
||
{{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}} | ||
<button class="ui dropdown basic compact jump button"{{if not .Repository.CanEnableEditor}} disabled{{end}}> | ||
{{ctx.Locale.Tr "repo.editor.add_file"}} | ||
{{svg "octicon-triangle-down" 14 "dropdown icon"}} | ||
<div class="menu"> | ||
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}"> | ||
{{ctx.Locale.Tr "repo.editor.new_file"}} | ||
</a> | ||
{{if .RepositoryUploadEnabled}} | ||
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}"> | ||
{{ctx.Locale.Tr "repo.editor.upload_file"}} | ||
</a> | ||
{{end}} | ||
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}"> | ||
{{ctx.Locale.Tr "repo.editor.patch"}} | ||
</a> | ||
</div> | ||
</button> | ||
{{end}} | ||
</div> | ||
</div> | ||
<div class="view-file-tree-sidebar-bottom"> | ||
<div id="view-file-tree" class="center" data-api-base-url="{{.RepoLink}}" data-tree-path="{{$.TreePath}}"> | ||
{{svg "octicon-sync" 16 "job-status-rotate"}} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<script lang="ts" setup> | ||
import ViewFileTreeItem from './ViewFileTreeItem.vue'; | ||
defineProps<{ | ||
files: any, | ||
selectedItem: string, | ||
loadChildren: any, | ||
}>(); | ||
</script> | ||
|
||
<template> | ||
<div class="view-file-tree-items"> | ||
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often --> | ||
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :load-children="loadChildren"/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.view-file-tree-items { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1px; | ||
margin-right: .5rem; | ||
} | ||
</style> |
Oops, something went wrong.