- Aggiornati margini.
- Cataloghi: Export ed Import di una pagine ed i suoi elementi !
This commit is contained in:
@@ -32,7 +32,7 @@ GCM_API_KEY=""
|
||||
PROD=0
|
||||
PROJECT_DESCR_MAIN='__PROJECTS'
|
||||
SECRK=Askb38v23jjDFaoskBOWj92axXCQ
|
||||
TOKEN_LIFE=2h
|
||||
TOKEN_LIFE=1m
|
||||
REFRESH_TOKEN_LIFE=14d
|
||||
FTPSERVER_HOST=139.162.166.31
|
||||
FTPSERVER_PORT=21
|
||||
|
||||
@@ -26,10 +26,10 @@ PATH_SSL_CHAIN_PEM=chain.pem
|
||||
PROD=0
|
||||
PROJECT_DESCR_MAIN='__PROJECTS'
|
||||
SECRK=iUUb38v23jjDFaosWj92axkBOXCQ
|
||||
TOKEN_LIFE=2h
|
||||
TOKEN_LIFE=1m
|
||||
REFRESH_TOKEN_LIFE=14d
|
||||
AUTH_NEW_SITES=B234HDSAOJ734ndcsdKWNV
|
||||
DOMAINS=[{"hostname":"abitaregliiblei.it","port":"3021"},{"hostname":"riso.app","port":"3005"}]
|
||||
DOMAINS=[{"hostname":"riso.app","port":"3005"}]
|
||||
SCRIPTS_DIR=admin_scripts
|
||||
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}]
|
||||
MIAB_HOST=box.lamiaposta.org
|
||||
|
||||
BIN
public/upload/pages/home/gruppo_macro.png
Normal file
BIN
public/upload/pages/home/gruppo_macro.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 KiB |
BIN
public/upload/pages/undefined/gruppo_macro.png
Normal file
BIN
public/upload/pages/undefined/gruppo_macro.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 KiB |
@@ -235,6 +235,13 @@ const MyElemSchema = new Schema({
|
||||
}
|
||||
}
|
||||
],
|
||||
date_created: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
});
|
||||
|
||||
MyElemSchema.pre('save', async function (next) {
|
||||
|
||||
@@ -43,6 +43,7 @@ const IText = new Schema(
|
||||
contenuto: String,
|
||||
maxlength: Number,
|
||||
font: IFont,
|
||||
size: ISize,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -98,6 +99,7 @@ const IBarCode = new Schema(
|
||||
size: ISize,
|
||||
font: IFont,
|
||||
widthlines: Number,
|
||||
show_at_right: Boolean,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -116,6 +118,7 @@ const scheletroScheda = {
|
||||
numschede_perRiga: { type: Number },
|
||||
numschede_perCol: { type: Number },
|
||||
show_separatore: { type: Boolean },
|
||||
testo_right_attaccato: IText,
|
||||
testo_right: IText,
|
||||
testo_bottom: IText,
|
||||
barcode: IBarCode,
|
||||
|
||||
@@ -14,7 +14,7 @@ const Product = require('../models/product');
|
||||
const Inventariogm = require('../models/inventariogm');
|
||||
const Importamacro = require('../models/importamacro');
|
||||
const ImportaDescr = require('../models/importadescr');
|
||||
const ImportaIsbn = require('../models/importaIsbn');
|
||||
const ImportaIsbn = require('../models/importaisbn');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
const CatProd = require('../models/catprod');
|
||||
const Author = require('../models/author');
|
||||
|
||||
@@ -842,6 +842,7 @@ async function duplicatePage(pageId, newpath) {
|
||||
// modifiche ai campi se necessario, per esempio:
|
||||
path: newpath,
|
||||
title: newpath,
|
||||
active: true,
|
||||
date_updated: new Date()
|
||||
});
|
||||
|
||||
@@ -849,15 +850,14 @@ async function duplicatePage(pageId, newpath) {
|
||||
await newPage.save();
|
||||
|
||||
// Trova tutti gli elementi associati a Page da duplicare
|
||||
const elemsToDuplicate = await MyElem.find({ idPage: pageId });
|
||||
const elemsToDuplicate = await MyElem.find({ idPage: pageId }).lean();
|
||||
|
||||
// Duplica ogni elemento utilizzando il nuovo idPath
|
||||
const duplicates = elemsToDuplicate.map(elem => {
|
||||
const newElem = new MyElem({
|
||||
...elem.toObject(), // Copia le proprietà dell'elemento
|
||||
...elem, // 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
|
||||
idPage: newPage._id.toString() // Imposta il nuovo campo IdPage
|
||||
});
|
||||
return newElem;
|
||||
});
|
||||
@@ -873,7 +873,121 @@ async function duplicatePage(pageId, newpath) {
|
||||
}
|
||||
};
|
||||
|
||||
router.post('/duppage', async (req, res) => {
|
||||
async function exportPage(idapp, pageId) {
|
||||
try {
|
||||
|
||||
const myexp = {
|
||||
mypages: [],
|
||||
myelems: [],
|
||||
}
|
||||
|
||||
// Trova il record di Page da duplicare
|
||||
const pageToExp = await MyPage.find({ _id: pageId, idapp }).lean();
|
||||
if (!pageToExp) {
|
||||
console.error('Page not found.');
|
||||
return;
|
||||
}
|
||||
|
||||
myexp.mypages = [...pageToExp];
|
||||
|
||||
// Trova tutti gli elementi associati a Page da duplicare
|
||||
const elemsToExp = await MyElem.find({ idapp, idPage: pageId }).lean();
|
||||
|
||||
myexp.myelems = [...elemsToExp];
|
||||
|
||||
const jsonString = JSON.stringify(myexp);
|
||||
|
||||
if (jsonString) {
|
||||
console.log('Esportazione completata con successo.');
|
||||
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
} catch (error) {
|
||||
console.error('Errore durante l\'esportazione:', error);
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
async function upsertRecord(table, record, appId) {
|
||||
|
||||
const existingRecord = await table.findOne({ idapp: appId, _id: record._id }); // Assumendo che `record` ha un ID
|
||||
if (existingRecord) {
|
||||
const modif = await table.updateOne({ _id: record._id }, { $set: { ...record, idapp: appId } });
|
||||
wasModified = modif.nModified > 0;
|
||||
} else {
|
||||
const ris = await table.create({
|
||||
...record,
|
||||
idapp: appId,
|
||||
});
|
||||
wasModified = !!ris;
|
||||
}
|
||||
|
||||
return wasModified; // Torna il numero di record importati (1 in questo caso)
|
||||
}
|
||||
|
||||
async function importPage(req, idapp, jsonString) {
|
||||
try {
|
||||
// Parsing dei dati JSON
|
||||
const myexp = JSON.parse(jsonString);
|
||||
|
||||
// Assicurati che i dati siano ben strutturati
|
||||
if (!myexp) {
|
||||
console.error('Dati non validi per l\'importazione.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let totalImportedRecords = 0;
|
||||
|
||||
// Ciclo su ogni proprietà di myexp
|
||||
for (const key in myexp) {
|
||||
if (myexp.hasOwnProperty(key)) {
|
||||
const tableName = key;
|
||||
|
||||
// Verifica se la tabella esiste
|
||||
if (tableName) {
|
||||
const table = globalTables.getTableByTableName(tableName);
|
||||
|
||||
if (tableName === 'mypages') {
|
||||
if (User.isEditor(req.user.perm)) {
|
||||
for (const page of myexp.mypages) {
|
||||
totalImportedRecords += await upsertRecord(table, page, idapp) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (tableName === 'myelems') {
|
||||
if (User.isEditor(req.user.perm)) {
|
||||
for (const elem of myexp.myelems) {
|
||||
totalImportedRecords += await upsertRecord(table, elem, idapp) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (tableName === 'myusers') {
|
||||
if (User.isManager(req.user.perm)) {
|
||||
for (const user of myexp.myusers) {
|
||||
totalImportedRecords += await upsertRecord(table, user, idapp) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalImportedRecords) {
|
||||
console.log(`Importazione completata con successo. Totale record importati: ${totalImportedRecords}`);
|
||||
}
|
||||
|
||||
return { imported: totalImportedRecords };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Errore durante l\'importazione:', error);
|
||||
}
|
||||
}
|
||||
|
||||
router.post('/duppage', authenticate, async (req, res) => {
|
||||
const params = req.body;
|
||||
const idapp = req.body.idapp;
|
||||
const mypath = params.path;
|
||||
@@ -899,6 +1013,52 @@ router.post('/duppage', async (req, res) => {
|
||||
console.error('Error', e);
|
||||
}
|
||||
|
||||
});
|
||||
router.post('/exppage', authenticate, 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 resultJSon = await exportPage(idapp, ris._id);
|
||||
if (resultJSon) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, json: resultJSon });
|
||||
} 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.post('/imppage', authenticate, async (req, res) => {
|
||||
const params = req.body;
|
||||
const idapp = req.body.idapp;
|
||||
const jsonString = params.jsonString;
|
||||
|
||||
try {
|
||||
|
||||
const result = await importPage(req, idapp, jsonString);
|
||||
if (result) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, ris: result });
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, ris: '' });
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
router.patch('/setlang', authenticate, async (req, res) => {
|
||||
@@ -1403,7 +1563,7 @@ 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') {
|
||||
} else if (tablename === shared_consts.TAB_MYPAGES) {
|
||||
// Cancella tutti gli elementi di quella pagina
|
||||
MyElem.deleteAllFromThisPage(rec._id);
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ module.exports = {
|
||||
TAB_MYCIRCUITS: 'circuits',
|
||||
TAB_BOTS: 'bots',
|
||||
TAB_USERS: 'users',
|
||||
TAB_MYPAGES: 'mypages',
|
||||
|
||||
KEY_TO_CRYPTED: ['PWD_FROM'],
|
||||
SITES_KEY_TO_CRYPTED: ['email_pwd'],
|
||||
@@ -244,7 +245,7 @@ module.exports = {
|
||||
],
|
||||
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
TABLES_CREATEDBY: ['mygroups', 'circuits', 'attivitas'],
|
||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'bots', 'mygroups', 'circuits', 'attivitas'],
|
||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'bots', 'mygroups', 'circuits', 'attivitas', 'myelems', 'mypages'],
|
||||
|
||||
TABLES_FIELDS_DESCR_AND_CITY_AND_USER: ['myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user