This commit is contained in:
parent
1a97622926
commit
b4311a613e
3 changed files with 57 additions and 40 deletions
|
|
@ -421,13 +421,13 @@ pub async fn remove_from_db(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_song_to_db(
|
pub async fn add_song_to_db(
|
||||||
song: Song,
|
|
||||||
db: PoolConnection<Sqlite>,
|
db: PoolConnection<Sqlite>,
|
||||||
) -> Result<()> {
|
) -> Result<Song> {
|
||||||
let mut db = db.detach();
|
let mut db = db.detach();
|
||||||
|
let mut song = Song::default();
|
||||||
|
|
||||||
let verse_order = {
|
let verse_order = {
|
||||||
if let Some(vo) = song.verse_order {
|
if let Some(vo) = song.verse_order.clone() {
|
||||||
vo.into_iter()
|
vo.into_iter()
|
||||||
.map(|mut s| {
|
.map(|mut s| {
|
||||||
s.push(' ');
|
s.push(' ');
|
||||||
|
|
@ -441,13 +441,15 @@ pub async fn add_song_to_db(
|
||||||
|
|
||||||
let audio = song
|
let audio = song
|
||||||
.audio
|
.audio
|
||||||
|
.clone()
|
||||||
.map(|a| a.to_str().unwrap_or_default().to_string());
|
.map(|a| a.to_str().unwrap_or_default().to_string());
|
||||||
|
|
||||||
let background = song
|
let background = song
|
||||||
.background
|
.background
|
||||||
|
.clone()
|
||||||
.map(|b| b.path.to_str().unwrap_or_default().to_string());
|
.map(|b| b.path.to_str().unwrap_or_default().to_string());
|
||||||
|
|
||||||
query!(
|
let res = query!(
|
||||||
r#"INSERT INTO songs (title, lyrics, author, ccli, verse_order, audio, font, font_size, background) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)"#,
|
r#"INSERT INTO songs (title, lyrics, author, ccli, verse_order, audio, font, font_size, background) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)"#,
|
||||||
song.title,
|
song.title,
|
||||||
song.lyrics,
|
song.lyrics,
|
||||||
|
|
@ -462,7 +464,8 @@ pub async fn add_song_to_db(
|
||||||
.execute(&mut db)
|
.execute(&mut db)
|
||||||
.await
|
.await
|
||||||
.into_diagnostic()?;
|
.into_diagnostic()?;
|
||||||
Ok(())
|
song.id = res.last_insert_rowid() as i32;
|
||||||
|
Ok(song)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_song_in_db(
|
pub async fn update_song_in_db(
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@ pub enum Message {
|
||||||
OpenContext(i32),
|
OpenContext(i32),
|
||||||
None,
|
None,
|
||||||
AddFiles(Vec<ServiceItemKind>),
|
AddFiles(Vec<ServiceItemKind>),
|
||||||
|
AddSong(Song),
|
||||||
AddImages(Option<Vec<Image>>),
|
AddImages(Option<Vec<Image>>),
|
||||||
AddVideos(Option<Vec<Video>>),
|
AddVideos(Option<Vec<Video>>),
|
||||||
AddPresentations(Option<Vec<Presentation>>),
|
AddPresentations(Option<Vec<Presentation>>),
|
||||||
|
|
@ -141,19 +142,37 @@ impl<'a> Library {
|
||||||
Message::DeleteItem => {
|
Message::DeleteItem => {
|
||||||
return self.delete_items();
|
return self.delete_items();
|
||||||
}
|
}
|
||||||
|
Message::AddSong(song) => {
|
||||||
|
if let Err(e) = self.song_library.add_item(song) {
|
||||||
|
error!(?e, "couldn't add song to model");
|
||||||
|
} else {
|
||||||
|
let index =
|
||||||
|
(self.song_library.items.len() - 1) as i32;
|
||||||
|
return Action::Task(Task::done(
|
||||||
|
Message::OpenItem(Some((
|
||||||
|
LibraryKind::Song,
|
||||||
|
index,
|
||||||
|
))),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::AddItem => {
|
Message::AddItem => {
|
||||||
let kind =
|
let kind =
|
||||||
self.library_open.unwrap_or(LibraryKind::Song);
|
self.library_open.unwrap_or(LibraryKind::Song);
|
||||||
let item = match kind {
|
match kind {
|
||||||
LibraryKind::Song => {
|
LibraryKind::Song => {
|
||||||
let song = Song::default();
|
let song = Song::default();
|
||||||
let index = self.song_library.items.len();
|
let task = Task::future(self.db.acquire()).and_then(move |db| {
|
||||||
self.song_library
|
Task::perform(add_song_to_db(db), move |res| {
|
||||||
.add_item(song)
|
match res {
|
||||||
.map(|_| {
|
Ok(song) => {
|
||||||
(LibraryKind::Song, index as i32)
|
Message::AddSong(song)
|
||||||
|
},
|
||||||
|
Err(e) => {error!(?e, "couldn't add song to db"); Message::None}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.ok()
|
});
|
||||||
|
return Action::Task(task);
|
||||||
}
|
}
|
||||||
LibraryKind::Video => {
|
LibraryKind::Video => {
|
||||||
return Action::Task(Task::perform(
|
return Action::Task(Task::perform(
|
||||||
|
|
@ -174,7 +193,6 @@ impl<'a> Library {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return self.update(Message::OpenItem(item));
|
|
||||||
}
|
}
|
||||||
Message::AddVideos(videos) => {
|
Message::AddVideos(videos) => {
|
||||||
debug!(?videos);
|
debug!(?videos);
|
||||||
|
|
@ -653,30 +671,26 @@ impl<'a> Library {
|
||||||
.add_item(song.clone())
|
.add_item(song.clone())
|
||||||
.err()
|
.err()
|
||||||
else {
|
else {
|
||||||
let task = Task::future(
|
let task =
|
||||||
self.db.acquire(),
|
Task::future(self.db.acquire())
|
||||||
)
|
.and_then(move |db| {
|
||||||
.and_then(move |db| {
|
Task::perform(
|
||||||
Task::perform(
|
add_song_to_db(db),
|
||||||
add_song_to_db(
|
{
|
||||||
song.clone(),
|
move |res| {
|
||||||
db,
|
if let Err(
|
||||||
),
|
e,
|
||||||
{
|
) = res
|
||||||
let song = song.clone();
|
{
|
||||||
move |res| {
|
error!(
|
||||||
debug!(
|
?e
|
||||||
?song,
|
);
|
||||||
"added to db"
|
}
|
||||||
);
|
Message::None
|
||||||
if let Err(e) = res {
|
}
|
||||||
error!(?e);
|
},
|
||||||
}
|
)
|
||||||
Message::None
|
});
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
});
|
|
||||||
tasks.push(task);
|
tasks.push(task);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ impl PresentationEditor {
|
||||||
Self {
|
Self {
|
||||||
presentation: None,
|
presentation: None,
|
||||||
document: None,
|
document: None,
|
||||||
title: "Death was Arrested".to_string(),
|
title: "".to_string(),
|
||||||
editing: false,
|
editing: false,
|
||||||
current_slide: None,
|
current_slide: None,
|
||||||
current_slide_index: None,
|
current_slide_index: None,
|
||||||
|
|
@ -183,7 +183,7 @@ impl PresentationEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<Message> {
|
pub fn view(&self) -> Element<Message> {
|
||||||
let container = if let Some(slide) = &self.current_slide {
|
let presentation = if let Some(slide) = &self.current_slide {
|
||||||
container(
|
container(
|
||||||
widget::image(slide)
|
widget::image(slide)
|
||||||
.content_fit(ContentFit::ScaleDown),
|
.content_fit(ContentFit::ScaleDown),
|
||||||
|
|
@ -199,7 +199,7 @@ impl PresentationEditor {
|
||||||
];
|
];
|
||||||
let column = column![
|
let column = column![
|
||||||
self.toolbar(),
|
self.toolbar(),
|
||||||
container.center(Length::Fill),
|
presentation.center(Length::Fill),
|
||||||
control_buttons
|
control_buttons
|
||||||
]
|
]
|
||||||
.spacing(theme::active().cosmic().space_l());
|
.spacing(theme::active().cosmic().space_l());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue