Mise en ligne de la version 0.2.0
All checks were successful
Build & Push Images / build (brain) (push) Successful in 46s
Build & Push Images / build (core) (push) Successful in 1m21s
Build & Push Images / build (web) (push) Successful in 1m25s

This commit is contained in:
2026-04-21 14:25:17 +02:00
parent ebee8e106b
commit ba8a503b3e
300 changed files with 35329 additions and 1 deletions

View File

@@ -0,0 +1,93 @@
<div class="campaign-detail" *ngIf="campaign">
<!-- ============ Header : mode lecture ============ -->
<div class="detail-header" *ngIf="!editing">
<div class="header-texts">
<h1>{{ campaign.name }}</h1>
<p class="description">{{ campaign.description }}</p>
<div class="meta">
<span class="badge">{{ campaign.playerCount || 0 }} joueurs</span>
<!-- Badge "Univers" : lien vers le Lore associé si présent -->
<a *ngIf="linkedLore"
class="badge badge-lore"
[routerLink]="['/lore', linkedLore.id]"
title="Ouvrir l'univers associé">
<lucide-icon [img]="Globe" [size]="12"></lucide-icon>
{{ linkedLore.name }}
</a>
<!-- Campagne liée à un Lore qui n'existe plus (supprimé ailleurs) -->
<span *ngIf="campaign.loreId && !linkedLore" class="badge badge-lore-missing" title="L'univers associé est introuvable">
<lucide-icon [img]="Globe" [size]="12"></lucide-icon>
Univers introuvable
</span>
</div>
</div>
<div class="header-actions">
<button type="button" class="btn-secondary" (click)="startEdit()">
<lucide-icon [img]="Pencil" [size]="14"></lucide-icon>
Modifier
</button>
<button type="button" class="btn-danger" (click)="deleteCampaign()">
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
Supprimer
</button>
</div>
</div>
<!-- ============ Header : mode édition inline ============ -->
<div class="detail-header edit-mode" *ngIf="editing">
<div class="field">
<label>Nom</label>
<input type="text" [(ngModel)]="editName" name="editName" required />
</div>
<div class="field">
<label>Description</label>
<textarea [(ngModel)]="editDescription" name="editDescription" rows="3"></textarea>
</div>
<div class="field">
<label>Univers associé</label>
<select [(ngModel)]="editLoreId" name="editLoreId">
<option value="">— Aucun univers (campagne libre) —</option>
<option *ngFor="let lore of availableLores" [value]="lore.id">{{ lore.name }}</option>
</select>
</div>
<div class="header-actions">
<button type="button" class="btn-primary" (click)="saveEdit()" [disabled]="!editName.trim()">
Sauvegarder
</button>
<button type="button" class="btn-secondary" (click)="cancelEdit()">
Annuler
</button>
</div>
</div>
<div class="arcs-section">
<div class="section-header">
<h2>Arcs narratifs</h2>
<button class="btn-add">
<lucide-icon [img]="Plus" [size]="14"></lucide-icon>
Nouvel arc
</button>
</div>
<div class="arcs-grid" *ngIf="arcs.length > 0">
<div class="arc-card" *ngFor="let arc of arcs">
<lucide-icon [img]="Swords" [size]="24" class="arc-icon"></lucide-icon>
<span class="arc-name">{{ arc.name }}</span>
<span class="arc-meta">{{ arc.chapterCount || 0 }} chapitres</span>
</div>
</div>
<div class="empty-state" *ngIf="arcs.length === 0">
<lucide-icon [img]="Swords" [size]="40" class="empty-icon"></lucide-icon>
<p>Aucun arc narratif pour le moment.</p>
<button class="btn-add-first">
<lucide-icon [img]="Plus" [size]="14"></lucide-icon>
Créer votre premier arc
</button>
</div>
</div>
</div>

View File

