- Editor Pagine Elementi: Sezione, Righe, Colonne, Elementi. (rows, columns, elems)
This commit is contained in:
@@ -4,6 +4,8 @@ const Schema = mongoose.Schema;
|
|||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
const { ObjectId } = require('mongodb');
|
const { ObjectId } = require('mongodb');
|
||||||
|
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
const { MySchedaSchema, IDimensioni, IImg, IText, IAreaDiStampa } = require('../models/myscheda');
|
const { MySchedaSchema, IDimensioni, IImg, IText, IAreaDiStampa } = require('../models/myscheda');
|
||||||
|
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
@@ -92,7 +94,7 @@ const catalogo = new Schema({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const MyElemSchema = new Schema({
|
const MySingleElemSchema = {
|
||||||
idapp: {
|
idapp: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -102,6 +104,9 @@ const MyElemSchema = new Schema({
|
|||||||
/*oldpath: {
|
/*oldpath: {
|
||||||
type: String,
|
type: String,
|
||||||
},*/
|
},*/
|
||||||
|
idElemParent: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
idPage: { type: String },
|
idPage: { type: String },
|
||||||
type: {
|
type: {
|
||||||
type: Number,
|
type: Number,
|
||||||
@@ -257,8 +262,26 @@ const MyElemSchema = new Schema({
|
|||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
};
|
||||||
|
|
||||||
children: { type: Array, default: undefined },
|
const MyElemSchema = new Schema({
|
||||||
|
...MySingleElemSchema,
|
||||||
|
// Aggiungi rows e columns
|
||||||
|
rows: {
|
||||||
|
type: [
|
||||||
|
{
|
||||||
|
...MySingleElemSchema,
|
||||||
|
columns: {
|
||||||
|
type: [
|
||||||
|
{
|
||||||
|
...MySingleElemSchema,
|
||||||
|
elems: [MySingleElemSchema],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
MyElemSchema.pre('save', async function (next) {
|
MyElemSchema.pre('save', async function (next) {
|
||||||
@@ -551,6 +574,24 @@ MyElemSchema.statics.getNewFreeNameTemplate = async function (idapp, idPageOrig,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MyElemSchema.statics.findParentElem = async function (idapp, idElemParent) {
|
||||||
|
try {
|
||||||
|
let myelemParent = null;
|
||||||
|
|
||||||
|
myelemParent = await this.findOne({
|
||||||
|
idapp,
|
||||||
|
rows: {
|
||||||
|
$elemMatch: { columns: { $elemMatch: { _id: idElemParent } } },
|
||||||
|
},
|
||||||
|
}).lean();
|
||||||
|
|
||||||
|
return myelemParent;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err', e);
|
||||||
|
throw e; // Propagate the error
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const MyElem = mongoose.model('MyElem', MyElemSchema);
|
const MyElem = mongoose.model('MyElem', MyElemSchema);
|
||||||
|
|
||||||
MyElem.createIndexes()
|
MyElem.createIndexes()
|
||||||
|
|||||||
@@ -314,6 +314,7 @@ router.get('/test1', authenticate_noerror, async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post('/settable', authenticate, async (req, res) => {
|
router.post('/settable', authenticate, async (req, res) => {
|
||||||
|
try {
|
||||||
const params = req.body;
|
const params = req.body;
|
||||||
const mytable = globalTables.getTableByTableName(params.table);
|
const mytable = globalTables.getTableByTableName(params.table);
|
||||||
|
|
||||||
@@ -331,7 +332,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
const fieldsvalue = { ALL: 1 };
|
const fieldsvalue = { ALL: 1 };
|
||||||
|
|
||||||
mydata.idapp = req.user.idapp;
|
mydata.idapp = req.user?.idapp;
|
||||||
const idapp = mydata.idapp;
|
const idapp = mydata.idapp;
|
||||||
|
|
||||||
if (req.user && req.user.username) {
|
if (req.user && req.user.username) {
|
||||||
@@ -340,7 +341,6 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let consentito = false;
|
let consentito = false;
|
||||||
|
|
||||||
try {
|
|
||||||
if (
|
if (
|
||||||
User.isAdmin(req.user.perm) ||
|
User.isAdmin(req.user.perm) ||
|
||||||
User.isManager(req.user.perm) ||
|
User.isManager(req.user.perm) ||
|
||||||
@@ -1214,6 +1214,58 @@ router.patch('/setlang', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function toObjId(id) {
|
||||||
|
try {
|
||||||
|
return Types.ObjectId.isValid(id) ? new Types.ObjectId(id) : id;
|
||||||
|
} catch {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateElemInsideColumn({ idapp, id, mydata }) {
|
||||||
|
const { fieldsvalue = {} } = mydata || {};
|
||||||
|
|
||||||
|
// 1) id della colonna parent (dove si trova l'elemento da aggiornare)
|
||||||
|
let idElemParent = null;
|
||||||
|
if (fieldsvalue && fieldsvalue.idElemParent) {
|
||||||
|
idElemParent = fieldsvalue.idElemParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) recupera il documento parent "top-level" (es. section) che contiene la colonna
|
||||||
|
const myelemParent = await MyElem.findParentElem(idapp, idElemParent);
|
||||||
|
if (!myelemParent) {
|
||||||
|
return { ok: false, msg: 'Parent non trovato' };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) costruisci il $set campo-per-campo
|
||||||
|
// path target: rows.$[].columns.$[col].elems.$[el].<campo>
|
||||||
|
const setOps = {};
|
||||||
|
for (const [key, value] of Object.entries(fieldsvalue)) {
|
||||||
|
if (key === '_id') continue; // non tocchiamo l'_id
|
||||||
|
setOps[`rows.$[].columns.$[col].elems.$[el].${key}`] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Se non c’è nulla da settare, esci pulito
|
||||||
|
if (Object.keys(setOps).length === 0) {
|
||||||
|
return { ok: true, msg: 'Nulla da aggiornare' };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4) esegui l’update
|
||||||
|
const filter = { _id: toObjId(myelemParent._id) };
|
||||||
|
const update = { $set: setOps };
|
||||||
|
const options = {
|
||||||
|
arrayFilters: [{ 'col._id': toObjId(idElemParent) }, { 'el._id': toObjId(id) }],
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await MyElem.updateOne(filter, update, options);
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: result?.matchedCount > 0,
|
||||||
|
modified: result?.modifiedCount || 0,
|
||||||
|
result,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
router.patch('/chval', authenticate, async (req, res) => {
|
router.patch('/chval', authenticate, async (req, res) => {
|
||||||
// const idapp = req.body.idapp;
|
// const idapp = req.body.idapp;
|
||||||
const id = req.body.data.id;
|
const id = req.body.data.id;
|
||||||
@@ -1328,6 +1380,20 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
fieldsvalue = { [`arrvariazioni.0.${chiave}`]: valore };
|
fieldsvalue = { [`arrvariazioni.0.${chiave}`]: valore };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mydata.table === 'myelems' && mydata.fieldsvalue.idElemParent) {
|
||||||
|
// se è un myelem, allora cerca l'id anche sugli elementi contenuti in elems, (sotto rows e columns)
|
||||||
|
// quindi devo aggiornare quell'elemento in elems
|
||||||
|
|
||||||
|
const risult = await updateElemInsideColumn({ idapp, id, mydata });
|
||||||
|
|
||||||
|
if (risult.ok) {
|
||||||
|
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||||
|
}
|
||||||
|
|
||||||
|
/*return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }, { new: true }).then(async (rec) => {
|
||||||
|
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||||
|
});*/
|
||||||
|
} else {
|
||||||
return await mytable
|
return await mytable
|
||||||
.findByIdAndUpdate(id, { $set: fieldsvalue }, { new: true })
|
.findByIdAndUpdate(id, { $set: fieldsvalue }, { new: true })
|
||||||
.then(async (rec) => {
|
.then(async (rec) => {
|
||||||
@@ -1484,6 +1550,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
tools.mylogserr('Error patch USER: ', e.message);
|
tools.mylogserr('Error patch USER: ', e.message);
|
||||||
res.status(400).send();
|
res.status(400).send();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
tools.mylogserr('Error chval: ', e.message);
|
tools.mylogserr('Error chval: ', e.message);
|
||||||
res.status(400).send();
|
res.status(400).send();
|
||||||
|
|||||||
@@ -1229,6 +1229,72 @@ module.exports = {
|
|||||||
SCONTI_APPLICA: {
|
SCONTI_APPLICA: {
|
||||||
NESSUNO: 0,
|
NESSUNO: 0,
|
||||||
A_TUTTI: 1,
|
A_TUTTI: 1,
|
||||||
}
|
},
|
||||||
|
|
||||||
|
ELEMTYPE: {
|
||||||
|
TITLE: 5,
|
||||||
|
MARGINI: 6,
|
||||||
|
CARD: 7,
|
||||||
|
IMGTITLE: 8,
|
||||||
|
IMGPOSTER: 9,
|
||||||
|
TEXT: 10,
|
||||||
|
HTML: 20,
|
||||||
|
IMAGE: 30,
|
||||||
|
IMAGEUPLOAD: 35,
|
||||||
|
SEPARATOR: 40,
|
||||||
|
VIDEO: 50,
|
||||||
|
PAGE: 55,
|
||||||
|
PAGEINTRO: 58,
|
||||||
|
CALENDAR: 70,
|
||||||
|
CAROUSEL_IDISCIPLINE: 80,
|
||||||
|
CAROUSEL_HOME: 85,
|
||||||
|
CHECK_EMAIL: 100,
|
||||||
|
CAROUSEL_IMGS: 110,
|
||||||
|
OPENSTREETMAP: 120,
|
||||||
|
MAINVIEW: 130,
|
||||||
|
CHECKAPPRUNNING: 135,
|
||||||
|
DASHBOARD: 140,
|
||||||
|
DASHGROUP: 145,
|
||||||
|
MOVEMENTS: 148,
|
||||||
|
CSENDRISTO: 150,
|
||||||
|
STATUSREG: 160,
|
||||||
|
CHECKIFISLOGGED: 170,
|
||||||
|
INFO_VERSION: 180,
|
||||||
|
BOTT_CONDIVIDI: 190,
|
||||||
|
BOTT_CHAT_TERRITORIALE: 192,
|
||||||
|
BUTTON: 195,
|
||||||
|
PRESENTAZIONE: 200,
|
||||||
|
MYACTIVITIES: 205,
|
||||||
|
NOTIFATTOP: 210,
|
||||||
|
CHART: 220,
|
||||||
|
CHECKNEWVERSION: 230,
|
||||||
|
CHECKTESTENV: 240,
|
||||||
|
BTN_REG: 250,
|
||||||
|
BTN_REG_BYBOT: 255,
|
||||||
|
REGISTRATION: 258,
|
||||||
|
BTN_LOGIN: 260,
|
||||||
|
FOOTER: 270,
|
||||||
|
PROFILETUTORIAL: 280,
|
||||||
|
VISUVIDEOPROMOANDPDF: 290,
|
||||||
|
ECOMMERCE: 300,
|
||||||
|
CATALOGO: 310,
|
||||||
|
RACCOLTA: 315,
|
||||||
|
TOOLSAI: 320,
|
||||||
|
CHATBOT: 325,
|
||||||
|
MAPPA: 350,
|
||||||
|
MAPPAUTENTI: 360,
|
||||||
|
MAPPACOMUNI: 370,
|
||||||
|
MAPPAGETCOORDINATE: 380,
|
||||||
|
EDITADDRESSBYCOORD: 390,
|
||||||
|
GRID_ORIZ: 400,
|
||||||
|
QRCODE: 410,
|
||||||
|
CATALOGLIST: 420,
|
||||||
|
SEARCHPRODUCT: 430,
|
||||||
|
RACCOLTE_CATALOGHI: 450,
|
||||||
|
STAT_PAGES: 460,
|
||||||
|
SECTION: 1000,
|
||||||
|
ROW: 1100,
|
||||||
|
COLUMN: 1200,
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user