feat(manager): built-in collection in the Media page and picker; signage screen settings in Devices (platform-v2 step 5.4a)
Media page and picker filter Everything / Your own / Built-in; built-in items are marked and can't be renamed or deleted. The Devices page offers the playlists for a signage screen (with its orientation and rotation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,7 +59,7 @@ export default function MediaDetails({ id, onClose, onChanged, onDeleted }) {
|
||||
<Button variant="secondary" onClick={() => setConfirm(false)}>{t('fees.cancel')}</Button>
|
||||
<Button variant="danger" loading={busy} onClick={remove} data-testid="media-delete-confirm">{t('media.delete')}</Button>
|
||||
</> : <>
|
||||
<Button variant="ghost" icon={<Trash2 size={16} />} disabled={busy || used.length > 0} onClick={() => setConfirm(true)}
|
||||
<Button variant="ghost" icon={<Trash2 size={16} />} disabled={busy || used.length > 0 || item.builtin} onClick={() => setConfirm(true)}
|
||||
className="mr-auto" data-testid="media-delete">{t('media.delete')}</Button>
|
||||
<Button variant="secondary" onClick={onClose}>{t('media.close')}</Button>
|
||||
</>}
|
||||
@@ -75,12 +75,12 @@ export default function MediaDetails({ id, onClose, onChanged, onDeleted }) {
|
||||
<div className="grid gap-1">
|
||||
<div className="flex gap-2 items-end">
|
||||
<Field label={t('media.displayName')} className="flex-1">
|
||||
<Input value={name} maxLength={120} onChange={e => setName(e.target.value)} data-testid="media-name" />
|
||||
<Input value={name} maxLength={120} disabled={item.builtin} onChange={e => setName(e.target.value)} data-testid="media-name" />
|
||||
</Field>
|
||||
<Button variant="secondary" loading={busy} disabled={!name.trim() || name.trim() === item.name} onClick={save}
|
||||
<Button variant="secondary" loading={busy} disabled={item.builtin || !name.trim() || name.trim() === item.name} onClick={save}
|
||||
data-testid="media-rename">{t('media.saveName')}</Button>
|
||||
</div>
|
||||
<p className="text-caption text-ink-3">{t('media.displayNameHint')}</p>
|
||||
<p className="text-caption text-ink-3">{t(item.builtin ? 'media.builtinHint' : 'media.displayNameHint')}</p>
|
||||
</div>
|
||||
|
||||
<dl className="grid gap-x-4 gap-y-1 text-label" style={{ gridTemplateColumns: 'max-content 1fr' }}>
|
||||
|
||||
@@ -17,6 +17,7 @@ import { useUploadQueue } from './mediaHooks'
|
||||
export default function MediaPage() {
|
||||
const { t } = useTranslation('manager')
|
||||
const [kind, setKind] = useState('')
|
||||
const [collection, setCollection] = useState('')
|
||||
const [q, setQ] = useState('')
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(null)
|
||||
@@ -28,8 +29,8 @@ export default function MediaPage() {
|
||||
useEffect(() => { const h = setTimeout(() => setSearch(q.trim()), 250); return () => clearTimeout(h) }, [q])
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try { setPage(await listMedia({ kind, q: search })); setError(null) } catch (err) { setError(errorMessage(err, t)) }
|
||||
}, [kind, search, t])
|
||||
try { setPage(await listMedia({ kind, q: search, collection })); setError(null) } catch (err) { setError(errorMessage(err, t)) }
|
||||
}, [kind, search, collection, t])
|
||||
useEffect(() => { load() }, [load])
|
||||
|
||||
// Each finished upload shows at once; the list is read again when the batch is done.
|
||||
@@ -68,6 +69,8 @@ export default function MediaPage() {
|
||||
<Input value={q} onChange={e => setQ(e.target.value)} placeholder={t('media.search')} aria-label={t('media.search')}
|
||||
className="flex-1 sm:w-56" data-testid="media-search" />
|
||||
<Select value={kind} onChange={e => setKind(e.target.value)} options={kinds} aria-label={t('media.kind')} data-testid="media-kind" />
|
||||
<Select value={collection} onChange={e => setCollection(e.target.value)} aria-label={t('media.collection')} data-testid="media-collection"
|
||||
options={[{ value: '', label: t('media.collections.all') }, { value: 'own', label: t('media.collections.own') }, { value: 'builtin', label: t('media.collections.builtin') }]} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -75,7 +78,7 @@ export default function MediaPage() {
|
||||
|
||||
{error ? <EmptyState title={error} />
|
||||
: !page ? <div className="flex justify-center p-6"><Spinner /></div>
|
||||
: page.items.length === 0 ? <EmptyState title={t(search || kind ? 'media.noMatch' : 'media.empty')} description={search || kind ? undefined : t('media.emptyHint')} />
|
||||
: page.items.length === 0 ? <EmptyState title={t(search || kind || collection ? 'media.noMatch' : 'media.empty')} description={search || kind || collection ? undefined : t('media.emptyHint')} />
|
||||
: <>
|
||||
<p className="text-label text-ink-3" data-testid="media-count">{t('media.count', { count: page.total })}</p>
|
||||
<MediaGrid items={page.items} onOpen={item => setOpen(item.id)} />
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useTranslation } from '@xenia/i18n'
|
||||
import { cx } from '@xenia/ui'
|
||||
import { useMediaMeta } from './mediaHooks'
|
||||
|
||||
/** The small picture of a library item (a film mark for videos, which have no still frame yet: 5.4b). */
|
||||
/** The small picture of a library item (a film mark for videos, which have no still frame yet: 5.4e). */
|
||||
export function MediaThumb({ item, className }) {
|
||||
const [broken, setBroken] = useState(false)
|
||||
if (item?.kind === 'video') {
|
||||
@@ -20,6 +20,7 @@ export function MediaThumb({ item, className }) {
|
||||
|
||||
/** A grid of library items; `selectedId` marks one, `selectedIds` (a Set) several (the picker). */
|
||||
export function MediaGrid({ items, onOpen, selectedId, selectedIds, testid = 'media-grid' }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const meta = useMediaMeta()
|
||||
return (
|
||||
<ul className="grid gap-3" style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(9.5rem, 1fr))' }} data-testid={testid}>
|
||||
@@ -31,6 +32,7 @@ export function MediaGrid({ items, onOpen, selectedId, selectedIds, testid = 'me
|
||||
selectedId === item.id || selectedIds?.has(item.id) ? 'border-accent ring-2 ring-accent' : 'border-line')}>
|
||||
<MediaThumb item={item} className="w-full aspect-square" />
|
||||
<span className="block px-2 pt-1.5 text-label font-medium text-ink truncate" title={item.name}>{item.name}</span>
|
||||
{item.builtin && <span className="block px-2 text-caption text-info-ink" data-testid="media-builtin">{t('media.builtin')}</span>}
|
||||
<span className="block px-2 pb-2 text-caption text-ink-3 truncate">{meta(item)}</span>
|
||||
</button>
|
||||
</li>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { Upload } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Input, Spinner } from '@xenia/ui'
|
||||
import { Button, Dialog, EmptyState, Input, Select, Spinner } from '@xenia/ui'
|
||||
import { listMedia } from './mediaApi'
|
||||
import { ACCEPT } from './mediaLogic'
|
||||
import { MediaGrid, UploadQueue } from './MediaParts'
|
||||
@@ -14,6 +14,7 @@ import { useUploadQueue } from './mediaHooks'
|
||||
export default function MediaPicker({ open, onClose, onPick, onPickMany, multiple = false, kind = 'image', selectedId }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [q, setQ] = useState('')
|
||||
const [collection, setCollection] = useState('')
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
@@ -25,9 +26,9 @@ export default function MediaPicker({ open, onClose, onPick, onPickMany, multipl
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
let live = true
|
||||
listMedia({ kind, q: search }).then(p => { if (live) { setPage(p); setError(null) } }).catch(err => live && setError(errorMessage(err, t)))
|
||||
listMedia({ kind, q: search, collection }).then(p => { if (live) { setPage(p); setError(null) } }).catch(err => live && setError(errorMessage(err, t)))
|
||||
return () => { live = false }
|
||||
}, [open, kind, search, t])
|
||||
}, [open, kind, search, collection, t])
|
||||
|
||||
const { queue, add, clear, summary } = useUploadQueue(useCallback(item => {
|
||||
setPage(p => (p && !p.items.some(x => x.id === item.id) ? { ...p, items: [item, ...p.items], total: p.total + 1 } : p))
|
||||
@@ -46,6 +47,8 @@ export default function MediaPicker({ open, onClose, onPick, onPickMany, multipl
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Input value={q} onChange={e => setQ(e.target.value)} placeholder={t('media.search')} aria-label={t('media.search')}
|
||||
className="flex-1 min-w-[10rem]" data-testid="media-picker-search" />
|
||||
<Select value={collection} onChange={e => setCollection(e.target.value)} aria-label={t('media.collection')} data-testid="media-picker-collection"
|
||||
options={[{ value: '', label: t('media.collections.all') }, { value: 'own', label: t('media.collections.own') }, { value: 'builtin', label: t('media.collections.builtin') }]} />
|
||||
<Button variant="secondary" icon={<Upload size={16} />} onClick={() => input.current?.click()} disabled={summary.busy}>{t('media.uploadNew')}</Button>
|
||||
<input ref={input} type="file" accept={kind === 'image' ? ACCEPT.split(',').filter(a => a.startsWith('image/')).join(',') : ACCEPT}
|
||||
className="sr-only" data-testid="media-picker-file" multiple={multiple} onChange={e => { if (e.target.files?.length) add(multiple ? e.target.files : [e.target.files[0]]); e.target.value = '' }} />
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// The media library's API (backend: local_backend/routers/media.py, plan steps 5.1 / 5.2).
|
||||
import client from '../../api/client'
|
||||
|
||||
export const listMedia = ({ kind, q, limit = 500 } = {}) =>
|
||||
client.get('/api/media', { params: { kind: kind || undefined, q: q || undefined, limit } }).then(r => r.data)
|
||||
export const listMedia = ({ kind, q, collection, limit = 500 } = {}) =>
|
||||
client.get('/api/media', { params: { kind: kind || undefined, q: q || undefined, collection: collection || undefined, limit } }).then(r => r.data)
|
||||
|
||||
export const getMedia = id => client.get(`/api/media/${id}`).then(r => r.data)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import client from '../../api/client'
|
||||
import { configGroups, configValue, refOptions } from './devicesLogic'
|
||||
|
||||
// Where a `ref` field's choices come from (the device list is passed in)
|
||||
const REF_URLS = { prep_zones: '/api/prep-zones', categories: '/api/products/categories', printers: '/api/system/printers', display_looks: '/api/display/looks' }
|
||||
const REF_URLS = { prep_zones: '/api/prep-zones', categories: '/api/products/categories', printers: '/api/system/printers', display_looks: '/api/display/looks', signage_playlists: '/api/signage/playlists' }
|
||||
|
||||
export default function DeviceConfigFields({ appKey, fields = [], value, onChange, devices = [], selfId = null }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -29,6 +29,7 @@ export default function DeviceConfigFields({ appKey, fields = [], value, onChang
|
||||
const categories = lists.categories ?? []
|
||||
const printers = lists.printers ?? []
|
||||
const looks = lists.display_looks ?? []
|
||||
const playlists = lists.signage_playlists ?? []
|
||||
|
||||
if (!fields.length) return null
|
||||
const base = key => `modules:${appKey}.config.${key}`
|
||||
@@ -54,7 +55,7 @@ export default function DeviceConfigFields({ appKey, fields = [], value, onChang
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
|
||||
options={[{ value: '', label: t(`${base(f.key)}.none`, { defaultValue: t('devices.form.none') }) },
|
||||
...refOptions(f, { zones, categories, printers, looks, devices, selfId })]} />
|
||||
...refOptions(f, { zones, categories, printers, looks, playlists, devices, selfId })]} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,8 @@ export function configGroups(fields = []) {
|
||||
}
|
||||
|
||||
/** Options of a `ref` field: prep zones, categories, printers, customer display looks, or live devices of one app ("devices:<app>"). */
|
||||
export function refOptions(field, { zones = [], categories = [], printers = [], looks = [], devices = [], selfId = null } = {}) {
|
||||
export function refOptions(field, { zones = [], categories = [], printers = [], looks = [], playlists = [], devices = [], selfId = null } = {}) {
|
||||
if (field.choices_from === 'signage_playlists') return playlists.map(p => ({ value: String(p.id), label: p.name }))
|
||||
if (field.choices_from === 'display_looks') return looks.map(l => ({ value: String(l.id), label: l.name }))
|
||||
if (field.choices_from === 'prep_zones') return zones.map(z => ({ value: String(z.id), label: z.name }))
|
||||
if (field.choices_from === 'categories') return categories.map(c => ({ value: String(c.id), label: c.name }))
|
||||
|
||||
@@ -796,6 +796,14 @@
|
||||
"nameAfterProduct": "Ονομασία με το όνομα του προϊόντος",
|
||||
"nameAfterCategory": "Ονομασία με το όνομα της κατηγορίας",
|
||||
"addChosen_one": "Προσθήκη {{count}} εικόνας",
|
||||
"addChosen_other": "Προσθήκη {{count}} εικόνων"
|
||||
"addChosen_other": "Προσθήκη {{count}} εικόνων",
|
||||
"collection": "Συλλογή",
|
||||
"collections": {
|
||||
"all": "Όλα",
|
||||
"own": "Δικά σας",
|
||||
"builtin": "Ενσωματωμένα"
|
||||
},
|
||||
"builtin": "Ενσωματωμένο",
|
||||
"builtinHint": "Οι ενσωματωμένες εικόνες έρχονται με το Xenia: χρησιμοποιούνται παντού, αλλά δεν μετονομάζονται ούτε διαγράφονται."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,6 +796,14 @@
|
||||
"nameAfterProduct": "Name it after the product",
|
||||
"nameAfterCategory": "Name it after the category",
|
||||
"addChosen_one": "Add {{count}} picture",
|
||||
"addChosen_other": "Add {{count}} pictures"
|
||||
"addChosen_other": "Add {{count}} pictures",
|
||||
"collection": "Collection",
|
||||
"collections": {
|
||||
"all": "Everything",
|
||||
"own": "Your own",
|
||||
"builtin": "Built-in"
|
||||
},
|
||||
"builtin": "Built-in",
|
||||
"builtinHint": "Built-in pictures come with Xenia: they can be used anywhere, but not renamed or deleted."
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user