From dc6209dbc1b4d0dfaa58c87d2cee698b07a06e0a Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Fri, 11 Apr 2025 12:17:03 -0700 Subject: [PATCH] feat: Enhance configuration form with validation and error handling - Implemented validation for the configuration form to ensure required fields are filled before submission. - Added a dynamic error display for user feedback, including validation messages for configuration name and paths. - Ensured at least one concurrent transfer is set by default to improve user experience. - Updated form layout to include accessibility features and improved error handling for various input fields. --- components/config_form.templ | 235 ++++++++++++++++++++++++++++++- internal/web/handlers/handler.go | 16 +-- 2 files changed, 242 insertions(+), 9 deletions(-) diff --git a/components/config_form.templ b/components/config_form.templ index 14d2957..547a2c1 100644 --- a/components/config_form.templ +++ b/components/config_form.templ @@ -167,6 +167,9 @@ func getInitialData(config *db.TransferConfig) string { deleteAfterTransfer = config.GetDeleteAfterTransfer() skipProcessedFiles = config.GetSkipProcessedFiles() maxConcurrentTransfers = config.MaxConcurrentTransfers + if maxConcurrentTransfers <= 0 { + maxConcurrentTransfers = 1 // Ensure at least 1 concurrent transfer + } rcloneFlags = config.RcloneFlags commandId = config.CommandID commandFlags = config.CommandFlags @@ -377,6 +380,7 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) {
+ + +
@@ -450,13 +469,16 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) {
- + @@ -703,4 +725,215 @@ templ ConfigForm(ctx context.Context, data ConfigFormData) {
} +} + +templ formvalidation() { + } \ No newline at end of file diff --git a/internal/web/handlers/handler.go b/internal/web/handlers/handler.go index 172ac2c..b95a29d 100644 --- a/internal/web/handlers/handler.go +++ b/internal/web/handlers/handler.go @@ -59,7 +59,7 @@ func NewHandlers(database *db.DB, scheduler scheduler.SchedulerInterface, jwtSec // StartLogBroadcaster starts a goroutine that broadcasts logs to all connected WebSocket clients func StartLogBroadcaster() { go func() { - fmt.Fprintln(os.Stderr, "[DEBUG-BROADCASTER-V4] Broadcaster goroutine started.") + fmt.Fprintln(os.Stderr, "[DEBUG-BROADCASTER] Broadcaster goroutine started.") for { logEntry := <-LogChannel // Wait for a log entry @@ -76,7 +76,7 @@ func StartLogBroadcaster() { continue // Skip if no clients } - fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER-V4] Received log. Broadcasting to %d clients. Level='%s', Src='%s'\n", + fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER] Received log. Broadcasting to %d clients. Level='%s', Src='%s'\n", len(clientsToSend), logEntry.Level, logEntry.Source) var wg sync.WaitGroup @@ -85,7 +85,7 @@ func StartLogBroadcaster() { go func(c *websocket.Conn, m *sync.Mutex, entry components.LogEntry) { defer wg.Done() - fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER-V4] Attempting send to client %v\n", c.RemoteAddr()) + fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER] Attempting send to client %v\n", c.RemoteAddr()) // Lock only for this specific client's write m.Lock() @@ -93,7 +93,7 @@ func StartLogBroadcaster() { deadline := time.Now().Add(5 * time.Second) // 5-second deadline err := c.SetWriteDeadline(deadline) if err != nil { - fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER-V4] Error setting write deadline for client %v: %v\n", c.RemoteAddr(), err) + fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER] Error setting write deadline for client %v: %v\n", c.RemoteAddr(), err) // Don't unlock yet, proceed to cleanup } else { err = c.WriteJSON(entry) @@ -101,19 +101,19 @@ func StartLogBroadcaster() { m.Unlock() // Unlock after write attempt (or deadline error) if err != nil { - fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER-V4] Error writing to client %v: %v. Initiating removal.\n", c.RemoteAddr(), err) + fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER] Error writing to client %v: %v. Initiating removal.\n", c.RemoteAddr(), err) WebSocketClientsMutex.Lock() if _, stillExists := WebSocketClients[c]; stillExists { delete(WebSocketClients, c) delete(WebSocketClientWriteMutexes, c) - fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER-V4] Removed client %v from maps.\n", c.RemoteAddr()) + fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER] Removed client %v from maps.\n", c.RemoteAddr()) } else { - fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER-V4] Client %v already removed by another process.\n", c.RemoteAddr()) + fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER] Client %v already removed by another process.\n", c.RemoteAddr()) } WebSocketClientsMutex.Unlock() c.Close() // Close the connection outside the lock } else { - fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER-V4] Successfully sent to client %v\n", c.RemoteAddr()) + fmt.Fprintf(os.Stderr, "[DEBUG-BROADCASTER] Successfully sent to client %v\n", c.RemoteAddr()) } }(client, mutex, logEntry) }