#25-cleanup-&-enhancements #26

Merged
jkeffects merged 4 commits from #25-cleanup-&-enhancements into main 2025-01-02 17:37:19 +00:00
10 changed files with 72 additions and 17 deletions
Showing only changes of commit cfefcd81d7 - Show all commits

View file

@ -3,4 +3,6 @@ export interface UpdateTemplateUsageCommand {
headerId: number | null; headerId: number | null;
bodyId: number | null; bodyId: number | null;
footerId: number | null; footerId: number | null;
headerHeight: number | null;
footerHeight: number | null;
} }

View file

@ -17,6 +17,8 @@ export default abstract class TemplateUsageCommandHandler {
headerId: updateTemplateUsage.headerId, headerId: updateTemplateUsage.headerId,
bodyId: updateTemplateUsage.bodyId, bodyId: updateTemplateUsage.bodyId,
footerId: updateTemplateUsage.footerId, footerId: updateTemplateUsage.footerId,
headerHeight: updateTemplateUsage.headerHeight,
footerHeight: updateTemplateUsage.footerHeight,
}) })
.where("scope = :scope", { scope: updateTemplateUsage.scope }) .where("scope = :scope", { scope: updateTemplateUsage.scope })
.execute() .execute()

View file

@ -78,12 +78,16 @@ export async function updateTemplateUsage(req: Request, res: Response): Promise<
const headerId = req.body.headerId ?? null; const headerId = req.body.headerId ?? null;
const bodyId = req.body.bodyId ?? null; const bodyId = req.body.bodyId ?? null;
const footerId = req.body.footerId ?? null; const footerId = req.body.footerId ?? null;
const headerHeight = req.body.headerHeight ?? null;
const footerHeight = req.body.footerHeight ?? null;
let updateTemplateUsage: UpdateTemplateUsageCommand = { let updateTemplateUsage: UpdateTemplateUsageCommand = {
scope: scope, scope: scope,
headerId: headerId, headerId: headerId,
bodyId: bodyId, bodyId: bodyId,
footerId: footerId, footerId: footerId,
headerHeight: headerHeight,
footerHeight: footerHeight,
}; };
await TemplateUsageCommandHandler.update(updateTemplateUsage); await TemplateUsageCommandHandler.update(updateTemplateUsage);

View file

