- Catalogo: Aggiunta di Schede

This commit is contained in:
Surya Paolo
2024-10-31 23:22:46 +01:00
parent fa1a2a7cdb
commit 3bdab927b6
9 changed files with 275 additions and 15 deletions

View File

@@ -1,12 +1,12 @@
DATABASE=test_FreePlanet
DATABASE=test_PiuCheBuono
UDB=paofreeplanet
PDB=mypassword@1A
SEND_EMAIL=0
SEND_EMAIL_ORDERS=1
PORT=3000
appTelegram_TEST=["1","13"]
appTelegram=["1","13"]
appTelegram_DEVELOP=["13"]
appTelegram_TEST=["1","17"]
appTelegram=["1","17"]
appTelegram_DEVELOP=["17"]
DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=1
MONGODB_USER=admin
@@ -42,3 +42,6 @@ FTPSERVER_PWD=ftpmypwd@1A_
AUTH_NEW_SITES=123123123
SCRIPTS_DIR=admin_scripts
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}]
MIAB_HOST=box.lamiaposta.org
MIAB_ADMIN_EMAIL=admin@lamiaposta.org
MIAB_ADMIN_PASSWORD=passpao1pabox@1A

View File

@@ -4,6 +4,8 @@ const Schema = mongoose.Schema;
const tools = require('../tools/general');
const { ObjectID, ObjectId } = require('mongodb');
const { MySchedaSchema, scheletroScheda } = require('../models/myscheda');
mongoose.Promise = global.Promise;
mongoose.level = "F";
@@ -46,6 +48,7 @@ const elemText = new Schema(
}
);
const catalogo = new Schema(
{
//++AddCATALOGO_FIELDS
@@ -59,16 +62,28 @@ const catalogo = new Schema(
widthpag: { type: Number },
widthpagPrintable: { type: Number },
width: { type: String },
widthscheda: { type: String },
height: { type: String },
numschede_perRiga: { type: Number },
numschede_perCol: { type: Number },
margine_pagina: { type: String },
margine_riga: { type: String },
first_page_img: { type: String },
first_page_html: { type: String },
first_page_width: { type: Number },
first_page_height: { type: Number },
last_page_img: { type: String },
last_page_html: { type: String },
last_page_height: { type: Number },
last_page_width: { type: Number },
margine_paginaPrintable: { type: String },
margine_rigaPrintable: { type: String },
// formato: [{ type: String, default: '' }],
// categoria: [{ type: String, default: '' }],
// -------------------
arrSchede: [
{
scheda: scheletroScheda,
order: { type: Number },
numSchede: { type: Number },
}
],
}
);
@@ -79,6 +94,10 @@ const MyElemSchema = new Schema({
path: {
type: String,
},
oldpath: {
type: String,
},
idPage: { type: String },
type: {
type: Number,
},
@@ -237,6 +256,79 @@ MyElemSchema.statics.executeQueryTable = function (idapp, params, user) {
return tools.executeQueryTable(this, idapp, params, user);
};
MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
const MyElem = this;
const { MyPage } = require('../models/mypage');
// Sostituisci path con IdPage
try {
// Recupera tutti i documenti di MyPage
const pages = await MyPage.find({ idapp }); // Puoi anche specificare condizioni, se necessario
// Utilizza una mappa per accoppiare i path con i loro Id
const pathToIdMap = {};
pages.forEach(page => {
pathToIdMap[page.path] = page._id; // Mappa il path all'ID del documento MyPage
});
// Aggiorna MyElem utilizzando la mappa
for (const [path, id] of Object.entries(pathToIdMap)) {
await MyElem.updateMany(
{ path: path }, // Condizione per aggiornare dove il path corrisponde
{
$set: {
idPage: id,
oldpath: path,
},
$unset: { path: "" } // Rimuove il campo path
} // Imposta IdPage all'ID del documento corrispondente
);
}
if (false) {
// Utilizza una mappa per accoppiare i path con i loro Id
const pathToIdMap2 = {};
pages.forEach(page => {
pathToIdMap2[page.path] = page._id.toString(); // Mappa il path all'ID del documento MyPage
});
// Aggiorna MyElem utilizzando la mappa
for (const [path, id] of Object.entries(pathToIdMap2)) {
await MyElem.updateMany(
{ oldpath: path }, // Condizione per aggiornare dove il path corrisponde
{
$unset: { idPage: "" } // Rimuove il campo path
} // Imposta IdPage all'ID del documento corrispondente
);
}
for (const [oldpath, id] of Object.entries(pathToIdMap2)) {
await MyElem.updateMany(
{ oldpath: oldpath }, // Condizione per aggiornare dove il path corrisponde
{
$set: { idPage: id }
} // Imposta IdPage all'ID del documento corrispondente
);
}
}
console.log('Aggiornamenti effettuati con successo.');
return 'Aggiornamenti effettuati con successo.';
} catch (error) {
console.error('Errore durante l\'aggiornamento:', error);
return 'Errore durante l\'aggiornamento:', error;
}
};
MyElemSchema.statics.deleteAllFromThisPage = async function (id) {
const MyElem = this;
return MyElem.deleteMany({ idPage: id });
};
MyElemSchema.statics.findAllIdApp = async function (idapp) {
const MyElem = this;

View File

@@ -137,6 +137,13 @@ const MyPageSchema = new Schema({
sottoMenu: [{
type: String
}],
date_created: {
type: Date,
default: Date.now
},
date_updated: {
type: Date,
},
});
MyPageSchema.statics.getFieldsForSearch = function () {

71
src/server/models/myscheda.js Executable file
View File

@@ -0,0 +1,71 @@
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
const { ObjectID, ObjectId } = require('mongodb');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const scheletroScheda = {
idapp: {
type: String,
},
name: { type: String },
isTemplate: { type: Boolean },
widthpag: { type: Number },
width: { type: Number },
height: { type: Number },
widthscheda: { type: String },
numschede_perRiga: { type: Number },
numschede_perCol: { type: Number },
margine_top: { type: Number },
margine_pagina: { type: String },
margine_riga: { type: String },
text: { type: String },
posiz_text: { type: Number },
line_height: { type: Number },
productTypes: [{ type: Number }],
excludeproductTypes: [{ type: Number }],
editore: [{ type: String }],
author: { type: String },
sort: { type: Number },
arrProdottiSpeciali: [{ type: String }],
};
const MySchedaSchema = new Schema(
scheletroScheda
);
MySchedaSchema.statics.getFieldsForSearch = function () {
return [{ field: 'name', type: tools.FieldType.string }]
};
MySchedaSchema.statics.executeQueryTable = function (idapp, params, user) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params, user);
};
MySchedaSchema.statics.findAllIdApp = async function (idapp) {
const MyScheda = this;
const myfind = { idapp };
return await MyScheda.find(myfind);
};
const MyScheda = mongoose.model('MyScheda', MySchedaSchema);
MyScheda.createIndexes((err) => {
if (err) throw err;
});
module.exports = { MyScheda, MySchedaSchema, scheletroScheda };

View File

@@ -44,6 +44,7 @@ const { Contribtype } = require('../models/contribtype');
const { PaymentType } = require('../models/paymenttype');
const { Discipline } = require('../models/discipline');
const { MyElem } = require('../models/myelem');
const { MySCheda } = require('../models/myscheda');
const { Skill } = require('../models/skill');
const { Good } = require('../models/good');
const { StatusSkill } = require('../models/statusSkill');
@@ -826,6 +827,80 @@ router.post('/getpage', async (req, res) => {
});
async function duplicatePage(pageId) {
try {
// Trova il record di Page da duplicare
const pageToDuplicate = await MyPage.findById(pageId);
if (!pageToDuplicate) {
console.error('Page not found.');
return;
}
// Crea una copia del record di Page
const newPage = new MyPage({
...pageToDuplicate.toObject(), // Converte il documento Moongose in oggetto
_id: new mongoose.Types.ObjectId(), // Genera un nuovo ID
// modifiche ai campi se necessario, per esempio:
path: `${pageToDuplicate.path}-copia`, // Modifica il campo path per identificare la copia
title: `${pageToDuplicate.title}-copia`, // Modifica il campo path per identificare la copia
date_updated: new Date()
});
// Salva il nuovo record di Page
await newPage.save();
// Trova tutti gli elementi associati a Page da duplicare
const elemsToDuplicate = await MyElem.find({ idPage: pageId });
// Duplica ogni elemento utilizzando il nuovo idPath
const duplicates = elemsToDuplicate.map(elem => {
const newElem = new MyElem({
...elem.toObject(), // Copia le proprietà dell'elemento
_id: new mongoose.Types.ObjectId(), // Genera un nuovo ID
idPage: newPage._id // Imposta il nuovo campo IdPage
// Puoi modificare altri campi se necessario qui
});
return newElem;
});
// Salva tutti gli elementi duplicati
await MyElem.insertMany(duplicates);
console.log('Duplicazione completata con successo.');
return true;
} catch (error) {
console.error('Errore durante la duplicazione:', error);
return false;
}
};
router.post('/duppage', async (req, res) => {
const params = req.body;
const idapp = req.body.idapp;
const mypath = params.path;
try {
let found = await MyPage.findOne({ idapp, path: mypath })
.then(async (ris) => {
const result = await duplicatePage(ris._id);
if (result) {
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
} else {
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
}
}).catch((e) => {
console.log(e.message);
res.status(400).send(e);
});
} catch (e) {
console.error('Error', e);
}
});
router.patch('/setlang', authenticate, async (req, res) => {
const username = req.body.data.username;
const idapp = req.user.idapp;
@@ -1313,6 +1388,9 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
} else if (tablename === shared_consts.TAB_MYCIRCUITS) {
// Se è un gruppo, allora cancella anche tutti i suoi riferimenti
User.removeAllUsersFromMyCircuits(rec.idapp, rec.name);
} else if (tablename === 'mypage') {
// Cancella tutti gli elementi di quella pagina
MyElem.deleteAllFromThisPage(rec._id);
}
tools.refreshAllTablesInMem(rec.idapp, tablename, true, rec.username);

View File

@@ -16,6 +16,7 @@ const sendemail = require('../sendemail');
const { Settings } = require('../models/settings');
const { SendNotif } = require('../models/sendnotif');
const { MyElem } = require('../models/myelem');
const { MyBot } = require('../models/bot');
@@ -1463,6 +1464,9 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
} else if (mydata.dbop === 'listCollectionsBySize') {
mystr = await tools.listCollectionsBySize();
ris = { mystr };
} else if (mydata.dbop === 'MyElemSetIdPageInsteadThePah') {
mystr = await MyElem.SetIdPageInsteadThePah(idapp);
ris = { mystr };
} else if (mydata.dbop === 'AbilitaNewsletterALL') {
await User.updateMany({
$or: [

View File

@@ -106,6 +106,7 @@ myLoad().then(ris => {
require('./models/newstosent');
require('./models/mypage');
require('./models/myelem');
require('./models/myscheda');
require('./models/bot');
require('./models/calzoom');
const mysql_func = require('./mysql/mysql_func');
@@ -805,7 +806,7 @@ function startServer(app, port) {
const NOCORS = false;
const CORS_ENABLE_FOR_ALL_SITES = false;
const ISDEBUG = true;
const ISDEBUG = false;
let corsOptions = {};
@@ -842,7 +843,7 @@ function startServer(app, port) {
}
},*/
credentials: false,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
allowedHeaders: [
'Origin',
'X-Requested-With',
@@ -861,6 +862,7 @@ function startServer(app, port) {
// Applica CORS come primo middleware
app.use(cors(corsOptions));
// HO AGGIUNTO QUESTA RIGA PER IL CORS !!!!!!!
app.use(express.json()); // Middleware per il parsing del corpo JSON
// Gestione specifica delle richieste OPTIONS

View File

@@ -44,6 +44,7 @@ const Pickup = require('../models/pickup');
const { Newstosent } = require('../models/newstosent');
const { MyPage } = require('../models/mypage');
const { MyElem } = require('../models/myelem');
const { MyScheda } = require('../models/myscheda');
const { MyBot } = require('../models/bot');
const { CfgServer } = require('../models/cfgserver');
const { CalZoom } = require('../models/calzoom');
@@ -181,6 +182,8 @@ module.exports = {
mytable = MyPage;
else if (tablename === 'myelems')
mytable = MyElem;
else if (tablename === 'myschedas')
mytable = MyScheda;
else if (tablename === 'bots')
mytable = MyBot;
else if (tablename === 'cfgservers')

View File

@@ -1 +1 @@
1.1.6
1.1.7