Browse Source

#1253 : filter user repositories by label

pull/5260/head
isundil 7 years ago
parent
commit
d616e453e3
  1. 4
      cmd/web.go
  2. 19
      models/repo.go
  3. 9
      routes/user/profile.go
  4. 4
      templates/explore/repo_list.tmpl
  5. 2
      templates/repo/header.tmpl

4
cmd/web.go

@ -304,6 +304,10 @@ func runWeb(c *cli.Context) error {
m.Get("/stars", user.Stars)
})
m.Group("/:username/labels", func() {
m.Get("/:labelID", user.Profile)
})
m.Get("/attachments/:uuid", func(c *context.Context) {
attach, err := models.GetAttachmentByUUID(c.Params(":uuid"))
if err != nil {

19
models/repo.go

@ -1595,6 +1595,7 @@ func GetRepositoryByID(id int64) (*Repository, error) {
type UserRepoOptions struct {
UserID int64
Private bool
LabelID int64
Page int
PageSize int
}
@ -1605,6 +1606,9 @@ func GetUserRepositories(opts *UserRepoOptions) ([]*Repository, error) {
if !opts.Private {
sess.And("is_private=?", false)
}
if opts.LabelID != 0 {
sess.Join("INNER", "repository_repo_label", "repository_repo_label.repository_id=repository.id AND repository_repo_label.label_id=?", opts.LabelID)
}
if opts.Page <= 0 {
opts.Page = 1
@ -1665,10 +1669,16 @@ func (l *RepositoryLabel) ForegroundColor() template.CSS {
return template.CSS("#000")
}
func CreateRepositoryLabel(owner *User, opts *CreateRepoLabelOptions) (_ *RepositoryLabel, err error) {
if !owner.CanCreateRepo() {
return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()}
func (l *RepositoryLabel) GetOwner() *User {
if l.Owner == nil {
if owner, err := GetUserByID(l.OwnerID); err == nil {
l.Owner = owner
}
}
return l.Owner
}
func CreateRepositoryLabel(owner *User, opts *CreateRepoLabelOptions) (_ *RepositoryLabel, err error) {
if !labelColorPattern.MatchString(opts.Color) {
return nil, fmt.Errorf("bad HTML color code %s", opts.Color)
}
@ -1695,9 +1705,6 @@ func CreateRepositoryLabel(owner *User, opts *CreateRepoLabelOptions) (_ *Reposi
}
func UpdateRepositoryLabel(id int64, owner *User, opts *CreateRepoLabelOptions) (_ *RepositoryLabel, err error) {
if !owner.CanCreateRepo() {
return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()}
}
if !labelColorPattern.MatchString(opts.Color) {
return nil, fmt.Errorf("bad HTML color code %s", opts.Color)
}

9
routes/user/profile.go

@ -95,11 +95,20 @@ func Profile(c *context.Context) {
page = 1
}
labelID := c.ParamsInt64(":labelID")
showPrivate := c.IsLogged && (ctxUser.ID == c.User.ID || c.User.IsAdmin)
if labelID != 0 {
label, err := models.GetRepositoryLabelById(labelID)
if err != nil || (label.IsPrivate && !showPrivate) {
c.NotFound()
return
}
}
repositories, err := models.GetUserRepositories(&models.UserRepoOptions{
UserID: ctxUser.ID,
Private: showPrivate,
Page: page,
LabelID: labelID,
PageSize: setting.UI.User.RepoPagingNum,
})
if err != nil {

4
templates/explore/repo_list.tmpl

@ -17,8 +17,8 @@
</div>
</div>
<div class="ui labels">
{{range index $.LabelsByRepoId .ID}}
<a class="ui label" style="background-color:{{.Color}};color:{{.ForegroundColor}}" href="{{AppSubURL}}/{{$.Owner.Name}}/labels/{{.ID}}">{{.Name}}</a>
{{$currentOwner:=.Owner}}{{range index $.LabelsByRepoId .ID}}
<a class="ui label" style="background-color:{{.Color}};color:{{.ForegroundColor}}" href="{{AppSubURL}}/{{if $currentOwner}}{{$currentOwner.Name}}{{else if $.Org}}{{$.Org.Name}}{{else}}{{$.Owner.Name}}{{end}}/labels/{{.ID}}">{{.Name}}</a>
{{end}}
</div>
{{if .Description}}<p class="has-emoji">{{.Description | Str2html}}</p>{{end}}

2
templates/repo/header.tmpl

@ -46,7 +46,7 @@
</div>
<div class="label-list">
{{range $.RepositoryLabels}}
<div class="ui label" style="background-color:{{.Color}}; color:{{.ForegroundColor}}">{{.Name}}</div>
<a class="ui label" style="background-color:{{.Color}}; color:{{.ForegroundColor}}" href="{{AppSubURL}}/{{.GetOwner.Name}}/labels/{{.ID}}">{{.Name}}</a>
{{end}}
</div>
</div><!-- end column -->

Loading…
Cancel
Save