- Generazione della Raccolta dei Cataloghi (web e Stampa), e creazione del PDF Online.
- Lista Raccolta Cataloghi, aggiungi/togli catalogo.
This commit is contained in:
BIN
prova_generato-stampabile.pdf
Normal file
BIN
prova_generato-stampabile.pdf
Normal file
Binary file not shown.
@@ -251,6 +251,28 @@ CatalogSchema.statics.findAllIdApp = async function (idapp) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CatalogSchema.statics.executeQueryPickup = async function (idapp, params) {
|
||||||
|
const strfind = params.search;
|
||||||
|
|
||||||
|
if (strfind === '') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cerca title
|
||||||
|
const reg = new RegExp(strfind, 'i');
|
||||||
|
const arrrec = await this.find({
|
||||||
|
idapp,
|
||||||
|
title: reg,
|
||||||
|
})
|
||||||
|
.sort({ title: 1 })
|
||||||
|
.limit(10)
|
||||||
|
.select('title _id')
|
||||||
|
.lean();
|
||||||
|
|
||||||
|
return arrrec;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const Catalog = mongoose.model('Catalog', CatalogSchema);
|
const Catalog = mongoose.model('Catalog', CatalogSchema);
|
||||||
|
|
||||||
Catalog.createIndexes()
|
Catalog.createIndexes()
|
||||||
|
|||||||
94
src/server/models/raccoltacataloghi.js
Executable file
94
src/server/models/raccoltacataloghi.js
Executable file
@@ -0,0 +1,94 @@
|
|||||||
|
const mongoose = require('mongoose').set('debug', false);
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
const { ObjectId } = require('mongodb');
|
||||||
|
|
||||||
|
const { IImg } = require('../models/myscheda');
|
||||||
|
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.level = 'F';
|
||||||
|
|
||||||
|
// Resolving error Unknown modifier: $pushAll
|
||||||
|
mongoose.plugin((schema) => {
|
||||||
|
schema.options.usePushEach = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const RaccoltaCataloghiSchema = new Schema({
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
active: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
index: true,
|
||||||
|
},
|
||||||
|
foto_raccolta: IImg,
|
||||||
|
|
||||||
|
idPageAssigned: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
idPageAssigned_stampa: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
nomefile_da_generare: String,
|
||||||
|
|
||||||
|
pdf_generato: String,
|
||||||
|
pdf_generato_stampa: String,
|
||||||
|
data_generato: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
data_generato_stampa: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
pdf_online: String,
|
||||||
|
data_online: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
pdf_online_stampa: String,
|
||||||
|
data_online_stampa: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
|
||||||
|
lista_cataloghi: [
|
||||||
|
{
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: 'Catalog',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
RaccoltaCataloghiSchema.statics.getFieldsForSearch = function () {
|
||||||
|
return [{ field: 'title', type: tools.FieldType.string }];
|
||||||
|
};
|
||||||
|
|
||||||
|
RaccoltaCataloghiSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||||
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
|
return tools.executeQueryTable(this, idapp, params, user);
|
||||||
|
};
|
||||||
|
|
||||||
|
RaccoltaCataloghiSchema.statics.findAllIdApp = async function (idapp) {
|
||||||
|
const RaccoltaCataloghi = this;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let arrrec = await RaccoltaCataloghi.find({ idapp }).sort({ title: 1 }).populate('lista_cataloghi').lean();
|
||||||
|
|
||||||
|
return arrrec;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Errore: ', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const RaccoltaCataloghi = mongoose.model('RaccoltaCataloghi', RaccoltaCataloghiSchema);
|
||||||
|
|
||||||
|
RaccoltaCataloghi.createIndexes()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = { RaccoltaCataloghi };
|
||||||
@@ -28,6 +28,7 @@ const Gasordine = require('../models/gasordine');
|
|||||||
const { User } = require('../models/user');
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
const { Catalog } = require('../models/catalog');
|
const { Catalog } = require('../models/catalog');
|
||||||
|
const { RaccoltaCataloghi } = require('../models/raccoltacataloghi');
|
||||||
|
|
||||||
const server_constants = require('../tools/server_constants');
|
const server_constants = require('../tools/server_constants');
|
||||||
|
|
||||||
@@ -420,41 +421,47 @@ router.post('/online-pdf', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
idapp = req.body.idapp;
|
idapp = req.body.idapp;
|
||||||
id_catalog = req.body.id_catalog;
|
id_catalog = req.body.id_catalog;
|
||||||
|
id_raccolta = req.body.id_raccolta;
|
||||||
stampa = req.body.stampa;
|
stampa = req.body.stampa;
|
||||||
let mydir = '';
|
let mydir = '';
|
||||||
let risout = {};
|
let risout = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let myrec = null;
|
||||||
// Aggiorna il PDF OnLine, copiando il file da Generato a OnLine
|
// Aggiorna il PDF OnLine, copiando il file da Generato a OnLine
|
||||||
let catalog = await Catalog.findOne({ _id: id_catalog });
|
if (id_catalog) {
|
||||||
|
myrec = await Catalog.findOne({ _id: id_catalog });
|
||||||
|
} else if (id_raccolta) {
|
||||||
|
myrec = await RaccoltaCataloghi.findOne({ _id: id_raccolta });
|
||||||
|
}
|
||||||
|
|
||||||
if (catalog) {
|
if (myrec) {
|
||||||
mydir = tools.getdirByIdApp(idapp);
|
mydir = tools.getdirByIdApp(idapp);
|
||||||
// const baseurl = this.getHostByIdApp(idapp);
|
// const baseurl = this.getHostByIdApp(idapp);
|
||||||
|
|
||||||
if (stampa) {
|
if (stampa) {
|
||||||
catalog.pdf_online_stampa = catalog.pdf_generato_stampa.replace('_generato', '');
|
myrec.pdf_online_stampa = myrec.pdf_generato_stampa.replace('_generato', '');
|
||||||
} else {
|
} else {
|
||||||
catalog.pdf_online = catalog.pdf_generato.replace('_generato', '');
|
myrec.pdf_online = myrec.pdf_generato.replace('_generato', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aggiorna il PDF OnLine, copiando il file da Generato a OnLine
|
// Aggiorna il PDF OnLine, copiando il file da Generato a OnLine
|
||||||
const fileOrigin = mydir + (stampa ? catalog.pdf_generato_stampa : catalog.pdf_generato);
|
const fileOrigin = mydir + (stampa ? myrec.pdf_generato_stampa : myrec.pdf_generato);
|
||||||
const fileDest = mydir + (stampa ? catalog.pdf_online_stampa : catalog.pdf_online);
|
const fileDest = mydir + (stampa ? myrec.pdf_online_stampa : myrec.pdf_online);
|
||||||
const fileDestNoDir = (stampa ? catalog.pdf_online_stampa : catalog.pdf_online);
|
const fileDestNoDir = stampa ? myrec.pdf_online_stampa : myrec.pdf_online;
|
||||||
// copia il file
|
// copia il file
|
||||||
await fs.promises.copyFile(fileOrigin, fileDest);
|
await fs.promises.copyFile(fileOrigin, fileDest);
|
||||||
|
|
||||||
if (stampa) {
|
if (stampa) {
|
||||||
catalog.data_online_stampa = catalog.data_generato_stampa;
|
myrec.data_online_stampa = myrec.data_generato_stampa;
|
||||||
} else {
|
} else {
|
||||||
catalog.data_online = catalog.data_generato;
|
myrec.data_online = myrec.data_generato;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aggiorna il record
|
// Aggiorna il record
|
||||||
await catalog.save();
|
await myrec.save();
|
||||||
|
|
||||||
risout = {catalog: catalog._doc};
|
risout = { record: myrec._doc };
|
||||||
}
|
}
|
||||||
|
|
||||||
// risout
|
// risout
|
||||||
@@ -465,6 +472,114 @@ router.post('/online-pdf', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function JoinPDFCatalogs(cataloghi, options, outputFile, stampa) {
|
||||||
|
try {
|
||||||
|
// Per ogni catalogo prendi il suo PDF Generato
|
||||||
|
|
||||||
|
const pdfDoc = await PDFDocument.create();
|
||||||
|
|
||||||
|
for (let id_catalog of cataloghi) {
|
||||||
|
let catalog = await Catalog.findOne({ _id: id_catalog });
|
||||||
|
if (catalog) {
|
||||||
|
let filename = stampa ? catalog.pdf_generato_stampa : catalog.pdf_generato;
|
||||||
|
if (filename) {
|
||||||
|
const pdfBytes = await fs.promises.readFile(options.mydir + filename);
|
||||||
|
const pdf = await PDFDocument.load(pdfBytes);
|
||||||
|
const pages = pdf.getPages();
|
||||||
|
const copiedPages = await pdfDoc.copyPages(
|
||||||
|
pdf,
|
||||||
|
pages.map((p, i) => i)
|
||||||
|
);
|
||||||
|
for (let page of copiedPages) {
|
||||||
|
pdfDoc.addPage(page);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('ATTENZIONE! Catalogo non ancora Generato ! ', catalog.title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raccolta salvata !
|
||||||
|
const pdfBytes = await pdfDoc.save();
|
||||||
|
await fs.promises.writeFile(outputFile, pdfBytes);
|
||||||
|
// scrivi il percorso relativo e nomefile sul DB
|
||||||
|
|
||||||
|
const outputFilename = path.basename(outputFile);
|
||||||
|
const outputPath = path.join(options.dir_out, outputFilename);
|
||||||
|
|
||||||
|
const ris = {
|
||||||
|
outputPath,
|
||||||
|
};
|
||||||
|
|
||||||
|
return ris;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error: ', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post('/join-pdf', authenticate, async (req, res) => {
|
||||||
|
console.log('/join-pdf');
|
||||||
|
|
||||||
|
idapp = req.body.idapp;
|
||||||
|
options = req.body.options;
|
||||||
|
options.idapp = idapp;
|
||||||
|
options.mydir = tools.getdirByIdApp(idapp);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const full_dir_out = tools.getdirByIdApp(options.idapp) + '/' + options.dir_out;
|
||||||
|
await fs.promises.mkdir(full_dir_out, { recursive: true });
|
||||||
|
|
||||||
|
// Aggiorna il PDF OnLine, copiando il file da Generato a OnLine
|
||||||
|
let raccolta = await RaccoltaCataloghi.findOne({ _id: options.id_raccolta });
|
||||||
|
|
||||||
|
if (raccolta) {
|
||||||
|
cataloghi = raccolta.lista_cataloghi;
|
||||||
|
|
||||||
|
let outputFile = path.join(
|
||||||
|
full_dir_out,
|
||||||
|
tools.removeFileExtension(raccolta.nomefile_da_generare) + '_generato.pdf'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (options.stampa) {
|
||||||
|
outputFileStampa = path.join(full_dir_out, path.basename(tools.removeFileExtension(outputFile))) + '-stampabile.pdf';
|
||||||
|
// Creazione file per STAMPA
|
||||||
|
const ris_stampa = await JoinPDFCatalogs(cataloghi, options, outputFileStampa, true);
|
||||||
|
if (ris_stampa) {
|
||||||
|
raccolta.pdf_generato_stampa = ris_stampa.outputPath;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Creazione file per WEB
|
||||||
|
const ris = await JoinPDFCatalogs(cataloghi, options, outputFile, false);
|
||||||
|
if (ris) {
|
||||||
|
raccolta.pdf_generato = ris.outputPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.metti_online) {
|
||||||
|
if (options.stampa) {
|
||||||
|
raccolta.pdf_online_stampa = raccolta.pdf_generato_stampa.replace('_generato', '');
|
||||||
|
} else {
|
||||||
|
raccolta.pdf_online = raccolta.pdf_generato.replace('_generato', '');
|
||||||
|
}
|
||||||
|
const fileDest = options.mydir + raccolta.pdf_online;
|
||||||
|
await fs.promises.writeFile(fileDest, pdfBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
raccolta.save();
|
||||||
|
|
||||||
|
risout = { raccolta: raccolta._doc };
|
||||||
|
}
|
||||||
|
|
||||||
|
// risout
|
||||||
|
|
||||||
|
return res.status(200).send(risout);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err join-pdf', e.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Endpoint POST per la conversione del PDF
|
// Endpoint POST per la conversione del PDF
|
||||||
router.post('/convert-pdf', upload.single('pdf'), async (req, res) => {
|
router.post('/convert-pdf', upload.single('pdf'), async (req, res) => {
|
||||||
if (!req.file) {
|
if (!req.file) {
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ const Product = require('../models/product');
|
|||||||
const Author = require('../models/author');
|
const Author = require('../models/author');
|
||||||
const Collana = require('../models/collana');
|
const Collana = require('../models/collana');
|
||||||
const { Catalog } = require('../models/catalog');
|
const { Catalog } = require('../models/catalog');
|
||||||
|
const { RaccoltaCataloghi } = require('../models/raccoltacataloghi');
|
||||||
const Publisher = require('../models/publisher');
|
const Publisher = require('../models/publisher');
|
||||||
const ProductInfo = require('../models/productInfo');
|
const ProductInfo = require('../models/productInfo');
|
||||||
const Scontistica = require('../models/scontistica');
|
const Scontistica = require('../models/scontistica');
|
||||||
@@ -2030,6 +2031,7 @@ async function load(req, res, version = '0') {
|
|||||||
tipologie: version >= 91 ? T_WEB_Tipologie.findAllIdApp() : Promise.resolve([]),
|
tipologie: version >= 91 ? T_WEB_Tipologie.findAllIdApp() : Promise.resolve([]),
|
||||||
tipoformato: version >= 91 ? T_WEB_TipiFormato.findAllIdApp() : Promise.resolve([]),
|
tipoformato: version >= 91 ? T_WEB_TipiFormato.findAllIdApp() : Promise.resolve([]),
|
||||||
crons: version >= 91 ? Cron.findAllIdApp() : Promise.resolve([]),
|
crons: version >= 91 ? Cron.findAllIdApp() : Promise.resolve([]),
|
||||||
|
raccoltacataloghis: version >= 91 ? RaccoltaCataloghi.findAllIdApp(idapp) : Promise.resolve([]),
|
||||||
myuserextra: req.user
|
myuserextra: req.user
|
||||||
? User.addExtraInfo(idapp, req.user, version)
|
? User.addExtraInfo(idapp, req.user, version)
|
||||||
: Promise.resolve(null)
|
: Promise.resolve(null)
|
||||||
@@ -2147,6 +2149,7 @@ async function load(req, res, version = '0') {
|
|||||||
tipologie: data.tipologie,
|
tipologie: data.tipologie,
|
||||||
tipoformato: data.tipoformato,
|
tipoformato: data.tipoformato,
|
||||||
crons: data.crons,
|
crons: data.crons,
|
||||||
|
raccoltacataloghis: data.raccoltacataloghis,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const { PaymentType } = require('../models/paymenttype');
|
|||||||
const { Discipline } = require('../models/discipline');
|
const { Discipline } = require('../models/discipline');
|
||||||
const { Skill } = require('../models/skill');
|
const { Skill } = require('../models/skill');
|
||||||
const { Catalog } = require('../models/catalog');
|
const { Catalog } = require('../models/catalog');
|
||||||
|
const { RaccoltaCataloghi } = require('../models/raccoltacataloghi');
|
||||||
const { Good } = require('../models/good');
|
const { Good } = require('../models/good');
|
||||||
const { SubSkill } = require('../models/subskill');
|
const { SubSkill } = require('../models/subskill');
|
||||||
const { MySkill } = require('../models/myskill');
|
const { MySkill } = require('../models/myskill');
|
||||||
@@ -233,6 +234,8 @@ module.exports = {
|
|||||||
mytable = Skill;
|
mytable = Skill;
|
||||||
else if (tablename === 'catalogs')
|
else if (tablename === 'catalogs')
|
||||||
mytable = Catalog;
|
mytable = Catalog;
|
||||||
|
else if (tablename === 'raccoltacataloghis')
|
||||||
|
mytable = RaccoltaCataloghi;
|
||||||
else if (tablename === 'goods')
|
else if (tablename === 'goods')
|
||||||
mytable = Good;
|
mytable = Good;
|
||||||
else if (tablename === 'subskills')
|
else if (tablename === 'subskills')
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ module.exports = {
|
|||||||
TABLES_MYGROUPS: 'mygroups',
|
TABLES_MYGROUPS: 'mygroups',
|
||||||
TABLES_ATTIVITAS: 'attivitas',
|
TABLES_ATTIVITAS: 'attivitas',
|
||||||
TABLES_CATALOG: 'catalogs',
|
TABLES_CATALOG: 'catalogs',
|
||||||
|
TABLES_LISTA_EDITORI: 'lista_editori',
|
||||||
|
TABLES_RACCOLTACATALOGHIS: 'raccoltacataloghis',
|
||||||
|
|
||||||
MYTABS: [{ id: 0, table: 'none' },
|
MYTABS: [{ id: 0, table: 'none' },
|
||||||
{ id: 1, table: this.TABLES_MYSKILLS },
|
{ id: 1, table: this.TABLES_MYSKILLS },
|
||||||
@@ -210,7 +212,7 @@ module.exports = {
|
|||||||
TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'attivitas'],
|
TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'attivitas'],
|
||||||
|
|
||||||
//++Todo: per abilitare gli utenti ad inserire un Circuito aggiungere 'circuits' alla lista TABLES_PERM_NEWREC
|
//++Todo: per abilitare gli utenti ad inserire un Circuito aggiungere 'circuits' alla lista TABLES_PERM_NEWREC
|
||||||
TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups', 'myhosps', 'catalogs'],
|
TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups', 'myhosps', 'catalogs', 'raccoltacataloghis'],
|
||||||
|
|
||||||
TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods', 'attivitas'],
|
TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods', 'attivitas'],
|
||||||
|
|
||||||
@@ -223,7 +225,7 @@ module.exports = {
|
|||||||
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
|
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
|
||||||
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
|
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
|
||||||
|
|
||||||
TABLES_ENABLE_GETTABLE_FOR_NOT_LOGGED: ['attivitas', 'catalogs'],
|
TABLES_ENABLE_GETTABLE_FOR_NOT_LOGGED: ['attivitas', 'catalogs', 'raccoltacataloghis'],
|
||||||
|
|
||||||
TABLES_NUM_AS_ID_NUMBER: [],
|
TABLES_NUM_AS_ID_NUMBER: [],
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user