more things, but mostly starting to add library management
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-15 14:42:07 -05:00
parent 3fe77c93e2
commit 645411b59c
13 changed files with 341 additions and 260 deletions

View file

@ -52,7 +52,9 @@ impl Content for Image {
if self.path.exists() {
self.path
.file_name()
.map_or("Missing image".into(), |f| f.to_string_lossy().to_string())
.map_or("Missing image".into(), |f| {
f.to_string_lossy().to_string()
})
} else {
"Missing image".into()
}
@ -158,7 +160,9 @@ impl Model<Image> {
}
}
Err(e) => {
error!("There was an error in converting images: {e}");
error!(
"There was an error in converting images: {e}"
);
}
}
}

View file

@ -21,11 +21,11 @@ pub enum ServiceItemKind {
impl std::fmt::Display for ServiceItemKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let s = match self {
Self::Song(s) => "song".to_owned(),
Self::Image(i) => "image".to_owned(),
Self::Video(v) => "video".to_owned(),
Self::Presentation(p) => "html".to_owned(),
Self::Content(s) => "content".to_owned(),
Self::Song(_) => "song".to_owned(),
Self::Image(_) => "image".to_owned(),
Self::Video(_) => "video".to_owned(),
Self::Presentation(_) => "html".to_owned(),
Self::Content(_) => "content".to_owned(),
};
write!(f, "{s}")
}
@ -76,7 +76,9 @@ impl Display for ParseError {
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
let message = match self {
Self::UnknownType => "The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'",
Self::UnknownType => {
"The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'"
}
};
write!(f, "Error: {message}")
}

View file

@ -1,7 +1,6 @@
use std::mem::replace;
use cosmic::iced::Executor;
use miette::{miette, Result};
use miette::{Result, miette};
use sqlx::{Connection, SqliteConnection};
#[derive(Debug, Clone)]
@ -46,7 +45,8 @@ impl<T> Model<T> {
Ok(())
}
#[must_use] pub fn get_item(&self, index: i32) -> Option<&T> {
#[must_use]
pub fn get_item(&self, index: i32) -> Option<&T> {
self.items.get(index as usize)
}

View file

