diff --git a/task.py b/task.py index eaa3443..4318aa0 100644 --- a/task.py +++ b/task.py @@ -28,7 +28,7 @@ def handle_task(args, last_action, conn): sys.exit(0) if args[0].isdigit(): - view_task(last_action.task_id, conn) + view_task_set_active(arg_number(args[0]), last_action.note_id, last_action.project_id, conn) elif args[0] == '-c': if len(args) == 1: print('missing task name') @@ -217,12 +217,6 @@ def delete_task(task_id, conn): def list_task(active_project_id, active_task_id, conn): logging.info('>> No arguments') - query = """ - SELECT id, username, name, status, created_at, - (SELECT count(*) FROM task WHERE task.project_id = project.id) - FROM project; - """ - query = """ SELECT id, username, status, priority, name, (SELECT count(*) FROM note WHERE note.task_id = task.id) @@ -240,5 +234,36 @@ def list_task(active_project_id, active_task_id, conn): # 2: (budd) |open| |normal| test (0 notes) # * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes) -def view_task(task_id, conn): - print('TODO View Task') \ No newline at end of file +def view_task_set_active(task_id, act_note_id, project_id, conn): + # FIXME duplicate with list_task / view_project_set_active + query = """ + SELECT id, username, status, priority, name, + (SELECT count(*) FROM note WHERE note.task_id = task.id) + FROM task WHERE id = ?; + """ #TODO Date & time + + cursor = conn.cursor() + cursor.execute(query, (task_id,)) + row = cursor.fetchone() + if not row: + print('Could not find task {}'.format(task_id)) + sys.exit(1) + + print('* {:d}: ({}) {} (status: {}, {} tasks)'.format(*row)) + + # FIXME duplicate with list_note + query = """ + SELECT id, username, message FROM note WHERE task_id = ? + """ + cursor.execute(query, (task_id,)) + for row in cursor.fetchall(): + logging.debug('Note row: {}'.format(row)) + note_id, username, message = row + print(' {} {:d}: ({}) {}'.format('*' if act_note_id == row[0] else ' ', + note_id, username, message)) + action.create_action(cursor, project_id=project_id, task_id=task_id) + +# $ pit t 11 +# * 11: (budd) a task (project: 1, status: in progress, priority: high, date: Apr 26, 2018, time: 5:00, 2 notes) +# 6: (budd) bonjour le monde +# * 7: (budd) bonjour le monde \ No newline at end of file