Pools now store a sort setting (sort_key + sort_order). "manual" keeps the user-arranged order in file_pool.position and allows drag-to-reorder; any other key (content_datetime, created, original_name) sorts the pool's files automatically server-side, in which case reordering is rejected. Manual order is always ascending by position — direction does not apply. Backend: add the columns (sort_key defaults to 'manual'), generalise the pool-files keyset cursor to page by the active sort, persist the setting on create/update, and guard reorder against non-manual pools. Frontend: a sort dropdown (+ direction toggle) on the pool page that PATCHes the pool and reloads; drag-to-reorder is disabled unless the pool is manual. Closes the "automatic sorting in pools" requirement (REQUIREMENTS.md §4.6.5). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,32 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Pool file sort keys. PoolSortManual keeps the user-defined order in
|
||||
// file_pool.position; the others sort the pool's files by that file field.
|
||||
const (
|
||||
PoolSortManual = "manual"
|
||||
PoolSortContentDatetime = "content_datetime"
|
||||
PoolSortCreated = "created"
|
||||
PoolSortOriginalName = "original_name"
|
||||
|
||||
SortOrderAsc = "asc"
|
||||
SortOrderDesc = "desc"
|
||||
)
|
||||
|
||||
// ValidPoolSortKey reports whether s is an accepted pool sort key.
|
||||
func ValidPoolSortKey(s string) bool {
|
||||
switch s {
|
||||
case PoolSortManual, PoolSortContentDatetime, PoolSortCreated, PoolSortOriginalName:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidSortOrder reports whether s is an accepted sort direction.
|
||||
func ValidSortOrder(s string) bool {
|
||||
return s == SortOrderAsc || s == SortOrderDesc
|
||||
}
|
||||
|
||||
// Pool is an ordered collection of files.
|
||||
type Pool struct {
|
||||
ID uuid.UUID
|
||||
@@ -16,6 +42,11 @@ type Pool struct {
|
||||
CreatorID int16
|
||||
CreatorName string // denormalized
|
||||
IsPublic bool
|
||||
// SortKey / SortOrder control how the pool's files are ordered. When SortKey
|
||||
// is PoolSortManual, files follow the manual position order and can be
|
||||
// reordered; otherwise they are sorted automatically and reordering is a no-op.
|
||||
SortKey string
|
||||
SortOrder string
|
||||
FileCount int
|
||||
CreatedAt time.Time // extracted from UUID v7 via UUIDCreatedAt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user