mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-08 10:37:42 -05:00
Fix viewed files number is not right if not all files loaded (#35821)
Fix #35803 --------- Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -49,6 +49,19 @@ func init() {
|
||||
db.RegisterModel(new(ReviewState))
|
||||
}
|
||||
|
||||
func (rs *ReviewState) GetViewedFileCount() int {
|
||||
if len(rs.UpdatedFiles) == 0 {
|
||||
return 0
|
||||
}
|
||||
var numViewedFiles int
|
||||
for _, state := range rs.UpdatedFiles {
|
||||
if state == Viewed {
|
||||
numViewedFiles++
|
||||
}
|
||||
}
|
||||
return numViewedFiles
|
||||
}
|
||||
|
||||
// GetReviewState returns the ReviewState with all given values prefilled, whether or not it exists in the database.
|
||||
// If the review didn't exist before in the database, it won't afterwards either.
|
||||
// The returned boolean shows whether the review exists in the database
|
||||
|
||||
@@ -782,12 +782,16 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
|
||||
// as the viewed information is designed to be loaded only on latest PR
|
||||
// diff and if you're signed in.
|
||||
var reviewState *pull_model.ReviewState
|
||||
var numViewedFiles int
|
||||
if ctx.IsSigned && isShowAllCommits {
|
||||
reviewState, err = gitdiff.SyncUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diff, diffOptions)
|
||||
if err != nil {
|
||||
ctx.ServerError("SyncUserSpecificDiff", err)
|
||||
return
|
||||
}
|
||||
if reviewState != nil {
|
||||
numViewedFiles = reviewState.GetViewedFileCount()
|
||||
}
|
||||
}
|
||||
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, beforeCommitID, afterCommitID)
|
||||
@@ -796,10 +800,11 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
|
||||
return
|
||||
}
|
||||
ctx.Data["DiffShortStat"] = diffShortStat
|
||||
ctx.Data["NumViewedFiles"] = numViewedFiles
|
||||
|
||||
ctx.PageData["prReview"] = map[string]any{
|
||||
"numberOfFiles": diffShortStat.NumFiles,
|
||||
"numberOfViewedFiles": diff.NumViewedFiles,
|
||||
"numberOfViewedFiles": numViewedFiles,
|
||||
}
|
||||
|
||||
if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil {
|
||||
|
||||
@@ -520,10 +520,9 @@ func getCommitFileLineCountAndLimitedContent(commit *git.Commit, filePath string
|
||||
|
||||
// Diff represents a difference between two git trees.
|
||||
type Diff struct {
|
||||
Start, End string
|
||||
Files []*DiffFile
|
||||
IsIncomplete bool
|
||||
NumViewedFiles int // user-specific
|
||||
Start, End string
|
||||
Files []*DiffFile
|
||||
IsIncomplete bool
|
||||
}
|
||||
|
||||
// LoadComments loads comments into each line
|
||||
@@ -1412,7 +1411,6 @@ outer:
|
||||
// Check whether the file has already been viewed
|
||||
if fileViewedState == pull_model.Viewed {
|
||||
diffFile.IsViewed = true
|
||||
diff.NumViewedFiles++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
{{if and .PageIsPullFiles $.SignedUserID (not .DiffNotAvailable)}}
|
||||
<div class="not-mobile tw-flex tw-items-center tw-flex-col tw-whitespace-nowrap tw-mr-1">
|
||||
<label for="viewed-files-summary" id="viewed-files-summary-label" data-text-changed-template="{{ctx.Locale.Tr "repo.pulls.viewed_files_label"}}">
|
||||
{{ctx.Locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .DiffShortStat.NumFiles}}
|
||||
{{ctx.Locale.Tr "repo.pulls.viewed_files_label" .NumViewedFiles .DiffShortStat.NumFiles}}
|
||||
</label>
|
||||
<progress id="viewed-files-summary" value="{{.Diff.NumViewedFiles}}" max="{{.DiffShortStat.NumFiles}}"></progress>
|
||||
<progress id="viewed-files-summary" value="{{.NumViewedFiles}}" max="{{.DiffShortStat.NumFiles}}"></progress>
|
||||
</div>
|
||||
{{end}}
|
||||
{{template "repo/diff/whitespace_dropdown" .}}
|
||||
|
||||
Reference in New Issue
Block a user