Use access time in some selectors

For now, only persons, instruments and ensembles will be ordered by
access time.
This commit is contained in:
Elias Projahn 2022-04-10 13:57:20 +02:00
parent 3064f18323
commit 3a27113bda
9 changed files with 34 additions and 7 deletions

View file

@ -64,4 +64,13 @@ impl Database {
let ensembles = ensembles::table.load::<Ensemble>(&self.connection)?;
Ok(ensembles)
}
/// Get recently used ensembles.
pub fn get_recent_ensembles(&self) -> Result<Vec<Ensemble>> {
let ensembles = ensembles::table
.order(ensembles::last_used.desc())
.load::<Ensemble>(&self.connection)?;
Ok(ensembles)
}
}

View file

@ -67,4 +67,13 @@ impl Database {
Ok(instruments)
}
/// Get recently used instruments.
pub fn get_recent_instruments(&self) -> Result<Vec<Instrument>> {
let instruments = instruments::table
.order(instruments::last_used.desc())
.load::<Instrument>(&self.connection)?;
Ok(instruments)
}
}

View file

@ -77,4 +77,13 @@ impl Database {
Ok(persons)
}
/// Get recently used persons.
pub fn get_recent_persons(&self) -> Result<Vec<Person>> {
let persons = persons::table
.order(persons::last_used.desc())
.load::<Person>(&self.connection)?;
Ok(persons)
}
}

View file

@ -63,7 +63,7 @@ impl Screen<(), Ensemble> for EnsembleSelector {
.set_filter(|search, ensemble| ensemble.name.to_lowercase().contains(search));
this.selector
.set_items(this.handle.backend.db().get_ensembles().unwrap());
.set_items(this.handle.backend.db().get_recent_ensembles().unwrap());
this
}

View file

@ -63,7 +63,7 @@ impl Screen<(), Instrument> for InstrumentSelector {
.set_filter(|search, instrument| instrument.name.to_lowercase().contains(search));
this.selector
.set_items(this.handle.backend.db().get_instruments().unwrap());
.set_items(this.handle.backend.db().get_recent_instruments().unwrap());
this
}

View file

@ -55,8 +55,8 @@ impl Screen<(), Medium> for MediumSelector {
let mut poes = Vec::new();
let persons = this.handle.backend.db().get_persons().unwrap();
let ensembles = this.handle.backend.db().get_ensembles().unwrap();
let persons = this.handle.backend.db().get_recent_persons().unwrap();
let ensembles = this.handle.backend.db().get_recent_ensembles().unwrap();
for person in persons {
poes.push(PersonOrEnsemble::Person(person));

View file

@ -63,7 +63,7 @@ impl Screen<(), Person> for PersonSelector {
.set_filter(|search, person| person.name_fl().to_lowercase().contains(search));
this.selector
.set_items(this.handle.backend.db().get_persons().unwrap());
.set_items(this.handle.backend.db().get_recent_persons().unwrap());
this
}

View file

@ -81,7 +81,7 @@ impl Screen<(), Recording> for RecordingSelector {
.set_filter(|search, person| person.name_fl().to_lowercase().contains(search));
this.selector
.set_items(this.handle.backend.db().get_persons().unwrap());
.set_items(this.handle.backend.db().get_recent_persons().unwrap());
this
}

View file

@ -71,7 +71,7 @@ impl Screen<(), Work> for WorkSelector {
.set_filter(|search, person| person.name_fl().to_lowercase().contains(search));
this.selector
.set_items(this.handle.backend.db().get_persons().unwrap());
.set_items(this.handle.backend.db().get_recent_persons().unwrap());
this
}