feat(admin): 分区增加「允许子分组」开关(与类型解耦)
- node 新增 allow_groups(迁移 v18):应用默认开、海报/图文默认关,已有分组的非应用分区自动开启 - 后台每行一个「子分组」开关;分组管理、卡片预览、内容弹窗选组、侧栏建组都跟随开关 - 关闭开关时条目平铺且不丢内容;首页卡片指向分组会自动挪回分区 - 三种类型共用同一模板,类型只决定渲染方式 - 测试 59 passed(迁移 15→18、开关建组、类型切换)
This commit is contained in:
+7
-4
@@ -25,6 +25,7 @@ struct NodeRow {
|
||||
preview_limit: Option<i64>,
|
||||
empty_text: Option<String>,
|
||||
show_in_sidebar: bool,
|
||||
allow_groups: bool,
|
||||
}
|
||||
|
||||
/// 条目行:与 `entry` 表的列一一对应
|
||||
@@ -56,7 +57,7 @@ pub fn load(conn: &Connection) -> Result<Catalog, StashError> {
|
||||
fn load_sections(conn: &Connection) -> Result<Vec<Value>, StashError> {
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
"SELECT key, title, view_mode, bar_color, icon, preview_limit, empty_text, show_in_sidebar
|
||||
"SELECT key, title, view_mode, bar_color, icon, preview_limit, empty_text, show_in_sidebar, allow_groups
|
||||
FROM node
|
||||
WHERE kind = 'section'
|
||||
ORDER BY sort, key",
|
||||
@@ -74,6 +75,7 @@ fn load_sections(conn: &Connection) -> Result<Vec<Value>, StashError> {
|
||||
preview_limit: row.get(5)?,
|
||||
empty_text: row.get(6)?,
|
||||
show_in_sidebar: row.get(7)?,
|
||||
allow_groups: row.get(8)?,
|
||||
})
|
||||
})
|
||||
.map_err(map_error)?
|
||||
@@ -159,6 +161,7 @@ fn build_section(
|
||||
);
|
||||
object.insert("icon".into(), json!(section.icon.clone().unwrap_or_default()));
|
||||
object.insert("showInSidebar".into(), json!(section.show_in_sidebar));
|
||||
object.insert("allowGroups".into(), json!(section.allow_groups));
|
||||
|
||||
// 可选字段:没配就不下发,交给前端用 `?? 默认值` 处理
|
||||
if let Some(limit) = section.preview_limit {
|
||||
@@ -181,9 +184,9 @@ fn build_section(
|
||||
}
|
||||
}
|
||||
|
||||
// 应用类:分区 → 分组 → 条目;海报 / 图文是平铺列表,分组不参与渲染
|
||||
// 「允许子分组」开启:分区 → 分组 → 条目;关闭:全部条目平铺
|
||||
let tags = load_tags(conn, §ion.key)?;
|
||||
if view_mode == "apps" {
|
||||
if section.allow_groups {
|
||||
object.insert(
|
||||
"groups".into(),
|
||||
build_groups(conn, section, view_mode, &tags)?,
|
||||
@@ -196,7 +199,7 @@ fn build_section(
|
||||
object.insert("items".into(), json!(items));
|
||||
} else {
|
||||
object.insert("groups".into(), json!([]));
|
||||
// 平铺:把(可能存在的)分组里的条目一起取出来,切换类型时不丢内容
|
||||
// 平铺:把(可能存在的)分组里的条目一起取出来,关闭开关时不丢内容
|
||||
let entries = load_section_entries(conn, §ion.key)?;
|
||||
let items = entries
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user