From 110b0b40141ad24775191add0ef8e4f5328c08ef Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Sat, 25 Jan 2020 17:54:08 +0100 Subject: [PATCH] Initial commit. --- .gitignore | 3 +++ wbadvanced/__main__.py | 31 ++++++++++++++++++++++ wbadvanced/collections.py | 56 +++++++++++++++++++++++++++++++++++++++ wbadvanced/projects.py | 50 ++++++++++++++++++++++++++++++++++ wbadvanced/users.py | 6 +++++ 5 files changed, 146 insertions(+) create mode 100644 .gitignore create mode 100755 wbadvanced/__main__.py create mode 100755 wbadvanced/collections.py create mode 100755 wbadvanced/projects.py create mode 100755 wbadvanced/users.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3901713 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*.pyc + diff --git a/wbadvanced/__main__.py b/wbadvanced/__main__.py new file mode 100755 index 0000000..3613c18 --- /dev/null +++ b/wbadvanced/__main__.py @@ -0,0 +1,31 @@ +import dash +import dash_bootstrap_components as dbc +import dash_html_components as html +import socket +import arvados +import functools +from .projects import list_projects_html +from .collections import list_collections_html + + +def main(): + app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP]) + arv = arvados.api('v1') + + user = arv.users().current().execute() + + # nav_btns = [ dbc.Button(a['name']) for a in projects ] + projects_table = list_projects_html(arv, user['uuid']) + collections_table = list_collections_html(arv, user['uuid']) + + app.layout = html.Div([ + html.H5('Projects'), + projects_table, + html.H5('Collections'), + collections_table + ], style={ 'margin': '10px' }) + + app.run_server(host=socket.getfqdn(), debug=True) + + +main() diff --git a/wbadvanced/collections.py b/wbadvanced/collections.py new file mode 100755 index 0000000..4303aac --- /dev/null +++ b/wbadvanced/collections.py @@ -0,0 +1,56 @@ +import dash_html_components as html +import dash_bootstrap_components as dbc +import humanize +from .users import get_user + + +def list_collections(arv, owner_uuid): + res = arv.collections().list(where = { + 'owner_uuid': owner_uuid + }).execute() + res = res['items'] + #while res['items_available'] > len(res['items']): + #res = arv.collections().list(where = {}) + return res + + +def list_collections_html(arv, parent): + projects = list_collections(arv, parent) + + header = html.Tr([ + html.Th('Name'), + html.Th('Description'), + html.Th('Owner'), + html.Th('Size') + ]) + header = [ html.Thead(header) ] + + rows = [] + for a in projects: + owner = get_user(arv, a['owner_uuid']) + rows.append( + html.Tr([ + html.Td([ + html.Div(html.A(href='/projects/' + a['uuid'], + children=a['name'])), + html.Div(a['uuid']) + ]), + + html.Td(a['description'] or 'Modified at ' + a['modified_at']), + + html.Td([ + html.Div(html.A(href='mailto:' + owner['email'], + children=owner['first_name'] + ' ' + owner['last_name'])), + html.Div(a['owner_uuid']) + ]), + + html.Td(humanize.naturalsize(a['file_size_total'])) + ])) + rows = [ html.Tbody(rows) ] + + res = dbc.Table(header + rows, + striped=True, + hover=True, + responsive=True) + + return res diff --git a/wbadvanced/projects.py b/wbadvanced/projects.py new file mode 100755 index 0000000..8d9b636 --- /dev/null +++ b/wbadvanced/projects.py @@ -0,0 +1,50 @@ +import dash_bootstrap_components as dbc +import dash_html_components as html +from .users import get_user + + +def list_projects(arv, parent): + res = arv.groups().list(where={ + 'owner_uuid': parent, + 'group_class': 'project' + }).execute()['items'] + return res + + +def list_projects_html(arv, parent): + projects = list_projects(arv, parent) + + header = html.Tr([ + html.Th('Name'), + html.Th('Description'), + html.Th('Owner') + ]) + header = [ html.Thead(header) ] + + rows = [] + for a in projects: + owner = get_user(arv, a['owner_uuid']) + rows.append( + html.Tr([ + html.Td([ + html.Div(html.A(href='/projects/' + a['uuid'], + children=a['name'])), + html.Div(a['uuid']) + ]), + + html.Td(a['description'] or 'Project'), + + html.Td([ + html.Div(html.A(href='mailto:' + owner['email'], + children=owner['first_name'] + ' ' + owner['last_name'])), + html.Div(a['owner_uuid']) + ]) + ])) + rows = [ html.Tbody(rows) ] + + res = dbc.Table(header + rows, + striped=True, + hover=True, + responsive=True) + + return res diff --git a/wbadvanced/users.py b/wbadvanced/users.py new file mode 100755 index 0000000..e3679c1 --- /dev/null +++ b/wbadvanced/users.py @@ -0,0 +1,6 @@ +import functools + +@functools.lru_cache(maxsize=128) +def get_user(arv, uuid): + res = arv.users().get(uuid=uuid).execute() + return res