(* Implement 'list' subcommand. *) open CalendarLib open Todo_types open Todo_utils open Todo_tag_utils open Printf let tags_of_task dbh id = let rows = PGSQL(dbh) "select tags.name, tags.colour from tags_tasks, tags where tags_tasks.taskid = $id and tags_tasks.tagid = tags.id order by tags.name" in if rows = [] then "" else " " ^ String.concat " " (List.map ( fun (name, colour) -> string_of_tag name colour ) rows) let cmd_list dbh anon_params list_retired list_all = if anon_params <> [] then error "extra parameters to 'list' subcommand"; let show_unretired, show_retired = match list_retired, list_all with | _, true -> true, true | false, false -> true, false | true, false -> false, true in if show_unretired then ( let rows = PGSQL(dbh) "select imminent.taskid, tasks.description from imminent, tasks where imminent.taskid = tasks.id order by tasks.description" in if rows <> [] then printf "Today:\n"; List.iter ( fun (id, desc) -> printf " %s #%ld%s\n" desc id (tags_of_task dbh id) ) rows; let rows = PGSQL(dbh) "select todo.taskid, todo.deadline, todo.estimate, tasks.description from todo, tasks where todo.taskid = tasks.id order by todo.deadline" in if rows <> [] then printf "To-do list:\n"; List.iter ( fun (id, deadline, estimate, desc) -> let deadline = if Time.equal (Time.midnight ()) (Calendar.to_time deadline) then Printer.Calendar.sprint "%F" deadline else Printer.Calendar.to_string deadline in let estimate = match estimate with | None -> "" | Some period -> string_of_estimate period ^ " " in printf " %s %s%s #%ld%s\n" deadline estimate desc id (tags_of_task dbh id) ) rows; let rows = PGSQL(dbh) " select tasks.id, tasks.description from tasks where not exists (select 1 from imminent where taskid = tasks.id) and not exists (select 1 from todo where taskid = tasks.id) and not exists (select 1 from ideas where taskid = tasks.id) and not exists (select 1 from retired where taskid = tasks.id) order by tasks.description" in if rows <> [] then printf "Unsorted (use 'todo move' to move these):\n"; List.iter ( fun (id, desc) -> printf " %s #%ld%s\n" desc id (tags_of_task dbh id) ) rows; let rows = PGSQL(dbh) "select ideas.taskid, tasks.description from ideas, tasks where ideas.taskid = tasks.id order by tasks.description" in if rows <> [] then printf "Ideas:\n"; List.iter ( fun (id, desc) -> printf " %s #%ld%s\n" desc id (tags_of_task dbh id) ) rows ); (* unretired *) if show_retired then ( let rows = PGSQL(dbh) "select retired.taskid, tasks.description from retired, tasks where retired.taskid = tasks.id order by tasks.description" in if rows <> [] then printf "Retired:\n"; List.iter ( fun (id, desc) -> printf " %s #%ld%s\n" desc id (tags_of_task dbh id) ) rows )