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:
Chris Cochrun 2024-12-10 09:27:50 -06:00
parent 9eb5bec320
commit cb7fa372a9
9 changed files with 493 additions and 79 deletions

View file

@ -2,65 +2,65 @@ use std::{error::Error, fmt::Display};
use serde::{Deserialize, Serialize};
use super::presentations::PresKind;
use crate::Slide;
#[derive(
Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize,
)]
use super::{
images::Image,
presentations::{PresKind, Presentation},
songs::Song,
videos::Video,
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ServiceItemKind {
#[default]
Song,
Video,
Image,
Presentation(PresKind),
Content,
Song(Song),
Video(Video),
Image(Image),
Presentation((Presentation, PresKind)),
Content(Slide),
}
impl std::fmt::Display for ServiceItemKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let s = match self {
Self::Song => "song".to_owned(),
Self::Image => "image".to_owned(),
Self::Video => "video".to_owned(),
Self::Presentation(PresKind::Html) => "html".to_owned(),
Self::Presentation(PresKind::Pdf) => "pdf".to_owned(),
Self::Presentation(PresKind::Generic) => {
"presentation".to_owned()
}
Self::Content => "content".to_owned(),
Self::Song(s) => "song".to_owned(),
Self::Image(i) => "image".to_owned(),
Self::Video(v) => "video".to_owned(),
Self::Presentation((p, k)) => "html".to_owned(),
Self::Content(s) => "content".to_owned(),
};
write!(f, "{s}")
}
}
impl TryFrom<String> for ServiceItemKind {
type Error = ParseError;
fn try_from(value: String) -> Result<Self, Self::Error> {
match value.as_str() {
"song" => Ok(Self::Song),
"image" => Ok(Self::Image),
"video" => Ok(Self::Video),
"presentation" => {
Ok(Self::Presentation(PresKind::Generic))
}
"html" => Ok(Self::Presentation(PresKind::Html)),
"pdf" => Ok(Self::Presentation(PresKind::Pdf)),
"content" => Ok(Self::Content),
_ => Err(ParseError::UnknownType),
}
}
}
// impl TryFrom<String> for ServiceItemKind {
// type Error = ParseError;
// fn try_from(value: String) -> Result<Self, Self::Error> {
// match value.as_str() {
// "song" => Ok(Self::Song),
// "image" => Ok(Self::Image),
// "video" => Ok(Self::Video),
// "presentation" => {
// Ok(Self::Presentation(PresKind::Generic))
// }
// "html" => Ok(Self::Presentation(PresKind::Html)),
// "pdf" => Ok(Self::Presentation(PresKind::Pdf)),
// "content" => Ok(Self::Content),
// _ => Err(ParseError::UnknownType),
// }
// }
// }
impl From<ServiceItemKind> for String {
fn from(val: ServiceItemKind) -> String {
match val {
ServiceItemKind::Song => "song".to_owned(),
ServiceItemKind::Video => "video".to_owned(),
ServiceItemKind::Image => "image".to_owned(),
ServiceItemKind::Song(_) => "song".to_owned(),
ServiceItemKind::Video(_) => "video".to_owned(),
ServiceItemKind::Image(_) => "image".to_owned(),
ServiceItemKind::Presentation(_) => {
"presentation".to_owned()
}
ServiceItemKind::Content => "content".to_owned(),
ServiceItemKind::Content(_) => "content".to_owned(),
}
}
}