Paginate project list. See #42224645733437
This commit is contained in:
14
cmdasana.py
14
cmdasana.py
@@ -12,6 +12,9 @@ from oauthlib.oauth2.rfc6749.errors import TokenExpiredError
|
|||||||
import ui
|
import ui
|
||||||
from secrets import CLIENT_ID, CLIENT_SECRET
|
from secrets import CLIENT_ID, CLIENT_SECRET
|
||||||
|
|
||||||
|
# id of the personal projects domain
|
||||||
|
PERSONAL = 498346170860
|
||||||
|
|
||||||
class CmdAsana:
|
class CmdAsana:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
try:
|
try:
|
||||||
@@ -56,8 +59,8 @@ class CmdAsana:
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
except Exception:
|
except Exception:
|
||||||
print "Go to the following link and enter the code:"
|
print("Go to the following link and enter the code:")
|
||||||
print url
|
print(url)
|
||||||
|
|
||||||
code = sys.stdin.readline().strip()
|
code = sys.stdin.readline().strip()
|
||||||
token = self.client.session.fetch_token(code=code)
|
token = self.client.session.fetch_token(code=code)
|
||||||
@@ -92,8 +95,11 @@ class CmdAsana:
|
|||||||
})
|
})
|
||||||
|
|
||||||
def allMyProjects(self):
|
def allMyProjects(self):
|
||||||
return self.client.projects.find_by_workspace(self.workspace_id,
|
if self.workspace_id != PERSONAL:
|
||||||
page_size=None)
|
return self.client.projects.find_by_workspace(self.workspace_id)
|
||||||
|
else:
|
||||||
|
return self.client.projects.find_by_workspace(self.workspace_id,
|
||||||
|
page_size=None)
|
||||||
|
|
||||||
def projectTasks(self, project_id):
|
def projectTasks(self, project_id):
|
||||||
return self.client.tasks.find_by_project(project_id, params={
|
return self.client.tasks.find_by_project(project_id, params={
|
||||||
|
|||||||
28
ui.py
28
ui.py
@@ -12,7 +12,8 @@ palette = [
|
|||||||
('header', 'bold,light green', ''),
|
('header', 'bold,light green', ''),
|
||||||
('task', 'light green', ''),
|
('task', 'light green', ''),
|
||||||
('section', 'white', 'dark green'),
|
('section', 'white', 'dark green'),
|
||||||
('workspace', 'white', 'dark blue')
|
('workspace', 'white', 'dark blue'),
|
||||||
|
('pager', 'standout', ''),
|
||||||
]
|
]
|
||||||
|
|
||||||
class WorkspaceMenu(urwid.Columns):
|
class WorkspaceMenu(urwid.Columns):
|
||||||
@@ -42,6 +43,11 @@ class WorkspaceButton(urwid.Button):
|
|||||||
super(WorkspaceButton, self).__init__(workspace['name'])
|
super(WorkspaceButton, self).__init__(workspace['name'])
|
||||||
urwid.connect_signal(self, 'click', onClick, workspace['id'])
|
urwid.connect_signal(self, 'click', onClick, workspace['id'])
|
||||||
|
|
||||||
|
class PagerButton(urwid.Button):
|
||||||
|
def __init__(self, loadPage):
|
||||||
|
super(PagerButton, self).__init__(('pager', 'load more'))
|
||||||
|
urwid.connect_signal(self, 'click', loadPage)
|
||||||
|
|
||||||
class ProjectIcon(urwid.SelectableIcon):
|
class ProjectIcon(urwid.SelectableIcon):
|
||||||
def __init__(self, project, onClick):
|
def __init__(self, project, onClick):
|
||||||
self.project = project
|
self.project = project
|
||||||
@@ -58,16 +64,24 @@ class ProjectList(urwid.ListBox):
|
|||||||
def __init__(self, projects):
|
def __init__(self, projects):
|
||||||
self.projects = projects
|
self.projects = projects
|
||||||
|
|
||||||
project_widgets = [ProjectIcon(project, self.loadProject)
|
|
||||||
for project in projects]
|
|
||||||
|
|
||||||
body = urwid.SimpleFocusListWalker(
|
body = urwid.SimpleFocusListWalker(
|
||||||
[ProjectIcon({'name': 'My Tasks', 'id': None},
|
[ProjectIcon({'name': 'My Tasks', 'id': None},
|
||||||
self.loadProject)] + \
|
self.loadProject),
|
||||||
project_widgets
|
None]
|
||||||
)
|
)
|
||||||
|
|
||||||
super(ProjectList, self).__init__(body)
|
super(ProjectList, self).__init__(body)
|
||||||
|
self.loadPage()
|
||||||
|
|
||||||
|
def loadPage(self, opt=None):
|
||||||
|
self.body.pop()
|
||||||
|
for i in range(50):
|
||||||
|
try:
|
||||||
|
self.body.append(ProjectIcon(self.projects.next(),
|
||||||
|
self.loadProject))
|
||||||
|
except StopIteration:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.body.append(PagerButton(self.loadPage))
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
if key == 'j':
|
if key == 'j':
|
||||||
|
|||||||
Reference in New Issue
Block a user