mirror of https://github.com/statping/statping
				
				
				
			fixed service reordering
							parent
							
								
									c4b1a5390d
								
							
						
					
					
						commit
						cb48afeeac
					
				|  | @ -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
 | ||||
| func (s *Service) Update(restart bool) error { | ||||
| 	err := servicesDB().Update(s) | ||||
| 	err := servicesDB().Update(&s) | ||||
| 	if err.Error != nil { | ||||
| 		utils.Log(3, fmt.Sprintf("Failed to update service %v. %v", s.Name, err)) | ||||
| 		return err.Error | ||||
|  | @ -396,7 +396,7 @@ func (s *Service) Update(restart bool) error { | |||
| 	// clear the notification queue for a service
 | ||||
| 	if !s.AllowNotifications.Bool { | ||||
| 		for _, n := range CoreApp.Notifications { | ||||
| 			notif := n.(*notifier.Notification) | ||||
| 			notif := n.(notifier.Notifier).Select() | ||||
| 			notif.ResetUniqueQueue(s.Id) | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
|  | @ -18,7 +18,6 @@ package handlers | |||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"github.com/gorilla/mux" | ||||
| 	"github.com/hunterlong/statup/core" | ||||
| 	"github.com/hunterlong/statup/types" | ||||
|  | @ -65,20 +64,17 @@ func reorderServiceHandler(w http.ResponseWriter, r *http.Request) { | |||
| 		http.Redirect(w, r, "/", http.StatusSeeOther) | ||||
| 		return | ||||
| 	} | ||||
| 	r.ParseForm() | ||||
| 	var newOrder []*serviceOrder | ||||
| 	decoder := json.NewDecoder(r.Body) | ||||
| 	if err := decoder.Decode(&newOrder); err != nil { | ||||
| 		utils.Log(3, fmt.Sprint("error decoding reordering services: %v", err.Error())) | ||||
| 	} | ||||
| 	decoder.Decode(&newOrder) | ||||
| 	for _, s := range newOrder { | ||||
| 		service := core.SelectService(s.Id) | ||||
| 		service.Order = s.Order | ||||
| 		if err := service.Update(false); err != nil { | ||||
| 			utils.Log(3, fmt.Sprint("error reordering services: %v", err.Error())) | ||||
| 		} | ||||
| 		service.Update(false) | ||||
| 	} | ||||
| 	w.Write([]byte("ok")) | ||||
| 	w.WriteHeader(http.StatusOK) | ||||
| 	w.Header().Set("Content-Type", "application/json") | ||||
| 	json.NewEncoder(w).Encode(newOrder) | ||||
| } | ||||
| 
 | ||||
| func servicesViewHandler(w http.ResponseWriter, r *http.Request) { | ||||
|  |  | |||
|  | @ -67,9 +67,6 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) { | |||
| 	timeFloat, _ := strconv.ParseFloat(timezone, 10) | ||||
| 	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") | ||||
| 	core.CoreApp, err = core.UpdateCore(app) | ||||
| 	if err != nil { | ||||
|  |  | |||
|  | @ -60,8 +60,15 @@ | |||
|             var o = {service: parseInt(dId), order: i}; | ||||
|             newOrder.push(o); | ||||
|         }); | ||||
|         console.log(JSON.stringify(newOrder)); | ||||
|         $.post("/services/reorder", JSON.stringify(newOrder), function(data, status){ | ||||
|         $.ajax({ | ||||
|             url: "/services/reorder", | ||||
|             type: 'POST', | ||||
|             data: JSON.stringify(newOrder), | ||||
|             contentType: "application/json", | ||||
|             dataType: "json", | ||||
|             success: function(data) { | ||||
|                 console.log(data) | ||||
|             } | ||||
|         }); | ||||
|     }); | ||||
| </script> | ||||
|  |  | |||
|  | @ -1 +1 @@ | |||
| 0.79.92 | ||||
| 0.79.93 | ||||
		Loading…
	
		Reference in New Issue
	
	 Hunter Long
						Hunter Long