feat: add folder filtering support to job reports and update UI filters
This commit is contained in:
+16
-4
@@ -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
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user