mirror of
https://github.com/michaeldv/pit.git
synced 2025-12-08 15:43:25 +00:00
Adding notes; show project list tasks; show task list notes
This commit is contained in:
@@ -9,7 +9,7 @@ static void action_list()
|
||||
|
||||
pit_db_load();
|
||||
if (actions->number_of_records > 0) {
|
||||
ppager = pit_pager_initialize(PAGER_ACTION, actions->number_of_records);
|
||||
ppager = pit_pager_initialize(PAGER_ACTION, 0, actions->number_of_records);
|
||||
for_each_action(pa) {
|
||||
pit_pager_print(ppager, (char *)pa);
|
||||
}
|
||||
@@ -19,9 +19,7 @@ static void action_list()
|
||||
|
||||
void pit_action(int id, char *subject, char *message)
|
||||
{
|
||||
static Action action;
|
||||
|
||||
memset(&action, 0, sizeof(action));
|
||||
static Action action = { 0 };
|
||||
|
||||
action.subject_id = id;
|
||||
strncpy(action.subject, subject, sizeof(action.subject) - 1);
|
||||
@@ -29,6 +27,7 @@ void pit_action(int id, char *subject, char *message)
|
||||
strncpy(action.message, message, sizeof(action.message) - 1);
|
||||
|
||||
pit_table_insert(actions, (char *)&action);
|
||||
if (strcmp(subject, "pit")) puts(message);
|
||||
}
|
||||
|
||||
void pit_log(char *argv[])
|
||||
|
||||
@@ -91,7 +91,7 @@ time_t pit_arg_date(char **arg, char *required)
|
||||
time_t now = time(NULL);
|
||||
time_t seconds = (time_t)0;
|
||||
struct tm *ptm = localtime(&now);
|
||||
struct tm tm;
|
||||
struct tm tm = { 0 };
|
||||
|
||||
if (required && (!*arg || pit_arg_is_option(arg))) {
|
||||
die("missing %s", required);
|
||||
@@ -142,7 +142,6 @@ time_t pit_arg_date(char **arg, char *required)
|
||||
adjust_time(arg, format); /* Replace %H with %I%p for am/pm time */
|
||||
|
||||
/* Ready to roll :-) */
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
// printf("format: %s\n", format);
|
||||
if (strptime(*arg, format, &tm)) {
|
||||
// printf("then: %s\n", asctime(&tm));
|
||||
|
||||
182
src/note.c
182
src/note.c
@@ -3,12 +3,190 @@
|
||||
#include <stdio.h>
|
||||
#include "pit.h"
|
||||
|
||||
/*
|
||||
** CREATING NOTES:
|
||||
** pit note -c message
|
||||
**
|
||||
** EDITING NOTES:
|
||||
** pit note -e [number] message
|
||||
**
|
||||
** DELETING NOTES:
|
||||
** pit note -d [number]
|
||||
**
|
||||
** LISTING NOTES:
|
||||
** pit note
|
||||
*/
|
||||
|
||||
static int note_find_current(int id, PProject *ppp)
|
||||
{
|
||||
// if (id) {
|
||||
// *ppp = (PProject)pit_table_find(notes, id);
|
||||
// if (!*ppp) die("could not find note %d", id);
|
||||
// } else {
|
||||
// *ppp = (PProject)pit_table_current(notes);
|
||||
// if (!*ppp) die("could not find current note");
|
||||
// }
|
||||
// return *ppp ? (*(PProject *)ppp)->id : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void note_log_create(PNote pn, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "created note %d: %s (task %d)", pn->id, po->note.message, pn->task_id);
|
||||
pit_action(pn->id, "note", str);
|
||||
}
|
||||
|
||||
static void note_log_update(PNote pn, POptions po)
|
||||
{
|
||||
// char str[256];
|
||||
// bool empty = TRUE;
|
||||
//
|
||||
// sprintf(str, "updated note %d:", pn->id);
|
||||
// if (po->note.name) {
|
||||
// sprintf(str + strlen(str), " (name: %s", po->note.name);
|
||||
// empty = FALSE;
|
||||
// } else {
|
||||
// sprintf(str + strlen(str), " %s (", pn->name);
|
||||
// }
|
||||
// if (po->note.status) {
|
||||
// sprintf(str + strlen(str), "%sstatus: %s)", (empty ? "" : ", "), po->note.status);
|
||||
// }
|
||||
// strcat(str, ")");
|
||||
// pit_action(pn->id, "note", str);
|
||||
}
|
||||
|
||||
static void note_log_delete(int id, char *name, int number_of_tasks)
|
||||
{
|
||||
// char str[256];
|
||||
//
|
||||
// sprintf(str, "deleted note %d: %s", id, name);
|
||||
// if (number_of_tasks > 0) {
|
||||
// sprintf(str + strlen(str), " with %d task%s", number_of_tasks, (number_of_tasks == 1 ? "" : "s"));
|
||||
// }
|
||||
// pit_action(id, "note", str);
|
||||
}
|
||||
|
||||
void pit_note_list(PTask pt)
|
||||
{
|
||||
if (!notes) pit_db_load();
|
||||
|
||||
if (notes->number_of_records > 0) {
|
||||
PPager ppager = pit_pager_initialize(PAGER_NOTE, pt ? 4 : 0, notes->number_of_records);
|
||||
if (!pt) pt = (PTask)pit_table_current(tasks);
|
||||
for_each_note(pn) {
|
||||
if (pt && pn->task_id != pt->id)
|
||||
continue;
|
||||
pit_pager_print(ppager, (char *)pn);
|
||||
}
|
||||
pit_pager_flush(ppager);
|
||||
}
|
||||
}
|
||||
|
||||
static void note_create(POptions po)
|
||||
{
|
||||
pit_db_load();
|
||||
PTask pt = (PTask)pit_table_current(tasks);
|
||||
|
||||
if (!pt) {
|
||||
die("no task selected");
|
||||
} else {
|
||||
Note n = { 0 }, *pn;
|
||||
|
||||
n.task_id = pt->id;
|
||||
strncpy(n.message, po->note.message, sizeof(n.message) - 1);
|
||||
strncpy(n.username, current_user(), sizeof(n.username) - 1);
|
||||
|
||||
pn = (PNote)pit_table_insert(notes, (char *)&n);
|
||||
pit_table_mark(notes, pn->id);
|
||||
pt->number_of_notes++;
|
||||
note_log_create(pn, po);
|
||||
pit_db_save();
|
||||
}
|
||||
}
|
||||
|
||||
static void note_update(int id, POptions po)
|
||||
{
|
||||
puts("note_update");
|
||||
// PProject pp;
|
||||
//
|
||||
// pit_db_load();
|
||||
// id = note_find_current(id, &pp);
|
||||
//
|
||||
// if (po->note.name) strncpy(pp->name, po->note.name, sizeof(pp->name) - 1);
|
||||
// if (po->note.status) strncpy(pp->status, po->note.status, sizeof(pp->status) - 1);
|
||||
// pit_table_mark(notes, pp->id);
|
||||
//
|
||||
// note_log_update(pp, po);
|
||||
// pit_db_save();
|
||||
}
|
||||
|
||||
void pit_note_delete(int id, PTask pt)
|
||||
{
|
||||
|
||||
puts("note_delete");
|
||||
// PProject pp;
|
||||
//
|
||||
// pit_db_load();
|
||||
// id = note_find_current(id, &pp);
|
||||
// /*
|
||||
// ** Delete note tasks.
|
||||
// */
|
||||
// if (pp->number_of_tasks > 0) {
|
||||
// for_each_task(pt) {
|
||||
// if (pt->note_id == id) {
|
||||
// pit_task_delete(pt->id, pp);
|
||||
// --pt; /* Make the task pointer stay since it now points to the next task. */
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// /*
|
||||
// ** Ready to delete the note itself. But first preserve the
|
||||
// ** name and number of tasks since we need these bits for logging.
|
||||
// */
|
||||
// char *deleted_name = str2str(pp->name);
|
||||
// int deleted_number_of_tasks = pp->number_of_tasks;
|
||||
//
|
||||
// pp = (PProject)pit_table_delete(notes, id);
|
||||
// if (pp) {
|
||||
// pit_table_mark(notes, 0); /* TODO: find better current note candidate. */
|
||||
// note_log_delete(id, deleted_name, deleted_number_of_tasks);
|
||||
// pit_db_save();
|
||||
// } else {
|
||||
// die("could not delete the note");
|
||||
// }
|
||||
}
|
||||
|
||||
void pit_note(char *argv[])
|
||||
{
|
||||
puts("pit: note is not implemented yet");
|
||||
char **arg = &argv[1];
|
||||
int number = 0;
|
||||
Options opt = {{ 0 }};
|
||||
|
||||
if (!*arg) {
|
||||
pit_note_list(NULL);
|
||||
} else {
|
||||
switch(pit_arg_option(arg)) {
|
||||
case 'c': /* pit note -c message */
|
||||
opt.note.message = pit_arg_string(++arg, "note message");
|
||||
note_create(&opt);
|
||||
break;
|
||||
case 'e': /* pit note -e [number] message */
|
||||
number = pit_arg_number(++arg, NULL);
|
||||
if (!number) --arg;
|
||||
opt.note.message = pit_arg_string(++arg, "note message");
|
||||
if (is_zero((char *)&opt.note, sizeof(opt.note))) {
|
||||
die("nothing to update");
|
||||
} else {
|
||||
note_update(number, &opt);
|
||||
}
|
||||
break;
|
||||
case 'd': /* pit note -d [number] */
|
||||
number = pit_arg_number(++arg, NULL);
|
||||
pit_note_delete(number, NULL);
|
||||
break;
|
||||
default:
|
||||
die("invalid note option: %s", *arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,10 @@ typedef union _Options {
|
||||
char *name;
|
||||
char *status;
|
||||
} project;
|
||||
struct {
|
||||
int id;
|
||||
char *message;
|
||||
} note;
|
||||
} Options, *POptions;
|
||||
|
||||
#endif
|
||||
|
||||
40
src/pager.c
40
src/pager.c
@@ -7,6 +7,18 @@
|
||||
#define TASK(attr) (((PTask)*pentry)->attr)
|
||||
#define PROJECT(attr) (((PProject)*pentry)->attr)
|
||||
#define ACTION(attr) (((PAction)*pentry)->attr)
|
||||
#define NOTE(attr) (((PNote)*pentry)->attr)
|
||||
|
||||
static void print_notes(PPager ppager)
|
||||
{
|
||||
char **pentry;
|
||||
char format[64];
|
||||
|
||||
sprintf(format, "%%%dc %%%dd: (%%-%ds) %%s\n", ppager->indent, ppager->max.note.id, ppager->max.note.username);
|
||||
for_each_entry(ppager, pentry) {
|
||||
printf(format, (NOTE(id) == notes->current ? '*' : ' '), NOTE(id), NOTE(username), NOTE(message));
|
||||
}
|
||||
}
|
||||
|
||||
static void print_actions(PPager ppager)
|
||||
{
|
||||
@@ -45,8 +57,8 @@ static void print_tasks(PPager ppager)
|
||||
char **pentry;
|
||||
char format[64];
|
||||
|
||||
sprintf(format, "%%c %%%dd: (%%-%ds) [%%-%ds] [%%-%ds] %%-%ds (%%d note%%s)\n",
|
||||
ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.name
|
||||
sprintf(format, "%%%dc %%%dd: (%%-%ds) |%%-%ds| |%%-%ds| %%-%ds (%%d note%%s)\n",
|
||||
ppager-> indent, ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.name
|
||||
);
|
||||
for_each_entry(ppager, pentry) {
|
||||
printf(format,
|
||||
@@ -67,8 +79,8 @@ static void print_tasks_with_date(PPager ppager)
|
||||
char **pentry;
|
||||
char format[64];
|
||||
|
||||
sprintf(format, "%%c %%%dd: (%%-%ds) [%%-%ds] [%%-%ds] %%-%ds %%-%ds (%%d note%%s)\n",
|
||||
ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.date, ppager->max.task.name
|
||||
sprintf(format, "%%%dc %%%dd: (%%-%ds) [%%-%ds] [%%-%ds] %%-%ds %%-%ds (%%d note%%s)\n",
|
||||
ppager->indent, ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.date, ppager->max.task.name
|
||||
);
|
||||
for_each_entry(ppager, pentry) {
|
||||
printf(format,
|
||||
@@ -90,8 +102,8 @@ static void print_tasks_with_time(PPager ppager)
|
||||
char **pentry;
|
||||
char format[64];
|
||||
|
||||
sprintf(format, "%%c %%%dd: (%%-%ds) [%%-%ds] [%%-%ds] %%%ds %%-%ds (%%d note%%s)\n",
|
||||
ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.time, ppager->max.task.name
|
||||
sprintf(format, "%%%dc %%%dd: (%%-%ds) [%%-%ds] [%%-%ds] %%%ds %%-%ds (%%d note%%s)\n",
|
||||
ppager->indent, ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.time, ppager->max.task.name
|
||||
);
|
||||
for_each_entry(ppager, pentry) {
|
||||
printf(format,
|
||||
@@ -113,8 +125,8 @@ static void print_tasks_with_date_and_time(PPager ppager)
|
||||
char **pentry;
|
||||
char format[64];
|
||||
|
||||
sprintf(format, "%%c %%%dd: (%%-%ds) [%%-%ds] [%%-%ds] %%-%ds %%%ds %%-%ds (%%d note%%s)\n",
|
||||
ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.date, ppager->max.task.time, ppager->max.task.name
|
||||
sprintf(format, "%%%dc %%%dd: (%%-%ds) [%%-%ds] [%%-%ds] %%-%ds %%%ds %%-%ds (%%d note%%s)\n",
|
||||
ppager->indent, ppager->max.task.id, ppager->max.task.username, ppager->max.task.status, ppager->max.task.priority, ppager->max.task.date, ppager->max.task.time, ppager->max.task.name
|
||||
);
|
||||
for_each_entry(ppager, pentry) {
|
||||
printf(format,
|
||||
@@ -132,12 +144,13 @@ static void print_tasks_with_date_and_time(PPager ppager)
|
||||
}
|
||||
}
|
||||
|
||||
PPager pit_pager_initialize(int type, int number_of_entries)
|
||||
PPager pit_pager_initialize(int type, int indent, int number_of_entries)
|
||||
{
|
||||
PPager ppager = calloc(1, sizeof(Pager));
|
||||
|
||||
memset(ppager, 0, sizeof(Pager));
|
||||
ppager->type = type;
|
||||
ppager->indent = indent;
|
||||
ppager->entries = calloc(number_of_entries + 1, sizeof(char *));
|
||||
|
||||
return ppager;
|
||||
@@ -177,6 +190,11 @@ void pit_pager_print(PPager ppager, char *entry)
|
||||
ppager->max.action.username = max(ppager->max.action.username, strlen(((PAction)*pentry)->username));
|
||||
ppager->max.action.subject = max(ppager->max.action.subject, strlen(((PAction)*pentry)->subject));
|
||||
break;
|
||||
case PAGER_NOTE:
|
||||
sprintf(str, "%d", NOTE(id));
|
||||
ppager->max.note.id = max(ppager->max.note.id, strlen(str));
|
||||
ppager->max.note.username = max(ppager->max.note.username, strlen(((PNote)*pentry)->username));
|
||||
break;
|
||||
default:
|
||||
die("invalid pager type: %d\n", ppager->type);
|
||||
}
|
||||
@@ -208,6 +226,10 @@ void pit_pager_flush(PPager ppager)
|
||||
print_actions(ppager);
|
||||
break;
|
||||
|
||||
case PAGER_NOTE:
|
||||
print_notes(ppager);
|
||||
break;
|
||||
|
||||
default:
|
||||
pit_pager_free(ppager);
|
||||
die("invalid pager type: %d\n", ppager->type);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
typedef struct _Pager {
|
||||
int type;
|
||||
int indent;
|
||||
int number_of_entries;
|
||||
char *entries;
|
||||
union {
|
||||
@@ -30,10 +31,14 @@ typedef struct _Pager {
|
||||
int username;
|
||||
int subject;
|
||||
} action;
|
||||
struct {
|
||||
int id;
|
||||
int username;
|
||||
} note;
|
||||
} max;
|
||||
} Pager, *PPager;
|
||||
|
||||
PPager pit_pager_initialize(int type, int number_of_entries);
|
||||
PPager pit_pager_initialize(int type, int indent, int number_of_entries);
|
||||
void pit_pager_print(PPager ppager, char *entry);
|
||||
void pit_pager_flush(PPager ppager);
|
||||
void pit_pager_free(PPager ppager);
|
||||
|
||||
10
src/pit.c
10
src/pit.c
@@ -4,11 +4,11 @@
|
||||
#include <stdio.h>
|
||||
#include "pit.h"
|
||||
|
||||
PHeader header;
|
||||
PTable projects;
|
||||
PTable tasks;
|
||||
PTable notes;
|
||||
PTable actions;
|
||||
PHeader header = NULL;
|
||||
PTable projects = NULL;
|
||||
PTable tasks = NULL;
|
||||
PTable notes = NULL;
|
||||
PTable actions = NULL;
|
||||
|
||||
void free_externals() {
|
||||
if (header) free(header);
|
||||
|
||||
@@ -55,7 +55,9 @@ void pit_db_load();
|
||||
void pit_db_save();
|
||||
void pit_db_initialize();
|
||||
void pit_action(int id, char *subject, char *message);
|
||||
void pit_task_list(POptions po, PProject pp);
|
||||
void pit_task_delete(int id, PProject pp);
|
||||
void pit_note_list(PTask pt);
|
||||
void pit_note_delete(int id, PTask pt);
|
||||
|
||||
|
||||
|
||||
153
src/project.c
153
src/project.c
@@ -3,18 +3,6 @@
|
||||
#include <stdio.h>
|
||||
#include "pit.h"
|
||||
|
||||
static void project_list(POptions po);
|
||||
static void project_show(int id);
|
||||
static void project_create(POptions po);
|
||||
static void project_update(int id, POptions po);
|
||||
static void project_delete(int id);
|
||||
static bool project_already_exist(char *name);
|
||||
static int project_find_current(int id, PProject *ppp);
|
||||
static void project_log_create(PProject pp, POptions po);
|
||||
static void project_log_update(PProject pp, POptions po);
|
||||
static void project_log_delete(int id, char *name, int number_of_tasks);
|
||||
static void project_parse_options(char **arg, POptions po);
|
||||
|
||||
/*
|
||||
** CREATING PROJECTS:
|
||||
** pit project -c name [-s status]
|
||||
@@ -32,13 +20,74 @@ static void project_parse_options(char **arg, POptions po);
|
||||
** pit project -q [number | [-n name] [-s status]]
|
||||
*/
|
||||
|
||||
static bool project_already_exist(char *name)
|
||||
{
|
||||
pit_db_load();
|
||||
for_each_project(pp) {
|
||||
if (!strcmp(pp->name, name)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int project_find_current(int id, PProject *ppp)
|
||||
{
|
||||
if (id) {
|
||||
*ppp = (PProject)pit_table_find(projects, id);
|
||||
if (!*ppp) die("could not find project %d", id);
|
||||
} else {
|
||||
*ppp = (PProject)pit_table_current(projects);
|
||||
if (!*ppp) die("could not find current project");
|
||||
}
|
||||
return *ppp ? (*(PProject *)ppp)->id : 0;
|
||||
}
|
||||
|
||||
static void project_log_create(PProject pp, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "created project %d: %s (status: %s)", pp->id, po->project.name, po->project.status);
|
||||
pit_action(pp->id, "project", str);
|
||||
}
|
||||
|
||||
static void project_log_update(PProject pp, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
bool empty = TRUE;
|
||||
|
||||
sprintf(str, "updated project %d:", pp->id);
|
||||
if (po->project.name) {
|
||||
sprintf(str + strlen(str), " (name: %s", po->project.name);
|
||||
empty = FALSE;
|
||||
} else {
|
||||
sprintf(str + strlen(str), " %s (", pp->name);
|
||||
}
|
||||
if (po->project.status) {
|
||||
sprintf(str + strlen(str), "%sstatus: %s)", (empty ? "" : ", "), po->project.status);
|
||||
}
|
||||
strcat(str, ")");
|
||||
pit_action(pp->id, "project", str);
|
||||
}
|
||||
|
||||
static void project_log_delete(int id, char *name, int number_of_tasks)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "deleted project %d: %s", id, name);
|
||||
if (number_of_tasks > 0) {
|
||||
sprintf(str + strlen(str), " with %d task%s", number_of_tasks, (number_of_tasks == 1 ? "" : "s"));
|
||||
}
|
||||
pit_action(id, "project", str);
|
||||
}
|
||||
|
||||
static void project_list(POptions po)
|
||||
{
|
||||
PPager ppager;
|
||||
|
||||
pit_db_load();
|
||||
if (projects->number_of_records > 0) {
|
||||
ppager = pit_pager_initialize(PAGER_PROJECT, projects->number_of_records);
|
||||
ppager = pit_pager_initialize(PAGER_PROJECT, 0, projects->number_of_records);
|
||||
for_each_project(pp) {
|
||||
pit_pager_print(ppager, (char *)pp);
|
||||
}
|
||||
@@ -54,9 +103,12 @@ static void project_show(int id)
|
||||
id = project_find_current(id, &pp);
|
||||
|
||||
if (pp) {
|
||||
printf("* %d: (%s) %s (status: %s, %d task%s)\n", pp->id, pp->username, pp->name, pp->status, pp->number_of_tasks, (pp->number_of_tasks != 1 ? "s" : ""));
|
||||
printf("The project was created on %s, last updated on %s\n", format_timestamp(pp->created_at), format_timestamp(pp->updated_at));
|
||||
/* printf("The project was created on %s, last updated on %s\n", format_timestamp(pp->created_at), format_timestamp(pp->updated_at)); */
|
||||
printf("* %d: (%s) %s (status: %s, %d task%s)\n",
|
||||
pp->id, pp->username, pp->name, pp->status, pp->number_of_tasks, pp->number_of_tasks != 1 ? "s" : "");
|
||||
pit_table_mark(projects, pp->id);
|
||||
if (pp->number_of_tasks > 0)
|
||||
pit_task_list(NULL, pp);
|
||||
pit_db_save();
|
||||
} else {
|
||||
die("could not find the project");
|
||||
@@ -70,9 +122,7 @@ static void project_create(POptions po)
|
||||
if (project_already_exist(po->project.name)) {
|
||||
die("project with the same name already exists");
|
||||
} else {
|
||||
Project p, *pp;
|
||||
|
||||
memset(&p, 0, sizeof(p));
|
||||
Project p = { 0 }, *pp;
|
||||
|
||||
if (!po->project.status) po->project.status = "active";
|
||||
|
||||
@@ -137,70 +187,6 @@ static void project_delete(int id)
|
||||
}
|
||||
}
|
||||
|
||||
static bool project_already_exist(char *name)
|
||||
{
|
||||
pit_db_load();
|
||||
for_each_project(pp) {
|
||||
if (!strcmp(pp->name, name)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int project_find_current(int id, PProject *ppp)
|
||||
{
|
||||
if (id) {
|
||||
*ppp = (PProject)pit_table_find(projects, id);
|
||||
if (!*ppp) die("could not find project %d", id);
|
||||
} else {
|
||||
*ppp = (PProject)pit_table_current(projects);
|
||||
if (!*ppp) die("could not find current project");
|
||||
}
|
||||
return *ppp ? (*(PProject *)ppp)->id : 0;
|
||||
}
|
||||
|
||||
static void project_log_create(PProject pp, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "created project %d: %s (status: %s)", pp->id, po->project.name, po->project.status);
|
||||
puts(str);
|
||||
pit_action(pp->id, "project", str);
|
||||
}
|
||||
|
||||
static void project_log_update(PProject pp, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
bool empty = TRUE;
|
||||
|
||||
sprintf(str, "updated project %d:", pp->id);
|
||||
if (po->project.name) {
|
||||
sprintf(str + strlen(str), " (name: %s", po->project.name);
|
||||
empty = FALSE;
|
||||
} else {
|
||||
sprintf(str + strlen(str), " %s (", pp->name);
|
||||
}
|
||||
if (po->project.status) {
|
||||
sprintf(str + strlen(str), "%sstatus: %s)", (empty ? "" : ", "), po->project.status);
|
||||
}
|
||||
strcat(str, ")");
|
||||
puts(str);
|
||||
pit_action(pp->id, "project", str);
|
||||
}
|
||||
|
||||
static void project_log_delete(int id, char *name, int number_of_tasks)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "deleted project %d: %s", id, name);
|
||||
if (number_of_tasks > 0) {
|
||||
sprintf(str + strlen(str), " with %d task%s", number_of_tasks, (number_of_tasks == 1 ? "" : "s"));
|
||||
}
|
||||
puts(str);
|
||||
pit_action(id, "project", str);
|
||||
}
|
||||
|
||||
static void project_parse_options(char **arg, POptions po)
|
||||
{
|
||||
while(*++arg) {
|
||||
@@ -219,11 +205,10 @@ static void project_parse_options(char **arg, POptions po)
|
||||
|
||||
void pit_project(char *argv[])
|
||||
{
|
||||
Options opt;
|
||||
char **arg = &argv[1];
|
||||
int number = 0;
|
||||
Options opt = {{ 0 }};
|
||||
|
||||
memset(&opt, 0, sizeof(opt));
|
||||
if (!*arg) {
|
||||
project_list(&opt); /* Show all projects. */
|
||||
} else { /* pit project [number] */
|
||||
|
||||
192
src/task.c
192
src/task.c
@@ -3,16 +3,6 @@
|
||||
#include <stdio.h>
|
||||
#include "pit.h"
|
||||
|
||||
static void task_list(POptions po);
|
||||
static void task_show(int id);
|
||||
static void task_create(POptions po);
|
||||
static void task_update(int id, POptions po);
|
||||
static int task_find_current(int id, PTask *ppt);
|
||||
static void task_log_create(PTask pt, POptions po);
|
||||
static void task_log_update(PTask pt, POptions po);
|
||||
static void task_log_delete(int id, char *name, int number_of_notes);
|
||||
static void task_parse_options(char **arg, POptions po);
|
||||
|
||||
/*
|
||||
** CREATING TASKS:
|
||||
** pit task -c name [-s status] [-p priority] [-d date] [-t time]
|
||||
@@ -30,17 +20,91 @@ static void task_parse_options(char **arg, POptions po);
|
||||
** pit task -q [number | [-n name] [-s status] [-p priority] [-d date] [-t time]]
|
||||
*/
|
||||
|
||||
static void task_list(POptions po)
|
||||
static int task_find_current(int id, PTask *ppt)
|
||||
{
|
||||
pit_db_load();
|
||||
if (id) {
|
||||
*ppt = (PTask)pit_table_find(tasks, id);
|
||||
if (!*ppt) die("could not find task %d", id);
|
||||
} else {
|
||||
*ppt = (PTask)pit_table_current(tasks);
|
||||
if (!*ppt) die("could not find current task");
|
||||
}
|
||||
return *ppt ? (*(PTask *)ppt)->id : 0;
|
||||
}
|
||||
|
||||
static void task_log_create(PTask pt, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "created task %d: %s (status: %s, priority: %s", pt->id, po->task.name, po->task.status, po->task.priority);
|
||||
if (po->task.date > 0) sprintf(str + strlen(str), ", date: %s", format_date(po->task.date));
|
||||
if (po->task.time > 0) sprintf(str + strlen(str), ", time: %s", format_time(po->task.time));
|
||||
sprintf(str + strlen(str), ", project: %d)", pt->project_id);
|
||||
pit_action(pt->id, "task", str);
|
||||
}
|
||||
|
||||
static void task_log_update(PTask pt, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
bool empty = TRUE;
|
||||
|
||||
sprintf(str, "updated task %d:", pt->id);
|
||||
if (po->task.name) {
|
||||
sprintf(str + strlen(str), " (name: %s", po->task.name);
|
||||
empty = FALSE;
|
||||
} else {
|
||||
sprintf(str + strlen(str), " %s (", pt->name);
|
||||
}
|
||||
if (po->task.status) {
|
||||
sprintf(str + strlen(str), "%sstatus: %s", (empty ? "" : ", "), po->task.status);
|
||||
empty = FALSE;
|
||||
}
|
||||
if (po->task.priority) {
|
||||
sprintf(str + strlen(str), "%spriority: %s", (empty ? "" : ", "), po->task.priority);
|
||||
empty = FALSE;
|
||||
}
|
||||
if (po->task.date) {
|
||||
if (po->task.date < 0) {
|
||||
sprintf(str + strlen(str), "%sdate: none", (empty ? "" : ", "));
|
||||
} else {
|
||||
sprintf(str + strlen(str), "%sdate: %s", (empty ? "" : ", "), format_date(po->task.date));
|
||||
}
|
||||
empty = FALSE;
|
||||
}
|
||||
if (po->task.time) {
|
||||
if (po->task.time < 0) {
|
||||
sprintf(str + strlen(str), "%stime: none", (empty ? "" : ", "));
|
||||
} else {
|
||||
sprintf(str + strlen(str), "%stime: %s", (empty ? "" : ", "), format_time(po->task.time));
|
||||
}
|
||||
empty = FALSE;
|
||||
}
|
||||
strcat(str, ")");
|
||||
pit_action(pt->id, "task", str);
|
||||
}
|
||||
|
||||
static void task_log_delete(int id, char *name, int number_of_notes)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "deleted task %d: %s", id, name);
|
||||
if (number_of_notes > 0) {
|
||||
sprintf(str + strlen(str), " with %d note%s", number_of_notes, (number_of_notes == 1 ? "" : "s"));
|
||||
}
|
||||
pit_action(id, "task", str);
|
||||
}
|
||||
|
||||
void pit_task_list(POptions po, PProject pp)
|
||||
{
|
||||
if (!tasks) pit_db_load();
|
||||
|
||||
if (tasks->number_of_records > 0) {
|
||||
PProject pp = (PProject)pit_table_current(projects);
|
||||
PPager ppager = pit_pager_initialize(PAGER_TASK, tasks->number_of_records);
|
||||
PPager ppager = pit_pager_initialize(PAGER_TASK, (pp ? 4 : 0), tasks->number_of_records);
|
||||
if (!pp) pp = (PProject)pit_table_current(projects);
|
||||
|
||||
for_each_task(pt) {
|
||||
if (pp && pt->project_id != pp->id) {
|
||||
if (pp && pt->project_id != pp->id)
|
||||
continue;
|
||||
}
|
||||
pit_pager_print(ppager, (char *)pt);
|
||||
}
|
||||
pit_pager_flush(ppager);
|
||||
@@ -55,12 +119,14 @@ static void task_show(int id)
|
||||
id = task_find_current(id, &pt);
|
||||
|
||||
if (pt) {
|
||||
/* printf("The task was created on %s, last updated on %s\n", format_timestamp(pt->created_at), format_timestamp(pt->updated_at)); */
|
||||
printf("* %d: (%s) %s (project: %d, status: %s, priority: %s", pt->id, pt->username, pt->name, pt->project_id, pt->status, pt->priority);
|
||||
if (pt->date) printf(", date: %s", format_date(pt->date));
|
||||
if (pt->time) printf(", time: %s", format_time(pt->time));
|
||||
printf(", %d note%s)\n", pt->number_of_notes, pt->number_of_notes == 1 ? "" : "s");
|
||||
printf("The task was created on %s, last updated on %s\n", format_timestamp(pt->created_at), format_timestamp(pt->updated_at));
|
||||
printf(", %d note%s)\n", pt->number_of_notes, pt->number_of_notes != 1 ? "s" : "");
|
||||
pit_table_mark(tasks, pt->id);
|
||||
if (pt->number_of_notes > 0)
|
||||
pit_note_list(pt);
|
||||
pit_db_save();
|
||||
} else {
|
||||
die("could not find the task");
|
||||
@@ -75,18 +141,15 @@ static void task_create(POptions po)
|
||||
if (!pp) {
|
||||
die("no project selected");
|
||||
} else {
|
||||
Task t, *pt;
|
||||
|
||||
memset(&t, 0, sizeof(t));
|
||||
Task t = { 0 }, *pt;
|
||||
|
||||
t.project_id = pp->id;
|
||||
if (!po->task.status) po->task.status = "open";
|
||||
if (!po->task.priority) po->task.priority = "normal";
|
||||
|
||||
strncpy(t.name, po->task.name, sizeof(t.name) - 1);
|
||||
strncpy(t.status, po->task.status, sizeof(t.status) - 1);
|
||||
strncpy(t.priority, po->task.priority, sizeof(t.priority) - 1);
|
||||
strncpy(t.username, current_user(), sizeof(t.username) - 1);
|
||||
t.project_id = pp->id;
|
||||
t.date = max(0, po->task.date);
|
||||
t.time = max(0, po->task.time);
|
||||
|
||||
@@ -166,82 +229,6 @@ void pit_task_delete(int id, PProject pp)
|
||||
}
|
||||
}
|
||||
|
||||
static int task_find_current(int id, PTask *ppt)
|
||||
{
|
||||
if (id) {
|
||||
*ppt = (PTask)pit_table_find(tasks, id);
|
||||
if (!*ppt) die("could not find task %d", id);
|
||||
} else {
|
||||
*ppt = (PTask)pit_table_current(tasks);
|
||||
if (!*ppt) die("could not find current task");
|
||||
}
|
||||
return *ppt ? (*(PTask *)ppt)->id : 0;
|
||||
}
|
||||
|
||||
static void task_log_create(PTask pt, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "created task %d: %s (status: %s, priority: %s", pt->id, po->task.name, po->task.status, po->task.priority);
|
||||
if (po->task.date > 0) sprintf(str + strlen(str), ", date: %s", format_date(po->task.date));
|
||||
if (po->task.time > 0) sprintf(str + strlen(str), ", time: %s", format_time(po->task.time));
|
||||
strcat(str, ")");
|
||||
puts(str);
|
||||
pit_action(pt->id, "task", str);
|
||||
}
|
||||
|
||||
static void task_log_update(PTask pt, POptions po)
|
||||
{
|
||||
char str[256];
|
||||
bool empty = TRUE;
|
||||
|
||||
sprintf(str, "updated task %d:", pt->id);
|
||||
if (po->task.name) {
|
||||
sprintf(str + strlen(str), " (name: %s", po->task.name);
|
||||
empty = FALSE;
|
||||
} else {
|
||||
sprintf(str + strlen(str), " %s (", pt->name);
|
||||
}
|
||||
if (po->task.status) {
|
||||
sprintf(str + strlen(str), "%sstatus: %s", (empty ? "" : ", "), po->task.status);
|
||||
empty = FALSE;
|
||||
}
|
||||
if (po->task.priority) {
|
||||
sprintf(str + strlen(str), "%spriority: %s", (empty ? "" : ", "), po->task.priority);
|
||||
empty = FALSE;
|
||||
}
|
||||
if (po->task.date) {
|
||||
if (po->task.date < 0) {
|
||||
sprintf(str + strlen(str), "%sdate: none", (empty ? "" : ", "));
|
||||
} else {
|
||||
sprintf(str + strlen(str), "%sdate: %s", (empty ? "" : ", "), format_date(po->task.date));
|
||||
}
|
||||
empty = FALSE;
|
||||
}
|
||||
if (po->task.time) {
|
||||
if (po->task.time < 0) {
|
||||
sprintf(str + strlen(str), "%stime: none", (empty ? "" : ", "));
|
||||
} else {
|
||||
sprintf(str + strlen(str), "%stime: %s", (empty ? "" : ", "), format_time(po->task.time));
|
||||
}
|
||||
}
|
||||
strcat(str, ")");
|
||||
puts(str);
|
||||
pit_action(pt->id, "task", str);
|
||||
}
|
||||
|
||||
static void task_log_delete(int id, char *name, int number_of_notes)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
sprintf(str, "deleted task %d: %s", id, name);
|
||||
if (number_of_notes > 0) {
|
||||
sprintf(str + strlen(str), " with %d note%s", number_of_notes, (number_of_notes == 1 ? "" : "s"));
|
||||
}
|
||||
puts(str);
|
||||
pit_action(id, "task", str);
|
||||
}
|
||||
|
||||
static void task_parse_options(char **arg, POptions po)
|
||||
{
|
||||
while(*++arg) {
|
||||
@@ -269,13 +256,12 @@ static void task_parse_options(char **arg, POptions po)
|
||||
|
||||
void pit_task(char *argv[])
|
||||
{
|
||||
Options opt;
|
||||
int number = 0;
|
||||
char **arg = &argv[1];
|
||||
Options opt = {{ 0 }};
|
||||
|
||||
memset(&opt, 0, sizeof(opt));
|
||||
if (!*arg) {
|
||||
task_list(&opt); /* List all tasks (i.e. use default paramaters). */
|
||||
pit_task_list(&opt, NULL); /* List all tasks for current project. */
|
||||
} else { /* pit task [number] */
|
||||
number = pit_arg_number(arg, NULL);
|
||||
if (number) {
|
||||
@@ -310,7 +296,7 @@ void pit_task(char *argv[])
|
||||
if (is_zero((char *)&opt.task, sizeof(opt.task))) {
|
||||
task_show(0); /* Show current task if any. */
|
||||
} else {
|
||||
task_list(&opt);
|
||||
pit_task_list(&opt, NULL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user