bug fixes and updates (menu) and added file references

v2.2
Steve Nyemba 2 weeks ago
parent 1b3a458b23
commit 5180838e18

@ -1,3 +1,2 @@
REM python .\qcms-sandbox\Scripts\qcms %1 %2 %3 %4 %5 %6
cd /D "%~dp0" cd /D "%~dp0"
python qcms %1 %2 %3 %4 %5 %6 python qcms %1 %2 %3 %4 %5 %6

@ -68,14 +68,16 @@ def build (_config, keep=[]): #(_path,_content):
def _realpath (uri,_config) : def _realpath (uri,_config) :
_layout = _config['layout'] _layout = _config['layout']
_uri = copy.copy(uri) _uri = copy.copy(uri)
if _layout['root'] not in _uri :
_uri = os.sep.join([_layout['root'],_uri])
if 'location' in _layout and _layout['location']: if 'location' in _layout and _layout['location']:
_loc = _layout['location'].strip() _loc = _layout['location'].strip()
if _loc.endswith(os.sep) and _uri.endswith(os.sep) : if _loc.endswith(os.sep) and _uri.endswith(os.sep) :
_uri = os.sep.join(_uri.split(os.sep)[1:]) _uri = os.sep.join(_uri.split(os.sep)[1:])
print (' *********************************** ')
_uri = os.sep.join([_layout['location'],_uri]) _uri = os.sep.join([_layout['location'],_uri])
return _uri return _uri
def _format (uri,_config): def _format (uri,_config):
@ -88,12 +90,13 @@ def read (**_args):
This will read binary files from disk, and allow the location or not to be read This will read binary files from disk, and allow the location or not to be read
@TODO: add permissions otherwise there can be disk-wide reads @TODO: add permissions otherwise there can be disk-wide reads
""" """
request = _args['request'] request = _args['request'] if 'request' in _args else None
_layout = _args['config']['layout'] _layout = _args['config']['layout']
_uri = request.args['uri'] # if 'location' in _layout : _uri = request.args['uri'] if request else _args['uri'] # if 'location' in _layout :
# _uri = os.sep.join([_layout['location'],_uri]) # _uri = os.sep.join([_layout['location'],_uri])
_uri = _realpath(_uri, _args['config']) _uri = _realpath(_uri, _args['config'])
_mimeType = 'text/plain' _mimeType = 'text/plain'
if os.path.exists(_uri): if os.path.exists(_uri):
f = open(_uri,mode='rb') f = open(_uri,mode='rb')
_stream = f.read() _stream = f.read()
@ -141,6 +144,8 @@ def html(_uri,_config) :
# _html = _html.replace(f'{os.sep}{_layout["root"]}',_layout['root']) # _html = _html.replace(f'{os.sep}{_layout["root"]}',_layout['root'])
return _html return _html
pass
def plugins (**_args): def plugins (**_args):
""" """
This function will load plugins from disk given where they come from This function will load plugins from disk given where they come from

@ -44,6 +44,14 @@ def _getId(app_id,app_x):
def _setHandler (app_id,resource) : def _setHandler (app_id,resource) :
session['app_id'] = _getId(app_id,resource) session['app_id'] = _getId(app_id,resource)
@_app.route("/favicon.ico")
@_app.route("/<app>/favicon.ico")
def favicon (app):
global _qcms
_site = _qcms.get (app)
print([' **** ',_site.get('layout.location'),_site.get('system.icon')])
return
@_app.route("/<_id>/robots.txt") @_app.route("/<_id>/robots.txt")
@_app.route("/robots.txt",defaults={'_id':None}) @_app.route("/robots.txt",defaults={'_id':None})
def robots_txt(_id): def robots_txt(_id):
@ -106,7 +114,16 @@ def _altIndex(app,resource):
_site = _qcms.get(_id) _site = _qcms.get(_id)
_uri = os.sep.join([_site.get('layout.root'),_site.get('layout.index')]) _uri = os.sep.join([_site.get('layout.root'),_site.get('layout.index')])
return render_template('index.html',**_qcms.render(_uri,'index',_id)),200 return render_template('index.html',**_qcms.render(_uri,'index',_id)),200
@_app.route('/files/<path:file>',defaults={'app':None,'module':None})
@_app.route('/<app>/files/<path:file>', defaults=[{'module':None}])
@_app.route('/<app>/<module>/files/<path:file>')
def _read(app,module,file):
global _qcms
_id = _getId(app,module)
_site = _qcms.get(_id)
_stream,_mimeType = _site.read(file)
return io.BytesIO(_stream),200,{'Content-Type':_mimeType}
@_app.route('/<app>/dialog') @_app.route('/<app>/dialog')
@_app.route('/dialog',defaults={'app':None}) @_app.route('/dialog',defaults={'app':None})
def _getdialog(app): def _getdialog(app):

@ -318,6 +318,9 @@ class Site(Initialization) :
_handler = cloud if self.get('system.source.id') == 'cloud' else disk _handler = cloud if self.get('system.source.id') == 'cloud' else disk
_html = _handler.html(_uri, self.get(None)) _html = _handler.html(_uri, self.get(None))
return " ".join([f'<div id="{_id}"> ',_html,"</div>"]) return " ".join([f'<div id="{_id}"> ',_html,"</div>"])
def read(self,_uri) :
_handler = cloud if self.get('system.source.id') == 'cloud' else disk
return _handler.read(uri=_uri, config=self.get(None))
class QCMS: class QCMS:
def __init__(self,**_args): def __init__(self,**_args):
@ -346,5 +349,4 @@ class QCMS:
def set(self,_id): def set(self,_id):
self._id = _id self._id = _id
def get(self,_id=None): def get(self,_id=None):
return self._sites[self._id] if not _id else self._sites[_id] return self._sites[self._id] if not _id else self._sites[_id]

