Skip to content

Commit

Permalink
skeleton for connectivity query form
Browse files Browse the repository at this point in the history
  • Loading branch information
tgbugs committed Jun 18, 2019
1 parent b85bde6 commit 0e3d592
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
30 changes: 30 additions & 0 deletions htmlfn/htmlfn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def tag(_tag, n=False):
s = f'<{_tag}{{extra}}>{nl}'
e = f'{nl}</{_tag}>'
def tagwrap(*value, **kwargs):
if 'class_' in kwargs:
kwargs['class'] = kwargs.pop('class_')
extra = (' ' + ' '.join(f'{k}="{v}"'
for k, v in kwargs.items())
if kwargs else '')
Expand All @@ -26,6 +28,8 @@ def cmb(_tag, n=False):
_s = f'<{_tag}{{extra}}>{nl}'
e = f'{nl}</{_tag}>'
def asdf(**kwargs):
if 'class_' in kwargs:
kwargs['class'] = kwargs.pop('class_')
extra = (' ' + ' '.join(f'{k}="{v}"'
for k, v in kwargs.items())
if kwargs else '')
Expand All @@ -39,6 +43,8 @@ def inner(*args):
def stag(tag_):
""" single tags """
def inner(**kwargs):
if 'class_' in kwargs:
kwargs['class'] = kwargs.pop('class_')
content = ' '.join(f'{key}="{value}"' for key, value in kwargs.items())
return f'<{tag_} {content}>'
return inner
Expand Down Expand Up @@ -168,6 +174,30 @@ def render_table(rows, *headers, halign=None):
out = '<table>' + '\n'.join(output) + '</table>'
return out


# forms
# FIXME this is quite bad

labeltag = tag('label')
inputtag = stag('input')
formtag = tag('form')
optiontag = tag('option')


def selecttag(*options, **kwargs):
return tag('select')(*(optiontag(o) for o in options), **kwargs)


def render_form(*elements, method='POST', **kwargs):
tags = labeltag, inputtag, selecttag
return formtag(*[divtag(*(tag(*args, **kwargs)
for tag, (args, kwargs) in zip(tags, parts)
if args or kwargs))
for parts in elements],
method=method,
**kwargs)


# css

monospace_body_style = 'body { font-family: Dejavu Sans Mono; font-size: 11pt }'
Expand Down
32 changes: 30 additions & 2 deletions nifstd/nifstd_tools/ontree.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,34 @@ def route_examples():
def route_sparc_connectivity_query():
kwargs = request.args
log.debug(kwargs)
return hfn.htmldoc('form here',
script = """
var ele = document.getElementById('model-selector')
ele.onselect
"""
return hfn.htmldoc(hfn.render_form(
[[('Model',), {}],
[None, None],
[('Kidney', 'Defensive breathing',), # TODO autopopulate
{'id':'model-selector'}]], # FIXME auto via js?

# FIXME must switch start and stop per model (argh)
# or hide/show depending on which model is selected
[[('start',), {}],
[None, None],
[('one', 'two', 'three'), # TODO auto populate
{}]], # FIXME auto via js?

[[('end',), {}],
[None, None],
[('one', 'two', 'three'), # TODO auto populate
{}]], # FIXME auto via js?

[[tuple(), {}],
[tuple(), {'type': 'submit', 'value': 'Query'}],
[None, None]] # FIXME auto via js?
),
scripts=(script,),
title='Connectivity query')
return connectivity_query(**kwargs)

@app.route(f'/{basename}/sparc/connectivity/view', methods=['GET'])
def route_sparc_connectivity_view():
Expand Down Expand Up @@ -689,6 +714,7 @@ def main():
sgg._verbose = verbose
sgv._verbose = verbose
sgc._verbose = verbose
sgd._verbose = verbose

if args['--test']:
test()
Expand All @@ -701,12 +727,14 @@ def main():
sgc._basePath = api
# reinit curies state
sgc.__init__(cache=sgc._get == sgc._cache_get, verbose=sgc._verbose)
sgd._basePath = api

api_key = args['--key']
if api_key:
sgg.api_key = api_key
sgv.api_key = api_key
sgc.api_key = api_key
sgd.api_key = api_key
scs = OntTerm.query.services[0]
scs.api_key = api_key
scs.setup(instrumented=OntTerm)
Expand Down

0 comments on commit 0e3d592

Please sign in to comment.