diff --git a/cms/__init__.py b/cms/__init__.py index e009f81..32b6458 100644 --- a/cms/__init__.py +++ b/cms/__init__.py @@ -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): + # """ + # 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]))] + # else: + # return [] @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) : - # 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 [] - @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(['
'.replace(':id',id),_html,'
']) @@ -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): diff --git a/index.py b/index.py index 05a6249..96d3083 100644 --- a/index.py +++ b/index.py @@ -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/') -def people(uid): - """ - This function will implement hardened links that can directly "do something" - """ - global _config - return "0",200 +# @_app.route('/id/') +# 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) + _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(["
",str( e.render(**_args)),'
']) @@ -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] - _data = pointer () - _code = 200 + if _args : + _data = pointer (**_args) + else: + _data = pointer() + _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'] - - _html = cms.components.html(_uri,_id,_args) + _system = copy.deepcopy(_config['system']) + + + _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,32 +208,38 @@ 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()) - - # _config['data'] = cms.components.data(_config) + if 'theme' not in _config['system'] : + _config['system']['theme'] = 'magazine.css' # + # root can be either on disk or in the cloud ... + # root: "" reading from disk + # root: {uid,token,folder} + # + + _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']) + # + _map = cms.components.plugins(_config) + _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 + # 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: print (__doc__) - print () + print () diff --git a/static/css/default.css b/static/css/default.css index 576cb57..5208706 100644 --- a/static/css/default.css +++ b/static/css/default.css @@ -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%; diff --git a/static/img/logo.png b/static/img/logo.png index eb64b3a..c483238 100644 Binary files a/static/img/logo.png and b/static/img/logo.png differ diff --git a/static/img/logo.svg b/static/img/logo.svg index 06b19c8..b6db745 100644 --- a/static/img/logo.svg +++ b/static/img/logo.svg @@ -1 +1,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/static/js/menu.js b/static/js/menu.js index fd8c553..faa61a0 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -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) diff --git a/templates/404.html b/templates/404.html index 0856321..e70ca45 100644 --- a/templates/404.html +++ b/templates/404.html @@ -56,7 +56,7 @@ Vanderbilt University Medical Center {%include "header.html" %}
-
+

404

diff --git a/templates/header.html b/templates/header.html index 94c1329..5958df1 100644 --- a/templates/header.html +++ b/templates/header.html @@ -1,5 +1,6 @@ {% if layout.header.logo == True %} + {% endif %}
{{layout.header.title}}
diff --git a/templates/index.html b/templates/index.html index 8769e8d..e1aef67 100644 --- a/templates/index.html +++ b/templates/index.html @@ -23,8 +23,9 @@ Vanderbilt University Medical Center - - + + + diff --git a/templates/menu.html b/templates/menu.html index 569f34d..e9dcfaa 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -15,7 +15,9 @@
{%endif%} - {{_item.text}}
+ {{_item.text}} + +
{%endfor%}
diff --git a/templates/pane.html b/templates/pane.html index f579d8b..37357a1 100644 --- a/templates/pane.html +++ b/templates/pane.html @@ -3,3 +3,4 @@ Hard code whatever you want here @TODO: Perhaps have code to add things here onload --> +