enabling reload functionlit (to be connected to a webhook)

master
Steve Nyemba 10 months ago
parent d06e352233
commit eeccd94d4d

@ -13,17 +13,10 @@ from cms import disk, cloud
class Loader : class Loader :
def __init__(self,**_args): def __init__(self,**_args):
f = open (_args['path']) self._path = _args['path']
self._config = json.loads(f.read()) self._original_location = None if 'location' not in _args else _args['location']
#
#
self._location = None self._location = None
self._caller = None self._caller = None if 'caller' not in _args else _args['caller']
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._menu = {} self._menu = {}
self._plugins={} self._plugins={}
self.load() self.load()
@ -32,9 +25,33 @@ class Loader :
""" """
This function will load menu (overwrite) and plugins This function will load menu (overwrite) and plugins
""" """
self.init_config()
self.init_menu() self.init_menu()
self.init_plugins() 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): def init_menu(self):
""" """
This function will read menu and sub-menu items from disk structure, 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' : if 'source' in _config['system'] and _config['system']['source']['id'] == 'cloud' :
_sourceHandler = cloud _sourceHandler = cloud
else: else:
print ([' **** '])
_sourceHandler = disk _sourceHandler = disk
_object = _sourceHandler.build(_config) _object = _sourceHandler.build(_config)
# #
# After building the site's menu, let us add the one from 3rd party apps # After building the site's menu, let us add the one from 3rd party apps
# #
@ -202,16 +221,20 @@ class Loader :
class Getter (Loader): class Getter (Loader):
def __init__(self,**_args): def __init__(self,**_args):
super().__init__(**_args) super().__init__(**_args)
def load(self):
super().load()
_system = self.system() _system = self.system()
_logo = _system['logo'] _logo = _system['logo']
if 'source' in _system and 'id' in _system['source'] and (_system['source']['id'] == 'cloud'): if 'source' in _system and 'id' in _system['source'] and (_system['source']['id'] == 'cloud'):
_icon = f'/api/cloud/download?doc=/{_logo}' _icon = f'/api/cloud/download?doc=/{_logo}'
_system['icon'] = _icon _system['icon'] = _icon
else: else:
_root = self._config['layout']['root'] _root = self._config['layout']['root']
_icon = os.sep.join([_root,_logo]) _icon = os.sep.join([_root,_logo])
_system['icon'] = _logo _system['icon'] = _logo
self._config['system'] = _system self._config['system'] = _system
if self._caller : if self._caller :
_system['caller'] = {'icon': self._caller.system()['icon']} _system['caller'] = {'icon': self._caller.system()['icon']}
@ -302,10 +325,12 @@ class Router :
for _name in _system : for _name in _system :
_path = _system[_name]['path'] _path = _system[_name]['path']
self._apps[_name] = Getter(path=_path,caller=_app,location=_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 self._apps['main'] = _app
def set(self,_id): def set(self,_id):
self._id = _id self._id = _id
def get(self): def get(self):
return self._apps['main'] if self._id not in self._apps else self._apps[self._id] return self._apps['main'] if self._id not in self._apps else self._apps[self._id]
def get_main(self):
return self._apps['main']

@ -23,8 +23,10 @@ _app = Flask(__name__)
def favicon(): def favicon():
global _route global _route
_system = _route.get ().system() _system = _route.get ().system()
_handler = _route.get()
_logo =_system['icon'] if 'icon' in _system else 'static/img/logo.svg' _logo =_system['icon'] if 'icon' in _system else 'static/img/logo.svg'
return _logo return _handler.get(_logo)
# # _root = _route.get().config()['layout']['root'] # # _root = _route.get().config()['layout']['root']
# # print ([_system]) # # print ([_system])
# # if 'source' in _system and 'id' in _system['source'] and (_system['source']['id'] == 'cloud'): # # 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 return _info,code
@_app.route('/version') @_app.route('/version')
def _version (): def _version ():
global _route
_handler = _route.get()
global _config 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']) @_app.route('/page',methods=['POST'])
def cms_page(): def cms_page():
""" """
@ -185,7 +206,6 @@ def cms_page():
_id = _uri.split('/')[-1].split('.')[0] _id = _uri.split('/')[-1].split('.')[0]
else: else:
_id = request.headers['dom'] _id = request.headers['dom']
print ([_id,_uri])
_args = {'layout':_config['layout']} _args = {'layout':_config['layout']}
if 'plugins' in _config: if 'plugins' in _config:
_args['routes'] = _config['plugins'] _args['routes'] = _config['plugins']

@ -1,89 +1,15 @@
/*** /**
The basic structure of a site is as follows : * This is the default window and we will have to hide the pane (side)
- 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
*/ */
.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%;
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 ;
} }
.active .fa-chevron-right { color:transparent} .main .header { display:grid; grid-template-columns:64px auto; gap:4px}
.active:hover { .main .header .title {font-size:28px; font-weight:bold}
border-bottom-color: #4682b4; .main .header img {width:55px; height:55px;}
.main .content{
align-self:center;
} }
.active:hover .fa-chevron-right{ .main .pane {border-left:1px solid #CAD5E0; height:100%;}
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;
}

Loading…
Cancel
Save