presentations can show only the slides in their index ranges
This means that we only generate slides for these indexes.
This commit is contained in:
parent
5d5ea1f78f
commit
001650a656
1 changed files with 45 additions and 3 deletions
|
|
@ -186,6 +186,15 @@ impl ServiceTrait for Presentation {
|
||||||
|
|
||||||
fn to_slides(&self) -> Result<Vec<Slide>> {
|
fn to_slides(&self) -> Result<Vec<Slide>> {
|
||||||
debug!(?self);
|
debug!(?self);
|
||||||
|
let PresKind::Pdf {
|
||||||
|
starting_index,
|
||||||
|
ending_index,
|
||||||
|
} = self.kind
|
||||||
|
else {
|
||||||
|
return Err(miette::miette!(
|
||||||
|
"This is not a pdf presentation"
|
||||||
|
));
|
||||||
|
};
|
||||||
let background = Background::try_from(self.path.clone())
|
let background = Background::try_from(self.path.clone())
|
||||||
.into_diagnostic()?;
|
.into_diagnostic()?;
|
||||||
debug!(?background);
|
debug!(?background);
|
||||||
|
|
@ -219,6 +228,12 @@ impl ServiceTrait for Presentation {
|
||||||
|
|
||||||
let mut slides: Vec<Slide> = vec![];
|
let mut slides: Vec<Slide> = vec![];
|
||||||
for (index, page) in pages.into_iter().enumerate() {
|
for (index, page) in pages.into_iter().enumerate() {
|
||||||
|
if (index as i32) < starting_index {
|
||||||
|
continue;
|
||||||
|
} else if (index as i32) > ending_index {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let slide = SlideBuilder::new()
|
let slide = SlideBuilder::new()
|
||||||
.background(
|
.background(
|
||||||
Background::try_from(self.path.clone())
|
Background::try_from(self.path.clone())
|
||||||
|
|
@ -307,7 +322,7 @@ impl Model<Presentation> {
|
||||||
let _ = self.add_item(Presentation {
|
let _ = self.add_item(Presentation {
|
||||||
id: presentation.id,
|
id: presentation.id,
|
||||||
title: presentation.title,
|
title: presentation.title,
|
||||||
path: presentation.path.into(),
|
path: presentation.path.clone().into(),
|
||||||
kind: if presentation.html {
|
kind: if presentation.html {
|
||||||
PresKind::Html
|
PresKind::Html
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -323,9 +338,30 @@ impl Model<Presentation> {
|
||||||
as i32,
|
as i32,
|
||||||
ending_index: ending_index as i32,
|
ending_index: ending_index as i32,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
let path =
|
||||||
|
PathBuf::from(presentation.path);
|
||||||
|
if let Ok(document) =
|
||||||
|
Document::open(path.as_path())
|
||||||
|
{
|
||||||
|
if let Ok(count) =
|
||||||
|
document.page_count()
|
||||||
|
{
|
||||||
|
let ending_index = count - 1;
|
||||||
|
PresKind::Pdf {
|
||||||
|
starting_index: 0,
|
||||||
|
ending_index,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PresKind::Pdf {
|
||||||
|
starting_index: 0,
|
||||||
|
ending_index: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PresKind::Generic
|
PresKind::Generic
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -485,7 +521,13 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_pres() {
|
pub fn test_pres() {
|
||||||
let pres = Presentation::new();
|
let pres = Presentation::new();
|
||||||
assert_eq!(pres.get_kind(), &PresKind::Pdf)
|
assert_eq!(
|
||||||
|
pres.get_kind(),
|
||||||
|
&PresKind::Pdf {
|
||||||
|
starting_index: 0,
|
||||||
|
ending_index: 0,
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue