From eeccd94d4dc74f5821ca2cf4c48c3f99b9c51c16 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Sun, 28 Jan 2024 23:12:38 -0600 Subject: [PATCH] enabling reload functionlit (to be connected to a webhook) --- cms/engine/__init__.py | 51 ++++++++++++++----- index.py | 26 ++++++++-- static/css/themes/default.css | 96 ++++------------------------------- 3 files changed, 72 insertions(+), 101 deletions(-) diff --git a/cms/engine/__init__.py b/cms/engine/__init__.py index b85632a..d3b75b6 100644 --- a/cms/engine/__init__.py +++ b/cms/engine/__init__.py @@ -13,17 +13,10 @@ from cms import disk, cloud class Loader : def __init__(self,**_args): - f = open (_args['path']) - self._config = json.loads(f.read()) - # - # + self._path = _args['path'] + self._original_location = None if 'location' not in _args else _args['location'] self._location = None - self._caller = None - if 'caller' in _args and _args['caller'] : - self._caller = _args['caller'] - self._location = _args['location'].split(os.sep) # needed for plugin loading - self._location = os.sep.join(self._location[:-1]) - self._config['system']['portal'] = self._caller != None + self._caller = None if 'caller' not in _args else _args['caller'] self._menu = {} self._plugins={} self.load() @@ -32,9 +25,33 @@ class Loader : """ This function will load menu (overwrite) and plugins """ + self.init_config() self.init_menu() self.init_plugins() + def init_config(self): + """ + Initialize & loading configuration from disk + """ + f = open (self._path) + self._config = json.loads(f.read()) + if self._caller : + self._location = self._original_location.split(os.sep) # needed for plugin loading + self._location = os.sep.join(self._location[:-1]) + self._config['system']['portal'] = self._caller != None + + # + # let's see if we have a location for a key in the configuration + # + _system = self._config['system'] + if 'source' in _system and 'key' in _system['source'] : + _path = _system['source']['key'] + if os.path.exists(_path): + f = open(_path) + _system['source']['key'] = f.read() + f.close() + self._system = _system + self._config['system'] = _system def init_menu(self): """ This function will read menu and sub-menu items from disk structure, @@ -45,8 +62,10 @@ class Loader : if 'source' in _config['system'] and _config['system']['source']['id'] == 'cloud' : _sourceHandler = cloud else: + print ([' **** ']) _sourceHandler = disk _object = _sourceHandler.build(_config) + # # After building the site's menu, let us add the one from 3rd party apps # @@ -202,16 +221,20 @@ class Loader : class Getter (Loader): def __init__(self,**_args): super().__init__(**_args) + def load(self): + super().load() _system = self.system() _logo = _system['logo'] if 'source' in _system and 'id' in _system['source'] and (_system['source']['id'] == 'cloud'): + _icon = f'/api/cloud/download?doc=/{_logo}' - _system['icon'] = _icon + _system['icon'] = _icon else: _root = self._config['layout']['root'] _icon = os.sep.join([_root,_logo]) _system['icon'] = _logo + self._config['system'] = _system if self._caller : _system['caller'] = {'icon': self._caller.system()['icon']} @@ -302,10 +325,12 @@ class Router : for _name in _system : _path = _system[_name]['path'] self._apps[_name] = Getter(path=_path,caller=_app,location=_path) - # print ([_name, self._apps[_name].plugins().keys()]) + print ([_name, self._apps[_name].plugins().keys()]) self._apps['main'] = _app def set(self,_id): self._id = _id def get(self): - return self._apps['main'] if self._id not in self._apps else self._apps[self._id] \ No newline at end of file + return self._apps['main'] if self._id not in self._apps else self._apps[self._id] + def get_main(self): + return self._apps['main'] diff --git a/index.py b/index.py index dac1201..a6dc883 100644 --- a/index.py +++ b/index.py @@ -23,8 +23,10 @@ _app = Flask(__name__) def favicon(): global _route _system = _route.get ().system() + _handler = _route.get() + _logo =_system['icon'] if 'icon' in _system else 'static/img/logo.svg' - return _logo + return _handler.get(_logo) # # _root = _route.get().config()['layout']['root'] # # print ([_system]) # # if 'source' in _system and 'id' in _system['source'] and (_system['source']['id'] == 'cloud'): @@ -167,8 +169,27 @@ def _post (module,name): return _info,code @_app.route('/version') def _version (): + global _route + _handler = _route.get() global _config - return _config['system']['version'] + return _handler.system()['version'] +@_app.route('/reload',methods=['POST']) +def reload(): + global _route + + _handler = _route.get_main() + _system = _handler.system() + _key = request.headers['key'] if 'key' in request.headers else None + if not 'source' in _system : + _systemKey = None + elif 'key' in _system['source'] and _system['source']['key']: + _systemKey = _system['source']['key'] + print ([_key,_systemKey,_systemKey == _key]) + if _key and _systemKey and _systemKey == _key : + _handler.load() + return "",200 + pass + return "",403 @_app.route('/page',methods=['POST']) def cms_page(): """ @@ -185,7 +206,6 @@ def cms_page(): _id = _uri.split('/')[-1].split('.')[0] else: _id = request.headers['dom'] - print ([_id,_uri]) _args = {'layout':_config['layout']} if 'plugins' in _config: _args['routes'] = _config['plugins'] diff --git a/static/css/themes/default.css b/static/css/themes/default.css index 2468298..64d3a17 100644 --- a/static/css/themes/default.css +++ b/static/css/themes/default.css @@ -1,89 +1,15 @@ -/*** - The basic structure of a site is as follows : - - header - - footer footer with the author ... - - menu main ways in which the site articulates itself (features) - - pane area where there are miscellaneous links or text +/** +* This is the default window and we will have to hide the pane (side) */ - - - - -body { - font-size:16px; - font-family: sans-serif; - font-weight:lighter; -} - -.bold {font-weight:bold} - -.main {height:98vh; display:grid; - grid-template-rows:100px 50px auto 32px; - grid-template-columns: 65% auto; gap:4px; padding:4px; margin-left:2%; margin-right:2%} -.main .header {display:grid; grid-template-columns: 80px auto; gap:4px;} -.main .header .title { font-size:32px;font-weight:bold} -.main .header img { width:80px; height: 80px;} -.main .pane {border-left:1px solid #CAD5E0} -.main .index {height:100%; line-height:1.5; padding:8px} -.footer { - border-top:1px solid #CAD5E0; - text-align:center; - display:grid; - grid-template-columns: repeat(3,1fr); - gap:4px; - padding:8px; - font-size:12px; - color:black; - align-items: center; - align-content: center; - text-transform: capitalize; - /* background-color: rgba(255,255,255,0.8); */ - - grid-column: 1 /span 2; -} - -.large-text {font-size: 24px; font-weight: bold;} - -.active { - padding:4px; - cursor:pointer; - border:2px solid transparent ; +.main {height:98vh; display:grid; grid-template-columns:70% auto; gap:4px; +grid-template-rows:70px 40px auto 32px; +padding-left:2%; padding-right:2%; } -.active .fa-chevron-right { color:transparent} -.active:hover { - border-bottom-color: #4682b4; +.main .header { display:grid; grid-template-columns:64px auto; gap:4px} +.main .header .title {font-size:28px; font-weight:bold} +.main .header img {width:55px; height:55px;} +.main .content{ + align-self:center; } -.active:hover .fa-chevron-right{ - color : #4682B4; -} -.highlight { - cursor:pointer; - border:4px solid transparent; - padding:4px; -} -.highlight:hover { - border-color:#4682B4 ; -} -.button-1 { - background-color:#d3d3d3; - color:#4682b4; - font-weight:bold; - cursor:pointer; - padding:15px; -} -.button-1:hover { - color:#FFFFFF; - background-color:#4682b4; -} - -.dialog-title { - background-color:#FF6500;color:#FFFFFF; - text-transform:capitalize; font-weight:bold; align-items:center;display:grid; grid-template-columns:auto 32px; -} -.dialog-button { - display:grid; - grid-template-columns: auto 115px; - gap:4px; -} - +.main .pane {border-left:1px solid #CAD5E0; height:100%;}