Merge pull request #90 from kdheepak/kd/add-depends-column

Add depends column
This commit is contained in:
Dheepak Krishnamurthy 2021-02-11 20:26:51 -07:00 committed by GitHub
commit 69682227c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();