mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-02 22:01:44 +02:00
Add topic support (#3711)
* add topic models and unit tests * fix comments * fix comment * add the UI to show or add topics for a repo * show topics on repositories list * fix test * don't show manage topics link when no permission * use green basic as topic label * fix topic label color * remove trace content * remove debug function
This commit is contained in:
1 parent
1946ce2954
commit
bec69f702b
17 files changed
+487
-2
No files matched your search
@@ -0,0 +1,11 @@
|
|||||||
|
-
|
||||||
|
repo_id: 1
|
||||||
|
topic_id: 1
|
||||||
|
|
||||||
|
-
|
||||||
|
repo_id: 1
|
||||||
|
topic_id: 2
|
||||||
|
|
||||||
|
-
|
||||||
|
repo_id: 1
|
||||||
|
topic_id: 3
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
name: golang
|
||||||
|
repo_count: 1
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 2
|
||||||
|
name: database
|
||||||
|
repo_count: 1
|
||||||
|
|
||||||
|
- id: 3
|
||||||
|
name: SQL
|
||||||
|
repo_count: 1
|
||||||
@@ -199,6 +199,7 @@ type Repository struct {
|
|||||||
Size int64 `xorm:"NOT NULL DEFAULT 0"`
|
Size int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||||
IndexerStatus *RepoIndexerStatus `xorm:"-"`
|
IndexerStatus *RepoIndexerStatus `xorm:"-"`
|
||||||
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
|
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
|
||||||
|
Topics []string `xorm:"TEXT JSON"`
|
||||||
|
|
||||||
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||||
|
|||||||
+192
@@ -0,0 +1,192 @@
|
|||||||
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
|
"github.com/go-xorm/builder"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
tables = append(tables,
|
||||||
|
new(Topic),
|
||||||
|
new(RepoTopic),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Topic represents a topic of repositories
|
||||||
|
type Topic struct {
|
||||||
|
ID int64
|
||||||
|
Name string `xorm:"unique"`
|
||||||
|
RepoCount int
|
||||||
|
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||||
|
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RepoTopic represents associated repositories and topics
|
||||||
|
type RepoTopic struct {
|
||||||
|
RepoID int64 `xorm:"unique(s)"`
|
||||||
|
TopicID int64 `xorm:"unique(s)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTopicNotExist represents an error that a topic is not exist
|
||||||
|
type ErrTopicNotExist struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrTopicNotExist checks if an error is an ErrTopicNotExist.
|
||||||
|
func IsErrTopicNotExist(err error) bool {
|
||||||
|
_, ok := err.(ErrTopicNotExist)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements error interface
|
||||||
|
func (err ErrTopicNotExist) Error() string {
|
||||||
|
return fmt.Sprintf("topic is not exist [name: %s]", err.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTopicByName retrieves topic by name
|
||||||
|
func GetTopicByName(name string) (*Topic, error) {
|
||||||
|
var topic Topic
|
||||||
|
if has, err := x.Where("name = ?", name).Get(&topic); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if !has {
|
||||||
|
return nil, ErrTopicNotExist{name}
|
||||||
|
}
|
||||||
|
return &topic, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTopicOptions represents the options when fdin topics
|
||||||
|
type FindTopicOptions struct {
|
||||||
|
RepoID int64
|
||||||
|
Keyword string
|
||||||
|
Limit int
|
||||||
|
Page int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (opts *FindTopicOptions) toConds() builder.Cond {
|
||||||
|
var cond = builder.NewCond()
|
||||||
|
if opts.RepoID > 0 {
|
||||||
|
cond = cond.And(builder.Eq{"repo_topic.repo_id": opts.RepoID})
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Keyword != "" {
|
||||||
|
cond = cond.And(builder.Like{"topic.name", opts.Keyword})
|
||||||
|
}
|
||||||
|
|
||||||
|
return cond
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTopics retrieves the topics via FindTopicOptions
|
||||||
|
func FindTopics(opts *FindTopicOptions) (topics []*Topic, err error) {
|
||||||
|
sess := x.Select("topic.*").Where(opts.toConds())
|
||||||
|
if opts.RepoID > 0 {
|
||||||
|
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
|
||||||
|
}
|
||||||
|
if opts.Limit > 0 {
|
||||||
|
sess.Limit(opts.Limit, opts.Page*opts.Limit)
|
||||||
|
}
|
||||||
|
return topics, sess.Desc("topic.repo_count").Find(&topics)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveTopics save topics to a repository
|
||||||
|
func SaveTopics(repoID int64, topicNames ...string) error {
|
||||||
|
topics, err := FindTopics(&FindTopicOptions{
|
||||||
|
RepoID: repoID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sess := x.NewSession()
|
||||||
|
defer sess.Close()
|
||||||
|
|
||||||
|
if err := sess.Begin(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var addedTopicNames []string
|
||||||
|
for _, topicName := range topicNames {
|
||||||
|
if strings.TrimSpace(topicName) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var found bool
|
||||||
|
for _, t := range topics {
|
||||||
|
if strings.EqualFold(topicName, t.Name) {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
addedTopicNames = append(addedTopicNames, topicName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var removeTopics []*Topic
|
||||||
|
for _, t := range topics {
|
||||||
|
var found bool
|
||||||
|
for _, topicName := range topicNames {
|
||||||
|
if strings.EqualFold(topicName, t.Name) {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
removeTopics = append(removeTopics, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, topicName := range addedTopicNames {
|
||||||
|
var topic Topic
|
||||||
|
if has, err := sess.Where("name = ?", topicName).Get(&topic); err != nil {
|
||||||
|
return err
|
||||||
|
} else if !has {
|
||||||
|
topic.Name = topicName
|
||||||
|
topic.RepoCount = 1
|
||||||
|
if _, err := sess.Insert(&topic); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
topic.RepoCount++
|
||||||
|
if _, err := sess.ID(topic.ID).Cols("repo_count").Update(&topic); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := sess.Insert(&RepoTopic{
|
||||||
|
RepoID: repoID,
|
||||||
|
TopicID: topic.ID,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, topic := range removeTopics {
|
||||||
|
topic.RepoCount--
|
||||||
|
if _, err := sess.ID(topic.ID).Cols("repo_count").Update(topic); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := sess.Delete(&RepoTopic{
|
||||||
|
RepoID: repoID,
|
||||||
|
TopicID: topic.ID,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := sess.ID(repoID).Cols("topics").Update(&Repository{
|
||||||
|
Topics: topicNames,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sess.Commit()
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAddTopic(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
|
||||||
|
topics, err := FindTopics(&FindTopicOptions{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 3, len(topics))
|
||||||
|
|
||||||
|
topics, err = FindTopics(&FindTopicOptions{
|
||||||
|
Limit: 2,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 2, len(topics))
|
||||||
|
|
||||||
|
topics, err = FindTopics(&FindTopicOptions{
|
||||||
|
RepoID: 1,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 3, len(topics))
|
||||||
|
|
||||||
|
assert.NoError(t, SaveTopics(2, "golang"))
|
||||||
|
topics, err = FindTopics(&FindTopicOptions{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 3, len(topics))
|
||||||
|
|
||||||
|
topics, err = FindTopics(&FindTopicOptions{
|
||||||
|
RepoID: 2,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 1, len(topics))
|
||||||
|
|
||||||
|
assert.NoError(t, SaveTopics(2, "golang", "gitea"))
|
||||||
|
topic, err := GetTopicByName("gitea")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 1, topic.RepoCount)
|
||||||
|
|
||||||
|
topics, err = FindTopics(&FindTopicOptions{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 4, len(topics))
|
||||||
|
|
||||||
|
topics, err = FindTopics(&FindTopicOptions{
|
||||||
|
RepoID: 2,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 2, len(topics))
|
||||||
|
}
|
||||||
@@ -516,3 +516,8 @@ type AddTimeManuallyForm struct {
|
|||||||
func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||||||
return validate(errs, ctx.Data, f, ctx.Locale)
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SaveTopicForm form for save topics for repository
|
||||||
|
type SaveTopicForm struct {
|
||||||
|
Topics []string `binding:"topics;Required;"`
|
||||||
|
}
|
||||||
@@ -1114,6 +1114,9 @@ branch.restore_success = %s successfully restored
|
|||||||
branch.restore_failed = Failed to restore branch %s.
|
branch.restore_failed = Failed to restore branch %s.
|
||||||
branch.protected_deletion_failed = It's not possible to delete protected branch %s.
|
branch.protected_deletion_failed = It's not possible to delete protected branch %s.
|
||||||
|
|
||||||
|
topic.manage_topics = Manage Topics
|
||||||
|
topic.done = Done
|
||||||
|
|
||||||
[org]
|
[org]
|
||||||
org_name_holder = Organization Name
|
org_name_holder = Organization Name
|
||||||
org_full_name_holder = Organization Full Name
|
org_full_name_holder = Organization Full Name
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
.tribute-container{box-shadow:0 1px 3px 1px #c7c7c7}.tribute-container ul{background:#fff}.tribute-container li{padding:8px 12px;border-bottom:1px solid #dcdcdc}.tribute-container li img{display:inline-block;vertical-align:middle;width:28px;height:28px;margin-right:5px}.tribute-container li span.fullname{font-weight:400;font-size:.8rem;margin-left:3px}.tribute-container li.highlight,.tribute-container li:hover{background:#2185D0;color:#fff}.emoji{width:1.5em;height:1.5em;display:inline-block;background-size:contain}body{font-family:Lato,"Segoe UI","Microsoft YaHei",Arial,Helvetica,sans-serif!important;background-color:#fff;overflow-y:scroll;-webkit-font-smoothing:antialiased}img{border-radius:3px}.rounded{border-radius:.28571429rem!important}code,pre{font:12px Consolas,"Liberation Mono",Menlo,Courier,monospace}code.raw,pre.raw{padding:7px 12px;margin:10px 0;background-color:#f8f8f8;border:1px solid #ddd;border-radius:3px;font-size:13px;line-height:1.5;overflow:auto}code.wrap,pre.wrap{white-space:pre-wrap;-ms-word-break:break-all;word-break:break-all;overflow-wrap:break-word;word-wrap:break-word}.dont-break-out{overflow-wrap:break-word;word-wrap:break-word;-ms-word-break:break-all;word-break:break-all;-ms-hyphens:auto;-moz-hyphens:auto;-webkit-hyphens:auto;hyphens:auto}.full.height{padding:0;margin:0 0 -80px 0;min-height:100%}.following.bar{z-index:900;left:0;width:100%;margin:0}.following.bar.light{background-color:#fff;border-bottom:1px solid #DDD;box-shadow:0 2px 3px rgba(0,0,0,.04)}.following.bar .column .menu{margin-top:0}.following.bar .top.menu a.item.brand{padding-left:0}.following.bar .brand .ui.mini.image{width:30px}.following.bar .top.menu .dropdown.item.active,.following.bar .top.menu .dropdown.item:hover,.following.bar .top.menu a.item:hover{background-color:transparent}.following.bar .top.menu a.item:hover{color:rgba(0,0,0,.45)}.following.bar .top.menu .menu{z-index:900}.following.bar .octicon{margin-right:.75em}.following.bar .octicon.fitted{margin-right:0}.following.bar .searchbox{background-color:#f4f4f4!important}.following.bar .searchbox:focus{background-color:#e9e9e9!important}.following.bar .text .octicon{width:16px;text-align:center}@media only screen and (max-width:767px){.following.bar #navbar:not(.shown)>:not(:first-child){display:none}}.right.stackable.menu{margin-left:auto;display:flex;display:-ms-flexbox;-ms-flex-align:inherit;align-items:inherit;-ms-flex-direction:inherit;flex-direction:inherit}.ui.left{float:left}.ui.right{float:right}.ui.button,.ui.menu .item{-moz-user-select:auto;-ms-user-select:auto;-webkit-user-select:auto;user-select:auto}.ui.container.fluid.padded{padding:0 10px 0 10px}.ui.form .ui.button{font-weight:400}.ui.menu,.ui.segment,.ui.vertical.menu{box-shadow:none}.ui .menu:not(.vertical) .item>.button.compact{padding:.58928571em 1.125em}.ui .menu:not(.vertical) .item>.button.small{font-size:.92857143rem}.ui .text.red{color:#d95c5c!important}.ui .text.red a{color:#d95c5c!important}.ui .text.red a:hover{color:#E67777!important}.ui .text.blue{color:#428bca!important}.ui .text.blue a{color:#15c!important}.ui .text.blue a:hover{color:#428bca!important}.ui .text.black{color:#444}.ui .text.black:hover{color:#000}.ui .text.grey{color:#767676!important}.ui .text.grey a{color:#444!important}.ui .text.grey a:hover{color:#000!important}.ui .text.light.grey{color:#888!important}.ui .text.green{color:#6cc644!important}.ui .text.purple{color:#6e5494!important}.ui .text.yellow{color:#FBBD08!important}.ui .text.gold{color:#a1882b!important}.ui .text.left{text-align:left!important}.ui .text.right{text-align:right!important}.ui .text.small{font-size:.75em}.ui .text.normal{font-weight:400}.ui .text.bold{font-weight:700}.ui .text.italic{font-style:italic}.ui .text.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:inline-block}.ui .text.thin{font-weight:400}.ui .text.middle{vertical-align:middle}.ui .message{text-align:center}.ui .header>i+.content{padding-left:.75rem;vertical-align:middle}.ui .warning.header{background-color:#F9EDBE!important;border-color:#F0C36D}.ui .warning.segment{border-color:#F0C36D}.ui .info.segment{border:1px solid #c5d5dd}.ui .info.segment.top{background-color:#e6f1f6!important}.ui .info.segment.top h3,.ui .info.segment.top h4{margin-top:0}.ui .info.segment.top h3:last-child{margin-top:4px}.ui .info.segment.top>:last-child{margin-bottom:0}.ui .normal.header{font-weight:400}.ui .avatar.image{border-radius:3px}.ui .form .fake{display:none!important}.ui .form .sub.field{margin-left:25px}.ui .sha.label{font-family:Consolas,Menlo,Monaco,"Lucida Console",monospace;font-size:13px;padding:6px 10px 4px 10px;font-weight:400;margin:0 6px}.ui.status.buttons .octicon{margin-right:4px}.ui.inline.delete-button{padding:8px 15px;font-weight:400}.ui .background.red{background-color:#d95c5c!important}.ui .background.blue{background-color:#428bca!important}.ui .background.black{background-color:#444}.ui .background.grey{background-color:#767676!importLine truncated
|
.tribute-container{box-shadow:0 1px 3px 1px #c7c7c7}.tribute-container ul{background:#fff}.tribute-container li{padding:8px 12px;border-bottom:1px solid #dcdcdc}.tribute-container li img{display:inline-block;vertical-align:middle;width:28px;height:28px;margin-right:5px}.tribute-container li span.fullname{font-weight:400;font-size:.8rem;margin-left:3px}.tribute-container li.highlight,.tribute-container li:hover{background:#2185D0;color:#fff}.emoji{width:1.5em;height:1.5em;display:inline-block;background-size:contain}body{font-family:Lato,"Segoe UI","Microsoft YaHei",Arial,Helvetica,sans-serif!important;background-color:#fff;overflow-y:scroll;-webkit-font-smoothing:antialiased}img{border-radius:3px}.rounded{border-radius:.28571429rem!important}code,pre{font:12px Consolas,"Liberation Mono",Menlo,Courier,monospace}code.raw,pre.raw{padding:7px 12px;margin:10px 0;background-color:#f8f8f8;border:1px solid #ddd;border-radius:3px;font-size:13px;line-height:1.5;overflow:auto}code.wrap,pre.wrap{white-space:pre-wrap;-ms-word-break:break-all;word-break:break-all;overflow-wrap:break-word;word-wrap:break-word}.dont-break-out{overflow-wrap:break-word;word-wrap:break-word;-ms-word-break:break-all;word-break:break-all;-ms-hyphens:auto;-moz-hyphens:auto;-webkit-hyphens:auto;hyphens:auto}.full.height{padding:0;margin:0 0 -80px 0;min-height:100%}.following.bar{z-index:900;left:0;width:100%;margin:0}.following.bar.light{background-color:#fff;border-bottom:1px solid #DDD;box-shadow:0 2px 3px rgba(0,0,0,.04)}.following.bar .column .menu{margin-top:0}.following.bar .top.menu a.item.brand{padding-left:0}.following.bar .brand .ui.mini.image{width:30px}.following.bar .top.menu .dropdown.item.active,.following.bar .top.menu .dropdown.item:hover,.following.bar .top.menu a.item:hover{background-color:transparent}.following.bar .top.menu a.item:hover{color:rgba(0,0,0,.45)}.following.bar .top.menu .menu{z-index:900}.following.bar .octicon{margin-right:.75em}.following.bar .octicon.fitted{margin-right:0}.following.bar .searchbox{background-color:#f4f4f4!important}.following.bar .searchbox:focus{background-color:#e9e9e9!important}.following.bar .text .octicon{width:16px;text-align:center}@media only screen and (max-width:767px){.following.bar #navbar:not(.shown)>:not(:first-child){display:none}}.right.stackable.menu{margin-left:auto;display:flex;display:-ms-flexbox;-ms-flex-align:inherit;align-items:inherit;-ms-flex-direction:inherit;flex-direction:inherit}.ui.left{float:left}.ui.right{float:right}.ui.button,.ui.menu .item{-moz-user-select:auto;-ms-user-select:auto;-webkit-user-select:auto;user-select:auto}.ui.container.fluid.padded{padding:0 10px 0 10px}.ui.form .ui.button{font-weight:400}.ui.menu,.ui.segment,.ui.vertical.menu{box-shadow:none}.ui .menu:not(.vertical) .item>.button.compact{padding:.58928571em 1.125em}.ui .menu:not(.vertical) .item>.button.small{font-size:.92857143rem}.ui .text.red{color:#d95c5c!important}.ui .text.red a{color:#d95c5c!important}.ui .text.red a:hover{color:#E67777!important}.ui .text.blue{color:#428bca!important}.ui .text.blue a{color:#15c!important}.ui .text.blue a:hover{color:#428bca!important}.ui .text.black{color:#444}.ui .text.black:hover{color:#000}.ui .text.grey{color:#767676!important}.ui .text.grey a{color:#444!important}.ui .text.grey a:hover{color:#000!important}.ui .text.light.grey{color:#888!important}.ui .text.green{color:#6cc644!important}.ui .text.purple{color:#6e5494!important}.ui .text.yellow{color:#FBBD08!important}.ui .text.gold{color:#a1882b!important}.ui .text.left{text-align:left!important}.ui .text.right{text-align:right!important}.ui .text.small{font-size:.75em}.ui .text.normal{font-weight:400}.ui .text.bold{font-weight:700}.ui .text.italic{font-style:italic}.ui .text.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:inline-block}.ui .text.thin{font-weight:400}.ui .text.middle{vertical-align:middle}.ui .message{text-align:center}.ui .header>i+.content{padding-left:.75rem;vertical-align:middle}.ui .warning.header{background-color:#F9EDBE!important;border-color:#F0C36D}.ui .warning.segment{border-color:#F0C36D}.ui .info.segment{border:1px solid #c5d5dd}.ui .info.segment.top{background-color:#e6f1f6!important}.ui .info.segment.top h3,.ui .info.segment.top h4{margin-top:0}.ui .info.segment.top h3:last-child{margin-top:4px}.ui .info.segment.top>:last-child{margin-bottom:0}.ui .normal.header{font-weight:400}.ui .avatar.image{border-radius:3px}.ui .form .fake{display:none!important}.ui .form .sub.field{margin-left:25px}.ui .sha.label{font-family:Consolas,Menlo,Monaco,"Lucida Console",monospace;font-size:13px;padding:6px 10px 4px 10px;font-weight:400;margin:0 6px}.ui.status.buttons .octicon{margin-right:4px}.ui.inline.delete-button{padding:8px 15px;font-weight:400}.ui .background.red{background-color:#d95c5c!important}.ui .background.blue{background-color:#428bca!important}.ui .background.black{background-color:#444}.ui .background.grey{background-color:#767676!importLine truncated
|
||||||
@@ -1591,6 +1591,7 @@ $(document).ready(function () {
|
|||||||
initTeamSettings();
|
initTeamSettings();
|
||||||
initCtrlEnterSubmit();
|
initCtrlEnterSubmit();
|
||||||
initNavbarContentToggle();
|
initNavbarContentToggle();
|
||||||
|
initTopicbar();
|
||||||
|
|
||||||
// Repo clone url.
|
// Repo clone url.
|
||||||
if ($('#repo-clone-url').length > 0) {
|
if ($('#repo-clone-url').length > 0) {
|
||||||
@@ -2122,3 +2123,74 @@ function initNavbarContentToggle() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initTopicbar() {
|
||||||
|
var mgrBtn = $("#manage_topic")
|
||||||
|
var editDiv = $("#topic_edit")
|
||||||
|
var viewDiv = $("#repo-topic")
|
||||||
|
var saveBtn = $("#save_topic")
|
||||||
|
|
||||||
|
mgrBtn.click(function() {
|
||||||
|
viewDiv.hide();
|
||||||
|
editDiv.show();
|
||||||
|
})
|
||||||
|
|
||||||
|
saveBtn.click(function() {
|
||||||
|
var topics = $("input[name=topics]").val();
|
||||||
|
|
||||||
|
$.post($(this).data('link'), {
|
||||||
|
"_csrf": csrf,
|
||||||
|
"topics": topics
|
||||||
|
}).success(function(res){
|
||||||
|
if (res["status"] != "ok") {
|
||||||
|
alert(res.message);
|
||||||
|
} else {
|
||||||
|
viewDiv.children(".topic").remove();
|
||||||
|
var topicArray = topics.split(",");
|
||||||
|
var last = viewDiv.children("a").last();
|
||||||
|
for (var i=0;i < topicArray.length; i++) {
|
||||||
|
$('<div class="ui green basic label topic" style="cursor:pointer;">'+topicArray[i]+'</div>').insertBefore(last)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).done(function() {
|
||||||
|
editDiv.hide();
|
||||||
|
viewDiv.show();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#topic_edit .dropdown').dropdown({
|
||||||
|
allowAdditions: true,
|
||||||
|
fields: { name: "description", value: "data-value" },
|
||||||
|
saveRemoteData: false,
|
||||||
|
label: {
|
||||||
|
transition : 'horizontal flip',
|
||||||
|
duration : 200,
|
||||||
|
variation : false,
|
||||||
|
blue : true,
|
||||||
|
basic: true,
|
||||||
|
},
|
||||||
|
className: {
|
||||||
|
label: 'ui green basic label'
|
||||||
|
},
|
||||||
|
apiSettings: {
|
||||||
|
url: suburl + '/api/v1/topics/search?q={query}',
|
||||||
|
throttle: 500,
|
||||||
|
cache: false,
|
||||||
|
onResponse: function(res) {
|
||||||
|
var formattedResponse = {
|
||||||
|
success: false,
|
||||||
|
results: new Array(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (res.topics) {
|
||||||
|
formattedResponse.success = true;
|
||||||
|
for (var i=0;i < res.topics.length;i++) {
|
||||||
|
formattedResponse.results.push({"description": res.topics[i].Name, "data-value":res.topics[i].Name})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedResponse;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1733,3 +1733,12 @@ tbody.commit-list {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#topic_edit {
|
||||||
|
margin-top:5px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#repo-topic {
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
@@ -571,5 +571,9 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}, reqAdmin())
|
}, reqAdmin())
|
||||||
|
|
||||||
|
m.Group("/topics", func() {
|
||||||
|
m.Get("/search", repo.TopicSearch)
|
||||||
|
})
|
||||||
}, context.APIContexter())
|
}, context.APIContexter())
|
||||||
}
|
}
|
||||||
@@ -501,3 +501,45 @@ func MirrorSync(ctx *context.APIContext) {
|
|||||||
go models.MirrorQueue.Add(repo.ID)
|
go models.MirrorQueue.Add(repo.ID)
|
||||||
ctx.Status(200)
|
ctx.Status(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TopicSearch search for creating topic
|
||||||
|
func TopicSearch(ctx *context.Context) {
|
||||||
|
// swagger:operation GET /topics/search repository topicSearch
|
||||||
|
// ---
|
||||||
|
// summary: search topics via keyword
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// parameters:
|
||||||
|
// - name: keyword
|
||||||
|
// in: path
|
||||||
|
// description: id of the repo to get
|
||||||
|
// type: integer
|
||||||
|
// required: true
|
||||||
|
// responses:
|
||||||
|
// "200":
|
||||||
|
// "$ref": "#/responses/Repository"
|
||||||
|
if ctx.User == nil {
|
||||||
|
ctx.JSON(403, map[string]interface{}{
|
||||||
|
"message": "Only owners could change the topics.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
kw := ctx.Query("q")
|
||||||
|
|
||||||
|
topics, err := models.FindTopics(&models.FindTopicOptions{
|
||||||
|
Keyword: kw,
|
||||||
|
Limit: 10,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Error(2, "SearchTopics failed: %v", err)
|
||||||
|
ctx.JSON(500, map[string]interface{}{
|
||||||
|
"message": "Search topics failed.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(200, map[string]interface{}{
|
||||||
|
"topics": topics,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TopicPost response for creating repository
|
||||||
|
func TopicPost(ctx *context.Context) {
|
||||||
|
if ctx.User == nil {
|
||||||
|
ctx.JSON(403, map[string]interface{}{
|
||||||
|
"message": "Only owners could change the topics.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
topics := strings.Split(ctx.Query("topics"), ",")
|
||||||
|
|
||||||
|
err := models.SaveTopics(ctx.Repo.Repository.ID, topics...)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(2, "SaveTopics failed: %v", err)
|
||||||
|
ctx.JSON(500, map[string]interface{}{
|
||||||
|
"message": "Save topics failed.",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(200, map[string]interface{}{
|
||||||
|
"status": "ok",
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -314,6 +314,16 @@ func renderCode(ctx *context.Context) {
|
|||||||
treeLink += "/" + ctx.Repo.TreePath
|
treeLink += "/" + ctx.Repo.TreePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Topics of this repo
|
||||||
|
topics, err := models.FindTopics(&models.FindTopicOptions{
|
||||||
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("models.FindTopics", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Data["Topics"] = topics
|
||||||
|
|
||||||
// Get current entry user currently looking at.
|
// Get current entry user currently looking at.
|
||||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -587,6 +587,10 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||||||
})
|
})
|
||||||
}, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeReleases))
|
}, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeReleases))
|
||||||
|
|
||||||
|
m.Group("/:username/:reponame", func() {
|
||||||
|
m.Post("/topics", repo.TopicPost)
|
||||||
|
}, context.RepoAssignment(), reqRepoAdmin)
|
||||||
|
|
||||||
m.Group("/:username/:reponame", func() {
|
m.Group("/:username/:reponame", func() {
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
|
m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}}
|
{{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}}
|
||||||
|
<div>
|
||||||
|
{{range .Topics}}<div class="ui green basic label topic">{{.}}</div>{{end}}
|
||||||
|
</div>
|
||||||
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}</p>
|
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}</p>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
{{template "base/alert" .}}
|
{{template "base/alert" .}}
|
||||||
<div class="ui repo-description">
|
<div class="ui repo-description">
|
||||||
<div id="repo-desc">
|
<div id="repo-desc">
|
||||||
{{if .Repository.DescriptionHTML}}<span class="description has-emoji">{{.Repository.DescriptionHTML}}</span>{{else if .IsRepositoryAdmin}}<span class="no-description text-italic">{{.i18n.Tr "repo.no_desc"}}</span>{{end}}
|
{{if .Repository.DescriptionHTML}}<span class="description has-emoji">{{.Repository.DescriptionHTML}}</span>{{else}}<span class="no-description text-italic">{{.i18n.Tr "repo.no_desc"}}</span>{{end}}
|
||||||
<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
|
<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{if .RepoSearchEnabled}}
|
{{if .RepoSearchEnabled}}
|
||||||
@@ -23,6 +23,27 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ui repo-topic" id="repo-topic">
|
||||||
|
{{range .Topics}}<div class="ui green basic label topic" style="cursor:pointer;">{{.Name}}</div>{{end}}
|
||||||
|
{{if .IsRepositoryAdmin}}<a id="manage_topic" style="cursor:pointer;margin-left:10px;">{{.i18n.Tr "repo.topic.manage_topics"}}</a>{{end}}
|
||||||
|
</div>
|
||||||
|
{{if .IsRepositoryAdmin}}
|
||||||
|
<div class="ui repo-topic-edit grid" id="topic_edit" >
|
||||||
|
<div class="fourteen wide column">
|
||||||
|
<div class="ui fluid multiple search selection dropdown">
|
||||||
|
<input type="hidden" name="topics" value="{{range $i, $v := .Topics}}{{.Name}}{{if lt (Add $i 1) (len $.Topics)}},{{end}}{{end}}">
|
||||||
|
{{range .Topics}}
|
||||||
|
<a class="ui green basic label topic transition visible" data-value="{{.Name}}" style="display: inline-block !important;">{{.Name}}<i class="delete icon"></i></a>
|
||||||
|
{{end}}
|
||||||
|
<div class="text"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="one wide column">
|
||||||
|
<a class="ui compact button primary" href="javascript:;" id="save_topic"
|
||||||
|
data-link="{{.RepoLink}}/topics">{{.i18n.Tr "repo.topic.done"}}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
{{template "repo/sub_menu" .}}
|
{{template "repo/sub_menu" .}}
|
||||||
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins">
|
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins">
|
||||||
{{if and .PullRequestCtx.Allowed .IsViewBranch}}
|
{{if and .PullRequestCtx.Allowed .IsViewBranch}}
|
||||||
|
|||||||
Reference in new issue
Block a user