feat: Implement reference value types reordering and confidence level sorting
- Added a new API endpoint for reordering reference value types based on user-defined order. - Updated the AdminReferenceValueTypesPage to allow users to reorder types using up/down buttons. - Introduced a consistent confidence level sorting mechanism across the application. - Refactored related components to remove unused sort order fields and improve user experience.
This commit is contained in:
1 parent
45e4e64f15
commit
296e79c3b3
7 files changed
+149
-31
No files matched your search
@@ -5,6 +5,36 @@ export function setProfileId(id) { _profileId = id }
|
||||
|
||||
const BASE = '/api'
|
||||
|
||||
/**
|
||||
* FastAPI-Fehler: `detail` kann String, Objekt oder Validierungs-Array sein.
|
||||
*/
|
||||
export function formatFastApiDetail(detail, fallback = '') {
|
||||
if (detail == null || detail === '') {
|
||||
return fallback || 'Anfrage fehlgeschlagen'
|
||||
}
|
||||
if (typeof detail === 'string') {
|
||||
return detail
|
||||
}
|
||||
if (Array.isArray(detail)) {
|
||||
const parts = detail.map((e) => {
|
||||
if (typeof e === 'string') return e
|
||||
if (e && typeof e === 'object') {
|
||||
const loc = Array.isArray(e.loc) ? e.loc.filter((x) => x != null && x !== '').join('.') : ''
|
||||
const msg = e.msg || e.message || ''
|
||||
if (loc && msg) return `${loc}: ${msg}`
|
||||
return msg || loc || ''
|
||||
}
|
||||
return String(e)
|
||||
}).filter(Boolean)
|
||||
return parts.length ? parts.join(' · ') : fallback || 'Validierungsfehler'
|
||||
}
|
||||
if (typeof detail === 'object') {
|
||||
if (typeof detail.msg === 'string') return detail.msg
|
||||
if (typeof detail.message === 'string') return detail.message
|
||||
}
|
||||
return fallback || 'Anfrage fehlgeschlagen'
|
||||
}
|
||||
|
||||
function hdrs(extra={}) {
|
||||
const h = {...extra}
|
||||
if (_profileId) h['X-Profile-Id'] = _profileId
|
||||
@@ -16,14 +46,14 @@ function hdrs(extra={}) {
|
||||
async function req(path, opts={}) {
|
||||
const res = await fetch(BASE+path, {...opts, headers:hdrs(opts.headers||{})})
|
||||
if (!res.ok) {
|
||||
const err = await res.text()
|
||||
// Try to parse JSON error with detail field
|
||||
const errText = await res.text()
|
||||
let parsed = null
|
||||
try {
|
||||
const parsed = JSON.parse(err)
|
||||
throw new Error(parsed.detail || err)
|
||||
parsed = JSON.parse(errText)
|
||||
} catch {
|
||||
throw new Error(err)
|
||||
throw new Error(errText.trim() || `HTTP ${res.status}`)
|
||||
}
|
||||
throw new Error(formatFastApiDetail(parsed.detail, errText.trim() || `HTTP ${res.status}`))
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
@@ -54,6 +84,12 @@ export const api = {
|
||||
adminCreateReferenceValueType: (d) => req('/admin/reference-value-types', json(d)),
|
||||
adminUpdateReferenceValueType: (id, d) => req(`/admin/reference-value-types/${id}`, jput(d)),
|
||||
adminDeleteReferenceValueType: (id) => req(`/admin/reference-value-types/${id}`, { method: 'DELETE' }),
|
||||
adminReorderReferenceValueTypes: (orderedIds) =>
|
||||
req('/admin/reference-value-types/reorder', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ordered_ids: orderedIds }),
|
||||
}),
|
||||
|
||||
// Weight
|
||||
listWeight: (l=365) => req(`/weight?limit=${l}`),
|
||||
@@ -85,7 +121,7 @@ export const api = {
|
||||
importActivityCsv: async(file)=>{
|
||||
const fd=new FormData();fd.append('file',file)
|
||||
const r=await fetch(`${BASE}/activity/import-csv`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const d=await r.json();if(!r.ok)throw new Error(d.detail||JSON.stringify(d));return d
|
||||
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
|
||||
},
|
||||
|
||||
// Photos
|
||||
@@ -103,7 +139,7 @@ export const api = {
|
||||
importCsv: async(file)=>{
|
||||
const fd=new FormData();fd.append('file',file)
|
||||
const r=await fetch(`${BASE}/nutrition/import-csv`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const d=await r.json();if(!r.ok)throw new Error(d.detail||JSON.stringify(d));return d
|
||||
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
|
||||
},
|
||||
listNutrition: (l=365) => req(`/nutrition?limit=${l}`),
|
||||
nutritionCorrelations: () => req('/nutrition/correlations'),
|
||||
|
||||
Reference in new issue
Block a user