From ff27e8a4ea3a4b045d00122bb036b26e7b692691 Mon Sep 17 00:00:00 2001 From: philc Date: Thu, 6 Feb 2025 00:02:44 +0100 Subject: [PATCH] add screensnew and tpldatanew --- apxtri/models/Wwws.js | 79 +++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/apxtri/models/Wwws.js b/apxtri/models/Wwws.js index c246caf..bceb3ce 100644 --- a/apxtri/models/Wwws.js +++ b/apxtri/models/Wwws.js @@ -18,12 +18,17 @@ const Wwws = {}; Wwws.getwco = (wconame, ctx) => { /** * In a webpage to add a wco - * - * This will update /tribe/objects/wwws/itm/xapp.json - * A wco has a /adminapi/objects/wco/itm/wconame.json - * - * - * + * + *
+ * + * The script request will update /tribe/objects/wwws/itm/xapp.json with + * tpl, schema, tpldata, ... + * A wco has a /adminapi/objects/wco/itm/wconame.json that contain tpl options, ref, schema, ... + * The dynamic content is store in
+ * so tpldata:{${tagid}_${wco.tpldatamodel.key}:"..."} + * When the script request is done, it checks if exist file in wwws/${app}/src/tpldata/${pagename}/${tagid}_${wco.tpldatamodel.key}_lg.json + * if not it create with the wco example tpldatamodel ${wco.tpldatamodel.key} + * Check also if exist in localdb.pagename.tpldata */ const filereq = `../${ctx.wcotribe}/objects/wco/${wconame}/${wconame}.js`; const wcoconf = `../${ctx.wcotribe}/objects/wco/itm/${wconame}.json`; @@ -63,20 +68,24 @@ Wwws.getwco = (wconame, ctx) => { }); } // check that tpldata exist for the wco, if not create them with template data example into the project - if (wcoinfo.tpldatamodel && Object.keys(wcoinfo.tpldatamodel).length > 0) { + if (ctx.tagid && wcoinfo.tpldatamodel && Object.keys(wcoinfo.tpldatamodel).length > 0) { Object.keys(wcoinfo.tpldatamodel).forEach((t) => { - const pathtpldata = `../${ctx.tribe}/objects/wwws/${ctx.xapp}/src/tpldata/${wconame}/${t}`; - if (!Object.keys(webpage.pages[ctx.pagename].tpldata).includes(t)) { - webpage.pages[ctx.pagename].tpldata[t] = pathtpldata; + const pathtpldata = `${ctx.tribe}/objects/wwws/${ctx.xapp}/src/tpldata/${ctx.pagename}/${ctx.tagid}_${t}`; + const localdbname=`${ctx.pagename}_${ctx.tagid}_${t}` + if (!Object.keys(webpage.pages[ctx.pagename].tpldata).includes(localdbname)) { + webpage.pages[ctx.pagename].tpldata[localdbname] = pathtpldata; } wcoinfo.lang.forEach((l) => { if ( - !fs.existsSync(`${pathtpldata}_${l}.json`) && + !fs.existsSync(`../${pathtpldata}_${l}.json`) && fs.existsSync(`../${wcoinfo.tpldatamodel[t]}_${l}.json`) ) { - fs.copySync( - `../${wcoinfo.tpldatamodel[t]}_${l}.json`, - `${pathtpldata}_${l}.json` + const tpldataexample=fs.readJSONSync(`../${wcoinfo.tpldatamodel[t]}_${l}.json`) + Object.keys(ctx).forEach(k=>{ + tpldataexample[k]=ctx[k] + }) + fs.outputJSONSync( + `../${pathtpldata}_${l}.json`,tpldataexample ); } }); @@ -96,7 +105,7 @@ Wwws.getwco = (wconame, ctx) => { [ wcoinfo.schema.forEach((s) => { s = s.replace("{{tribe}}", ctx.tribe); - if (webpage.pages[ctx.pagename].schema.includes(s)) { + if (!webpage.pages[ctx.pagename].schema.includes(s)) { webpage.pages[ctx.pagename].schema.push(s); } }), @@ -174,7 +183,7 @@ Wwws.build = (tribeId, webapp, srcdist, options) => { } if (!confwww.pages[pgname].languages.includes(lg)) confwww.pages[pgname].languages.push(lg); - + const pgtxt = fs.readFileSync(f, "utf8"); const pg = new JSDOM(pgtxt); const dc = pg.window.document; @@ -414,9 +423,11 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { options: {}, tpl: {}, tpldata: {}, + tdatanew, ref: {}, schema: {}, - screens:{} + screens:{}, + screensnew:{} }; localstorage.headers.xlang = lg; // A faire plus tard charger tous les referentiele et les data pour une page adminpage @@ -471,6 +482,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { } if (!loc.tpl) loc.tpl = {}; if (!loc.tpldata) loc.tpldata = {}; + if (!loc.tpldatanew) loc.tpldatanew = {}; // remove loc.components (this is now in tpldata and tpl) if (loc.components) { loc.components.forEach((c) => { @@ -512,6 +524,22 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { } }); } + if (loc.tpldatanew) { + Object.keys(loc.tpldatanew).forEach((r) => { + let src = `../${loc.tpldatanew[r]}`; + //console.log(path.resolve(src)) + if (!fs.existsSync(src)) { + src += `_${lg}.json`; + } + if (fs.existsSync(src)) { + localstorage.tpldatanew[r] = fs.readJSONSync(src); + } else { + localstorage.tpldatanew[ + r + ] = `Check your ${fileparam} for template in ${pagename} profil and ${r} in tpldatanew`; + } + }); + } if (!loc.screens) loc.screens={} if (loc.screens) { Object.keys(loc.screens).forEach((r) => { @@ -529,6 +557,23 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { } }); } + if (!loc.screensnew) loc.screensnew={} + if (loc.screensnew) { + Object.keys(loc.screensnew).forEach((r) => { + let src = `../${loc.screensnew[r]}`; + //console.log(path.resolve(src)) + if (!fs.existsSync(src)) { + src += `_${lg}.json`; + } + if (fs.existsSync(src)) { + localstorage.screensnew[r] = fs.readJSONSync(src); + } else { + localstorage.screensnew[ + r + ] = `Check your ${fileparam} for template in ${pagename} profil and ${r} in screensnew`; + } + }); + } if (loc.schema) { loc.schema.forEach((objpath) => { const name = path.basename(objpath);