@ -61,6 +61,7 @@ import { newsletterRecipients } from "./entity/newsletterRecipients";
import { Newsletter1735118780511 } from "./migrations/1735118780511-newsletter"; import { Newsletter1735118780511 } from "./migrations/1735118780511-newsletter";
import { newsletterConfig } from "./entity/newsletterConfig"; import { newsletterConfig } from "./entity/newsletterConfig";
import { NewsletterConfig1735207446910 } from "./migrations/1735207446910-newsletterConfig"; import { NewsletterConfig1735207446910 } from "./migrations/1735207446910-newsletterConfig";
import { TemplateMargins1735733514043 } from "./migrations/1735733514043-templateMargins";
const dataSource = new DataSource({ const dataSource = new DataSource({
type: DB_TYPE as any, type: DB_TYPE as any,
@ -132,6 +133,7 @@ const dataSource = new DataSource({
TemplateUsage1734949173739, TemplateUsage1734949173739,
Newsletter1735118780511, Newsletter1735118780511,
NewsletterConfig1735207446910, NewsletterConfig1735207446910,
TemplateMargins1735733514043,
], ],
migrationsRun: true, migrationsRun: true,
migrationsTransactionMode: "each", migrationsTransactionMode: "each",

View file

@ -7,15 +7,21 @@ export class templateUsage {
@PrimaryColumn({ type: "varchar", length: 255 }) @PrimaryColumn({ type: "varchar", length: 255 })
scope: PermissionModule; scope: PermissionModule;
@Column({ type: "number", nullable: true }) @Column({ type: "int", nullable: true })
headerId: number | null; headerId: number | null;
@Column({ type: "number", nullable: true }) @Column({ type: "int", nullable: true })
bodyId: number | null; bodyId: number | null;
@Column({ type: "number", nullable: true }) @Column({ type: "int", nullable: true })
footerId: number | null; footerId: number | null;
@Column({ type: "int", nullable: true })
headerHeight: number | null;
@Column({ type: "int", nullable: true })
footerHeight: number | null;
@ManyToOne(() => template, { @ManyToOne(() => template, {
nullable: true, nullable: true,
onDelete: "RESTRICT", onDelete: "RESTRICT",

View file

@ -13,6 +13,8 @@ export default abstract class TemplateUsageFactory {
header: record.header ? { id: record.header.id, template: record.header.template } : null, header: record.header ? { id: record.header.id, template: record.header.template } : null,
body: record.body ? { id: record.body.id, template: record.body.template } : null, body: record.body ? { id: record.body.id, template: record.body.template } : null,
footer: record.footer ? { id: record.footer.id, template: record.footer.template } : null, footer: record.footer ? { id: record.footer.id, template: record.footer.template } : null,
headerHeight: record.headerHeight,
footerHeight: record.footerHeight,
}; };
} }

View file

@ -11,7 +11,6 @@ export abstract class PdfExport {
filename = null, filename = null,
data = {}, data = {},
saveToDisk = true, saveToDisk = true,
margins = { top: "15mm", bottom: "15mm" },
folder = "", folder = "",
}: { }: {
template: PermissionModule; template: PermissionModule;
@ -19,12 +18,11 @@ export abstract class PdfExport {
filename?: string; filename?: string;
data?: any; data?: any;
saveToDisk?: boolean; saveToDisk?: boolean;
margins?: { top: string; bottom: string };
folder?: string; folder?: string;
}) { }) {
if (folder != "") FileSystemHelper.createFolder(folder); if (folder != "") FileSystemHelper.createFolder(folder);
const { header, footer, body } = await TemplateHelper.renderFileForModule({ const { header, footer, body, headerMargin, footerMargin } = await TemplateHelper.renderFileForModule({
module: template, module: template,
headerData: data, headerData: data,
bodyData: data, bodyData: data,
@ -46,8 +44,8 @@ export abstract class PdfExport {
format: "A4", format: "A4",
printBackground: false, printBackground: false,
margin: { margin: {
top: margins.top, top: (headerMargin ?? 15) + "mm",
bottom: margins.bottom, bottom: (footerMargin ?? 15) + "mm",
left: "10mm", left: "10mm",
right: "10mm", right: "10mm",
}, },

View file

@ -1,7 +1,7 @@
import TemplateService from "../service/templateService"; import TemplateService from "../service/templateService";
import { PermissionModule } from "../type/permissionTypes"; import { PermissionModule } from "../type/permissionTypes";
import TemplateUsageService from "../service/templateUsageService"; import TemplateUsageService from "../service/templateUsageService";
import Handlebars from "handlebars"; import Handlebars, { template } from "handlebars";
import { FileSystemHelper } from "./fileSystemHelper"; import { FileSystemHelper } from "./fileSystemHelper";
export abstract class TemplateHelper { export abstract class TemplateHelper {
@ -39,27 +39,27 @@ export abstract class TemplateHelper {
headerData?: any; headerData?: any;
bodyData?: any; bodyData?: any;
footerData?: any; footerData?: any;
}): Promise<{ header: string; body: string; footer: string; margins?: { top: string; bottom: string } }> { }): Promise<{ header: string; body: string; footer: string; headerMargin?: number; footerMargin?: number }> {
const moduleTemplates = await TemplateUsageService.getByScope(module); const moduleTemplate = await TemplateUsageService.getByScope(module);
let header = `<h1 style="font-size:10px; text-align:center; width:100%;">${title}</h1>`; let header = `<h1 style="font-size:10px; text-align:center; width:100%;">${title}</h1>`;
let footer = ""; let footer = "";
let body = ""; let body = "";
if (moduleTemplates.headerId) { if (moduleTemplate.headerId) {
header = await this.getTemplateFromStore(moduleTemplates.headerId); header = await this.getTemplateFromStore(moduleTemplate.headerId);
header = this.applyDataToTemplate(header, { title, ...headerData }); header = this.applyDataToTemplate(header, { title, ...headerData });
} }
if (moduleTemplates.footerId) { if (moduleTemplate.footerId) {
footer = await this.getTemplateFromStore(moduleTemplates.footerId); footer = await this.getTemplateFromStore(moduleTemplate.footerId);
} else { } else {
footer = this.getTemplateFromFile(module + ".footer"); footer = this.getTemplateFromFile(module + ".footer");
} }
footer = this.applyDataToTemplate(footer, footerData); footer = this.applyDataToTemplate(footer, footerData);
if (moduleTemplates.bodyId) { if (moduleTemplate.bodyId) {
body = await this.getTemplateFromStore(moduleTemplates.bodyId); body = await this.getTemplateFromStore(moduleTemplate.bodyId);
} else { } else {
body = this.getTemplateFromFile(module + ".body"); body = this.getTemplateFromFile(module + ".body");
} }
@ -69,6 +69,8 @@ export abstract class TemplateHelper {
header, header,
footer, footer,
body, body,
headerMargin: moduleTemplate.headerHeight,
footerMargin: moduleTemplate.footerHeight,
}; };
} }
} }

View file

@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class TemplateMargins1735733514043 implements MigrationInterface {
name = "TemplateMargins1735733514043";
public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.addColumn(
"template_usage",
new TableColumn({
name: "headerHeight",
type: variableType_int,
default: null,
isNullable: true,
})
);
await queryRunner.addColumn(
"template_usage",
new TableColumn({
name: "footerHeight",
type: variableType_int,
default: null,
isNullable: true,
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn("template_usage", "footerHeight");
await queryRunner.dropColumn("template_usage", "headerHeight");
}
}

View file

@ -5,4 +5,6 @@ export interface TemplateUsageViewModel {
header: { id: number; template: string } | null; header: { id: number; template: string } | null;
body: { id: number; template: string } | null; body: { id: number; template: string } | null;
footer: { id: number; template: string } | null; footer: { id: number; template: string } | null;
headerHeight: number | null;
footerHeight: number | null;
} }