mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Add wait to reports, for display and sorting
This commit is contained in:
parent
cf078e1233
commit
1aae7e059d
3 changed files with 70 additions and 0 deletions
|
@ -27,6 +27,7 @@ fn sort_tasks(tasks: &mut Vec<Task>, report: &Report, working_set: &WorkingSet)
|
|||
}
|
||||
SortBy::Uuid => a.get_uuid().cmp(&b.get_uuid()),
|
||||
SortBy::Description => a.get_description().cmp(b.get_description()),
|
||||
SortBy::Wait => a.get_wait().cmp(&b.get_wait()),
|
||||
};
|
||||
// If this sort property is equal, go on to the next..
|
||||
if ord == Ordering::Equal {
|
||||
|
@ -71,6 +72,13 @@ fn task_column(task: &Task, column: &Column, working_set: &WorkingSet) -> String
|
|||
tags.sort();
|
||||
tags.join(" ")
|
||||
}
|
||||
Property::Wait => {
|
||||
if task.is_waiting() {
|
||||
task.get_wait().unwrap().format("%Y-%m-%d").to_string()
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,6 +132,7 @@ mod test {
|
|||
use super::*;
|
||||
use crate::invocation::test::*;
|
||||
use crate::settings::Sort;
|
||||
use chrono::prelude::*;
|
||||
use std::convert::TryInto;
|
||||
use taskchampion::{Status, Uuid};
|
||||
|
||||
|
@ -217,6 +226,50 @@ mod test {
|
|||
assert_eq!(got_uuids, exp_uuids);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sorting_by_wait() {
|
||||
let mut replica = test_replica();
|
||||
let uuids = create_tasks(&mut replica);
|
||||
|
||||
replica
|
||||
.get_task(uuids[0])
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_mut(&mut replica)
|
||||
.set_wait(Some(Utc::now() + chrono::Duration::days(2)))
|
||||
.unwrap();
|
||||
|
||||
replica
|
||||
.get_task(uuids[1])
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_mut(&mut replica)
|
||||
.set_wait(Some(Utc::now() + chrono::Duration::days(3)))
|
||||
.unwrap();
|
||||
|
||||
let working_set = replica.working_set().unwrap();
|
||||
|
||||
let report = Report {
|
||||
sort: vec![Sort {
|
||||
ascending: true,
|
||||
sort_by: SortBy::Wait,
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut tasks: Vec<_> = replica.all_tasks().unwrap().values().cloned().collect();
|
||||
sort_tasks(&mut tasks, &report, &working_set);
|
||||
let got_uuids: Vec<_> = tasks.iter().map(|t| t.get_uuid()).collect();
|
||||
|
||||
let exp_uuids = vec![
|
||||
uuids[2], // no wait
|
||||
uuids[0], // wait:2d
|
||||
uuids[1], // wait:3d
|
||||
];
|
||||
|
||||
assert_eq!(got_uuids, exp_uuids);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sorting_by_multiple() {
|
||||
let mut replica = test_replica();
|
||||
|
|
|
@ -46,6 +46,9 @@ pub(crate) enum Property {
|
|||
|
||||
/// The task's tags
|
||||
Tags,
|
||||
|
||||
/// The task's wait date
|
||||
Wait,
|
||||
}
|
||||
|
||||
/// A sorting criterion for a sort operation.
|
||||
|
@ -71,6 +74,9 @@ pub(crate) enum SortBy {
|
|||
|
||||
/// The task's description
|
||||
Description,
|
||||
|
||||
/// The task's wait date
|
||||
Wait,
|
||||
}
|
||||
|
||||
// Conversions from settings::Settings.
|
||||
|
@ -174,6 +180,7 @@ impl TryFrom<&toml::Value> for Property {
|
|||
"active" => Property::Active,
|
||||
"description" => Property::Description,
|
||||
"tags" => Property::Tags,
|
||||
"wait" => Property::Wait,
|
||||
_ => bail!(": unknown property {}", s),
|
||||
})
|
||||
}
|
||||
|
@ -210,6 +217,7 @@ impl TryFrom<&toml::Value> for SortBy {
|
|||
"id" => SortBy::Id,
|
||||
"uuid" => SortBy::Uuid,
|
||||
"description" => SortBy::Description,
|
||||
"wait" => SortBy::Wait,
|
||||
_ => bail!(": unknown sort_by value `{}`", s),
|
||||
})
|
||||
}
|
||||
|
@ -231,6 +239,11 @@ pub(crate) fn get_usage(u: &mut Usage) {
|
|||
as_sort_by: None,
|
||||
as_column: Some("`*` if the task is active (started)"),
|
||||
});
|
||||
u.report_properties.push(usage::ReportProperty {
|
||||
name: "wait",
|
||||
as_sort_by: Some("Sort by the task's wait date, with non-waiting tasks first"),
|
||||
as_column: Some("Wait date of the task"),
|
||||
});
|
||||
u.report_properties.push(usage::ReportProperty {
|
||||
name: "description",
|
||||
as_sort_by: Some("Sort by the task's description"),
|
||||
|
|
|
@ -218,6 +218,10 @@ impl Default for Settings {
|
|||
label: "tags".to_owned(),
|
||||
property: Property::Tags,
|
||||
},
|
||||
Column {
|
||||
label: "wait".to_owned(),
|
||||
property: Property::Wait,
|
||||
},
|
||||
],
|
||||
filter: Default::default(),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue