bug fixes and minor updates

master
Steve Nyemba 11 months ago
parent aec9275468
commit 8bfa773195

@ -6,43 +6,61 @@ import copy
from jinja2 import Environment, BaseLoader, FileSystemLoader
import importlib
import importlib.util
from cms import disk, cloud
# import cloud
class components :
@staticmethod
def folders (_path):
_content = os.listdir(_path)
return [_name for _name in _content if os.path.isdir(os.sep.join([_path,_name])) if not _name.startswith('_')]
@staticmethod
def content (_folder) :
if os.path.exists(_folder) :
# @staticmethod
# def folders (_path):
# """
# This function reads the content of a folder (no depth, it must be simple)
# """
# _content = os.listdir(_path)
# return [_name for _name in _content if os.path.isdir(os.sep.join([_path,_name])) if not _name.startswith('_')]
# @staticmethod
# def content (_folder) :
# if os.path.exists(_folder) :
# # return [{'text':_name.split('.')[0].replace('_', ' ').replace('-',' ').strip(),'uri': os.sep.join([_folder,_name])} for _name in os.listdir(_folder) if not _name.startswith('_') and os.path.isfile( os.sep.join([_folder,_name]))]
# return [{'text':_name.split('.')[0].replace('_', ' ').replace('-',' ').strip(),'uri': os.sep.join([_folder,_name])} for _name in os.listdir(_folder) if not _name.startswith('_') and os.path.isfile( os.sep.join([_folder,_name]))]
return [{'text':_name.split('.')[0].replace('_', ' ').replace('-',' ').strip(),'uri': os.sep.join([_folder,_name])} for _name in os.listdir(_folder) if not _name.startswith('_') and os.path.isfile( os.sep.join([_folder,_name]))]
else:
return []
# else:
# return []
@staticmethod
def menu(_path,_config):
def menu(_config):
"""
This function will read menu and sub-menu items from disk structure,
The files are loaded will
"""
_items = components.folders(_path)
# _items = components.folders(_path)
_layout = copy.deepcopy(_config['layout'])
_overwrite = _layout['overwrite'] if 'overwrite' in _layout else {}
# _layout = copy.deepcopy(_config['layout'])
# _overwrite = _layout['overwrite'] if 'overwrite' in _layout else {}
#
# content of each menu item
_subItems = [ components.content (os.sep.join([_path,_name]))for _name in _items ]
if 'map' in _layout :
_items = [_name if _name not in _layout['map'] else _layout['map'][_name] for _name in _items]
# _subItems = [ components.content (os.sep.join([_path,_name]))for _name in _items ]
# if 'map' in _layout :
# _items = [_name if _name not in _layout['map'] else _layout['map'][_name] for _name in _items]
_object = dict(zip(_items,_subItems))
# _object = dict(zip(_items,_subItems))
if 'source' in _config['system'] and _config['system']['source']['id'] == 'cloud' :
_sourceHandler = cloud
else:
_sourceHandler = disk
_object = _sourceHandler.build(_config)
# _object = disk.build(_path,_config) if type(_path) == str else cloud.build(_path,_config)
_layout = copy.deepcopy(_config['layout'])
_overwrite = _layout['overwrite'] if 'overwrite' in _layout else {}
#
# @TODO: Find a way to translate rename/replace keys of the _object (menu) here
#
#-- applying overwrites to the menu items
for _name in _object :
_submenu = _object[_name]
_index = 0
for _item in _submenu :
text = _item['text']
text = _item['text'].strip()
if text in _overwrite :
if 'uri' in _item and 'url' in 'url' in _overwrite[text] :
del _item['uri']
@ -52,13 +70,21 @@ class components :
_submenu[_index] = _item
_index += 1
return _object
@staticmethod
def html(uri,id,_args={}) :
def html(uri,id,_args={},_system={}) :
"""
This function reads a given uri and returns the appropriate html document, and applies environment context
"""
_html = (open(uri)).read()
if 'source' in _system and _system['source']['id'] == 'cloud':
_html = cloud.html(uri,_args)
else:
_html = disk.html(uri)
# _html = (open(uri)).read()
#return ' '.join(['<div id=":id" class=":id">'.replace(':id',id),_html,'</div>'])
@ -111,10 +137,15 @@ class components :
return getattr(module,_name) if hasattr(module,_name) else None
@staticmethod
def plugins(_config) :
"""
This function looks for plugins in the folder on disk (no cloud support) and attempts to load them
"""
PATH= os.sep.join([_config['layout']['root'],'_plugins'])
_map = {}
if not os.path.exists(PATH) :
return _map
if 'plugins' not in _config :
_config['plugins'] = {}
_conf = _config['plugins']
for _key in _conf :
@ -125,6 +156,17 @@ class components :
if _pointer :
_uri = "/".join(["api",_key,_name])
_map[_uri] = _pointer
#
# Let us load the default plugins
if 'source' in _config['system'] and _config['system']['source']['id'] == 'cloud' :
_plugins = cloud.plugins()
else:
_plugins = disk.plugins()
#
# If there are any plugins found, we should load them and use them
if _plugins :
_map = dict(_map,**_plugins)
return _map
@staticmethod
def context(_config):

