feat: add folder filtering support to job reports and update UI filters
Build / Build and Push Docker Image (push) Successful in 50s
Build / Build and Upload Binary (push) Successful in 22s

This commit is contained in:
2026-06-10 23:20:40 +01:00
parent 8506dfd7f1
commit d5b4df9d56
3 changed files with 58 additions and 9 deletions
+16 -4
View File
@@ -2,6 +2,7 @@ package db
import (
"database/sql"
"strings"
)
// Watch Folders
@@ -151,21 +152,32 @@ func AddJobReport(j Job, status string, encodedSize int64, sizeSaved int64, proc
return err
}
func GetJobReports(limit, offset int, statusFilter string) ([]JobReport, int, error) {
func GetJobReports(limit, offset int, statusFilter string, folderFilter string) ([]JobReport, int, error) {
var total int
queryArgs := []interface{}{}
countQuery := `SELECT COUNT(*) FROM job_reports`
selectQuery := `SELECT id, file_path, media_type, status, original_size, encoded_size, size_saved, processing_time, target_resolution, ffmpeg_flags, error_message, created_at FROM job_reports`
whereClause := ""
whereClauses := []string{}
if statusFilter != "" && statusFilter != "all" {
if statusFilter == "exclude_skipped" {
whereClause = ` WHERE status != 'skipped'`
whereClauses = append(whereClauses, `status != 'skipped'`)
} else {
whereClause = ` WHERE status = ?`
whereClauses = append(whereClauses, `status = ?`)
queryArgs = append(queryArgs, statusFilter)
}
}
if folderFilter != "" && folderFilter != "all" {
whereClauses = append(whereClauses, `(file_path LIKE ? OR file_path = ?)`)
queryArgs = append(queryArgs, folderFilter+"/%", folderFilter)
}
whereClause := ""
if len(whereClauses) > 0 {
whereClause = " WHERE " + strings.Join(whereClauses, " AND ")
}
if err := DB.QueryRow(countQuery+whereClause, queryArgs...).Scan(&total); err != nil {
return nil, 0, err
+20 -1
View File
@@ -281,6 +281,7 @@ func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
limitStr := r.URL.Query().Get("limit")
pageStr := r.URL.Query().Get("page")
statusFilter := r.URL.Query().Get("status")
folderFilterIDStr := r.URL.Query().Get("folder")
limit := 50
if l, err := strconv.Atoi(limitStr); err == nil && l > 0 {
@@ -294,7 +295,21 @@ func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
offset := (page - 1) * limit
reports, total, err := db.GetJobReports(limit, offset, statusFilter)
folders, _ := db.GetWatchFolders()
folderFilterPath := ""
folderFilterID := 0
if fID, err := strconv.Atoi(folderFilterIDStr); err == nil && fID > 0 {
folderFilterID = fID
for _, f := range folders {
if f.ID == fID {
folderFilterPath = f.FolderPath
break
}
}
}
reports, total, err := db.GetJobReports(limit, offset, statusFilter, folderFilterPath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -316,6 +331,8 @@ func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
PrevPage int
NextPage int
FilterStatus string
FilterFolder int
Folders []db.WatchFolder
Limit int
}{
AuthEnabled: s.cfg.Auth.Username != "",
@@ -328,6 +345,8 @@ func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
PrevPage: page - 1,
NextPage: page + 1,
FilterStatus: statusFilter,
FilterFolder: folderFilterID,
Folders: folders,
Limit: limit,
}