Show collaborative repositories in dashboard

This commit is contained in:
Unknown 2014-05-12 15:14:22 -04:00
parent 54e95fa367
commit a913aff1d0
3 changed files with 53 additions and 3 deletions

View file

@ -721,7 +721,7 @@ func GetRepositoryById(id int64) (*Repository, error) {
return repo, nil
}
// GetRepositories returns the list of repositories of given user.
// GetRepositories returns a list of repositories of given user.
func GetRepositories(user *User, private bool) ([]*Repository, error) {
repos := make([]*Repository, 0, 10)
sess := orm.Desc("updated")
@ -758,6 +758,36 @@ func GetCollaboratorNames(repoName string) ([]string, error) {
return names, nil
}
// GetCollaborativeRepos returns a list of repositories that user is collaborator.
func GetCollaborativeRepos(uname string) ([]*Repository, error) {
uname = strings.ToLower(uname)
accesses := make([]*Access, 0, 10)
if err := orm.Find(&accesses, &Access{UserName: uname}); err != nil {
return nil, err
}
repos := make([]*Repository, 0, 10)
for _, access := range accesses {
if strings.HasPrefix(access.RepoName, uname) {
continue
}
infos := strings.Split(access.RepoName, "/")
u, err := GetUserByName(infos[0])
if err != nil {
return nil, err
}
repo, err := GetRepositoryByName(u.Id, infos[1])
if err != nil {
return nil, err
}
repo.Owner = u
repos = append(repos, repo)
}
return repos, nil
}
// GetCollaborators returns a list of users of repository's collaborators.
func GetCollaborators(repoName string) (us []*User, err error) {
accesses := make([]*Access, 0, 10)

View file

@ -22,14 +22,21 @@ func Dashboard(ctx *middleware.Context) {
ctx.Data["PageIsUserDashboard"] = true
repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id}, true)
if err != nil {
ctx.Handle(500, "user.Dashboard", err)
ctx.Handle(500, "home.Dashboard(GetRepositories)", err)
return
}
ctx.Data["MyRepos"] = repos
collaRepos, err := models.GetCollaborativeRepos(ctx.User.Name)
if err != nil {
ctx.Handle(500, "home.Dashboard(GetCollaborativeRepos)", err)
return
}
ctx.Data["CollaborativeRepos"] = collaRepos
actions, err := models.GetFeeds(ctx.User.Id, 0, false)
if err != nil {
ctx.Handle(500, "user.Dashboard", err)
ctx.Handle(500, "home.Dashboard", err)
return
}

View file

@ -40,6 +40,7 @@
</div>
</div>
</div>
<div class="panel-body">
<ul class="list-group">{{range .MyRepos}}
<li class="list-group-item"><a href="/{{$.SignedUserName}}/{{.Name}}">
@ -49,6 +50,18 @@
</ul>
</div>
</div>
<div class="panel panel-default repo-panel">
<div class="panel-heading">Collaborative Repositories</div>
<div class="panel-body">
<ul class="list-group">{{range .CollaborativeRepos}}
<li class="list-group-item"><a href="/{{.Owner.Name}}/{{.Name}}">
<!-- <span class="stars pull-right"><i class="fa fa-star"></i>{{.NumStars}}</span> -->
<i class="fa fa-book"></i>{{.Name}}{{if .IsPrivate}} <span class="label label-default">Private</span>{{end}}</a>
</li>{{end}}
</ul>
</div>
</div>
</div>
</div>
{{template "base/footer" .}}