From 03dc29a5e3ea5987938821a49800171c40ff35f6 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Thu, 11 Feb 2021 20:01:40 -0700 Subject: [PATCH] Add depends column --- src/task_report.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/task_report.rs b/src/task_report.rs index 7e7c134..2f61d25 100644 --- a/src/task_report.rs +++ b/src/task_report.rs @@ -1,4 +1,5 @@ use chrono::{Datelike, Local, NaiveDate, NaiveDateTime, TimeZone}; +use itertools::join; use std::error::Error; use std::process::Command; use task_hookrs::task::Task; @@ -127,7 +128,7 @@ impl TaskReportTable { } let mut item = vec![]; for name in &self.columns { - let s = self.get_string_attribute(name, &task); + let s = self.get_string_attribute(name, &task, tasks); item.push(s); } self.tasks.push(item) @@ -175,7 +176,7 @@ impl TaskReportTable { (tasks, headers) } - pub fn get_string_attribute(&self, attribute: &str, task: &Task) -> String { + pub fn get_string_attribute(&self, attribute: &str, task: &Task, tasks: &[Task]) -> String { match attribute { "id" => task.id().unwrap_or_default().to_string(), "due.relative" => match task.due() { @@ -210,6 +211,20 @@ impl TaskReportTable { } None => "".to_string(), }, + "depends" => match task.depends() { + Some(v) => { + if v.is_empty() { + "".to_string() + } else { + let mut dt = vec![]; + for u in v { + dt.push(tasks.iter().find(|t| t.uuid() == u).unwrap().id().unwrap()); + } + join(dt.iter().map(|i| i.to_string()), " ") + } + } + None => "".to_string(), + }, "tags.count" => match task.tags() { Some(v) => { let t = v.iter().filter(|t| !self.virtual_tags.contains(t)).cloned().count();