feat: first take at milestone M3
This commit is contained in:
104
crates/bds-ui/src/views/dashboard.rs
Normal file
104
crates/bds-ui/src/views/dashboard.rs
Normal file
@@ -0,0 +1,104 @@
|
||||
use iced::widget::{column, container, row, text, Space};
|
||||
use iced::{Alignment, Background, Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
/// Dashboard overview state.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DashboardState {
|
||||
pub post_count: usize,
|
||||
pub media_count: usize,
|
||||
pub template_count: usize,
|
||||
pub script_count: usize,
|
||||
pub draft_count: usize,
|
||||
pub published_count: usize,
|
||||
pub project_name: String,
|
||||
}
|
||||
|
||||
impl DashboardState {
|
||||
pub fn new(project_name: String) -> Self {
|
||||
Self {
|
||||
post_count: 0,
|
||||
media_count: 0,
|
||||
template_count: 0,
|
||||
script_count: 0,
|
||||
draft_count: 0,
|
||||
published_count: 0,
|
||||
project_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Render the dashboard overview.
|
||||
pub fn view<'a>(
|
||||
state: &'a DashboardState,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
let header = text(t(locale, "dashboard.overview"))
|
||||
.size(20)
|
||||
.color(Color::WHITE);
|
||||
|
||||
let project_label = text(state.project_name.clone())
|
||||
.size(14)
|
||||
.color(Color::from_rgb(0.6, 0.6, 0.7));
|
||||
|
||||
let counts_row = row![
|
||||
stat_card(&t(locale, "dashboard.posts"), state.post_count),
|
||||
stat_card(&t(locale, "dashboard.media"), state.media_count),
|
||||
stat_card(&t(locale, "dashboard.templates"), state.template_count),
|
||||
stat_card(&t(locale, "dashboard.scripts"), state.script_count),
|
||||
]
|
||||
.spacing(16);
|
||||
|
||||
let status_row = row![
|
||||
stat_card(&t(locale, "dashboard.drafts"), state.draft_count),
|
||||
stat_card(&t(locale, "dashboard.published"), state.published_count),
|
||||
]
|
||||
.spacing(16);
|
||||
|
||||
container(
|
||||
column![
|
||||
header,
|
||||
project_label,
|
||||
Space::with_height(16),
|
||||
inputs::section_header(&t(locale, "dashboard.entityCounts")),
|
||||
counts_row,
|
||||
Space::with_height(12),
|
||||
inputs::section_header(&t(locale, "dashboard.statusCounts")),
|
||||
status_row,
|
||||
]
|
||||
.spacing(8)
|
||||
.padding(24)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn stat_card<'a>(label: &str, count: usize) -> Element<'a, Message> {
|
||||
let card_bg = Color::from_rgb(0.15, 0.16, 0.20);
|
||||
container(
|
||||
column![
|
||||
text(count.to_string()).size(28).color(Color::WHITE),
|
||||
text(label.to_string()).size(12).color(Color::from_rgb(0.55, 0.58, 0.65)),
|
||||
]
|
||||
.spacing(4)
|
||||
.align_x(Alignment::Center),
|
||||
)
|
||||
.padding(16)
|
||||
.width(Length::FillPortion(1))
|
||||
.style(move |_: &Theme| container::Style {
|
||||
background: Some(Background::Color(card_bg)),
|
||||
border: iced::Border {
|
||||
radius: 8.0.into(),
|
||||
..iced::Border::default()
|
||||
},
|
||||
..container::Style::default()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
208
crates/bds-ui/src/views/media_editor.rs
Normal file
208
crates/bds-ui/src/views/media_editor.rs
Normal file
@@ -0,0 +1,208 @@
|
||||
use std::path::Path;
|
||||
|
||||
use iced::widget::{button, column, container, image, row, scrollable, text, Space};
|
||||
use iced::{Color, Element, Length};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
use bds_core::model::Media;
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
/// State for an open media editor.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MediaEditorState {
|
||||
pub media_id: String,
|
||||
pub filename: String,
|
||||
pub original_name: String,
|
||||
pub mime_type: String,
|
||||
pub size: i64,
|
||||
pub width: Option<i32>,
|
||||
pub height: Option<i32>,
|
||||
pub title: String,
|
||||
pub alt: String,
|
||||
pub caption: String,
|
||||
pub author: String,
|
||||
pub language: String,
|
||||
pub file_path: String,
|
||||
pub tags: Vec<String>,
|
||||
pub created_at: i64,
|
||||
pub updated_at: i64,
|
||||
pub is_dirty: bool,
|
||||
}
|
||||
|
||||
impl MediaEditorState {
|
||||
pub fn from_media(media: &Media) -> Self {
|
||||
Self {
|
||||
media_id: media.id.clone(),
|
||||
filename: media.filename.clone(),
|
||||
original_name: media.original_name.clone(),
|
||||
mime_type: media.mime_type.clone(),
|
||||
size: media.size,
|
||||
width: media.width,
|
||||
height: media.height,
|
||||
title: media.title.clone().unwrap_or_default(),
|
||||
alt: media.alt.clone().unwrap_or_default(),
|
||||
caption: media.caption.clone().unwrap_or_default(),
|
||||
author: media.author.clone().unwrap_or_default(),
|
||||
language: media.language.clone().unwrap_or_default(),
|
||||
file_path: media.file_path.clone(),
|
||||
tags: media.tags.clone(),
|
||||
created_at: media.created_at,
|
||||
updated_at: media.updated_at,
|
||||
is_dirty: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Media editor messages.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum MediaEditorMsg {
|
||||
TitleChanged(String),
|
||||
AltChanged(String),
|
||||
CaptionChanged(String),
|
||||
AuthorChanged(String),
|
||||
Save,
|
||||
Delete,
|
||||
}
|
||||
|
||||
/// Render the media editor view.
|
||||
pub fn view<'a>(
|
||||
state: &'a MediaEditorState,
|
||||
locale: UiLocale,
|
||||
data_dir: Option<&Path>,
|
||||
) -> Element<'a, Message> {
|
||||
let header = inputs::toolbar(
|
||||
vec![
|
||||
text(state.original_name.clone()).size(18).into(),
|
||||
],
|
||||
vec![
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::MediaEditor(MediaEditorMsg::Save))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "modal.confirmDelete.delete")).size(13))
|
||||
.on_press(Message::MediaEditor(MediaEditorMsg::Delete))
|
||||
.style(inputs::danger_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
],
|
||||
);
|
||||
|
||||
// Preview section
|
||||
let preview: Element<'a, Message> = if state.mime_type.starts_with("image/") {
|
||||
if let Some(dir) = data_dir {
|
||||
let img_path = dir.join(&state.file_path);
|
||||
if img_path.exists() {
|
||||
container(
|
||||
image(img_path.to_string_lossy().to_string())
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fixed(300.0)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
} else {
|
||||
no_preview()
|
||||
}
|
||||
} else {
|
||||
no_preview()
|
||||
}
|
||||
} else {
|
||||
no_preview()
|
||||
};
|
||||
|
||||
// File info
|
||||
let dimensions = match (state.width, state.height) {
|
||||
(Some(w), Some(h)) => format!("{w} × {h}"),
|
||||
_ => String::new(),
|
||||
};
|
||||
let size_str = format_file_size(state.size);
|
||||
let info = row![
|
||||
text(format!("{} • {} • {}", state.mime_type, size_str, dimensions))
|
||||
.size(12)
|
||||
.color(Color::from_rgb(0.55, 0.58, 0.65)),
|
||||
]
|
||||
.padding(8);
|
||||
|
||||
// Metadata fields
|
||||
let title_input = inputs::labeled_input(
|
||||
&t(locale, "editor.title"),
|
||||
&t(locale, "editor.titlePlaceholder"),
|
||||
&state.title,
|
||||
|s| Message::MediaEditor(MediaEditorMsg::TitleChanged(s)),
|
||||
);
|
||||
let alt_input = inputs::labeled_input(
|
||||
&t(locale, "editor.alt"),
|
||||
&t(locale, "editor.altPlaceholder"),
|
||||
&state.alt,
|
||||
|s| Message::MediaEditor(MediaEditorMsg::AltChanged(s)),
|
||||
);
|
||||
let meta_row1 = row![title_input, alt_input].spacing(16).width(Length::Fill);
|
||||
|
||||
let caption_input = inputs::labeled_input(
|
||||
&t(locale, "editor.caption"),
|
||||
"",
|
||||
&state.caption,
|
||||
|s| Message::MediaEditor(MediaEditorMsg::CaptionChanged(s)),
|
||||
);
|
||||
let author_input = inputs::labeled_input(
|
||||
&t(locale, "editor.author"),
|
||||
"",
|
||||
&state.author,
|
||||
|s| Message::MediaEditor(MediaEditorMsg::AuthorChanged(s)),
|
||||
);
|
||||
let meta_row2 = row![caption_input, author_input].spacing(16).width(Length::Fill);
|
||||
|
||||
// Footer
|
||||
let footer = row![
|
||||
inputs::date_label(&t(locale, "editor.createdAt"), state.created_at),
|
||||
Space::with_width(Length::Fixed(24.0)),
|
||||
inputs::date_label(&t(locale, "editor.updatedAt"), state.updated_at),
|
||||
]
|
||||
.padding(8);
|
||||
|
||||
let body = scrollable(
|
||||
column![
|
||||
header,
|
||||
preview,
|
||||
info,
|
||||
inputs::section_header(&t(locale, "editor.metadata")),
|
||||
meta_row1,
|
||||
meta_row2,
|
||||
footer,
|
||||
]
|
||||
.spacing(12)
|
||||
.padding(16)
|
||||
.width(Length::Fill)
|
||||
);
|
||||
|
||||
container(body)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn no_preview<'a>() -> Element<'a, Message> {
|
||||
container(
|
||||
text("No preview available")
|
||||
.size(14)
|
||||
.color(Color::from_rgb(0.5, 0.5, 0.5)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fixed(200.0))
|
||||
.center_x(Length::Fill)
|
||||
.center_y(Length::Fixed(200.0))
|
||||
.into()
|
||||
}
|
||||
|
||||
fn format_file_size(bytes: i64) -> String {
|
||||
if bytes < 1024 {
|
||||
format!("{bytes} B")
|
||||
} else if bytes < 1024 * 1024 {
|
||||
format!("{:.1} KB", bytes as f64 / 1024.0)
|
||||
} else {
|
||||
format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0))
|
||||
}
|
||||
}
|
||||
@@ -8,3 +8,11 @@ pub mod project_selector;
|
||||
pub mod toast;
|
||||
pub mod welcome;
|
||||
pub mod modal;
|
||||
pub mod post_editor;
|
||||
pub mod media_editor;
|
||||
pub mod template_editor;
|
||||
pub mod script_editor;
|
||||
pub mod tags_view;
|
||||
pub mod settings_view;
|
||||
pub mod dashboard;
|
||||
pub mod translation_editor;
|
||||
|
||||
199
crates/bds-ui/src/views/post_editor.rs
Normal file
199
crates/bds-ui/src/views/post_editor.rs
Normal file
@@ -0,0 +1,199 @@
|
||||
use iced::widget::{button, column, container, row, scrollable, text, text_input, Space};
|
||||
use iced::{Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
use bds_core::model::{Post, PostStatus};
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
/// State for an open post editor.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PostEditorState {
|
||||
pub post_id: String,
|
||||
pub title: String,
|
||||
pub slug: String,
|
||||
pub excerpt: String,
|
||||
pub content: String,
|
||||
pub tags: Vec<String>,
|
||||
pub categories: Vec<String>,
|
||||
pub author: String,
|
||||
pub language: String,
|
||||
pub template_slug: String,
|
||||
pub do_not_translate: bool,
|
||||
pub status: PostStatus,
|
||||
pub created_at: i64,
|
||||
pub updated_at: i64,
|
||||
pub is_dirty: bool,
|
||||
}
|
||||
|
||||
impl PostEditorState {
|
||||
pub fn from_post(post: &Post) -> Self {
|
||||
Self {
|
||||
post_id: post.id.clone(),
|
||||
title: post.title.clone(),
|
||||
slug: post.slug.clone(),
|
||||
excerpt: post.excerpt.clone().unwrap_or_default(),
|
||||
content: post.content.clone().unwrap_or_default(),
|
||||
tags: post.tags.clone(),
|
||||
categories: post.categories.clone(),
|
||||
author: post.author.clone().unwrap_or_default(),
|
||||
language: post.language.clone().unwrap_or_default(),
|
||||
template_slug: post.template_slug.clone().unwrap_or_default(),
|
||||
do_not_translate: post.do_not_translate,
|
||||
status: post.status.clone(),
|
||||
created_at: post.created_at,
|
||||
updated_at: post.updated_at,
|
||||
is_dirty: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Post editor messages.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PostEditorMsg {
|
||||
TitleChanged(String),
|
||||
SlugChanged(String),
|
||||
ExcerptChanged(String),
|
||||
ContentChanged(String),
|
||||
AuthorChanged(String),
|
||||
TemplateSlugChanged(String),
|
||||
ToggleDoNotTranslate(bool),
|
||||
Save,
|
||||
Publish,
|
||||
Delete,
|
||||
}
|
||||
|
||||
/// Render the post editor view.
|
||||
pub fn view<'a>(
|
||||
state: &'a PostEditorState,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
let header = inputs::toolbar(
|
||||
vec![
|
||||
text(state.title.clone()).size(18).into(),
|
||||
status_badge(&state.status),
|
||||
],
|
||||
vec![
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::PostEditor(PostEditorMsg::Save))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "editor.publish")).size(13))
|
||||
.on_press(Message::PostEditor(PostEditorMsg::Publish))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "modal.confirmDelete.delete")).size(13))
|
||||
.on_press(Message::PostEditor(PostEditorMsg::Delete))
|
||||
.style(inputs::danger_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
],
|
||||
);
|
||||
|
||||
// Metadata section
|
||||
let title_input = inputs::labeled_input(
|
||||
&t(locale, "editor.title"),
|
||||
&t(locale, "editor.titlePlaceholder"),
|
||||
&state.title,
|
||||
|s| Message::PostEditor(PostEditorMsg::TitleChanged(s)),
|
||||
);
|
||||
let slug_input = inputs::labeled_input(
|
||||
&t(locale, "editor.slug"),
|
||||
&t(locale, "editor.slugPlaceholder"),
|
||||
&state.slug,
|
||||
|s| Message::PostEditor(PostEditorMsg::SlugChanged(s)),
|
||||
);
|
||||
let meta_row1 = row![title_input, slug_input].spacing(16).width(Length::Fill);
|
||||
|
||||
let author_input = inputs::labeled_input(
|
||||
&t(locale, "editor.author"),
|
||||
"",
|
||||
&state.author,
|
||||
|s| Message::PostEditor(PostEditorMsg::AuthorChanged(s)),
|
||||
);
|
||||
let template_input = inputs::labeled_input(
|
||||
&t(locale, "editor.templateSlug"),
|
||||
"",
|
||||
&state.template_slug,
|
||||
|s| Message::PostEditor(PostEditorMsg::TemplateSlugChanged(s)),
|
||||
);
|
||||
let dnt = inputs::labeled_checkbox(
|
||||
&t(locale, "editor.doNotTranslate"),
|
||||
state.do_not_translate,
|
||||
|b| Message::PostEditor(PostEditorMsg::ToggleDoNotTranslate(b)),
|
||||
);
|
||||
let meta_row2 = row![author_input, template_input, dnt].spacing(16).width(Length::Fill);
|
||||
|
||||
// Excerpt
|
||||
let excerpt_input = inputs::labeled_input(
|
||||
&t(locale, "editor.excerpt"),
|
||||
&t(locale, "editor.excerptPlaceholder"),
|
||||
&state.excerpt,
|
||||
|s| Message::PostEditor(PostEditorMsg::ExcerptChanged(s)),
|
||||
);
|
||||
|
||||
// Content (text area placeholder — full editor will use CodeEditor widget)
|
||||
let content_section: Element<'a, Message> = column![
|
||||
inputs::section_header(&t(locale, "editor.content")),
|
||||
container(
|
||||
text_input(&t(locale, "editor.contentPlaceholder"), &state.content)
|
||||
.on_input(|s| Message::PostEditor(PostEditorMsg::ContentChanged(s)))
|
||||
.size(14)
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fixed(300.0)),
|
||||
]
|
||||
.spacing(8)
|
||||
.width(Length::Fill)
|
||||
.into();
|
||||
|
||||
// Footer
|
||||
let footer = row![
|
||||
inputs::date_label(&t(locale, "editor.createdAt"), state.created_at),
|
||||
Space::with_width(Length::Fixed(24.0)),
|
||||
inputs::date_label(&t(locale, "editor.updatedAt"), state.updated_at),
|
||||
]
|
||||
.padding(8);
|
||||
|
||||
let body = scrollable(
|
||||
column![
|
||||
header,
|
||||
meta_row1,
|
||||
meta_row2,
|
||||
excerpt_input,
|
||||
content_section,
|
||||
footer,
|
||||
]
|
||||
.spacing(12)
|
||||
.padding(16)
|
||||
.width(Length::Fill)
|
||||
);
|
||||
|
||||
container(body)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn status_badge<'a>(status: &PostStatus) -> Element<'a, Message> {
|
||||
let (label, color) = match status {
|
||||
PostStatus::Draft => ("Draft", Color::from_rgb(0.8, 0.7, 0.2)),
|
||||
PostStatus::Published => ("Published", Color::from_rgb(0.2, 0.7, 0.3)),
|
||||
PostStatus::Archived => ("Archived", Color::from_rgb(0.5, 0.5, 0.5)),
|
||||
};
|
||||
container(text(label).size(11).color(color))
|
||||
.padding([2, 8])
|
||||
.style(move |_: &Theme| container::Style {
|
||||
border: iced::Border {
|
||||
radius: 4.0.into(),
|
||||
width: 1.0,
|
||||
color,
|
||||
},
|
||||
..container::Style::default()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
232
crates/bds-ui/src/views/script_editor.rs
Normal file
232
crates/bds-ui/src/views/script_editor.rs
Normal file
@@ -0,0 +1,232 @@
|
||||
use iced::widget::{button, column, container, row, scrollable, text, text_input, Space};
|
||||
use iced::{Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
use bds_core::model::{Script, ScriptKind, ScriptStatus};
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
/// State for an open script editor.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ScriptEditorState {
|
||||
pub script_id: String,
|
||||
pub title: String,
|
||||
pub slug: String,
|
||||
pub kind: ScriptKind,
|
||||
pub entrypoint: String,
|
||||
pub enabled: bool,
|
||||
pub content: String,
|
||||
pub status: ScriptStatus,
|
||||
pub version: i32,
|
||||
pub created_at: i64,
|
||||
pub updated_at: i64,
|
||||
pub discovered_entrypoints: Vec<String>,
|
||||
pub validation_error: Option<String>,
|
||||
pub is_dirty: bool,
|
||||
}
|
||||
|
||||
impl ScriptEditorState {
|
||||
pub fn from_script(script: &Script) -> Self {
|
||||
let content = script.content.clone().unwrap_or_default();
|
||||
let discovered = bds_core::engine::script::discover_entrypoints(&content);
|
||||
Self {
|
||||
script_id: script.id.clone(),
|
||||
title: script.title.clone(),
|
||||
slug: script.slug.clone(),
|
||||
kind: script.kind.clone(),
|
||||
entrypoint: script.entrypoint.clone(),
|
||||
enabled: script.enabled,
|
||||
content,
|
||||
status: script.status.clone(),
|
||||
version: script.version,
|
||||
created_at: script.created_at,
|
||||
updated_at: script.updated_at,
|
||||
discovered_entrypoints: discovered,
|
||||
validation_error: None,
|
||||
is_dirty: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Script kind display helper.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ScriptKindOption(pub ScriptKind);
|
||||
|
||||
impl std::fmt::Display for ScriptKindOption {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.0 {
|
||||
ScriptKind::Macro => write!(f, "Macro"),
|
||||
ScriptKind::Utility => write!(f, "Utility"),
|
||||
ScriptKind::Transform => write!(f, "Transform"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Script editor messages.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ScriptEditorMsg {
|
||||
TitleChanged(String),
|
||||
SlugChanged(String),
|
||||
KindChanged(ScriptKindOption),
|
||||
EntrypointChanged(String),
|
||||
EnabledChanged(bool),
|
||||
ContentChanged(String),
|
||||
Save,
|
||||
CheckSyntax,
|
||||
Run,
|
||||
Delete,
|
||||
}
|
||||
|
||||
/// Render the script editor view.
|
||||
pub fn view<'a>(
|
||||
state: &'a ScriptEditorState,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
let header = inputs::toolbar(
|
||||
vec![
|
||||
text(state.title.clone()).size(18).into(),
|
||||
status_badge(&state.status),
|
||||
],
|
||||
vec![
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::ScriptEditor(ScriptEditorMsg::Save))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "editor.run")).size(13))
|
||||
.on_press(Message::ScriptEditor(ScriptEditorMsg::Run))
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "editor.checkSyntax")).size(13))
|
||||
.on_press(Message::ScriptEditor(ScriptEditorMsg::CheckSyntax))
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "modal.confirmDelete.delete")).size(13))
|
||||
.on_press(Message::ScriptEditor(ScriptEditorMsg::Delete))
|
||||
.style(inputs::danger_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
],
|
||||
);
|
||||
|
||||
// Metadata row 1: title, slug
|
||||
let title_input = inputs::labeled_input(
|
||||
&t(locale, "editor.title"),
|
||||
&t(locale, "editor.titlePlaceholder"),
|
||||
&state.title,
|
||||
|s| Message::ScriptEditor(ScriptEditorMsg::TitleChanged(s)),
|
||||
);
|
||||
let slug_input = inputs::labeled_input(
|
||||
&t(locale, "editor.slug"),
|
||||
&t(locale, "editor.slugPlaceholder"),
|
||||
&state.slug,
|
||||
|s| Message::ScriptEditor(ScriptEditorMsg::SlugChanged(s)),
|
||||
);
|
||||
let meta_row1 = row![title_input, slug_input].spacing(16).width(Length::Fill);
|
||||
|
||||
// Metadata row 2: kind, entrypoint, enabled
|
||||
let kind_options = vec![
|
||||
ScriptKindOption(ScriptKind::Macro),
|
||||
ScriptKindOption(ScriptKind::Utility),
|
||||
ScriptKindOption(ScriptKind::Transform),
|
||||
];
|
||||
let selected_kind = Some(ScriptKindOption(state.kind.clone()));
|
||||
let kind_select = inputs::labeled_select(
|
||||
&t(locale, "editor.kind"),
|
||||
&kind_options,
|
||||
selected_kind.as_ref(),
|
||||
|k| Message::ScriptEditor(ScriptEditorMsg::KindChanged(k)),
|
||||
);
|
||||
|
||||
// Entrypoint: show discovered functions as a select or text input
|
||||
let entrypoint_input = inputs::labeled_input(
|
||||
&t(locale, "editor.entrypoint"),
|
||||
"render",
|
||||
&state.entrypoint,
|
||||
|s| Message::ScriptEditor(ScriptEditorMsg::EntrypointChanged(s)),
|
||||
);
|
||||
|
||||
let enabled_check = inputs::labeled_checkbox(
|
||||
&t(locale, "editor.enabled"),
|
||||
state.enabled,
|
||||
|b| Message::ScriptEditor(ScriptEditorMsg::EnabledChanged(b)),
|
||||
);
|
||||
let meta_row2 = row![kind_select, entrypoint_input, enabled_check]
|
||||
.spacing(16)
|
||||
.width(Length::Fill);
|
||||
|
||||
// Content editor (placeholder — will use CodeEditor with Lua syntax)
|
||||
let content_section: Element<'a, Message> = column![
|
||||
inputs::section_header(&t(locale, "editor.content")),
|
||||
container(
|
||||
text_input("", &state.content)
|
||||
.on_input(|s| Message::ScriptEditor(ScriptEditorMsg::ContentChanged(s)))
|
||||
.size(14)
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fixed(300.0)),
|
||||
]
|
||||
.spacing(8)
|
||||
.width(Length::Fill)
|
||||
.into();
|
||||
|
||||
// Validation error
|
||||
let validation: Element<'a, Message> = if let Some(ref err) = state.validation_error {
|
||||
container(
|
||||
text(err.clone())
|
||||
.size(12)
|
||||
.color(Color::from_rgb(0.9, 0.3, 0.3)),
|
||||
)
|
||||
.padding(8)
|
||||
.into()
|
||||
} else {
|
||||
Space::new(0, 0).into()
|
||||
};
|
||||
|
||||
// Footer
|
||||
let footer = row![
|
||||
inputs::date_label(&t(locale, "editor.createdAt"), state.created_at),
|
||||
Space::with_width(Length::Fixed(24.0)),
|
||||
inputs::date_label(&t(locale, "editor.updatedAt"), state.updated_at),
|
||||
]
|
||||
.padding(8);
|
||||
|
||||
let body = scrollable(
|
||||
column![
|
||||
header,
|
||||
meta_row1,
|
||||
meta_row2,
|
||||
content_section,
|
||||
validation,
|
||||
footer,
|
||||
]
|
||||
.spacing(12)
|
||||
.padding(16)
|
||||
.width(Length::Fill)
|
||||
);
|
||||
|
||||
container(body)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn status_badge<'a>(status: &ScriptStatus) -> Element<'a, Message> {
|
||||
let (label, color) = match status {
|
||||
ScriptStatus::Draft => ("Draft", Color::from_rgb(0.8, 0.7, 0.2)),
|
||||
ScriptStatus::Published => ("Published", Color::from_rgb(0.2, 0.7, 0.3)),
|
||||
};
|
||||
container(text(label).size(11).color(color))
|
||||
.padding([2, 8])
|
||||
.style(move |_: &Theme| container::Style {
|
||||
border: iced::Border {
|
||||
radius: 4.0.into(),
|
||||
width: 1.0,
|
||||
color,
|
||||
},
|
||||
..container::Style::default()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
431
crates/bds-ui/src/views/settings_view.rs
Normal file
431
crates/bds-ui/src/views/settings_view.rs
Normal file
@@ -0,0 +1,431 @@
|
||||
use iced::widget::{button, column, container, row, scrollable, text, text_input};
|
||||
use iced::{Alignment, Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
/// Collapsible section identifiers per editor_settings.allium.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum SettingsSection {
|
||||
Project,
|
||||
Editor,
|
||||
Content,
|
||||
AI,
|
||||
Technology,
|
||||
Publishing,
|
||||
Data,
|
||||
MCP,
|
||||
}
|
||||
|
||||
impl SettingsSection {
|
||||
pub fn all() -> &'static [SettingsSection] {
|
||||
&[
|
||||
Self::Project,
|
||||
Self::Editor,
|
||||
Self::Content,
|
||||
Self::AI,
|
||||
Self::Technology,
|
||||
Self::Publishing,
|
||||
Self::Data,
|
||||
Self::MCP,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn i18n_key(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Project => "settings.nav.project",
|
||||
Self::Editor => "settings.nav.editor",
|
||||
Self::Content => "settings.nav.content",
|
||||
Self::AI => "settings.nav.ai",
|
||||
Self::Technology => "settings.nav.technology",
|
||||
Self::Publishing => "settings.nav.publishing",
|
||||
Self::Data => "settings.nav.data",
|
||||
Self::MCP => "settings.nav.mcp",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// State for the settings view.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SettingsViewState {
|
||||
pub search_query: String,
|
||||
pub collapsed: Vec<SettingsSection>,
|
||||
// Project
|
||||
pub project_name: String,
|
||||
pub project_description: String,
|
||||
pub data_path: String,
|
||||
pub public_url: String,
|
||||
pub default_author: String,
|
||||
pub max_posts_per_page: String,
|
||||
// Editor
|
||||
pub default_mode: String,
|
||||
pub diff_view_style: String,
|
||||
pub wrap_long_lines: bool,
|
||||
pub hide_unchanged_regions: bool,
|
||||
// Publishing
|
||||
pub ssh_mode: String,
|
||||
pub ssh_host: String,
|
||||
pub ssh_username: String,
|
||||
pub ssh_remote_path: String,
|
||||
// AI
|
||||
pub offline_mode: bool,
|
||||
pub system_prompt: String,
|
||||
}
|
||||
|
||||
impl Default for SettingsViewState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
search_query: String::new(),
|
||||
collapsed: Vec::new(),
|
||||
project_name: String::new(),
|
||||
project_description: String::new(),
|
||||
data_path: String::new(),
|
||||
public_url: String::new(),
|
||||
default_author: String::new(),
|
||||
max_posts_per_page: "50".to_string(),
|
||||
default_mode: "markdown".to_string(),
|
||||
diff_view_style: "inline".to_string(),
|
||||
wrap_long_lines: true,
|
||||
hide_unchanged_regions: false,
|
||||
ssh_mode: "rsync".to_string(),
|
||||
ssh_host: String::new(),
|
||||
ssh_username: String::new(),
|
||||
ssh_remote_path: String::new(),
|
||||
offline_mode: false,
|
||||
system_prompt: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Settings view messages.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SettingsMsg {
|
||||
SearchChanged(String),
|
||||
ToggleSection(SettingsSection),
|
||||
// Project
|
||||
ProjectNameChanged(String),
|
||||
ProjectDescriptionChanged(String),
|
||||
DataPathChanged(String),
|
||||
BrowseDataPath,
|
||||
ResetDataPath,
|
||||
PublicUrlChanged(String),
|
||||
DefaultAuthorChanged(String),
|
||||
MaxPostsPerPageChanged(String),
|
||||
SaveProject,
|
||||
// Editor
|
||||
DefaultModeChanged(String),
|
||||
DiffViewStyleChanged(String),
|
||||
WrapLongLinesChanged(bool),
|
||||
HideUnchangedRegionsChanged(bool),
|
||||
SaveEditor,
|
||||
// Publishing
|
||||
SshModeChanged(String),
|
||||
SshHostChanged(String),
|
||||
SshUsernameChanged(String),
|
||||
SshRemotePathChanged(String),
|
||||
SavePublishing,
|
||||
ClearPublishing,
|
||||
// AI
|
||||
OfflineModeChanged(bool),
|
||||
SystemPromptChanged(String),
|
||||
SaveSystemPrompt,
|
||||
ResetSystemPrompt,
|
||||
// Data maintenance
|
||||
RebuildPosts,
|
||||
RebuildMedia,
|
||||
RebuildScripts,
|
||||
RebuildTemplates,
|
||||
RebuildLinks,
|
||||
RegenerateThumbnails,
|
||||
OpenDataFolder,
|
||||
}
|
||||
|
||||
/// Render the settings view.
|
||||
pub fn view<'a>(
|
||||
state: &'a SettingsViewState,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
let search = text_input(&t(locale, "sidebar.filter.search"), &state.search_query)
|
||||
.on_input(|s| Message::Settings(SettingsMsg::SearchChanged(s)))
|
||||
.size(14);
|
||||
|
||||
let query_lower = state.search_query.to_lowercase();
|
||||
|
||||
let mut sections = column![].spacing(12).width(Length::Fill);
|
||||
for section in SettingsSection::all() {
|
||||
let label = t(locale, section.i18n_key());
|
||||
if !query_lower.is_empty() && !label.to_lowercase().contains(&query_lower) {
|
||||
continue;
|
||||
}
|
||||
let collapsed = state.collapsed.contains(section);
|
||||
let section_el = render_section(state, section, &label, collapsed, locale);
|
||||
sections = sections.push(section_el);
|
||||
}
|
||||
|
||||
let body = scrollable(
|
||||
column![search, sections]
|
||||
.spacing(16)
|
||||
.padding(16)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill);
|
||||
|
||||
container(body)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn render_section<'a>(
|
||||
state: &'a SettingsViewState,
|
||||
section: &SettingsSection,
|
||||
label: &str,
|
||||
collapsed: bool,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
let toggle_char = if collapsed { "\u{25B6}" } else { "\u{25BC}" };
|
||||
let header = button(
|
||||
row![
|
||||
text(toggle_char).size(12),
|
||||
text(label.to_string()).size(14).color(Color::WHITE),
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(Alignment::Center),
|
||||
)
|
||||
.on_press(Message::Settings(SettingsMsg::ToggleSection(section.clone())))
|
||||
.padding([6, 8])
|
||||
.width(Length::Fill)
|
||||
.style(|_: &Theme, _| button::Style::default());
|
||||
|
||||
if collapsed {
|
||||
return column![header].into();
|
||||
}
|
||||
|
||||
let content: Element<'a, Message> = match section {
|
||||
SettingsSection::Project => section_project(state, locale),
|
||||
SettingsSection::Editor => section_editor(state, locale),
|
||||
SettingsSection::Content => section_content(locale),
|
||||
SettingsSection::AI => section_ai(state, locale),
|
||||
SettingsSection::Technology => section_technology(locale),
|
||||
SettingsSection::Publishing => section_publishing(state, locale),
|
||||
SettingsSection::Data => section_data(locale),
|
||||
SettingsSection::MCP => section_mcp(locale),
|
||||
};
|
||||
|
||||
column![header, content]
|
||||
.spacing(4)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_project<'a>(state: &'a SettingsViewState, locale: UiLocale) -> Element<'a, Message> {
|
||||
let name = inputs::labeled_input(
|
||||
&t(locale, "settings.projectName"),
|
||||
"",
|
||||
&state.project_name,
|
||||
|s| Message::Settings(SettingsMsg::ProjectNameChanged(s)),
|
||||
);
|
||||
let desc = inputs::labeled_input(
|
||||
&t(locale, "settings.projectDescription"),
|
||||
"",
|
||||
&state.project_description,
|
||||
|s| Message::Settings(SettingsMsg::ProjectDescriptionChanged(s)),
|
||||
);
|
||||
let data_path = row![
|
||||
inputs::labeled_input(
|
||||
&t(locale, "settings.dataPath"),
|
||||
"",
|
||||
&state.data_path,
|
||||
|s| Message::Settings(SettingsMsg::DataPathChanged(s)),
|
||||
),
|
||||
button(text(t(locale, "settings.browse")).size(12))
|
||||
.on_press(Message::Settings(SettingsMsg::BrowseDataPath))
|
||||
.padding([6, 12]),
|
||||
button(text(t(locale, "settings.reset")).size(12))
|
||||
.on_press(Message::Settings(SettingsMsg::ResetDataPath))
|
||||
.padding([6, 12]),
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(Alignment::End);
|
||||
|
||||
let url = inputs::labeled_input(
|
||||
&t(locale, "settings.publicUrl"),
|
||||
"https://",
|
||||
&state.public_url,
|
||||
|s| Message::Settings(SettingsMsg::PublicUrlChanged(s)),
|
||||
);
|
||||
let author = inputs::labeled_input(
|
||||
&t(locale, "settings.defaultAuthor"),
|
||||
"",
|
||||
&state.default_author,
|
||||
|s| Message::Settings(SettingsMsg::DefaultAuthorChanged(s)),
|
||||
);
|
||||
let max_posts = inputs::labeled_input(
|
||||
&t(locale, "settings.maxPostsPerPage"),
|
||||
"50",
|
||||
&state.max_posts_per_page,
|
||||
|s| Message::Settings(SettingsMsg::MaxPostsPerPageChanged(s)),
|
||||
);
|
||||
let save = button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::SaveProject))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16]);
|
||||
|
||||
column![name, desc, data_path, url, author, max_posts, save]
|
||||
.spacing(8)
|
||||
.padding([0, 16])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_editor<'a>(state: &'a SettingsViewState, locale: UiLocale) -> Element<'a, Message> {
|
||||
let wrap = inputs::labeled_checkbox(
|
||||
&t(locale, "settings.wrapLongLines"),
|
||||
state.wrap_long_lines,
|
||||
|b| Message::Settings(SettingsMsg::WrapLongLinesChanged(b)),
|
||||
);
|
||||
let hide = inputs::labeled_checkbox(
|
||||
&t(locale, "settings.hideUnchangedRegions"),
|
||||
state.hide_unchanged_regions,
|
||||
|b| Message::Settings(SettingsMsg::HideUnchangedRegionsChanged(b)),
|
||||
);
|
||||
let save = button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::SaveEditor))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16]);
|
||||
|
||||
column![wrap, hide, save]
|
||||
.spacing(8)
|
||||
.padding([0, 16])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_content<'a>(locale: UiLocale) -> Element<'a, Message> {
|
||||
// Categories table placeholder — full implementation in future iteration
|
||||
text(t(locale, "settings.contentPlaceholder"))
|
||||
.size(13)
|
||||
.color(Color::from_rgb(0.5, 0.5, 0.5))
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_ai<'a>(state: &'a SettingsViewState, locale: UiLocale) -> Element<'a, Message> {
|
||||
let offline = inputs::labeled_checkbox(
|
||||
&t(locale, "settings.offlineMode"),
|
||||
state.offline_mode,
|
||||
|b| Message::Settings(SettingsMsg::OfflineModeChanged(b)),
|
||||
);
|
||||
let prompt = inputs::labeled_input(
|
||||
&t(locale, "settings.systemPrompt"),
|
||||
"",
|
||||
&state.system_prompt,
|
||||
|s| Message::Settings(SettingsMsg::SystemPromptChanged(s)),
|
||||
);
|
||||
let btns = row![
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::SaveSystemPrompt))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16]),
|
||||
button(text(t(locale, "settings.resetToDefault")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::ResetSystemPrompt))
|
||||
.padding([6, 16]),
|
||||
]
|
||||
.spacing(8);
|
||||
|
||||
column![offline, prompt, btns]
|
||||
.spacing(8)
|
||||
.padding([0, 16])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_technology<'a>(locale: UiLocale) -> Element<'a, Message> {
|
||||
text(t(locale, "settings.technologyPlaceholder"))
|
||||
.size(13)
|
||||
.color(Color::from_rgb(0.5, 0.5, 0.5))
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_publishing<'a>(state: &'a SettingsViewState, locale: UiLocale) -> Element<'a, Message> {
|
||||
let host = inputs::labeled_input(
|
||||
&t(locale, "settings.sshHost"),
|
||||
"",
|
||||
&state.ssh_host,
|
||||
|s| Message::Settings(SettingsMsg::SshHostChanged(s)),
|
||||
);
|
||||
let user = inputs::labeled_input(
|
||||
&t(locale, "settings.sshUsername"),
|
||||
"",
|
||||
&state.ssh_username,
|
||||
|s| Message::Settings(SettingsMsg::SshUsernameChanged(s)),
|
||||
);
|
||||
let path = inputs::labeled_input(
|
||||
&t(locale, "settings.sshRemotePath"),
|
||||
"",
|
||||
&state.ssh_remote_path,
|
||||
|s| Message::Settings(SettingsMsg::SshRemotePathChanged(s)),
|
||||
);
|
||||
let btns = row![
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::SavePublishing))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16]),
|
||||
button(text(t(locale, "settings.clear")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::ClearPublishing))
|
||||
.style(inputs::danger_button)
|
||||
.padding([6, 16]),
|
||||
]
|
||||
.spacing(8);
|
||||
|
||||
column![host, user, path, btns]
|
||||
.spacing(8)
|
||||
.padding([0, 16])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_data<'a>(locale: UiLocale) -> Element<'a, Message> {
|
||||
let rebuild_btns = column![
|
||||
button(text(t(locale, "settings.rebuildPosts")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::RebuildPosts))
|
||||
.padding([6, 16])
|
||||
.width(Length::Fill),
|
||||
button(text(t(locale, "settings.rebuildMedia")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::RebuildMedia))
|
||||
.padding([6, 16])
|
||||
.width(Length::Fill),
|
||||
button(text(t(locale, "settings.rebuildScripts")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::RebuildScripts))
|
||||
.padding([6, 16])
|
||||
.width(Length::Fill),
|
||||
button(text(t(locale, "settings.rebuildTemplates")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::RebuildTemplates))
|
||||
.padding([6, 16])
|
||||
.width(Length::Fill),
|
||||
button(text(t(locale, "settings.rebuildLinks")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::RebuildLinks))
|
||||
.padding([6, 16])
|
||||
.width(Length::Fill),
|
||||
button(text(t(locale, "settings.regenerateThumbnails")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::RegenerateThumbnails))
|
||||
.padding([6, 16])
|
||||
.width(Length::Fill),
|
||||
]
|
||||
.spacing(4);
|
||||
|
||||
let open = button(text(t(locale, "settings.openDataFolder")).size(13))
|
||||
.on_press(Message::Settings(SettingsMsg::OpenDataFolder))
|
||||
.padding([6, 16]);
|
||||
|
||||
column![rebuild_btns, open]
|
||||
.spacing(12)
|
||||
.padding([0, 16])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_mcp<'a>(locale: UiLocale) -> Element<'a, Message> {
|
||||
// MCP status and agent toggles — placeholder for M3
|
||||
text(t(locale, "settings.mcpPlaceholder"))
|
||||
.size(13)
|
||||
.color(Color::from_rgb(0.5, 0.5, 0.5))
|
||||
.into()
|
||||
}
|
||||
309
crates/bds-ui/src/views/tags_view.rs
Normal file
309
crates/bds-ui/src/views/tags_view.rs
Normal file
@@ -0,0 +1,309 @@
|
||||
use iced::widget::{button, column, container, row, scrollable, text, text_input, Space};
|
||||
use iced::{Alignment, Background, Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
use bds_core::model::Tag;
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
const DEFAULT_TAG_COLOR: &str = "#6495ed";
|
||||
|
||||
/// Active view within the Tags tab.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum TagsSection {
|
||||
Cloud,
|
||||
Manage,
|
||||
Merge,
|
||||
}
|
||||
|
||||
/// State for the tags view.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TagsViewState {
|
||||
pub section: TagsSection,
|
||||
pub tags: Vec<Tag>,
|
||||
pub search_query: String,
|
||||
/// For "Manage": the currently editing tag
|
||||
pub editing_tag: Option<EditingTag>,
|
||||
/// For "Merge": source and target tag selection
|
||||
pub merge_source: Option<String>,
|
||||
pub merge_target: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EditingTag {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub color: String,
|
||||
pub template_slug: String,
|
||||
}
|
||||
|
||||
impl TagsViewState {
|
||||
pub fn new(tags: Vec<Tag>) -> Self {
|
||||
Self {
|
||||
section: TagsSection::Cloud,
|
||||
tags,
|
||||
search_query: String::new(),
|
||||
editing_tag: None,
|
||||
merge_source: None,
|
||||
merge_target: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Tags view messages.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TagsMsg {
|
||||
SetSection(TagsSection),
|
||||
SearchChanged(String),
|
||||
SelectTag(String),
|
||||
CreateTag(String),
|
||||
EditTagName(String),
|
||||
EditTagColor(String),
|
||||
EditTagTemplate(String),
|
||||
SaveTag,
|
||||
DeleteTag(String),
|
||||
SetMergeSource(String),
|
||||
SetMergeTarget(String),
|
||||
MergeTags,
|
||||
}
|
||||
|
||||
/// Render the tags management view.
|
||||
pub fn view<'a>(
|
||||
state: &'a TagsViewState,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
// Section navigation tabs
|
||||
let section_nav = row![
|
||||
section_tab(&t(locale, "tags.nav.cloud"), state.section == TagsSection::Cloud, TagsSection::Cloud),
|
||||
section_tab(&t(locale, "tags.nav.manage"), state.section == TagsSection::Manage, TagsSection::Manage),
|
||||
section_tab(&t(locale, "tags.nav.merge"), state.section == TagsSection::Merge, TagsSection::Merge),
|
||||
]
|
||||
.spacing(4)
|
||||
.padding(8);
|
||||
|
||||
let content: Element<'a, Message> = match state.section {
|
||||
TagsSection::Cloud => view_cloud(state, locale),
|
||||
TagsSection::Manage => view_manage(state, locale),
|
||||
TagsSection::Merge => view_merge(state, locale),
|
||||
};
|
||||
|
||||
column![section_nav, content]
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn section_tab<'a>(label: &str, active: bool, section: TagsSection) -> Element<'a, Message> {
|
||||
let color = if active {
|
||||
Color::WHITE
|
||||
} else {
|
||||
Color::from_rgb(0.55, 0.58, 0.65)
|
||||
};
|
||||
button(text(label.to_string()).size(13).color(color))
|
||||
.on_press(Message::Tags(TagsMsg::SetSection(section)))
|
||||
.padding([6, 12])
|
||||
.style(move |_theme: &Theme, _status| {
|
||||
if active {
|
||||
button::Style {
|
||||
background: Some(Background::Color(Color::from_rgb(0.25, 0.27, 0.33))),
|
||||
border: iced::Border {
|
||||
radius: 4.0.into(),
|
||||
..iced::Border::default()
|
||||
},
|
||||
..button::Style::default()
|
||||
}
|
||||
} else {
|
||||
button::Style::default()
|
||||
}
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
fn view_cloud<'a>(state: &'a TagsViewState, locale: UiLocale) -> Element<'a, Message> {
|
||||
if state.tags.is_empty() {
|
||||
return container(
|
||||
text(t(locale, "tags.noTags")).size(14).color(Color::from_rgb(0.5, 0.5, 0.5)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.center_x(Length::Fill)
|
||||
.center_y(Length::Fill)
|
||||
.into();
|
||||
}
|
||||
|
||||
let chips: Vec<Element<'a, Message>> = state
|
||||
.tags
|
||||
.iter()
|
||||
.map(|tag| {
|
||||
let color = parse_tag_color(tag.color.as_deref().unwrap_or(DEFAULT_TAG_COLOR));
|
||||
button(text(&tag.name).size(13).color(Color::WHITE))
|
||||
.on_press(Message::Tags(TagsMsg::SelectTag(tag.id.clone())))
|
||||
.padding([4, 10])
|
||||
.style(move |_: &Theme, _| button::Style {
|
||||
background: Some(Background::Color(color)),
|
||||
border: iced::Border {
|
||||
radius: 12.0.into(),
|
||||
..iced::Border::default()
|
||||
},
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
})
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let cloud = iced::widget::Column::with_children(chips).spacing(6);
|
||||
|
||||
scrollable(
|
||||
container(cloud)
|
||||
.width(Length::Fill)
|
||||
.padding(16),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn view_manage<'a>(state: &'a TagsViewState, locale: UiLocale) -> Element<'a, Message> {
|
||||
let search = text_input(&t(locale, "sidebar.filter.search"), &state.search_query)
|
||||
.on_input(|s| Message::Tags(TagsMsg::SearchChanged(s)))
|
||||
.size(14);
|
||||
|
||||
let filtered: Vec<&Tag> = state
|
||||
.tags
|
||||
.iter()
|
||||
.filter(|t| {
|
||||
state.search_query.is_empty()
|
||||
|| t.name.to_lowercase().contains(&state.search_query.to_lowercase())
|
||||
})
|
||||
.collect();
|
||||
|
||||
let rows: Vec<Element<'a, Message>> = filtered
|
||||
.iter()
|
||||
.map(|tag| {
|
||||
let color = parse_tag_color(tag.color.as_deref().unwrap_or(DEFAULT_TAG_COLOR));
|
||||
row![
|
||||
container(Space::new(12, 12))
|
||||
.style(move |_: &Theme| container::Style {
|
||||
background: Some(Background::Color(color)),
|
||||
border: iced::Border {
|
||||
radius: 6.0.into(),
|
||||
..iced::Border::default()
|
||||
},
|
||||
..container::Style::default()
|
||||
}),
|
||||
text(&tag.name).size(14),
|
||||
Space::with_width(Length::Fill),
|
||||
button(text(t(locale, "modal.confirmDelete.delete")).size(12))
|
||||
.on_press(Message::Tags(TagsMsg::DeleteTag(tag.id.clone())))
|
||||
.style(inputs::danger_button)
|
||||
.padding([3, 8])
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(Alignment::Center)
|
||||
.padding(4)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let tag_list = iced::widget::Column::with_children(rows).spacing(2);
|
||||
|
||||
// Edit panel for selected tag
|
||||
let edit_panel: Element<'a, Message> = if let Some(ref editing) = state.editing_tag {
|
||||
column![
|
||||
inputs::section_header(&t(locale, "tags.editTag")),
|
||||
inputs::labeled_input(
|
||||
&t(locale, "tags.name"),
|
||||
"",
|
||||
&editing.name,
|
||||
|s| Message::Tags(TagsMsg::EditTagName(s)),
|
||||
),
|
||||
inputs::labeled_input(
|
||||
&t(locale, "tags.color"),
|
||||
"#3498db",
|
||||
&editing.color,
|
||||
|s| Message::Tags(TagsMsg::EditTagColor(s)),
|
||||
),
|
||||
inputs::labeled_input(
|
||||
&t(locale, "tags.postTemplate"),
|
||||
"",
|
||||
&editing.template_slug,
|
||||
|s| Message::Tags(TagsMsg::EditTagTemplate(s)),
|
||||
),
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::Tags(TagsMsg::SaveTag))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16]),
|
||||
]
|
||||
.spacing(8)
|
||||
.padding(12)
|
||||
.into()
|
||||
} else {
|
||||
Space::new(0, 0).into()
|
||||
};
|
||||
|
||||
scrollable(
|
||||
column![
|
||||
search,
|
||||
tag_list,
|
||||
edit_panel,
|
||||
]
|
||||
.spacing(12)
|
||||
.padding(16)
|
||||
.width(Length::Fill)
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn view_merge<'a>(state: &'a TagsViewState, locale: UiLocale) -> Element<'a, Message> {
|
||||
let source_input = inputs::labeled_input(
|
||||
&t(locale, "tags.mergeSource"),
|
||||
&t(locale, "tags.selectTag"),
|
||||
state.merge_source.as_deref().unwrap_or(""),
|
||||
|s| Message::Tags(TagsMsg::SetMergeSource(s)),
|
||||
);
|
||||
let target_input = inputs::labeled_input(
|
||||
&t(locale, "tags.mergeTarget"),
|
||||
&t(locale, "tags.selectTag"),
|
||||
state.merge_target.as_deref().unwrap_or(""),
|
||||
|s| Message::Tags(TagsMsg::SetMergeTarget(s)),
|
||||
);
|
||||
|
||||
let can_merge = state.merge_source.is_some() && state.merge_target.is_some();
|
||||
|
||||
let merge_btn = if can_merge {
|
||||
button(text(t(locale, "tags.merge")).size(13))
|
||||
.on_press(Message::Tags(TagsMsg::MergeTags))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
} else {
|
||||
button(text(t(locale, "tags.merge")).size(13))
|
||||
.padding([6, 16])
|
||||
};
|
||||
|
||||
column![
|
||||
source_input,
|
||||
target_input,
|
||||
merge_btn,
|
||||
]
|
||||
.spacing(12)
|
||||
.padding(16)
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn parse_tag_color(hex: &str) -> Color {
|
||||
let hex = hex.trim_start_matches('#');
|
||||
if hex.len() == 6 {
|
||||
let r = u8::from_str_radix(&hex[0..2], 16).unwrap_or(100);
|
||||
let g = u8::from_str_radix(&hex[2..4], 16).unwrap_or(100);
|
||||
let b = u8::from_str_radix(&hex[4..6], 16).unwrap_or(100);
|
||||
Color::from_rgb(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0)
|
||||
} else {
|
||||
Color::from_rgb(0.4, 0.5, 0.7)
|
||||
}
|
||||
}
|
||||
211
crates/bds-ui/src/views/template_editor.rs
Normal file
211
crates/bds-ui/src/views/template_editor.rs
Normal file
@@ -0,0 +1,211 @@
|
||||
use iced::widget::{button, column, container, row, scrollable, text, text_input, Space};
|
||||
use iced::{Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
use bds_core::model::{Template, TemplateKind, TemplateStatus};
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
/// State for an open template editor.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TemplateEditorState {
|
||||
pub template_id: String,
|
||||
pub title: String,
|
||||
pub slug: String,
|
||||
pub kind: TemplateKind,
|
||||
pub enabled: bool,
|
||||
pub content: String,
|
||||
pub status: TemplateStatus,
|
||||
pub version: i32,
|
||||
pub created_at: i64,
|
||||
pub updated_at: i64,
|
||||
pub validation_error: Option<String>,
|
||||
pub is_dirty: bool,
|
||||
}
|
||||
|
||||
impl TemplateEditorState {
|
||||
pub fn from_template(tpl: &Template) -> Self {
|
||||
Self {
|
||||
template_id: tpl.id.clone(),
|
||||
title: tpl.title.clone(),
|
||||
slug: tpl.slug.clone(),
|
||||
kind: tpl.kind.clone(),
|
||||
enabled: tpl.enabled,
|
||||
content: tpl.content.clone().unwrap_or_default(),
|
||||
status: tpl.status.clone(),
|
||||
version: tpl.version,
|
||||
created_at: tpl.created_at,
|
||||
updated_at: tpl.updated_at,
|
||||
validation_error: None,
|
||||
is_dirty: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Template kind display helper.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TemplateKindOption(pub TemplateKind);
|
||||
|
||||
impl std::fmt::Display for TemplateKindOption {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.0 {
|
||||
TemplateKind::Post => write!(f, "Post"),
|
||||
TemplateKind::List => write!(f, "List"),
|
||||
TemplateKind::NotFound => write!(f, "Not Found"),
|
||||
TemplateKind::Partial => write!(f, "Partial"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Template editor messages.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TemplateEditorMsg {
|
||||
TitleChanged(String),
|
||||
SlugChanged(String),
|
||||
KindChanged(TemplateKindOption),
|
||||
EnabledChanged(bool),
|
||||
ContentChanged(String),
|
||||
Save,
|
||||
Validate,
|
||||
Delete,
|
||||
}
|
||||
|
||||
/// Render the template editor view.
|
||||
pub fn view<'a>(
|
||||
state: &'a TemplateEditorState,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
let header = inputs::toolbar(
|
||||
vec![
|
||||
text(state.title.clone()).size(18).into(),
|
||||
status_badge(&state.status),
|
||||
],
|
||||
vec![
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::TemplateEditor(TemplateEditorMsg::Save))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "editor.validate")).size(13))
|
||||
.on_press(Message::TemplateEditor(TemplateEditorMsg::Validate))
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "modal.confirmDelete.delete")).size(13))
|
||||
.on_press(Message::TemplateEditor(TemplateEditorMsg::Delete))
|
||||
.style(inputs::danger_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
],
|
||||
);
|
||||
|
||||
// Metadata row 1: title, slug
|
||||
let title_input = inputs::labeled_input(
|
||||
&t(locale, "editor.title"),
|
||||
&t(locale, "editor.titlePlaceholder"),
|
||||
&state.title,
|
||||
|s| Message::TemplateEditor(TemplateEditorMsg::TitleChanged(s)),
|
||||
);
|
||||
let slug_input = inputs::labeled_input(
|
||||
&t(locale, "editor.slug"),
|
||||
&t(locale, "editor.slugPlaceholder"),
|
||||
&state.slug,
|
||||
|s| Message::TemplateEditor(TemplateEditorMsg::SlugChanged(s)),
|
||||
);
|
||||
let meta_row1 = row![title_input, slug_input].spacing(16).width(Length::Fill);
|
||||
|
||||
// Metadata row 2: kind (select), enabled (checkbox)
|
||||
let kind_options = vec![
|
||||
TemplateKindOption(TemplateKind::Post),
|
||||
TemplateKindOption(TemplateKind::List),
|
||||
TemplateKindOption(TemplateKind::NotFound),
|
||||
TemplateKindOption(TemplateKind::Partial),
|
||||
];
|
||||
let selected_kind = Some(TemplateKindOption(state.kind.clone()));
|
||||
let kind_select = inputs::labeled_select(
|
||||
&t(locale, "editor.kind"),
|
||||
&kind_options,
|
||||
selected_kind.as_ref(),
|
||||
|k| Message::TemplateEditor(TemplateEditorMsg::KindChanged(k)),
|
||||
);
|
||||
let enabled_check = inputs::labeled_checkbox(
|
||||
&t(locale, "editor.enabled"),
|
||||
state.enabled,
|
||||
|b| Message::TemplateEditor(TemplateEditorMsg::EnabledChanged(b)),
|
||||
);
|
||||
let meta_row2 = row![kind_select, enabled_check].spacing(16).width(Length::Fill);
|
||||
|
||||
// Content editor (text area placeholder — will use CodeEditor widget for liquid)
|
||||
let content_section: Element<'a, Message> = column![
|
||||
inputs::section_header(&t(locale, "editor.content")),
|
||||
container(
|
||||
text_input("", &state.content)
|
||||
.on_input(|s| Message::TemplateEditor(TemplateEditorMsg::ContentChanged(s)))
|
||||
.size(14)
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fixed(300.0)),
|
||||
]
|
||||
.spacing(8)
|
||||
.width(Length::Fill)
|
||||
.into();
|
||||
|
||||
// Validation error
|
||||
let validation: Element<'a, Message> = if let Some(ref err) = state.validation_error {
|
||||
container(
|
||||
text(err.clone())
|
||||
.size(12)
|
||||
.color(Color::from_rgb(0.9, 0.3, 0.3)),
|
||||
)
|
||||
.padding(8)
|
||||
.into()
|
||||
} else {
|
||||
Space::new(0, 0).into()
|
||||
};
|
||||
|
||||
// Footer
|
||||
let footer = row![
|
||||
inputs::date_label(&t(locale, "editor.createdAt"), state.created_at),
|
||||
Space::with_width(Length::Fixed(24.0)),
|
||||
inputs::date_label(&t(locale, "editor.updatedAt"), state.updated_at),
|
||||
]
|
||||
.padding(8);
|
||||
|
||||
let body = scrollable(
|
||||
column![
|
||||
header,
|
||||
meta_row1,
|
||||
meta_row2,
|
||||
content_section,
|
||||
validation,
|
||||
footer,
|
||||
]
|
||||
.spacing(12)
|
||||
.padding(16)
|
||||
.width(Length::Fill)
|
||||
);
|
||||
|
||||
container(body)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn status_badge<'a>(status: &TemplateStatus) -> Element<'a, Message> {
|
||||
let (label, color) = match status {
|
||||
TemplateStatus::Draft => ("Draft", Color::from_rgb(0.8, 0.7, 0.2)),
|
||||
TemplateStatus::Published => ("Published", Color::from_rgb(0.2, 0.7, 0.3)),
|
||||
};
|
||||
container(text(label).size(11).color(color))
|
||||
.padding([2, 8])
|
||||
.style(move |_: &Theme| container::Style {
|
||||
border: iced::Border {
|
||||
radius: 4.0.into(),
|
||||
width: 1.0,
|
||||
color,
|
||||
},
|
||||
..container::Style::default()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
154
crates/bds-ui/src/views/translation_editor.rs
Normal file
154
crates/bds-ui/src/views/translation_editor.rs
Normal file
@@ -0,0 +1,154 @@
|
||||
use iced::widget::{button, column, container, row, scrollable, text, text_input, Space};
|
||||
use iced::{Color, Element, Length, Theme};
|
||||
|
||||
use bds_core::i18n::UiLocale;
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::components::inputs;
|
||||
use crate::i18n::t;
|
||||
|
||||
/// State for the translation editor (post translation).
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TranslationEditorState {
|
||||
pub post_id: String,
|
||||
pub post_title: String,
|
||||
pub language: String,
|
||||
pub title: String,
|
||||
pub excerpt: String,
|
||||
pub content: String,
|
||||
pub status: String, // draft | published
|
||||
pub created_at: i64,
|
||||
pub updated_at: i64,
|
||||
pub is_dirty: bool,
|
||||
}
|
||||
|
||||
impl TranslationEditorState {
|
||||
pub fn new(post_id: String, post_title: String, language: String) -> Self {
|
||||
Self {
|
||||
post_id,
|
||||
post_title,
|
||||
language,
|
||||
title: String::new(),
|
||||
excerpt: String::new(),
|
||||
content: String::new(),
|
||||
status: "draft".to_string(),
|
||||
created_at: 0,
|
||||
updated_at: 0,
|
||||
is_dirty: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Translation editor messages.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TranslationEditorMsg {
|
||||
TitleChanged(String),
|
||||
ExcerptChanged(String),
|
||||
ContentChanged(String),
|
||||
Save,
|
||||
Publish,
|
||||
Delete,
|
||||
}
|
||||
|
||||
/// Render the translation editor view.
|
||||
pub fn view<'a>(
|
||||
state: &'a TranslationEditorState,
|
||||
locale: UiLocale,
|
||||
) -> Element<'a, Message> {
|
||||
let header = inputs::toolbar(
|
||||
vec![
|
||||
text(format!("{} [{}]", &state.post_title, &state.language))
|
||||
.size(18)
|
||||
.into(),
|
||||
status_badge(&state.status),
|
||||
],
|
||||
vec![
|
||||
button(text(t(locale, "common.save")).size(13))
|
||||
.on_press(Message::TranslationEditor(TranslationEditorMsg::Save))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "editor.publish")).size(13))
|
||||
.on_press(Message::TranslationEditor(TranslationEditorMsg::Publish))
|
||||
.style(inputs::primary_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
button(text(t(locale, "modal.confirmDelete.delete")).size(13))
|
||||
.on_press(Message::TranslationEditor(TranslationEditorMsg::Delete))
|
||||
.style(inputs::danger_button)
|
||||
.padding([6, 16])
|
||||
.into(),
|
||||
],
|
||||
);
|
||||
|
||||
let title_input = inputs::labeled_input(
|
||||
&t(locale, "editor.title"),
|
||||
&t(locale, "editor.titlePlaceholder"),
|
||||
&state.title,
|
||||
|s| Message::TranslationEditor(TranslationEditorMsg::TitleChanged(s)),
|
||||
);
|
||||
|
||||
let excerpt_input = inputs::labeled_input(
|
||||
&t(locale, "editor.excerpt"),
|
||||
&t(locale, "editor.excerptPlaceholder"),
|
||||
&state.excerpt,
|
||||
|s| Message::TranslationEditor(TranslationEditorMsg::ExcerptChanged(s)),
|
||||
);
|
||||
|
||||
let content_section: Element<'a, Message> = column![
|
||||
inputs::section_header(&t(locale, "editor.content")),
|
||||
container(
|
||||
text_input(&t(locale, "editor.contentPlaceholder"), &state.content)
|
||||
.on_input(|s| Message::TranslationEditor(TranslationEditorMsg::ContentChanged(s)))
|
||||
.size(14)
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fixed(300.0)),
|
||||
]
|
||||
.spacing(8)
|
||||
.width(Length::Fill)
|
||||
.into();
|
||||
|
||||
let footer = row![
|
||||
inputs::date_label(&t(locale, "editor.createdAt"), state.created_at),
|
||||
Space::with_width(Length::Fixed(24.0)),
|
||||
inputs::date_label(&t(locale, "editor.updatedAt"), state.updated_at),
|
||||
]
|
||||
.padding(8);
|
||||
|
||||
let body = scrollable(
|
||||
column![
|
||||
header,
|
||||
title_input,
|
||||
excerpt_input,
|
||||
content_section,
|
||||
footer,
|
||||
]
|
||||
.spacing(12)
|
||||
.padding(16)
|
||||
.width(Length::Fill),
|
||||
);
|
||||
|
||||
container(body)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn status_badge<'a>(status: &str) -> Element<'a, Message> {
|
||||
let (label, color) = match status {
|
||||
"published" => ("Published", Color::from_rgb(0.2, 0.7, 0.3)),
|
||||
_ => ("Draft", Color::from_rgb(0.8, 0.7, 0.2)),
|
||||
};
|
||||
container(text(label).size(11).color(color))
|
||||
.padding([2, 8])
|
||||
.style(move |_: &Theme| container::Style {
|
||||
border: iced::Border {
|
||||
radius: 4.0.into(),
|
||||
width: 1.0,
|
||||
color,
|
||||
},
|
||||
..container::Style::default()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
use iced::widget::{button, column, container, mouse_area, row, stack, text, Space};
|
||||
@@ -12,7 +13,16 @@ use crate::state::navigation::{OutputEntry, PanelTab, SidebarView, TaskSnapshot}
|
||||
use crate::state::sidebar_filter::{PostFilter, MediaFilter};
|
||||
use crate::state::tabs::{Tab, TabType};
|
||||
use crate::state::toast::Toast;
|
||||
use crate::views::{activity_bar, modal, panel, project_selector, sidebar, status_bar, tab_bar, toast, welcome};
|
||||
use crate::views::{
|
||||
activity_bar, modal, panel, project_selector, sidebar, status_bar, tab_bar, toast, welcome,
|
||||
post_editor::{self, PostEditorState},
|
||||
media_editor::{self, MediaEditorState},
|
||||
template_editor::{self, TemplateEditorState},
|
||||
script_editor::{self, ScriptEditorState},
|
||||
tags_view::{self, TagsViewState},
|
||||
settings_view::{self, SettingsViewState},
|
||||
dashboard::DashboardState,
|
||||
};
|
||||
|
||||
/// Main content area background.
|
||||
fn content_bg(_theme: &Theme) -> container::Style {
|
||||
@@ -31,7 +41,7 @@ fn drag_handle_style(_theme: &Theme) -> container::Style {
|
||||
}
|
||||
|
||||
/// Horizontal line separator (full width).
|
||||
fn separator_h() -> iced::widget::Container<'static, Message> {
|
||||
fn separator_h<'a>() -> Element<'a, Message> {
|
||||
container(Space::new(0, 0))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fixed(1.0))
|
||||
@@ -39,57 +49,70 @@ fn separator_h() -> iced::widget::Container<'static, Message> {
|
||||
background: Some(Background::Color(Color::from_rgb(0.25, 0.25, 0.30))),
|
||||
..container::Style::default()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Compose the full workspace layout.
|
||||
pub fn view(
|
||||
pub fn view<'a>(
|
||||
// Navigation
|
||||
sidebar_view: SidebarView,
|
||||
sidebar_visible: bool,
|
||||
sidebar_width: f32,
|
||||
// Tabs
|
||||
tabs: &[Tab],
|
||||
active_tab: Option<&str>,
|
||||
tabs: &'a [Tab],
|
||||
active_tab: Option<&'a str>,
|
||||
// Panel
|
||||
panel_visible: bool,
|
||||
panel_tab: PanelTab,
|
||||
task_snapshots: &[TaskSnapshot],
|
||||
output_entries: &[OutputEntry],
|
||||
task_snapshots: &'a [TaskSnapshot],
|
||||
output_entries: &'a [OutputEntry],
|
||||
// Sidebar data
|
||||
sidebar_posts: &[Post],
|
||||
sidebar_media: &[Media],
|
||||
sidebar_scripts: &[Script],
|
||||
sidebar_templates: &[Template],
|
||||
sidebar_posts: &'a [Post],
|
||||
sidebar_media: &'a [Media],
|
||||
sidebar_scripts: &'a [Script],
|
||||
sidebar_templates: &'a [Template],
|
||||
// Sidebar filters
|
||||
post_filter: &PostFilter,
|
||||
media_filter: &MediaFilter,
|
||||
post_filter: &'a PostFilter,
|
||||
media_filter: &'a MediaFilter,
|
||||
// Status bar
|
||||
active_project_name: Option<&str>,
|
||||
projects: &[Project],
|
||||
active_project_id: Option<&str>,
|
||||
active_project_name: Option<&'a str>,
|
||||
projects: &'a [Project],
|
||||
active_project_id: Option<&'a str>,
|
||||
post_count: usize,
|
||||
media_count: usize,
|
||||
offline_mode: bool,
|
||||
locale_dropdown_open: bool,
|
||||
project_dropdown_open: bool,
|
||||
theme_badge: &str,
|
||||
theme_badge: &'a str,
|
||||
// i18n
|
||||
locale: UiLocale,
|
||||
// Toasts
|
||||
toasts: &[Toast],
|
||||
toasts: &'a [Toast],
|
||||
// Modal
|
||||
active_modal: Option<&modal::ModalState>,
|
||||
active_modal: Option<&'a modal::ModalState>,
|
||||
// Data directory (for thumbnail paths)
|
||||
data_dir: Option<&Path>,
|
||||
) -> Element<'static, Message> {
|
||||
data_dir: Option<&'a Path>,
|
||||
// Editor states
|
||||
post_editors: &'a HashMap<String, PostEditorState>,
|
||||
media_editors: &'a HashMap<String, MediaEditorState>,
|
||||
template_editors: &'a HashMap<String, TemplateEditorState>,
|
||||
script_editors: &'a HashMap<String, ScriptEditorState>,
|
||||
tags_view_state: Option<&'a TagsViewState>,
|
||||
settings_state: Option<&'a SettingsViewState>,
|
||||
dashboard_state: Option<&'a DashboardState>,
|
||||
) -> Element<'a, Message> {
|
||||
// Activity bar (leftmost column)
|
||||
let activity = activity_bar::view(sidebar_view, sidebar_visible, locale);
|
||||
|
||||
// Tab bar
|
||||
let tabs_el = tab_bar::view(tabs, active_tab, locale);
|
||||
|
||||
// Content area
|
||||
let content_area = welcome::view(locale);
|
||||
// Content area — route based on active tab type
|
||||
let content_area = route_content_area(
|
||||
tabs, active_tab, locale, data_dir,
|
||||
post_editors, media_editors, template_editors, script_editors,
|
||||
tags_view_state, settings_state, dashboard_state,
|
||||
);
|
||||
|
||||
// Right column: tab bar + content + panel
|
||||
let mut right_col = column![tabs_el, content_area];
|
||||
@@ -163,14 +186,14 @@ pub fn view(
|
||||
active_post_status.as_deref(),
|
||||
);
|
||||
|
||||
let base_layout: Element<'static, Message> = column![main_row, separator_h(), status]
|
||||
let base_layout: Element<'a, Message> = column![main_row, separator_h(), status]
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into();
|
||||
|
||||
// Overlay: either locale dropdown or project dropdown (mutually exclusive)
|
||||
let overlay: Option<Element<'static, Message>> = if locale_dropdown_open {
|
||||
let items: Vec<Element<'static, Message>> = UiLocale::all()
|
||||
let overlay: Option<Element<'a, Message>> = if locale_dropdown_open {
|
||||
let items: Vec<Element<'a, Message>> = UiLocale::all()
|
||||
.iter()
|
||||
.map(|&l| {
|
||||
let flag_text = text(l.flag_emoji())
|
||||
@@ -236,7 +259,7 @@ pub fn view(
|
||||
};
|
||||
|
||||
// Collect overlays: dropdowns and toasts
|
||||
let mut overlays: Vec<Element<'static, Message>> = Vec::new();
|
||||
let mut overlays: Vec<Element<'a, Message>> = Vec::new();
|
||||
|
||||
if let Some(toast_overlay) = toast::view(toasts) {
|
||||
overlays.push(toast_overlay);
|
||||
@@ -262,3 +285,83 @@ pub fn view(
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Route the content area based on the active tab type.
|
||||
fn route_content_area<'a>(
|
||||
tabs: &'a [Tab],
|
||||
active_tab: Option<&'a str>,
|
||||
locale: UiLocale,
|
||||
data_dir: Option<&'a Path>,
|
||||
post_editors: &'a HashMap<String, PostEditorState>,
|
||||
media_editors: &'a HashMap<String, MediaEditorState>,
|
||||
template_editors: &'a HashMap<String, TemplateEditorState>,
|
||||
script_editors: &'a HashMap<String, ScriptEditorState>,
|
||||
tags_view_state: Option<&'a TagsViewState>,
|
||||
settings_state: Option<&'a SettingsViewState>,
|
||||
_dashboard_state: Option<&'a DashboardState>,
|
||||
) -> Element<'a, Message> {
|
||||
let Some(tab_id) = active_tab else {
|
||||
return welcome::view(locale);
|
||||
};
|
||||
let Some(tab) = tabs.iter().find(|t| t.id == tab_id) else {
|
||||
return welcome::view(locale);
|
||||
};
|
||||
|
||||
match tab.tab_type {
|
||||
TabType::Post => {
|
||||
if let Some(state) = post_editors.get(tab_id) {
|
||||
post_editor::view(state, locale)
|
||||
} else {
|
||||
loading_view(locale)
|
||||
}
|
||||
}
|
||||
TabType::Media => {
|
||||
if let Some(state) = media_editors.get(tab_id) {
|
||||
media_editor::view(state, locale, data_dir)
|
||||
} else {
|
||||
loading_view(locale)
|
||||
}
|
||||
}
|
||||
TabType::Templates => {
|
||||
if let Some(state) = template_editors.get(tab_id) {
|
||||
template_editor::view(state, locale)
|
||||
} else {
|
||||
loading_view(locale)
|
||||
}
|
||||
}
|
||||
TabType::Scripts => {
|
||||
if let Some(state) = script_editors.get(tab_id) {
|
||||
script_editor::view(state, locale)
|
||||
} else {
|
||||
loading_view(locale)
|
||||
}
|
||||
}
|
||||
TabType::Tags => {
|
||||
if let Some(state) = tags_view_state {
|
||||
tags_view::view(state, locale)
|
||||
} else {
|
||||
loading_view(locale)
|
||||
}
|
||||
}
|
||||
TabType::Settings => {
|
||||
if let Some(state) = settings_state {
|
||||
settings_view::view(state, locale)
|
||||
} else {
|
||||
loading_view(locale)
|
||||
}
|
||||
}
|
||||
_ => welcome::view(locale),
|
||||
}
|
||||
}
|
||||
|
||||
fn loading_view<'a>(locale: UiLocale) -> Element<'a, Message> {
|
||||
use crate::i18n::t;
|
||||
container(
|
||||
text(t(locale, "tabBar.loading")).size(14).color(Color::from_rgb(0.5, 0.5, 0.5)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.center_x(Length::Fill)
|
||||
.center_y(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user