Add support for subtasks
This commit is contained in:
@@ -19,6 +19,8 @@ class AsanaService(object):
|
|||||||
'custom_fields.text_value',
|
'custom_fields.text_value',
|
||||||
'custom_fields.number_value',
|
'custom_fields.number_value',
|
||||||
'custom_fields.enum_value.name',
|
'custom_fields.enum_value.name',
|
||||||
|
'subtasks.completed',
|
||||||
|
'subtasks.name',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
|
|||||||
1
main.py
1
main.py
@@ -84,7 +84,6 @@ class CmdAsana(object):
|
|||||||
def exit_handler(self, key):
|
def exit_handler(self, key):
|
||||||
if key in ('q', 'Q', 'esc'):
|
if key in ('q', 'Q', 'esc'):
|
||||||
raise urwid.ExitMainLoop()
|
raise urwid.ExitMainLoop()
|
||||||
print(key)
|
|
||||||
if key in ('backspace'):
|
if key in ('backspace'):
|
||||||
self.ui.go_back()
|
self.ui.go_back()
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class User(AsanaObject):
|
|||||||
class Task(AsanaObject):
|
class Task(AsanaObject):
|
||||||
def name(self):
|
def name(self):
|
||||||
if self.object_dict['completed']:
|
if self.object_dict['completed']:
|
||||||
return '✓ %s' % super(self).name()
|
return '✓ %s' % super(Task, self).name()
|
||||||
return super(Task, self).name()
|
return super(Task, self).name()
|
||||||
|
|
||||||
def assignee(self):
|
def assignee(self):
|
||||||
@@ -59,6 +59,12 @@ class Task(AsanaObject):
|
|||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def subtasks(self):
|
||||||
|
if 'subtasks' in self.object_dict:
|
||||||
|
return [Task(t) for t in self.object_dict['subtasks']]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
def custom_fields(self):
|
def custom_fields(self):
|
||||||
if 'custom_fields' in self.object_dict:
|
if 'custom_fields' in self.object_dict:
|
||||||
return [CustomField(c) for c in self.object_dict['custom_fields']]
|
return [CustomField(c) for c in self.object_dict['custom_fields']]
|
||||||
@@ -74,20 +80,21 @@ class Project(AsanaObject):
|
|||||||
class CustomField(AsanaObject):
|
class CustomField(AsanaObject):
|
||||||
def string_value(self):
|
def string_value(self):
|
||||||
if 'text_value' in self.object_dict:
|
if 'text_value' in self.object_dict:
|
||||||
return self.object_dict['text_value']
|
return str(self.object_dict['text_value'])
|
||||||
elif 'number_value' in self.object_dict:
|
elif 'number_value' in self.object_dict:
|
||||||
return self.object_dict['number_value']
|
return str(self.object_dict['number_value'])
|
||||||
elif 'enum_value' in self.object_dict and self.object_dict['enum_value']:
|
elif 'enum_value' in self.object_dict and self.object_dict['enum_value']:
|
||||||
enum_value = AsanaObject(self.object_dict['enum_value'])
|
enum_value = AsanaObject(self.object_dict['enum_value'])
|
||||||
return enum_value.name()
|
return str(enum_value.name())
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
class Story(AsanaObject):
|
class Story(AsanaObject):
|
||||||
def string_value(self):
|
def creator(self):
|
||||||
if 'created_by' in self.object_dict:
|
if 'created_by' in self.object_dict:
|
||||||
creator = self.object_dict['created_by']['name'] + ' '
|
return self.object_dict['created_by']['name'] + ' '
|
||||||
else:
|
else:
|
||||||
creator = ''
|
return ''
|
||||||
|
|
||||||
return '%s%s' % (creator, self.object_dict['text'])
|
def text(self):
|
||||||
|
return self.object_dict['text']
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
palette = [
|
palette = [
|
||||||
('selected', 'standout', ''),
|
('atm_section', 'white,bold', 'dark blue'),
|
||||||
('selected workspace', 'standout,bold', ''),
|
('author', 'bold,dark blue', ''),
|
||||||
|
('custom_fields', 'dark red', ''),
|
||||||
('header', 'bold,light green', ''),
|
('header', 'bold,light green', ''),
|
||||||
('secondary', 'light green', ''),
|
|
||||||
('task', 'light green', ''),
|
|
||||||
('project', 'yellow', ''),
|
('project', 'yellow', ''),
|
||||||
('section', 'dark green,bold', ''),
|
('section', 'dark green,bold', ''),
|
||||||
('atm_section', 'white,bold', 'dark blue'),
|
('selected', 'standout', ''),
|
||||||
|
('task', 'light green', ''),
|
||||||
|
('text', '', ''),
|
||||||
('workspace', 'white', 'dark blue'),
|
('workspace', 'white', 'dark blue'),
|
||||||
('pager', 'standout', ''),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
keys = {
|
keys = {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
|
from ui.task_list import TaskRow
|
||||||
|
|
||||||
class TaskDetails(object):
|
class TaskDetails(object):
|
||||||
def __init__(self, task, stories, on_subtask_click, on_project_click,
|
def __init__(self, task, stories, on_subtask_click, on_project_click,
|
||||||
on_comment):
|
on_comment):
|
||||||
@@ -8,17 +10,28 @@ class TaskDetails(object):
|
|||||||
self.on_project_click = on_project_click,
|
self.on_project_click = on_project_click,
|
||||||
self.on_comment = on_comment
|
self.on_comment = on_comment
|
||||||
|
|
||||||
self.details = urwid.Pile([
|
body = [
|
||||||
('pack', urwid.Text(('task', task.name()))),
|
urwid.Text(('task', task.name())),
|
||||||
('pack', urwid.Divider('-')),
|
urwid.Divider('-'),
|
||||||
('weight', 1, Memberships(task, on_subtask_click, on_project_click) \
|
Memberships(task, on_subtask_click, on_project_click).component(),
|
||||||
.component()),
|
urwid.Divider('-'),
|
||||||
('pack', urwid.Divider('-')),
|
CustomFields(task).component(),
|
||||||
('pack', CustomFields(task).component()),
|
urwid.Divider('='),
|
||||||
('pack', urwid.Divider('-')),
|
urwid.Text(task.description()),
|
||||||
('weight', 20, urwid.Filler(urwid.Text(task.description()))),
|
urwid.Divider('-'),
|
||||||
('weight', 5, urwid.Filler(Stories(stories).component()))
|
]
|
||||||
])
|
|
||||||
|
if task.subtasks():
|
||||||
|
body.append(urwid.Pile([
|
||||||
|
TaskRow(t, on_subtask_click) for t in task.subtasks()
|
||||||
|
]))
|
||||||
|
|
||||||
|
body = body + [
|
||||||
|
urwid.Divider('-'),
|
||||||
|
Stories(stories).component()
|
||||||
|
]
|
||||||
|
|
||||||
|
self.details = urwid.ListBox(urwid.SimpleFocusListWalker(body))
|
||||||
|
|
||||||
def component(self):
|
def component(self):
|
||||||
return self.details
|
return self.details
|
||||||
@@ -35,17 +48,17 @@ class Memberships(object):
|
|||||||
on_press = lambda x: on_subtask_click(task.parent().id())
|
on_press = lambda x: on_subtask_click(task.parent().id())
|
||||||
))
|
))
|
||||||
|
|
||||||
self.memberships = urwid.ListBox(
|
self.memberships = urwid.Pile(components)
|
||||||
urwid.SimpleFocusListWalker(components)
|
|
||||||
)
|
|
||||||
|
|
||||||
def component(self):
|
def component(self):
|
||||||
return self.memberships
|
return self.memberships
|
||||||
|
|
||||||
class CustomFields(object):
|
class CustomFields(object):
|
||||||
def __init__(self, task):
|
def __init__(self, task):
|
||||||
components = [urwid.Text('%s: %s' % (f.name(), f.string_value()))
|
components = [urwid.Text([
|
||||||
for f in task.custom_fields()]
|
('custom_fields', f.name() + ': '),
|
||||||
|
f.string_value()
|
||||||
|
]) for f in task.custom_fields()]
|
||||||
|
|
||||||
self.custom_fields = urwid.Pile(components)
|
self.custom_fields = urwid.Pile(components)
|
||||||
|
|
||||||
@@ -54,7 +67,11 @@ class CustomFields(object):
|
|||||||
|
|
||||||
class Stories(object):
|
class Stories(object):
|
||||||
def __init__(self, stories):
|
def __init__(self, stories):
|
||||||
components = [urwid.Text(s.string_value()) for s in stories]
|
components = [urwid.Text([
|
||||||
|
('author', s.creator()),
|
||||||
|
s.text(),
|
||||||
|
'\n'
|
||||||
|
]) for s in stories]
|
||||||
|
|
||||||
self.stories = urwid.Pile(components)
|
self.stories = urwid.Pile(components)
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class TaskRow(urwid.SelectableIcon):
|
|||||||
def __init__(self, task, on_click):
|
def __init__(self, task, on_click):
|
||||||
self.on_click = on_click
|
self.on_click = on_click
|
||||||
self.task = task
|
self.task = task
|
||||||
style = 'section' if task.name()[-1] == ':' else 'task'
|
style = 'section' if task.name() and task.name()[-1] == ':' else 'task'
|
||||||
super(TaskRow, self).__init__((style, task.name()))
|
super(TaskRow, self).__init__((style, task.name()))
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
|
|||||||
Reference in New Issue
Block a user