Export PDF : fiche Publication et options d'export (module à partager ou vendre)
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 44s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 57s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Successful in 1m41s
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 44s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 57s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Successful in 1m41s
- Correctifs du livret : le résumé des scènes est enfin exporté, libellés
accentués (Thèmes, Récompenses, Résolution, Choix et conséquences), stats
Foundry en français (PV, CA, FOR, FP…), encadrés et longues pages de lore
coupables entre deux pages (fini les grands blancs), plus de date d'export
en couverture, titre/auteur/sujet/langue dans les propriétés du PDF.
- Fiche Publication de la campagne (écran /campaigns/:id/publication) :
sous-titre, auteur, version, illustration de couverture, page technique
(système, niveaux, joueurs, durée), argument, avertissements de contenu,
contexte caché et accroches pour le MJ, crédits et licence. Stockée en JSON
(migration V26), API GET/PUT /api/campaigns/{id}/publication, conservée à
l'export/import de campagne (couverture remappée).
- Dans le PDF : couverture illustrée, page de crédits, introduction (page
technique, l'aventure en bref, contexte MJ, accroches, structure). Fiche
vide : livret de campagne inchangé.
- Options d'export (modale au clic sur « Exporter en PDF ») : version MJ ou
joueurs (aucun secret : notes MJ, conséquences, sorties, combats, contexte),
format A4 / A5 / US Letter, mode impression sans aplats, choix des parties,
lore complet ou seulement les pages liées à la campagne.
- Cinq nouvelles fiches du coach d'écriture sur l'écran Publication
(argument, avertissements, contexte caché, accroches, crédits).
Vérifié : core clean verify (1247 tests, dont contenu du PDF par option,
version joueurs sans secret, propriétés du fichier, format Letter, remap de
la couverture à l'import), web build + 357 vitest, lint sans erreur, essai
dans le navigateur (migration V26 sur une base existante, enregistrement de
la fiche, export joueurs A5).
À redéployer : core + web (migration V26).
This commit is contained in:
@@ -17,6 +17,7 @@ export const routes: Routes = [
|
||||
{ path: 'campaigns', loadComponent: () => import('./campaigns/campaigns.component').then(m => m.CampaignsComponent) },
|
||||
{ path: 'campaigns/:id', loadComponent: () => import('./campaigns/campaign/campaign-detail/campaign-detail.component').then(m => m.CampaignDetailComponent) },
|
||||
{ path: 'campaigns/:campaignId/graph', loadComponent: () => import('./campaigns/campaign-graph/campaign-graph.component').then(m => m.CampaignGraphComponent) },
|
||||
{ path: 'campaigns/:campaignId/publication', loadComponent: () => import('./campaigns/campaign/campaign-publication/campaign-publication.component').then(m => m.CampaignPublicationComponent) },
|
||||
{ path: 'campaigns/:campaignId/import', loadComponent: () => import('./campaigns/campaign/campaign-import/campaign-import.component').then(m => m.CampaignImportComponent) },
|
||||
{ path: 'campaigns/:campaignId/playthroughs/:playthroughId', loadComponent: () => import('./campaigns/playthrough/playthrough-detail/playthrough-detail.component').then(m => m.PlaythroughDetailComponent) },
|
||||
{ path: 'campaigns/:campaignId/playthroughs/:playthroughId/flags', loadComponent: () => import('./campaigns/playthrough/playthrough-flags-page/playthrough-flags-page.component').then(m => m.PlaythroughFlagsPageComponent) },
|
||||
|
||||
@@ -322,6 +322,15 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Options du livret PDF (version MJ/joueurs, format, parties, lore) + accès à la fiche Publication. -->
|
||||
<app-pdf-export-dialog
|
||||
[open]="pdfDialogOpen"
|
||||
[exporting]="exportingPdf"
|
||||
[hasPublication]="hasPublication"
|
||||
(cancelled)="pdfDialogOpen = false"
|
||||
(confirmed)="onPdfExportConfirmed($event)"
|
||||
(editPublication)="openPublication()"></app-pdf-export-dialog>
|
||||
|
||||
<!-- Choix du périmètre de l'export Foundry (tout / cartes+ennemis / journaux / tables). -->
|
||||
<app-foundry-export-dialog
|
||||
[open]="foundryDialogOpen"
|
||||
|
||||
@@ -11,7 +11,7 @@ import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { forkJoin, of, Observable } from 'rxjs';
|
||||
import { catchError, switchMap, filter, map } from 'rxjs/operators';
|
||||
import { CampaignService, FoundryExportOptions } from '../../../services/campaign.service';
|
||||
import { CampaignService, FoundryExportOptions, PdfExportOptions } from '../../../services/campaign.service';
|
||||
import { LoreService } from '../../../services/lore.service';
|
||||
import { GameSystemService } from '../../../services/game-system.service';
|
||||
import { GameSystem } from '../../../services/game-system.model';
|
||||
@@ -35,10 +35,12 @@ import { ReadinessPanelComponent } from '../../../shared/readiness-panel/readine
|
||||
import { WritingReviewPanelComponent } from '../../../shared/writing-review/writing-review-panel.component';
|
||||
import { CampaignPlayBlockComponent } from '../campaign-play-block/campaign-play-block.component';
|
||||
import { FoundryExportDialogComponent } from '../foundry-export-dialog/foundry-export-dialog.component';
|
||||
import { PdfExportDialogComponent } from '../pdf-export-dialog/pdf-export-dialog.component';
|
||||
import { downloadBlob, safeFileName } from '../../../shared/download.util';
|
||||
|
||||
@Component({
|
||||
selector: 'app-campaign-detail',
|
||||
imports: [FormsModule, LucideAngularModule, RouterLink, TranslatePipe, CdkDropList, CdkDrag, ReadinessPanelComponent, WritingReviewPanelComponent, CampaignPlayBlockComponent, FoundryExportDialogComponent],
|
||||
imports: [FormsModule, LucideAngularModule, RouterLink, TranslatePipe, CdkDropList, CdkDrag, ReadinessPanelComponent, WritingReviewPanelComponent, CampaignPlayBlockComponent, FoundryExportDialogComponent, PdfExportDialogComponent],
|
||||
templateUrl: './campaign-detail.component.html',
|
||||
styleUrls: ['./campaign-detail.component.scss']
|
||||
})
|
||||
@@ -67,6 +69,10 @@ export class CampaignDetailComponent implements OnInit, OnDestroy {
|
||||
foundryDialogOpen = false;
|
||||
/** Export PDF en cours (anti double-clic). */
|
||||
exportingPdf = false;
|
||||
/** Modale des options du livret PDF. */
|
||||
pdfDialogOpen = false;
|
||||
/** Fiche Publication remplie (sinon la modale propose de la compléter). */
|
||||
hasPublication = true;
|
||||
|
||||
campaign: Campaign | null = null;
|
||||
arcs: Arc[] = [];
|
||||
@@ -430,22 +436,27 @@ export class CampaignDetailComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
/** Génère et télécharge le livret PDF de la campagne. */
|
||||
/** Ouvre la modale d'options du livret PDF (en vérifiant si la fiche Publication est remplie). */
|
||||
exportPdf(): void {
|
||||
if (!this.campaign?.id || this.exportingPdf) return;
|
||||
this.pdfDialogOpen = true;
|
||||
this.campaignService.getPublication(this.campaign.id).subscribe({
|
||||
next: (p) => this.hasPublication = Object.values(p ?? {}).some(v => typeof v === 'string' && v.trim().length > 0),
|
||||
error: () => this.hasPublication = true // inconnu : pas d'incitation à tort
|
||||
});
|
||||
}
|
||||
|
||||
/** Génère et télécharge le livret PDF selon les options choisies. */
|
||||
onPdfExportConfirmed(opts: PdfExportOptions): void {
|
||||
if (!this.campaign?.id || this.exportingPdf) return;
|
||||
this.exportingPdf = true;
|
||||
const name = this.campaign.name;
|
||||
this.campaignService.exportPdf(this.campaign.id).subscribe({
|
||||
this.campaignService.exportPdf(this.campaign.id, opts).subscribe({
|
||||
next: (blob) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `${(name || 'campagne').replace(/[^a-zA-Z0-9-_]+/g, '_')}.pdf`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
const suffix = opts.edition === 'player' ? '_joueurs' : '';
|
||||
downloadBlob(blob, `${safeFileName(name, 'campagne')}${suffix}.pdf`);
|
||||
this.exportingPdf = false;
|
||||
this.pdfDialogOpen = false;
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Échec de l\'export PDF', err);
|
||||
@@ -454,6 +465,13 @@ export class CampaignDetailComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
/** Depuis la modale PDF : compléter la fiche Publication (couverture, crédits…). */
|
||||
openPublication(): void {
|
||||
if (!this.campaign?.id) return;
|
||||
this.pdfDialogOpen = false;
|
||||
this.router.navigate(['/campaigns', this.campaign.id, 'publication']);
|
||||
}
|
||||
|
||||
/** Réordonne les arcs par glisser-déposer et persiste le nouvel ordre. */
|
||||
dropArc(event: CdkDragDrop<Arc[]>): void {
|
||||
if (event.previousIndex === event.currentIndex) return;
|
||||
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
<div class="edit-page">
|
||||
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>{{ 'publication.title' | translate }}</h1>
|
||||
<p class="subtitle">{{ campaignName }}</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button type="button" class="btn-secondary" (click)="back()">
|
||||
<lucide-icon [img]="ArrowLeft" [size]="14"></lucide-icon>
|
||||
{{ 'common.back' | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary" (click)="pdfDialogOpen = true" [disabled]="loading">
|
||||
<lucide-icon [img]="FileText" [size]="14"></lucide-icon>
|
||||
{{ 'campaignDetail.pdfExport' | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary" (click)="save()" [disabled]="loading || saving || !dirty">
|
||||
<lucide-icon [img]="Save" [size]="14"></lucide-icon>
|
||||
{{ (saving ? 'common.saving' : (savedFlash ? 'publication.saved' : 'common.save')) | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (errorMessage) {
|
||||
<div class="pub-error" role="alert">{{ errorMessage }}</div>
|
||||
}
|
||||
|
||||
@if (!loading) {
|
||||
<div class="edit-form">
|
||||
<p class="optional-hint">{{ 'publication.intro' | translate }}</p>
|
||||
|
||||
<app-expandable-section [title]="'publication.coverSection' | translate" icon="📕" [initiallyOpen]="true"
|
||||
[filled]="filledAny('subtitle', 'author', 'version', 'coverImageId')">
|
||||
<div class="cover-grid">
|
||||
<div class="cover-fields">
|
||||
<div class="field">
|
||||
<label for="pub-subtitle">{{ 'publication.subtitleLabel' | translate }}</label>
|
||||
<input id="pub-subtitle" type="text" [ngModel]="pub.subtitle" (ngModelChange)="set('subtitle', $event)"
|
||||
[placeholder]="'publication.subtitlePlaceholder' | translate" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="pub-author">{{ 'publication.authorLabel' | translate }}</label>
|
||||
<input id="pub-author" type="text" [ngModel]="pub.author" (ngModelChange)="set('author', $event)"
|
||||
[placeholder]="'publication.authorPlaceholder' | translate" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="pub-version">{{ 'publication.versionLabel' | translate }}</label>
|
||||
<input id="pub-version" type="text" [ngModel]="pub.version" (ngModelChange)="set('version', $event)"
|
||||
placeholder="1.0" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<p class="cover-label">{{ 'publication.coverLabel' | translate }}</p>
|
||||
<app-single-image-picker
|
||||
[imageId]="pub.coverImageId ?? null"
|
||||
aspectRatio="3 / 4"
|
||||
[hint]="'publication.coverHint' | translate"
|
||||
(imageIdChange)="setCover($event)"></app-single-image-picker>
|
||||
</div>
|
||||
</div>
|
||||
</app-expandable-section>
|
||||
|
||||
<app-expandable-section [title]="'publication.techSection' | translate" icon="🎲" [initiallyOpen]="true"
|
||||
[filled]="filledAny('system', 'levels', 'players', 'duration')">
|
||||
<p class="field-hint">{{ 'publication.techHint' | translate }}</p>
|
||||
<div class="field-row">
|
||||
<div class="field">
|
||||
<label for="pub-system">{{ 'publication.systemLabel' | translate }}</label>
|
||||
<input id="pub-system" type="text" [ngModel]="pub.system" (ngModelChange)="set('system', $event)"
|
||||
[placeholder]="'publication.systemPlaceholder' | translate" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="pub-levels">{{ 'publication.levelsLabel' | translate }}</label>
|
||||
<input id="pub-levels" type="text" [ngModel]="pub.levels" (ngModelChange)="set('levels', $event)"
|
||||
[placeholder]="'publication.levelsPlaceholder' | translate" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="pub-players">{{ 'publication.playersLabel' | translate }}</label>
|
||||
<input id="pub-players" type="text" [ngModel]="pub.players" (ngModelChange)="set('players', $event)"
|
||||
[placeholder]="'publication.playersPlaceholder' | translate" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="pub-duration">{{ 'publication.durationLabel' | translate }}</label>
|
||||
<input id="pub-duration" type="text" [ngModel]="pub.duration" (ngModelChange)="set('duration', $event)"
|
||||
[placeholder]="'publication.durationPlaceholder' | translate" />
|
||||
</div>
|
||||
</div>
|
||||
</app-expandable-section>
|
||||
|
||||
<app-expandable-section [title]="'publication.presentationSection' | translate" icon="📣"
|
||||
[filled]="filledAny('pitch', 'contentWarnings')">
|
||||
<div class="field">
|
||||
<div class="field-label-row">
|
||||
<label for="pub-pitch">{{ 'publication.pitchLabel' | translate }}</label>
|
||||
<app-writing-coach-trigger topic="publication.pitch"></app-writing-coach-trigger>
|
||||
</div>
|
||||
<textarea id="pub-pitch" rows="4" [ngModel]="pub.pitch" (ngModelChange)="set('pitch', $event)"
|
||||
[placeholder]="'publication.pitchPlaceholder' | translate"></textarea>
|
||||
<small class="field-hint">{{ 'publication.pitchHint' | translate }}</small>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-row">
|
||||
<label for="pub-warnings">{{ 'publication.warningsLabel' | translate }}</label>
|
||||
<app-writing-coach-trigger topic="publication.contentWarnings"></app-writing-coach-trigger>
|
||||
</div>
|
||||
<textarea id="pub-warnings" rows="2" [ngModel]="pub.contentWarnings" (ngModelChange)="set('contentWarnings', $event)"
|
||||
[placeholder]="'publication.warningsPlaceholder' | translate"></textarea>
|
||||
</div>
|
||||
</app-expandable-section>
|
||||
|
||||
<app-expandable-section [title]="'publication.gmSection' | translate" icon="🔒" variant="private"
|
||||
[filled]="filledAny('gmBackground', 'hooks')">
|
||||
<p class="field-hint">{{ 'publication.gmHint' | translate }}</p>
|
||||
<div class="field">
|
||||
<div class="field-label-row">
|
||||
<label for="pub-background">{{ 'publication.backgroundLabel' | translate }}</label>
|
||||
<app-writing-coach-trigger topic="publication.gmBackground"></app-writing-coach-trigger>
|
||||
</div>
|
||||
<textarea id="pub-background" rows="7" [ngModel]="pub.gmBackground" (ngModelChange)="set('gmBackground', $event)"
|
||||
[placeholder]="'publication.backgroundPlaceholder' | translate"></textarea>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-row">
|
||||
<label for="pub-hooks">{{ 'publication.hooksLabel' | translate }}</label>
|
||||
<app-writing-coach-trigger topic="publication.hooks"></app-writing-coach-trigger>
|
||||
</div>
|
||||
<textarea id="pub-hooks" rows="4" [ngModel]="pub.hooks" (ngModelChange)="set('hooks', $event)"
|
||||
[placeholder]="'publication.hooksPlaceholder' | translate"></textarea>
|
||||
<small class="field-hint">{{ 'publication.listHint' | translate }}</small>
|
||||
</div>
|
||||
</app-expandable-section>
|
||||
|
||||
<app-expandable-section [title]="'publication.creditsSection' | translate" icon="©️"
|
||||
[filled]="filledAny('credits', 'legal')">
|
||||
<div class="field">
|
||||
<div class="field-label-row">
|
||||
<label for="pub-credits">{{ 'publication.creditsLabel' | translate }}</label>
|
||||
<app-writing-coach-trigger topic="publication.credits"></app-writing-coach-trigger>
|
||||
</div>
|
||||
<textarea id="pub-credits" rows="4" [ngModel]="pub.credits" (ngModelChange)="set('credits', $event)"
|
||||
[placeholder]="'publication.creditsPlaceholder' | translate"></textarea>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="pub-legal">{{ 'publication.legalLabel' | translate }}</label>
|
||||
<textarea id="pub-legal" rows="4" [ngModel]="pub.legal" (ngModelChange)="set('legal', $event)"
|
||||
[placeholder]="'publication.legalPlaceholder' | translate"></textarea>
|
||||
<small class="field-hint">{{ 'publication.legalHint' | translate }}</small>
|
||||
</div>
|
||||
</app-expandable-section>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<app-pdf-export-dialog
|
||||
[open]="pdfDialogOpen"
|
||||
[exporting]="exportingPdf"
|
||||
[showPublicationLink]="false"
|
||||
(cancelled)="pdfDialogOpen = false"
|
||||
(confirmed)="onPdfConfirmed($event)"></app-pdf-export-dialog>
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
.edit-page {
|
||||
padding: 2.5rem 2rem;
|
||||
max-width: 720px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
|
||||
button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.edit-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.optional-hint {
|
||||
margin: 0;
|
||||
padding: 0.6rem 0.85rem;
|
||||
background: rgba(108, 99, 255, 0.08);
|
||||
border: 1px solid rgba(108, 99, 255, 0.25);
|
||||
border-radius: 8px;
|
||||
color: #a5b4fc;
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.pub-error {
|
||||
padding: 0.6rem 0.9rem;
|
||||
border-radius: 8px;
|
||||
background: rgba(224, 90, 90, 0.12);
|
||||
border: 1px solid rgba(224, 90, 90, 0.4);
|
||||
color: #fca5a5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
// Couverture : champs à gauche, illustration (portrait 3/4) à droite.
|
||||
.cover-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 180px;
|
||||
gap: 1.25rem;
|
||||
align-items: start;
|
||||
|
||||
@media (max-width: 600px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
// Libellé de l'illustration (pas un <label> : le sélecteur d'image n'est pas un champ).
|
||||
.cover-label {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
color: #d1d5db;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.cover-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
app-expandable-section .field + .field { margin-top: 1rem; }
|
||||
|
||||
.field-hint { margin: 0 0 0.75rem; }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.edit-page { padding: 1rem; }
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { forkJoin, Observable, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { LucideAngularModule, ArrowLeft, Save, FileText } from 'lucide-angular';
|
||||
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||
import { CampaignPublication, CampaignService, PdfExportOptions } from '../../../services/campaign.service';
|
||||
import { CampaignSidebarService } from '../../../services/campaign-sidebar.service';
|
||||
import { PageTitleService } from '../../../services/page-title.service';
|
||||
import { ExpandableSectionComponent } from '../../../shared/expandable-section/expandable-section.component';
|
||||
import { SingleImagePickerComponent } from '../../../shared/single-image-picker/single-image-picker.component';
|
||||
import { WritingCoachTriggerComponent } from '../../../shared/writing-coach/writing-coach-trigger.component';
|
||||
import { PdfExportDialogComponent } from '../pdf-export-dialog/pdf-export-dialog.component';
|
||||
import { downloadBlob, safeFileName } from '../../../shared/download.util';
|
||||
|
||||
type PublicationField = Exclude<keyof CampaignPublication, 'coverImageId'>;
|
||||
|
||||
/**
|
||||
* Fiche « Publication » d'une campagne : ce que le PDF affiche quand l'aventure est
|
||||
* vendue ou partagée — couverture (sous-titre, auteur, illustration), page technique,
|
||||
* présentation, introduction pour le MJ, crédits et licence. Tout est facultatif ; une
|
||||
* fiche vide garde le livret de campagne habituel.
|
||||
* Route : /campaigns/:campaignId/publication
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-campaign-publication',
|
||||
imports: [FormsModule, LucideAngularModule, TranslatePipe, ExpandableSectionComponent,
|
||||
SingleImagePickerComponent, WritingCoachTriggerComponent, PdfExportDialogComponent],
|
||||
templateUrl: './campaign-publication.component.html',
|
||||
styleUrls: ['./campaign-publication.component.scss']
|
||||
})
|
||||
export class CampaignPublicationComponent implements OnInit {
|
||||
readonly ArrowLeft = ArrowLeft;
|
||||
readonly Save = Save;
|
||||
readonly FileText = FileText;
|
||||
|
||||
campaignId = '';
|
||||
campaignName = '';
|
||||
pub: CampaignPublication = {};
|
||||
/** Dernier état enregistré (JSON) : détecte les modifications non sauvegardées. */
|
||||
private savedSnapshot = '{}';
|
||||
|
||||
loading = true;
|
||||
saving = false;
|
||||
savedFlash = false;
|
||||
errorMessage = '';
|
||||
|
||||
pdfDialogOpen = false;
|
||||
exportingPdf = false;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private campaignService: CampaignService,
|
||||
private campaignSidebar: CampaignSidebarService,
|
||||
private pageTitle: PageTitleService,
|
||||
private translate: TranslateService,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.campaignId = this.route.snapshot.paramMap.get('campaignId') ?? '';
|
||||
if (!this.campaignId) return;
|
||||
this.campaignSidebar.show(this.campaignId);
|
||||
forkJoin({
|
||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||
publication: this.campaignService.getPublication(this.campaignId),
|
||||
}).subscribe({
|
||||
next: ({ campaign, publication }) => {
|
||||
this.campaignName = campaign.name;
|
||||
this.pageTitle.set(this.translate.instant('publication.pageTitle', { name: campaign.name }));
|
||||
this.pub = { ...publication };
|
||||
this.savedSnapshot = this.snapshot();
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.errorMessage = this.translate.instant('publication.loadError');
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get dirty(): boolean { return this.snapshot() !== this.savedSnapshot; }
|
||||
|
||||
/** Au moins un champ renseigné (le PDF passe alors en présentation « module »). */
|
||||
get filled(): boolean {
|
||||
return Object.values(this.pub).some(v => typeof v === 'string' && v.trim().length > 0);
|
||||
}
|
||||
|
||||
filledAny(...fields: (keyof CampaignPublication)[]): boolean {
|
||||
return fields.some(f => !!this.pub[f]?.trim());
|
||||
}
|
||||
|
||||
set(field: PublicationField, value: string): void {
|
||||
this.pub = { ...this.pub, [field]: value };
|
||||
}
|
||||
|
||||
setCover(id: string | null): void {
|
||||
this.pub = { ...this.pub, coverImageId: id };
|
||||
}
|
||||
|
||||
back(): void {
|
||||
this.router.navigate(['/campaigns', this.campaignId]);
|
||||
}
|
||||
|
||||
save(): void {
|
||||
this.persist().subscribe();
|
||||
}
|
||||
|
||||
/** Enregistre si besoin, puis émet la fiche à jour (ou rien en cas d'erreur). */
|
||||
private persist(): Observable<CampaignPublication | null> {
|
||||
if (!this.dirty) return of(this.pub);
|
||||
this.saving = true;
|
||||
this.errorMessage = '';
|
||||
return new Observable(observer => {
|
||||
this.campaignService.updatePublication(this.campaignId, this.pub).subscribe({
|
||||
next: saved => {
|
||||
this.pub = { ...saved };
|
||||
this.savedSnapshot = this.snapshot();
|
||||
this.saving = false;
|
||||
this.savedFlash = true;
|
||||
setTimeout(() => this.savedFlash = false, 1800);
|
||||
observer.next(saved);
|
||||
observer.complete();
|
||||
},
|
||||
error: () => {
|
||||
this.saving = false;
|
||||
this.errorMessage = this.translate.instant('publication.saveError');
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Export PDF : la fiche est d'abord enregistrée pour que le livret reflète l'écran. */
|
||||
onPdfConfirmed(opts: PdfExportOptions): void {
|
||||
if (this.exportingPdf) return;
|
||||
this.exportingPdf = true;
|
||||
this.persist().pipe(
|
||||
switchMap(saved => saved ? this.campaignService.exportPdf(this.campaignId, opts) : of(null))
|
||||
).subscribe({
|
||||
next: blob => {
|
||||
if (blob) {
|
||||
const suffix = opts.edition === 'player' ? '_joueurs' : '';
|
||||
downloadBlob(blob, `${safeFileName(this.campaignName, 'campagne')}${suffix}.pdf`);
|
||||
this.pdfDialogOpen = false;
|
||||
}
|
||||
this.exportingPdf = false;
|
||||
},
|
||||
error: () => {
|
||||
this.errorMessage = this.translate.instant('publication.exportError');
|
||||
this.exportingPdf = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private snapshot(): string {
|
||||
const clean: Record<string, string> = {};
|
||||
for (const [k, v] of Object.entries(this.pub)) {
|
||||
if (typeof v === 'string' && v.trim()) clean[k] = v.trim();
|
||||
}
|
||||
return JSON.stringify(clean, Object.keys(clean).sort());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
@if (open) {
|
||||
<div class="confirm-backdrop" (click)="onCancel()">
|
||||
<div class="confirm-modal variant-info"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
[attr.aria-label]="'pdfDialog.title' | translate"
|
||||
(click)="$event.stopPropagation()">
|
||||
<div class="confirm-header">
|
||||
<div class="confirm-icon">
|
||||
<lucide-icon [img]="FileText" [size]="20"></lucide-icon>
|
||||
</div>
|
||||
<h2>{{ 'pdfDialog.title' | translate }}</h2>
|
||||
<button type="button" class="btn-close" (click)="onCancel()" [attr.aria-label]="'common.close' | translate">
|
||||
<lucide-icon [img]="X" [size]="18"></lucide-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="confirm-body">
|
||||
@if (showPublicationLink) {
|
||||
<div class="pdf-publication" [class.empty]="!hasPublication">
|
||||
<lucide-icon [img]="BookOpen" [size]="16"></lucide-icon>
|
||||
<span>{{ (hasPublication ? 'pdfDialog.publicationFilled' : 'pdfDialog.publicationEmpty') | translate }}</span>
|
||||
<button type="button" class="link-btn" (click)="editPublication.emit()">
|
||||
{{ (hasPublication ? 'pdfDialog.publicationEdit' : 'pdfDialog.publicationFill') | translate }}
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="pdf-group">
|
||||
<span class="pdf-group-label">{{ 'pdfDialog.editionLabel' | translate }}</span>
|
||||
<div class="pdf-choice">
|
||||
<label class="pdf-choice-option" [class.selected]="edition === 'gm'">
|
||||
<input type="radio" name="pdf-edition" value="gm" [checked]="edition === 'gm'" (change)="setEdition('gm')" />
|
||||
<strong>{{ 'pdfDialog.editionGm' | translate }}</strong>
|
||||
<small>{{ 'pdfDialog.editionGmHint' | translate }}</small>
|
||||
</label>
|
||||
<label class="pdf-choice-option" [class.selected]="edition === 'player'">
|
||||
<input type="radio" name="pdf-edition" value="player" [checked]="edition === 'player'" (change)="setEdition('player')" />
|
||||
<strong>{{ 'pdfDialog.editionPlayer' | translate }}</strong>
|
||||
<small>{{ 'pdfDialog.editionPlayerHint' | translate }}</small>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pdf-group">
|
||||
<span class="pdf-group-label">{{ 'pdfDialog.sectionsLabel' | translate }}</span>
|
||||
<div class="pdf-sections">
|
||||
@for (s of allSections; track s) {
|
||||
<label class="pdf-check">
|
||||
<input type="checkbox" [attr.name]="'pdf-section-' + s" [checked]="has(s)" (change)="toggle(s)" />
|
||||
{{ ('pdfDialog.section.' + s) | translate }}
|
||||
</label>
|
||||
}
|
||||
</div>
|
||||
@if (has('LORE')) {
|
||||
<div class="pdf-lore">
|
||||
<label class="pdf-check">
|
||||
<input type="radio" name="pdf-lore" value="LINKED" [checked]="lore === 'LINKED'" (change)="lore = 'LINKED'" />
|
||||
{{ 'pdfDialog.loreLinked' | translate }}
|
||||
</label>
|
||||
<label class="pdf-check">
|
||||
<input type="radio" name="pdf-lore" value="ALL" [checked]="lore === 'ALL'" (change)="lore = 'ALL'" />
|
||||
{{ 'pdfDialog.loreAll' | translate }}
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="pdf-group pdf-inline">
|
||||
<label class="pdf-format">
|
||||
<span class="pdf-group-label">{{ 'pdfDialog.formatLabel' | translate }}</span>
|
||||
<select name="pdf-format" [value]="format" (change)="format = $any($event.target).value">
|
||||
<option value="A4">A4</option>
|
||||
<option value="A5">A5</option>
|
||||
<option value="LETTER">US Letter</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="pdf-check">
|
||||
<input type="checkbox" name="pdf-print" [checked]="print" (change)="print = !print" />
|
||||
<span>
|
||||
{{ 'pdfDialog.print' | translate }}
|
||||
<small>{{ 'pdfDialog.printHint' | translate }}</small>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="confirm-actions">
|
||||
<button type="button" class="btn-secondary" (click)="onCancel()" [disabled]="exporting">
|
||||
{{ 'common.cancel' | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-confirm" (click)="onConfirm()" [disabled]="nothingSelected || exporting">
|
||||
{{ (exporting ? 'campaignDetail.pdfExporting' : 'pdfDialog.confirm') | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
// Même squelette visuel que la modale d'export Foundry (backdrop/modal/header/actions),
|
||||
// avec un corps défilant : la modale reste utilisable sur téléphone.
|
||||
.confirm-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
backdrop-filter: blur(2px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 1rem;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
.confirm-modal {
|
||||
background: #111827;
|
||||
border: 1px solid #1f2937;
|
||||
border-radius: 16px;
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
max-height: calc(100dvh - 2rem);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
||||
overflow: hidden;
|
||||
|
||||
&.variant-info { border-top: 4px solid #6c63ff; }
|
||||
}
|
||||
|
||||
.confirm-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 1.1rem 1.5rem;
|
||||
border-bottom: 1px solid #1f2937;
|
||||
|
||||
h2 {
|
||||
flex: 1;
|
||||
color: white;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.confirm-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
background: rgba(108, 99, 255, 0.15);
|
||||
color: #6c63ff;
|
||||
}
|
||||
|
||||
.btn-close {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #6b7280;
|
||||
cursor: pointer;
|
||||
padding: 0.25rem;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
|
||||
&:hover { color: white; }
|
||||
}
|
||||
|
||||
.confirm-body {
|
||||
padding: 1.1rem 1.5rem;
|
||||
color: #d1d5db;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.5;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.pdf-publication {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
padding: 0.6rem 0.75rem;
|
||||
border-radius: 8px;
|
||||
background: rgba(108, 99, 255, 0.08);
|
||||
border: 1px solid rgba(108, 99, 255, 0.25);
|
||||
color: #c7d2fe;
|
||||
font-size: 0.85rem;
|
||||
|
||||
&.empty {
|
||||
background: rgba(234, 179, 8, 0.08);
|
||||
border-color: rgba(234, 179, 8, 0.3);
|
||||
color: #fde68a;
|
||||
}
|
||||
|
||||
span { flex: 1; min-width: 12rem; }
|
||||
}
|
||||
|
||||
.link-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
color: #a5b4fc;
|
||||
font-weight: 600;
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.pdf-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.45rem;
|
||||
}
|
||||
|
||||
.pdf-group-label {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: #9ca3af;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.pdf-choice {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.5rem;
|
||||
|
||||
@media (max-width: 480px) { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.pdf-choice-option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
padding: 0.6rem 0.75rem;
|
||||
border: 1px solid #1f2937;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
|
||||
&.selected { border-color: #6c63ff; background: rgba(108, 99, 255, 0.08); }
|
||||
|
||||
input { position: absolute; opacity: 0; pointer-events: none; }
|
||||
strong { color: white; font-size: 0.9rem; }
|
||||
small { color: #9ca3af; font-size: 0.78rem; line-height: 1.35; }
|
||||
}
|
||||
|
||||
.pdf-sections {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.35rem 1rem;
|
||||
|
||||
@media (max-width: 480px) { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.pdf-check {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
cursor: pointer;
|
||||
|
||||
input { margin-top: 0.25rem; accent-color: #6c63ff; }
|
||||
span { display: flex; flex-direction: column; }
|
||||
small { color: #9ca3af; font-size: 0.78rem; }
|
||||
}
|
||||
|
||||
.pdf-lore {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem 1.25rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-left: 2px solid #374151;
|
||||
margin-left: 0.4rem;
|
||||
}
|
||||
|
||||
.pdf-inline {
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
.pdf-format {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.3rem;
|
||||
|
||||
select {
|
||||
background: #1a1a2e;
|
||||
color: #e5e7eb;
|
||||
border: 1px solid #374151;
|
||||
border-radius: 8px;
|
||||
padding: 0.4rem 0.6rem;
|
||||
font: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.confirm-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.75rem;
|
||||
padding: 0.9rem 1.5rem;
|
||||
background: #0d121d;
|
||||
border-top: 1px solid #1f2937;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
padding: 0.6rem 1.25rem;
|
||||
background: #1f2937;
|
||||
color: #d1d5db;
|
||||
border: 1px solid #374151;
|
||||
border-radius: 8px;
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { background: #374151; }
|
||||
&:disabled { opacity: 0.6; cursor: default; }
|
||||
}
|
||||
|
||||
.btn-confirm {
|
||||
padding: 0.6rem 1.25rem;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
background: #6c63ff;
|
||||
|
||||
&:hover { background: #5b52e0; }
|
||||
&:disabled { opacity: 0.6; cursor: default; }
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
import { LucideAngularModule, FileText, X, BookOpen } from 'lucide-angular';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { PDF_SECTIONS, PdfExportOptions, PdfSection } from '../../../services/pdf-export.model';
|
||||
import { editionPreset, toExportOptions, toggleSection } from './pdf-export-presets';
|
||||
|
||||
/**
|
||||
* Modale des options de l'export PDF : version MJ ou joueurs, format de page, mode
|
||||
* impression, parties incluses et périmètre du lore. Passer en version joueurs
|
||||
* pré-sélectionne ce qui convient à des joueurs (sans bestiaire, quêtes ni tables,
|
||||
* lore limité aux pages liées) ; tout reste modifiable. Le parent télécharge au confirm.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-pdf-export-dialog',
|
||||
imports: [LucideAngularModule, TranslatePipe],
|
||||
templateUrl: './pdf-export-dialog.component.html',
|
||||
styleUrls: ['./pdf-export-dialog.component.scss']
|
||||
})
|
||||
export class PdfExportDialogComponent implements OnChanges {
|
||||
readonly FileText = FileText;
|
||||
readonly X = X;
|
||||
readonly BookOpen = BookOpen;
|
||||
readonly allSections = PDF_SECTIONS;
|
||||
|
||||
@Input() open = false;
|
||||
@Input() exporting = false;
|
||||
/** Faux = fiche Publication vide : la modale propose de la compléter. */
|
||||
@Input() hasPublication = true;
|
||||
/** Masque le lien vers la fiche (on est déjà dessus). */
|
||||
@Input() showPublicationLink = true;
|
||||
@Output() cancelled = new EventEmitter<void>();
|
||||
@Output() confirmed = new EventEmitter<PdfExportOptions>();
|
||||
@Output() editPublication = new EventEmitter<void>();
|
||||
|
||||
edition: 'gm' | 'player' = 'gm';
|
||||
format: 'A4' | 'A5' | 'LETTER' = 'A4';
|
||||
print = false;
|
||||
sections: ReadonlySet<PdfSection> = editionPreset('gm').sections;
|
||||
lore: 'ALL' | 'LINKED' = 'ALL';
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
// Réouverture : on repart du livret MJ complet (pas de parties fantômes d'un export précédent).
|
||||
if (changes['open']?.currentValue && !changes['open'].previousValue) this.setEdition('gm');
|
||||
}
|
||||
|
||||
get nothingSelected(): boolean { return this.sections.size === 0; }
|
||||
|
||||
setEdition(edition: 'gm' | 'player'): void {
|
||||
this.edition = edition;
|
||||
({ sections: this.sections, lore: this.lore } = editionPreset(edition));
|
||||
}
|
||||
|
||||
has(section: PdfSection): boolean { return this.sections.has(section); }
|
||||
|
||||
toggle(section: PdfSection): void {
|
||||
this.sections = toggleSection(this.sections, section);
|
||||
}
|
||||
|
||||
onCancel(): void {
|
||||
if (this.exporting) return;
|
||||
this.cancelled.emit();
|
||||
}
|
||||
|
||||
onConfirm(): void {
|
||||
if (this.exporting) return;
|
||||
const options = toExportOptions({
|
||||
edition: this.edition, format: this.format, print: this.print, sections: this.sections, lore: this.lore,
|
||||
});
|
||||
if (options) this.confirmed.emit(options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { editionPreset, toExportOptions, toggleSection, PdfExportChoice } from './pdf-export-presets';
|
||||
import { safeFileName } from '../../../shared/download.util';
|
||||
|
||||
describe('PDF export presets', () => {
|
||||
const gm = (): PdfExportChoice => ({ edition: 'gm', format: 'A4', print: false, ...editionPreset('gm') });
|
||||
|
||||
it('GM edition = complete booklet, whole lore', () => {
|
||||
expect(toExportOptions(gm())).toEqual({
|
||||
edition: 'gm', format: 'A4', print: false,
|
||||
sections: ['NARRATIVE', 'QUESTS', 'NPCS', 'ENEMIES', 'TABLES', 'LORE'], lore: 'ALL',
|
||||
});
|
||||
});
|
||||
|
||||
it('player edition preselects player-safe parts and linked lore only', () => {
|
||||
const o = toExportOptions({ edition: 'player', format: 'A5', print: true, ...editionPreset('player') })!;
|
||||
expect(o.sections).toEqual(['NARRATIVE', 'NPCS', 'LORE']);
|
||||
expect(o.lore).toBe('LINKED');
|
||||
expect(o.format).toBe('A5');
|
||||
expect(o.print).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps the canonical order when a section is unchecked then checked again', () => {
|
||||
const base = gm();
|
||||
const sections = toggleSection(toggleSection(base.sections, 'NARRATIVE'), 'NARRATIVE');
|
||||
expect(toExportOptions({ ...base, sections })!.sections[0]).toBe('NARRATIVE');
|
||||
expect(base.sections.has('NARRATIVE')).toBe(true); // ensemble d'origine intact
|
||||
});
|
||||
|
||||
it('refuses an empty selection', () => {
|
||||
expect(toExportOptions({ ...gm(), sections: new Set() })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('safeFileName', () => {
|
||||
it('matches the server-side slug', () => {
|
||||
expect(safeFileName("Les Cendres d'Été", 'campagne')).toBe('Les_Cendres_d_t');
|
||||
expect(safeFileName(' ', 'campagne')).toBe('campagne');
|
||||
expect(safeFileName(null, 'campagne')).toBe('campagne');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import { PDF_SECTIONS, PdfExportOptions, PdfSection } from '../../../services/pdf-export.model';
|
||||
|
||||
/** Choix de la modale d'export PDF (état éditable). */
|
||||
export interface PdfExportChoice {
|
||||
edition: 'gm' | 'player';
|
||||
format: 'A4' | 'A5' | 'LETTER';
|
||||
print: boolean;
|
||||
sections: ReadonlySet<PdfSection>;
|
||||
lore: 'ALL' | 'LINKED';
|
||||
}
|
||||
|
||||
/**
|
||||
* Préréglages d'une version : MJ = livret complet ; joueurs = ce qu'on peut leur montrer
|
||||
* (narration, PNJ, lore limité aux pages liées), sans bestiaire, quêtes ni tables.
|
||||
*/
|
||||
export function editionPreset(edition: 'gm' | 'player'): Pick<PdfExportChoice, 'sections' | 'lore'> {
|
||||
return edition === 'player'
|
||||
? { sections: new Set<PdfSection>(['NARRATIVE', 'NPCS', 'LORE']), lore: 'LINKED' }
|
||||
: { sections: new Set<PdfSection>(PDF_SECTIONS), lore: 'ALL' };
|
||||
}
|
||||
|
||||
/** Coche ou décoche une partie (nouvel ensemble, l'ancien n'est pas modifié). */
|
||||
export function toggleSection(sections: ReadonlySet<PdfSection>, section: PdfSection): Set<PdfSection> {
|
||||
const next = new Set(sections);
|
||||
if (next.has(section)) next.delete(section); else next.add(section);
|
||||
return next;
|
||||
}
|
||||
|
||||
/** Options envoyées au serveur, parties dans l'ordre canonique du livret ; null si rien n'est coché. */
|
||||
export function toExportOptions(choice: PdfExportChoice): PdfExportOptions | null {
|
||||
const sections = PDF_SECTIONS.filter(s => choice.sections.has(s));
|
||||
if (sections.length === 0) return null;
|
||||
return { edition: choice.edition, format: choice.format, print: choice.print, sections, lore: choice.lore };
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { CampaignReadinessAssessment } from './readiness.model';
|
||||
import { Npc } from './npc.model';
|
||||
import { RandomTable } from './random-table.model';
|
||||
import { Enemy } from './enemy.model';
|
||||
import { PdfExportOptions } from './pdf-export.model';
|
||||
|
||||
/**
|
||||
* Arbre de campagne AGRÉGÉ (une seule requête HTTP) — miroir de CampaignTreeDTO.
|
||||
@@ -36,6 +37,30 @@ export interface FoundryExportOptions {
|
||||
tables: boolean;
|
||||
}
|
||||
|
||||
export { PDF_SECTIONS } from './pdf-export.model';
|
||||
export type { PdfSection, PdfExportOptions } from './pdf-export.model';
|
||||
|
||||
/**
|
||||
* Fiche « Publication » d'une campagne (module à vendre ou à partager) : couverture,
|
||||
* page technique, introduction pour le MJ et page de crédits du PDF. Texte libre.
|
||||
*/
|
||||
export interface CampaignPublication {
|
||||
subtitle?: string | null;
|
||||
author?: string | null;
|
||||
system?: string | null;
|
||||
levels?: string | null;
|
||||
players?: string | null;
|
||||
duration?: string | null;
|
||||
pitch?: string | null;
|
||||
gmBackground?: string | null;
|
||||
hooks?: string | null;
|
||||
contentWarnings?: string | null;
|
||||
credits?: string | null;
|
||||
legal?: string | null;
|
||||
version?: string | null;
|
||||
coverImageId?: string | null;
|
||||
}
|
||||
|
||||
/** Compte des entités qui seront supprimées en cascade avec la campagne. */
|
||||
export interface CampaignDeletionImpact {
|
||||
arcs: number;
|
||||
@@ -106,8 +131,25 @@ export class CampaignService {
|
||||
}
|
||||
|
||||
/** Génère et télécharge le livret PDF de la campagne. */
|
||||
exportPdf(id: string): Observable<Blob> {
|
||||
return this.http.get(`${this.apiUrl}/${id}/pdf-export`, { responseType: 'blob' });
|
||||
exportPdf(id: string, opts?: PdfExportOptions): Observable<Blob> {
|
||||
let params = new HttpParams();
|
||||
if (opts) {
|
||||
params = params
|
||||
.set('edition', opts.edition)
|
||||
.set('format', opts.format)
|
||||
.set('print', String(opts.print))
|
||||
.set('sections', opts.sections.join(','))
|
||||
.set('lore', opts.lore);
|
||||
}
|
||||
return this.http.get(`${this.apiUrl}/${id}/pdf-export`, { responseType: 'blob', params });
|
||||
}
|
||||
|
||||
getPublication(id: string): Observable<CampaignPublication> {
|
||||
return this.http.get<CampaignPublication>(`${this.apiUrl}/${id}/publication`);
|
||||
}
|
||||
|
||||
updatePublication(id: string, publication: CampaignPublication): Observable<CampaignPublication> {
|
||||
return this.http.put<CampaignPublication>(`${this.apiUrl}/${id}/publication`, publication);
|
||||
}
|
||||
|
||||
createCampaign(campaign: CampaignCreate): Observable<Campaign> {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/** Parties du livret PDF qu'on peut inclure ou non (miroir de PdfExportOptions.Section). */
|
||||
export type PdfSection = 'NARRATIVE' | 'QUESTS' | 'NPCS' | 'ENEMIES' | 'TABLES' | 'LORE';
|
||||
|
||||
/** Ordre canonique des parties dans le livret. */
|
||||
export const PDF_SECTIONS: PdfSection[] = ['NARRATIVE', 'QUESTS', 'NPCS', 'ENEMIES', 'TABLES', 'LORE'];
|
||||
|
||||
/**
|
||||
* Options de l'export PDF (modale) :
|
||||
* - edition : 'gm' = livret MJ complet ; 'player' = version joueurs sans aucun secret.
|
||||
* - format : A4, A5 ou US Letter.
|
||||
* - print : sans aplats de couleur (économie d'encre).
|
||||
* - sections : parties incluses.
|
||||
* - lore : toutes les pages du lore, ou seulement celles liées au contenu de la campagne.
|
||||
*/
|
||||
export interface PdfExportOptions {
|
||||
edition: 'gm' | 'player';
|
||||
format: 'A4' | 'A5' | 'LETTER';
|
||||
print: boolean;
|
||||
sections: PdfSection[];
|
||||
lore: 'ALL' | 'LINKED';
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/** Déclenche le téléchargement d'un fichier reçu en Blob (lien temporaire). */
|
||||
export function downloadBlob(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
|
||||
/** Nom de fichier sûr (alphanumérique, tirets, soulignés), comme côté serveur. */
|
||||
export function safeFileName(name: string | null | undefined, fallback: string): string {
|
||||
let slug = (name || '').trim().replace(/[^a-zA-Z0-9-_]+/g, '_');
|
||||
// Au plus un « _ » de bord après la fusion ci-dessus : retiré sans regex ancrée.
|
||||
if (slug.startsWith('_')) slug = slug.slice(1);
|
||||
if (slug.endsWith('_')) slug = slug.slice(0, -1);
|
||||
return slug || fallback;
|
||||
}
|
||||
Reference in New Issue
Block a user