Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file tree to file view page #32721

Open
wants to merge 62 commits into
base: main
Choose a base branch
from

Conversation

kerwin612
Copy link
Member

@kerwin612 kerwin612 commented Dec 5, 2024

This pull request introduces a file tree on the left side when reviewing files of a repository.

32721

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 5, 2024
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Dec 5, 2024
@kerwin612 kerwin612 marked this pull request as draft December 5, 2024 02:38
@github-actions github-actions bot added modifies/templates This PR modifies the template files modifies/frontend labels Dec 5, 2024
@yp05327 yp05327 added this to the 1.24.0 milestone Dec 5, 2024
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 5, 2024
@kerwin612 kerwin612 marked this pull request as ready for review December 5, 2024 06:34
templates/repo/home.tmpl Outdated Show resolved Hide resolved
templates/repo/home.tmpl Outdated Show resolved Hide resolved
templates/repo/home.tmpl Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 5, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Dec 5, 2024
@kerwin612 kerwin612 requested a review from wxiaoguang December 5, 2024 14:22
@lunny
Copy link
Member

lunny commented Dec 5, 2024

1 Move the three buttons on top of the left tree when expanding and move to the right once folding.
图片

2 The expanding state should be stored to users' configuration or as a session value once changed.
3 It should be sorted so that folders should always be on top of files on the left tree.
图片

@wxiaoguang wxiaoguang marked this pull request as draft December 7, 2024 03:21
@kerwin612 kerwin612 force-pushed the add-file-tree-to-file-view-page branch from 7229b60 to 59e46d4 Compare December 13, 2024 06:30
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 13, 2024
@kerwin612 kerwin612 force-pushed the add-file-tree-to-file-view-page branch from e45940d to c4e7f0c Compare December 13, 2024 12:20
Comment on lines +1 to +12
{{template "repo/branch_dropdown" dict
"Repository" .ctxData.Repository
"ShowTabBranches" true
"ShowTabTags" true
"CurrentRefType" .ctxData.RefType
"CurrentRefShortName" .ctxData.RefShortName
"CurrentTreePath" .ctxData.TreePath
"RefLinkTemplate" "{RepoLink}/src/{RefType}/{RefShortName}/{TreePath}"
"AllowCreateNewRef" .ctxData.CanCreateBranch
"ShowViewAllRefsEntry" true
"ContainerClasses" .containerClasses
}}
Copy link
Contributor

@wxiaoguang wxiaoguang Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not right (the merge was wrong)

Maybe not wrong but it should not be like that IMO

Comment on lines +1007 to +1008
ctx.Data["RefShortName"] = util.Iif(refType == RepoRefCommit, base.ShortSha(ctx.Repo.RefName), ctx.Repo.RefName)
ctx.Data["RefType"] = RefTypeName(refType)
Copy link
Contributor

@wxiaoguang wxiaoguang Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't do that (keep adding more variables to global template data)

If you'd like to refactor it, it needs a separate PR, mixing everything together would make this PR unmaintainable and possible to lose code.

-> Refactor context repository #33202

ref := ctx.FormTrim("ref")
recursive := ctx.FormBool("recursive")

gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, ctx.Repo.Repository)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is ctx.Repo.GitRepo

}
defer closer.Close()

refName := gitRepo.UnstableGuessRefByShortName(ref)
Copy link
Contributor

@wxiaoguang wxiaoguang Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not guess anymore, frontend should pass the correctly ref to backend.

image

@@ -743,6 +744,21 @@ const (
RepoRefBlob
)

func RefTypeName(refType RepoRefType) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It duplicates with BranchNameSubURL

@yp05327

This comment was marked as outdated.

@kerwin612

This comment was marked as resolved.

@yp05327
Copy link
Contributor

yp05327 commented Jan 10, 2025

It seems that PDF file will broken.

a good test repo: https://gitea.com/silverwind/symlink-test/src/branch/master/pdf/bitcoin.pdf

Reproduce:

  1. click the pdf file in file tree -> loading forever
  2. refresh the page -> OK

Edited:
https://gitea.com/silverwind/symlink-test/src/branch/master/media/asciinema.cast
This is also NG, maybe it is same.

details

click the pdf file in file tree -> nothing
image

refresh the page -> OK
image

@yp05327

This comment was marked as outdated.

@kerwin612
Copy link
Member Author

It seems that PDF file will broken.

resolved

@kerwin612
Copy link
Member Author

This notification can not be closed. The trigger is broken.

resolved

@yp05327
Copy link
Contributor

yp05327 commented Jan 10, 2025

My mouse has a back button, if I click the file tree, and then back, the URL will be changed, but the web page won't. 👀
This can be done later. Not a request.

@yp05327
Copy link
Contributor

yp05327 commented Jan 10, 2025

http://host/owner/symlink-test/src/tag/0.0.1/file-symlink

file-symlink not work.

image

@@ -118,3 +122,363 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git
}
return tree, nil
}

type TreeEntry struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't call it TreeEntry again since there are already some TreeEntry structs in code.


type TreeEntry struct {
Name string `json:"name"`
IsFile bool `json:"isFile"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides "file" / "dir", it could also be something like "submodule"

// There are many "cancel button" elements in modal dialogs, Fomantic UI expects they are button-like elements but never submit a form.
// However, Gitea misuses the modal dialog and put the cancel buttons inside forms, so we must prevent the form submission.
// There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content")
addDelegatedEventListener(document, 'click', 'form button.ui.cancel.button', (_ /* el */, e) => e.preventDefault());
addDelegatedEventListener(target, 'click', 'form button.ui.cancel.button', (_ /* el */, e) => e.preventDefault());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addDelegatedEventListener means the event listener has been added to the "document" globally, it works for all nodes (including newly added ones), the listener shouldn't be added to any children elements anymore.

@wxiaoguang
Copy link
Contributor

To make things clear, we need this first: Refactor context repository #33202

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jan 10, 2025

And I would suggest you to split the PR into small ones, do refactorings and preparations first, otherwise neither current tmpl layout nor the framework works for your new feature.

You can see how many PRs I made in 1.23 to make the render system right:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/changelog Adds the changelog for a new Gitea version type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants