Collapse a project's sessions by clicking its name
This commit is contained in:
@@ -257,6 +257,8 @@ pub struct Project {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
/// Sidebar state: hides this project's session rows.
|
||||
pub collapsed: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
@@ -536,6 +538,18 @@ impl Database {
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub fn set_project_collapsed(
|
||||
&mut self,
|
||||
project_id: i32,
|
||||
collapsed: bool,
|
||||
) -> Result<(), String> {
|
||||
diesel::update(projects::table.find(project_id))
|
||||
.set(projects::collapsed.eq(collapsed))
|
||||
.execute(&mut self.connection)
|
||||
.map(|_| ())
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub fn delete_project(&mut self, project_id: i32) -> Result<(), String> {
|
||||
self.connection
|
||||
.transaction(|connection| {
|
||||
@@ -863,6 +877,9 @@ mod tests {
|
||||
|
||||
database.set_sidebar_collapsed(true).unwrap();
|
||||
database.set_last_project(Some(project.id)).unwrap();
|
||||
assert!(!loaded[0].project.collapsed);
|
||||
database.set_project_collapsed(project.id, true).unwrap();
|
||||
assert!(database.load_projects().unwrap()[0].project.collapsed);
|
||||
|
||||
database.delete_project(project.id).unwrap();
|
||||
assert!(database.load_projects().unwrap().is_empty());
|
||||
|
||||
Reference in New Issue
Block a user