Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix followers and following tabs in profile (#10202) #10203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,7 @@ func RegisterRoutes(m *macaron.Macaron) {
// ***** END: Admin *****

m.Group("", func() {
m.Group("/:username", func() {
m.Get("", user.Profile)
m.Get("/followers", user.Followers)
m.Get("/following", user.Following)
})

m.Get("/:username", user.Profile)
m.Get("/attachments/:uuid", repo.GetAttachment)
}, ignSignIn)

Expand Down
50 changes: 18 additions & 32 deletions routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ import (
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/org"
"code.gitea.io/gitea/routers/repo"
)

const (
tplFollowers base.TplName = "user/meta/followers"
)

// GetUserByName get user by name
Expand Down Expand Up @@ -164,6 +158,24 @@ func Profile(ctx *context.Context) {
keyword := strings.Trim(ctx.Query("q"), " ")
ctx.Data["Keyword"] = keyword
switch tab {
case "followers":
items, err := ctxUser.GetFollowers(page)
if err != nil {
ctx.ServerError("GetFollowers", err)
return
}
ctx.Data["Cards"] = items

total = ctxUser.NumFollowers
case "following":
items, err := ctxUser.GetFollowing(page)
if err != nil {
ctx.ServerError("GetFollowing", err)
return
}
ctx.Data["Cards"] = items

total = ctxUser.NumFollowing
case "activity":
retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
RequestingUserID: requestingUserID,
Expand Down Expand Up @@ -229,32 +241,6 @@ func Profile(ctx *context.Context) {
ctx.HTML(200, tplProfile)
}

// Followers render user's followers page
func Followers(ctx *context.Context) {
u := GetUserByParams(ctx)
if ctx.Written() {
return
}
ctx.Data["Title"] = u.DisplayName()
ctx.Data["CardsTitle"] = ctx.Tr("user.followers")
ctx.Data["PageIsFollowers"] = true
ctx.Data["Owner"] = u
repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, tplFollowers)
}

// Following render user's followering page
func Following(ctx *context.Context) {
u := GetUserByParams(ctx)
if ctx.Written() {
return
}
ctx.Data["Title"] = u.DisplayName()
ctx.Data["CardsTitle"] = ctx.Tr("user.following")
ctx.Data["PageIsFollowing"] = true
ctx.Data["Owner"] = u
repo.RenderUserCards(ctx, u.NumFollowing, u.GetFollowing, tplFollowers)
}

// Action response for follow/unfollow user request
func Action(ctx *context.Context) {
u := GetUserByParams(ctx)
Expand Down
2 changes: 2 additions & 0 deletions templates/repo/user_cards.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="ui container user-cards">
{{if .CardsTitle}}
<h2 class="ui dividing header">
{{.CardsTitle}}
</h2>
{{end}}
<ul class="list">
{{range .Cards}}
<li class="item ui segment">
Expand Down
6 changes: 0 additions & 6 deletions templates/user/meta/followers.tmpl

This file was deleted.

24 changes: 0 additions & 24 deletions templates/user/meta/header.tmpl

This file was deleted.

33 changes: 14 additions & 19 deletions templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,6 @@
{{end}}
{{end}}
<li><i class="octicon octicon-clock"></i> {{.i18n.Tr "user.join_on"}} {{.Owner.CreatedUnix.FormatShort}}</li>
<li>
<i class="octicon octicon-person"></i>
<a href="{{.Owner.HomeLink}}/followers">
{{.Owner.NumFollowers}} {{.i18n.Tr "user.followers"}}
</a>
-
<a href="{{.Owner.HomeLink}}/following">
{{.Owner.NumFollowing}} {{.i18n.Tr "user.following"}}
</a>
</li>
{{/*
<li>
<i class="octicon octicon-star"></i>
<a href="{{.Owner.HomeLink}}/stars">
{{.Owner.NumStars}} {{.i18n.Tr "user.starred"}}
</a>
</li>
*/}}
{{if and .Orgs .HasOrgsVisible}}
<li>
<ul class="user-orgs">
Expand Down Expand Up @@ -95,14 +77,23 @@
</div>
<div class="ui eleven wide column">
<div class="ui secondary stackable pointing menu">
<a class='{{if and (ne .TabName "activity") (ne .TabName "stars")}}active{{end}} item' href="{{.Owner.HomeLink}}">
<a class='{{if and (ne .TabName "activity") (ne .TabName "following") (ne .TabName "followers") (ne .TabName "stars")}}active{{end}} item' href="{{.Owner.HomeLink}}">
<i class="octicon octicon-repo"></i> {{.i18n.Tr "user.repositories"}}
</a>
<a class='{{if eq .TabName "activity"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=activity">
<i class="octicon octicon-rss"></i> {{.i18n.Tr "user.activity"}}
</a>
<a class='{{if eq .TabName "stars"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=stars">
<i class="octicon octicon-star"></i> {{.i18n.Tr "user.starred"}}
<div class="ui label">{{.Owner.NumStars}}</div>
</a>
<a class='{{if eq .TabName "following"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=following">
<i class="octicon octicon-person"></i> {{.i18n.Tr "user.following"}}
<div class="ui label">{{.Owner.NumFollowing}}</div>
</a>
<a class='{{if eq .TabName "followers"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=followers">
<i class="octicon octicon-person"></i> {{.i18n.Tr "user.followers"}}
<div class="ui label">{{.Owner.NumFollowers}}</div>
</a>
</div>

Expand All @@ -126,6 +117,10 @@
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
{{else if eq .TabName "following"}}
{{template "repo/user_cards" .}}
{{else if eq .TabName "followers"}}
{{template "repo/user_cards" .}}
{{else}}
{{template "explore/repo_search" .}}
{{template "explore/repo_list" .}}
Expand Down