new edit webhook UI

tokarchuk/v1.17
Unknwon 9 years ago
parent 4217c2333c
commit c08600c59b
  1. 25
      cmd/web.go
  2. 1
      modules/auth/repo_form.go
  3. 2
      public/css/gogs.min.css
  4. 21
      public/less/_form.less
  5. 173
      routers/repo/setting.go
  6. 6
      templates/repo/settings/githook_edit.tmpl
  7. 2
      templates/repo/settings/hook_gogs.tmpl
  8. 14
      templates/repo/settings/hook_history.tmpl
  9. 2
      templates/repo/settings/hook_slack.tmpl

@ -414,11 +414,11 @@ func runWeb(ctx *cli.Context) {
m.Get("/:type/new", repo.WebhooksNew) m.Get("/:type/new", repo.WebhooksNew)
m.Post("/gogs/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost) m.Post("/gogs/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost) m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
m.Get("/:id", repo.WebHooksEdit)
m.Post("/gogs/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
}) })
m.Get("/hooks/:id", repo.WebHooksEdit)
m.Post("/hooks/gogs/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
m.Post("/hooks/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
m.Route("/delete", "GET,POST", org.SettingsDelete) m.Route("/delete", "GET,POST", org.SettingsDelete)
}) })
@ -452,18 +452,17 @@ func runWeb(ctx *cli.Context) {
m.Get("/:type/new", repo.WebhooksNew) m.Get("/:type/new", repo.WebhooksNew)
m.Post("/gogs/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost) m.Post("/gogs/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost) m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
m.Get("/:id", repo.WebHooksEdit)
m.Post("/gogs/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
m.Group("/git", func() {
m.Get("", repo.GitHooks)
m.Combo("/:name").Get(repo.GitHooksEdit).
Post(repo.GitHooksEditPost)
}, middleware.GitHookService())
}) })
m.Get("/hooks/:id", repo.WebHooksEdit)
m.Post("/hooks/gogs/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
m.Post("/hooks/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
m.Group("/hooks/git", func() {
m.Get("", repo.GitHooks)
m.Combo("/:name").Get(repo.GitHooksEdit).
Post(repo.GitHooksEditPost)
}, middleware.GitHookService())
m.Group("/keys", func() { m.Group("/keys", func() {
m.Combo("").Get(repo.DeployKeys). m.Combo("").Get(repo.DeployKeys).
Post(bindIgnErr(auth.AddSSHKeyForm{}), repo.DeployKeysPost) Post(bindIgnErr(auth.AddSSHKeyForm{}), repo.DeployKeysPost)

@ -66,7 +66,6 @@ func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) bi
// \/ \/ \/ \/ \/ \/ // \/ \/ \/ \/ \/ \/
type WebhookForm struct { type WebhookForm struct {
HookType string `binding:"Required"`
PushOnly bool PushOnly bool
Active bool Active bool
} }

File diff suppressed because one or more lines are too long

@ -59,27 +59,6 @@
} }
} }
} }
.repository.edit.githook {
form {
@input-padding: 25%!important;
.inline.field > label {
text-align: right;
width: @input-padding;
word-wrap: break-word;
}
input,
textarea {
width: 50%!important;
}
}
}
.repository.edit.githook {
form {
textarea {
width: 70%!important;
}
}
}
.new.webhook { .new.webhook {
form { form {

@ -368,18 +368,56 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) {
ctx.Redirect(orCtx.Link + "/settings/hooks") ctx.Redirect(orCtx.Link + "/settings/hooks")
} }
func WebHooksEdit(ctx *middleware.Context) { func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true ctx.Data["PageIsSettingsHooksNew"] = true
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err) ctx.Handle(500, "getOrgRepoCtx", err)
return return
} }
ctx.Data["BaseLink"] = orCtx.Link
if ctx.HasError() {
ctx.HTML(200, orCtx.NewTemplate)
return
}
meta, err := json.Marshal(&models.Slack{
Channel: form.Channel,
})
if err != nil {
ctx.Handle(500, "Marshal", err)
return
}
w := &models.Webhook{
RepoID: orCtx.RepoID,
URL: form.PayloadURL,
ContentType: models.JSON,
HookEvent: &models.HookEvent{
PushOnly: form.PushOnly,
},
IsActive: form.Active,
HookTaskType: models.SLACK,
Meta: string(meta),
OrgID: orCtx.OrgID,
}
if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err)
return
} else if err := models.CreateWebhook(w); err != nil {
ctx.Handle(500, "CreateWebhook", err)
return
}
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
ctx.Redirect(orCtx.Link + "/settings/hooks")
}
func checkWebhook(ctx *middleware.Context) *models.Webhook {
w, err := models.GetWebhookById(ctx.ParamsInt64(":id")) w, err := models.GetWebhookById(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if err == models.ErrWebhookNotExist { if err == models.ErrWebhookNotExist {
@ -387,7 +425,7 @@ func WebHooksEdit(ctx *middleware.Context) {
} else { } else {
ctx.Handle(500, "GetWebhookById", err) ctx.Handle(500, "GetWebhookById", err)
} }
return return nil
} }
switch w.HookTaskType { switch w.HookTaskType {
@ -398,35 +436,38 @@ func WebHooksEdit(ctx *middleware.Context) {
ctx.Data["HookType"] = "gogs" ctx.Data["HookType"] = "gogs"
} }
w.GetEvent() w.GetEvent()
ctx.Data["Webhook"] = w return w
ctx.HTML(200, orCtx.NewTemplate)
} }
func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { func WebHooksEdit(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true ctx.Data["PageIsSettingsHooksEdit"] = true
w, err := models.GetWebhookById(ctx.ParamsInt64(":id")) ctx.Data["Webhook"] = checkWebhook(ctx)
if ctx.Written() {
return
}
orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
if err == models.ErrWebhookNotExist { ctx.Handle(500, "getOrgRepoCtx", err)
ctx.Handle(404, "GetWebhookById", nil)
} else {
ctx.Handle(500, "GetWebhookById", err)
}
return return
} }
ctx.Data["BaseLink"] = orCtx.Link
// set data per HookTaskType ctx.HTML(200, orCtx.NewTemplate)
switch w.HookTaskType { }
case models.SLACK:
ctx.Data["SlackHook"] = w.GetSlackHook() func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) {
ctx.Data["HookType"] = "Slack" ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
default: ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["HookType"] = "Gogs" ctx.Data["PageIsSettingsHooksEdit"] = true
w := checkWebhook(ctx)
if ctx.Written() {
return
} }
w.GetEvent()
ctx.Data["Webhook"] = w ctx.Data["Webhook"] = w
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
@ -441,13 +482,13 @@ func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) {
return return
} }
ct := models.JSON contentType := models.JSON
if models.HookContentType(form.ContentType) == models.FORM { if models.HookContentType(form.ContentType) == models.FORM {
ct = models.FORM contentType = models.FORM
} }
w.URL = form.PayloadURL w.URL = form.PayloadURL
w.ContentType = ct w.ContentType = contentType
w.Secret = form.Secret w.Secret = form.Secret
w.HookEvent = &models.HookEvent{ w.HookEvent = &models.HookEvent{
PushOnly: form.PushOnly, PushOnly: form.PushOnly,
@ -462,57 +503,7 @@ func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) {
} }
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
ctx.Redirect(orCtx.Link + "/settings/hooks") ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
}
func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
orCtx, err := getOrgRepoCtx(ctx)
if err != nil {
ctx.Handle(500, "SlackHooksNewPost(getOrgRepoCtx)", err)
return
}
if ctx.HasError() {
ctx.HTML(200, orCtx.NewTemplate)
return
}
meta, err := json.Marshal(&models.Slack{
Channel: form.Channel,
})
if err != nil {
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err)
return
}
w := &models.Webhook{
RepoID: orCtx.RepoID,
URL: form.PayloadURL,
ContentType: models.JSON,
Secret: "",
HookEvent: &models.HookEvent{
PushOnly: form.PushOnly,
},
IsActive: form.Active,
HookTaskType: models.SLACK,
Meta: string(meta),
OrgID: orCtx.OrgID,
}
if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err)
return
} else if err := models.CreateWebhook(w); err != nil {
ctx.Handle(500, "CreateWebhook", err)
return
}
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
ctx.Redirect(orCtx.Link + "/settings/hooks")
} }
func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
@ -520,39 +511,29 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true ctx.Data["PageIsSettingsHooksEdit"] = true
hookId := com.StrTo(ctx.Params(":id")).MustInt64() w := checkWebhook(ctx)
if hookId == 0 { if ctx.Written() {
ctx.Handle(404, "SlackHooksEditPost(hookId)", nil)
return return
} }
ctx.Data["Webhook"] = w
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "SlackHooksEditPost(getOrgRepoCtx)", err) ctx.Handle(500, "getOrgRepoCtx", err)
return
}
w, err := models.GetWebhookById(hookId)
if err != nil {
if err == models.ErrWebhookNotExist {
ctx.Handle(404, "GetWebhookById", nil)
} else {
ctx.Handle(500, "GetWebhookById", err)
}
return return
} }
w.GetEvent() ctx.Data["BaseLink"] = orCtx.Link
ctx.Data["Webhook"] = w
if ctx.HasError() { if ctx.HasError() {
ctx.HTML(200, orCtx.NewTemplate) ctx.HTML(200, orCtx.NewTemplate)
return return
} }
meta, err := json.Marshal(&models.Slack{ meta, err := json.Marshal(&models.Slack{
Channel: form.Channel, Channel: form.Channel,
}) })
if err != nil { if err != nil {
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err) ctx.Handle(500, "Marshal", err)
return return
} }
@ -566,12 +547,12 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
ctx.Handle(500, "UpdateEvent", err) ctx.Handle(500, "UpdateEvent", err)
return return
} else if err := models.UpdateWebhook(w); err != nil { } else if err := models.UpdateWebhook(w); err != nil {
ctx.Handle(500, "SlackHooksEditPost", err) ctx.Handle(500, "UpdateWebhook", err)
return return
} }
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, hookId)) ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
} }
func DeleteWebhook(ctx *middleware.Context) { func DeleteWebhook(ctx *middleware.Context) {

@ -10,15 +10,15 @@
{{.i18n.Tr "repo.settings.githooks"}} {{.i18n.Tr "repo.settings.githooks"}}
</h4> </h4>
<div class="ui attached segment"> <div class="ui attached segment">
<p class="center">{{.i18n.Tr "repo.settings.githook_edit_desc"}}</p> <p>{{.i18n.Tr "repo.settings.githook_edit_desc"}}</p>
<form class="ui form" action="{{.Link}}" method="post"> <form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
{{with .Hook}} {{with .Hook}}
<div class="inline field"> <div class="inline field">
<label>{{$.i18n.Tr "repo.settings.githook_name"}}</label> <label>{{$.i18n.Tr "repo.settings.githook_name"}}</label>
<label class="text left">{{.Name}}</label> <span>{{.Name}}</span>
</div> </div>
<div class="inline field"> <div class="field">
<label for="content">{{$.i18n.Tr "repo.settings.githook_content"}}</label> <label for="content">{{$.i18n.Tr "repo.settings.githook_content"}}</label>
<textarea id="content" name="content" rows="20" wrap="off">{{if .IsActive}}{{.Content}}{{else}}{{.Sample}}{{end}}</textarea> <textarea id="content" name="content" rows="20" wrap="off">{{if .IsActive}}{{.Content}}{{else}}{{.Sample}}{{end}}</textarea>
</div> </div>

@ -1,6 +1,6 @@
{{if eq .HookType "gogs"}} {{if eq .HookType "gogs"}}
<p>{{.i18n.Tr "repo.settings.add_webhook_desc" "http://gogs.io/docs/features/webhook.html" | Str2html}}</p> <p>{{.i18n.Tr "repo.settings.add_webhook_desc" "http://gogs.io/docs/features/webhook.html" | Str2html}}</p>
<form class="ui form" action="{{.BaseLink}}/settings/hooks/{{if .PageIsSettingsHooksNew}}gogs/new{{else}}{{.Webhook.ID}}{{end}}" method="post"> <form class="ui form" action="{{.BaseLink}}/settings/hooks/gogs/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post">
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> <div class="required field {{if .Err_PayloadURL}}error{{end}}">
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> <label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>

@ -1,12 +1,8 @@
{{if .PageIsSettingsHooksEdit}} {{if .PageIsSettingsHooksEdit}}
<div id="setting-content"> <h4 class="ui top attached header">
<div id="repo-hooks-history-panel" class="panel panel-radius"> {{.i18n.Tr "repo.settings.recent_deliveries"}}
<div class="panel-header"> </h4>
<strong>{{.i18n.Tr "repo.settings.recent_deliveries"}}</strong> <div class="ui attached segment">
</div> Coming soon!
<ul class="panel-body setting-list">
<li>Coming soon!</li>
</ul>
</div>
</div> </div>
{{end}} {{end}}

@ -1,6 +1,6 @@
{{if eq .HookType "slack"}} {{if eq .HookType "slack"}}
<p>{{.i18n.Tr "repo.settings.add_slack_hook_desc" "http://slack.com" | Str2html}}</p> <p>{{.i18n.Tr "repo.settings.add_slack_hook_desc" "http://slack.com" | Str2html}}</p>
<form class="ui form" action="{{.BaseLink}}/settings/hooks/{{if .PageIsSettingsHooksNew}}slack/new{{else}}{{.Webhook.ID}}{{end}}" method="post"> <form class="ui form" action="{{.BaseLink}}/settings/hooks/slack/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post">
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> <div class="required field {{if .Err_PayloadURL}}error{{end}}">
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> <label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>

Loading…
Cancel
Save