@@ -65,6 +65,7 @@ const (
6565 tplRepoHome base.TplName = "repo/home"
6666 tplRepoViewList base.TplName = "repo/view_list"
6767 tplWatchers base.TplName = "repo/watchers"
68+ tplCards base.TplName = "repo/user_cards"
6869 tplForks base.TplName = "repo/forks"
6970 tplMigrating base.TplName = "repo/migrate/migrating"
7071)
@@ -1122,25 +1123,42 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOp
11221123 ctx .HTML (http .StatusOK , tpl )
11231124}
11241125
1126+ func renderUserList (ctx * context.Context , pageType string , total int , getter func (opts db.ListOptions ) ([]* user_model.User , error ), tpl base.TplName ) {
1127+ ctx .Data ["Title" ] = ctx .Tr (pageType )
1128+ ctx .Data ["CardsTitle" ] = ctx .Tr (pageType )
1129+ RenderUserCards (ctx , total , getter , tpl )
1130+ }
1131+
11251132// Watchers render repository's watch users
11261133func Watchers (ctx * context.Context ) {
1127- ctx .Data ["Title" ] = ctx .Tr ("repo.watchers" )
1128- ctx .Data ["CardsTitle" ] = ctx .Tr ("repo.watchers" )
1129- ctx .Data ["PageIsWatchers" ] = true
1134+ renderUserList (ctx , "repo.watchers" , ctx .Repo .Repository .NumWatches ,
1135+ func (opts db.ListOptions ) ([]* user_model.User , error ) {
1136+ return repo_model .GetRepoWatchers (ctx , ctx .Repo .Repository .ID , opts )
1137+ }, tplWatchers )
1138+ }
11301139
1131- RenderUserCards (ctx , ctx .Repo .Repository .NumWatches , func (opts db.ListOptions ) ([]* user_model.User , error ) {
1132- return repo_model .GetRepoWatchers (ctx , ctx .Repo .Repository .ID , opts )
1133- }, tplWatchers )
1140+ // WatchersCards renders a repository's watchers user cards
1141+ func WatchersCards (ctx * context.Context ) {
1142+ renderUserList (ctx , "repo.watchers" , ctx .Repo .Repository .NumWatches ,
1143+ func (opts db.ListOptions ) ([]* user_model.User , error ) {
1144+ return repo_model .GetRepoWatchers (ctx , ctx .Repo .Repository .ID , opts )
1145+ }, tplCards )
11341146}
11351147
11361148// Stars render repository's starred users
11371149func Stars (ctx * context.Context ) {
1138- ctx .Data ["Title" ] = ctx .Tr ("repo.stargazers" )
1139- ctx .Data ["CardsTitle" ] = ctx .Tr ("repo.stargazers" )
1140- ctx .Data ["PageIsStargazers" ] = true
1141- RenderUserCards (ctx , ctx .Repo .Repository .NumStars , func (opts db.ListOptions ) ([]* user_model.User , error ) {
1142- return repo_model .GetStargazers (ctx , ctx .Repo .Repository , opts )
1143- }, tplWatchers )
1150+ renderUserList (ctx , "repo.stargazers" , ctx .Repo .Repository .NumStars ,
1151+ func (opts db.ListOptions ) ([]* user_model.User , error ) {
1152+ return repo_model .GetStargazers (ctx , ctx .Repo .Repository , opts )
1153+ }, tplWatchers )
1154+ }
1155+
1156+ // StarsCards renders a repository's stargazers user cards
1157+ func StarsCards (ctx * context.Context ) {
1158+ renderUserList (ctx , "repo.stargazers" , ctx .Repo .Repository .NumStars ,
1159+ func (opts db.ListOptions ) ([]* user_model.User , error ) {
1160+ return repo_model .GetStargazers (ctx , ctx .Repo .Repository , opts )
1161+ }, tplCards )
11441162}
11451163
11461164// Forks render repository's forked users
0 commit comments