summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-18 18:07:04 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-18 18:07:04 -0400
commit93f8f9252304d4e8028e13dd95e4cdf2e3178594 (patch)
tree43218b1bbb2f3cb466b9afa8ed60022924526519 /models
parenta4c3ab48a52a0cade5d3c3ba76c5555ed1453566 (diff)
downloadgitea-93f8f9252304d4e8028e13dd95e4cdf2e3178594.tar.gz
gitea-93f8f9252304d4e8028e13dd95e4cdf2e3178594.zip
Finish create new label
Diffstat (limited to 'models')
-rw-r--r--models/issue.go47
-rw-r--r--models/login.go5
-rw-r--r--models/models.go2
3 files changed, 39 insertions, 15 deletions
diff --git a/models/issue.go b/models/issue.go
index d3eb89c356..62cc9363b8 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -400,17 +400,6 @@ func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error {
return nil
}
-// Label represents a label of repository for issues.
-type Label struct {
- Id int64
- RepoId int64 `xorm:"INDEX"`
- Name string
- Color string
- NumIssues int
- NumClosedIssues int
- NumOpenIssues int `xorm:"-"`
-}
-
// _____ .__.__ __
// / \ |__| | ____ _______/ |_ ____ ____ ____
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
@@ -622,6 +611,42 @@ func DeleteMilestone(m *Milestone) (err error) {
return sess.Commit()
}
+// .____ ___. .__
+// | | _____ \_ |__ ____ | |
+// | | \__ \ | __ \_/ __ \| |
+// | |___ / __ \| \_\ \ ___/| |__
+// |_______ (____ /___ /\___ >____/
+// \/ \/ \/ \/
+
+// Label represents a label of repository for issues.
+type Label struct {
+ Id int64
+ RepoId int64 `xorm:"INDEX"`
+ Name string
+ Color string `xorm:"VARCHAR(7)"`
+ NumIssues int
+ NumClosedIssues int
+ NumOpenIssues int `xorm:"-"`
+}
+
+// CalOpenIssues calculates the open issues of label.
+func (m *Label) CalOpenIssues() {
+ m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
+}
+
+// NewLabel creates new label of repository.
+func NewLabel(l *Label) error {
+ _, err := orm.Insert(l)
+ return err
+}
+
+// GetLabels returns a list of labels of given repository ID.
+func GetLabels(repoId int64) ([]*Label, error) {
+ labels := make([]*Label, 0, 10)
+ err := orm.Where("repo_id=?", repoId).Find(&labels)
+ return labels, err
+}
+
// _________ __
// \_ ___ \ ____ _____ _____ ____ _____/ |_
// / \ \/ / _ \ / \ / \_/ __ \ / \ __\
diff --git a/models/login.go b/models/login.go
index ed5a8425a8..3efef2f78f 100644
--- a/models/login.go
+++ b/models/login.go
@@ -185,9 +185,8 @@ func LoginUser(uname, passwd string) (*User, error) {
} else {
if !has {
var sources []LoginSource
- cond := &LoginSource{IsActived: true, AllowAutoRegister: true}
- err = orm.UseBool().Find(&sources, cond)
- if err != nil {
+ if err = orm.UseBool().Find(&sources,
+ &LoginSource{IsActived: true, AllowAutoRegister: true}); err != nil {
return nil, err
}
diff --git a/models/models.go b/models/models.go
index 3adec1a56c..841b10639d 100644
--- a/models/models.go
+++ b/models/models.go
@@ -35,7 +35,7 @@ func init() {
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser),
- new(Milestone))
+ new(Milestone), new(Label))
}
func LoadModelsConfig() {