@@ -0,0 +1,203 @@
.campaign-detail {
padding: 2.5rem 2rem;
}
.detail-header {
margin-bottom: 2.5rem;
h1 {
font-size: 1.75rem;
font-weight: 700;
color: white;
margin-bottom: 0.5rem;
}
.description {
color: #6b7280;
font-size: 0.95rem;
line-height: 1.6;
margin-bottom: 1rem;
}
.meta {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
align-items: center;
}
.badge {
display: inline-flex;
align-items: center;
gap: 0.35rem;
background: #1e3a5f;
color: #60a5fa;
font-size: 0.75rem;
font-weight: 600;
padding: 0.25rem 0.75rem;
border-radius: 999px;
text-decoration: none;
}
// Lien cliquable vers le Lore associé (weak cross-context link).
.badge-lore {
background: #2d2450;
color: #a78bfa;
transition: background 0.15s ease;
&:hover {
background: #3d3168;
cursor: pointer;
}
}
// Cas dégradé : loreId renseigné mais Lore introuvable (supprimé).
.badge-lore-missing {
background: #3a1e1e;
color: #f87171;
font-style: italic;
}
}
.detail-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1.5rem;
.header-texts { flex: 1; min-width: 0; }
.header-actions {
display: flex;
gap: 0.5rem;
flex-shrink: 0;
}
// Variante mode édition : champs empilés verticalement.
&.edit-mode {
flex-direction: column;
align-items: stretch;
.field {
display: flex;
flex-direction: column;
gap: 0.35rem;
margin-bottom: 1rem;
label { color: #9ca3af; font-size: 0.8rem; font-weight: 500; }
input, textarea, select {
background: #0f172a;
border: 1px solid #1f2937;
border-radius: 8px;
color: white;
padding: 0.6rem 0.85rem;
font-size: 0.9rem;
font-family: inherit;
&:focus { outline: none; border-color: #6c63ff; }
}
textarea { resize: vertical; }
}
.header-actions { justify-content: flex-end; }
}
}
// Boutons partagés.
.btn-primary, .btn-secondary, .btn-danger {
display: inline-flex;
align-items: center;
gap: 0.4rem;
padding: 0.5rem 1rem;
border: none;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
transition: background 0.15s;
&:disabled { opacity: 0.5; cursor: not-allowed; }
}
.btn-primary { background: #6c63ff; color: white; &:hover:not(:disabled) { background: #5b52e0; } }
.btn-secondary { background: #1f2937; color: #d1d5db; &:hover:not(:disabled) { background: #374151; } }
.btn-danger { background: #3a1e1e; color: #f87171; &:hover:not(:disabled) { background: #5a2e2e; } }
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1.5rem;
h2 { color: #d1d5db; font-size: 1rem; font-weight: 600; }
}
.btn-add {
display: flex;
align-items: center;
gap: 0.4rem;
padding: 0.5rem 1rem;
background: #6c63ff;
color: white;
border: none;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
&:hover { background: #5b52e0; }
}
.arcs-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
gap: 1rem;
}
.arc-card {
background: #111827;
border: 1px solid #1f2937;
border-radius: 10px;
padding: 1.25rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
cursor: pointer;
transition: border-color 0.2s, transform 0.2s;
&:hover { border-color: #6c63ff; transform: translateY(-2px); }
.arc-icon { color: #6c63ff; }
.arc-name { color: white; font-size: 0.9rem; font-weight: 600; }
.arc-meta { color: #6b7280; font-size: 0.75rem; }
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
padding: 4rem 2rem;
color: #6b7280;
.empty-icon { color: #374151; }
p { font-size: 0.95rem; }
}
.btn-add-first {
display: flex;
align-items: center;
gap: 0.4rem;
padding: 0.6rem 1.25rem;
background: #6c63ff;
color: white;
border: none;
border-radius: 8px;
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
&:hover { background: #5b52e0; }
}

View File

@@ -0,0 +1,194 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { LucideAngularModule, Swords, Plus, Globe, Pencil, Trash2 } from 'lucide-angular';
import { Router, RouterLink } from '@angular/router';
import { forkJoin, of } from 'rxjs';
import { catchError, switchMap, filter, map } from 'rxjs/operators';
import { CampaignService } from '../../services/campaign.service';
import { LoreService } from '../../services/lore.service';
import { LayoutService, GlobalItem } from '../../services/layout.service';
import { PageTitleService } from '../../services/page-title.service';
import { Campaign, Arc } from '../../services/campaign.model';
import { Lore } from '../../services/lore.model';
import { loadCampaignTreeData, buildCampaignTree, CampaignTreeData } from '../campaign-tree.helper';
@Component({
selector: 'app-campaign-detail',
standalone: true,
imports: [CommonModule, FormsModule, LucideAngularModule, RouterLink],
templateUrl: './campaign-detail.component.html',
styleUrls: ['./campaign-detail.component.scss']
})
export class CampaignDetailComponent implements OnInit, OnDestroy {
readonly Swords = Swords;
readonly Plus = Plus;
readonly Globe = Globe;
readonly Pencil = Pencil;
readonly Trash2 = Trash2;
campaign: Campaign | null = null;
arcs: Arc[] = [];
/** Lore associé si `campaign.loreId` est renseigné ; sinon null. */
linkedLore: Lore | null = null;
/** Lores disponibles pour changer l'association en mode édition. */
availableLores: Lore[] = [];
/** Mode édition inline. */
editing = false;
editName = '';
editDescription = '';
editLoreId = '';
constructor(
private route: ActivatedRoute,
private router: Router,
private campaignService: CampaignService,
private loreService: LoreService,
private layoutService: LayoutService,
private pageTitleService: PageTitleService
) {}
ngOnInit(): void {
// switchMap annule automatiquement le load précédent si l'utilisateur
// change de campagne avant que le forkJoin ne réponde — évite qu'une
// réponse en retard écrase des données plus récentes (race condition).
this.route.paramMap.pipe(
map(pm => pm.get('id')),
filter((id): id is string => !!id && id !== this.campaign?.id),
switchMap(id => forkJoin({
campaign: this.campaignService.getCampaignById(id),
allCampaigns: this.campaignService.getAllCampaigns(),
treeData: loadCampaignTreeData(this.campaignService, id).pipe(
catchError(() => of({ arcs: [], chaptersByArc: {}, scenesByChapter: {} } as CampaignTreeData))
)
}))
).subscribe(({ campaign, allCampaigns, treeData }) => {
this.campaign = campaign;
this.editing = false;
this.loadLinkedLore(campaign);
this.arcs = treeData.arcs;
this.showLayout(allCampaigns, treeData);
this.pageTitleService.set(campaign.name);
});
}
/**
* Recharge explicitement après une mise à jour locale (ex: saveEdit).
* Contrairement au flux ngOnInit, on bypass le filter sur l'ID puisqu'on
* veut rafraîchir même si l'ID n'a pas changé.
*/
private reload(id: string): void {
forkJoin({
campaign: this.campaignService.getCampaignById(id),
allCampaigns: this.campaignService.getAllCampaigns(),
treeData: loadCampaignTreeData(this.campaignService, id).pipe(
catchError(() => of({ arcs: [], chaptersByArc: {}, scenesByChapter: {} } as CampaignTreeData))
)
}).subscribe(({ campaign, allCampaigns, treeData }) => {
this.campaign = campaign;
this.editing = false;
this.loadLinkedLore(campaign);
this.arcs = treeData.arcs;
this.showLayout(allCampaigns, treeData);
this.pageTitleService.set(campaign.name);
});
}
/**
* Charge le Lore associé (si loreId présent). On swallow l'erreur :
* si le Lore a été supprimé entre-temps, on affiche simplement "Univers introuvable".
*/
private loadLinkedLore(campaign: Campaign): void {
if (!campaign.loreId) {
this.linkedLore = null;
return;
}
this.loreService.getLoreById(campaign.loreId).pipe(
catchError(() => of(null))
).subscribe(lore => this.linkedLore = lore);
}
private showLayout(allCampaigns: Campaign[], data: CampaignTreeData): void {
const campaignId = this.campaign!.id!;
const globalItems: GlobalItem[] = allCampaigns.map(c => ({
id: c.id!,
name: c.name,
route: `/campaigns/${c.id}`
}));
this.layoutService.show({
title: this.campaign!.name,
items: buildCampaignTree(campaignId, data),
footerLabel: 'Toutes les campagnes',
createActions: [
{ id: 'create-arc', label: '+ Nouvel arc', variant: 'primary', route: `/campaigns/${campaignId}/arcs/create` }
],
globalItems,
globalBackLabel: 'Toutes les campagnes',
globalBackRoute: '/campaigns'
});
}
// ─────────────── Édition / suppression de la Campagne ───────────────
startEdit(): void {
if (!this.campaign) return;
this.editName = this.campaign.name;
this.editDescription = this.campaign.description ?? '';
this.editLoreId = this.campaign.loreId ?? '';
// On charge les Lores disponibles pour le select uniquement à l'entrée en mode édition.
this.loreService.getAllLores().subscribe({
next: (lores) => this.availableLores = lores,
error: () => this.availableLores = []
});
this.editing = true;
}
cancelEdit(): void {
this.editing = false;
}
saveEdit(): void {
if (!this.campaign || !this.editName.trim()) return;
this.campaignService.updateCampaign(this.campaign.id!, {
name: this.editName.trim(),
description: this.editDescription,
playerCount: this.campaign.playerCount ?? 0,
loreId: this.editLoreId ? this.editLoreId : null
}).subscribe({
next: (updated) => {
this.campaign = updated;
this.editing = false;
// Recharge pour actualiser le badge "Univers" et le titre sidebar.
this.reload(updated.id!);
},
error: () => console.error('Erreur lors de la mise à jour de la campagne')
});
}
/**
* Suppression protégée : refus si la campagne contient des arcs.
* Les arcs contiennent potentiellement des chapitres/scènes construits longuement.
*/
deleteCampaign(): void {
if (!this.campaign) return;
if (this.arcs.length > 0) {
alert(
`Impossible de supprimer "${this.campaign.name}" : elle contient encore ${this.arcs.length} arc(s).\n` +
`Videz la campagne (arcs et chapitres) avant de la supprimer.`
);
return;
}
if (!confirm(`Supprimer définitivement la campagne "${this.campaign.name}" ?`)) return;
this.campaignService.deleteCampaign(this.campaign.id!).subscribe({
next: () => this.router.navigate(['/campaigns']),
error: () => console.error('Erreur lors de la suppression de la campagne')
});
}
ngOnDestroy(): void {
this.layoutService.hide();
}
}