diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 6880d646149d..bede21be1763 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -302,6 +302,11 @@ func CreatePost(ctx *context.Context) { handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form) } +const ( + tplWatchUnwatch base.TplName = "repo/watch_unwatch" + tplStarUnstar base.TplName = "repo/star_unstar" +) + // Action response for actions to a repository func Action(ctx *context.Context) { var err error @@ -334,6 +339,32 @@ func Action(ctx *context.Context) { return } + switch ctx.Params(":action") { + case "watch", "unwatch": + ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) + case "star", "unstar": + ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) + } + + switch ctx.Params(":action") { + case "watch", "unwatch", "star", "unstar": + // we have to reload the repository because NumStars or NumWatching (used in the templates) has just changed + ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name) + if err != nil { + ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err) + return + } + } + + switch ctx.Params(":action") { + case "watch", "unwatch": + ctx.HTML(http.StatusOK, tplWatchUnwatch) + return + case "star", "unstar": + ctx.HTML(http.StatusOK, tplStarUnstar) + return + } + ctx.RedirectToFirst(ctx.FormString("redirect_to"), ctx.Repo.RepoLink) } diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index dac30af600c3..93102467ccb3 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -58,37 +58,9 @@ {{svg "octicon-rss" 16}} {{end}} -
+ {{template "repo/watch_unwatch" $}} {{if not $.DisableStars}} - + {{template "repo/star_unstar" $}} {{end}} {{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}