1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

Watch backend

This commit is contained in:
Unknown 2014-03-19 23:20:55 -04:00
parent 8b0f421eb5
commit a922c3ff6a
7 changed files with 44 additions and 13 deletions

View file

@ -88,7 +88,8 @@ func setEngine() {
func init() { func init() {
setEngine() setEngine()
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Access), new(Action)); err != nil { if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Access),
new(Action), new(Watch)); err != nil {
fmt.Printf("sync database struct error: %v\n", err) fmt.Printf("sync database struct error: %v\n", err)
os.Exit(2) os.Exit(2)
} }

View file

@ -43,11 +43,20 @@ type Repository struct {
Updated time.Time `xorm:"updated"` Updated time.Time `xorm:"updated"`
} }
type Star struct { // Watch is connection request for receiving repository notifycation.
type Watch struct {
Id int64 Id int64
RepoId int64 RepoId int64 `xorm:"UNIQUE(watch)"`
UserId int64 UserId int64 `xorm:"UNIQUE(watch)"`
Created time.Time `xorm:"created"` }
func WatchRepo(userId, repoId int64, watch bool) (err error) {
if watch {
_, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId})
} else {
_, err = orm.Delete(&Watch{0, repoId, userId})
}
return err
} }
var ( var (

View file

@ -208,3 +208,25 @@ func Pulls(ctx *middleware.Context) {
ctx.Data["IsRepoToolbarPulls"] = true ctx.Data["IsRepoToolbarPulls"] = true
ctx.HTML(200, "repo/pulls", ctx.Data) ctx.HTML(200, "repo/pulls", ctx.Data)
} }
func Action(ctx *middleware.Context, params martini.Params) {
var err error
switch params["action"] {
case "watch":
err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.Id, true)
case "unwatch":
err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.Id, false)
}
if err != nil {
log.Error("repo.Action(%s): %v", params["action"], err)
ctx.JSON(200, map[string]interface{}{
"ok": false,
"err": err.Error(),
})
return
}
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
}

View file

@ -93,7 +93,6 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
if ctx.Req.Method == "DELETE" || ctx.Query("_method") == "DELETE" { if ctx.Req.Method == "DELETE" || ctx.Query("_method") == "DELETE" {
id, err := strconv.ParseInt(ctx.Query("id"), 10, 64) id, err := strconv.ParseInt(ctx.Query("id"), 10, 64)
if err != nil { if err != nil {
ctx.Data["ErrorMsg"] = err
log.Error("ssh.DelPublicKey: %v", err) log.Error("ssh.DelPublicKey: %v", err)
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"ok": false, "ok": false,
@ -107,7 +106,6 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
} }
if err = models.DeletePublicKey(k); err != nil { if err = models.DeletePublicKey(k); err != nil {
ctx.Data["ErrorMsg"] = err
log.Error("ssh.DelPublicKey: %v", err) log.Error("ssh.DelPublicKey: %v", err)
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"ok": false, "ok": false,

View file

@ -26,7 +26,7 @@
{{$r := List .Commits}} {{$r := List .Commits}}
{{range $r}} {{range $r}}
<tr> <tr>
<td class="author"><img class="avatar" src="{{AvatarLink .Committer.Email}}" alt=""/>{{.Committer.Name}}</td> <td class="author"><img class="avatar" src="{{AvatarLink .Committer.Email}}" alt=""/><a href="/user/{{.Committer.Name}}">{{.Committer.Name}}</a></td>
<td class="sha"><a class="label label-success" href="/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 7}} </a></td> <td class="sha"><a class="label label-success" href="/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 7}} </a></td>
<td class="message">{{.Message}} </td> <td class="message">{{.Message}} </td>
<td class="date">{{TimeSince .Committer.When}}</td> <td class="date">{{TimeSince .Committer.When}}</td>

View file

@ -3,8 +3,8 @@
<div id="gogs-body" class="container" data-page="user"> <div id="gogs-body" class="container" data-page="user">
<div id="gogs-user-profile" class="col-md-3"> <div id="gogs-user-profile" class="col-md-3">
<div class="profile-avatar text-center"> <div class="profile-avatar text-center">
<a href="{{.Owner.HomeLink}}" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar"> <a href="http://gravatar.com/emails/" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change your avatar at gravatar.com">
<img id="gogs-user-avatar" src="{{.Owner.AvatarLink}}?s=200" alt="user-avatar" title="username"/> <img id="gogs-user-avatar" src="{{.Owner.AvatarLink}}?s=200" alt="user-avatar" title="{{.Owner.Name}}"/>
</a> </a>
<span id="gogs-user-name" class="center-block">{{.Owner.Name}}</span> <span id="gogs-user-name" class="center-block">{{.Owner.Name}}</span>
</div> </div>

5
web.go
View file

@ -73,8 +73,8 @@ func runWeb(*cli.Context) {
m.Use(middleware.InitContext()) m.Use(middleware.InitContext())
ignSignIn := middleware.SignInRequire(false) reqSignIn, ignSignIn := middleware.SignInRequire(true), middleware.SignInRequire(false)
reqSignIn, reqSignOut := middleware.SignInRequire(true), middleware.SignOutRequire() reqSignOut := middleware.SignOutRequire()
// Routers. // Routers.
m.Get("/", ignSignIn, routers.Home) m.Get("/", ignSignIn, routers.Home)
m.Get("/issues", reqSignIn, user.Issues) m.Get("/issues", reqSignIn, user.Issues)
@ -106,6 +106,7 @@ func runWeb(*cli.Context) {
m.Get("/:username/:reponame/issues", ignSignIn, middleware.RepoAssignment(true), repo.Issues) m.Get("/:username/:reponame/issues", ignSignIn, middleware.RepoAssignment(true), repo.Issues)
m.Get("/:username/:reponame/pulls", ignSignIn, middleware.RepoAssignment(true), repo.Pulls) m.Get("/:username/:reponame/pulls", ignSignIn, middleware.RepoAssignment(true), repo.Pulls)
m.Get("/:username/:reponame/branches", ignSignIn, middleware.RepoAssignment(true), repo.Branches) m.Get("/:username/:reponame/branches", ignSignIn, middleware.RepoAssignment(true), repo.Branches)
m.Get("/:username/:reponame/action/:action", reqSignIn, middleware.RepoAssignment(true), repo.Action)
m.Get("/:username/:reponame/tree/:branchname/**", m.Get("/:username/:reponame/tree/:branchname/**",
ignSignIn, middleware.RepoAssignment(true), repo.Single) ignSignIn, middleware.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame/tree/:branchname", m.Get("/:username/:reponame/tree/:branchname",