@ -16,8 +16,8 @@ import base64
from jinja2 import Environment, BaseLoader
_app = Flask(__name__)
@_app.route('/favicon.ico')
def favicon():
global _config
@ -28,16 +28,19 @@ def favicon():
@_app.route("/")
def _index ():
global _config
_args = {'system':_config['system']}
_args = {}
if 'plugins' in _config :
_args['routes']=_config['plugins']
_args['routes']=['plugins']
_system = copy.deepcopy(_config['system'])
try:
_args['layout'] = _config['layout']
# _args = dict(_args,**_config['layout'])
# _args = copy.copy(_config)
uri = os.sep.join([_config['layout']['root'], _config['layout']['index']])
_html = cms.components.html(uri,'index',_args)
_html = cms.components.html(uri,'index',_args,_system)
_args['index'] = _html
# e = Environment(loader=BaseLoader()).from_string(_html)
# e = cms.components.context(_config).from_string(_html)
@ -49,30 +52,39 @@ def _index ():
_index_page = "404.html"
_args['uri'] = request.base_url
pass
if 'source' in _system :
del _system['source']
_args['system'] = _system
return render_template(_index_page,**_args)
@_app.route('/id/<uid>')
def people(uid):
"""
This function will implement hardened links that can directly "do something"
"""
global _config
return "0",200
# @_app.route('/id/<uid>')
# def people(uid):
# """
# This function will implement hardened links that can directly "do something"
# """
# global _config
# return "0",200
@_app.route('/dialog')
def _dialog ():
global _config
_uri = os.sep.join([_config['layout']['root'],request.headers['uri']])
# _uri = request.headers['uri']
_id = request.headers['dom']
# _data = cms.components.data(_config)
_args = {'system':_config['system']}
_args = {} #{'system':_config['system']}
_args['title'] = _id
if 'plugins' in _config :
_args['routes'] = _config['plugins']
_html = cms.components.html(_uri,_id,_args)
e = Environment(loader=BaseLoader()).from_string(_html)
_system = copy.deepcopy(_config['system'])
_html = cms.components.html(_uri,_id,_config,_system)
e = Environment(loader=BaseLoader()).from_string(_html)
if 'source' in _system :
del _system['source']
_args['system'] = _system
_args['html'] = _html
_html = ''.join(["<div style='padding:1%'>",str( e.render(**_args)),'</div>'])
@ -94,13 +106,18 @@ def _getproxy(module,name) :
global _config
uri = '/'.join(['api',module,name])
_args = dict(request.args,**{})
_args['config'] = _config
if uri not in _config['plugins'] :
_data = {}
_code = 404
else:
pointer = _config['plugins'][uri]
if _args :
_data = pointer (**_args)
else:
_data = pointer()
_code = 200
_code = 200 if _data else 500
return _data,_code
@ -137,14 +154,18 @@ def cms_page():
global _config
_uri = os.sep.join([_config['layout']['root'],request.headers['uri']])
_id = request.headers['dom']
_args = {'system':_config['system']}
_args = {'layout':_config['layout']}
if 'plugins' in _config:
_args['routes'] = _config['plugins']
_system = copy.deepcopy(_config['system'])
_html = cms.components.html(_uri,_id,_args)
_html = cms.components.html(_uri,_id,_args,_system)
e = Environment(loader=BaseLoader()).from_string(_html)
# _data = {} #cms.components.data(_config)
if 'source' in _system :
del _system['source']
_args['system'] = _system
_html = e.render(**_args)
return _html,200
@ -187,30 +208,36 @@ if __name__ == '__main__' :
_path = SYS_ARGS['config'] if 'config' in SYS_ARGS else 'config.json'
if os.path.exists(_path):
_config = json.loads((open (_path)).read())
_root = _config['layout']['root']
_config['layout']['menu'] = cms.components.menu(_root,_config)
if 'map' in _config['layout'] and 'order' in _config['layout'] and 'menu' in _config['layout']['order'] :
"""
We are insuring that the order of the menu items can be manually configured and have proper representation without quircks associated with folder name convention
"""
_map = _config['layout']['map']
labels = [_name if _name not in _map else _map[_name] for _name in _config['layout']['order']['menu']]
labels = [_name for _name in labels if _name in _config['layout']['menu']]
_config['layout']['order']['menu'] = labels
else:
_config['layout']['order']['menu'] = list(_config['layout']['menu'].keys())
if 'theme' not in _config['system'] :
_config['system']['theme'] = 'magazine.css'
#
# root can be either on disk or in the cloud ...
# root: "<path>" reading from disk
# root: {uid,token,folder}
#
# _config['data'] = cms.components.data(_config)
_root = _config['layout']['root']
_menu = cms.components.menu(_config)
if 'order' in _config['layout'] and 'menu' in _config['layout']['order']:
_sortedmenu = {}
for _name in _config['layout']['order']['menu'] :
_sortedmenu[_name] = _menu[_name]
_menu = _sortedmenu
_config['layout']['menu'] = _menu #cms.components.menu(_config)
# if 'data' in _config :
# _config['data'] = cms.components.data(_config['data'])
#
# Let us load the plugins if any are available
if 'plugins' in _config :
_map = cms.components.plugins(_config)
if _map :
_config['plugins'] = _map
# Let us load the plugins if any are available
# if 'plugins' in _config :
# _map = cms.components.plugins(_config)
# if _map :
# _config['plugins'] = _map
#
# register the functions with Jinja2
cms.components.context(_config)
# cms.components.context(_config)
_args = _config['system']['app']
_app.run(**_args)
else:

