moving the lisp presentation parsing to service_items
Since we need the nav_bar to have the ServiceItemModel, the presentation needs to be a list of service items, not slides, each service item will have a list of slides attached though.
This commit is contained in:
parent
9eb5bec320
commit
cb7fa372a9
9 changed files with 493 additions and 79 deletions
|
@ -1,5 +1,10 @@
|
|||
use super::model::Model;
|
||||
use crate::{Background, SlideBuilder, TextAlignment};
|
||||
|
||||
use super::{
|
||||
model::Model, service_items::ServiceTrait, slide::Slide,
|
||||
};
|
||||
use cosmic::{executor, iced::Executor};
|
||||
use crisp::types::Value;
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{query_as, SqliteConnection};
|
||||
|
@ -18,6 +23,51 @@ pub struct Video {
|
|||
pub looping: bool,
|
||||
}
|
||||
|
||||
impl From<Value> for Video {
|
||||
fn from(value: Value) -> Self {
|
||||
Self::from(&value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Value> for Video {
|
||||
fn from(value: &Value) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl ServiceTrait for Video {
|
||||
fn title(&self) -> String {
|
||||
self.title.clone()
|
||||
}
|
||||
|
||||
fn id(&self) -> i32 {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn to_slides(&self) -> Result<Vec<Slide>> {
|
||||
let slide = SlideBuilder::new()
|
||||
.background(
|
||||
Background::try_from(self.path.clone())
|
||||
.into_diagnostic()?,
|
||||
)
|
||||
.text("")
|
||||
.audio("")
|
||||
.font("")
|
||||
.font_size(50)
|
||||
.text_alignment(TextAlignment::MiddleCenter)
|
||||
.video_loop(self.looping)
|
||||
.video_start_time(self.start_time.unwrap_or(0.0))
|
||||
.video_end_time(self.end_time.unwrap_or(0.0))
|
||||
.build()?;
|
||||
|
||||
Ok(vec![slide])
|
||||
}
|
||||
|
||||
fn box_clone(&self) -> Box<dyn ServiceTrait> {
|
||||
Box::new((*self).clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Model<Video> {
|
||||
pub async fn load_from_db(&mut self) {
|
||||
let result = query_as!(Video, r#"SELECT title as "title!", file_path as "path!", start_time as "start_time!: f32", end_time as "end_time!: f32", loop as "looping!", id as "id: i32" from videos"#).fetch_all(&mut self.db).await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue