tracker schema

This commit is contained in:
2025-02-20 19:40:15 +01:00
parent baef67ef98
commit 9b64d946cd
6 changed files with 214 additions and 38 deletions

View File

@@ -21,13 +21,13 @@ Wwws.getwco = (wconame, ctx) => {
* <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
* 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}
* 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]}`;

View File

@@ -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