From 4b8e888437a9972459e73496d811ea30f105f06c Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 15 Mar 2014 05:30:59 -0400 Subject: [PATCH 1/2] Finish feeds --- README.md | 2 +- models/action.go | 1 + modules/auth/user.go | 2 +- routers/user/user.go | 47 +++++++++++++++++++++-------------- templates/user/dashboard.tmpl | 12 ++++++++- templates/user/profile.tmpl | 4 +-- 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 0e354a9d4..dd95e90d6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![wercker status](https://app.wercker.com/status/ad0bdb0b Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language, it currently supports Linux and Max OS X, but Windows has **NOT** supported yet due to installation problem with [libgit2](http://libgit2.github.com/) in Windows. -##### Current version: 0.0.7 Alpha +##### Current version: 0.0.8 Alpha ## Purpose diff --git a/models/action.go b/models/action.go index 8008d331c..6a77d7300 100644 --- a/models/action.go +++ b/models/action.go @@ -56,6 +56,7 @@ func NewRepoAction(user *User, repo *Repository) error { return err } +// GetFeeds returns action list of given user in given context. func GetFeeds(userid, offset int64, isProfile bool) ([]Action, error) { actions := make([]Action, 0, 20) sess := orm.Limit(20, int(offset)).Desc("id").Where("user_id=?", userid) diff --git a/modules/auth/user.go b/modules/auth/user.go index d950b2500..e5f22a091 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -97,7 +97,7 @@ func SignOutRequire() martini.Handler { type FeedsForm struct { UserId int64 `form:"userid" binding:"Required"` - Offset int64 `form:"offset"` + Page int64 `form:"p"` } type UpdateProfileForm struct { diff --git a/routers/user/user.go b/routers/user/user.go index 680055f66..513767a30 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -5,6 +5,7 @@ package user import ( + "fmt" "net/http" "github.com/codegangsta/martini" @@ -26,10 +27,17 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) { return } data["MyRepos"] = repos + + feeds, err := models.GetFeeds(auth.SignedInId(session), 0, false) + if err != nil { + log.Handle(200, "user.Dashboard", data, r, err) + return + } + data["Feeds"] = feeds r.HTML(200, "user/dashboard", data) } -func Profile(params martini.Params, r render.Render, req *http.Request, data base.TmplData, session sessions.Session) { +func Profile(params martini.Params, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { data["Title"] = "Profile" // TODO: Need to check view self or others. @@ -40,23 +48,13 @@ func Profile(params martini.Params, r render.Render, req *http.Request, data bas } data["Owner"] = user - - req.ParseForm() - tab := req.Form.Get("tab") - data["TabName"] = tab - - switch tab { - case "activity": - feeds, err := models.GetFeeds(user.Id, 0, true) - if err != nil { - log.Handle(200, "user.Profile", data, r, err) - return - } - data["Feeds"] = feeds - default: - + data["TabName"] = req.FormValue("tab") + feeds, err := models.GetFeeds(user.Id, 0, true) + if err != nil { + log.Handle(200, "user.Profile", data, r, err) + return } - + data["Feeds"] = feeds r.HTML(200, "user/profile", data) } @@ -172,10 +170,21 @@ func Delete(data base.TmplData, req *http.Request, session sessions.Session, r r r.HTML(200, "user/delete", data) } +const ( + feedTpl = ` +
%s
%s
` +) + func Feeds(form auth.FeedsForm, r render.Render) { - actions, err := models.GetFeeds(form.UserId, form.Offset, false) + actions, err := models.GetFeeds(form.UserId, form.Page*20, false) if err != nil { r.JSON(500, err) } - r.JSON(200, actions) + + feeds := make([]string, len(actions)) + for i := range actions { + feeds[i] = fmt.Sprintf(feedTpl, base.ActionIcon(actions[i].OpType), + base.TimeSince(actions[i].Created), base.ActionDesc(actions[i])) + } + r.JSON(200, &feeds) } diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index 7768a7ee6..14b345156 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -14,7 +14,17 @@
{{if .HasInfo}}
{{.InfoMsg}}
{{end}}
- Website is still in the progress of building...please come back later! {{.SignedUserName}} is logged! +
    + {{range .Feeds}} +
  • + +
    {{TimeSince .Created}}
    {{ActionDesc . | str2html}}
    + +
  • + {{else}} +
  • Not any activity yet.
  • + {{end}} +
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index fd4313efd..f2bb984b3 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -39,12 +39,12 @@ {{else}} -
  • Not found any activity
  • +
  • Not any public activity yet.
  • {{end}}
    {{else}} -
    repo
    +
    repo
    {{end}}
    From e9fdf1031da4bf3c1acff0377b1d125ad99274e6 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 15 Mar 2014 05:53:13 -0400 Subject: [PATCH 2/2] Clean code --- models/repo2.go | 4 ++++ templates/repo/created.tmpl | 8 -------- web.go | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 templates/repo/created.tmpl diff --git a/models/repo2.go b/models/repo2.go index ef0131d83..6aa6eda60 100644 --- a/models/repo2.go +++ b/models/repo2.go @@ -1,3 +1,7 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + package models import ( diff --git a/templates/repo/created.tmpl b/templates/repo/created.tmpl deleted file mode 100644 index 35803e393..000000000 --- a/templates/repo/created.tmpl +++ /dev/null @@ -1,8 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
    -
    - Created successfully! -
    -
    -{{template "base/footer" .}} \ No newline at end of file diff --git a/web.go b/web.go index cb6ee4aec..24f01d68a 100644 --- a/web.go +++ b/web.go @@ -62,7 +62,7 @@ func runWeb(*cli.Context) { m.Use(sessions.Sessions("my_session", store)) // Routers. - m.Get("/", auth.SignInRequire(false), routers.Home) + m.Get("/", auth.SignInRequire(true), routers.Home) m.Any("/user/login", auth.SignOutRequire(), binding.BindIgnErr(auth.LogInForm{}), user.SignIn) m.Any("/user/logout", auth.SignInRequire(true), user.SignOut) m.Any("/user/sign_up", auth.SignOutRequire(), binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)