mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Inital library manager UI
This commit is contained in:
parent
38638d6fcd
commit
f0135cd415
8 changed files with 1528 additions and 486 deletions
111
src/library.rs
111
src/library.rs
|
|
@ -1,8 +1,9 @@
|
|||
use std::{
|
||||
cell::{OnceCell, RefCell},
|
||||
path::{Path, PathBuf},
|
||||
use crate::{
|
||||
db::{self, models::*, schema::*, tables, TranslatedString},
|
||||
program::Program,
|
||||
};
|
||||
|
||||
use adw::gtk::{glib, glib::Properties, prelude::*, subclass::prelude::*};
|
||||
use anyhow::Result;
|
||||
use chrono::prelude::*;
|
||||
use diesel::{
|
||||
|
|
@ -12,11 +13,10 @@ use diesel::{
|
|||
sql_types::BigInt,
|
||||
QueryDsl, SqliteConnection,
|
||||
};
|
||||
use gtk::{glib, glib::Properties, prelude::*, subclass::prelude::*};
|
||||
|
||||
use crate::{
|
||||
db::{self, models::*, schema::*, tables, TranslatedString},
|
||||
program::Program,
|
||||
use std::{
|
||||
cell::{OnceCell, RefCell},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
diesel::define_sql_function! {
|
||||
|
|
@ -537,6 +537,15 @@ impl MusicusLibrary {
|
|||
Ok(persons)
|
||||
}
|
||||
|
||||
pub fn all_persons(&self) -> Result<Vec<Person>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let persons = persons::table.order(persons::name).load(connection)?;
|
||||
|
||||
Ok(persons)
|
||||
}
|
||||
|
||||
pub fn search_roles(&self, search: &str) -> Result<Vec<Role>> {
|
||||
let search = format!("%{}%", search);
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
|
|
@ -551,6 +560,15 @@ impl MusicusLibrary {
|
|||
Ok(roles)
|
||||
}
|
||||
|
||||
pub fn all_roles(&self) -> Result<Vec<Role>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let roles = roles::table.order(roles::name).load(connection)?;
|
||||
|
||||
Ok(roles)
|
||||
}
|
||||
|
||||
pub fn search_instruments(&self, search: &str) -> Result<Vec<Instrument>> {
|
||||
let search = format!("%{}%", search);
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
|
|
@ -565,6 +583,17 @@ impl MusicusLibrary {
|
|||
Ok(instruments)
|
||||
}
|
||||
|
||||
pub fn all_instruments(&self) -> Result<Vec<Instrument>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let instruments = instruments::table
|
||||
.order(instruments::name)
|
||||
.load(connection)?;
|
||||
|
||||
Ok(instruments)
|
||||
}
|
||||
|
||||
pub fn search_works(&self, composer: &Person, search: &str) -> Result<Vec<Work>> {
|
||||
let search = format!("%{}%", search);
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
|
|
@ -588,6 +617,20 @@ impl MusicusLibrary {
|
|||
Ok(works)
|
||||
}
|
||||
|
||||
pub fn all_works(&self) -> Result<Vec<Work>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let works = works::table
|
||||
.order(works::name)
|
||||
.load::<tables::Work>(connection)?
|
||||
.into_iter()
|
||||
.map(|w| Work::from_table(w, connection))
|
||||
.collect::<Result<Vec<Work>>>()?;
|
||||
|
||||
Ok(works)
|
||||
}
|
||||
|
||||
pub fn search_ensembles(&self, search: &str) -> Result<Vec<Ensemble>> {
|
||||
let search = format!("%{}%", search);
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
|
|
@ -611,6 +654,60 @@ impl MusicusLibrary {
|
|||
Ok(ensembles)
|
||||
}
|
||||
|
||||
pub fn all_ensembles(&self) -> Result<Vec<Ensemble>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let ensembles = ensembles::table
|
||||
.order(ensembles::name)
|
||||
.load::<tables::Ensemble>(connection)?
|
||||
.into_iter()
|
||||
.map(|e| Ensemble::from_table(e, connection))
|
||||
.collect::<Result<Vec<Ensemble>>>()?;
|
||||
|
||||
Ok(ensembles)
|
||||
}
|
||||
|
||||
pub fn all_recordings(&self) -> Result<Vec<Recording>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let recordings = recordings::table
|
||||
.load::<tables::Recording>(connection)?
|
||||
.into_iter()
|
||||
.map(|e| Recording::from_table(e, connection))
|
||||
.collect::<Result<Vec<Recording>>>()?;
|
||||
|
||||
Ok(recordings)
|
||||
}
|
||||
|
||||
pub fn all_tracks(&self) -> Result<Vec<Track>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let tracks = tracks::table
|
||||
.load::<tables::Track>(connection)?
|
||||
.into_iter()
|
||||
.map(|e| Track::from_table(e, connection))
|
||||
.collect::<Result<Vec<Track>>>()?;
|
||||
|
||||
Ok(tracks)
|
||||
}
|
||||
|
||||
pub fn all_mediums(&self) -> Result<Vec<tables::Medium>> {
|
||||
// TODO
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
pub fn all_albums(&self) -> Result<Vec<Album>> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
||||
let albums = albums::table.load::<Album>(connection)?;
|
||||
|
||||
Ok(albums)
|
||||
}
|
||||
|
||||
pub fn composer_default_role(&self) -> Result<Role> {
|
||||
let mut binding = self.imp().connection.borrow_mut();
|
||||
let connection = &mut *binding.as_mut().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue