Enhance admin UI and schema management: Introduce generic handling for image/asset URL fields, ensuring explicit widget usage for image previews. Update translations for new UI elements and implement field ordering in schema definitions. Add functionality for managing field extensions and improve asset filtering in the admin UI.
This commit is contained in:
@@ -368,6 +368,51 @@ pub async fn get_collection_schema(
|
||||
Ok(Json(serde_json::to_value(schema).unwrap()))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GET /api/schemas – list all type names (including reusable, for extends dropdown)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_schema_names(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Json<Value> {
|
||||
let names: Vec<String> = {
|
||||
let registry = state.registry.read().await;
|
||||
registry.names()
|
||||
};
|
||||
Json(json!({ "names": names }))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GET /api/schemas/:name/raw – schema as stored on disk (own fields + extends, unresolved)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn get_schema_raw(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Path(name): Path<String>,
|
||||
) -> Result<Json<Value>, ApiError> {
|
||||
let path_json5 = state.types_dir.join(format!("{}.json5", name));
|
||||
let path_json = state.types_dir.join(format!("{}.json", name));
|
||||
let path = if path_json5.exists() {
|
||||
path_json5
|
||||
} else if path_json.exists() {
|
||||
path_json
|
||||
} else {
|
||||
return Err(ApiError::NotFound(format!("Schema '{}' not found", name)));
|
||||
};
|
||||
let content = tokio::fs::read_to_string(&path)
|
||||
.await
|
||||
.map_err(|e| ApiError::Internal(format!("Failed to read schema file: {}", e)))?;
|
||||
let schema: SchemaDefinition = json5::from_str(&content)
|
||||
.map_err(|e| ApiError::BadRequest(format!("Invalid schema file: {}", e)))?;
|
||||
if schema.name != name {
|
||||
return Err(ApiError::BadRequest(format!(
|
||||
"Schema file name mismatch: expected '{}', got '{}'",
|
||||
name, schema.name
|
||||
)));
|
||||
}
|
||||
Ok(Json(serde_json::to_value(schema).unwrap()))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GET /api/collections/:collection/slug-check?slug=xxx&exclude=yyy&_locale=zzz
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -23,7 +23,11 @@ pub fn create_router(state: Arc<AppState>) -> Router {
|
||||
.route("/api-docs/openapi.json", get(openapi::openapi_json))
|
||||
// Collection schema endpoints
|
||||
.route("/api/collections", get(handlers::list_collections))
|
||||
.route("/api/schemas", post(handlers::create_schema))
|
||||
.route(
|
||||
"/api/schemas",
|
||||
get(handlers::list_schema_names).post(handlers::create_schema),
|
||||
)
|
||||
.route("/api/schemas/:name/raw", get(handlers::get_schema_raw))
|
||||
.route(
|
||||
"/api/schemas/:name",
|
||||
put(handlers::update_schema).delete(handlers::delete_schema),
|
||||
|
||||
@@ -84,6 +84,10 @@ pub struct SchemaDefinition {
|
||||
#[serde(rename = "defaultOrder", skip_serializing_if = "Option::is_none", default)]
|
||||
pub default_order: Option<String>,
|
||||
|
||||
/// Optional order of field names for admin UI. Not all fields need to be listed; any missing appear after.
|
||||
#[serde(rename = "fieldOrder", skip_serializing_if = "Option::is_none", default)]
|
||||
pub field_order: Option<Vec<String>>,
|
||||
|
||||
pub fields: IndexMap<String, FieldDefinition>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user