Browse Source

#981

add tag in org index
tags/v1.21.12.2^2
chenyifan01 4 years ago
parent
commit
74c9595aac
2 changed files with 55 additions and 1 deletions
  1. +47
    -1
      models/repo_tag.go
  2. +8
    -0
      routers/org/home.go

+ 47
- 1
models/repo_tag.go View File

@@ -36,6 +36,24 @@ type TagReposSelected struct {
Selected bool
}

type TagsDetail struct {
TagId int64
TagName string
RepoList []RepositoryForTag
}

type RepositoryForTag struct {
TagId int64
TagName string
ID int64
Name string
Description string
NumWatches int
NumStars int
NumForks int
Topics []string
}

func GetTagByID(id int64) (*OfficialTag, error) {
r := &OfficialTag{
ID: id,
@@ -84,7 +102,6 @@ func UpdateTagReposByID(tagID, orgID int64, repoIdList []int64) error {
}

func GetTagRepos(tagID, orgID int64) ([]TagReposSelected, error) {

t := make([]TagReposBrief, 0)
const SQLCmd = "select t1.id as repo_id,t1.name as repo_name,t2.id as tag_id from repository t1 left join official_tag_repos t2 on (t1.id = t2.repo_id and t2.tag_id = ?) where t1.owner_id = ? and t1.is_private = false"

@@ -105,3 +122,32 @@ func GetTagRepos(tagID, orgID int64) ([]TagReposSelected, error) {
}
return r, nil
}

func GetTagsDetails(orgID int64) ([]TagsDetail, error) {
t := make([]RepositoryForTag, 0)
const SQLCmd = "select t1.tag_id ,t3.name as tag_name,t2.* from official_tag_repos t1 inner join repository t2 on t1.repo_id = t2.id inner join official_tag t3 on t1.tag_id = t3.id where t1.org_id = ?"

if err := x.SQL(SQLCmd, orgID).Find(&t); err != nil {
return nil, err
}
r := make([]TagsDetail, 0)
tempMap := make(map[int64]TagsDetail, 0)
for _, v := range t {
tagId := v.TagId
detail, ok := tempMap[tagId]
if !ok {
detail = TagsDetail{
TagId: v.TagId,
TagName: v.TagName,
RepoList: make([]RepositoryForTag, 0),
}
}
detail.RepoList = append(detail.RepoList, v)
tempMap[tagId] = detail
}

for _, v := range tempMap {
r = append(r, v)
}
return r, nil
}

+ 8
- 0
routers/org/home.go View File

@@ -130,5 +130,13 @@ func Home(ctx *context.Context) {
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager

//find org tag info
tags, err := models.GetTagsDetails(org.ID)
if err != nil {
ctx.ServerError("GetTagsDetails", err)
return
}

ctx.Data["tags"] = tags
ctx.HTML(200, tplOrgHome)
}

Loading…
Cancel
Save