mirror of
https://github.com/michaeldv/pit.git
synced 2025-12-09 16:05:35 +00:00
Implemented creating tasks
This commit is contained in:
10
src/pit.h
10
src/pit.h
@@ -7,7 +7,7 @@ typedef unsigned char uchar;
|
||||
|
||||
#include "table.h"
|
||||
|
||||
typedef struct {
|
||||
typedef struct _Project {
|
||||
ulong id;
|
||||
char name[128]; /* Project name. */
|
||||
char status[16]; /* Project status. */
|
||||
@@ -21,7 +21,7 @@ typedef struct {
|
||||
time_t updated_at; /* When the project was last updated? */
|
||||
} Project, *PProject;
|
||||
|
||||
typedef struct {
|
||||
typedef struct _Task {
|
||||
ulong id;
|
||||
ulong project_id; /* Which project the task belongs to? */
|
||||
int priority; /* Task priority. */
|
||||
@@ -37,7 +37,7 @@ typedef struct {
|
||||
time_t updated_at; /* When the task was last updated? */
|
||||
} Task, *PTask;
|
||||
|
||||
typedef struct {
|
||||
typedef struct _Note {
|
||||
ulong id;
|
||||
ulong task_id; /* Task the note belongs to. */
|
||||
char message[255]; /* The body of the note. */
|
||||
@@ -47,7 +47,7 @@ typedef struct {
|
||||
time_t updated_at; /* When the note was last updated? */
|
||||
} Note, *PNote;
|
||||
|
||||
typedef struct {
|
||||
typedef struct _Activity {
|
||||
ulong subject_id; /* Reference to the specific Project, Task, or Note. */
|
||||
char subject[16]; /* Project, Task, or Note. */
|
||||
char message[255]; /* Log message. */
|
||||
@@ -55,7 +55,7 @@ typedef struct {
|
||||
time_t created_at; /* When log message was added? */
|
||||
} Activity, *PActivity;
|
||||
|
||||
typedef struct {
|
||||
typedef struct _User {
|
||||
ulong id;
|
||||
char username[32]; /* Username. */
|
||||
char email[32]; /* User's email. */
|
||||
|
||||
@@ -27,7 +27,9 @@ static void list_projects()
|
||||
|
||||
pit_db_load();
|
||||
for(i = 0, pp = (PProject)projects->slots; i < projects->number_of_records; i++, pp++) {
|
||||
printf("%c %lu: [%s] %s\n", (pp->id == projects->current ? '*' : ' '), pp->id, pp->status, pp->name);
|
||||
printf("%c %lu: %s (%s, %lu open task%s)\n", (pp->id == projects->current ? '*' : ' '),
|
||||
pp->id, pp->name, pp->status,
|
||||
pp->number_of_open_tasks, (pp->number_of_open_tasks != 1 ? "s" : ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +45,7 @@ static void create_project(char *name, char *status)
|
||||
memset(&p, 0, sizeof(p));
|
||||
|
||||
if (!status) {
|
||||
status = "open";
|
||||
status = "active";
|
||||
}
|
||||
printf("creating project [%s], status [%s]\n", name, status);
|
||||
|
||||
@@ -68,7 +70,22 @@ static int show_project(ulong number)
|
||||
pit_db_load();
|
||||
pp = (PProject)pit_table_find(projects, number);
|
||||
if (pp) {
|
||||
printf("%lu: [%s] %s\n", pp->id, pp->status, pp->name);
|
||||
printf("%lu: %s (%s, %lu open task%s, %lu closed task%s)\n",
|
||||
pp->id, pp->name, pp->status,
|
||||
pp->number_of_open_tasks, (pp->number_of_open_tasks != 1 ? "s" : ""),
|
||||
pp->number_of_closed_tasks, (pp->number_of_closed_tasks != 1 ? "s" : ""));
|
||||
if (pp->number_of_open_tasks > 0) {
|
||||
ulong i;
|
||||
PTask pt = (PTask)tasks->slots;
|
||||
|
||||
puts("Open tasks:");
|
||||
for(i = 0; i < tasks->number_of_records; i++, pt++) {
|
||||
if (pt->closed_at) {
|
||||
continue;
|
||||
}
|
||||
printf(" %c %lu: %s (%lu notes)\n", (pt->id == tasks->current ? '*' : ' '), pt->id, pt->name, pt->number_of_notes);
|
||||
}
|
||||
}
|
||||
pit_table_mark(projects, pp->id);
|
||||
pit_db_save();
|
||||
} else {
|
||||
|
||||
99
src/task.c
99
src/task.c
@@ -3,9 +3,104 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "pit.h"
|
||||
#include "db.h"
|
||||
#include "task.h"
|
||||
|
||||
int pit_task(char *argv[]) {
|
||||
printf("pit_task\n");
|
||||
static void list_tasks()
|
||||
{
|
||||
pit_db_load();
|
||||
|
||||
ulong i = 0;
|
||||
PTask pt = (PTask)tasks->slots;
|
||||
PProject pp = (PProject)pit_table_current(projects);
|
||||
|
||||
for(; i < tasks->number_of_records; i++, pt++) {
|
||||
if (pp && pt->project_id != pp->id) {
|
||||
continue;
|
||||
}
|
||||
printf("%c %lu: [%s] %s (%lu notes)\n", (pt->id == tasks->current ? '*' : ' '), pt->id, pt->status, pt->name, pt->number_of_notes);
|
||||
}
|
||||
}
|
||||
|
||||
static void create_task(char *name, char *status)
|
||||
{
|
||||
pit_db_load();
|
||||
|
||||
PProject pp = (PProject)pit_table_current(projects);
|
||||
|
||||
if (!pp) {
|
||||
die("no project selected");
|
||||
} else {
|
||||
Task t, *pt;
|
||||
|
||||
memset(&t, 0, sizeof(t));
|
||||
|
||||
if (!status) {
|
||||
status = "open";
|
||||
}
|
||||
printf("creating task [%s], status [%s]\n", name, status);
|
||||
|
||||
strncpy(t.name, name, sizeof(t.name) - 1);
|
||||
strncpy(t.status, status, sizeof(t.status) - 1);
|
||||
t.project_id = pp->id;
|
||||
t.priority = 1;
|
||||
t.deadline = time(NULL);
|
||||
t.number_of_notes = 0;
|
||||
t.closed_by = 0;
|
||||
t.created_by = t.updated_by = 1; // TODO
|
||||
t.closed_at = 0;
|
||||
t.created_at = t.updated_at = time(NULL);
|
||||
|
||||
pt = (PTask)pit_table_insert(tasks, (uchar *)&t);
|
||||
pit_table_mark(tasks, pt->id);
|
||||
pp->number_of_open_tasks++;
|
||||
pit_db_save();
|
||||
}
|
||||
}
|
||||
|
||||
static int show_task(ulong number)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int delete_task(ulong number)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pit_task(char *argv[])
|
||||
{
|
||||
char **arg = &argv[1];
|
||||
unsigned long number;
|
||||
|
||||
if (!*arg) {
|
||||
list_tasks();
|
||||
} else if (!strcmp(*arg, "-c")) {
|
||||
if (!*++arg) {
|
||||
die("missing task name");
|
||||
} else {
|
||||
create_task(*arg, *(arg + 1));
|
||||
}
|
||||
} else if (!strcmp(*arg, "-d")) {
|
||||
if (!*++arg) {
|
||||
die("missing task number");
|
||||
} else {
|
||||
number = atoi(*arg);
|
||||
if (!number) {
|
||||
die("invalid task number");
|
||||
} else {
|
||||
delete_task(number);
|
||||
}
|
||||
}
|
||||
/* } else if (!strcmp(*arg, "-e")) { TODO: Edit */
|
||||
} else {
|
||||
number = atoi(*arg);
|
||||
if (!number) {
|
||||
die("invalid task parameters");
|
||||
} else {
|
||||
show_task(number);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user