@ -115,11 +115,12 @@ body {
.main .content {
padding:8px;
border-radius: 10px;
/* box-shadow: 0px 6px 10px rgba(0, 0, 0, 0.25); */
/* transition: all 0.2s; */
}
.main .content img {width:78%}
.index {
height:100%;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 19 KiB

@ -1 +1,4 @@
<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 50 50" id="Layer_1" version="1.1" viewBox="0 0 50 50" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><g><path d="M45.47913,47.26579H4.5208c-1.9445,0-3.52083-1.57633-3.52083-3.52083V6.25508 c0-1.9445,1.57633-3.52083,3.52083-3.52083h40.95833c1.9445,0,3.52083,1.57633,3.52083,3.52083v37.48988 C48.99996,45.68946,47.42363,47.26579,45.47913,47.26579z" fill="#E7E3E6"/><path d="M48.99997,9.76048V6.25507c0-1.94453-1.57633-3.52086-3.52081-3.52086H4.52079 c-1.94448,0-3.52081,1.57633-3.52081,3.52086v3.50541H48.99997z" fill="#53B1E2"/><path d="M17.06462,10.40814H4.45078v-2.7194c0-0.67552,0.54762-1.22313,1.22313-1.22313h10.16758 c0.67552,0,1.22313,0.54762,1.22313,1.22313V10.40814z" fill="#E7E3E6"/><path d="M29.67847,9.76048H17.06462V7.68875c0-0.67552,0.54762-1.22313,1.22313-1.22313h10.16758 c0.67552,0,1.22313,0.54762,1.22313,1.22313V9.76048z" fill="#D2D2D2"/><circle cx="40.42996" cy="6.54935" fill="#E7E3E6" r="1.34955"/><circle cx="36.3145" cy="6.54935" fill="#E7E3E6" r="1.34955"/></g><g><rect fill="#D2D2D2" height="8.07299" width="41.91538" x="4.26873" y="12.18866"/><g><circle cx="10.19687" cy="25.56284" fill="#EC6E62" r="2.83107"/><circle cx="25.22643" cy="25.56284" fill="#85BD57" r="2.83107"/><circle cx="40.25598" cy="25.56284" fill="#53B1E2" r="2.83107"/><rect fill="#D2D2D2" height="0.79573" width="8.9377" x="5.72802" y="31.618"/><rect fill="#D2D2D2" height="0.79573" width="8.9377" x="5.72802" y="30.11498"/><rect fill="#D2D2D2" height="0.79575" width="6.33346" x="5.72803" y="33.12099"/><g><rect fill="#D2D2D2" height="0.79573" width="8.9377" x="20.75758" y="31.618"/><rect fill="#D2D2D2" height="0.79573" width="8.9377" x="20.75758" y="30.11498"/><rect fill="#D2D2D2" height="0.79575" width="6.33346" x="20.75757" y="33.12099"/></g><rect fill="#D2D2D2" height="0.79573" width="8.9377" x="35.78713" y="31.618"/><rect fill="#D2D2D2" height="0.79573" width="8.9377" x="35.78713" y="30.11498"/><rect fill="#D2D2D2" height="0.79575" width="6.33346" x="35.78712" y="33.12099"/><rect fill="#EC6E62" height="7.46029" width="11.23692" x="4.57841" y="35.93731"/><rect fill="#85BD57" height="7.46029" width="11.23692" x="19.60796" y="35.93731"/><rect fill="#53B1E2" height="7.46029" width="11.23692" x="34.63752" y="35.93731"/></g></g></g></svg>
<?xml version="1.0" ?><svg id="Layer_1" style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style type="text/css">
.st0{fill:#2B79C2;}
.st1{fill:#3B4652;}
</style><g><path class="st1" d="M317.7,230c-6,0-10.9-4.9-10.9-10.9c0-6,4.9-10.9,10.9-10.9c6,0,10.9,4.9,10.9,10.9 C328.7,225.1,323.8,230,317.7,230z"/><path class="st1" d="M256,252C256,252,256,252,256,252C256,252,256,252,256,252c-6.1,0-10.9-4.9-10.9-10.9s4.9-10.9,10.9-10.9 s10.9,4.9,10.9,10.9S262,251.9,256,252z"/><path class="st1" d="M194.3,230c-6,0-10.9-4.9-10.9-10.9c0-6,4.9-10.9,10.9-10.9c6,0,10.9,4.9,10.9,10.9 C205.2,225.1,200.3,230,194.3,230z"/><path class="st0" d="M385.8,227.6c0,53.9-32.8,100.1-79.6,119.7c-3.2,1.3-6.5,2.6-9.8,3.7v-80.9h21.4c3.9,0,7-3.1,7-7V243 c10.4-3,17.9-12.6,17.9-23.9c0-13.7-11.2-24.9-24.9-24.9c-13.7,0-24.9,11.2-24.9,24.9c0,11.3,7.6,20.9,17.9,23.9v13.1h-21.4 c-3.9,0-7,3.1-7,7v90.2c0,0.5,0,0.9,0.1,1.4c-6.3,1.3-12.8,2.2-19.5,2.5v-92.3c10.3-3,17.9-12.6,17.9-23.9 c0-13.7-11.2-24.9-24.9-24.9s-24.9,11.2-24.9,24.9c0,11.3,7.6,20.9,17.9,23.9v92.3c-6.6-0.3-13.1-1.2-19.5-2.5 c0.1-0.4,0.1-0.9,0.1-1.4v-90.2c0-3.9-3.1-7-7-7h-21.4V243c10.3-3,17.9-12.6,17.9-23.9c0-13.7-11.2-24.9-24.9-24.9 c-13.8,0-24.9,11.2-24.9,24.9c0,11.3,7.6,20.9,17.9,23.9v20.1c0,3.9,3.1,7,7,7h21.4V351c-3.3-1.1-6.6-2.3-9.8-3.7 c-46.8-19.6-79.6-65.8-79.6-119.7c0-71.7,58.1-129.8,129.8-129.8S385.8,155.9,385.8,227.6z"/><path class="st1" d="M302,489.4c-4.5,6.9-12.3,11.4-21.2,11.4h-49.5c-8.9,0-16.7-4.5-21.2-11.4H302z"/><path class="st1" d="M327.4,440.3c-2.8,2.8-6.6,4.5-10.8,4.5c8.5,0,15.3,6.9,15.3,15.3c0,4.2-1.7,8-4.5,10.8 c-2.8,2.8-6.6,4.5-10.8,4.5H195.4c-8.5,0-15.3-6.9-15.3-15.3c0-4.2,1.7-8,4.5-10.8c2.8-2.8,6.6-4.5,10.8-4.5 c-8.5,0-15.3-6.9-15.3-15.3c0-4.2,1.7-8.1,4.5-10.8c2.8-2.8,6.6-4.5,10.8-4.5c-8.5,0-15.3-6.8-15.3-15.3c0-4.2,1.7-8,4.5-10.8 c2.8-2.8,6.6-4.5,10.8-4.5h10.4v-18.5c32.3,11.8,68,11.9,100.3,0.2v18.3h10.4c8.5,0,15.3,6.8,15.3,15.3c0,4.2-1.7,8.1-4.5,10.8 c-2.8,2.8-6.6,4.5-10.8,4.5c8.5,0,15.3,6.9,15.3,15.3C331.9,433.7,330.2,437.6,327.4,440.3z"/><g><path class="st1" d="M256.3,11.2c-12,0-21.8,9.8-21.8,21.8c0,9.5,6.1,17.5,14.5,20.5v13.9c0,3.9,3.1,7,7,7s7-3.1,7-7V53.6 c8.7-2.8,15-11,15-20.7C278,20.9,268.2,11.2,256.3,11.2z"/><path class="st1" d="M369.3,121.3c1.8,0,3.6-0.7,4.9-2.1l9.7-9.7c3.1,1.6,6.5,2.4,9.8,2.4c5.6,0,11.1-2.1,15.4-6.4 c4.1-4.1,6.4-9.6,6.4-15.4c0-5.8-2.3-11.3-6.4-15.4s-9.6-6.4-15.4-6.4s-11.3,2.3-15.4,6.4s-6.4,9.6-6.4,15.4 c0,3.3,0.8,6.5,2.1,9.4l-9.9,9.9c-2.7,2.7-2.7,7.2,0,9.9C365.7,120.6,367.5,121.3,369.3,121.3z"/><path class="st1" d="M450.7,206.1c-9.5,0-17.5,6.1-20.5,14.5h-13.9c-3.9,0-7,3.1-7,7s3.1,7,7,7H430c2.8,8.7,11,15,20.7,15 c12,0,21.8-9.8,21.8-21.8S462.7,206.1,450.7,206.1z"/><path class="st1" d="M393.5,343.7c-3.3,0-6.5,0.8-9.4,2.1l-9.9-9.9c-2.7-2.7-7.2-2.7-9.9,0c-2.7,2.7-2.7,7.2,0,9.9l9.7,9.7 c-1.5,3-2.4,6.4-2.4,9.8c0,5.8,2.3,11.3,6.4,15.4c0,0,0,0,0,0c4.2,4.2,9.8,6.4,15.4,6.4c5.6,0,11.1-2.1,15.4-6.4 c4.1-4.1,6.4-9.6,6.4-15.4c0-5.8-2.3-11.3-6.4-15.4C404.8,346,399.3,343.7,393.5,343.7z"/><path class="st1" d="M137.7,336l-9.7,9.7c-3-1.5-6.4-2.4-9.8-2.4c-5.8,0-11.3,2.3-15.4,6.4c0,0,0,0,0,0c-4.1,4.1-6.4,9.6-6.4,15.4 c0,5.8,2.3,11.3,6.4,15.4c4.2,4.2,9.8,6.4,15.4,6.4c5.6,0,11.1-2.1,15.4-6.4c4.1-4.1,6.4-9.6,6.4-15.4c0-3.3-0.8-6.5-2.1-9.4 l9.9-9.9c2.7-2.7,2.7-7.2,0-9.9C144.9,333.3,140.5,333.3,137.7,336z"/><path class="st1" d="M102.7,227.6c0-3.9-3.1-7-7-7H82c-2.8-8.7-11-15-20.7-15c-12,0-21.8,9.8-21.8,21.8s9.8,21.8,21.8,21.8 c9.5,0,17.5-6.1,20.5-14.5h13.9C99.6,234.6,102.7,231.5,102.7,227.6z"/><path class="st1" d="M137.9,99.6c1.5-3,2.4-6.4,2.4-9.8c0-5.8-2.3-11.3-6.4-15.4s-9.6-6.4-15.4-6.4s-11.3,2.3-15.4,6.4 s-6.4,9.6-6.4,15.4s2.3,11.3,6.4,15.4s9.6,6.4,15.4,6.4c3.3,0,6.5-0.8,9.4-2.1l9.9,9.9c1.4,1.4,3.2,2.1,4.9,2.1 c1.8,0,3.6-0.7,4.9-2.1c2.7-2.7,2.7-7.2,0-9.9L137.9,99.6z"/></g></g></svg>

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

@ -67,7 +67,6 @@ menu.apply_link =function(_args){
if (_args.url){
jx.modal.show(_args.url)
}else{
// _html = jx.dom.get.value(_args.text)
// console.log(_html)
// jx.modal.show(_html)

@ -56,7 +56,7 @@ Vanderbilt University Medical Center
{%include "header.html" %}
</div>
<div id="dialog" class="dialog">
<div align="center" class="large-text" style="font-size:48px">
<div align="center" class="large-text" style="font-size:48px; font-weight: bold;">
<p><i class="fa-regular fa-circle-xmark"></i> 404
</p>

@ -1,5 +1,6 @@
{% if layout.header.logo == True %}
<img src="{{system.context}}/static/img/{{system.logo}}">
{% endif %}
<div>
<div class="title">{{layout.header.title}}</div>

@ -23,8 +23,9 @@ Vanderbilt University Medical Center
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="x12,parser,healthcare,tools,informatics,research,phd,post-doc,api,python, jamia,amia,pnas,nature">
<meta name="robots" content="/, follow, max-snippet:-1, max-image-preview:large">
<link href="{{system.context}}/static/css/{{system.theme}}/default.css" rel="stylesheet" type="text/css">
<link href="{{system.context}}/static/css/animation/_ocean.css" rel="stylesheet" type="text/css">
<link href="{{system.context}}/static/css/default.css" rel="stylesheet" type="text/css">
<!-- <link href="{{system.context}}/static/css/animation/_ocean.css" rel="stylesheet" type="text/css"> -->
<link href="{{system.context}}/static/css/themes/{{system.theme}}" rel="stylesheet" type="text/css">
<link href="{{system.context}}/static/css/icons.css" rel="stylesheet" type="text/css">
<link href="{{system.context}}/static/css/border.css" rel="stylesheet" type="text/css">
<script src="{{system.context}}/static/js/jx/dom.js"></script>

@ -15,7 +15,9 @@
<div class="active" onclick='menu.apply_link({{_item|tojson}})'>
{%endif%}
<i class="fa-solid fa-chevron-right"></i>
{{_item.text}}</div>
{{_item.text}}
</div>
{%endfor%}
</div>

@ -3,3 +3,4 @@
Hard code whatever you want here
@TODO: Perhaps have code to add things here onload
-->
<iframe src="/api/cloud/download?doc=/www/_news/index.html"></iframe>

Loading…
Cancel
Save