add screensnew and tpldatanew
This commit is contained in:
		| @@ -18,12 +18,17 @@ const Wwws = {}; | ||||
| Wwws.getwco = (wconame, ctx) => { | ||||
|   /** | ||||
|    * In a webpage to add a wco | ||||
|    * <script src="/api/adminapi/wwws/getwco/wco.js?wcotribe=adminapi&tribe=adminapi&xapp=admin&pagename=apxid&code=enjoy"></script> | ||||
|    *  This will update /tribe/objects/wwws/itm/xapp.json | ||||
|    *  A wco has a /adminapi/objects/wco/itm/wconame.json  | ||||
|    *  | ||||
|    *  | ||||
|    *  | ||||
|    * <script src="/api/adminapi/wwws/getwco/wco.js?wcotribe=adminapi&tribe=adminapi&xapp=admin&pagename=apxid&code=enjoy&tagid=id"></script> | ||||
|    * <div id="tagid"  add tag here to customize if needded></div> | ||||
|    * | ||||
|    *  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 <div id="ctx.tagid"> | ||||
|    * 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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user