feat: Enhance notification services with delete confirmation dialog

- Added a confirmation dialog for deleting notification services to prevent accidental deletions.
- Updated the notifications management interface to include improved delete button functionality.
- Enhanced JavaScript event handling for delete requests, providing user feedback on success and error scenarios.
- Refactored notification service deletion logic to ensure accurate tracking and messaging during deletion operations.
This commit is contained in:
StarFleetCPTN
2025-03-26 06:26:39 -07:00
parent 8e1321d251
commit db1a0ad5f5
4 changed files with 190 additions and 24 deletions
+13
View File
@@ -1579,12 +1579,23 @@ func (s *Scheduler) sendServiceWebhookNotification(service *db.NotificationServi
// generateDefaultPayload creates a standard webhook payload
func generateDefaultPayload(job *db.Job, history *db.JobHistory, config *db.TransferConfig, eventType string) map[string]interface{} {
// get event type
switch eventType {
case "job_start":
eventType = "Job Started"
case "job_complete":
eventType = "Job Completed"
case "job_fail":
eventType = "Job Failed"
}
payload := map[string]interface{}{
"event": eventType,
"job": map[string]interface{}{
"id": job.ID,
"name": job.Name,
"status": history.Status,
"event": eventType,
"message": history.ErrorMessage,
"started_at": history.StartTime.Format(time.RFC3339),
"config_id": config.ID,
@@ -2400,6 +2411,8 @@ func (s *Scheduler) sendNtfyNotification(service *db.NotificationService, job *d
func (s *Scheduler) sendGotifyNotification(service *db.NotificationService, job *db.Job, history *db.JobHistory, config *db.TransferConfig, eventType string) error {
s.log.LogDebug("Sending Gotify notification for job %d", job.ID)
// pretty print job
fmt.Printf("Job: %+v\n", job)
// Get Gotify server URL and token from service config
serverURL, ok := service.Config["url"]
if !ok || serverURL == "" {
+2 -6
View File
@@ -74,12 +74,6 @@ func (h *Handlers) HandleCreateNotificationService(c *gin.Context) {
description := c.PostForm("description")
isEnabled := c.PostForm("is_enabled") == "on"
// print the form data
fmt.Println("name", name)
fmt.Println("serviceType", serviceType)
fmt.Println("description", description)
fmt.Println("isEnabled", isEnabled)
// Validate required fields
if name == "" || serviceType == "" {
// Return to notifications page with error message
@@ -727,6 +721,8 @@ func (h *Handlers) HandleTestNotification(c *gin.Context) {
config["priority"] = c.PostForm("gotify_priority")
config["title"] = c.PostForm("gotify_title_template")
fmt.Println("config", config)
// Validate required fields
if config["url"] == "" || config["token"] == "" {
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "Gotify Server URL and Application Token are required"})