Files
freeplanet_serverside/src/server/models/myelem.js

213 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-10-27 11:22:58 +02:00
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
2022-11-17 08:09:48 +01:00
const { ObjectID, ObjectId } = require('mongodb');
2022-10-27 11:22:58 +02:00
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const myCard = new Schema(
{
imagefile: String,
alt: String,
description: String,
style: String,
size: String,
color: String,
content: String,
colorsub: String,
}
)
const animation = new Schema(
{
name: String,
clduration: String,
cldelay: String,
timingtype: String,
}
);
const elemText = new Schema(
{
text: String,
color: String,
class: String,
size: String,
anim: animation,
}
);
2022-10-27 11:22:58 +02:00
const MyElemSchema = new Schema({
2022-11-10 19:33:23 +01:00
_id: {
2022-11-12 12:00:21 +01:00
type: ObjectId,
2022-11-17 08:09:48 +01:00
default: function () {
2022-11-12 12:00:21 +01:00
return new ObjectId();
2022-11-10 19:33:23 +01:00
},
},
2022-10-27 11:22:58 +02:00
idapp: {
type: String,
},
2022-11-10 19:33:23 +01:00
path: {
type: String,
},
2022-10-27 11:22:58 +02:00
type: {
2022-10-29 12:37:50 +02:00
type: Number,
2022-10-27 11:22:58 +02:00
},
2022-11-12 12:00:21 +01:00
img: {
2022-10-27 11:22:58 +02:00
type: String,
},
container: {
type: String,
},
2022-10-29 12:37:50 +02:00
container2: {
type: String,
},
container3: {
type: String,
},
container4: {
type: String,
},
2022-11-12 12:00:21 +01:00
align: {
type: Number,
},
2022-11-18 18:54:18 +01:00
vertalign: {
type: Number,
},
speed: {
type: Number,
},
2022-11-11 18:18:44 +01:00
parambool: {
type: Boolean,
},
2022-11-13 22:39:07 +01:00
span: {
type: Boolean,
},
2022-11-11 18:18:44 +01:00
parambool2: {
type: Boolean,
},
parambool3: {
type: Boolean,
},
2022-10-29 12:37:50 +02:00
number: {
type: String,
},
imgback: {
type: String,
},
ratio: {
type: String,
},
containerHtml: {
type: String,
},
2022-10-27 11:22:58 +02:00
size: {
type: String,
},
order: {
type: Number,
default: 0,
},
height: {
type: Number,
},
2022-10-29 12:37:50 +02:00
heightimg: {
2022-11-12 12:00:21 +01:00
type: String,
2022-10-29 12:37:50 +02:00
},
widthimg: {
2022-11-12 12:00:21 +01:00
type: String,
2022-10-29 12:37:50 +02:00
},
width: {
type: Number,
},
link: {
type: String,
},
2022-11-12 12:00:21 +01:00
fit: {
type: String,
},
2022-10-27 11:22:58 +02:00
onlyif_logged: {
type: Boolean,
},
color: {
type: String,
},
elemsText: [elemText],
anim: animation,
active: {
2022-10-27 11:22:58 +02:00
type: Boolean,
},
class: {
type: String,
},
2022-11-13 22:39:07 +01:00
class2: {
type: String,
},
2022-11-17 08:09:48 +01:00
class3: {
type: String,
},
2022-11-18 18:54:18 +01:00
class4: {
type: String,
},
2022-10-29 12:37:50 +02:00
styleadd: {
type: String,
},
2022-11-13 22:39:07 +01:00
image: {
type: String,
},
listcards: [myCard],
2022-10-29 12:37:50 +02:00
list: [
{
imagefile: {
type: String
},
order: {
type: Number
},
alt: {
type: String
},
description: {
type: String
}
}
],
2022-10-27 11:22:58 +02:00
});
2022-11-17 08:09:48 +01:00
MyElemSchema.pre('save', async function (next) {
2022-11-10 19:33:23 +01:00
if (this.isNew) {
this._id = new ObjectID();
}
next();
});
2022-10-27 11:22:58 +02:00
MyElemSchema.statics.getFieldsForSearch = function () {
return [{ field: 'title', type: tools.FieldType.string },
2022-11-17 08:09:48 +01:00
{ field: 'content', type: tools.FieldType.string }]
2022-10-27 11:22:58 +02:00
};
MyElemSchema.statics.executeQueryTable = function (idapp, params, user) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params, user);
};
MyElemSchema.statics.findAllIdApp = async function (idapp) {
const MyElem = this;
const myfind = { idapp };
2022-10-29 12:37:50 +02:00
return await MyElem.find(myfind).sort({ order: 1 });
2022-10-27 11:22:58 +02:00
};
const MyElem = mongoose.model('MyElem', MyElemSchema);
module.exports = { MyElem };