fixed service reordering

pull/109/head
Hunter Long 2018-11-29 08:26:42 -08:00
parent c4b1a5390d
commit cb48afeeac
5 changed files with 17 additions and 17 deletions

View File

@ -388,7 +388,7 @@ func (s *Service) UpdateSingle(attr ...interface{}) error {
// Update will update a service in the database, the service's checking routine can be restarted by passing true // Update will update a service in the database, the service's checking routine can be restarted by passing true
func (s *Service) Update(restart bool) error { func (s *Service) Update(restart bool) error {
err := servicesDB().Update(s) err := servicesDB().Update(&s)
if err.Error != nil { if err.Error != nil {
utils.Log(3, fmt.Sprintf("Failed to update service %v. %v", s.Name, err)) utils.Log(3, fmt.Sprintf("Failed to update service %v. %v", s.Name, err))
return err.Error return err.Error
@ -396,7 +396,7 @@ func (s *Service) Update(restart bool) error {
// clear the notification queue for a service // clear the notification queue for a service
if !s.AllowNotifications.Bool { if !s.AllowNotifications.Bool {
for _, n := range CoreApp.Notifications { for _, n := range CoreApp.Notifications {
notif := n.(*notifier.Notification) notif := n.(notifier.Notifier).Select()
notif.ResetUniqueQueue(s.Id) notif.ResetUniqueQueue(s.Id)
} }
} }

View File

@ -18,7 +18,6 @@ package handlers
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/hunterlong/statup/core" "github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/types" "github.com/hunterlong/statup/types"
@ -65,20 +64,17 @@ func reorderServiceHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusSeeOther) http.Redirect(w, r, "/", http.StatusSeeOther)
return return
} }
r.ParseForm()
var newOrder []*serviceOrder var newOrder []*serviceOrder
decoder := json.NewDecoder(r.Body) decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&newOrder); err != nil { decoder.Decode(&newOrder)
utils.Log(3, fmt.Sprint("error decoding reordering services: %v", err.Error()))
}
for _, s := range newOrder { for _, s := range newOrder {
service := core.SelectService(s.Id) service := core.SelectService(s.Id)
service.Order = s.Order service.Order = s.Order
if err := service.Update(false); err != nil { service.Update(false)
utils.Log(3, fmt.Sprint("error reordering services: %v", err.Error()))
} }
} w.Header().Set("Content-Type", "application/json")
w.Write([]byte("ok")) json.NewEncoder(w).Encode(newOrder)
w.WriteHeader(http.StatusOK)
} }
func servicesViewHandler(w http.ResponseWriter, r *http.Request) { func servicesViewHandler(w http.ResponseWriter, r *http.Request) {

View File

@ -67,9 +67,6 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
timeFloat, _ := strconv.ParseFloat(timezone, 10) timeFloat, _ := strconv.ParseFloat(timezone, 10)
app.Timezone = float32(timeFloat) app.Timezone = float32(timeFloat)
utils.Log(1, fmt.Sprintf("timezone: %v", timezone))
utils.Log(1, fmt.Sprintf("tzone: %f", app.Timezone))
app.UseCdn = types.NewNullBool(r.PostForm.Get("enable_cdn") == "on") app.UseCdn = types.NewNullBool(r.PostForm.Get("enable_cdn") == "on")
core.CoreApp, err = core.UpdateCore(app) core.CoreApp, err = core.UpdateCore(app)
if err != nil { if err != nil {

View File

@ -60,8 +60,15 @@
var o = {service: parseInt(dId), order: i}; var o = {service: parseInt(dId), order: i};
newOrder.push(o); newOrder.push(o);
}); });
console.log(JSON.stringify(newOrder)); $.ajax({
$.post("/services/reorder", JSON.stringify(newOrder), function(data, status){ url: "/services/reorder",
type: 'POST',
data: JSON.stringify(newOrder),
contentType: "application/json",
dataType: "json",
success: function(data) {
console.log(data)
}
}); });
}); });
</script> </script>

View File

@ -1 +1 @@
0.79.92 0.79.93