Remember diff view style (#163)

pull/166/head
Andrey Nering 8 years ago committed by Lunny Xiao
parent bd76e156bb
commit 739f07c98e
  1. 6
      cmd/web.go
  2. 4
      models/migrations/migrations.go
  3. 12
      models/migrations/v14.go
  4. 8
      models/user.go
  5. 2
      routers/repo/commit.go
  6. 21
      routers/repo/middlewares.go
  7. 1
      routers/repo/pull.go

@ -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)

@ -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
}

@ -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))
}

@ -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":

@ -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()

@ -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)
}
}

@ -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

Loading…
Cancel
Save