diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2016-11-13 00:54:04 -0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2016-11-13 10:54:04 +0800 |
commit | 739f07c98e1254f776a7cb943a3430de32b17d1d (patch) | |
tree | 5ba37863a5b2f3188413dc9267d57c63cdb744ff /routers | |
parent | bd76e156bb08424841ff992aaffcc5aef913b703 (diff) | |
download | gitea-739f07c98e1254f776a7cb943a3430de32b17d1d.tar.gz gitea-739f07c98e1254f776a7cb943a3430de32b17d1d.zip |
Remember diff view style (#163)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/commit.go | 2 | ||||
-rw-r--r-- | routers/repo/middlewares.go | 21 | ||||
-rw-r--r-- | routers/repo/pull.go | 1 |
3 files changed, 21 insertions, 3 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go index e3170b053d..9706779ee5 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -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() diff --git a/routers/repo/middlewares.go b/routers/repo/middlewares.go index 94e007cd20..757a049ab7 100644 --- a/routers/repo/middlewares.go +++ b/routers/repo/middlewares.go @@ -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) + } +} diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 83352d7f3c..6e99dfaed0 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -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 |