mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-23 01:20:50 +00:00
Finish new home page of organization
This commit is contained in:
parent
7af7584d25
commit
5fbf8531e6
27 changed files with 445 additions and 142 deletions
|
@ -137,6 +137,7 @@ type Repository struct {
|
|||
NumTags int `xorm:"-"`
|
||||
IsPrivate bool
|
||||
IsMirror bool
|
||||
*Mirror `xorm:"-"`
|
||||
IsFork bool `xorm:"NOT NULL DEFAULT false"`
|
||||
IsBare bool
|
||||
IsGoget bool
|
||||
|
@ -150,6 +151,11 @@ func (repo *Repository) GetOwner() (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func (repo *Repository) GetMirror() (err error) {
|
||||
repo.Mirror, err = GetMirror(repo.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
// DescriptionHtml does special handles to description and return HTML string.
|
||||
func (repo *Repository) DescriptionHtml() template.HTML {
|
||||
sanitize := func(s string) string {
|
||||
|
@ -953,21 +959,33 @@ type Watch struct {
|
|||
}
|
||||
|
||||
// Watch or unwatch repository.
|
||||
func WatchRepo(uid, rid int64, watch bool) (err error) {
|
||||
func WatchRepo(uid, repoId int64, watch bool) (err error) {
|
||||
if watch {
|
||||
if _, err = x.Insert(&Watch{RepoId: rid, UserId: uid}); err != nil {
|
||||
if IsWatching(uid, repoId) {
|
||||
return nil
|
||||
}
|
||||
if _, err = x.Insert(&Watch{RepoId: repoId, UserId: uid}); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = x.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", rid)
|
||||
_, err = x.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoId)
|
||||
} else {
|
||||
if _, err = x.Delete(&Watch{0, uid, rid}); err != nil {
|
||||
if !IsWatching(uid, repoId) {
|
||||
return nil
|
||||
}
|
||||
if _, err = x.Delete(&Watch{0, uid, repoId}); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = x.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", rid)
|
||||
_, err = x.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoId)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// IsWatching checks if user has watched given repository.
|
||||
func IsWatching(uid, rid int64) bool {
|
||||
has, _ := x.Get(&Watch{0, uid, rid})
|
||||
return has
|
||||
}
|
||||
|
||||
// GetWatchers returns all watchers of given repository.
|
||||
func GetWatchers(rid int64) ([]*Watch, error) {
|
||||
watches := make([]*Watch, 0, 10)
|
||||
|
@ -1003,9 +1021,37 @@ func NotifyWatchers(act *Action) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// IsWatching checks if user has watched given repository.
|
||||
func IsWatching(uid, rid int64) bool {
|
||||
has, _ := x.Get(&Watch{0, uid, rid})
|
||||
type Star struct {
|
||||
Id int64
|
||||
Uid int64 `xorm:"UNIQUE(s)"`
|
||||
RepoId int64 `xorm:"UNIQUE(s)"`
|
||||
}
|
||||
|
||||
// Star or unstar repository.
|
||||
func StarRepo(uid, repoId int64, star bool) (err error) {
|
||||
if star {
|
||||
if IsStaring(uid, repoId) {
|
||||
return nil
|
||||
}
|
||||
if _, err = x.Insert(&Star{Uid: uid, RepoId: repoId}); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoId)
|
||||
} else {
|
||||
if !IsStaring(uid, repoId) {
|
||||
return nil
|
||||
}
|
||||
if _, err = x.Delete(&Star{0, uid, repoId}); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoId)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// IsStaring checks if user has starred given repository.
|
||||
func IsStaring(uid, repoId int64) bool {
|
||||
has, _ := x.Get(&Star{0, uid, repoId})
|
||||
return has
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue