From 5180838e1854fe22ec88e519440165c907658b39 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Fri, 29 Aug 2025 13:56:23 -0500 Subject: [PATCH] bug fixes and updates (menu) and added file references --- bin/qcms.bat | 3 +- cms/disk.py | 11 +++++-- cms/index.py | 19 ++++++++++- cms/sites/__init__.py | 4 ++- cms/static/js/qcms/menu.js | 21 ++++++------ cms/static/js/qcms/page-loader.js | 11 +++++-- cms/static/js/qcms/qcms.js | 53 ++++++++++--------------------- cms/templates/menu.html | 10 +++--- 8 files changed, 70 insertions(+), 62 deletions(-) diff --git a/bin/qcms.bat b/bin/qcms.bat index d3c4114..8de5a63 100644 --- a/bin/qcms.bat +++ b/bin/qcms.bat @@ -1,3 +1,2 @@ -REM python .\qcms-sandbox\Scripts\qcms %1 %2 %3 %4 %5 %6 cd /D "%~dp0" -python qcms %1 %2 %3 %4 %5 %6 \ No newline at end of file +python qcms %1 %2 %3 %4 %5 %6 diff --git a/cms/disk.py b/cms/disk.py index 917a191..18cbbb3 100644 --- a/cms/disk.py +++ b/cms/disk.py @@ -68,14 +68,16 @@ def build (_config, keep=[]): #(_path,_content): def _realpath (uri,_config) : _layout = _config['layout'] _uri = copy.copy(uri) + if _layout['root'] not in _uri : + _uri = os.sep.join([_layout['root'],_uri]) if 'location' in _layout and _layout['location']: _loc = _layout['location'].strip() if _loc.endswith(os.sep) and _uri.endswith(os.sep) : _uri = os.sep.join(_uri.split(os.sep)[1:]) - print (' *********************************** ') _uri = os.sep.join([_layout['location'],_uri]) + return _uri 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 @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'] - _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 = _realpath(_uri, _args['config']) _mimeType = 'text/plain' + if os.path.exists(_uri): f = open(_uri,mode='rb') _stream = f.read() @@ -141,6 +144,8 @@ def html(_uri,_config) : # _html = _html.replace(f'{os.sep}{_layout["root"]}',_layout['root']) return _html + + pass def plugins (**_args): """ This function will load plugins from disk given where they come from diff --git a/cms/index.py b/cms/index.py index df91057..15ec13e 100644 --- a/cms/index.py +++ b/cms/index.py @@ -44,6 +44,14 @@ def _getId(app_id,app_x): def _setHandler (app_id,resource) : session['app_id'] = _getId(app_id,resource) +@_app.route("/favicon.ico") +@_app.route("//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("/robots.txt",defaults={'_id':None}) def robots_txt(_id): @@ -106,7 +114,16 @@ def _altIndex(app,resource): _site = _qcms.get(_id) _uri = os.sep.join([_site.get('layout.root'),_site.get('layout.index')]) return render_template('index.html',**_qcms.render(_uri,'index',_id)),200 - +@_app.route('/files/',defaults={'app':None,'module':None}) +@_app.route('//files/', defaults=[{'module':None}]) +@_app.route('///files/') +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('//dialog') @_app.route('/dialog',defaults={'app':None}) def _getdialog(app): diff --git a/cms/sites/__init__.py b/cms/sites/__init__.py index 8dc2a11..5ceff9d 100644 --- a/cms/sites/__init__.py +++ b/cms/sites/__init__.py @@ -318,6 +318,9 @@ class Site(Initialization) : _handler = cloud if self.get('system.source.id') == 'cloud' else disk _html = _handler.html(_uri, self.get(None)) return " ".join([f'
',_html,"
"]) + 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: def __init__(self,**_args): @@ -346,5 +349,4 @@ class QCMS: def set(self,_id): self._id = _id def get(self,_id=None): - return self._sites[self._id] if not _id else self._sites[_id] diff --git a/cms/static/js/qcms/menu.js b/cms/static/js/qcms/menu.js index 14e0209..95bdf19 100644 --- a/cms/static/js/qcms/menu.js +++ b/cms/static/js/qcms/menu.js @@ -21,14 +21,14 @@ qcms.menu.Common = function (){ if($(`${_parentId} #${_domId}`).length){ $(`${_parentId} #${_domId}`).remove() } - $(`${_parentId}`).children().slideUp('fast',()=>{ - $(`${_parentId}`).append(_dom) - - this._finalize(`${_parentId} #${_domId}`) - // - // we should finalize the scripts - - }) + var _found = qcms.html.hasNode ($(`${_parentId}`),$(_domId)) + if (_found == 0){ + $(`${_parentId}`).children().slideUp('fast',()=>{ + $(`${_parentId}`).append(_dom) + this._finalize(`${_parentId} #${_domId}`) + + }) + } }) @@ -72,7 +72,6 @@ qcms.menu.Basic = function (_layout,_outputId,_domId){ $(_div).on('click', function (){ // // how do we process this ... - console.log(this.data) if (this.data.type == 'redirect') { window.open(this.data.url,_me._format(this.data.text)) }else if (this.data.type == 'dialog'){ @@ -173,9 +172,8 @@ qcms.menu.Tabs = function (_layout,_outputId,_domId){ // var _parentId = this._parentId var _me = this ; $(_label).on('click',function (){ - alert('....') + // _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) }) @@ -187,7 +185,6 @@ qcms.menu.Tabs = function (_layout,_outputId,_domId){ // Object.keys(_layout.menu). _names.forEach(function(_text){ _item = _layout.menu[_text] - // console.log([_item]) _tabItem = this._build(_text,_item) $(tabs).append(_tabItem) diff --git a/cms/static/js/qcms/page-loader.js b/cms/static/js/qcms/page-loader.js index b55baad..b778e7b 100644 --- a/cms/static/js/qcms/page-loader.js +++ b/cms/static/js/qcms/page-loader.js @@ -31,8 +31,15 @@ qcms.page.Observer = function (_parentId,_domId,_uri){ http.post(`${qcms.context}/page`,function(x){ var _dom = $(x.responseText) - $(_id).append (_dom) - _finalize(_id) + var _found = qcms.html.hasNode( $(_id), $(_dom)) + + if (_found == 0){ + + + $(_id).append (_dom) + _finalize(_id) + + } _caller.notify() }) diff --git a/cms/static/js/qcms/qcms.js b/cms/static/js/qcms/qcms.js index 1f0a3b0..da68da1 100644 --- a/cms/static/js/qcms/qcms.js +++ b/cms/static/js/qcms/qcms.js @@ -3,42 +3,21 @@ if (!qcms){ } qcms.html = {} -qcms.html.Common = function (){ - this._format = function (text){ - return text.replace(/(-|_)/g,' ').trim() +qcms.html.hasNode = function (_parent,_child){ + var _found = 0 + if ($(_child).length == 0){ + return 0 } - this._open = function (text,uri,_parentId){ - var _domId = text.replace(/ /g,'-') - 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}`) - // - // we should finalize the scripts - - }) - - - }) - } - this._finalize = function (_id){ - var _script = $(`${_id} script`) - - if (_script.lenth > 0){ - _script.each( (_index)=>{ - var _code = $(_script)[_index].text - eval(_code) - }) + $(_parent).each((_index)=>{ + var _node = $(_parent)[_index] + + if ( $(_node)[0].innerHTML == $(_child)[0].outerHTML){ + _found = 1 } - } -} \ No newline at end of file + + }) + + return _found + +} + diff --git a/cms/templates/menu.html b/cms/templates/menu.html index 6fe5964..4a16155 100644 --- a/cms/templates/menu.html +++ b/cms/templates/menu.html @@ -5,10 +5,12 @@ {% else %} {% set _backURI = system.parentContext%} {% endif %} -
-
- - +
+
+
+ + +
{% else %}