- inizio di modifiche all'editor di Pagine Web
This commit is contained in:
@@ -257,6 +257,8 @@ const MyElemSchema = new Schema({
|
|||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
children: { type: Array, default: undefined },
|
||||||
});
|
});
|
||||||
|
|
||||||
MyElemSchema.pre('save', async function (next) {
|
MyElemSchema.pre('save', async function (next) {
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ const MyPageSchema = new Schema({
|
|||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
sections: { type: Array },
|
||||||
});
|
});
|
||||||
|
|
||||||
MyPageSchema.statics.getFieldsForSearch = function () {
|
MyPageSchema.statics.getFieldsForSearch = function () {
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ const Author = require('../models/author');
|
|||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
const { MyPage } = require('../models/mypage');
|
||||||
|
const { MyElem } = require('../models/myelem');
|
||||||
|
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
router.post('/test-lungo', authenticate, (req, res) => {
|
router.post('/test-lungo', authenticate, (req, res) => {
|
||||||
@@ -195,19 +198,20 @@ router.delete('/mypage/:id', authenticate, async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Trova il record di MyPage da cancellare
|
// Trova il record di MyPage da cancellare
|
||||||
const pageToDelete = await MyPage.findByIdAndRemove(id);
|
const pageToDelete = await MyPage.findByIdAndDelete(id);
|
||||||
|
|
||||||
|
if (!pageToDelete) return res.status(404).json({ error: 'Pagina non trovata' });
|
||||||
if (!pageToDelete) {
|
if (!pageToDelete) {
|
||||||
return res.status(404).json({ error: 'Pagina non trovata' });
|
return res.status(404).json({ error: 'Pagina non trovata' });
|
||||||
|
} else {
|
||||||
|
await MyElem.deleteAllFromThisPage(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({ message: `Pagina eliminata con successo: ${pageToDelete.path}` });
|
res.json({ message: `Pagina eliminata con successo: ${pageToDelete.path}` });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(500).json({ error: 'Errore durante l\'eliminazione della pagina' });
|
res.status(500).json({ error: "Errore durante l'eliminazione della pagina" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -487,5 +491,4 @@ router.post('/chatbot', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -906,8 +906,22 @@ router.post('/savepage', authenticate, async (req, res) => {
|
|||||||
const mypage = params.page;
|
const mypage = params.page;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (mypage?._id) {
|
if (!mypage?._id) {
|
||||||
let found = await MyPage.findOneAndUpdate({ idapp, _id: mypage._id }, mypage, { upsert: true, new: true })
|
// creazione nuovo record
|
||||||
|
return await MyPage.create({ idapp, ...mypage })
|
||||||
|
.then((ris) => {
|
||||||
|
if (ris) {
|
||||||
|
return res.send({ code: server_constants.RIS_CODE_OK, mypage: ris });
|
||||||
|
}
|
||||||
|
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.log(e.message);
|
||||||
|
res.status(400).send(e);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// update record
|
||||||
|
return await MyPage.findOneAndUpdate({ idapp, _id: mypage._id }, mypage, { upsert: true, new: true })
|
||||||
.then((ris) => {
|
.then((ris) => {
|
||||||
if (ris) {
|
if (ris) {
|
||||||
return res.send({ code: server_constants.RIS_CODE_OK, mypage: ris });
|
return res.send({ code: server_constants.RIS_CODE_OK, mypage: ris });
|
||||||
@@ -2303,7 +2317,11 @@ async function uploadFile(req, res, version, options = {}) {
|
|||||||
console.log('File ricevuto:', file.originalFilename);
|
console.log('File ricevuto:', file.originalFilename);
|
||||||
|
|
||||||
const oldFile = file.filepath || file.path;
|
const oldFile = file.filepath || file.path;
|
||||||
const newFilePath = path.join(uploadDir, `${file.newFilename}_${file.originalFilename}`);
|
//const newFilePath = path.join(uploadDir, `${file.newFilename}_${file.originalFilename}`);
|
||||||
|
const newFilePath = path.join(uploadDir, `${file.originalFilename}`);
|
||||||
|
|
||||||
|
//@@ATTENZIONE ! HO RIMESSO COM'ERA PRIMA ! MA NON MI CONVINCE !
|
||||||
|
// RICONTROLLARE SE DEVO METTERLGI UN SUFFISSO PRIMA... (newFilePath)
|
||||||
|
|
||||||
// Sposta e rinomina
|
// Sposta e rinomina
|
||||||
await tools.move(oldFile, newFilePath);
|
await tools.move(oldFile, newFilePath);
|
||||||
|
|||||||
17
src/server/seed/seedTemplates.js
Normal file
17
src/server/seed/seedTemplates.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const { Page } = require('../models/pageModel');
|
||||||
|
|
||||||
|
const seedTemplates = async () => {
|
||||||
|
const templates = [
|
||||||
|
{ title: 'EcoVillage – Landing', sections: [] }, // Aggiungi il contenuto per questo template
|
||||||
|
{ title: 'Comunità – “Conosciamoci”', sections: [] },
|
||||||
|
{ title: 'Progetto – Presentazione', sections: [] },
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const template of templates) {
|
||||||
|
const page = new Page(template);
|
||||||
|
await page.save();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
seedTemplates();
|
||||||
|
s
|
||||||
@@ -102,6 +102,7 @@ connectToDatabase(connectionUrl, options)
|
|||||||
require('./models/myscheda');
|
require('./models/myscheda');
|
||||||
require('./models/bot');
|
require('./models/bot');
|
||||||
require('./models/calzoom');
|
require('./models/calzoom');
|
||||||
|
|
||||||
const mysql_func = require('./mysql/mysql_func');
|
const mysql_func = require('./mysql/mysql_func');
|
||||||
|
|
||||||
const index_router = require('./router/index_router');
|
const index_router = require('./router/index_router');
|
||||||
@@ -1057,4 +1058,8 @@ connectToDatabase(connectionUrl, options)
|
|||||||
process.exit(1); // Termina il processo se non riesce a connettersi
|
process.exit(1); // Termina il processo se non riesce a connettersi
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function add_numbers(a, b) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = { app };
|
module.exports = { app };
|
||||||
|
|||||||
@@ -3978,7 +3978,12 @@ module.exports = {
|
|||||||
const moveOp = async () => {
|
const moveOp = async () => {
|
||||||
// Assicurati che la cartella di destinazione esista
|
// Assicurati che la cartella di destinazione esista
|
||||||
const dir = path.dirname(newPath);
|
const dir = path.dirname(newPath);
|
||||||
|
console.log('crea directory ricorsivamente', dir);
|
||||||
await fs.promises.mkdir(dir, { recursive: true });
|
await fs.promises.mkdir(dir, { recursive: true });
|
||||||
|
if (!(await fs.promises.stat(dir).catch(() => false))) {
|
||||||
|
console.log('directory non creata, riprovo');
|
||||||
|
await fs.promises.mkdir(dir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newOldPath = oldPath.replace(/\/$/, '');
|
const newOldPath = oldPath.replace(/\/$/, '');
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.2.68
|
1.2.69
|
||||||
Reference in New Issue
Block a user