mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore(settings): remove duplicated code
This commit is contained in:
parent
0b8181acab
commit
998ff009f5
@ -140,8 +140,6 @@ func (h *SettingsHandler) dispatchAction(action string) action {
|
|||||||
return h.actionDeleteAlias
|
return h.actionDeleteAlias
|
||||||
case "add_alias":
|
case "add_alias":
|
||||||
return h.actionAddAlias
|
return h.actionAddAlias
|
||||||
case "add_project_to_label":
|
|
||||||
return h.addProjectToLabel
|
|
||||||
case "add_label":
|
case "add_label":
|
||||||
return h.actionAddLabel
|
return h.actionAddLabel
|
||||||
case "delete_label":
|
case "delete_label":
|
||||||
@ -382,30 +380,7 @@ func (h *SettingsHandler) actionAddLabel(w http.ResponseWriter, r *http.Request)
|
|||||||
return http.StatusBadRequest, "", "invalid input"
|
return http.StatusBadRequest, "", "invalid input"
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.StatusOK, "label added successfully", ""
|
return http.StatusOK, "label added to project successfully", ""
|
||||||
}
|
|
||||||
|
|
||||||
func (h *SettingsHandler) addProjectToLabel(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
|
||||||
if h.config.IsDev() {
|
|
||||||
loadTemplates()
|
|
||||||
}
|
|
||||||
user := middlewares.GetPrincipal(r)
|
|
||||||
label := &models.ProjectLabel{
|
|
||||||
UserID: user.ID,
|
|
||||||
ProjectKey: r.PostFormValue("project"),
|
|
||||||
Label: r.PostFormValue("label"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if !label.IsValid() {
|
|
||||||
return http.StatusBadRequest, "", "invalid input"
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := h.projectLabelSrvc.Create(label); err != nil {
|
|
||||||
// TODO: distinguish between bad request, conflict and server error
|
|
||||||
return http.StatusBadRequest, "", "invalid input"
|
|
||||||
}
|
|
||||||
|
|
||||||
return http.StatusOK, "added project to label successfully", ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SettingsHandler) actionDeleteLabel(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
func (h *SettingsHandler) actionDeleteLabel(w http.ResponseWriter, r *http.Request) (int, string, string) {
|
||||||
|
@ -272,14 +272,12 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<form action="" method="post" class="inline-flex space-x-1">
|
<form action="" method="post" class="inline-flex space-x-1">
|
||||||
<input type="hidden" name="action" class="block" value="add_project_to_label">
|
<input type="hidden" name="action" class="block" value="add_label">
|
||||||
<input type="hidden" name="label" value="{{ $label.Key }}">
|
<input type="hidden" name="value" value="{{ $label.Key }}">
|
||||||
<select name="project" class="block text-sm select-default !w-auto">
|
<select name="key" class="block text-sm select-default !w-auto">
|
||||||
{{ range $k, $project := $.Projects }}
|
{{ range $k, $project := $.Projects }}
|
||||||
{{ if ne $label.Key $project }}
|
|
||||||
<option value="{{ $project }}">{{ $project }}</option>
|
<option value="{{ $project }}">{{ $project }}</option>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
|
||||||
</select>
|
</select>
|
||||||
<button type="submit" class="btn-primary btn-small">
|
<button type="submit" class="btn-primary btn-small">
|
||||||
Add project
|
Add project
|
||||||
|
Loading…
Reference in New Issue
Block a user