1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00

Remember diff view style (#163)

This commit is contained in:
Andrey Nering 2016-11-13 00:54:04 -02:00 committed by Lunny Xiao
parent bd76e156bb
commit 739f07c98e
7 changed files with 47 additions and 7 deletions

View File

@ -584,7 +584,7 @@ func runWeb(ctx *cli.Context) error {
m.Group("/pulls/:index", func() {
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.ViewPullFiles)
m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ViewPullFiles)
m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
}, repo.MustAllowPulls)
@ -592,12 +592,12 @@ func runWeb(ctx *cli.Context) error {
m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
m.Get("/raw/*", repo.SingleDownload)
m.Get("/commits/*", repo.RefCommits)
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.Diff)
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
m.Get("/forks", repo.Forks)
}, context.RepoRef())
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff)
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.CompareDiff)
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff)
}, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare)
m.Group("/:username/:reponame", func() {
m.Get("/stars", repo.Stars)

View File

@ -72,6 +72,8 @@ var migrations = []Migration{
// v13 -> v14:v0.9.87
NewMigration("set comment updated with created", setCommentUpdatedWithCreated),
NewMigration("create user column diff view style", createUserColumnDiffViewStyle),
}
// Migrate database to current version
@ -96,7 +98,7 @@ func Migrate(x *xorm.Engine) error {
v := currentVersion.Version
if _MIN_DB_VER > v {
log.Fatal(4, `Gogs no longer supports auto-migration from your previously installed version.
log.Fatal(4, `Gogs no longer supports auto-migration from your previously installed version.
Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to current version.`)
return nil
}

View File

@ -22,3 +22,15 @@ func setCommentUpdatedWithCreated(x *xorm.Engine) (err error) {
}
return nil
}
type UserV14 struct {
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
}
func (*UserV14) TableName() string {
return "user"
}
func createUserColumnDiffViewStyle(x *xorm.Engine) error {
return x.Sync2(new(UserV14))
}

View File

@ -107,6 +107,9 @@ type User struct {
NumMembers int
Teams []*Team `xorm:"-"`
Members []*User `xorm:"-"`
// Preferences
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
}
func (u *User) BeforeInsert() {
@ -126,6 +129,11 @@ func (u *User) SetLastLogin() {
u.LastLoginUnix = time.Now().Unix()
}
func (u *User) UpdateDiffViewStyle(style string) error {
u.DiffViewStyle = style
return UpdateUser(u)
}
func (u *User) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "full_name":

View File

@ -180,7 +180,6 @@ func Diff(ctx *context.Context) {
}
ctx.Data["CommitID"] = commitID
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName
ctx.Data["IsImageFile"] = commit.IsImageFile
@ -239,7 +238,6 @@ func CompareDiff(ctx *context.Context) {
}
commits = models.ValidateCommitsWithEmails(commits)
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["CommitRepoLink"] = ctx.Repo.RepoLink
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = commits.Len()

View File

@ -21,3 +21,24 @@ func SetEditorconfigIfExists(ctx *context.Context) {
ctx.Data["Editorconfig"] = ec
}
func SetDiffViewStyle(ctx *context.Context) {
var (
userStyle = ctx.User.DiffViewStyle
queryStyle = ctx.Query("style")
style string
)
if queryStyle == "unified" || queryStyle == "split" {
style = queryStyle
} else if userStyle == "unified" || userStyle == "split" {
style = userStyle
} else {
style = "unified"
}
ctx.Data["IsSplitStyle"] = style == "split"
if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
ctx.Handle(500, "ErrUpdateDiffViewStyle", err)
}
}

View File

@ -367,7 +367,6 @@ func ViewPullFiles(ctx *context.Context) {
}
headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["Username"] = pull.HeadUserName
ctx.Data["Reponame"] = pull.HeadRepo.Name
ctx.Data["IsImageFile"] = commit.IsImageFile