Add task_by_uuid and task_by_index

This commit is contained in:
Dheepak Krishnamurthy 2020-10-10 20:25:08 -06:00
parent 738bce9a21
commit d00dd90043
3 changed files with 21 additions and 0 deletions

1
Cargo.lock generated
View file

@ -767,6 +767,7 @@ dependencies = [
"task-hookrs",
"tui",
"unicode-width",
"uuid",
]
[[package]]

View file

@ -30,3 +30,4 @@ unicode-width = "0.1"
tui = { version = "0.10", optional = true, default-features = false }
crossterm = { version = "0.17", optional = true, default-features = false }
rustyline = "6.3.0"
uuid = { version = "0.8.1", features = ["serde", "v4"] }

View file

@ -10,6 +10,7 @@ use task_hookrs::import::import;
use task_hookrs::status::TaskStatus;
use task_hookrs::task::Task;
use task_hookrs::uda::UDAValue;
use uuid::Uuid;
use chrono::{Local, NaiveDateTime, TimeZone};
@ -741,6 +742,24 @@ impl TTApp {
}
}
fn task_by_index(&self, i: usize) -> Option<Task> {
let tasks = &self.tasks.lock().unwrap();
if i > tasks.len() {
None
} else {
Some(tasks[i].clone())
}
}
fn task_by_uuid(&self, uuid: Uuid) -> Option<Task> {
let tasks = &self.tasks.lock().unwrap();
let m = tasks.iter().find(|t| *t.uuid() == uuid);
match m {
Some(v) => Some(v.clone()),
None => None
}
}
fn draw_task_report(&mut self, f: &mut Frame<impl Backend>, rect: Rect) {
let (tasks, headers, widths) = self.task_report();
if tasks.is_empty() {