Add a work in progress implementation of the cycle message

This commit is contained in:
Campbell Alden 2023-07-21 19:47:55 +09:00
parent 8ad7a2c4e6
commit 4eea2ac43b
3 changed files with 43 additions and 3 deletions

View file

@ -51,8 +51,8 @@ fn main() -> Result<()> {
let args = CliArgs::parse(); let args = CliArgs::parse();
let tasks = match args.mode { let tasks = match args.mode {
Modes::Morning => Task::today(), Modes::Morning => Task::today(),
Modes::Signoff => Task::logbook(), Modes::Signoff => Task::logbook_today(),
Modes::Cycle => panic!("Unimplemented"), Modes::Cycle => Task::logbook_this_cycle(),
}?; }?;
let reported: Vec<Task> = tasks.into_iter().filter(|task| { let reported: Vec<Task> = tasks.into_iter().filter(|task| {
args.tags.iter().all(|tag| task.has_tag(tag)) args.tags.iter().all(|tag| task.has_tag(tag))

View file

@ -0,0 +1,36 @@
var things = Application("Things");
var logbook = things.lists.byName("Logbook").toDos();
var objs = [];
// From 6 weeks ago
var from = new Date(new Date().getTime() - (6 * 7 * 24 * 60 * 60 * 1000));
from.setHours(0);
from.setMinutes(0);
from.setSeconds(0);
var to = new Date();
to.setHours(23);
to.setMinutes(59);
to.setSeconds(59);
logbook.filter(task => {
return task.completionDate() >= from && task.completionDate() < to;
}).forEach(todo => {
var proj = todo.project();
var tags = [];
if (proj) {
tags.push(...proj.tagNames().split(', '));
}
var area = todo.area() || proj && proj.area();
objs.push({
id: todo.id(),
title: todo.name(),
notes: todo.notes() || null,
status: todo.status(),
completion_date: todo.completionDate(),
project: proj && { id: proj.id(), title: proj.name() },
area: area && { id: area.id(), title: area.name() },
tags: [...tags, ...todo.tagNames().split(', ')].filter(t => t),
});
});
return JSON.stringify(objs, undefined, 2);

View file

@ -54,10 +54,14 @@ impl Task {
} }
/// Get all tasks in the logbook list from Things /// Get all tasks in the logbook list from Things
pub fn logbook() -> Result<Vec<Task>> { pub fn logbook_today() -> Result<Vec<Task>> {
Task::from_script(include_bytes!("logbook.js")) Task::from_script(include_bytes!("logbook.js"))
} }
pub fn logbook_this_cycle() -> Result<Vec<Task>> {
Task::from_script(include_bytes!("logbook_cycle.js"))
}
pub fn has_tag(&self, tag: &str) -> bool { pub fn has_tag(&self, tag: &str) -> bool {
self.tags.contains(&String::from(tag)) self.tags.contains(&String::from(tag))
} }