@ -75,7 +75,9 @@ impl Content for Presentation {
if self.path.exists() {
self.path
.file_name()
.map_or("Missing presentation".into(), |f| f.to_string_lossy().to_string())
.map_or("Missing presentation".into(), |f| {
f.to_string_lossy().to_string()
})
} else {
"Missing presentation".into()
}
@ -189,14 +191,16 @@ impl ServiceTrait for Presentation {
}
impl Presentation {
#[must_use] pub fn new() -> Self {
#[must_use]
pub fn new() -> Self {
Self {
title: String::new(),
..Default::default()
}
}
#[must_use] pub const fn get_kind(&self) -> &PresKind {
#[must_use]
pub const fn get_kind(&self) -> &PresKind {
&self.kind
}
}

View file

@ -172,30 +172,32 @@ impl From<&Value> for ServiceItem {
} else if let Some(background) =
list.get(background_pos)
{
if let Value::List(item) = background { match &item[0] {
Value::Symbol(Symbol(s))
if s == "image" =>
{
Self::from(&Image::from(
background,
))
if let Value::List(item) = background {
match &item[0] {
Value::Symbol(Symbol(s))
if s == "image" =>
{
Self::from(&Image::from(
background,
))
}
Value::Symbol(Symbol(s))
if s == "video" =>
{
Self::from(&Video::from(
background,
))
}
Value::Symbol(Symbol(s))
if s == "presentation" =>
{
Self::from(&Presentation::from(
background,
))
}
_ => todo!(),
}
Value::Symbol(Symbol(s))
if s == "video" =>
{
Self::from(&Video::from(
background,
))
}
Value::Symbol(Symbol(s))
if s == "presentation" =>
{
Self::from(&Presentation::from(
background,
))
}
_ => todo!(),
} } else {
} else {
error!(
"There is no background here: {:?}",
background

View file

@ -1,16 +1,15 @@
use std::{collections::HashMap, option::Option, path::PathBuf};
use cosmic::iced::Executor;
use crisp::types::{Keyword, Symbol, Value};
use miette::{miette, IntoDiagnostic, Result};
use miette::{IntoDiagnostic, Result, miette};
use serde::{Deserialize, Serialize};
use sqlx::{
pool::PoolConnection, query, sqlite::SqliteRow, FromRow, Row,
Sqlite, SqliteConnection, SqlitePool,
FromRow, Row, Sqlite, SqliteConnection, SqlitePool,
pool::PoolConnection, query, sqlite::SqliteRow,
};
use tracing::error;
use crate::{core::slide, Slide, SlideBuilder};
use crate::{Slide, SlideBuilder, core::slide};
use super::{
content::Content,
@ -128,7 +127,9 @@ impl FromRow<'_, SqliteRow> for Song {
})),
verse_order: Some({
let str: &str = row.try_get(0)?;
str.split(' ').map(std::string::ToString::to_string).collect()
str.split(' ')
.map(std::string::ToString::to_string)
.collect()
}),
background: {
let string: String = row.try_get(7)?;
@ -250,8 +251,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
.position(|v| v == &Value::Keyword(Keyword::from("title")))
{
let pos = key_pos + 1;
list.get(pos)
.map_or(String::from("song"), String::from)
list.get(pos).map_or(String::from("song"), String::from)
} else {
String::from("song")
};
@ -625,7 +625,27 @@ You saved my soul"
let lyrics = song.get_lyrics();
match lyrics {
Ok(lyrics) => {
assert_eq!(vec!["From the Day\nI Am They", "When You found me,\nI was so blind\nMy sin was before me,\nI was swallowed by pride", "But out of the darkness,\nYou brought me to Your light\nYou showed me new mercy\nAnd opened up my eyes", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "Where brilliant light\nIs all around\nAnd endless joy\nIs the only sound", "Oh, rest my heart\nForever now\nOh, in Your arms\nI'll always be found", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "My love is Yours\nMy heart is Yours\nMy life is Yours\nForever", "My love is Yours\nMy heart is Yours\nMy life is Yours\nForever", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "From the day\nYou saved my soul\n'Til the very moment\nWhen I come home", "I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul", "Oh Oh Oh\nFrom the day\nYou saved my soul\n"], lyrics);
assert_eq!(
vec![
"From the Day\nI Am They",
"When You found me,\nI was so blind\nMy sin was before me,\nI was swallowed by pride",
"But out of the darkness,\nYou brought me to Your light\nYou showed me new mercy\nAnd opened up my eyes",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"Where brilliant light\nIs all around\nAnd endless joy\nIs the only sound",
"Oh, rest my heart\nForever now\nOh, in Your arms\nI'll always be found",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"My love is Yours\nMy heart is Yours\nMy life is Yours\nForever",
"My love is Yours\nMy heart is Yours\nMy life is Yours\nForever",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"From the day\nYou saved my soul\n'Til the very moment\nWhen I come home",
"I'll sing, I'll dance,\nMy heart will overflow\nFrom the day\nYou saved my soul",
"Oh Oh Oh\nFrom the day\nYou saved my soul\n"
],
lyrics
);
}
Err(e) => {
assert!(false, "{:?}", e)

View file

@ -7,13 +7,12 @@ use super::{
service_items::ServiceTrait,
slide::Slide,
};
use cosmic::iced::Executor;
use crisp::types::{Keyword, Symbol, Value};
use miette::{IntoDiagnostic, Result};
use serde::{Deserialize, Serialize};
use sqlx::{
pool::PoolConnection, query, query_as, Sqlite, SqliteConnection,
SqlitePool,
Sqlite, SqliteConnection, SqlitePool, pool::PoolConnection,
query, query_as,
};
use std::path::PathBuf;
use tracing::error;
@ -57,7 +56,9 @@ impl Content for Video {
if self.path.exists() {
self.path
.file_name()
.map_or("Missing video".into(), |f| f.to_string_lossy().to_string())
.map_or("Missing video".into(), |f| {
f.to_string_lossy().to_string()
})
} else {
"Missing video".into()
}
@ -196,7 +197,9 @@ impl Model<Video> {
}
}
Err(e) => {
error!("There was an error in converting videos: {e}");
error!(
"There was an error in converting videos: {e}"
);
}
}
}