Améliore la navigation et la mise en page des exports PDF
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 37s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m37s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 1m1s
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 37s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m37s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 1m1s
- Ajoute les fils d’Ariane, les favoris et l’historique de navigation - Étend la recherche aux arcs, chapitres, scènes et quêtes - Regroupe les actions de campagne dans le menu Gérer - Améliore la navigation au clavier et sur mobile - Refonte de l’export A4 : deux colonnes, couverture illustrée et encadrés - Ajoute des motifs décoratifs en pied de page et une variante pour l’impression - Vérifie la pagination, les renvois et la confidentialité de l’édition joueurs
This commit is contained in:
@@ -63,6 +63,7 @@
|
||||
}
|
||||
|
||||
<main #mainContent class="main-content" tabindex="-1">
|
||||
<app-campaign-breadcrumb></app-campaign-breadcrumb>
|
||||
<router-outlet></router-outlet>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { LucideAngularModule, Menu, PanelLeft, Search, X } from 'lucide-angular';
|
||||
import { filter, map } from 'rxjs';
|
||||
import { SidebarComponent } from './sidebar/sidebar.component';
|
||||
import { CampaignBreadcrumbComponent } from './shared/breadcrumb/campaign-breadcrumb.component';
|
||||
import { SecondarySidebarComponent } from './shared/secondary-sidebar/secondary-sidebar.component';
|
||||
import { GlobalSearchComponent } from './shared/global-search/global-search.component';
|
||||
import { UpdateBannerComponent } from './shared/update-banner/update-banner.component';
|
||||
@@ -29,6 +30,7 @@ const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), selec
|
||||
selector: 'app-root',
|
||||
imports: [
|
||||
RouterOutlet,
|
||||
CampaignBreadcrumbComponent,
|
||||
LucideAngularModule,
|
||||
TranslatePipe,
|
||||
SidebarComponent,
|
||||
|
||||
@@ -40,22 +40,27 @@
|
||||
<lucide-icon [img]="Network" [size]="14"></lucide-icon>
|
||||
{{ 'campaignDetail.graph' | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary" (click)="exportPdf()" [disabled]="exportingPdf">
|
||||
<lucide-icon [img]="FileText" [size]="14"></lucide-icon>
|
||||
{{ (exportingPdf ? 'campaignDetail.pdfExporting' : 'campaignDetail.pdfExport') | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary" (click)="exportFoundry()" [disabled]="exportingFoundry">
|
||||
<lucide-icon [img]="Download" [size]="14"></lucide-icon>
|
||||
{{ (exportingFoundry ? 'campaignDetail.foundryExporting' : 'campaignDetail.foundryExport') | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary" (click)="startEdit()">
|
||||
<details #managementMenu class="management-menu" (keydown.escape)="managementMenu.open = false; managementToggle.focus()">
|
||||
<summary #managementToggle class="btn-secondary">{{ 'campaignDetail.manage' | translate }}</summary>
|
||||
<div class="management-actions">
|
||||
<button type="button" class="btn-secondary" (click)="managementMenu.open = false; startEdit()">
|
||||
<lucide-icon [img]="Pencil" [size]="14"></lucide-icon>
|
||||
{{ 'common.edit' | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-danger" (click)="deleteCampaign()">
|
||||
<button type="button" class="btn-secondary" (click)="managementMenu.open = false; exportPdf()" [disabled]="exportingPdf">
|
||||
<lucide-icon [img]="FileText" [size]="14"></lucide-icon>
|
||||
{{ (exportingPdf ? 'campaignDetail.pdfExporting' : 'campaignDetail.pdfExport') | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary" (click)="managementMenu.open = false; exportFoundry()" [disabled]="exportingFoundry">
|
||||
<lucide-icon [img]="Download" [size]="14"></lucide-icon>
|
||||
{{ (exportingFoundry ? 'campaignDetail.foundryExporting' : 'campaignDetail.foundryExport') | translate }}
|
||||
</button>
|
||||
<button type="button" class="btn-danger" (click)="managementMenu.open = false; deleteCampaign()">
|
||||
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
|
||||
{{ 'common.delete' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -6,6 +6,32 @@
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.management-menu {
|
||||
position: relative;
|
||||
summary { cursor: pointer; list-style: none; }
|
||||
summary::-webkit-details-marker { display: none; }
|
||||
summary::after { content: '▾'; margin-left: 0.5rem; }
|
||||
&[open] summary::after { content: '▴'; }
|
||||
summary:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }
|
||||
}
|
||||
.management-actions {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: calc(100% + 0.5rem);
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
width: max-content;
|
||||
max-width: min(280px, 80vw);
|
||||
padding: 0.5rem;
|
||||
background: #131722;
|
||||
border: 1px solid #374151;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 24px #0006;
|
||||
button { width: 100%; text-align: left; justify-content: flex-start; white-space: normal; }
|
||||
}
|
||||
|
||||
// ==== Parties (Playthroughs) ====
|
||||
.playthroughs-grid {
|
||||
display: grid;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { CampaignContentHit, campaignContentRoute, campaignContentContext } from './campaign-content-search.model';
|
||||
|
||||
const hit: CampaignContentHit = { kind: 'scene', id: '4', name: 'Le témoin', campaignId: '1',
|
||||
campaignName: 'Les Ombres', arcId: '2', arcName: 'Le port', chapterId: '3', chapterName: 'La nuit' };
|
||||
|
||||
describe('campaign search destinations', () => {
|
||||
it('resolves each entity even when IDs overlap between types', () => {
|
||||
expect(campaignContentRoute(hit)).toEqual(['/campaigns', '1', 'arcs', '2', 'chapters', '3', 'scenes', '4']);
|
||||
expect(campaignContentRoute({ ...hit, kind: 'chapter' })).toEqual(['/campaigns', '1', 'arcs', '2', 'chapters', '4']);
|
||||
expect(campaignContentRoute({ ...hit, kind: 'arc' })).toEqual(['/campaigns', '1', 'arcs', '4']);
|
||||
expect(campaignContentRoute({ ...hit, kind: 'quest', arcId: null })).toEqual(['/campaigns', '1', 'quests', '4']);
|
||||
});
|
||||
it('keeps a system arc in the destination but out of the visible context', () => {
|
||||
expect(campaignContentContext({ ...hit, arcName: null })).toBe('Les Ombres › La nuit');
|
||||
expect(campaignContentContext(hit)).toBe('Les Ombres › Le port › La nuit');
|
||||
expect(campaignContentRoute({ ...hit, chapterId: null })).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
export interface CampaignContentHit {
|
||||
kind: 'arc' | 'chapter' | 'scene' | 'quest';
|
||||
id: string;
|
||||
name: string;
|
||||
campaignId: string;
|
||||
campaignName: string;
|
||||
arcId: string | null;
|
||||
arcName: string | null;
|
||||
chapterId: string | null;
|
||||
chapterName: string | null;
|
||||
}
|
||||
|
||||
export function campaignContentRoute(hit: CampaignContentHit): string[] {
|
||||
const root = ['/campaigns', hit.campaignId];
|
||||
if (hit.kind === 'quest') return [...root, 'quests', hit.id];
|
||||
if (hit.kind === 'arc') return [...root, 'arcs', hit.id];
|
||||
if (!hit.arcId) return [];
|
||||
const arc = [...root, 'arcs', hit.arcId];
|
||||
if (hit.kind === 'chapter') return [...arc, 'chapters', hit.id];
|
||||
return hit.chapterId ? [...arc, 'chapters', hit.chapterId, 'scenes', hit.id] : [];
|
||||
}
|
||||
|
||||
export function campaignContentContext(hit: CampaignContentHit): string {
|
||||
return [hit.campaignName, hit.kind !== 'arc' ? hit.arcName : null,
|
||||
hit.kind === 'scene' ? hit.chapterName : null].filter(Boolean).join(' › ');
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { Npc } from './npc.model';
|
||||
import { RandomTable } from './random-table.model';
|
||||
import { Enemy } from './enemy.model';
|
||||
import { PdfExportOptions } from './pdf-export.model';
|
||||
import { CampaignContentHit } from './campaign-content-search.model';
|
||||
|
||||
/**
|
||||
* Arbre de campagne AGRÉGÉ (une seule requête HTTP) — miroir de CampaignTreeDTO.
|
||||
@@ -262,4 +263,8 @@ export class CampaignService {
|
||||
const params = new HttpParams().set('q', q);
|
||||
return this.http.get<Campaign[]>(`${this.apiUrl}/search`, { params });
|
||||
}
|
||||
|
||||
searchContent(q: string): Observable<CampaignContentHit[]> {
|
||||
return this.http.get<CampaignContentHit[]>(`${this.apiUrl}/search-content`, { params: { q } });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { Router } from '@angular/router';
|
||||
import { LayoutService, SecondarySidebarConfig } from './layout.service';
|
||||
import { campaignBreadcrumbs, isWithinRoute } from '../shared/navigation-path';
|
||||
import { NavigationEntry, NavigationHistory, contentUrl, readHistory, rememberVisit, toggleFavorite } from '../shared/navigation-history';
|
||||
|
||||
/** Shortcuts belong to this browser and origin; unavailable storage is non-fatal. */
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class NavigationHistoryService {
|
||||
private readonly key = 'loremind.navigation.v1';
|
||||
private readonly state = signal<NavigationHistory>(this.load());
|
||||
readonly history = this.state.asReadonly();
|
||||
private context: SecondarySidebarConfig | null = null;
|
||||
|
||||
constructor(layout: LayoutService, router: Router) {
|
||||
layout.secondarySidebar$.pipe(takeUntilDestroyed()).subscribe(context => {
|
||||
this.context = context;
|
||||
const current = this.state().recent.find(item => item.url === contentUrl(router.url));
|
||||
if (current) this.visit(current.url, current.title);
|
||||
});
|
||||
}
|
||||
|
||||
private subtitleFor(url: string): string {
|
||||
const path = campaignBreadcrumbs(url, this.context, '');
|
||||
if (path.length > 1) return path.slice(0, -1).map(item => item.label).join(' › ');
|
||||
const parent = this.context?.globalItems.find(item => item.route !== url && isWithinRoute(url, item.route));
|
||||
return parent?.name ?? '';
|
||||
}
|
||||
|
||||
private load(): NavigationHistory {
|
||||
try { return readHistory(localStorage.getItem(this.key)); }
|
||||
catch { return { recent: [], favorites: [] }; }
|
||||
}
|
||||
|
||||
private save(history: NavigationHistory): void {
|
||||
this.state.set(history);
|
||||
try { localStorage.setItem(this.key, JSON.stringify(history)); } catch { /* Keep shortcuts in memory. */ }
|
||||
}
|
||||
|
||||
visit(url: string, title: string, subtitle = ''): void {
|
||||
const path = contentUrl(url);
|
||||
if (path && title.trim()) {
|
||||
const existing = this.state().recent.find(item => item.url === path);
|
||||
this.save(rememberVisit(this.state(), { url: path, title, subtitle: subtitle || this.subtitleFor(path) || existing?.subtitle || '' }));
|
||||
}
|
||||
}
|
||||
|
||||
isFavorite(url: string): boolean { return this.state().favorites.some(item => item.url === url); }
|
||||
|
||||
toggle(entry: NavigationEntry): void {
|
||||
if (contentUrl(entry.url) === entry.url) this.save(toggleFavorite(this.state(), entry));
|
||||
}
|
||||
|
||||
clearRecent(): void { this.save({ ...this.state(), recent: [] }); }
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
import { Router } from '@angular/router';
|
||||
import { NavigationHistoryService } from './navigation-history.service';
|
||||
|
||||
/**
|
||||
* Service centralisé pour le titre de l'onglet navigateur.
|
||||
@@ -11,7 +13,7 @@ import { Title } from '@angular/platform-browser';
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PageTitleService {
|
||||
constructor(private title: Title) {}
|
||||
constructor(private title: Title, private router: Router, private history: NavigationHistoryService) {}
|
||||
|
||||
/**
|
||||
* Définit le titre de l'onglet au format "LoreMind - <subject>".
|
||||
@@ -21,5 +23,6 @@ export class PageTitleService {
|
||||
set(subject: string | null | undefined): void {
|
||||
const s = subject?.trim();
|
||||
this.title.setTitle(s ? `LoreMind - ${s}` : 'LoreMind');
|
||||
if (s) this.history.visit(this.router.url, s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
@if (session) {
|
||||
<div class="session-detail">
|
||||
<a class="back-link" [routerLink]="campaignId ? ['/campaigns', campaignId] : ['/campaigns']">
|
||||
<lucide-icon [img]="ArrowLeft" [size]="14"></lucide-icon>
|
||||
{{ 'sessionDetail.backToCampaign' | translate }}
|
||||
</a>
|
||||
<app-breadcrumb [items]="breadcrumbItems"></app-breadcrumb>
|
||||
<div class="detail-header">
|
||||
<div class="header-texts">
|
||||
@if (!editingName) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Component, OnInit, OnDestroy, DestroyRef, inject } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||
import {
|
||||
@@ -15,7 +16,8 @@ import { SessionService } from '../../services/session.service';
|
||||
import { Session } from '../../services/session.model';
|
||||
import { PlaythroughService } from '../../services/playthrough.service';
|
||||
import { CampaignService } from '../../services/campaign.service';
|
||||
import { Scene } from '../../services/campaign.model';
|
||||
import { Scene, Campaign, Playthrough } from '../../services/campaign.model';
|
||||
import { BreadcrumbComponent, BreadcrumbItem } from '../../shared/breadcrumb/breadcrumb.component';
|
||||
import {
|
||||
SessionEntry, SessionEntryInput, EntryType, ENTRY_TYPE_META
|
||||
} from '../../services/session-entry.model';
|
||||
@@ -33,11 +35,22 @@ import { DiceRollResult } from '../session-dice-panel/session-dice-panel.compone
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-session-detail',
|
||||
imports: [CommonModule, FormsModule, LucideAngularModule, TranslatePipe, RouterLink, SessionReferencePanelComponent],
|
||||
imports: [CommonModule, FormsModule, LucideAngularModule, TranslatePipe, BreadcrumbComponent, SessionReferencePanelComponent],
|
||||
templateUrl: './session-detail.component.html',
|
||||
styleUrls: ['./session-detail.component.scss']
|
||||
})
|
||||
export class SessionDetailComponent implements OnInit, OnDestroy {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private campaign: Campaign | null = null;
|
||||
private playthrough: Playthrough | null = null;
|
||||
|
||||
get breadcrumbItems(): BreadcrumbItem[] {
|
||||
const items: BreadcrumbItem[] = [{ label: this.translate.instant('campaignTree.allCampaigns'), route: ['/campaigns'] }];
|
||||
if (this.campaign) items.push({ label: this.campaign.name, route: ['/campaigns', this.campaign.id] });
|
||||
if (this.playthrough) items.push({ label: this.playthrough.name, route: ['/campaigns', this.playthrough.campaignId, 'playthroughs', this.playthrough.id] });
|
||||
if (this.session) items.push({ label: this.session.name });
|
||||
return items;
|
||||
}
|
||||
readonly Dices = Dices;
|
||||
readonly ArrowLeft = ArrowLeft;
|
||||
readonly Square = Square;
|
||||
@@ -126,18 +139,33 @@ export class SessionDetailComponent implements OnInit, OnDestroy {
|
||||
filter((id): id is string => !!id),
|
||||
switchMap(id => this.sessionService.getSessionById(id).pipe(
|
||||
catchError(() => of(null))
|
||||
))
|
||||
).subscribe(session => {
|
||||
)),
|
||||
switchMap(session => {
|
||||
this.campaignId = null;
|
||||
this.campaign = null;
|
||||
this.playthrough = null;
|
||||
if (!session?.playthroughId) return of({ session, playthrough: null, campaign: null });
|
||||
return this.playthroughService.getById(session.playthroughId).pipe(
|
||||
catchError(() => of(null)),
|
||||
switchMap(playthrough => {
|
||||
if (!playthrough) return of({ session, playthrough, campaign: null });
|
||||
return this.campaignService.getCampaignById(playthrough.campaignId).pipe(
|
||||
catchError(() => of(null)),
|
||||
map(campaign => ({ session, playthrough, campaign }))
|
||||
);
|
||||
})
|
||||
);
|
||||
}),
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe(({ session, playthrough, campaign }) => {
|
||||
this.session = session;
|
||||
this.playthrough = playthrough;
|
||||
this.campaign = campaign;
|
||||
this.campaignId = playthrough?.campaignId ?? null;
|
||||
if (session) {
|
||||
this.pageTitleService.set(session.name);
|
||||
this.loadEntries(session.id);
|
||||
this.loadPinnedScene(session.currentSceneId ?? null);
|
||||
if (session.playthroughId) {
|
||||
this.playthroughService.getById(session.playthroughId).pipe(
|
||||
catchError(() => of(null))
|
||||
).subscribe(pt => { this.campaignId = pt ? pt.campaignId : null; });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
class="breadcrumb-link">{{ item.label }}</a>
|
||||
}
|
||||
@if (!item.route || last) {
|
||||
<span class="breadcrumb-text">{{ item.label }}</span>
|
||||
<span class="breadcrumb-text" [attr.aria-current]="last ? 'page' : null">{{ item.label }}</span>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
}
|
||||
|
||||
.breadcrumb-item {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Component, DestroyRef, inject } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { NavigationEnd, Router } from '@angular/router';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { filter } from 'rxjs';
|
||||
import { LayoutService, SecondarySidebarConfig } from '../../services/layout.service';
|
||||
import { BreadcrumbComponent } from './breadcrumb.component';
|
||||
import { campaignBreadcrumbs } from '../navigation-path';
|
||||
|
||||
@Component({
|
||||
selector: 'app-campaign-breadcrumb',
|
||||
imports: [BreadcrumbComponent],
|
||||
template: '@if (items.length) { <div class="campaign-path"><app-breadcrumb [items]="items"></app-breadcrumb></div> }',
|
||||
styles: ['.campaign-path { padding-top: 1rem; overflow-wrap: anywhere; }']
|
||||
})
|
||||
export class CampaignBreadcrumbComponent {
|
||||
private readonly router = inject(Router);
|
||||
private readonly translate = inject(TranslateService);
|
||||
private config: SecondarySidebarConfig | null = null;
|
||||
private url = this.router.url;
|
||||
|
||||
constructor() {
|
||||
const destroyRef = inject(DestroyRef);
|
||||
inject(LayoutService).secondarySidebar$.pipe(takeUntilDestroyed(destroyRef))
|
||||
.subscribe(config => this.config = config);
|
||||
this.router.events.pipe(filter(e => e instanceof NavigationEnd), takeUntilDestroyed(destroyRef))
|
||||
.subscribe(e => this.url = e.urlAfterRedirects);
|
||||
}
|
||||
|
||||
get items() {
|
||||
return campaignBreadcrumbs(this.url, this.config, this.translate.instant('common.edit'));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,41 @@
|
||||
@if (open) {
|
||||
<div class="gs-overlay" (click)="close()">
|
||||
<div class="gs-modal" (click)="$event.stopPropagation()">
|
||||
<div class="gs-modal" role="dialog" aria-modal="true" cdkTrapFocus [cdkTrapFocusAutoCapture]="true" [attr.aria-label]="'sidebar.globalSearch' | translate" (click)="$event.stopPropagation()">
|
||||
<div class="gs-input-row">
|
||||
<lucide-icon [img]="Search" [size]="18" class="gs-search-icon"></lucide-icon>
|
||||
<input
|
||||
#searchInput
|
||||
cdkFocusInitial
|
||||
type="text"
|
||||
class="gs-input"
|
||||
[attr.aria-label]="'sidebar.globalSearch' | translate"
|
||||
[placeholder]="'globalSearch.placeholder' | translate"
|
||||
[ngModel]="query"
|
||||
(ngModelChange)="onQueryChange($event)" />
|
||||
<span class="gs-kbd">ESC</span>
|
||||
<button type="button" class="gs-icon-btn" [attr.aria-label]="'globalSearch.close' | translate" (click)="close()">
|
||||
<lucide-icon [img]="X" [size]="18"></lucide-icon>
|
||||
</button>
|
||||
</div>
|
||||
@if (results.length > 0) {
|
||||
@if (loading) {
|
||||
<div class="gs-empty" role="status">{{ 'globalSearch.loading' | translate }}</div>
|
||||
}
|
||||
@if (visibleResults.length > 0) {
|
||||
<div class="gs-results">
|
||||
@for (r of results; track r; let i = $index) {
|
||||
@for (r of visibleResults; track resultUrl(r); let i = $index) {
|
||||
@if (query.trim().length < 2 && i === 0 && favorites.length > 0) {
|
||||
<h2 class="gs-section-title">{{ 'globalSearch.favorites' | translate }}</h2>
|
||||
}
|
||||
@if (query.trim().length < 2 && i === favorites.length && recent.length > 0) {
|
||||
<div class="gs-section-header">
|
||||
<h2 class="gs-section-title">{{ 'globalSearch.recent' | translate }}</h2>
|
||||
<button type="button" class="gs-clear" (click)="clearRecent()">{{ 'globalSearch.clearRecent' | translate }}</button>
|
||||
</div>
|
||||
}
|
||||
<div class="gs-result-row" [class.active]="i === activeIndex">
|
||||
<button
|
||||
type="button"
|
||||
[id]="'gs-result-' + i"
|
||||
class="gs-result"
|
||||
[class.active]="i === activeIndex"
|
||||
(mouseenter)="activeIndex = i"
|
||||
(click)="select(r)">
|
||||
<lucide-icon [img]="iconFor(r.kind)" [size]="16" class="gs-result-icon"></lucide-icon>
|
||||
@@ -26,9 +44,16 @@
|
||||
@if (r.subtitle) {
|
||||
<div class="gs-result-subtitle">{{ r.subtitle }}</div>
|
||||
}
|
||||
<div class="gs-result-tag">{{ r.tag }}</div>
|
||||
@if (r.tag) { <div class="gs-result-tag">{{ r.tag }}</div> }
|
||||
</div>
|
||||
</button>
|
||||
<button type="button" class="gs-icon-btn gs-favorite" [class.starred]="isFavorite(r)"
|
||||
[attr.aria-pressed]="isFavorite(r)"
|
||||
[attr.aria-label]="(isFavorite(r) ? 'globalSearch.removeFavorite' : 'globalSearch.addFavorite') | translate:{ name: r.title }"
|
||||
(click)="toggleFavorite(r)">
|
||||
<lucide-icon [img]="Star" [size]="18"></lucide-icon>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@@ -37,9 +62,9 @@
|
||||
{{ 'globalSearch.noResults' | translate }}
|
||||
</div>
|
||||
}
|
||||
@if (query.trim().length < 2) {
|
||||
@if (query.trim().length < 2 && visibleResults.length === 0) {
|
||||
<div class="gs-empty">
|
||||
{{ 'globalSearch.minChars' | translate }}
|
||||
{{ 'globalSearch.shortcutsEmpty' | translate }}
|
||||
</div>
|
||||
}
|
||||
<div class="gs-footer">
|
||||
@@ -48,7 +73,7 @@
|
||||
<span><kbd>↵</kbd> {{ 'globalSearch.hintSelect' | translate }}</span>
|
||||
<span><kbd>ESC</kbd> {{ 'globalSearch.hintClose' | translate }}</span>
|
||||
</div>
|
||||
@if (results.length > 0) {
|
||||
@if (query.trim().length >= 2 && results.length > 0) {
|
||||
<span class="gs-count">
|
||||
{{ (results.length > 1 ? 'globalSearch.countPlural' : 'globalSearch.countSingular') | translate:{ count: results.length } }}
|
||||
</span>
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
.gs-search-icon { color: #6b7280; flex-shrink: 0; }
|
||||
|
||||
.gs-input {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
background: transparent;
|
||||
border: none;
|
||||
@@ -58,6 +59,7 @@
|
||||
}
|
||||
|
||||
.gs-result {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
@@ -116,3 +118,38 @@
|
||||
|
||||
span { display: flex; align-items: center; gap: 0.3rem; }
|
||||
}
|
||||
|
||||
.gs-result-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
&.active { background: rgba(99, 102, 241, 0.18); }
|
||||
}
|
||||
.gs-icon-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 44px;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: #9ca3af;
|
||||
cursor: pointer;
|
||||
&:hover { color: #e5e7eb; background: #2d3145; }
|
||||
&.starred { color: #fbbf24; }
|
||||
}
|
||||
.gs-favorite { margin-right: 0.5rem; }
|
||||
.gs-section-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
|
||||
.gs-section-title { margin: 0; padding: 0.75rem 1.25rem 0.25rem; font-size: 0.85rem; color: #c4b5fd; }
|
||||
.gs-clear { padding: 0.5rem 1.25rem; background: none; border: none; color: #9ca3af; cursor: pointer; }
|
||||
.gs-result:focus-visible, .gs-icon-btn:focus-visible, .gs-clear:focus-visible {
|
||||
outline: 2px solid #a5b4fc;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.gs-result-title { overflow-wrap: anywhere; }
|
||||
@media (max-width: 480px) {
|
||||
.gs-footer, .gs-hints { flex-wrap: wrap; gap: 0.5rem; }
|
||||
.gs-input-row { padding: 0.5rem 0.75rem; }
|
||||
.gs-result { padding: 0.75rem; }
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@ import { Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } fro
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||
import { BehaviorSubject, Subject, forkJoin, of } from 'rxjs';
|
||||
import { catchError, debounceTime, distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators';
|
||||
import { LucideAngularModule, Search, BookOpen, Folder, Users, FileText, Scroll, Drama, User, Dices, Package, Skull } from 'lucide-angular';
|
||||
import { BehaviorSubject, Subject, forkJoin, of, timer } from 'rxjs';
|
||||
import { catchError, distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators';
|
||||
import { LucideAngularModule, Search, BookOpen, Folder, Users, FileText, Scroll, Drama, User, Dices, Package, Skull, Star, X } from 'lucide-angular';
|
||||
import { A11yModule } from '@angular/cdk/a11y';
|
||||
import { NavigationHistoryService } from '../../services/navigation-history.service';
|
||||
import { NavigationEntry } from '../navigation-history';
|
||||
import { GlobalSearchService } from '../../services/global-search.service';
|
||||
import { LoreService } from '../../services/lore.service';
|
||||
import { PageService } from '../../services/page.service';
|
||||
@@ -24,10 +27,12 @@ import { Npc } from '../../services/npc.model';
|
||||
import { RandomTable } from '../../services/random-table.model';
|
||||
import { ItemCatalog } from '../../services/item-catalog.model';
|
||||
import { Enemy } from '../../services/enemy.model';
|
||||
import { CampaignContentHit, campaignContentRoute, campaignContentContext } from '../../services/campaign-content-search.model';
|
||||
|
||||
type ResultKind =
|
||||
| 'lore' | 'node' | 'template' | 'page' | 'campaign'
|
||||
| 'npc' | 'character' | 'random-table' | 'item-catalog' | 'enemy';
|
||||
| 'npc' | 'character' | 'random-table' | 'item-catalog' | 'enemy'
|
||||
| CampaignContentHit['kind'] | 'saved';
|
||||
|
||||
interface SearchResult {
|
||||
/** Optionnel dans les DTOs (objets pas encore persistés) mais toujours
|
||||
@@ -50,11 +55,13 @@ interface SearchResult {
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-global-search',
|
||||
imports: [FormsModule, LucideAngularModule, TranslatePipe],
|
||||
imports: [FormsModule, LucideAngularModule, TranslatePipe, A11yModule],
|
||||
templateUrl: './global-search.component.html',
|
||||
styleUrls: ['./global-search.component.scss']
|
||||
})
|
||||
export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
readonly Star = Star;
|
||||
readonly X = X;
|
||||
readonly Search = Search;
|
||||
readonly BookOpen = BookOpen;
|
||||
readonly Folder = Folder;
|
||||
@@ -90,12 +97,37 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
private randomTableService: RandomTableService,
|
||||
private itemCatalogService: ItemCatalogService,
|
||||
private enemyService: EnemyService,
|
||||
private translate: TranslateService
|
||||
private translate: TranslateService,
|
||||
public history: NavigationHistoryService
|
||||
) {}
|
||||
|
||||
private savedResult(entry: NavigationEntry): SearchResult {
|
||||
return { id: entry.url, kind: 'saved', title: entry.title, subtitle: entry.subtitle, tag: '', route: [entry.url] };
|
||||
}
|
||||
|
||||
get favorites(): SearchResult[] { return this.history.history().favorites.map(entry => this.savedResult(entry)); }
|
||||
get recent(): SearchResult[] {
|
||||
return this.history.history().recent.filter(entry => !this.history.isFavorite(entry.url)).map(entry => this.savedResult(entry));
|
||||
}
|
||||
get visibleResults(): SearchResult[] {
|
||||
return this.query.trim().length < 2 ? [...this.favorites, ...this.recent] : this.results;
|
||||
}
|
||||
resultUrl(result: SearchResult): string { return this.router.serializeUrl(this.router.createUrlTree(result.route)); }
|
||||
isFavorite(result: SearchResult): boolean { return this.history.isFavorite(this.resultUrl(result)); }
|
||||
toggleFavorite(result: SearchResult): void {
|
||||
this.history.toggle({ url: this.resultUrl(result), title: result.title, subtitle: result.subtitle });
|
||||
this.activeIndex = Math.min(this.activeIndex, Math.max(0, this.visibleResults.length - 1));
|
||||
}
|
||||
clearRecent(): void { this.history.clearRecent(); this.activeIndex = 0; }
|
||||
|
||||
private scrollToActive(): void {
|
||||
setTimeout(() => document.getElementById('gs-result-' + this.activeIndex)?.scrollIntoView({ block: 'nearest' }), 0);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.globalSearch.open$.pipe(takeUntil(this.destroy$)).subscribe(open => {
|
||||
this.open = open;
|
||||
this.queryChanges$.next('');
|
||||
if (open) {
|
||||
this.query = '';
|
||||
this.results = [];
|
||||
@@ -106,16 +138,17 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
|
||||
this.queryChanges$.pipe(
|
||||
debounceTime(200),
|
||||
distinctUntilChanged(),
|
||||
switchMap(q => {
|
||||
this.results = [];
|
||||
this.activeIndex = 0;
|
||||
const trimmed = q.trim();
|
||||
if (trimmed.length < 2) {
|
||||
this.loading = false;
|
||||
return of<SearchResult[]>([]);
|
||||
}
|
||||
this.loading = true;
|
||||
return forkJoin({
|
||||
return timer(200).pipe(switchMap(() => forkJoin({
|
||||
lores: this.loreService.searchLores(trimmed).pipe(catchError(() => of([]))),
|
||||
nodes: this.loreService.searchLoreNodes(trimmed).pipe(catchError(() => of([]))),
|
||||
templates: this.templateService.search(trimmed).pipe(catchError(() => of([]))),
|
||||
@@ -125,8 +158,9 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
characters: this.characterService.search(trimmed).pipe(catchError(() => of([]))),
|
||||
tables: this.randomTableService.search(trimmed).pipe(catchError(() => of([]))),
|
||||
catalogs: this.itemCatalogService.search(trimmed).pipe(catchError(() => of([]))),
|
||||
enemies: this.enemyService.search(trimmed).pipe(catchError(() => of([])))
|
||||
}).pipe(
|
||||
enemies: this.enemyService.search(trimmed).pipe(catchError(() => of([]))),
|
||||
content: this.campaignService.searchContent(trimmed).pipe(catchError(() => of([])))
|
||||
})),
|
||||
switchMap(r => of(this.buildResults(r))),
|
||||
catchError(() => of<SearchResult[]>([]))
|
||||
);
|
||||
@@ -151,7 +185,7 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
private buildResults(r: {
|
||||
lores: Lore[]; nodes: LoreNode[]; templates: Template[]; pages: Page[]; campaigns: Campaign[];
|
||||
npcs: Npc[]; characters: CharacterSearchResult[]; tables: RandomTable[]; catalogs: ItemCatalog[]; enemies: Enemy[];
|
||||
npcs: Npc[]; characters: CharacterSearchResult[]; tables: RandomTable[]; catalogs: ItemCatalog[]; enemies: Enemy[]; content: CampaignContentHit[];
|
||||
}): SearchResult[] {
|
||||
const { lores, nodes, templates, pages, campaigns, npcs, characters, tables, catalogs, enemies } = r;
|
||||
const pageResults: SearchResult[] = pages.map(p => ({
|
||||
@@ -236,6 +270,12 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
}));
|
||||
return [
|
||||
...pageResults,
|
||||
...r.content.map(hit => ({
|
||||
id: hit.id, kind: hit.kind, title: hit.name,
|
||||
subtitle: campaignContentContext(hit),
|
||||
tag: this.translate.instant('globalSearch.tags.' + hit.kind),
|
||||
route: campaignContentRoute(hit)
|
||||
})).filter(hit => hit.route.length > 0),
|
||||
...npcResults, ...characterResults, ...enemyResults, ...tableResults, ...catalogResults,
|
||||
...nodeResults, ...templateResults,
|
||||
...campaignResults, ...loreResults
|
||||
@@ -248,6 +288,7 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
select(result: SearchResult): void {
|
||||
this.history.visit(this.resultUrl(result), result.title, result.subtitle);
|
||||
this.router.navigate(result.route);
|
||||
this.globalSearch.close();
|
||||
}
|
||||
@@ -263,19 +304,24 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
this.close();
|
||||
} else if (event.target !== this.searchInput?.nativeElement) {
|
||||
// Native buttons (including stars) keep their own Enter/Space behavior.
|
||||
return;
|
||||
} else if (event.key === 'ArrowDown') {
|
||||
event.preventDefault();
|
||||
if (this.results.length > 0) {
|
||||
this.activeIndex = (this.activeIndex + 1) % this.results.length;
|
||||
if (this.visibleResults.length > 0) {
|
||||
this.activeIndex = (this.activeIndex + 1) % this.visibleResults.length;
|
||||
this.scrollToActive();
|
||||
}
|
||||
} else if (event.key === 'ArrowUp') {
|
||||
event.preventDefault();
|
||||
if (this.results.length > 0) {
|
||||
this.activeIndex = (this.activeIndex - 1 + this.results.length) % this.results.length;
|
||||
if (this.visibleResults.length > 0) {
|
||||
this.activeIndex = (this.activeIndex - 1 + this.visibleResults.length) % this.visibleResults.length;
|
||||
this.scrollToActive();
|
||||
}
|
||||
} else if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
const r = this.results[this.activeIndex];
|
||||
const r = this.visibleResults[this.activeIndex];
|
||||
if (r) this.select(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { contentUrl, readHistory, rememberVisit, toggleFavorite } from './navigation-history';
|
||||
|
||||
const scene = { url: '/campaigns/1/arcs/2/chapters/3/scenes/4', title: 'La taverne', subtitle: 'Les Ombres' };
|
||||
|
||||
describe('navigation shortcuts', () => {
|
||||
it('keeps a bounded, deduplicated recent list and refreshes renamed favorites', () => {
|
||||
let state = toggleFavorite({ recent: [], favorites: [] }, scene);
|
||||
for (let i = 0; i < 20; i++) state = rememberVisit(state, { ...scene, url: '/lore/' + i });
|
||||
state = rememberVisit(state, scene);
|
||||
state = rememberVisit(state, { ...scene, title: 'La nouvelle taverne' });
|
||||
expect(state.recent).toHaveLength(12);
|
||||
expect(state.recent[0].title).toBe('La nouvelle taverne');
|
||||
expect(state.favorites[0].title).toBe('La nouvelle taverne');
|
||||
expect(state.recent.filter(item => item.url === scene.url)).toHaveLength(1);
|
||||
});
|
||||
it('removes a favorite without removing its recent visit', () => {
|
||||
const visited = rememberVisit({ recent: [], favorites: [] }, scene);
|
||||
expect(toggleFavorite(toggleFavorite(visited, scene), scene)).toEqual(visited);
|
||||
});
|
||||
it('ignores broken storage, unsafe URLs and duplicate entries', () => {
|
||||
expect(readHistory('{broken')).toEqual({ recent: [], favorites: [] });
|
||||
const saved = readHistory(JSON.stringify({ recent: [scene, scene, { ...scene, url: 'https://example.com' }, null], favorites: [scene] }));
|
||||
expect(saved).toEqual({ recent: [scene], favorites: [scene] });
|
||||
});
|
||||
it('never records creation or editing forms and drops query parameters', () => {
|
||||
expect(contentUrl(scene.url + '?edit=1#notes')).toBe(scene.url);
|
||||
for (const url of [scene.url + '/edit', '/lore/1/pages/create', '/campaigns/1/guided/five-room', '//evil.test', '/settings']) {
|
||||
expect(contentUrl(url)).toBeNull();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
export interface NavigationEntry {
|
||||
url: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
}
|
||||
|
||||
export interface NavigationHistory {
|
||||
recent: NavigationEntry[];
|
||||
favorites: NavigationEntry[];
|
||||
}
|
||||
|
||||
/** Only saved content pages, never forms, query parameters or external URLs. */
|
||||
export function contentUrl(url: string): string | null {
|
||||
const path = url.split(/[?#]/)[0];
|
||||
if (!/^\/(campaigns|lore|sessions)\/[a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*$/.test(path)) return null;
|
||||
if (/(?:^|\/)(create|edit|import|guided|publication|flags)(?:\/|$)/.test(path)) return null;
|
||||
return path;
|
||||
}
|
||||
|
||||
export function readHistory(raw: string | null): NavigationHistory {
|
||||
const empty: NavigationHistory = { recent: [], favorites: [] };
|
||||
try {
|
||||
const data: unknown = JSON.parse(raw ?? 'null');
|
||||
if (!data || typeof data !== 'object') return empty;
|
||||
const clean = (value: unknown): NavigationEntry[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
const seen = new Set<string>();
|
||||
return value.filter((entry): entry is NavigationEntry => {
|
||||
if (!entry || typeof entry.url !== 'string' || contentUrl(entry.url) !== entry.url ||
|
||||
typeof entry.title !== 'string' || !entry.title.trim() || typeof entry.subtitle !== 'string' || seen.has(entry.url)) return false;
|
||||
seen.add(entry.url);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
const saved = data as Partial<NavigationHistory>;
|
||||
return { recent: clean(saved.recent).slice(0, 12), favorites: clean(saved.favorites) };
|
||||
} catch { return empty; }
|
||||
}
|
||||
|
||||
export function rememberVisit(history: NavigationHistory, entry: NavigationEntry): NavigationHistory {
|
||||
return {
|
||||
recent: [entry, ...history.recent.filter(item => item.url !== entry.url)].slice(0, 12),
|
||||
favorites: history.favorites.map(item => item.url === entry.url ? entry : item)
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleFavorite(history: NavigationHistory, entry: NavigationEntry): NavigationHistory {
|
||||
const exists = history.favorites.some(item => item.url === entry.url);
|
||||
return { ...history, favorites: exists
|
||||
? history.favorites.filter(item => item.url !== entry.url)
|
||||
: [...history.favorites, entry] };
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { campaignBreadcrumbs, isWithinRoute } from './navigation-path';
|
||||
import type { SecondarySidebarConfig } from '../services/layout.service';
|
||||
|
||||
const root = '/campaigns/1';
|
||||
const arc = root + '/arcs/2';
|
||||
const chapter = arc + '/chapters/3';
|
||||
const scene = chapter + '/scenes/4';
|
||||
const config: SecondarySidebarConfig = {
|
||||
title: 'Les Ombres', titleRoute: root, globalItems: [], globalBackLabel: '', globalBackRoute: '/campaigns',
|
||||
createActions: [{ id: 'arc', label: 'Nouvel arc', variant: 'primary', route: root + '/arcs/create' }],
|
||||
items: [{ id: 'arc', label: 'Le port', route: arc, children: [
|
||||
{ id: 'chapter', label: 'La nuit', route: chapter, children: [
|
||||
{ id: 'scene', label: 'La taverne', route: scene }
|
||||
], createActions: [{ id: 'scene', label: 'Nouvelle scène', route: chapter + '/scenes/create' }] }
|
||||
] }]
|
||||
};
|
||||
|
||||
describe('navigation context', () => {
|
||||
it('keeps the current campaign selected without matching a different numeric ID', () => {
|
||||
expect(isWithinRoute(scene + '?tab=notes#title', root)).toBe(true);
|
||||
expect(isWithinRoute('/campaigns/10/arcs/2', root)).toBe(false);
|
||||
expect(isWithinRoute('/lore/1', root)).toBe(false);
|
||||
});
|
||||
it('allows returning from a scene to each named ancestor', () => {
|
||||
expect(campaignBreadcrumbs(scene, config, 'Modifier')).toEqual([
|
||||
{ label: 'Les Ombres', route: root }, { label: 'Le port', route: arc },
|
||||
{ label: 'La nuit', route: chapter }, { label: 'La taverne', route: scene }
|
||||
]);
|
||||
});
|
||||
it('links back to the scene while editing and to the parent while creating', () => {
|
||||
expect(campaignBreadcrumbs(scene + '/edit', config, 'Modifier').at(-1)).toEqual({ label: 'Modifier' });
|
||||
expect(campaignBreadcrumbs(chapter + '/scenes/create', config, 'Modifier').map(i => i.label))
|
||||
.toEqual(['Les Ombres', 'Le port', 'La nuit', 'Nouvelle scène']);
|
||||
expect(campaignBreadcrumbs(root + '/arcs/create', config, 'Modifier').map(i => i.label))
|
||||
.toEqual(['Les Ombres', 'Nouvel arc']);
|
||||
});
|
||||
it('preserves the visible quest hierarchy instead of revealing its system arc', () => {
|
||||
const questConfig = { ...config, items: [{ id: 'quests', label: 'Quêtes', children: [
|
||||
{ id: 'quest', label: 'Le témoin', route: root + '/quests/5', children: [
|
||||
{ id: 'scene', label: 'La taverne', route: scene }
|
||||
] }
|
||||
] }] };
|
||||
expect(campaignBreadcrumbs(scene, questConfig, 'Modifier').map(i => i.label))
|
||||
.toEqual(['Les Ombres', 'Quêtes', 'Le témoin', 'La taverne']);
|
||||
});
|
||||
it('uses the scenes graph as parent for a flattened campaign', () => {
|
||||
const flat = { ...config, items: [{ id: 'chapter', label: 'Scènes', route: chapter + '/graph', children: [
|
||||
{ id: 'scene', label: 'La taverne', route: scene }
|
||||
] }] };
|
||||
expect(campaignBreadcrumbs(scene, flat, 'Modifier')[1]).toEqual({ label: 'Scènes', route: chapter + '/graph' });
|
||||
});
|
||||
it('does not show stale context or invent a title for an unknown page', () => {
|
||||
for (const path of [root, '/campaigns/10/arcs/2', root + '/npcs/9', '/lore/1']) {
|
||||
expect(campaignBreadcrumbs(path, config, 'Modifier')).toEqual([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import type { SecondarySidebarConfig, TreeItem } from '../services/layout.service';
|
||||
import type { BreadcrumbItem } from './breadcrumb/breadcrumb.component';
|
||||
|
||||
/** Segment boundaries prevent campaign 1 from matching campaign 10. */
|
||||
export function isWithinRoute(url: string, route: string): boolean {
|
||||
const path = url.split(/[?#]/)[0];
|
||||
return path === route || path.startsWith(route + '/');
|
||||
}
|
||||
|
||||
/** Follow the visible tree, including flattened campaigns and quest containers. */
|
||||
export function campaignBreadcrumbs(
|
||||
url: string, config: SecondarySidebarConfig | null, editLabel: string
|
||||
): BreadcrumbItem[] {
|
||||
const root = config?.titleRoute;
|
||||
if (!config || !root?.startsWith('/campaigns/') || !isWithinRoute(url, root)) return [];
|
||||
const path = url.split(/[?#]/)[0];
|
||||
if (path === root) return [];
|
||||
let best: BreadcrumbItem[] = [];
|
||||
let matchedRoute = '';
|
||||
const visit = (items: TreeItem[], parents: BreadcrumbItem[]) => {
|
||||
for (const item of items) {
|
||||
const trail = item.route === root ? parents : [...parents, { label: item.label, route: item.route }];
|
||||
if (item.route && item.route !== root && isWithinRoute(path, item.route) && item.route.length > matchedRoute.length) {
|
||||
best = trail;
|
||||
matchedRoute = item.route;
|
||||
}
|
||||
for (const action of item.createActions ?? []) {
|
||||
if (path === action.route) {
|
||||
best = [...trail, { label: action.label }];
|
||||
matchedRoute = action.route;
|
||||
}
|
||||
}
|
||||
visit(item.children ?? [], trail);
|
||||
}
|
||||
};
|
||||
visit(config.items, []);
|
||||
for (const action of config.createActions) {
|
||||
if (action.route === path) {
|
||||
best = [{ label: action.label }];
|
||||
matchedRoute = path;
|
||||
}
|
||||
}
|
||||
if (!matchedRoute || (path !== matchedRoute && path !== matchedRoute + '/edit')) return [];
|
||||
if (path.endsWith('/edit')) best.push({ label: editLabel });
|
||||
return [{ label: config.title, route: root }, ...best];
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
@if (assessment) {
|
||||
<section class="readiness-panel" [class.ready]="isReady">
|
||||
<button type="button" class="readiness-header" (click)="toggle()">
|
||||
<button type="button" class="readiness-header" (click)="toggle()" [attr.aria-expanded]="!collapsed">
|
||||
<lucide-icon [img]="collapsed ? ChevronRight : ChevronDown" [size]="16"></lucide-icon>
|
||||
@if (isReady) {
|
||||
<lucide-icon [img]="CheckCircle2" [size]="16" class="ready-icon"></lucide-icon>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<button class="toggle-btn" [class.active]="currentRoute.startsWith('/lore')" (click)="navigateTo('/lore')">
|
||||
{{ 'sidebar.tabLore' | translate }}
|
||||
</button>
|
||||
<button class="toggle-btn" [class.active]="currentRoute.startsWith('/campaigns')" (click)="navigateTo('/campaigns')">
|
||||
<button class="toggle-btn" [class.active]="currentRoute.startsWith('/campaigns') || currentRoute.startsWith('/sessions/')" (click)="navigateTo('/campaigns')">
|
||||
{{ 'sidebar.tabCampaign' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
@@ -27,6 +27,7 @@
|
||||
<button
|
||||
class="context-item"
|
||||
[class.active]="isActive(item.route)"
|
||||
[attr.aria-current]="isActive(item.route) ? 'location' : null"
|
||||
(click)="navigateTo(item.route)">
|
||||
{{ item.name }}
|
||||
</button>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { ActiveSessionShortcutComponent } from '../sessions/active-session-short
|
||||
// Single source of truth pour la version affichée dans le footer :
|
||||
// on lit directement package.json à la compilation (resolveJsonModule).
|
||||
import packageJson from '../../../package.json';
|
||||
import { isWithinRoute } from '../shared/navigation-path';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidebar',
|
||||
@@ -57,7 +58,7 @@ export class SidebarComponent implements OnInit {
|
||||
}
|
||||
|
||||
isActive(itemRoute: string): boolean {
|
||||
return this.currentRoute === itemRoute;
|
||||
return isWithinRoute(this.currentRoute, itemRoute);
|
||||
}
|
||||
|
||||
openSearch(): void {
|
||||
|
||||
Reference in New Issue
Block a user