- 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 { ObjectId } = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { MySchedaSchema, IDimensioni, IImg, IText, IAreaDiStampa } = require('../models/myscheda');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
@@ -92,7 +94,7 @@ const catalogo = new Schema({
|
||||
],
|
||||
});
|
||||
|
||||
const MyElemSchema = new Schema({
|
||||
const MySingleElemSchema = {
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
@@ -102,6 +104,9 @@ const MyElemSchema = new Schema({
|
||||
/*oldpath: {
|
||||
type: String,
|
||||
},*/
|
||||
idElemParent: {
|
||||
type: String,
|
||||
},
|
||||
idPage: { type: String },
|
||||
type: {
|
||||
type: Number,
|
||||
@@ -257,8 +262,26 @@ const MyElemSchema = new Schema({
|
||||
date_updated: {
|
||||
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) {
|
||||
@@ -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);
|
||||
|
||||
MyElem.createIndexes()
|
||||
|
||||
Reference in New Issue
Block a user