mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-12 01:30:34 +01: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:
parent
d9c0f86de8
commit
de26c8acce
@ -49,6 +49,19 @@ func init() {
|
|||||||
db.RegisterModel(new(ReviewState))
|
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.
|
// 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.
|
// 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
|
// 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
|
// as the viewed information is designed to be loaded only on latest PR
|
||||||
// diff and if you're signed in.
|
// diff and if you're signed in.
|
||||||
var reviewState *pull_model.ReviewState
|
var reviewState *pull_model.ReviewState
|
||||||
|
var numViewedFiles int
|
||||||
if ctx.IsSigned && isShowAllCommits {
|
if ctx.IsSigned && isShowAllCommits {
|
||||||
reviewState, err = gitdiff.SyncUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diff, diffOptions)
|
reviewState, err = gitdiff.SyncUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diff, diffOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SyncUserSpecificDiff", err)
|
ctx.ServerError("SyncUserSpecificDiff", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if reviewState != nil {
|
||||||
|
numViewedFiles = reviewState.GetViewedFileCount()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, beforeCommitID, afterCommitID)
|
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
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["DiffShortStat"] = diffShortStat
|
ctx.Data["DiffShortStat"] = diffShortStat
|
||||||
|
ctx.Data["NumViewedFiles"] = numViewedFiles
|
||||||
|
|
||||||
ctx.PageData["prReview"] = map[string]any{
|
ctx.PageData["prReview"] = map[string]any{
|
||||||
"numberOfFiles": diffShortStat.NumFiles,
|
"numberOfFiles": diffShortStat.NumFiles,
|
||||||
"numberOfViewedFiles": diff.NumViewedFiles,
|
"numberOfViewedFiles": numViewedFiles,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil {
|
if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil {
|
||||||
|
|||||||
@ -523,7 +523,6 @@ type Diff struct {
|
|||||||
Start, End string
|
Start, End string
|
||||||
Files []*DiffFile
|
Files []*DiffFile
|
||||||
IsIncomplete bool
|
IsIncomplete bool
|
||||||
NumViewedFiles int // user-specific
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadComments loads comments into each line
|
// LoadComments loads comments into each line
|
||||||
@ -1412,7 +1411,6 @@ outer:
|
|||||||
// Check whether the file has already been viewed
|
// Check whether the file has already been viewed
|
||||||
if fileViewedState == pull_model.Viewed {
|
if fileViewedState == pull_model.Viewed {
|
||||||
diffFile.IsViewed = true
|
diffFile.IsViewed = true
|
||||||
diff.NumViewedFiles++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,9 +27,9 @@
|
|||||||
{{if and .PageIsPullFiles $.SignedUserID (not .DiffNotAvailable)}}
|
{{if and .PageIsPullFiles $.SignedUserID (not .DiffNotAvailable)}}
|
||||||
<div class="not-mobile tw-flex tw-items-center tw-flex-col tw-whitespace-nowrap tw-mr-1">
|
<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"}}">
|
<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>
|
</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>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{template "repo/diff/whitespace_dropdown" .}}
|
{{template "repo/diff/whitespace_dropdown" .}}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user