single.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "strings"
  7. "github.com/codegangsta/martini"
  8. "github.com/gogits/gogs/models"
  9. "github.com/gogits/gogs/modules/middleware"
  10. )
  11. func Single(ctx *middleware.Context, params martini.Params) {
  12. if !ctx.Repo.IsValid {
  13. return
  14. }
  15. if params["branchname"] == "" {
  16. params["branchname"] = "master"
  17. }
  18. treename := params["_1"]
  19. files, err := models.GetReposFiles(params["username"], params["reponame"],
  20. params["branchname"], treename)
  21. if err != nil {
  22. ctx.Handle(200, "repo.Single", err)
  23. return
  24. }
  25. ctx.Data["Username"] = params["username"]
  26. ctx.Data["Reponame"] = params["reponame"]
  27. ctx.Data["Branchname"] = params["branchname"]
  28. brs, err := models.GetBranches(params["username"], params["reponame"])
  29. if err != nil {
  30. ctx.Handle(200, "repo.Single", err)
  31. return
  32. }
  33. ctx.Data["Branches"] = brs
  34. var treenames []string
  35. Paths := make([]string, 0)
  36. if len(treename) > 0 {
  37. treenames = strings.Split(treename, "/")
  38. for i, _ := range treenames {
  39. Paths = append(Paths, strings.Join(treenames[0:i+1], "/"))
  40. }
  41. }
  42. ctx.Data["Paths"] = Paths
  43. ctx.Data["Treenames"] = treenames
  44. ctx.Data["IsRepoToolbarSource"] = true
  45. ctx.Data["IsRepositoryOwner"] = strings.ToLower(params["username"]) == ctx.User.LowerName
  46. ctx.Data["Files"] = files
  47. ctx.Render.HTML(200, "repo/single", ctx.Data)
  48. }
  49. func Setting(ctx *middleware.Context, params martini.Params) {
  50. if !ctx.Repo.IsValid {
  51. return
  52. }
  53. var title string
  54. if t, ok := ctx.Data["Title"].(string); ok {
  55. title = t
  56. }
  57. ctx.Data["Title"] = title + " - settings"
  58. ctx.Data["IsRepoToolbarSetting"] = true
  59. ctx.Data["IsRepositoryOwner"] = strings.ToLower(params["username"]) == ctx.User.LowerName
  60. ctx.Render.HTML(200, "repo/setting", ctx.Data)
  61. }
  62. func Commits(ctx *middleware.Context) string {
  63. return "This is commits page"
  64. }
  65. func Issues(ctx *middleware.Context) string {
  66. return "This is issues page"
  67. }
  68. func Pulls(ctx *middleware.Context) string {
  69. return "This is pulls page"
  70. }