@ -21,14 +21,14 @@ qcms.menu.Common = function (){
if($(`${_parentId} #${_domId}`).length){ if($(`${_parentId} #${_domId}`).length){
$(`${_parentId} #${_domId}`).remove() $(`${_parentId} #${_domId}`).remove()
} }
var _found = qcms.html.hasNode ($(`${_parentId}`),$(_domId))
if (_found == 0){
$(`${_parentId}`).children().slideUp('fast',()=>{ $(`${_parentId}`).children().slideUp('fast',()=>{
$(`${_parentId}`).append(_dom) $(`${_parentId}`).append(_dom)
this._finalize(`${_parentId} #${_domId}`) this._finalize(`${_parentId} #${_domId}`)
//
// we should finalize the scripts
}) })
}
}) })
@ -72,7 +72,6 @@ qcms.menu.Basic = function (_layout,_outputId,_domId){
$(_div).on('click', function (){ $(_div).on('click', function (){
// //
// how do we process this ... // how do we process this ...
console.log(this.data)
if (this.data.type == 'redirect') { if (this.data.type == 'redirect') {
window.open(this.data.url,_me._format(this.data.text)) window.open(this.data.url,_me._format(this.data.text))
}else if (this.data.type == 'dialog'){ }else if (this.data.type == 'dialog'){
@ -173,9 +172,8 @@ qcms.menu.Tabs = function (_layout,_outputId,_domId){
// var _parentId = this._parentId // var _parentId = this._parentId
var _me = this ; var _me = this ;
$(_label).on('click',function (){ $(_label).on('click',function (){
alert('....')
// _me._open(this.data.id,this.data.uri,_me._parentId) // _me._open(this.data.id,this.data.uri,_me._parentId)
console.log([_me._format(this.data.text),this.data.uri,_parentId])
_me._open(_me._format(this.data.text),this.data.uri,_parentId) _me._open(_me._format(this.data.text),this.data.uri,_parentId)
}) })
@ -187,7 +185,6 @@ qcms.menu.Tabs = function (_layout,_outputId,_domId){
// Object.keys(_layout.menu). // Object.keys(_layout.menu).
_names.forEach(function(_text){ _names.forEach(function(_text){
_item = _layout.menu[_text] _item = _layout.menu[_text]
// console.log([_item])
_tabItem = this._build(_text,_item) _tabItem = this._build(_text,_item)
$(tabs).append(_tabItem) $(tabs).append(_tabItem)

@ -31,8 +31,15 @@ qcms.page.Observer = function (_parentId,_domId,_uri){
http.post(`${qcms.context}/page`,function(x){ http.post(`${qcms.context}/page`,function(x){
var _dom = $(x.responseText) var _dom = $(x.responseText)
var _found = qcms.html.hasNode( $(_id), $(_dom))
if (_found == 0){
$(_id).append (_dom) $(_id).append (_dom)
_finalize(_id) _finalize(_id)
}
_caller.notify() _caller.notify()
}) })

@ -3,42 +3,21 @@ if (!qcms){
} }
qcms.html = {} qcms.html = {}
qcms.html.Common = function (){ qcms.html.hasNode = function (_parent,_child){
this._format = function (text){ var _found = 0
return text.replace(/(-|_)/g,' ').trim() if ($(_child).length == 0){
return 0
} }
this._open = function (text,uri,_parentId){ $(_parent).each((_index)=>{
var _domId = text.replace(/ /g,'-') var _node = $(_parent)[_index]
var http = HttpClient.instance()
http.setHeader('dom',_domId)
http.setHeader('uri',uri)
http.post(`${qcms.context}/page`,(x)=>{
//
// @TODO: In case of an error
var _dom = $(x.responseText)
if($(`${_parentId} #${_domId}`).length){
$(`${_parentId} #${_domId}`).remove()
}
$(`${_parentId}`).children().slideUp('fast',()=>{
$(`${_parentId}`).append(_dom)
this._finalize(`${_parentId} #${_domId}`) if ( $(_node)[0].innerHTML == $(_child)[0].outerHTML){
// _found = 1
// we should finalize the scripts }
}) })
return _found
})
}
this._finalize = function (_id){
var _script = $(`${_id} script`)
if (_script.lenth > 0){
_script.each( (_index)=>{
var _code = $(_script)[_index].text
eval(_code)
})
}
}
} }

@ -5,10 +5,12 @@
{% else %} {% else %}
{% set _backURI = system.parentContext%} {% set _backURI = system.parentContext%}
{% endif %} {% endif %}
<div class="icon active"> <div class="icon" style="margin:0px" >
<div align="center" class="button" onclick="window.open('{{_backURI}}','_self')" style="display:grid; grid-template-columns:auto auto; gap:4px; align-items:center "> <div align="left" class="back-button active" onclick="window.open('{{_backURI}}','_self')" >
<i class="fa-solid fa-chevron-left" style="color:darkgray; display:block"></i> <div style="display:grid; align-items:center; grid-template-columns: auto auto;">
<img src="{{system.caller.icon}}" style="height:100%"/> <i class="fa-solid fa-chevron-left" style="color:darkgray;"></i>
<img src="{{system.caller.icon}}"/>
</div>
</div> </div>
</div> </div>
{% else %} {% else %}

Loading…
Cancel
Save