+
+ Learner who needs to develop their ability to communicate effectively at work, both in writing and speaking + |
+
+
+ Learner who needs to develop their ability to communicate effectively at work, both in writing and speaking + |
+
PACK JOB SEARCH
",,english,2,0,,2,0,classroom,,,0000-00-00,0000-00-00,https://www.yesnyoulearning.com/lms/index.php?r=player&course_id=32934,1108,,,0, +32935,BK_F2F_B_JOB_10x1H-02,"My Job Search Workshop Session N°2 - 1H","PACK JOB SEARCH
",,english,2,0,,2,0,classroom,,,0000-00-00,0000-00-00,https://www.yesnyoulearning.com/lms/index.php?r=player&course_id=32935,1108,,,0,`; +//utils.analysestring(txtstring) +//console.log(utils.replacecarbtweendblquote(txtstring, ",", 'CARSEPARATOR') +// .split("\n")[0].split(",")) +utils.csv2json = (csv, options, callback) => { + // EN CAS DE PB AVEC UN FICHIER EXCEL RECALCITRANT + // l'ouvrir dans calc linux et sauvegarder csv utf8, ; , " enregistrer le contenu de la cellule comme affiché + console.log("\n--------------- CSV2JSON ---------------\n"); + // Default CSV options + if (!options.retln) options.retln = "\n"; + if (csv.indexOf("\n\r") > -1) options.retln = "\n\r"; + if (!options.sep) options.sep = ";"; + //gestion d un separateur dans une chaine de texte + //const regseptext = new RegExp(`${options.sep}(?!(?:[^"]*"[^"]*")*[^"]*$)`, 'gm'); + //csv = csv.replace(regseptext, "CARACSEPAR"); + // csv = utils.replacecarbtweendblquote(csv, options.retln, "RETLIGNE") + csv = utils.replacecarbtweendblquote(csv, options.sep, "CARSEPARATOR"); + if (!options.replacespecialcarCsv2Json) { + options.replacespecialcarCsv2Json = []; + } else { + if (typeof options.replacespecialcarCsv2Json == "string") { + //permet de passer des regex en string + options.replacespecialcarCsv2Json = eval( + options.replacespecialcarCsv2Json + ); + } + } + const result = []; + const lines = csv.split(options.retln); + const headers = utils.getHeaders(lines, options.sep); + let unknownHeaders = ""; + //console.log('headers', headers) + //console.log('options.champs', options.champs) + headers.forEach((header) => { + // Si un header n'est pas présent dans la liste des champs prédéfinis + // on l'ajoute aux champs inconnus + if (options.champs.indexOf(header) === -1) { + unknownHeaders += `${header}, `; + } + }); + if (unknownHeaders !== "") { + const errorMsg = `CSV2JSON() - Champs inconnus : ${unknownHeaders}`; + return callback(errorMsg, null); + } + lines.forEach((line, index) => { + // Skip headers line or empty lines + if (index === 0 || line.replace(/\s/g, "").length === 0) { + return; + } + // pour debuguer on met origincsv pour voir la ligne d'origine + const currentLineData = { origincsv: line, linenumber: index }; + const currentLine = line.split(options.sep); // Current string in the line + for (let j = 0; j < headers.length; j++) { + // Si la ligne n'est pas vide + if (currentLine[j]) { + // On clean le champs + // ajout eventuel de modification de caracter reservé ; dans les libelléetc... + let currentValue = currentLine[j].trim(); + //on transforme le caractere separateur modifié entre double quote + currentValue = currentValue.replace("CARSEPARATOR", options.sep); + options.replacespecialcarCsv2Json.forEach((re) => { + currentValue = currentValue.replace(re[0], re[1]); + }); + // Si le header est un email + if (headers[j].includes("EMAIL")) { + // Supprimer tous les espaces + currentValue = currentLine[j].replace(/\s/g, ""); + } + // on check si le chamos doit être numerique + if (options.numericfield.includes(headers[j])) { + currentValue = currentLine[j].replace(/\,/g, "."); + try { + const test = parseFloat(currentValue); + } catch (er) { + return callback( + `${headers[j]} contiens la valeur -${currentValue}- et devrait être numerique`, + null + ); + } + } + if (currentValue) { + // Si le header actuel est de type array + // Cela signifie que le header apparaît plusieurs fois dans le CSV + // et que les valeurs correspondantes à ce header + // doivent être mis dans un array + if (options.array && options.array.indexOf(headers[j]) > -1) { + // Si le tableau pour ce header n'existe pas on le crée + if (!currentLineData[headers[j]]) { + currentLineData[headers[j]] = []; + } + if (options.arraysplitsep) { + currentValue.split(options.arraysplitsep).forEach((v) => { + currentLineData[headers[j]].push(v); + }); + } else { + currentLineData[headers[j]].push(currentValue); + } + } else { + // Si un header est déjà présent pour la ligne + // alors que il n'est pas spécifié comme étant un array + // on retourne une erreur + if (currentLineData[headers[j]]) { + const errorMsg = `Le champ ${headers[j]} est présent plusieurs fois alors qu'il n'est pas spécifié comme étant un array !`; + return callback(errorMsg, null); + } + currentLineData[headers[j]] = currentValue; + } + } + } + } + result.push(currentLineData); + }); + return callback(null, result); +}; +/** + * [csvparam2json description] + * @param {object} csv object of csv file that has been read + * @param {object} options object containing csv options, headers, ... + {retln:'code de retour de ligne \n ou \n\r', + sep:'code to split cells', + champs:[ch1,ch2,...] catch only those field, + array:[ch1, ] can have more than one field champs with same name then data are push into an array } + * @param {Function} callback callback function + * @return {callback} - return an error if error, else return json + it converts a csv with 3 column col1;col2;col3 in a json in a tree + if in col1 we have __ => then it splits a leaf + col1 = xxxx__yyyy ; col2 = value ; col3 = comment that is ignored + return data = {xxxx:{yyyy:value}} + col1 = xxxx; col2 = value; col3 = comment ignored +return data = {xxxx:value} + +Usage example: +fiche.csvparam2article = (err, fiche) => { + if (!err) { + console.log(fiche) + } +} +utils.csvparam2json(fs.readFileSync('./devdata/tribee/aubergenville/infoexterne/localbusiness.csv', 'utf-8'), { + retln: "\n", + sep: ";", + champs: ["NOM", "OBJET", "ADRESSE_PRO", "CP_PRO", "VILLE_PRO", "ZONE", "PHONE_PRO", "HORAIRESDESC", "HORAIREDATA", "URL", "FACEBOOK", "INSTA", "EMAIL_PRO", "IMG", "TAG"], + array: ["TAG", "PHONE_PRO", "EMAIL_PRO"] +}, fiche.csv2article) + + */ +utils.csvparam2json = (csv, options, callback) => { + console.log("\n--------------- CSVPARAM2JSON ---------------\n"); + let etat = ""; + const param = {}; + if (!options.retln) { + options.retln = "\n"; + } + if (csv.indexOf("\n\r") > -1) { + options.retln = "\n\r"; + } + if (!options.sep) { + options.sep = ";"; + } + if (!options.seplevel) { + options.seplevel = "__"; + } + if (!options.replacespecialcarCsv2Json) { + options.replacespecialcarCsv2Json = []; + } else { + if (typeof options.replacespecialcarCsv2Json == "string") { + //permet de passer des regex en string + options.replacespecialcarCsv2Json = eval( + options.replacespecialcarCsv2Json + ); + } + } + const lines = csv.split(options.retln); + for (let i = 0; i < lines.length; i++) { + const infol = lines[i].split(options.sep); + //console.log(infol) + if (infol[0].length > 4 && infol.length < 2) { + // si le 1er element à plus de 4 caractere et s'il y a moins de 3 colonnes c'est qu'il y a un pb + etat += `Erreur sur ${lines[i]} moins de 3 column separé par ${options.sep}`; + continue; + } + // On ajoute ici la gestion de tous les caracteres spéciaux + // reservées pour le csv ; ' etc..' + if (infol[1] && infol[1] + "" == infol[1]) { + options.replacespecialcarCsv2Json.forEach((re) => { + //console.log("gggggggggggggggggggg", infol[1]) + infol[1] = infol[1].replace(re[0], re[1]); + }); + // console.log(infol[1]) + infol[1] = infol[1].replace(/'|’/g, '"'); + //console.log(infol[1]) + if (infol[1].toLowerCase() === "true") { + infol[1] = true; + } else if (infol[1].toLowerCase() === "false") { + infol[1] = false; + } + } + console.log(infol[1]); + //supprime des lignes vides + if (infol[0] == "") continue; + if (infol[0].indexOf(options.seplevel) == -1) { + param[infol[0]] = infol[1]; + continue; + } else { + const arbre = infol[0].split(options.seplevel); + switch (arbre.length) { + case 1: + param[arbre[0]] = infol[1]; + break; + case 2: + if (arbre[1] != "ARRAY") { + if (!param[arbre[0]]) param[arbre[0]] = {}; + param[arbre[0]][arbre[1]] = infol[1]; + } else { + if (!param[arbre[0]]) param[arbre[0]] = []; + //console.log('aff', infol[1].substring(1, infol[1].length - 1).replace(/""/g, '"')) + eval("result=" + infol[1]); + //.substring(1, infol[1].length - 1).replace(/""/g, '"')) + param[arbre[0]].push(result); + } + break; + case 3: + if (arbre[2] != "ARRAY") { + if (!param[arbre[0]]) param[arbre[0]] = {}; + if (!param[arbre[0]][arbre[1]]) param[arbre[0]][arbre[1]] = {}; + param[arbre[0]][arbre[1]][arbre[2]] = infol[1]; + } else { + if (!param[arbre[0]]) param[arbre[0]] = {}; + if (!param[arbre[0]][arbre[1]]) param[arbre[0]][arbre[1]] = []; + //eval("result = \"test\""); + //console.log(result); + eval("result=" + infol[1]); + //.substring(1, infol[1].length - 1).replace(/""/g, '"')) + param[arbre[0]][arbre[1]].push(result); + } + break; + case 4: + if (arbre[3] != "ARRAY") { + if (!param[arbre[0]]) param[arbre[0]] = {}; + if (!param[arbre[0]][arbre[1]]) param[arbre[0]][arbre[1]] = {}; + if (!param[arbre[0]][arbre[1]][arbre[2]]) + param[arbre[0]][arbre[1]][arbre[2]] = {}; + param[arbre[0]][arbre[1]][arbre[2]][arbre[3]] = infol[1]; + } else { + if (!param[arbre[0]]) param[arbre[0]] = {}; + if (!param[arbre[0]][arbre[1]]) param[arbre[0]][arbre[1]] = {}; + if (!param[arbre[0]][arbre[1]][arbre[2]]) + param[arbre[0]][arbre[1]][arbre[2]] = []; + eval("result=" + infol[1]); + //.substring(1, infol[1].length - 1).replace(/""/g, '"')) + param[arbre[0]][arbre[1]][arbre[2]].push(result); + break; + } + default: + break; + } + } + } + // JSON.parse(JSON.stringify(param)) + console.log( + "kkkkkkkkkkkkkkkkkk", + param["catalogue"]["filtrecatalog"]["searchengine"] + ); + if (etat == "") { + return callback(null, JSON.parse(JSON.stringify(param))); + } else { + return callback(etat, null); + } +}; +utils.levenshtein = (a, b) => { + if (a.length === 0) return b.length; + if (b.length === 0) return a.length; + let tmp, i, j, prev, val, row; + // swap to save some memory O(min(a,b)) instead of O(a) + if (a.length > b.length) { + tmp = a; + a = b; + b = tmp; + } + row = Array(a.length + 1); + // init the row + for (i = 0; i <= a.length; i++) { + row[i] = i; + } + // fill in the rest + for (i = 1; i <= b.length; i++) { + prev = i; + for (j = 1; j <= a.length; j++) { + if (b[i - 1] === a[j - 1]) { + val = row[j - 1]; // match + } else { + val = Math.min( + row[j - 1] + 1, // substitution + Math.min( + prev + 1, // insertion + row[j] + 1 + ) + ); // deletion + } + row[j - 1] = prev; + prev = val; + } + row[a.length] = prev; + } + return row[a.length]; +}; +utils.testinarray = (array, arrayreferent) => { + // au moins un element de array existe dans arryreferent + let exist = false; + if (arrayreferent) { + //console.log('arrrrrrrrrrrrrrr', arrayreferent) + array.forEach((e) => { + //console.log(e) + if (arrayreferent.includes(e)) exist = true; + }); + } + return exist; +}; +/* +DIRECTORY +*/ +const isDirectory = (source) => fs.lstatSync(source).isDirectory(); +const getDirectories = (source) => + fs + .readdirSync(source) + .map((name) => path.join(source, name)) + .filter(isDirectory); + +module.exports = utils; diff --git a/app/models/Towns.js b/app/models/Towns.js new file mode 100644 index 0000000..c82657f --- /dev/null +++ b/app/models/Towns.js @@ -0,0 +1,13 @@ +const bcrypt = require( 'bcrypt' ); +const fs = require( 'fs-extra' ); +const glob = require( 'glob' ); +const moment = require( 'moment' ); +const jwt = require( 'jwt-simple' ); +const UUID = require( 'uuid' ); +const config = require( '../tribes/townconf.js' ); +const Checkjson = require( `./Checkjson.js`); + +const Towns = {}; + + +module.exports= Towns; \ No newline at end of file diff --git a/models/Tribes.js b/app/models/Tribes.js similarity index 99% rename from models/Tribes.js rename to app/models/Tribes.js index b420aec..fe94505 100755 --- a/models/Tribes.js +++ b/app/models/Tribes.js @@ -9,11 +9,10 @@ const dnsSync = require( 'dns-sync' ); const jwt = require( 'jwt-simple' ); const moment = require( 'moment' ); const UUID = require( 'uuid' ); -const Outputs = require( './Outputs.js' ); const Pagans = require( './Pagans.js' ); const config = require( '../tribes/townconf' ); -const checkdata = require( `../nationchains/socialworld/contracts/checkdata.js`); +const Checkjson = require( `./Checkjson.js`); /* tribeid manager diff --git a/models/UploadFiles.js b/app/models/UploadFiles.js similarity index 100% rename from models/UploadFiles.js rename to app/models/UploadFiles.js diff --git a/nationchains/socialworld/contracts/lg/checkdata_en.json b/app/models/lg/Checkjson_en.json similarity index 88% rename from nationchains/socialworld/contracts/lg/checkdata_en.json rename to app/models/lg/Checkjson_en.json index 119f72b..9b74f1b 100644 --- a/nationchains/socialworld/contracts/lg/checkdata_en.json +++ b/app/models/lg/Checkjson_en.json @@ -1,5 +1,5 @@ { - "typedoesnnotexistinschema":"This type in your propertie is not manage by checkdata.js", + "typedoesnnotexistinschema":"This type in your propertie is not manage by Checkjson.js", "dataerrpropertie":"Check your data that not fit your schema rules propertie", "dataerrpropertiesrequired":"This propertie is required and not present in your data" } \ No newline at end of file diff --git a/app/models/lg/Odmdb_en.json b/app/models/lg/Odmdb_en.json new file mode 100644 index 0000000..8576485 --- /dev/null +++ b/app/models/lg/Odmdb_en.json @@ -0,0 +1,4 @@ +{ + "schemanotfound":"Schema not found in {{fullpath}}", + "pathnamedoesnotexist":"ObjectPath or objectName does not exist {{fullpath}}" +} \ No newline at end of file diff --git a/nationchains/socialworld/contracts/unittest/checkdata.js b/app/models/unittest/Checkjson.js similarity index 87% rename from nationchains/socialworld/contracts/unittest/checkdata.js rename to app/models/unittest/Checkjson.js index 21920b8..64a962e 100644 --- a/nationchains/socialworld/contracts/unittest/checkdata.js +++ b/app/models/unittest/Checkjson.js @@ -2,21 +2,27 @@ Unit testing */ const assert = require("assert"); -const checkdata = require("../checkdata.js"); +const Checkjson = require("../Checkjson.js"); -const ut = { name: "checkdata" }; +const ut = { name: "Checkjson" }; const schema = { $schema: "http://json-schema.org/schema#", - title: "Dummy schema to test checkdata.js", - description: "Checkdata is use on server as well as into a browser", + title: "Dummy schema to test Checkjson.js", + description: "Checkjson is use on server as well as into a browser", $comment: "We change schema type on the fly to simplify the test", - type: "Object", + type: "object", properties: { totest: {}, }, }; const testproperties = [ + { + name: "test0", + data: { totest: true }, + properties: { totest: { type: "boolean" } }, + status: 200 + }, { name: "test1", data: { totest: "blabla" }, @@ -126,7 +132,7 @@ ut.testproperties = (options) => { let msg = ""; testproperties.forEach((t) => { schema.properties = t.properties; - const res = checkdata.schema.data(schema, {}, t.data); + const res = Checkjson.schema.data(schema, t.data); if (res.status != t.status) { msg = (msg == "") ? "Unconsistent testproperties() name list: " : `${msg},`; if (options.verbose) { @@ -140,7 +146,7 @@ ut.testproperties = (options) => { }; ut.run = (options) => { - console.log("Test checkdata properties"); + console.log("Test Checkjson properties"); ut.testproperties(options); }; module.exports = ut; diff --git a/app/models/unittest/Odmdb.js b/app/models/unittest/Odmdb.js new file mode 100644 index 0000000..1015e42 --- /dev/null +++ b/app/models/unittest/Odmdb.js @@ -0,0 +1,72 @@ +/* +Unit testing +*/ +const assert = require("assert"); +const fs=require('fs-extra'); +const path= require('path'); +const Odmdb = require("../Odmdb.js"); +const {generemdp} = require('../../nationchains/socialworld/contracts/toolsbox.js'); + +const ut = { name: "Odmdb" }; +/* +We test only search and indexation here +Create Update Read and Delete are unit testing with specificities of each Object. + +To do that we create in tmp a dummy data folder for a dummy schema object +*/ +const schema = { + $schema: "http://json-schema.org/schema#", + title: "Dummy schema to test Checkjson.js", + description: "Checkjson is use on server as well as into a browser", + $comment: "We change schema type on the fly to simplify the test", + type: "object", + properties: { + uuid: { + type:"string", + format:"uuid", + default:"=uuid.v4()" + }, + dtcreate:{ + type:"string", + format:"datetime", + default:"=date.now()" + }, + tag:{ + type:"string", + enum:["t1","t2","t3"], + default:"t1" + }, + info:{ + type:"string", + minLength: 10, + default:"=generemdp(255,'ABCDEFGHIJKLM 12340')" + } + }, + required:["uuid"], + apxprimarykey:"uuid", + apxuniquekey:["info"], + apxsearchindex:{ + "uuid":{"list":[],"taginfo":['tag','info'],"all":""}, + "info":{"uuid":['uuid']} + } + }; + + const obj={tag:"t1",info:"Lorem ipsum A"} + +ut.createanobject=(schema,obj)=>{ + + const res={status:200,err:[]} + return res +} + +ut.run = (options) => { + const objectPath=path.resolve(__dirname,'../../tmp/testobjects'); + const schemaPath=path.resolve(__dirname,'../../tmp/testschema'); + if (!fs.existsSync(objectPath)) fs.ensureDirSync(objectPath); + if (!fs.existsSync(schemaPath)) fs.ensureDirSync(schemaPath); + const createenvobj=Odmdb.setObject(schemaPath,objectPath,"objtest",schema,{},"en"); + assert.deepEqual(createenvobj,{status:200},JSON.stringify(createenvobj)); + const checkschema= Odmdb.schema(schemaPath,"objtest",true) + assert.deepEqual(checkschema.status,200,JSON.stringify(checkschema)) + }; +module.exports = ut; \ No newline at end of file diff --git a/routes/messages.js b/app/routes/messages.js similarity index 92% rename from routes/messages.js rename to app/routes/messages.js index 217cc8a..20438f9 100755 --- a/routes/messages.js +++ b/app/routes/messages.js @@ -30,7 +30,7 @@ router.put( '/:objectname/:uuid', checkHeaders, isAuthenticated, ( req, res ) => // if does not exist and accessright C then it create it with uuid // then if req.body.tplmessage => render email with data // No data management are done here, if need you can add plugin to create a workflow based object - // if need specific data check => req.body.callback={tribeidpugin,pluginname,function} will run pluginname.function(data) add data run specific stuf before saved the message object in /objectname/data.uuid_lg/json + // if need specific data Checkjson => req.body.callback={tribeidpugin,pluginname,function} will run pluginname.function(data) add data run specific stuf before saved the message object in /objectname/data.uuid_lg/json let result; console.log( "object", req.params.objectname ) if( req.params.objectname == 'notifications' ) { diff --git a/routes/nationchains.js b/app/routes/nationchains.js similarity index 100% rename from routes/nationchains.js rename to app/routes/nationchains.js diff --git a/app/routes/odmdb.js b/app/routes/odmdb.js new file mode 100644 index 0000000..f44ada2 --- /dev/null +++ b/app/routes/odmdb.js @@ -0,0 +1,78 @@ +const express = require( 'express' ); +const glob = require( 'glob' ); +const path = require( 'path' ); +// Classes +const Odmdb = require( '../models/Odmdb.js' ); +// Middlewares +const checkHeaders = require( '../middlewares/checkHeaders' ); +const isAuthenticated = require( '../middlewares/isAuthenticated' ); +const hasAccessrighton = require( '../middlewares/hasAccessrighton' ); +const router = express.Router(); + +router.get('/searchauth/:objectname/:question',checkHeaders,isAuthenticated,( req, res ) => { + /** + * + * + */ + console.log( 'route referentials get all language' + req.params.objectname + '-' + req.params.question ); + const getref = Referentials.getref( true, req.params.source, req.params.idref, req.session.header.xworkon, req.session.header.xlang ); + // Return any status the data if any erreur return empty object + res.jsonp( getref.payload.data ); +} ); +router.get('schema/:objectname', checkHeaders, isAuthenticated,(req,res)=>{ + /** + * @api {get} /odmdb/schema/:objectname + * @apiName GetSchema + * @apiGroup Odmdb + * + * @apiUse apxHeader + * + * @apiParam {String} objectname Mandatory if headers.xworkon == nationchains then into ./nationchains/ else into ./tribes/xworkon/ + * + * @apiError (404) {string} info a key word to understand not found schema + * @apiError (404) {string} ref an string to find referential to get description of info in xlang request + * @apiError (404) {object} [moreinfo} an object with element to render ref_lg.json[info] to understand error + * + * @apiSuccess (200) {object} data contains schema requested + * + */ + const fullpath = path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`); + if (fs.existsSync(fullpath)){ + res.status(200).json(data:fs.readJsonSync(fullpath)) + }else{ + res.status(404).json(info:"schemanotfound", ref:"odmdb", moreinfo:{fullpath}) + } +}) +router.put('schema/:objectname', checkHeaders, isAuthenticated,(req,res)=>{ + /** + * @api {put} /odmdb/schema/:objectname + * @apiName putSchema + * @apiGroup Odmdb + * + * @apiUse apxHeader + * + * @apiParam {String} objectname Mandatory if headers.xworkon == nationchains then into ./nationchains/ else into ./tribes/xworkon/ + * @apiBody {string} schemapath where to store schema .../schema + * @apiBody {string} objectpath where to store object ...objectname/index/config.json + * @apiBody {json} schema content + * @apiBody {json} schemalang content in lg + * @apiBody {string} lang define which schemalg is (2 letters) + * + * @apiError (404) {string} info a key word to understand not found schema + * @apiError (404) {string} ref an string to find referential to get description of info in xlang request + * @apiError (404) {object} [moreinfo} an object with element to render ref_lg.json[info] to understand error + * + * @apiSuccess (200) {object} data contains schema requested + * + */ + const fullpath = path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`); + const set=Odmdb.setObject(path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}`),) + + if (fs.existsSync(fullpath)){ + res.status(200).json(data:fs.readJsonSync(fullpath)) + }else{ + res.status(404).json(info:"schemanotfound", ref:"odmdb", moreinfo:{fullpath}) + } +}) + +module.exports = router; diff --git a/routes/outputs.js b/app/routes/outputs.js similarity index 100% rename from routes/outputs.js rename to app/routes/outputs.js diff --git a/routes/pagans.js b/app/routes/pagans.js similarity index 100% rename from routes/pagans.js rename to app/routes/pagans.js diff --git a/routes/referentials.js b/app/routes/referentials.js similarity index 100% rename from routes/referentials.js rename to app/routes/referentials.js diff --git a/routes/tags.js b/app/routes/tags.js similarity index 100% rename from routes/tags.js rename to app/routes/tags.js diff --git a/routes/tribes.js b/app/routes/tribes.js similarity index 100% rename from routes/tribes.js rename to app/routes/tribes.js diff --git a/routes/uploadFiles.js b/app/routes/uploadFiles.js similarity index 100% rename from routes/uploadFiles.js rename to app/routes/uploadFiles.js diff --git a/apxtrib.js b/apxtrib.js index a5491b3..2cadab4 100755 --- a/apxtrib.js +++ b/apxtrib.js @@ -16,18 +16,48 @@ if( !fs.existsSync( '/etc/nginx/nginx.conf' ) ) { console.log( '\x1b[31m Check documentation, nginx have to be installed on this server first, no /etc/nginx/nginx.conf available, install then rerun yarn command.' ); process.exit(); } -if( !fs.existsSync( './tribes/townconf.js' ) ) { - console.log( `\x1b[42m#########################################################################\x1b[0m\n\x1b[42mWellcome into apxtrib, init your town and first tribe by 'yarn setup'. \x1b[0m \n\x1b[42mThen 'yarn dev' or 'yarn startpm2'. Check README's project to learn more.\x1b[0m\n\x1b[42m#########################################################################\x1b[0m` ); +if( !fs.existsSync( './nationchains/tribes/index/conf.json' ) ) { + // this is a first installation of a dev or prod machine + const readline = require( 'readline' ); + const rl = readline.createInterface( { + input: process.stdin, + output: process.stdout + } ); + const townconf = fs.readJsonSync( './nationchains/www/setup/townconf.json') ; + townconf.sudoerUser=process.env.USER; + townconf.dirname=__dirname; + townconf.nginx.include.push(`${__dirname}/nationchains/**/nginx_*.conf`); + townconf.nginx.logs=`${__dirname}/nationchains/logs/nginx`; + townconf.nginx.website='setup'; + townconf.nginx.fswww='nationchains/';//for a local tribe nationchains/tribes/tribeid + townconf.nginx.tribeid="town" + console.log(townconf) + + rl.question( 'This is the first install from ./nationchains/www/setup/townconf.json used, this will change your nginx config (/etc/nginx.conf will be saved as /etc/nginxconf.saved) (Yes/no)?', function ( rep1 ) { + let quest = `This is a production install, please check that ${townconf.townName}.${townconf.nationName}.${townconf.dns} IP is well redirect to tour server`; + if( rep1 !== "Yes" ) process.exit( 0 ); + + //console.log(process.env) + // saved and change nginx conf + const mustache=require('Mustache'); + fs.moveSync("/etc/nginx/nginx.conf","/etc/nginx/nginxconf.saved"); + const tplnginxconf=fs.readFileSync("./nationchains/www/setup/nginx/nginx.conf.mustache","utf8"); + fs.outputFileSync("/etc/nginx/nginx.conftest",mustache.render(tplnginxconf, townconf),"utf8") + const tplnginxwww=fs.readFileSync("./nationchains/www/setup/nginx/modelwebsiteconf.mustache","utf8"); + fs.outputFileSync(`./${townconf.nginx.fswww}www/nginx_${townconf.nginx.website}.conf`,mustache.render(tplnginxwww, townconf),"utf8") + //restart nginx + //fs.outputJsonSync('./nationchains/tribes/index/conf.json',setupconf); + console.log( `\x1b[42m#########################################################################\x1b[0m\n\x1b[42mWellcome into apxtrib, init your town and first tribe by 'yarn setup'. \x1b[0m \n\x1b[42mThen 'yarn dev' or 'yarn startpm2' or 'yarn unittest'. Check README's project to learn more.\x1b[0m\n\x1b[42m#########################################################################\x1b[0m` ); process.exit(); } -// config.js exist in any case from Setup.checkinit(); -const config = require( './tribes/townconf.js' ); +const config = require( './nationchains/tribes/index/conf.json' ); // Tribes allow to get local apxtrib instance context // dataclient .tribeids [] .DOMs [] .routes (plugins {url:name route:path}) .appname {tribeid:[website]} -const dataclient = require( './models/Tribes' ) +const dataclient = require( './app/models/Tribes' ) .init(); console.log( 'allowed DOMs to access to this apxtrib server: ', dataclient.DOMs ) const app = express(); + Object.keys(config.appset).forEach(p=>{ app.set(p,config.appset[p]) }) diff --git a/setup/ASUPconfig.jsold b/asupsetup/ASUPconfig.jsold similarity index 100% rename from setup/ASUPconfig.jsold rename to asupsetup/ASUPconfig.jsold diff --git a/setup/apixtribe.crabdance.com.mustache b/asupsetup/apixtribe.crabdance.com.mustache similarity index 100% rename from setup/apixtribe.crabdance.com.mustache rename to asupsetup/apixtribe.crabdance.com.mustache diff --git a/setup/config.mustache b/asupsetup/config.mustache similarity index 100% rename from setup/config.mustache rename to asupsetup/config.mustache diff --git a/setup/configsetup.json b/asupsetup/configsetup.json similarity index 100% rename from setup/configsetup.json rename to asupsetup/configsetup.json diff --git a/setup/data/domain/apixpress/blockchains/blocks/0.json b/asupsetup/data/domain/apixpress/blockchains/blocks/0.json similarity index 100% rename from setup/data/domain/apixpress/blockchains/blocks/0.json rename to asupsetup/data/domain/apixpress/blockchains/blocks/0.json diff --git a/setup/data/domain/apixpress/blockchains/nodes/apixpress.ndda.fr b/asupsetup/data/domain/apixpress/blockchains/nodes/apixpress.ndda.fr similarity index 100% rename from setup/data/domain/apixpress/blockchains/nodes/apixpress.ndda.fr rename to asupsetup/data/domain/apixpress/blockchains/nodes/apixpress.ndda.fr diff --git a/setup/data/domain/apixpress/clientconf.mustache b/asupsetup/data/domain/apixpress/clientconf.mustache similarity index 100% rename from setup/data/domain/apixpress/clientconf.mustache rename to asupsetup/data/domain/apixpress/clientconf.mustache diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/OrdersAction.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/OrdersAction.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/OrdersAction.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/OrdersAction.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/OutputsAction.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/OutputsAction.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/OutputsAction.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/OutputsAction.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/UploadFilesAction.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/UploadFilesAction.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/UploadFilesAction.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/UploadFilesAction.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/UsersAction.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/UsersAction.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/UsersAction.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/UsersAction.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/gender.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/gender.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/gender.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/gender.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/missionpos.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/missionpos.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/missionpos.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/missionpos.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/profile.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/profile.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/profile.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/profile.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/data/role.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/data/role.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/data/role.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/data/role.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/json/catalogueCompanies.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/json/catalogueCompanies.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/json/catalogueCompanies.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/json/catalogueCompanies.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/json/importcsvCompanies.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/json/importcsvCompanies.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/json/importcsvCompanies.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/json/importcsvCompanies.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/json/menuAdmin.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/json/menuAdmin.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/json/menuAdmin.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/json/menuAdmin.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/json/menuUser.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/json/menuUser.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/json/menuUser.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/json/menuUser.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/json/referentialsetting.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/json/referentialsetting.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/json/referentialsetting.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/json/referentialsetting.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/json/testref.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/json/testref.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/json/testref.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/json/testref.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/json/usersetting.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/json/usersetting.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/json/usersetting.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/json/usersetting.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/action.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/action.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/action.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/action.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/basic.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/basic.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/basic.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/basic.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/basicnolang.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/basicnolang.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/basicnolang.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/basicnolang.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/cards.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/cards.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/cards.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/cards.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/chgpsw.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/chgpsw.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/chgpsw.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/chgpsw.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/companies.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/companies.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/companies.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/companies.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/item.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/item.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/item.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/item.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/userOperator.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/userOperator.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/userOperator.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/userOperator.json diff --git a/setup/data/domain/apixpress/referentials/dataManagement/object/users.json b/asupsetup/data/domain/apixpress/referentials/dataManagement/object/users.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagement/object/users.json rename to asupsetup/data/domain/apixpress/referentials/dataManagement/object/users.json diff --git a/setup/data/domain/apixpress/referentials/dataManagementBackup/object/users.json b/asupsetup/data/domain/apixpress/referentials/dataManagementBackup/object/users.json similarity index 100% rename from setup/data/domain/apixpress/referentials/dataManagementBackup/object/users.json rename to asupsetup/data/domain/apixpress/referentials/dataManagementBackup/object/users.json diff --git a/setup/data/domain/apixpress/referentials/fr/object/users.json b/asupsetup/data/domain/apixpress/referentials/fr/object/users.json similarity index 100% rename from setup/data/domain/apixpress/referentials/fr/object/users.json rename to asupsetup/data/domain/apixpress/referentials/fr/object/users.json diff --git a/setup/data/domain/apixpress/users/searchindex/emails.json b/asupsetup/data/domain/apixpress/users/searchindex/emails.json similarity index 100% rename from setup/data/domain/apixpress/users/searchindex/emails.json rename to asupsetup/data/domain/apixpress/users/searchindex/emails.json diff --git a/setup/data/domain/apixpress/users/searchindex/logins.json b/asupsetup/data/domain/apixpress/users/searchindex/logins.json similarity index 100% rename from setup/data/domain/apixpress/users/searchindex/logins.json rename to asupsetup/data/domain/apixpress/users/searchindex/logins.json diff --git a/setup/data/domain/apixpress/users/searchindex/uids.json b/asupsetup/data/domain/apixpress/users/searchindex/uids.json similarity index 100% rename from setup/data/domain/apixpress/users/searchindex/uids.json rename to asupsetup/data/domain/apixpress/users/searchindex/uids.json diff --git a/setup/data/domain/apixpress/www/app/webapp/app_index_fr.html b/asupsetup/data/domain/apixpress/www/app/webapp/app_index_fr.html similarity index 96% rename from setup/data/domain/apixpress/www/app/webapp/app_index_fr.html rename to asupsetup/data/domain/apixpress/www/app/webapp/app_index_fr.html index 8f8dcb1..2c1f05a 100755 --- a/setup/data/domain/apixpress/www/app/webapp/app_index_fr.html +++ b/asupsetup/data/domain/apixpress/www/app/webapp/app_index_fr.html @@ -45,4 +45,4 @@ -