diff --git a/.gitignore b/.gitignore index fed0d91..ca0a28c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,10 +18,6 @@ !objects/ !objects/options/ !objects/options/** -!objects/tpldata/ -!objects/tpldata/** -!objects/screens/ -!objects/screens/** !objects/tplstrings/ !objects/tplstrings/** diff --git a/apxtri/models/Wwws.js b/apxtri/models/Wwws.js index c2a07a3..88275c0 100644 --- a/apxtri/models/Wwws.js +++ b/apxtri/models/Wwws.js @@ -21,13 +21,13 @@ Wwws.getwco = (wconame, ctx) => { * *
* - * The script request will update /tribe/objects/wwws/itm/xapp.json with + * 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} + * 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`; @@ -47,15 +47,18 @@ Wwws.getwco = (wconame, ctx) => { const wcoinfo = fs.readJSONSync(wcoconf); const webpage = fs.readJSONSync(webconf); // check that webconf for tailwindcsscontent property exist for this wco request - const pathtocheckfortw=[`../adminapi/objects/wco/${wconame}/*.{html,js,mustache}`,`../${ctx.tribe}/objects/wwws/${ctx.xapp}/src/**/*.{html,js,mustache}`] - if (!webpage.tailwindcsscontent){ - webpage.tailwindcsscontent=[] + const pathtocheckfortw = [ + `../adminapi/objects/wco/${wconame}/*.{html,js,mustache}`, + `../${ctx.tribe}/objects/wwws/${ctx.xapp}/src/**/*.{html,js,mustache}`, + ]; + if (!webpage.tailwindcsscontent) { + webpage.tailwindcsscontent = []; } - pathtocheckfortw.forEach(tw=>{ - if (!webpage.tailwindcsscontent.includes(tw)){ - webpage.tailwindcsscontent.push(tw) + pathtocheckfortw.forEach((tw) => { + if (!webpage.tailwindcsscontent.includes(tw)) { + webpage.tailwindcsscontent.push(tw); } - }) + }); // check that all tpl for this compoent are well in pages tpl object if (wcoinfo.tpl && Object.keys(wcoinfo.tpl).length > 0) { Object.keys(wcoinfo.tpl).forEach((t) => { @@ -68,26 +71,60 @@ Wwws.getwco = (wconame, ctx) => { }); } // check that tpldata exist for the wco, if not create them with template data example into the project - if (ctx.tagid && wcoinfo.tpldatamodel && Object.keys(wcoinfo.tpldatamodel).length > 0) { + //console.log(wcoinfo,ctx) + if ( + !ctx.tagid && + wcoinfo.tpldatamodel && + Object.keys(wcoinfo.tpldatamodel).length > 0 + ) { + console.log( + `Warning: you add a wco that request tagid to initiate tpldata into your project, please add in wwws/getwco/${wcoinfo.wconame}.js?xx&tagid=id1,id2 where this wco is used` + ); + } + 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/${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) => { + //tagid can concern many id then tagid=idA,idB,idC + ctx.tagid = ctx.tagid.includes(",") ? ctx.tagid.split(",") : [ctx.tagid]; + ctx.tagid.forEach((tid) => { + const pathtpldata = `${ctx.tribe}/objects/wwws/${ctx.xapp}/src/tpldata/${ctx.pagename}/${tid}_${t}`; + console.log("pathtpldata:", pathtpldata); + const localdbname = `${ctx.pagename}_${tid}_${t}`; if ( - !fs.existsSync(`../${pathtpldata}_${l}.json`) && - fs.existsSync(`../${wcoinfo.tpldatamodel[t]}_${l}.json`) + !Object.keys(webpage.pages[ctx.pagename].tpldata).includes( + localdbname + ) ) { - const tpldataexample=fs.readJSONSync(`../${wcoinfo.tpldatamodel[t]}_${l}.json`) - Object.keys(ctx).forEach(k=>{ - tpldataexample[k]=ctx[k] - }) - fs.outputJSONSync( - `../${pathtpldata}_${l}.json`,tpldataexample - ); + webpage.pages[ctx.pagename].tpldata[localdbname] = pathtpldata; } + wcoinfo.lang.forEach((l) => { + if (!fs.existsSync(`../${wcoinfo.tpldatamodel[t]}_${l}.json`)) { + console.log( + `Warning, this file is suppose to exist ../${wcoinfo.tpldatamodel[t]}_${l}.json check lg or mispelling` + ); + } + if ( + !fs.existsSync(`../${pathtpldata}_${l}.json`) && + fs.existsSync(`../${wcoinfo.tpldatamodel[t]}_${l}.json`) + ) { + const tpldataexample = fs.readJSONSync( + `../${wcoinfo.tpldatamodel[t]}_${l}.json` + ); + Object.keys(ctx).forEach((k) => { + if (k == "tagid") { + tpldataexample[k] = tid; + } else { + tpldataexample[k] = ctx[k]; + } + }); + fs.outputJSONSync(`../${pathtpldata}_${l}.json`, tpldataexample, { + spaces: 2, + }); + } + }); }); }); } @@ -111,7 +148,7 @@ Wwws.getwco = (wconame, ctx) => { }), ]; // save the conf for update localdb when the web page request it - fs.outputJSONSync(webconf, webpage, {spaces:2}); + fs.outputJSONSync(webconf, webpage, { spaces: 2 }); return { status: 200, ref: "Wwws", @@ -122,6 +159,12 @@ Wwws.getwco = (wconame, ctx) => { Wwws.build = (tribeId, webapp, srcdist, options) => { console.log(`Building ${tribeId}/objects/wwws/${webapp}/${srcdist}`); + /* + mettre en cdn de la tribe /cdn/share/lib/nom du fichier + /adminapi/node_modules/axios/dist/axios.min.js ds /cdn/lib/axios/dist/axios.min.js + et dans html le build sera src="/cdn/lib/axios/dist/axios.min.js" + + */ const pathto = `../${tribeId}/objects/wwws`; let confwww; if (fs.existsSync(`${pathto}/itm/${webapp}.json`)) { @@ -183,7 +226,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; @@ -379,7 +422,12 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { const fileparam = `../${tribe}/objects/wwws/itm/${appname}.json`; //console.log(path.resolve(fileparam)); if (!fs.existsSync(fileparam)) { - return { status: 404, ref: "Wwws", msg: "appdoesnotexist", data: {} }; + return { + status: 404, + ref: "Wwws", + msg: "appdoesnotexist", + data: { fileparam }, + }; } const locals = fs.readJSONSync(fileparam); if (!locals.pages[pagename]) { @@ -423,11 +471,11 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { options: {}, tpl: {}, tpldata: {}, - tpldatanew:{}, + tpldatanew: {}, ref: {}, schema: {}, - screens:{}, - screensnew:{} + screens: {}, + screensnew: {}, }; localstorage.headers.xlang = lg; // A faire plus tard charger tous les referentiele et les data pour une page adminpage @@ -494,6 +542,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { } if (loc.tpl) { Object.keys(loc.tpl).forEach((r) => { + // possible to store an independant language mustache let src = `../${loc.tpl[r]}`; if (!fs.existsSync(src)) { src += `_${lg}.mustache`; @@ -540,7 +589,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { } }); } - if (!loc.screens) loc.screens={} + if (!loc.screens) loc.screens = {}; if (loc.screens) { Object.keys(loc.screens).forEach((r) => { let src = `../${loc.screens[r]}`; @@ -557,7 +606,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { } }); } - if (!loc.screensnew) loc.screensnew={} + if (!loc.screensnew) loc.screensnew = {}; if (loc.screensnew) { Object.keys(loc.screensnew).forEach((r) => { let src = `../${loc.screensnew[r]}`; diff --git a/apxtri/setup/setup.sh b/apxtri/setup/setup.sh index 871dccf..3c93876 100755 --- a/apxtri/setup/setup.sh +++ b/apxtri/setup/setup.sh @@ -24,7 +24,7 @@ # .setup.sh smatchit https://testwall-ants.ndda.fr https://gitea.ndda.fr/smatchit/smatchit tribe=$1 # name of the tribe to install -url=$2 # url to get the data from OR newtribe +url=$2 # url to get the data from OR "newtribe" value gitrepo=$3 # url to get apxtri code from a git repo (empty if must come from a backup or the url) codekey=$4 # code to access backend of the tribe in case it is not newtribe or adminapi tribe diff --git a/objects/options/dayofweek_en.json b/objects/options/dayofweek_en.json new file mode 100644 index 0000000..270669f --- /dev/null +++ b/objects/options/dayofweek_en.json @@ -0,0 +1,30 @@ +{ + "title": "Country Code", + "description": "Country Code and Info", + "commment": "Alpha-2 country code (ISO 3166-2:XX)", + "lastupdatedata": "", + "lst_idx": ["monday","tuesday","wednesday","thursday","friday","saturday","sunday"], + "itms": { + "monday": { + "title": "Monday" + }, + "tuesday": { + "title": "Tuesday" + }, + "wednesday": { + "title": "Wednesday" + }, + "thursday": { + "title": "Thursday" + }, + "friday": { + "title": "Friday" + }, + "saturday": { + "title": "Saturday" + }, + "sunday": { + "title": "Sunday" + } + } +} \ No newline at end of file diff --git a/objects/options/dayofweek_fr.json b/objects/options/dayofweek_fr.json new file mode 100644 index 0000000..7d11a08 --- /dev/null +++ b/objects/options/dayofweek_fr.json @@ -0,0 +1,30 @@ +{ + "title": "Country Code", + "description": "Country Code and Info", + "commment": "Alpha-2 country code (ISO 3166-2:XX)", + "lastupdatedata": "", + "lst_idx": ["monday","tuesday","wednesday","thursday","friday","saturday","sunday"], + "itms": { + "monday": { + "title": "Lundi" + }, + "tuesady": { + "title": "Mardi" + }, + "wednesday": { + "title": "Mercredi" + }, + "thursday": { + "title": "Jeudi" + }, + "friday": { + "title": "Vendredi" + }, + "saturday": { + "title": "Samedi" + }, + "sunday": { + "title": "Dimanche" + } + } +} \ No newline at end of file diff --git a/schema/devices.json b/schema/devices.json new file mode 100644 index 0000000..65ac7c6 --- /dev/null +++ b/schema/devices.json @@ -0,0 +1,71 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "adminapi/schema/wco", + "title": "web components", + "description": "A web component wco is a folder with list of mustache and one name.js that deal all the business logic", + "type": "object", + "properties": { + "wconame": { + "description": "Folder name into a tribeId/objects/wco/itm", + "title": "Web component reusable in web project based with tailwindcss", + "type": "string" + }, + "owner": { + "description": "owner that earn some fees", + "type": "string" + }, + "codehash": { + "description": "Code signature of alias publickey", + "type": "string" + }, + "thumbnail":{ + "title":"Thumbnail of the component", + "type":"string" + }, + "title":{ + "title":"Short description of the wco", + "type":"string" + }, + "description":{ + "title":"Long description in html of the component", + "type":"string" + }, + "tpl":{ + "description":"list of mustache template to manage components each file must ended by _xx.mustache where xx is the language of the template, so you can add translation easily", + "type":"array" + }, + "tpldata":{ + "description":"Example of tpldata that you have to add in your local to customize the wco ended by _xx.json where xx is the language of the template", + "type":"array" + } +}, +"required": [ +"wconame", +"owner", +"title" +], +"apxid": "wconame", +"apxuniquekey": [ +"wconame" +], +"apxidx": [ +{ + "name": "lst_wconame", + "type": "array", + "keyval": "wconame" +} +], +"apxaccessrights": { +"owner": { + "D": [], + "R": [], + "U": [] +}, +"mayor": { + "C": [] +}, +"person": { + "R": [] +} +} +} \ No newline at end of file