All checks were successful
Corrections fonctionnelles - order initialisé à la création des pages et dossiers de lore (nextOrderFor) : un nouvel élément se place désormais en dernier de sa fratrie au lieu de 0 - storePortrait : type MIME canonique dérivé de l'extension du fichier (un data URL "image/jpg" n'est plus rejeté silencieusement) - takeUntilDestroyed ajouté sur les abonnements paramMap de arc-view, folder-view et campaign-detail (fuites mémoire) Factorisation (suppression de duplication) - shared/folder-grouping.util.ts : groupByFolder + byOrder + byFolderName mutualisés entre npc-list, enemy-list, campaign-detail et la sidebar (folderChildren). Le tri des dossiers est désormais cohérent entre la sidebar et les vues cartes (insensible casse/accents partout) - DataSyncService.onChange()/persist() remplacent le câblage changed$ + reorder recopié dans 5 vues - campaign-detail : loadCampaignBundle()/applyCampaignBundle() éliminent le forkJoin dupliqué entre ngOnInit et reload - ReorderSupport (domain/shared) : squelette générique remplaçant les 8 boucles de réordonnancement copiées dans les services - FoundryExportService : GameSystem résolu une seule fois dans buildBundle - module Foundry : walkScalars mutualise la récursion de flattenStats et flattenStructure (comportements préservés) ; esc() de l'importer aligné sur foundry.utils.escapeHTML Suppression de code mort - characterService/characters retirés de loadCampaignTreeData et de ses 16 appelants (arguments, injections, imports et littéraux CampaignTreeData) - CSS orphelin : .tree-row.cdk-drop-list-receiving et .btn-back - BottomPanel.initiallyOpen (jamais lu) retiré de l'interface et de l'appelant - commentaire trompeur du PDF corrigé Tests - mise à jour de 3 tests obsolètes de campaign-tree.helper.spec qui vérifiaient encore l'ancien comportement (tri alphabétique, non-classés en enfants directs) → alignés sur le modèle actuel (tri par order + pseudo-dossier "Sans dossier")
222 lines
8.8 KiB
TypeScript
222 lines
8.8 KiB
TypeScript
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
|
|
import { ReactiveFormsModule, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { forkJoin, of } from 'rxjs';
|
|
import { switchMap } from 'rxjs/operators';
|
|
import { LucideAngularModule, Trash2, Sparkles } from 'lucide-angular';
|
|
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
|
import { CampaignService } from '../../../services/campaign.service';
|
|
import { NpcService } from '../../../services/npc.service';
|
|
import { RandomTableService } from '../../../services/random-table.service';
|
|
import { EnemyService } from '../../../services/enemy.service';
|
|
import { PageService } from '../../../services/page.service';
|
|
import { LayoutService } from '../../../services/layout.service';
|
|
import { PageTitleService } from '../../../services/page-title.service';
|
|
import { Chapter, Prerequisite, Arc } from '../../../services/campaign.model';
|
|
import { Page } from '../../../services/page.model';
|
|
import { loadCampaignTreeData, buildCampaignSidebarConfig } from '../../campaign-tree.helper';
|
|
import { LoreLinkPickerComponent } from '../../../shared/lore-link-picker/lore-link-picker.component';
|
|
import { AiChatDrawerComponent } from '../../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
|
import { ImageGalleryComponent } from '../../../shared/image-gallery/image-gallery.component';
|
|
import { IconPickerComponent } from '../../../shared/icon-picker/icon-picker.component';
|
|
import { PrerequisiteEditorComponent } from '../../../shared/prerequisite-editor/prerequisite-editor.component';
|
|
import { CampaignFlagService } from '../../../services/campaign-flag.service';
|
|
import { CAMPAIGN_ICON_OPTIONS } from '../../campaign-icons';
|
|
import { ConfirmDialogService } from '../../../shared/confirm-dialog/confirm-dialog.service';
|
|
|
|
/**
|
|
* Écran d'édition d'un Chapitre. Donnée de SCÉNARIO uniquement.
|
|
*
|
|
* Depuis Playthrough : la progression et le toggle des flags se font dans le
|
|
* contexte d'une Partie (voir Playthrough Detail). On garde ici uniquement les
|
|
* prérequis (conditions de déblocage), qui font partie du scénario.
|
|
*/
|
|
@Component({
|
|
selector: 'app-chapter-edit',
|
|
imports: [
|
|
ReactiveFormsModule,
|
|
LucideAngularModule,
|
|
LoreLinkPickerComponent,
|
|
AiChatDrawerComponent,
|
|
ImageGalleryComponent,
|
|
IconPickerComponent,
|
|
PrerequisiteEditorComponent,
|
|
TranslatePipe
|
|
],
|
|
templateUrl: './chapter-edit.component.html',
|
|
styleUrls: ['./chapter-edit.component.scss']
|
|
})
|
|
export class ChapterEditComponent implements OnInit, OnDestroy {
|
|
readonly Trash2 = Trash2;
|
|
readonly Sparkles = Sparkles;
|
|
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
|
|
selectedIcon: string | null = null;
|
|
|
|
chatOpen = false;
|
|
readonly chatQuickSuggestions: string[];
|
|
|
|
toggleChat(): void { this.chatOpen = !this.chatOpen; }
|
|
|
|
form: FormGroup;
|
|
campaignId = '';
|
|
arcId = '';
|
|
chapterId = '';
|
|
chapter: Chapter | null = null;
|
|
|
|
availablePages: Page[] = [];
|
|
loreId: string | null = null;
|
|
relatedPageIds: string[] = [];
|
|
illustrationImageIds: string[] = [];
|
|
|
|
/** Prérequis (donnée de scénario). */
|
|
prerequisites: Prerequisite[] = [];
|
|
|
|
/** Quêtes candidates pour QUEST_COMPLETED (chapitres de la campagne, sauf celui-ci). */
|
|
availableQuests: Chapter[] = [];
|
|
|
|
/** Faits déclarés au niveau Campagne (autocomplete FLAG_SET). */
|
|
availableFlagNames: string[] = [];
|
|
|
|
/** L'arc parent — pour conditionner la section Hub (prérequis pertinents). */
|
|
parentArc: Arc | null = null;
|
|
|
|
constructor(
|
|
private fb: FormBuilder,
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private campaignService: CampaignService,
|
|
private npcService: NpcService,
|
|
private randomTableService: RandomTableService,
|
|
private enemyService: EnemyService,
|
|
private pageService: PageService,
|
|
private layoutService: LayoutService,
|
|
private pageTitleService: PageTitleService,
|
|
private confirmDialog: ConfirmDialogService,
|
|
private campaignFlagService: CampaignFlagService,
|
|
private translate: TranslateService
|
|
) {
|
|
this.form = this.fb.group({
|
|
name: ['', Validators.required],
|
|
description: [''],
|
|
gmNotes: [''],
|
|
playerObjectives: [''],
|
|
narrativeStakes: ['']
|
|
});
|
|
this.chatQuickSuggestions = [
|
|
this.translate.instant('chapterEdit.chatSuggestion1'),
|
|
this.translate.instant('chapterEdit.chatSuggestion2'),
|
|
this.translate.instant('chapterEdit.chatSuggestion3')
|
|
];
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.route.paramMap.subscribe(pm => {
|
|
const newCampaignId = pm.get('campaignId')!;
|
|
const newArcId = pm.get('arcId')!;
|
|
const newChapterId = pm.get('chapterId')!;
|
|
if (newChapterId !== this.chapterId ||
|
|
newArcId !== this.arcId ||
|
|
newCampaignId !== this.campaignId) {
|
|
this.campaignId = newCampaignId;
|
|
this.arcId = newArcId;
|
|
this.chapterId = newChapterId;
|
|
this.loadAll();
|
|
}
|
|
});
|
|
}
|
|
|
|
private loadAll(): void {
|
|
forkJoin({
|
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
|
chapter: this.campaignService.getChapterById(this.chapterId),
|
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.npcService, this.randomTableService, this.enemyService)
|
|
}).pipe(
|
|
switchMap(data => {
|
|
const lid = data.campaign.loreId ?? null;
|
|
const pages$ = lid ? this.pageService.getByLoreId(lid) : of([] as Page[]);
|
|
return pages$.pipe(switchMap(pages => of({ ...data, pages, loreId: lid })));
|
|
})
|
|
).subscribe(({ campaign, allCampaigns, chapter, treeData, pages, loreId }) => {
|
|
this.chapter = chapter;
|
|
this.pageTitleService.set(chapter.name);
|
|
this.loreId = loreId;
|
|
this.availablePages = pages;
|
|
this.relatedPageIds = [...(chapter.relatedPageIds ?? [])];
|
|
this.selectedIcon = chapter.icon ?? null;
|
|
this.illustrationImageIds = [...(chapter.illustrationImageIds ?? [])];
|
|
|
|
this.prerequisites = [...(chapter.prerequisites ?? [])];
|
|
|
|
const allChapters: Chapter[] = [];
|
|
Object.values(treeData.chaptersByArc).forEach(list => allChapters.push(...list));
|
|
this.availableQuests = allChapters.filter(c => c.id !== this.chapterId);
|
|
|
|
this.parentArc = treeData.arcs.find(a => a.id === this.arcId) ?? null;
|
|
|
|
// Autocomplete des FLAG_SET : les noms de faits déjà référencés ailleurs
|
|
// dans la campagne (déduit des autres quêtes).
|
|
this.campaignFlagService.listReferenced(this.campaignId).subscribe({
|
|
next: names => { this.availableFlagNames = names; }
|
|
});
|
|
|
|
this.form.patchValue({
|
|
name: chapter.name,
|
|
description: chapter.description ?? '',
|
|
gmNotes: chapter.gmNotes ?? '',
|
|
playerObjectives: chapter.playerObjectives ?? '',
|
|
narrativeStakes: chapter.narrativeStakes ?? ''
|
|
});
|
|
|
|
this.layoutService.show(buildCampaignSidebarConfig(campaign, allCampaigns, treeData, this.campaignId, this.translate));
|
|
});
|
|
}
|
|
|
|
onPrerequisitesChange(next: Prerequisite[]): void {
|
|
this.prerequisites = next;
|
|
}
|
|
|
|
submit(): void {
|
|
if (this.form.invalid || !this.chapter) return;
|
|
this.campaignService.updateChapter(this.chapterId, {
|
|
name: this.form.value.name,
|
|
description: this.form.value.description,
|
|
arcId: this.arcId,
|
|
order: this.chapter.order ?? 1,
|
|
gmNotes: this.form.value.gmNotes,
|
|
playerObjectives: this.form.value.playerObjectives,
|
|
narrativeStakes: this.form.value.narrativeStakes,
|
|
prerequisites: this.prerequisites,
|
|
relatedPageIds: this.relatedPageIds,
|
|
illustrationImageIds: this.illustrationImageIds,
|
|
icon: this.selectedIcon
|
|
}).subscribe({
|
|
next: () => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId]),
|
|
error: () => console.error('Erreur lors de la sauvegarde')
|
|
});
|
|
}
|
|
|
|
delete(): void {
|
|
this.confirmDialog.confirm({
|
|
title: this.translate.instant('chapterEdit.deleteTitle'),
|
|
message: this.translate.instant('chapterEdit.deleteMessage', { name: this.chapter?.name }),
|
|
details: [this.translate.instant('chapterEdit.irreversible')],
|
|
confirmLabel: this.translate.instant('common.delete'),
|
|
variant: 'danger'
|
|
}).then(ok => {
|
|
if (!ok) return;
|
|
this.campaignService.deleteChapter(this.chapterId).subscribe({
|
|
next: () => this.router.navigate(['/campaigns', this.campaignId]),
|
|
error: () => console.error('Erreur lors de la suppression')
|
|
});
|
|
});
|
|
}
|
|
|
|
cancel(): void {
|
|
this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId]);
|
|
}
|
|
|
|
ngOnDestroy(): void {}
|
|
}
|