Improve tag and priority handling
This commit is contained in:
parent
7362e6c4f9
commit
297ac4b77c
1 changed files with 125 additions and 56 deletions
|
@ -460,6 +460,35 @@ What's the progress?",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn select_priority(&mut self, uuid: &Uuid) -> Result<()> {
|
||||||
|
{
|
||||||
|
let task = self.cache.get_mut(uuid).chain_err(
|
||||||
|
|| "select_priority: missing uuid",
|
||||||
|
)?;
|
||||||
|
match self.dialog.select_option(
|
||||||
|
format!(
|
||||||
|
"Choose a priority for task\n{}",
|
||||||
|
print_task(task)
|
||||||
|
),
|
||||||
|
vec![
|
||||||
|
(prio_name(Some(&TaskPriority::High)), "h"),
|
||||||
|
(prio_name(Some(&TaskPriority::Medium)), "m"),
|
||||||
|
(prio_name(Some(&TaskPriority::Low)), "l"),
|
||||||
|
(prio_name(None), "n"),
|
||||||
|
("Optional", "o"),
|
||||||
|
],
|
||||||
|
)? {
|
||||||
|
"h" => task.set_priority(Some(TaskPriority::High)),
|
||||||
|
"l" => task.set_priority(Some(TaskPriority::Medium)),
|
||||||
|
"m" => task.set_priority(Some(TaskPriority::Low)),
|
||||||
|
"n" => task.set_priority(None as Option<TaskPriority>),
|
||||||
|
"o" => task.add_tag("optional"),
|
||||||
|
other => bail!("Unknown option {}", other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(self.cache.write()?)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn edit_task(&mut self, uuid: &Uuid) -> Result<()> {
|
pub fn edit_task(&mut self, uuid: &Uuid) -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
let task_name = print_task(
|
let task_name = print_task(
|
||||||
|
@ -471,14 +500,15 @@ What's the progress?",
|
||||||
task_name
|
task_name
|
||||||
),
|
),
|
||||||
vec![
|
vec![
|
||||||
("Do it: I'll get to it", "do"),
|
("Now: I'll get to it", "do"),
|
||||||
("Done: I already did this", "done"),
|
("Done: I already did this", "done"),
|
||||||
("Delete: This does not need to be done anymore","delete"),
|
("Delete: This does not need to be done anymore","delete"),
|
||||||
|
("Priority","prio"),
|
||||||
("Edit description: I want to change the description", "edit"),
|
("Edit description: I want to change the description", "edit"),
|
||||||
("Move: Change position in tasktree", "move"),
|
("Move: Change position in tasktree", "move"),
|
||||||
("Split: Give this tasks subtasks", "split"),
|
("Split: Give this tasks subtasks", "split"),
|
||||||
("Depend: Set dependency", "depend"),
|
("Depend: Set dependency", "depend"),
|
||||||
("Postpone: Set wait time", "postpone"),
|
("Wait: Set wait time", "postpone"),
|
||||||
("Tag: Add a tag", "tag"),
|
("Tag: Add a tag", "tag"),
|
||||||
("Clear tags", "clear_tags"),
|
("Clear tags", "clear_tags"),
|
||||||
("Manual: I have to change something by hand", "manual"),
|
("Manual: I have to change something by hand", "manual"),
|
||||||
|
@ -546,29 +576,7 @@ What's the progress?",
|
||||||
self.cache.write()?;
|
self.cache.write()?;
|
||||||
}
|
}
|
||||||
"tag" => {
|
"tag" => {
|
||||||
let tag = self.dialog.input_line(
|
self.add_tag(uuid)?;
|
||||||
format!("Enter tag for {}", task_name),
|
|
||||||
vec![
|
|
||||||
"alber",
|
|
||||||
"await",
|
|
||||||
"city",
|
|
||||||
"home",
|
|
||||||
"pc",
|
|
||||||
"research",
|
|
||||||
"streicher",
|
|
||||||
"uni",
|
|
||||||
"work",
|
|
||||||
"claire",
|
|
||||||
"burkhard",
|
|
||||||
"cornelia",
|
|
||||||
"nathalie",
|
|
||||||
],
|
|
||||||
)?;
|
|
||||||
self.cache
|
|
||||||
.get_mut(uuid)
|
|
||||||
.chain_err(|| "missing uuid")?
|
|
||||||
.add_tag(tag);
|
|
||||||
self.cache.write()?;
|
|
||||||
}
|
}
|
||||||
"clear_tags" => {
|
"clear_tags" => {
|
||||||
self.cache
|
self.cache
|
||||||
|
@ -577,6 +585,9 @@ What's the progress?",
|
||||||
.set_tags(None as Option<Vec<String>>);
|
.set_tags(None as Option<Vec<String>>);
|
||||||
self.cache.write()?;
|
self.cache.write()?;
|
||||||
}
|
}
|
||||||
|
"prio" => {
|
||||||
|
self.select_priority(uuid)?;
|
||||||
|
}
|
||||||
"postpone" => {
|
"postpone" => {
|
||||||
str2cmd(&format!(
|
str2cmd(&format!(
|
||||||
"task {} mod wait:{}",
|
"task {} mod wait:{}",
|
||||||
|
@ -655,6 +666,88 @@ What's the progress?",
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_tag(&mut self, uuid: &Uuid) -> Result<()> {
|
||||||
|
enum Select {
|
||||||
|
Edit,
|
||||||
|
More,
|
||||||
|
Tag(&'static str),
|
||||||
|
};
|
||||||
|
match self.dialog.select_option(
|
||||||
|
format!(
|
||||||
|
"Handling Task: {}\nWhen will you do this?",
|
||||||
|
print_task(
|
||||||
|
self.cache.get(uuid).chain_err(|| "missing uuid")?,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
vec![
|
||||||
|
(
|
||||||
|
"Await: Somebody else has to do this",
|
||||||
|
Select::Tag("await")
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"PC: When I'm at my computer",
|
||||||
|
Select::Tag("pc")
|
||||||
|
),
|
||||||
|
("Work: While working", Select::Tag("work")),
|
||||||
|
(
|
||||||
|
"Research: While doing research",
|
||||||
|
Select::Tag("research")
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Home: When I'm at home",
|
||||||
|
Select::Tag("home")
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Uni: At the university",
|
||||||
|
Select::Tag("uni")
|
||||||
|
),
|
||||||
|
("City: In the city", Select::Tag("city")),
|
||||||
|
(
|
||||||
|
"More: Set other or multiple tag",
|
||||||
|
Select::More
|
||||||
|
),
|
||||||
|
("Edit: This task instead", Select::Edit),
|
||||||
|
],
|
||||||
|
)? {
|
||||||
|
Select::Tag(tag) => {
|
||||||
|
{
|
||||||
|
let task = self.cache.get_mut(uuid).chain_err(|| "missing uuid")?;
|
||||||
|
task.set_tags(None as Option<Vec<String>>);
|
||||||
|
task.add_tag(tag);
|
||||||
|
}
|
||||||
|
self.cache.write()?;
|
||||||
|
}
|
||||||
|
Select::More => {
|
||||||
|
let tags = self.dialog.input_line(
|
||||||
|
format!(
|
||||||
|
"Enter tag(s) for:\n{}",
|
||||||
|
print_task(
|
||||||
|
self.cache.get(uuid).chain_err(|| "missing uuid")?,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
vec![
|
||||||
|
"alber",
|
||||||
|
"streicher",
|
||||||
|
"burkhard",
|
||||||
|
"cornelia",
|
||||||
|
"nathalie",
|
||||||
|
],
|
||||||
|
)?;
|
||||||
|
{
|
||||||
|
let task = self.cache.get_mut(uuid).chain_err(|| "missing uuid")?;
|
||||||
|
task.set_tags(None as Option<Vec<String>>);
|
||||||
|
for tag in tags.split_whitespace() {
|
||||||
|
task.add_tag(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.cache.write()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Select::Edit => self.edit_task(uuid)?,
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_task(&mut self, uuid: &Uuid) -> Result<()> {
|
pub fn handle_task(&mut self, uuid: &Uuid) -> Result<()> {
|
||||||
let task_name = print_task(self.cache.get(uuid).chain_err(
|
let task_name = print_task(self.cache.get(uuid).chain_err(
|
||||||
|| "handle_task: missing uuid",
|
|| "handle_task: missing uuid",
|
||||||
|
@ -707,40 +800,16 @@ What's the progress?",
|
||||||
self.sort(uuid)?;
|
self.sort(uuid)?;
|
||||||
}
|
}
|
||||||
if !self.make_project(uuid)? {
|
if !self.make_project(uuid)? {
|
||||||
if let Some(tag) = self.dialog.select_option(
|
if self.cache
|
||||||
format!(
|
.get(uuid)
|
||||||
"Handling Task: {}\nWhen will you do this?",
|
|
||||||
print_task(
|
|
||||||
self.cache.get(uuid).chain_err(|| "missing uuid")?,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
vec![
|
|
||||||
("Optional: I might never", Some("optional")),
|
|
||||||
("Later: This has to wait", Some("later")),
|
|
||||||
(
|
|
||||||
"Await: Somebody else has to do this",
|
|
||||||
Some("await")
|
|
||||||
),
|
|
||||||
("PC: When I'm at my computer", Some("pc")),
|
|
||||||
("Work: While working", Some("work")),
|
|
||||||
(
|
|
||||||
"Research: While doing research",
|
|
||||||
Some("research")
|
|
||||||
),
|
|
||||||
("Home: When I'm at home", Some("home")),
|
|
||||||
("Edit: This task instead", None),
|
|
||||||
],
|
|
||||||
)?
|
|
||||||
{
|
|
||||||
self.cache
|
|
||||||
.get_mut(uuid)
|
|
||||||
.chain_err(|| "missing uuid")?
|
.chain_err(|| "missing uuid")?
|
||||||
.add_tag(tag);
|
.priority()
|
||||||
self.cache.write()?;
|
.is_none()
|
||||||
} else {
|
{
|
||||||
self.edit_task(uuid)?;
|
self.select_priority(uuid)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.add_tag(uuid)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue