mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add mediums to person and ensemble screen
This commit is contained in:
parent
026e6deddf
commit
d12b85afc6
2 changed files with 88 additions and 2 deletions
|
|
@ -7,7 +7,7 @@ use gettextrs::gettext;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use libadwaita::prelude::*;
|
use libadwaita::prelude::*;
|
||||||
use musicus_backend::db::{Ensemble, Recording};
|
use musicus_backend::db::{Ensemble, Medium, Recording};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
@ -17,7 +17,9 @@ pub struct EnsembleScreen {
|
||||||
ensemble: Ensemble,
|
ensemble: Ensemble,
|
||||||
widget: widgets::Screen,
|
widget: widgets::Screen,
|
||||||
recording_list: Rc<List>,
|
recording_list: Rc<List>,
|
||||||
|
medium_list: Rc<List>,
|
||||||
recordings: RefCell<Vec<Recording>>,
|
recordings: RefCell<Vec<Recording>>,
|
||||||
|
mediums: RefCell<Vec<Medium>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen<Ensemble, ()> for EnsembleScreen {
|
impl Screen<Ensemble, ()> for EnsembleScreen {
|
||||||
|
|
@ -28,13 +30,16 @@ impl Screen<Ensemble, ()> for EnsembleScreen {
|
||||||
widget.set_title(&ensemble.name);
|
widget.set_title(&ensemble.name);
|
||||||
|
|
||||||
let recording_list = List::new();
|
let recording_list = List::new();
|
||||||
|
let medium_list = List::new();
|
||||||
|
|
||||||
let this = Rc::new(Self {
|
let this = Rc::new(Self {
|
||||||
handle,
|
handle,
|
||||||
ensemble,
|
ensemble,
|
||||||
widget,
|
widget,
|
||||||
recording_list,
|
recording_list,
|
||||||
|
medium_list,
|
||||||
recordings: RefCell::new(Vec::new()),
|
recordings: RefCell::new(Vec::new()),
|
||||||
|
mediums: RefCell::new(Vec::new()),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.widget.set_back_cb(clone!(@weak this => move || {
|
this.widget.set_back_cb(clone!(@weak this => move || {
|
||||||
|
|
@ -58,6 +63,7 @@ impl Screen<Ensemble, ()> for EnsembleScreen {
|
||||||
|
|
||||||
this.widget.set_search_cb(clone!(@weak this => move || {
|
this.widget.set_search_cb(clone!(@weak this => move || {
|
||||||
this.recording_list.invalidate_filter();
|
this.recording_list.invalidate_filter();
|
||||||
|
this.medium_list.invalidate_filter();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.recording_list.set_make_widget_cb(clone!(@weak this => move |index| {
|
this.recording_list.set_make_widget_cb(clone!(@weak this => move |index| {
|
||||||
|
|
@ -86,6 +92,27 @@ impl Screen<Ensemble, ()> for EnsembleScreen {
|
||||||
search.is_empty() || text.to_lowercase().contains(&search)
|
search.is_empty() || text.to_lowercase().contains(&search)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this.medium_list.set_make_widget_cb(clone!(@weak this => move |index| {
|
||||||
|
let medium = &this.mediums.borrow()[index];
|
||||||
|
|
||||||
|
let row = libadwaita::ActionRow::new();
|
||||||
|
row.set_activatable(true);
|
||||||
|
row.set_title(Some(&medium.name));
|
||||||
|
|
||||||
|
row.connect_activated(clone!(@weak this => move |_| {
|
||||||
|
// TODO: Show medium screen.
|
||||||
|
}));
|
||||||
|
|
||||||
|
row.upcast()
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.medium_list.set_filter_cb(clone!(@weak this => move |index| {
|
||||||
|
let medium = &this.mediums.borrow()[index];
|
||||||
|
let search = this.widget.get_search();
|
||||||
|
let name = medium.name.to_lowercase();
|
||||||
|
search.is_empty() || name.contains(&search)
|
||||||
|
}));
|
||||||
|
|
||||||
// Load the content asynchronously.
|
// Load the content asynchronously.
|
||||||
|
|
||||||
spawn!(@clone this, async move {
|
spawn!(@clone this, async move {
|
||||||
|
|
@ -96,6 +123,13 @@ impl Screen<Ensemble, ()> for EnsembleScreen {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let mediums = this.handle
|
||||||
|
.backend
|
||||||
|
.db()
|
||||||
|
.get_mediums_for_ensemble(&this.ensemble.id)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
if !recordings.is_empty() {
|
if !recordings.is_empty() {
|
||||||
let length = recordings.len();
|
let length = recordings.len();
|
||||||
this.recordings.replace(recordings);
|
this.recordings.replace(recordings);
|
||||||
|
|
@ -105,6 +139,15 @@ impl Screen<Ensemble, ()> for EnsembleScreen {
|
||||||
this.widget.add_content(§ion.widget);
|
this.widget.add_content(§ion.widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !mediums.is_empty() {
|
||||||
|
let length = mediums.len();
|
||||||
|
this.mediums.replace(mediums);
|
||||||
|
this.medium_list.update(length);
|
||||||
|
|
||||||
|
let section = Section::new("Mediums", &this.medium_list.widget);
|
||||||
|
this.widget.add_content(§ion.widget);
|
||||||
|
}
|
||||||
|
|
||||||
this.widget.ready();
|
this.widget.ready();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use gettextrs::gettext;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use libadwaita::prelude::*;
|
use libadwaita::prelude::*;
|
||||||
use musicus_backend::db::{Person, Recording, Work};
|
use musicus_backend::db::{Medium, Person, Recording, Work};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
@ -18,8 +18,10 @@ pub struct PersonScreen {
|
||||||
widget: widgets::Screen,
|
widget: widgets::Screen,
|
||||||
work_list: Rc<List>,
|
work_list: Rc<List>,
|
||||||
recording_list: Rc<List>,
|
recording_list: Rc<List>,
|
||||||
|
medium_list: Rc<List>,
|
||||||
works: RefCell<Vec<Work>>,
|
works: RefCell<Vec<Work>>,
|
||||||
recordings: RefCell<Vec<Recording>>,
|
recordings: RefCell<Vec<Recording>>,
|
||||||
|
mediums: RefCell<Vec<Medium>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen<Person, ()> for PersonScreen {
|
impl Screen<Person, ()> for PersonScreen {
|
||||||
|
|
@ -31,6 +33,7 @@ impl Screen<Person, ()> for PersonScreen {
|
||||||
|
|
||||||
let work_list = List::new();
|
let work_list = List::new();
|
||||||
let recording_list = List::new();
|
let recording_list = List::new();
|
||||||
|
let medium_list = List::new();
|
||||||
|
|
||||||
let this = Rc::new(Self {
|
let this = Rc::new(Self {
|
||||||
handle,
|
handle,
|
||||||
|
|
@ -38,8 +41,10 @@ impl Screen<Person, ()> for PersonScreen {
|
||||||
widget,
|
widget,
|
||||||
work_list,
|
work_list,
|
||||||
recording_list,
|
recording_list,
|
||||||
|
medium_list,
|
||||||
works: RefCell::new(Vec::new()),
|
works: RefCell::new(Vec::new()),
|
||||||
recordings: RefCell::new(Vec::new()),
|
recordings: RefCell::new(Vec::new()),
|
||||||
|
mediums: RefCell::new(Vec::new()),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.widget.set_back_cb(clone!(@weak this => move || {
|
this.widget.set_back_cb(clone!(@weak this => move || {
|
||||||
|
|
@ -64,6 +69,7 @@ impl Screen<Person, ()> for PersonScreen {
|
||||||
this.widget.set_search_cb(clone!(@weak this => move || {
|
this.widget.set_search_cb(clone!(@weak this => move || {
|
||||||
this.work_list.invalidate_filter();
|
this.work_list.invalidate_filter();
|
||||||
this.recording_list.invalidate_filter();
|
this.recording_list.invalidate_filter();
|
||||||
|
this.medium_list.invalidate_filter();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.work_list.set_make_widget_cb(clone!(@weak this => move |index| {
|
this.work_list.set_make_widget_cb(clone!(@weak this => move |index| {
|
||||||
|
|
@ -117,6 +123,27 @@ impl Screen<Person, ()> for PersonScreen {
|
||||||
search.is_empty() || text.to_lowercase().contains(&search)
|
search.is_empty() || text.to_lowercase().contains(&search)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this.medium_list.set_make_widget_cb(clone!(@weak this => move |index| {
|
||||||
|
let medium = &this.mediums.borrow()[index];
|
||||||
|
|
||||||
|
let row = libadwaita::ActionRow::new();
|
||||||
|
row.set_activatable(true);
|
||||||
|
row.set_title(Some(&medium.name));
|
||||||
|
|
||||||
|
row.connect_activated(clone!(@weak this => move |_| {
|
||||||
|
// TODO: Show medium screen.
|
||||||
|
}));
|
||||||
|
|
||||||
|
row.upcast()
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.medium_list.set_filter_cb(clone!(@weak this => move |index| {
|
||||||
|
let medium = &this.mediums.borrow()[index];
|
||||||
|
let search = this.widget.get_search();
|
||||||
|
let name = medium.name.to_lowercase();
|
||||||
|
search.is_empty() || name.contains(&search)
|
||||||
|
}));
|
||||||
|
|
||||||
// Load the content asynchronously.
|
// Load the content asynchronously.
|
||||||
|
|
||||||
spawn!(@clone this, async move {
|
spawn!(@clone this, async move {
|
||||||
|
|
@ -134,6 +161,13 @@ impl Screen<Person, ()> for PersonScreen {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let mediums = this.handle
|
||||||
|
.backend
|
||||||
|
.db()
|
||||||
|
.get_mediums_for_person(&this.person.id)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
if !works.is_empty() {
|
if !works.is_empty() {
|
||||||
let length = works.len();
|
let length = works.len();
|
||||||
this.works.replace(works);
|
this.works.replace(works);
|
||||||
|
|
@ -152,6 +186,15 @@ impl Screen<Person, ()> for PersonScreen {
|
||||||
this.widget.add_content(§ion.widget);
|
this.widget.add_content(§ion.widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !mediums.is_empty() {
|
||||||
|
let length = mediums.len();
|
||||||
|
this.mediums.replace(mediums);
|
||||||
|
this.medium_list.update(length);
|
||||||
|
|
||||||
|
let section = Section::new("Mediums", &this.medium_list.widget);
|
||||||
|
this.widget.add_content(§ion.widget);
|
||||||
|
}
|
||||||
|
|
||||||
this.widget.ready();
|
this.widget.ready();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue