Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 550078268c | |||
| 0582690dca | |||
| 88278bd1dd | |||
| d24d6459a0 | |||
| 4b866e5212 | |||
| 6c6bd20f0d | |||
| 2764228abf | |||
| f95d69c915 | |||
| 70351e9d9a | |||
| ff4905126d | |||
| 0e5b5a7de4 | |||
| c8c032336b | |||
| dda27e55fc | |||
| 83ac67471e | |||
| e3c8232e38 | |||
| a4df9fc759 |
95
.gitea/workflows/e2e.yml
Normal file
95
.gitea/workflows/e2e.yml
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
name: E2E Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
e2e:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
|
||||||
|
- name: Create .env for stack
|
||||||
|
run: |
|
||||||
|
cat > .env <<'EOF'
|
||||||
|
POSTGRES_PASSWORD=ci-postgres-pass
|
||||||
|
BRAIN_INTERNAL_SECRET=ci-brain-secret
|
||||||
|
ADMIN_USERNAME=admin
|
||||||
|
ADMIN_PASSWORD=ci-admin-pass
|
||||||
|
WEB_PORT=8081
|
||||||
|
LLM_PROVIDER=ollama
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Build & start stack
|
||||||
|
run: |
|
||||||
|
docker compose -f docker-compose.yml -f docker-compose.e2e.yml up -d --build
|
||||||
|
|
||||||
|
- name: Attach runner to compose network
|
||||||
|
run: |
|
||||||
|
NET=$(docker network ls --format '{{.Name}}' | grep -E '(^|_)loremind(_|$)' | grep -i default | head -1)
|
||||||
|
if [ -z "$NET" ]; then
|
||||||
|
echo "Compose network not found" >&2
|
||||||
|
docker network ls
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Connecting $(hostname) to network $NET"
|
||||||
|
docker network connect "$NET" "$(hostname)"
|
||||||
|
|
||||||
|
- name: Wait for web to be ready
|
||||||
|
run: |
|
||||||
|
timeout 180 bash -c 'until curl -sf http://web/ > /dev/null; do echo "waiting..."; sleep 3; done'
|
||||||
|
|
||||||
|
- name: Install web deps
|
||||||
|
working-directory: web
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Work around runner clock skew for apt
|
||||||
|
run: |
|
||||||
|
sudo tee /etc/apt/apt.conf.d/99no-check-valid-until >/dev/null <<'EOF'
|
||||||
|
Acquire::Check-Valid-Until "false";
|
||||||
|
Acquire::Check-Date "false";
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Install Playwright browsers
|
||||||
|
working-directory: web
|
||||||
|
run: npx playwright install --with-deps chromium
|
||||||
|
|
||||||
|
- name: Run Playwright tests
|
||||||
|
working-directory: web
|
||||||
|
env:
|
||||||
|
E2E_BASE_URL: http://web
|
||||||
|
CI: 'true'
|
||||||
|
run: npm run e2e
|
||||||
|
|
||||||
|
- name: Dump container logs on failure
|
||||||
|
if: failure()
|
||||||
|
run: docker compose -f docker-compose.yml -f docker-compose.e2e.yml logs --no-color
|
||||||
|
|
||||||
|
- name: Upload Playwright report
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: playwright-report
|
||||||
|
path: web/playwright-report/
|
||||||
|
retention-days: 14
|
||||||
|
|
||||||
|
- name: Stop stack
|
||||||
|
if: always()
|
||||||
|
run: docker compose -f docker-compose.yml -f docker-compose.e2e.yml down -v
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -53,6 +53,12 @@ yarn-error.log*
|
|||||||
.pnpm-debug.log*
|
.pnpm-debug.log*
|
||||||
coverage/
|
coverage/
|
||||||
|
|
||||||
|
# Playwright (E2E)
|
||||||
|
web/test-results/
|
||||||
|
web/playwright-report/
|
||||||
|
web/blob-report/
|
||||||
|
web/playwright/.cache/
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# IDE / Editeurs
|
# IDE / Editeurs
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ from app.infrastructure.onemin_adapter import OneMinAiLLMProvider
|
|||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="LoreMind Brain",
|
title="LoreMind Brain",
|
||||||
description="Backend IA pour la génération de contenu narratif.",
|
description="Backend IA pour la génération de contenu narratif.",
|
||||||
version="0.6.0",
|
version="0.6.5",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<groupId>com.loremind</groupId>
|
<groupId>com.loremind</groupId>
|
||||||
<artifactId>loremind-core</artifactId>
|
<artifactId>loremind-core</artifactId>
|
||||||
<version>0.6.0</version>
|
<version>0.6.5</version>
|
||||||
<name>LoreMind Core</name>
|
<name>LoreMind Core</name>
|
||||||
<description>Backend Core - Architecture Hexagonale</description>
|
<description>Backend Core - Architecture Hexagonale</description>
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,16 @@ public class ArcService {
|
|||||||
public record DeletionImpact(int chapters, int scenes) {}
|
public record DeletionImpact(int chapters, int scenes) {}
|
||||||
|
|
||||||
public Arc createArc(String name, String description, String campaignId, int order) {
|
public Arc createArc(String name, String description, String campaignId, int order) {
|
||||||
|
return createArc(name, description, campaignId, order, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arc createArc(String name, String description, String campaignId, int order, String icon) {
|
||||||
Arc arc = Arc.builder()
|
Arc arc = Arc.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
.description(description)
|
.description(description)
|
||||||
.campaignId(campaignId)
|
.campaignId(campaignId)
|
||||||
.order(order)
|
.order(order)
|
||||||
|
.icon(icon)
|
||||||
.build();
|
.build();
|
||||||
return arcRepository.save(arc);
|
return arcRepository.save(arc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,16 @@ public class ChapterService {
|
|||||||
public record DeletionImpact(int scenes) {}
|
public record DeletionImpact(int scenes) {}
|
||||||
|
|
||||||
public Chapter createChapter(String name, String description, String arcId, int order) {
|
public Chapter createChapter(String name, String description, String arcId, int order) {
|
||||||
|
return createChapter(name, description, arcId, order, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chapter createChapter(String name, String description, String arcId, int order, String icon) {
|
||||||
Chapter chapter = Chapter.builder()
|
Chapter chapter = Chapter.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
.description(description)
|
.description(description)
|
||||||
.arcId(arcId)
|
.arcId(arcId)
|
||||||
.order(order)
|
.order(order)
|
||||||
|
.icon(icon)
|
||||||
.build();
|
.build();
|
||||||
return chapterRepository.save(chapter);
|
return chapterRepository.save(chapter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,16 @@ public class SceneService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Scene createScene(String name, String description, String chapterId, int order) {
|
public Scene createScene(String name, String description, String chapterId, int order) {
|
||||||
|
return createScene(name, description, chapterId, order, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Scene createScene(String name, String description, String chapterId, int order, String icon) {
|
||||||
Scene scene = Scene.builder()
|
Scene scene = Scene.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
.description(description)
|
.description(description)
|
||||||
.chapterId(chapterId)
|
.chapterId(chapterId)
|
||||||
.order(order)
|
.order(order)
|
||||||
|
.icon(icon)
|
||||||
.build();
|
.build();
|
||||||
return sceneRepository.save(scene);
|
return sceneRepository.save(scene);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ public class Arc {
|
|||||||
private String campaignId; // Référence vers la Campaign parente
|
private String campaignId; // Référence vers la Campaign parente
|
||||||
private int order; // Ordre de l'arc dans la campagne
|
private int order; // Ordre de l'arc dans la campagne
|
||||||
|
|
||||||
|
/** Cle d'icone choisie par l'utilisateur (cf. CAMPAIGN_ICON_OPTIONS cote front). */
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis (voir docs/maquettes/campagne/détail/)
|
// Champs narratifs enrichis (voir docs/maquettes/campagne/détail/)
|
||||||
private String themes; // Thèmes principaux explorés dans cet arc
|
private String themes; // Thèmes principaux explorés dans cet arc
|
||||||
private String stakes; // Enjeux globaux pour les personnages
|
private String stakes; // Enjeux globaux pour les personnages
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ public class Chapter {
|
|||||||
private String arcId; // Référence vers l'Arc parent
|
private String arcId; // Référence vers l'Arc parent
|
||||||
private int order; // Ordre du chapitre dans l'arc
|
private int order; // Ordre du chapitre dans l'arc
|
||||||
|
|
||||||
|
/** Cle d'icone choisie par l'utilisateur (cf. CAMPAIGN_ICON_OPTIONS cote front). */
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis (voir docs/maquettes/campagne/détail/)
|
// Champs narratifs enrichis (voir docs/maquettes/campagne/détail/)
|
||||||
private String gmNotes; // Notes privées du MJ (non exportées vers FoundryVTT)
|
private String gmNotes; // Notes privées du MJ (non exportées vers FoundryVTT)
|
||||||
private String playerObjectives; // Objectifs des joueurs dans ce chapitre
|
private String playerObjectives; // Objectifs des joueurs dans ce chapitre
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ public class Scene {
|
|||||||
private String chapterId; // Référence vers le Chapter parent
|
private String chapterId; // Référence vers le Chapter parent
|
||||||
private int order; // Ordre de la scène dans le chapitre
|
private int order; // Ordre de la scène dans le chapitre
|
||||||
|
|
||||||
|
/** Cle d'icone choisie par l'utilisateur (cf. CAMPAIGN_ICON_OPTIONS cote front). */
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// === Contexte et ambiance ===
|
// === Contexte et ambiance ===
|
||||||
private String location; // Lieu de la scène (ex: Taverne du Dragon d'Or)
|
private String location; // Lieu de la scène (ex: Taverne du Dragon d'Or)
|
||||||
private String timing; // Moment (ex: Soir, à la tombée de la nuit)
|
private String timing; // Moment (ex: Soir, à la tombée de la nuit)
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class ArcJpaEntity {
|
|||||||
@Column(name = "\"order\"", nullable = false)
|
@Column(name = "\"order\"", nullable = false)
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis — ajoutés automatiquement par Hibernate DDL (ddl-auto=update)
|
// Champs narratifs enrichis — ajoutés automatiquement par Hibernate DDL (ddl-auto=update)
|
||||||
@Column(columnDefinition = "TEXT")
|
@Column(columnDefinition = "TEXT")
|
||||||
private String themes;
|
private String themes;
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class ChapterJpaEntity {
|
|||||||
@Column(name = "\"order\"", nullable = false)
|
@Column(name = "\"order\"", nullable = false)
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis — ajoutés automatiquement par Hibernate DDL (ddl-auto=update)
|
// Champs narratifs enrichis — ajoutés automatiquement par Hibernate DDL (ddl-auto=update)
|
||||||
@Column(name = "gm_notes", columnDefinition = "TEXT")
|
@Column(name = "gm_notes", columnDefinition = "TEXT")
|
||||||
private String gmNotes;
|
private String gmNotes;
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public class SceneJpaEntity {
|
|||||||
@Column(name = "\"order\"", nullable = false)
|
@Column(name = "\"order\"", nullable = false)
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis — ajoutés automatiquement par Hibernate (ddl-auto=update)
|
// Champs narratifs enrichis — ajoutés automatiquement par Hibernate (ddl-auto=update)
|
||||||
|
|
||||||
// Contexte et ambiance
|
// Contexte et ambiance
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class PostgresArcRepository implements ArcRepository {
|
|||||||
.description(jpaEntity.getDescription())
|
.description(jpaEntity.getDescription())
|
||||||
.campaignId(jpaEntity.getCampaignId().toString())
|
.campaignId(jpaEntity.getCampaignId().toString())
|
||||||
.order(jpaEntity.getOrder())
|
.order(jpaEntity.getOrder())
|
||||||
|
.icon(jpaEntity.getIcon())
|
||||||
.themes(jpaEntity.getThemes())
|
.themes(jpaEntity.getThemes())
|
||||||
.stakes(jpaEntity.getStakes())
|
.stakes(jpaEntity.getStakes())
|
||||||
.gmNotes(jpaEntity.getGmNotes())
|
.gmNotes(jpaEntity.getGmNotes())
|
||||||
@@ -99,6 +100,7 @@ public class PostgresArcRepository implements ArcRepository {
|
|||||||
.description(arc.getDescription())
|
.description(arc.getDescription())
|
||||||
.campaignId(Long.parseLong(arc.getCampaignId()))
|
.campaignId(Long.parseLong(arc.getCampaignId()))
|
||||||
.order(arc.getOrder())
|
.order(arc.getOrder())
|
||||||
|
.icon(arc.getIcon())
|
||||||
.themes(arc.getThemes())
|
.themes(arc.getThemes())
|
||||||
.stakes(arc.getStakes())
|
.stakes(arc.getStakes())
|
||||||
.gmNotes(arc.getGmNotes())
|
.gmNotes(arc.getGmNotes())
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class PostgresChapterRepository implements ChapterRepository {
|
|||||||
.description(jpaEntity.getDescription())
|
.description(jpaEntity.getDescription())
|
||||||
.arcId(jpaEntity.getArcId().toString())
|
.arcId(jpaEntity.getArcId().toString())
|
||||||
.order(jpaEntity.getOrder())
|
.order(jpaEntity.getOrder())
|
||||||
|
.icon(jpaEntity.getIcon())
|
||||||
.gmNotes(jpaEntity.getGmNotes())
|
.gmNotes(jpaEntity.getGmNotes())
|
||||||
.playerObjectives(jpaEntity.getPlayerObjectives())
|
.playerObjectives(jpaEntity.getPlayerObjectives())
|
||||||
.narrativeStakes(jpaEntity.getNarrativeStakes())
|
.narrativeStakes(jpaEntity.getNarrativeStakes())
|
||||||
@@ -96,6 +97,7 @@ public class PostgresChapterRepository implements ChapterRepository {
|
|||||||
.description(chapter.getDescription())
|
.description(chapter.getDescription())
|
||||||
.arcId(Long.parseLong(chapter.getArcId()))
|
.arcId(Long.parseLong(chapter.getArcId()))
|
||||||
.order(chapter.getOrder())
|
.order(chapter.getOrder())
|
||||||
|
.icon(chapter.getIcon())
|
||||||
.gmNotes(chapter.getGmNotes())
|
.gmNotes(chapter.getGmNotes())
|
||||||
.playerObjectives(chapter.getPlayerObjectives())
|
.playerObjectives(chapter.getPlayerObjectives())
|
||||||
.narrativeStakes(chapter.getNarrativeStakes())
|
.narrativeStakes(chapter.getNarrativeStakes())
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class PostgresSceneRepository implements SceneRepository {
|
|||||||
.description(jpaEntity.getDescription())
|
.description(jpaEntity.getDescription())
|
||||||
.chapterId(jpaEntity.getChapterId().toString())
|
.chapterId(jpaEntity.getChapterId().toString())
|
||||||
.order(jpaEntity.getOrder())
|
.order(jpaEntity.getOrder())
|
||||||
|
.icon(jpaEntity.getIcon())
|
||||||
.location(jpaEntity.getLocation())
|
.location(jpaEntity.getLocation())
|
||||||
.timing(jpaEntity.getTiming())
|
.timing(jpaEntity.getTiming())
|
||||||
.atmosphere(jpaEntity.getAtmosphere())
|
.atmosphere(jpaEntity.getAtmosphere())
|
||||||
@@ -104,6 +105,7 @@ public class PostgresSceneRepository implements SceneRepository {
|
|||||||
.description(scene.getDescription())
|
.description(scene.getDescription())
|
||||||
.chapterId(Long.parseLong(scene.getChapterId()))
|
.chapterId(Long.parseLong(scene.getChapterId()))
|
||||||
.order(scene.getOrder())
|
.order(scene.getOrder())
|
||||||
|
.icon(scene.getIcon())
|
||||||
.location(scene.getLocation())
|
.location(scene.getLocation())
|
||||||
.timing(scene.getTiming())
|
.timing(scene.getTiming())
|
||||||
.atmosphere(scene.getAtmosphere())
|
.atmosphere(scene.getAtmosphere())
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class ArcController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<ArcDTO> createArc(@RequestBody ArcDTO arcDTO) {
|
public ResponseEntity<ArcDTO> createArc(@RequestBody ArcDTO arcDTO) {
|
||||||
Arc arc = arcMapper.toDomain(arcDTO);
|
Arc arc = arcMapper.toDomain(arcDTO);
|
||||||
Arc createdArc = arcService.createArc(arc.getName(), arc.getDescription(), arc.getCampaignId(), arc.getOrder());
|
Arc createdArc = arcService.createArc(arc.getName(), arc.getDescription(), arc.getCampaignId(), arc.getOrder(), arc.getIcon());
|
||||||
return ResponseEntity.ok(arcMapper.toDTO(createdArc));
|
return ResponseEntity.ok(arcMapper.toDTO(createdArc));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,17 +40,11 @@ public class ArcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<List<ArcDTO>> getAllArcs() {
|
public ResponseEntity<List<ArcDTO>> getAllArcs(
|
||||||
List<Arc> arcs = arcService.getAllArcs();
|
@RequestParam(value = "campaignId", required = false) String campaignId) {
|
||||||
List<ArcDTO> arcDTOs = arcs.stream()
|
List<Arc> arcs = (campaignId != null && !campaignId.isBlank())
|
||||||
.map(arcMapper::toDTO)
|
? arcService.getArcsByCampaignId(campaignId)
|
||||||
.collect(Collectors.toList());
|
: arcService.getAllArcs();
|
||||||
return ResponseEntity.ok(arcDTOs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/campaign/{campaignId}")
|
|
||||||
public ResponseEntity<List<ArcDTO>> getArcsByCampaignId(@PathVariable String campaignId) {
|
|
||||||
List<Arc> arcs = arcService.getArcsByCampaignId(campaignId);
|
|
||||||
List<ArcDTO> arcDTOs = arcs.stream()
|
List<ArcDTO> arcDTOs = arcs.stream()
|
||||||
.map(arcMapper::toDTO)
|
.map(arcMapper::toDTO)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class ChapterController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<ChapterDTO> createChapter(@RequestBody ChapterDTO chapterDTO) {
|
public ResponseEntity<ChapterDTO> createChapter(@RequestBody ChapterDTO chapterDTO) {
|
||||||
Chapter chapter = chapterMapper.toDomain(chapterDTO);
|
Chapter chapter = chapterMapper.toDomain(chapterDTO);
|
||||||
Chapter createdChapter = chapterService.createChapter(chapter.getName(), chapter.getDescription(), chapter.getArcId(), chapter.getOrder());
|
Chapter createdChapter = chapterService.createChapter(chapter.getName(), chapter.getDescription(), chapter.getArcId(), chapter.getOrder(), chapter.getIcon());
|
||||||
return ResponseEntity.ok(chapterMapper.toDTO(createdChapter));
|
return ResponseEntity.ok(chapterMapper.toDTO(createdChapter));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,17 +40,11 @@ public class ChapterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<List<ChapterDTO>> getAllChapters() {
|
public ResponseEntity<List<ChapterDTO>> getAllChapters(
|
||||||
List<Chapter> chapters = chapterService.getAllChapters();
|
@RequestParam(value = "arcId", required = false) String arcId) {
|
||||||
List<ChapterDTO> chapterDTOs = chapters.stream()
|
List<Chapter> chapters = (arcId != null && !arcId.isBlank())
|
||||||
.map(chapterMapper::toDTO)
|
? chapterService.getChaptersByArcId(arcId)
|
||||||
.collect(Collectors.toList());
|
: chapterService.getAllChapters();
|
||||||
return ResponseEntity.ok(chapterDTOs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/arc/{arcId}")
|
|
||||||
public ResponseEntity<List<ChapterDTO>> getChaptersByArcId(@PathVariable String arcId) {
|
|
||||||
List<Chapter> chapters = chapterService.getChaptersByArcId(arcId);
|
|
||||||
List<ChapterDTO> chapterDTOs = chapters.stream()
|
List<ChapterDTO> chapterDTOs = chapters.stream()
|
||||||
.map(chapterMapper::toDTO)
|
.map(chapterMapper::toDTO)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.loremind.infrastructure.web.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose la configuration publique consommee par le frontend au demarrage.
|
||||||
|
* Activer le mode demo via la variable d'env DEMO_MODE=true : le front
|
||||||
|
* masque alors Settings / Export VTT, et les endpoints sensibles sont
|
||||||
|
* verrouilles cote serveur (cf. SettingsController).
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/config")
|
||||||
|
public class ConfigController {
|
||||||
|
|
||||||
|
private final boolean demoMode;
|
||||||
|
|
||||||
|
public ConfigController(@Value("${app.demo-mode:false}") boolean demoMode) {
|
||||||
|
this.demoMode = demoMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Map<String, Object> getPublicConfig() {
|
||||||
|
return Map.of("demoMode", demoMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ public class SceneController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<SceneDTO> createScene(@RequestBody SceneDTO sceneDTO) {
|
public ResponseEntity<SceneDTO> createScene(@RequestBody SceneDTO sceneDTO) {
|
||||||
Scene scene = sceneMapper.toDomain(sceneDTO);
|
Scene scene = sceneMapper.toDomain(sceneDTO);
|
||||||
Scene createdScene = sceneService.createScene(scene.getName(), scene.getDescription(), scene.getChapterId(), scene.getOrder());
|
Scene createdScene = sceneService.createScene(scene.getName(), scene.getDescription(), scene.getChapterId(), scene.getOrder(), scene.getIcon());
|
||||||
return ResponseEntity.ok(sceneMapper.toDTO(createdScene));
|
return ResponseEntity.ok(sceneMapper.toDTO(createdScene));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,17 +40,11 @@ public class SceneController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<List<SceneDTO>> getAllScenes() {
|
public ResponseEntity<List<SceneDTO>> getAllScenes(
|
||||||
List<Scene> scenes = sceneService.getAllScenes();
|
@RequestParam(value = "chapterId", required = false) String chapterId) {
|
||||||
List<SceneDTO> sceneDTOs = scenes.stream()
|
List<Scene> scenes = (chapterId != null && !chapterId.isBlank())
|
||||||
.map(sceneMapper::toDTO)
|
? sceneService.getScenesByChapterId(chapterId)
|
||||||
.collect(Collectors.toList());
|
: sceneService.getAllScenes();
|
||||||
return ResponseEntity.ok(sceneDTOs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/chapter/{chapterId}")
|
|
||||||
public ResponseEntity<List<SceneDTO>> getScenesByChapterId(@PathVariable String chapterId) {
|
|
||||||
List<Scene> scenes = sceneService.getScenesByChapterId(chapterId);
|
|
||||||
List<SceneDTO> sceneDTOs = scenes.stream()
|
List<SceneDTO> sceneDTOs = scenes.stream()
|
||||||
.map(sceneMapper::toDTO)
|
.map(sceneMapper::toDTO)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -32,20 +34,25 @@ public class SettingsController {
|
|||||||
|
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
private final String brainBaseUrl;
|
private final String brainBaseUrl;
|
||||||
|
private final boolean demoMode;
|
||||||
|
|
||||||
public SettingsController(RestTemplate restTemplate,
|
public SettingsController(RestTemplate restTemplate,
|
||||||
@Value("${brain.base-url}") String brainBaseUrl) {
|
@Value("${brain.base-url}") String brainBaseUrl,
|
||||||
|
@Value("${app.demo-mode:false}") boolean demoMode) {
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
this.brainBaseUrl = brainBaseUrl;
|
this.brainBaseUrl = brainBaseUrl;
|
||||||
|
this.demoMode = demoMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<Map<String, Object>> getSettings() {
|
public ResponseEntity<Map<String, Object>> getSettings() {
|
||||||
|
guardDemoMode();
|
||||||
return forward(HttpMethod.GET, "/settings", null);
|
return forward(HttpMethod.GET, "/settings", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public ResponseEntity<Map<String, Object>> updateSettings(@RequestBody Map<String, Object> patch) {
|
public ResponseEntity<Map<String, Object>> updateSettings(@RequestBody Map<String, Object> patch) {
|
||||||
|
guardDemoMode();
|
||||||
return forward(HttpMethod.PUT, "/settings", patch);
|
return forward(HttpMethod.PUT, "/settings", patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +71,12 @@ public class SettingsController {
|
|||||||
return forward(HttpMethod.GET, "/models/onemin", null);
|
return forward(HttpMethod.GET, "/models/onemin", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void guardDemoMode() {
|
||||||
|
if (demoMode) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Settings disabled in demo mode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
private ResponseEntity<Map<String, Object>> forward(HttpMethod method, String path, Object body) {
|
private ResponseEntity<Map<String, Object>> forward(HttpMethod method, String path, Object body) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ public class ArcDTO {
|
|||||||
private String campaignId;
|
private String campaignId;
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
/** Cle d'icone (cf. CAMPAIGN_ICON_OPTIONS cote front). */
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis
|
// Champs narratifs enrichis
|
||||||
private String themes;
|
private String themes;
|
||||||
private String stakes;
|
private String stakes;
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ public class ChapterDTO {
|
|||||||
private String arcId;
|
private String arcId;
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
/** Cle d'icone (cf. CAMPAIGN_ICON_OPTIONS cote front). */
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis
|
// Champs narratifs enrichis
|
||||||
private String gmNotes;
|
private String gmNotes;
|
||||||
private String playerObjectives;
|
private String playerObjectives;
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ public class SceneDTO {
|
|||||||
private String chapterId;
|
private String chapterId;
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
/** Cle d'icone (cf. CAMPAIGN_ICON_OPTIONS cote front). */
|
||||||
|
private String icon;
|
||||||
|
|
||||||
// Champs narratifs enrichis
|
// Champs narratifs enrichis
|
||||||
private String location;
|
private String location;
|
||||||
private String timing;
|
private String timing;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class ArcMapper {
|
|||||||
dto.setDescription(arc.getDescription());
|
dto.setDescription(arc.getDescription());
|
||||||
dto.setCampaignId(arc.getCampaignId());
|
dto.setCampaignId(arc.getCampaignId());
|
||||||
dto.setOrder(arc.getOrder());
|
dto.setOrder(arc.getOrder());
|
||||||
|
dto.setIcon(arc.getIcon());
|
||||||
dto.setThemes(arc.getThemes());
|
dto.setThemes(arc.getThemes());
|
||||||
dto.setStakes(arc.getStakes());
|
dto.setStakes(arc.getStakes());
|
||||||
dto.setGmNotes(arc.getGmNotes());
|
dto.setGmNotes(arc.getGmNotes());
|
||||||
@@ -46,6 +47,7 @@ public class ArcMapper {
|
|||||||
.description(dto.getDescription())
|
.description(dto.getDescription())
|
||||||
.campaignId(dto.getCampaignId())
|
.campaignId(dto.getCampaignId())
|
||||||
.order(dto.getOrder())
|
.order(dto.getOrder())
|
||||||
|
.icon(dto.getIcon())
|
||||||
.themes(dto.getThemes())
|
.themes(dto.getThemes())
|
||||||
.stakes(dto.getStakes())
|
.stakes(dto.getStakes())
|
||||||
.gmNotes(dto.getGmNotes())
|
.gmNotes(dto.getGmNotes())
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class ChapterMapper {
|
|||||||
dto.setDescription(chapter.getDescription());
|
dto.setDescription(chapter.getDescription());
|
||||||
dto.setArcId(chapter.getArcId());
|
dto.setArcId(chapter.getArcId());
|
||||||
dto.setOrder(chapter.getOrder());
|
dto.setOrder(chapter.getOrder());
|
||||||
|
dto.setIcon(chapter.getIcon());
|
||||||
dto.setGmNotes(chapter.getGmNotes());
|
dto.setGmNotes(chapter.getGmNotes());
|
||||||
dto.setPlayerObjectives(chapter.getPlayerObjectives());
|
dto.setPlayerObjectives(chapter.getPlayerObjectives());
|
||||||
dto.setNarrativeStakes(chapter.getNarrativeStakes());
|
dto.setNarrativeStakes(chapter.getNarrativeStakes());
|
||||||
@@ -44,6 +45,7 @@ public class ChapterMapper {
|
|||||||
.description(dto.getDescription())
|
.description(dto.getDescription())
|
||||||
.arcId(dto.getArcId())
|
.arcId(dto.getArcId())
|
||||||
.order(dto.getOrder())
|
.order(dto.getOrder())
|
||||||
|
.icon(dto.getIcon())
|
||||||
.gmNotes(dto.getGmNotes())
|
.gmNotes(dto.getGmNotes())
|
||||||
.playerObjectives(dto.getPlayerObjectives())
|
.playerObjectives(dto.getPlayerObjectives())
|
||||||
.narrativeStakes(dto.getNarrativeStakes())
|
.narrativeStakes(dto.getNarrativeStakes())
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class SceneMapper {
|
|||||||
dto.setDescription(scene.getDescription());
|
dto.setDescription(scene.getDescription());
|
||||||
dto.setChapterId(scene.getChapterId());
|
dto.setChapterId(scene.getChapterId());
|
||||||
dto.setOrder(scene.getOrder());
|
dto.setOrder(scene.getOrder());
|
||||||
|
dto.setIcon(scene.getIcon());
|
||||||
dto.setLocation(scene.getLocation());
|
dto.setLocation(scene.getLocation());
|
||||||
dto.setTiming(scene.getTiming());
|
dto.setTiming(scene.getTiming());
|
||||||
dto.setAtmosphere(scene.getAtmosphere());
|
dto.setAtmosphere(scene.getAtmosphere());
|
||||||
@@ -59,6 +60,7 @@ public class SceneMapper {
|
|||||||
.description(dto.getDescription())
|
.description(dto.getDescription())
|
||||||
.chapterId(dto.getChapterId())
|
.chapterId(dto.getChapterId())
|
||||||
.order(dto.getOrder())
|
.order(dto.getOrder())
|
||||||
|
.icon(dto.getIcon())
|
||||||
.location(dto.getLocation())
|
.location(dto.getLocation())
|
||||||
.timing(dto.getTiming())
|
.timing(dto.getTiming())
|
||||||
.atmosphere(dto.getAtmosphere())
|
.atmosphere(dto.getAtmosphere())
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ spring.jpa.show-sql=true
|
|||||||
spring.jpa.properties.hibernate.format_sql=true
|
spring.jpa.properties.hibernate.format_sql=true
|
||||||
|
|
||||||
# Configuration CORS pour autoriser le Frontend Angular
|
# Configuration CORS pour autoriser le Frontend Angular
|
||||||
spring.web.cors.allowed-origins=http://localhost:4200
|
spring.web.cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:4200}
|
||||||
spring.web.cors.allowed-methods=GET,POST,PUT,DELETE,OPTIONS
|
spring.web.cors.allowed-methods=GET,POST,PUT,DELETE,OPTIONS
|
||||||
spring.web.cors.allowed-headers=*
|
spring.web.cors.allowed-headers=*
|
||||||
spring.web.cors.allow-credentials=true
|
spring.web.cors.allow-credentials=true
|
||||||
|
|
||||||
# Configuration du Brain (service IA Python)
|
# Configuration du Brain (service IA Python)
|
||||||
brain.base-url=http://localhost:8000
|
brain.base-url=${BRAIN_BASE_URL:http://localhost:8000}
|
||||||
brain.timeout-seconds=120
|
brain.timeout-seconds=120
|
||||||
|
|
||||||
# Secret partage Core <-> Brain (auth inter-service via entete X-Internal-Secret).
|
# Secret partage Core <-> Brain (auth inter-service via entete X-Internal-Secret).
|
||||||
@@ -50,3 +50,7 @@ minio.bucket=${MINIO_BUCKET:loremind-images}
|
|||||||
# Limites d'upload d'images (MB)
|
# Limites d'upload d'images (MB)
|
||||||
spring.servlet.multipart.max-file-size=10MB
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
spring.servlet.multipart.max-request-size=10MB
|
||||||
|
|
||||||
|
# Mode demo : masque Settings/Export cote front et bloque les PUT /api/settings
|
||||||
|
# cote serveur. Activer via DEMO_MODE=true sur les deploiements publics.
|
||||||
|
app.demo-mode=${DEMO_MODE:false}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class ArcControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
void getByCampaign_pathVariant() throws Exception {
|
void getByCampaign_pathVariant() throws Exception {
|
||||||
arcRepository.save(Arc.builder().campaignId(campaignId).name("A").order(0).build());
|
arcRepository.save(Arc.builder().campaignId(campaignId).name("A").order(0).build());
|
||||||
mockMvc.perform(get("/api/arcs/campaign/{id}", campaignId))
|
mockMvc.perform(get("/api/arcs").param("campaignId", campaignId))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$").isArray());
|
.andExpect(jsonPath("$").isArray());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class ChapterControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
void getByArc_pathVariant() throws Exception {
|
void getByArc_pathVariant() throws Exception {
|
||||||
chapterRepository.save(Chapter.builder().arcId(arcId).name("A").order(0).build());
|
chapterRepository.save(Chapter.builder().arcId(arcId).name("A").order(0).build());
|
||||||
mockMvc.perform(get("/api/chapters/arc/{id}", arcId))
|
mockMvc.perform(get("/api/chapters").param("arcId", arcId))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$").isArray());
|
.andExpect(jsonPath("$").isArray());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class SceneControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
void getByChapter_pathVariant() throws Exception {
|
void getByChapter_pathVariant() throws Exception {
|
||||||
sceneRepository.save(Scene.builder().chapterId(chapterId).name("A").order(0).build());
|
sceneRepository.save(Scene.builder().chapterId(chapterId).name("A").order(0).build());
|
||||||
mockMvc.perform(get("/api/scenes/chapter/{id}", chapterId))
|
mockMvc.perform(get("/api/scenes").param("chapterId", chapterId))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$").isArray());
|
.andExpect(jsonPath("$").isArray());
|
||||||
}
|
}
|
||||||
|
|||||||
27
demo/.env.example
Normal file
27
demo/.env.example
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Copie en .env sur le serveur (jamais commite).
|
||||||
|
|
||||||
|
# Registre et tag des images core / brain a spawner par session.
|
||||||
|
REGISTRY=git.igmlcreation.fr
|
||||||
|
TAG=latest
|
||||||
|
|
||||||
|
# Secret partage entre core et brain (genere aleatoirement au build de chaque
|
||||||
|
# session, mais un defaut est utile pour les checks de sante au boot).
|
||||||
|
BRAIN_INTERNAL_SECRET_DEFAULT=change-me-on-server
|
||||||
|
|
||||||
|
# Capacite
|
||||||
|
MAX_SESSIONS=10
|
||||||
|
SESSION_TTL_MINUTES=20
|
||||||
|
|
||||||
|
# Rate limiting : 1 creation de session par IP par fenetre (secondes).
|
||||||
|
RATE_LIMIT_WINDOW_SECONDS=60
|
||||||
|
|
||||||
|
# Limites par conteneur de session (Docker API)
|
||||||
|
CORE_MEMORY_MB=700
|
||||||
|
BRAIN_MEMORY_MB=300
|
||||||
|
POSTGRES_MEMORY_MB=200
|
||||||
|
|
||||||
|
# Nom du reseau Docker externe Traefik (doit exister avant docker compose up)
|
||||||
|
TRAEFIK_NETWORK=traefik
|
||||||
|
|
||||||
|
# Domaine expose par Traefik
|
||||||
|
DEMO_HOST=loremind-demo.igmlcreation.fr
|
||||||
2
demo/.gitignore
vendored
Normal file
2
demo/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.env
|
||||||
|
*.log
|
||||||
46
demo/README.md
Normal file
46
demo/README.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Demo publique LoreMind
|
||||||
|
|
||||||
|
Deploiement d'une instance de demo ephemere pour `loremind-demo.igmlcreation.fr`.
|
||||||
|
|
||||||
|
## Principe
|
||||||
|
|
||||||
|
Chaque visiteur recoit un environnement isole spawne a la volee, detruit apres
|
||||||
|
un court delai d'inactivite. Les donnees ne sont jamais persistees.
|
||||||
|
|
||||||
|
Le mode demo (variable d'env `DEMO_MODE=true` sur le core) masque les ecrans
|
||||||
|
de configuration qui n'ont pas de sens en vitrine.
|
||||||
|
|
||||||
|
## Deploiement
|
||||||
|
|
||||||
|
Prerequis :
|
||||||
|
- Reseau Traefik existant cote host
|
||||||
|
- Images `core` et `brain` pushees au registre
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
# Ajuster .env
|
||||||
|
docker compose -f docker-compose.infra.yml up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
Premier build : 5-10 min. Suivants : incrementaux.
|
||||||
|
|
||||||
|
## Mise a jour
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose -f docker-compose.infra.yml pull
|
||||||
|
docker compose -f docker-compose.infra.yml up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
Les sessions en cours sont tuees au redemarrage.
|
||||||
|
|
||||||
|
## Observations
|
||||||
|
|
||||||
|
- `docker logs loremind-demo-orchestrator -f`
|
||||||
|
- `docker ps --filter "name=demo-"`
|
||||||
|
|
||||||
|
## Desactiver
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose -f docker-compose.infra.yml down
|
||||||
|
docker ps -q --filter "name=demo-" | xargs -r docker rm -f
|
||||||
|
```
|
||||||
80
demo/docker-compose.infra.yml
Normal file
80
demo/docker-compose.infra.yml
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
# ==========================================================================
|
||||||
|
# LoreMind Demo - Infra permanente
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# - dockerproxy : expose un subset restreint de l'API Docker a l'orchestrateur
|
||||||
|
# (lecture seule sauf containers/images/networks). Remplace le mount direct
|
||||||
|
# de /var/run/docker.sock : meme avec RCE sur l'orchestrateur, un attaquant
|
||||||
|
# ne peut pas exec sur l'hote, creer des volumes, ni lire le daemon.
|
||||||
|
# - orchestrator : sert l'Angular et proxy les /api/* vers les sessions.
|
||||||
|
#
|
||||||
|
# Les conteneurs de session sont crees dynamiquement par l'orchestrateur.
|
||||||
|
# ==========================================================================
|
||||||
|
|
||||||
|
services:
|
||||||
|
dockerproxy:
|
||||||
|
image: tecnativa/docker-socket-proxy:latest
|
||||||
|
container_name: loremind-demo-dockerproxy
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
# Minimum requis par l'orchestrateur.
|
||||||
|
CONTAINERS: 1
|
||||||
|
IMAGES: 1
|
||||||
|
NETWORKS: 1
|
||||||
|
POST: 1
|
||||||
|
# Tout le reste reste a 0 (defaut) : pas d'EXEC, VOLUMES, BUILD, AUTH,
|
||||||
|
# SYSTEM, INFO, SWARM, SECRETS, CONFIGS, NODES, etc.
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
|
networks:
|
||||||
|
- socket-proxy
|
||||||
|
# Pas de ports exposes : accessible uniquement via le reseau socket-proxy.
|
||||||
|
|
||||||
|
orchestrator:
|
||||||
|
container_name: loremind-demo-orchestrator
|
||||||
|
depends_on:
|
||||||
|
- dockerproxy
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: demo/orchestrator/Dockerfile
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
# L'orchestrateur parle a dockerproxy au lieu du socket direct.
|
||||||
|
DOCKER_HOST: tcp://dockerproxy:2375
|
||||||
|
REGISTRY: ${REGISTRY:-git.igmlcreation.fr}
|
||||||
|
TAG: ${TAG:-latest}
|
||||||
|
MAX_SESSIONS: ${MAX_SESSIONS:-10}
|
||||||
|
SESSION_TTL_MINUTES: ${SESSION_TTL_MINUTES:-20}
|
||||||
|
CORE_MEMORY_MB: ${CORE_MEMORY_MB:-700}
|
||||||
|
BRAIN_MEMORY_MB: ${BRAIN_MEMORY_MB:-300}
|
||||||
|
POSTGRES_MEMORY_MB: ${POSTGRES_MEMORY_MB:-200}
|
||||||
|
SESSIONS_NETWORK: loremind-demo-sessions
|
||||||
|
BRAIN_INTERNAL_SECRET_DEFAULT: ${BRAIN_INTERNAL_SECRET_DEFAULT:-change-me}
|
||||||
|
# Rate limit : 1 creation par IP par fenetre (en secondes).
|
||||||
|
RATE_LIMIT_WINDOW_SECONDS: ${RATE_LIMIT_WINDOW_SECONDS:-60}
|
||||||
|
# Domaine public : propage aux cores de session pour configurer CORS.
|
||||||
|
DEMO_HOST: ${DEMO_HOST:-loremind-demo.igmlcreation.fr}
|
||||||
|
networks:
|
||||||
|
- traefik
|
||||||
|
- sessions
|
||||||
|
- socket-proxy
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.loremind-demo.rule=Host(`${DEMO_HOST:-loremind-demo.igmlcreation.fr}`)"
|
||||||
|
- "traefik.http.routers.loremind-demo.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.loremind-demo.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.services.loremind-demo.loadbalancer.server.port=80"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
traefik:
|
||||||
|
external: true
|
||||||
|
name: ${TRAEFIK_NETWORK:-traefik}
|
||||||
|
sessions:
|
||||||
|
# Reseau interne pour les trios de session. Pas d'acces Internet direct
|
||||||
|
# (sauf via le DNS Docker), pas expose au host.
|
||||||
|
name: loremind-demo-sessions
|
||||||
|
driver: bridge
|
||||||
|
socket-proxy:
|
||||||
|
# Reseau prive entre dockerproxy et orchestrateur. Isole du reste.
|
||||||
|
name: loremind-demo-socket-proxy
|
||||||
|
driver: bridge
|
||||||
|
internal: true
|
||||||
32
demo/orchestrator/Dockerfile
Normal file
32
demo/orchestrator/Dockerfile
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# syntax=docker/dockerfile:1.6
|
||||||
|
# Build context attendu : racine du repo LoreMind.
|
||||||
|
# Appele depuis demo/docker-compose.infra.yml avec context: ../
|
||||||
|
|
||||||
|
# --- Etage 1 : build Angular statique ---
|
||||||
|
FROM node:20-alpine AS web-build
|
||||||
|
WORKDIR /build
|
||||||
|
COPY web/package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY web/ .
|
||||||
|
RUN npm run build -- --configuration production
|
||||||
|
|
||||||
|
# --- Etage 2 : build orchestrateur Go ---
|
||||||
|
# go 1.25+ requis par une dependance transitive de github.com/docker/docker
|
||||||
|
# (otelhttp v0.68+ impose cette version minimale).
|
||||||
|
FROM golang:1.25-alpine AS go-build
|
||||||
|
WORKDIR /src
|
||||||
|
COPY demo/orchestrator/ ./
|
||||||
|
# go mod tidy resout le go.sum au build pour eviter d'avoir a le committer.
|
||||||
|
RUN go mod tidy && CGO_ENABLED=0 go build -o /orchestrator .
|
||||||
|
|
||||||
|
# --- Etage final : runtime minimal ---
|
||||||
|
FROM alpine:3.20
|
||||||
|
RUN apk add --no-cache ca-certificates
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=go-build /orchestrator /app/orchestrator
|
||||||
|
COPY --from=web-build /build/dist/web /app/static
|
||||||
|
COPY demo/orchestrator/preparing.html /app/preparing.html
|
||||||
|
EXPOSE 80
|
||||||
|
ENV STATIC_DIR=/app/static \
|
||||||
|
PREPARING_PAGE=/app/preparing.html
|
||||||
|
ENTRYPOINT ["/app/orchestrator"]
|
||||||
68
demo/orchestrator/config.go
Normal file
68
demo/orchestrator/config.go
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config centralise les parametres lus depuis les variables d'env au boot.
|
||||||
|
type Config struct {
|
||||||
|
Registry string
|
||||||
|
Tag string
|
||||||
|
MaxSessions int
|
||||||
|
SessionTTL time.Duration
|
||||||
|
CoreMemoryBytes int64
|
||||||
|
BrainMemoryBytes int64
|
||||||
|
PostgresMemoryBytes int64
|
||||||
|
SessionsNetwork string
|
||||||
|
BrainSecretDefault string
|
||||||
|
StaticDir string
|
||||||
|
PreparingPage string
|
||||||
|
RateLimitWindow time.Duration
|
||||||
|
MaxBodyBytes int64
|
||||||
|
DemoHost string
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
Registry: envStr("REGISTRY", "git.igmlcreation.fr"),
|
||||||
|
Tag: envStr("TAG", "latest"),
|
||||||
|
MaxSessions: envInt("MAX_SESSIONS", 10),
|
||||||
|
SessionTTL: time.Duration(envInt("SESSION_TTL_MINUTES", 20)) * time.Minute,
|
||||||
|
CoreMemoryBytes: int64(envInt("CORE_MEMORY_MB", 700)) * 1024 * 1024,
|
||||||
|
BrainMemoryBytes: int64(envInt("BRAIN_MEMORY_MB", 300)) * 1024 * 1024,
|
||||||
|
PostgresMemoryBytes: int64(envInt("POSTGRES_MEMORY_MB", 200)) * 1024 * 1024,
|
||||||
|
SessionsNetwork: envStr("SESSIONS_NETWORK", "loremind-demo-sessions"),
|
||||||
|
BrainSecretDefault: envStr("BRAIN_INTERNAL_SECRET_DEFAULT", "change-me"),
|
||||||
|
StaticDir: envStr("STATIC_DIR", "/app/static"),
|
||||||
|
PreparingPage: envStr("PREPARING_PAGE", "/app/preparing.html"),
|
||||||
|
RateLimitWindow: time.Duration(envInt("RATE_LIMIT_WINDOW_SECONDS", 60)) * time.Second,
|
||||||
|
// 10 Mo : aligne avec la limite d'upload d'image cote core.
|
||||||
|
MaxBodyBytes: int64(envInt("MAX_BODY_MB", 10)) * 1024 * 1024,
|
||||||
|
// Utilise pour injecter APP_CORS_ALLOWED_ORIGINS dans les cores spawnes :
|
||||||
|
// sans ca, Spring bloque les POST avec 403 (origine rejetee).
|
||||||
|
DemoHost: envStr("DEMO_HOST", "loremind-demo.igmlcreation.fr"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func envStr(key, def string) string {
|
||||||
|
if v := os.Getenv(key); v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
|
||||||
|
func envInt(key string, def int) int {
|
||||||
|
v := os.Getenv(key)
|
||||||
|
if v == "" {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
i, err := strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("warning: env %s=%q not a number, using default %d", key, v, def)
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
339
demo/orchestrator/docker.go
Normal file
339
demo/orchestrator/docker.go
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DockerClient parle a l'API Engine Docker en HTTP brut via le dockerproxy.
|
||||||
|
// Pas de SDK externe : evite les conflits de versions transitives qui
|
||||||
|
// rendaient github.com/docker/docker v27/v28 ininstallable proprement.
|
||||||
|
//
|
||||||
|
// L'API Engine v1.43 est exposee par Docker Engine 24+ (et le dockerproxy
|
||||||
|
// la supporte sans config supplementaire).
|
||||||
|
type DockerClient struct {
|
||||||
|
baseURL string
|
||||||
|
http *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDockerClient() (*DockerClient, error) {
|
||||||
|
base := os.Getenv("DOCKER_HOST")
|
||||||
|
if base == "" {
|
||||||
|
return nil, fmt.Errorf("DOCKER_HOST non defini (attendu : tcp://dockerproxy:2375)")
|
||||||
|
}
|
||||||
|
// tcp://host:port -> http://host:port (le dockerproxy parle HTTP en clair).
|
||||||
|
base = strings.Replace(base, "tcp://", "http://", 1)
|
||||||
|
return &DockerClient{
|
||||||
|
baseURL: strings.TrimRight(base, "/") + "/v1.43",
|
||||||
|
http: &http.Client{Timeout: 60 * time.Second},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Types serialises vers l'API Engine ---
|
||||||
|
|
||||||
|
type containerSpec struct {
|
||||||
|
Image string `json:"Image"`
|
||||||
|
Env []string `json:"Env,omitempty"`
|
||||||
|
Labels map[string]string `json:"Labels,omitempty"`
|
||||||
|
HostConfig hostConfig `json:"HostConfig"`
|
||||||
|
NetworkingConfig networkingConfig `json:"NetworkingConfig"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type hostConfig struct {
|
||||||
|
Memory int64 `json:"Memory,omitempty"`
|
||||||
|
NanoCPUs int64 `json:"NanoCPUs,omitempty"`
|
||||||
|
PidsLimit int64 `json:"PidsLimit,omitempty"`
|
||||||
|
Tmpfs map[string]string `json:"Tmpfs,omitempty"`
|
||||||
|
SecurityOpt []string `json:"SecurityOpt,omitempty"`
|
||||||
|
RestartPolicy restartPolicy `json:"RestartPolicy"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type restartPolicy struct {
|
||||||
|
Name string `json:"Name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type networkingConfig struct {
|
||||||
|
EndpointsConfig map[string]endpointSettings `json:"EndpointsConfig,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type endpointSettings struct {
|
||||||
|
Aliases []string `json:"Aliases,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// runSpec : forme intermediate cote orchestrateur, mappee sur containerSpec
|
||||||
|
// au moment d'envoyer la requete.
|
||||||
|
type runSpec struct {
|
||||||
|
Name string
|
||||||
|
Image string
|
||||||
|
Env []string
|
||||||
|
Labels map[string]string
|
||||||
|
Memory int64
|
||||||
|
Tmpfs map[string]string
|
||||||
|
Net string
|
||||||
|
Alias string
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Operations de haut niveau ---
|
||||||
|
|
||||||
|
// SpawnTrio cree postgres + brain + core pour une session.
|
||||||
|
func (d *DockerClient) SpawnTrio(ctx context.Context, sessionID string, cfg *Config) error {
|
||||||
|
pgName := "demo-" + sessionID + "-postgres"
|
||||||
|
brainName := "demo-" + sessionID + "-brain"
|
||||||
|
coreName := "demo-" + sessionID + "-core"
|
||||||
|
pgPassword := randomHex(16)
|
||||||
|
brainSecret := randomHex(32)
|
||||||
|
adminPassword := randomHex(16)
|
||||||
|
|
||||||
|
labels := map[string]string{"demo-session": sessionID}
|
||||||
|
|
||||||
|
if err := d.runContainer(ctx, runSpec{
|
||||||
|
Name: pgName,
|
||||||
|
Image: "postgres:16-alpine",
|
||||||
|
Env: []string{"POSTGRES_DB=loremind", "POSTGRES_USER=loremind", "POSTGRES_PASSWORD=" + pgPassword},
|
||||||
|
Labels: copyLabels(labels, "postgres"),
|
||||||
|
Memory: cfg.PostgresMemoryBytes,
|
||||||
|
Tmpfs: map[string]string{"/var/lib/postgresql/data": "rw,size=200m"},
|
||||||
|
Net: cfg.SessionsNetwork,
|
||||||
|
Alias: pgName,
|
||||||
|
}); err != nil {
|
||||||
|
return fmt.Errorf("spawn postgres: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.runContainer(ctx, runSpec{
|
||||||
|
Name: brainName,
|
||||||
|
Image: cfg.Registry + "/ietm64/brain:" + cfg.Tag,
|
||||||
|
Env: []string{
|
||||||
|
"INTERNAL_SHARED_SECRET=" + brainSecret,
|
||||||
|
// Pas de provider LLM configure en demo : les features IA echoueront
|
||||||
|
// proprement, la demo sert principalement a explorer l'edition.
|
||||||
|
"LLM_PROVIDER=ollama",
|
||||||
|
"OLLAMA_BASE_URL=http://localhost:1",
|
||||||
|
},
|
||||||
|
Labels: copyLabels(labels, "brain"),
|
||||||
|
Memory: cfg.BrainMemoryBytes,
|
||||||
|
Net: cfg.SessionsNetwork,
|
||||||
|
Alias: brainName,
|
||||||
|
}); err != nil {
|
||||||
|
return fmt.Errorf("spawn brain: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.runContainer(ctx, runSpec{
|
||||||
|
Name: coreName,
|
||||||
|
Image: cfg.Registry + "/ietm64/core:" + cfg.Tag,
|
||||||
|
Env: []string{
|
||||||
|
"SPRING_DATASOURCE_URL=jdbc:postgresql://" + pgName + ":5432/loremind",
|
||||||
|
"SPRING_DATASOURCE_USERNAME=loremind",
|
||||||
|
"SPRING_DATASOURCE_PASSWORD=" + pgPassword,
|
||||||
|
"BRAIN_BASE_URL=http://" + brainName + ":8000",
|
||||||
|
"BRAIN_INTERNAL_SECRET=" + brainSecret,
|
||||||
|
"ADMIN_USERNAME=admin",
|
||||||
|
"ADMIN_PASSWORD=" + adminPassword,
|
||||||
|
"DEMO_MODE=true",
|
||||||
|
// CorsConfig.java lit app.cors.allowed-origins (= APP_CORS_ALLOWED_ORIGINS
|
||||||
|
// via le relaxed binding Spring). Necessaire meme en same-origin car
|
||||||
|
// le browser envoie Origin sur les POST et le CorsFilter 403 les
|
||||||
|
// origines inconnues.
|
||||||
|
"APP_CORS_ALLOWED_ORIGINS=https://" + cfg.DemoHost,
|
||||||
|
},
|
||||||
|
Labels: copyLabels(labels, "core"),
|
||||||
|
Memory: cfg.CoreMemoryBytes,
|
||||||
|
Net: cfg.SessionsNetwork,
|
||||||
|
Alias: coreName,
|
||||||
|
}); err != nil {
|
||||||
|
return fmt.Errorf("spawn core: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DockerClient) runContainer(ctx context.Context, s runSpec) error {
|
||||||
|
// Pull best-effort : si l'image est deja locale, ContainerCreate la reprendra.
|
||||||
|
_ = d.pullImage(ctx, s.Image)
|
||||||
|
|
||||||
|
spec := containerSpec{
|
||||||
|
Image: s.Image,
|
||||||
|
Env: s.Env,
|
||||||
|
Labels: s.Labels,
|
||||||
|
HostConfig: hostConfig{
|
||||||
|
Memory: s.Memory,
|
||||||
|
NanoCPUs: 1_000_000_000, // 1 vCPU par conteneur
|
||||||
|
PidsLimit: 200, // anti fork-bomb
|
||||||
|
Tmpfs: s.Tmpfs,
|
||||||
|
SecurityOpt: []string{"no-new-privileges:true"},
|
||||||
|
RestartPolicy: restartPolicy{Name: "no"},
|
||||||
|
},
|
||||||
|
NetworkingConfig: networkingConfig{
|
||||||
|
EndpointsConfig: map[string]endpointSettings{
|
||||||
|
s.Net: {Aliases: []string{s.Alias}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(spec)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
createResp, err := d.do(ctx, "POST", "/containers/create?name="+url.QueryEscape(s.Name), body)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create %s: %w", s.Name, err)
|
||||||
|
}
|
||||||
|
var created struct {
|
||||||
|
ID string `json:"Id"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(createResp, &created); err != nil {
|
||||||
|
return fmt.Errorf("parse create %s: %w", s.Name, err)
|
||||||
|
}
|
||||||
|
if _, err := d.do(ctx, "POST", "/containers/"+created.ID+"/start", nil); err != nil {
|
||||||
|
return fmt.Errorf("start %s: %w", s.Name, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// pullImage drain le flux de progression. Erreur silencieuse : si le pull
|
||||||
|
// echoue (registre prive sans auth, image deja locale), runContainer aura un
|
||||||
|
// retour clair via ContainerCreate.
|
||||||
|
func (d *DockerClient) pullImage(ctx context.Context, img string) error {
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "POST",
|
||||||
|
d.baseURL+"/images/create?fromImage="+url.QueryEscape(img), nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resp, err := d.http.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
|
if resp.StatusCode >= 400 {
|
||||||
|
return fmt.Errorf("pull %s: status %d", img, resp.StatusCode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaitReady poll l'endpoint /api/config du core jusqu'a 200 ou timeout.
|
||||||
|
func (d *DockerClient) WaitReady(ctx context.Context, sessionID string, timeout time.Duration) bool {
|
||||||
|
deadline := time.Now().Add(timeout)
|
||||||
|
target := "http://demo-" + sessionID + "-core:8080/api/config"
|
||||||
|
c := &http.Client{Timeout: 2 * time.Second}
|
||||||
|
for time.Now().Before(deadline) {
|
||||||
|
resp, err := c.Get(target)
|
||||||
|
if err == nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return false
|
||||||
|
case <-time.After(2 * time.Second):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// KillTrio supprime tous les conteneurs labellises demo-session=<id>.
|
||||||
|
func (d *DockerClient) KillTrio(ctx context.Context, sessionID string) error {
|
||||||
|
containers, err := d.listContainersWithLabel(ctx, "demo-session="+sessionID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, c := range containers {
|
||||||
|
_, _ = d.do(ctx, "DELETE", "/containers/"+c.ID+"?force=true", nil)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListSessionIDs : utilise au boot pour retrouver les conteneurs orphelins.
|
||||||
|
func (d *DockerClient) ListSessionIDs(ctx context.Context) ([]string, error) {
|
||||||
|
containers, err := d.listContainersWithLabel(ctx, "demo-session")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
seen := map[string]bool{}
|
||||||
|
for _, c := range containers {
|
||||||
|
if v, ok := c.Labels["demo-session"]; ok && v != "" {
|
||||||
|
seen[v] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out := make([]string, 0, len(seen))
|
||||||
|
for id := range seen {
|
||||||
|
out = append(out, id)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type containerInfo struct {
|
||||||
|
ID string `json:"Id"`
|
||||||
|
Labels map[string]string `json:"Labels"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DockerClient) listContainersWithLabel(ctx context.Context, label string) ([]containerInfo, error) {
|
||||||
|
filters := map[string][]string{"label": {label}}
|
||||||
|
filtersJSON, _ := json.Marshal(filters)
|
||||||
|
q := url.Values{}
|
||||||
|
q.Set("all", "true")
|
||||||
|
q.Set("filters", string(filtersJSON))
|
||||||
|
body, err := d.do(ctx, "GET", "/containers/json?"+q.Encode(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var list []containerInfo
|
||||||
|
if err := json.Unmarshal(body, &list); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// do envoie une requete et renvoie le body. Une reponse 4xx/5xx est convertie
|
||||||
|
// en erreur avec le contenu pour faciliter le debug.
|
||||||
|
func (d *DockerClient) do(ctx context.Context, method, path string, body []byte) ([]byte, error) {
|
||||||
|
var rdr io.Reader
|
||||||
|
if body != nil {
|
||||||
|
rdr = bytes.NewReader(body)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, d.baseURL+path, rdr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if body != nil {
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
}
|
||||||
|
resp, err := d.http.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
out, _ := io.ReadAll(resp.Body)
|
||||||
|
if resp.StatusCode >= 400 {
|
||||||
|
return nil, fmt.Errorf("%s %s: HTTP %d %s", method, path, resp.StatusCode, out)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- helpers ---
|
||||||
|
|
||||||
|
func copyLabels(base map[string]string, role string) map[string]string {
|
||||||
|
out := make(map[string]string, len(base)+1)
|
||||||
|
for k, v := range base {
|
||||||
|
out[k] = v
|
||||||
|
}
|
||||||
|
out["demo-role"] = role
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func randomHex(n int) string {
|
||||||
|
b := make([]byte, n)
|
||||||
|
_, _ = rand.Read(b)
|
||||||
|
return hex.EncodeToString(b)
|
||||||
|
}
|
||||||
8
demo/orchestrator/go.mod
Normal file
8
demo/orchestrator/go.mod
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module github.com/loremind/demo-orchestrator
|
||||||
|
|
||||||
|
go 1.23
|
||||||
|
|
||||||
|
// Aucune dependance externe : on parle a Docker Engine en HTTP brut
|
||||||
|
// (cf. docker.go) plutot que d'utiliser github.com/docker/docker, dont le
|
||||||
|
// graphe transitif est instable d'une version a l'autre (sockets.DialPipe,
|
||||||
|
// errors.As/Is, otelhttp...).
|
||||||
231
demo/orchestrator/main.go
Normal file
231
demo/orchestrator/main.go
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httputil"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const cookieName = "loremind-demo-session"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg := loadConfig()
|
||||||
|
|
||||||
|
docker, err := newDockerClient()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("docker init: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mgr := newManager(docker, cfg)
|
||||||
|
limiter := newRateLimiter(cfg.RateLimitWindow)
|
||||||
|
|
||||||
|
// Nettoyage des sessions residuelles au boot (redemarrage orchestrateur).
|
||||||
|
cleanCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
mgr.CleanupOrphans(cleanCtx)
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
go mgr.RunGC(context.Background())
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/_demo/ready", readyHandler(mgr))
|
||||||
|
mux.HandleFunc("/api/", apiHandler(mgr, cfg))
|
||||||
|
mux.HandleFunc("/", rootHandler(mgr, limiter, cfg))
|
||||||
|
|
||||||
|
srv := &http.Server{
|
||||||
|
Addr: ":80",
|
||||||
|
Handler: mux,
|
||||||
|
// Timeouts anti-slowloris. WriteTimeout laisse de la marge pour le
|
||||||
|
// streaming SSE (ai/chat/stream) qui peut durer plusieurs minutes.
|
||||||
|
ReadHeaderTimeout: 10 * time.Second,
|
||||||
|
ReadTimeout: 60 * time.Second,
|
||||||
|
WriteTimeout: 10 * time.Minute,
|
||||||
|
IdleTimeout: 120 * time.Second,
|
||||||
|
// Headers max : 1 Mo (defaut Go), suffisant.
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("orchestrator listening on :80 (max sessions=%d, ttl=%s, rate window=%s)",
|
||||||
|
cfg.MaxSessions, cfg.SessionTTL, cfg.RateLimitWindow)
|
||||||
|
if err := srv.ListenAndServe(); err != nil {
|
||||||
|
log.Fatalf("http server: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// rootHandler gere toutes les routes non-API : sert l'Angular statique si le
|
||||||
|
// visiteur a deja une session prete, sinon cree une session (sous rate limit)
|
||||||
|
// et renvoie la page de preparation.
|
||||||
|
func rootHandler(mgr *Manager, limiter *rateLimiter, cfg *Config) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
sess := currentSession(r, mgr)
|
||||||
|
|
||||||
|
// Visiteur connu et session prete -> sert l'app normalement.
|
||||||
|
if sess != nil && sess.Status == StatusReady {
|
||||||
|
serveStatic(w, r, cfg.StaticDir)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// On ne spawn qu'a la navigation initiale (GET d'un document HTML).
|
||||||
|
// Les assets secondaires (JS/CSS/favicon) ne doivent pas declencher
|
||||||
|
// de nouvelle session.
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
http.Error(w, "No session", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !acceptsHTML(r) {
|
||||||
|
http.Error(w, "No session", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Session inexistante (ou expiree) -> en creer une, sous rate limit.
|
||||||
|
if sess == nil {
|
||||||
|
ip := clientIP(r)
|
||||||
|
if !limiter.Allow(ip) {
|
||||||
|
http.Error(w, "Trop de tentatives. Merci d'attendre "+
|
||||||
|
strconv.Itoa(int(cfg.RateLimitWindow.Seconds()))+"s.",
|
||||||
|
http.StatusTooManyRequests)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newSess, err := mgr.Create(r.Context())
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, ErrCapacity) {
|
||||||
|
http.Error(w, "La demo est pleine (max "+
|
||||||
|
strconv.Itoa(cfg.MaxSessions)+
|
||||||
|
" sessions simultanees). Merci de reessayer plus tard.",
|
||||||
|
http.StatusServiceUnavailable)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.Error(w, "Impossible de creer la session : "+err.Error(),
|
||||||
|
http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sess = newSess
|
||||||
|
setCookie(w, sess.ID, cfg.SessionTTL)
|
||||||
|
}
|
||||||
|
|
||||||
|
servePreparingPage(w, cfg.PreparingPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// apiHandler proxifie /api/* vers le core de la session.
|
||||||
|
// Bride la taille des bodies a MaxBodyBytes pour limiter les DoS memoire.
|
||||||
|
func apiHandler(mgr *Manager, cfg *Config) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
sess := currentSession(r, mgr)
|
||||||
|
if sess == nil {
|
||||||
|
http.Error(w, "No session", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sess.Status != StatusReady {
|
||||||
|
http.Error(w, "Session not ready", http.StatusServiceUnavailable)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.Body != nil {
|
||||||
|
r.Body = http.MaxBytesReader(w, r.Body, cfg.MaxBodyBytes)
|
||||||
|
}
|
||||||
|
proxy := sessionProxy(sess)
|
||||||
|
proxy.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sessionProxy renvoie (et cree si besoin) un reverse proxy cache dans la
|
||||||
|
// session via sync.Once : garantit une seule creation meme sous requetes
|
||||||
|
// concurrentes, sans mutex explicite.
|
||||||
|
func sessionProxy(sess *Session) *httputil.ReverseProxy {
|
||||||
|
sess.proxyOnce.Do(func() {
|
||||||
|
target, _ := url.Parse("http://" + sess.CoreHost + ":8080")
|
||||||
|
p := httputil.NewSingleHostReverseProxy(target)
|
||||||
|
p.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
|
||||||
|
log.Printf("proxy error session=%s: %v", sess.ID, err)
|
||||||
|
http.Error(w, "Upstream error", http.StatusBadGateway)
|
||||||
|
}
|
||||||
|
sess.proxy = p
|
||||||
|
})
|
||||||
|
return sess.proxy.(*httputil.ReverseProxy)
|
||||||
|
}
|
||||||
|
|
||||||
|
// readyHandler renvoie l'etat de la session en JSON pour le polling client.
|
||||||
|
// N'expose aucun ID de session ni d'information sur les autres sessions.
|
||||||
|
func readyHandler(mgr *Manager) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
sess := currentSession(r, mgr)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
if sess == nil {
|
||||||
|
json.NewEncoder(w).Encode(map[string]any{"status": "none"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(map[string]any{
|
||||||
|
"status": string(sess.Status),
|
||||||
|
"error": sess.Err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// currentSession lit le cookie et retrouve la session en memoire.
|
||||||
|
// Si le cookie pointe vers une session disparue (redemarrage orchestrateur ou
|
||||||
|
// TTL expire), retourne nil -> le handler traitera comme un nouveau visiteur.
|
||||||
|
func currentSession(r *http.Request, mgr *Manager) *Session {
|
||||||
|
c, err := r.Cookie(cookieName)
|
||||||
|
if err != nil || c.Value == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return mgr.Get(c.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setCookie(w http.ResponseWriter, id string, ttl time.Duration) {
|
||||||
|
http.SetCookie(w, &http.Cookie{
|
||||||
|
Name: cookieName,
|
||||||
|
Value: id,
|
||||||
|
Path: "/",
|
||||||
|
HttpOnly: true,
|
||||||
|
Secure: true, // Traefik termine le TLS ; le browser ne doit envoyer ce cookie qu'en HTTPS.
|
||||||
|
SameSite: http.SameSiteLaxMode,
|
||||||
|
MaxAge: int(ttl.Seconds()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// serveStatic sert les fichiers de l'Angular build avec fallback sur index.html
|
||||||
|
// pour que le routeur cote client fonctionne (SPA).
|
||||||
|
// Le check HasPrefix apres Join + Clean empeche les path traversals (..).
|
||||||
|
func serveStatic(w http.ResponseWriter, r *http.Request, dir string) {
|
||||||
|
reqPath := r.URL.Path
|
||||||
|
if reqPath == "/" || reqPath == "" {
|
||||||
|
reqPath = "/index.html"
|
||||||
|
}
|
||||||
|
fullPath := filepath.Join(dir, filepath.Clean(reqPath))
|
||||||
|
if !strings.HasPrefix(fullPath, dir) {
|
||||||
|
http.Error(w, "bad path", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if info, err := os.Stat(fullPath); err == nil && !info.IsDir() {
|
||||||
|
http.ServeFile(w, r, fullPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.ServeFile(w, r, filepath.Join(dir, "index.html"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// servePreparingPage sert la page de chargement statique. Le cookie vient
|
||||||
|
// d'etre pose, le JS de la page utilisera sessionId implicitement via le
|
||||||
|
// cookie pour poller /_demo/ready.
|
||||||
|
func servePreparingPage(w http.ResponseWriter, path string) {
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Preparing page not found", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func acceptsHTML(r *http.Request) bool {
|
||||||
|
accept := r.Header.Get("Accept")
|
||||||
|
return strings.Contains(accept, "text/html") || accept == "" || accept == "*/*"
|
||||||
|
}
|
||||||
127
demo/orchestrator/preparing.html
Normal file
127
demo/orchestrator/preparing.html
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>LoreMind — Demo en preparation</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||||
|
background: #1a1625;
|
||||||
|
color: #e4def5;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 100vh;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
max-width: 440px;
|
||||||
|
padding: 2.5rem 2rem;
|
||||||
|
}
|
||||||
|
.logo {
|
||||||
|
font-size: 2rem;
|
||||||
|
color: #b794f4;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
.subtitle {
|
||||||
|
letter-spacing: 0.2em;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #9880c4;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 1.35rem;
|
||||||
|
font-weight: 500;
|
||||||
|
margin: 0 0 1rem;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
color: #aaa0c5;
|
||||||
|
line-height: 1.6;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
.spinner {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
margin: 1.5rem auto 0;
|
||||||
|
border: 3px solid rgba(183, 148, 244, 0.2);
|
||||||
|
border-top-color: #b794f4;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
.error {
|
||||||
|
display: none;
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
background: rgba(239, 68, 68, 0.1);
|
||||||
|
border: 1px solid rgba(239, 68, 68, 0.3);
|
||||||
|
color: #fca5a5;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.error.visible { display: block; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="card">
|
||||||
|
<div class="logo">✦ LoreMind</div>
|
||||||
|
<div class="subtitle">THE DIGITAL CODEX</div>
|
||||||
|
<h1>Preparation de votre demo…</h1>
|
||||||
|
<p>
|
||||||
|
Nous initialisons une instance isolee rien que pour vous.
|
||||||
|
Cela prend generalement 20 a 40 secondes.
|
||||||
|
</p>
|
||||||
|
<p style="font-size: 0.8rem; color: #7d6ba0; margin-top: 1rem;">
|
||||||
|
Votre session sera automatiquement reinitialisee au bout de 20 minutes.
|
||||||
|
</p>
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<div id="err" class="error"></div>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
var errBox = document.getElementById('err');
|
||||||
|
var attempts = 0;
|
||||||
|
var maxAttempts = 90; // 90 * 2s = 3 min max
|
||||||
|
|
||||||
|
function poll() {
|
||||||
|
attempts++;
|
||||||
|
fetch('/_demo/ready', { credentials: 'same-origin' })
|
||||||
|
.then(function (r) { return r.json(); })
|
||||||
|
.then(function (data) {
|
||||||
|
if (data.status === 'ready') {
|
||||||
|
window.location.href = '/';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.status === 'failed') {
|
||||||
|
errBox.textContent = 'Echec du demarrage : ' + (data.error || 'raison inconnue') + '. Rechargez la page pour reessayer.';
|
||||||
|
errBox.classList.add('visible');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (attempts >= maxAttempts) {
|
||||||
|
errBox.textContent = 'Timeout. Rechargez la page pour reessayer.';
|
||||||
|
errBox.classList.add('visible');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setTimeout(poll, 2000);
|
||||||
|
})
|
||||||
|
.catch(function () {
|
||||||
|
if (attempts >= maxAttempts) {
|
||||||
|
errBox.textContent = 'Connexion perdue. Rechargez la page pour reessayer.';
|
||||||
|
errBox.classList.add('visible');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setTimeout(poll, 2000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
poll();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
79
demo/orchestrator/ratelimit.go
Normal file
79
demo/orchestrator/ratelimit.go
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// rateLimiter autorise au plus une action par IP dans une fenetre glissante.
|
||||||
|
// Pas de token bucket : pour un endpoint de creation de session, "1 par
|
||||||
|
// fenetre" est largement suffisant et plus simple a raisonner.
|
||||||
|
type rateLimiter struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
lastSeen map[string]time.Time
|
||||||
|
window time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRateLimiter(window time.Duration) *rateLimiter {
|
||||||
|
rl := &rateLimiter{
|
||||||
|
lastSeen: make(map[string]time.Time),
|
||||||
|
window: window,
|
||||||
|
}
|
||||||
|
go rl.cleanupLoop()
|
||||||
|
return rl
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow renvoie true si l'IP n'a pas deja declenche d'action dans la fenetre.
|
||||||
|
// Sur true, l'horloge de l'IP est reinitialisee.
|
||||||
|
func (rl *rateLimiter) Allow(ip string) bool {
|
||||||
|
rl.mu.Lock()
|
||||||
|
defer rl.mu.Unlock()
|
||||||
|
now := time.Now()
|
||||||
|
if last, ok := rl.lastSeen[ip]; ok && now.Sub(last) < rl.window {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
rl.lastSeen[ip] = now
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanupLoop purge les entrees plus anciennes que 2x la fenetre pour eviter
|
||||||
|
// la croissance non bornee de la map sous trafic varie.
|
||||||
|
func (rl *rateLimiter) cleanupLoop() {
|
||||||
|
ticker := time.NewTicker(5 * time.Minute)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for range ticker.C {
|
||||||
|
cutoff := time.Now().Add(-2 * rl.window)
|
||||||
|
rl.mu.Lock()
|
||||||
|
for ip, t := range rl.lastSeen {
|
||||||
|
if t.Before(cutoff) {
|
||||||
|
delete(rl.lastSeen, ip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rl.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clientIP extrait l'IP reelle du visiteur en tenant compte du setup reverse-proxy.
|
||||||
|
// Ordre de priorite :
|
||||||
|
// 1. CF-Connecting-IP : defini par Cloudflare sur la base de SA propre vue du
|
||||||
|
// peer TCP, non-forgeable par le client, ecrase toute valeur entrante.
|
||||||
|
// 2. X-Forwarded-For, derniere entree : quand seul Traefik est en front (pas
|
||||||
|
// de Cloudflare), Traefik append l'IP qu'il observe. Prendre la premiere
|
||||||
|
// serait une faille (header forgeable).
|
||||||
|
// 3. RemoteAddr : fallback si aucun header de proxy n'est present.
|
||||||
|
func clientIP(r *http.Request) string {
|
||||||
|
if cfIP := r.Header.Get("CF-Connecting-IP"); cfIP != "" {
|
||||||
|
return strings.TrimSpace(cfIP)
|
||||||
|
}
|
||||||
|
if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
|
||||||
|
parts := strings.Split(xff, ",")
|
||||||
|
return strings.TrimSpace(parts[len(parts)-1])
|
||||||
|
}
|
||||||
|
if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
return r.RemoteAddr
|
||||||
|
}
|
||||||
177
demo/orchestrator/sessions.go
Normal file
177
demo/orchestrator/sessions.go
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SessionStatus reflete l'etat du cycle de vie d'un trio de session.
|
||||||
|
type SessionStatus string
|
||||||
|
|
||||||
|
const (
|
||||||
|
StatusStarting SessionStatus = "starting"
|
||||||
|
StatusReady SessionStatus = "ready"
|
||||||
|
StatusFailed SessionStatus = "failed"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Session represente une demo isolee pour un visiteur.
|
||||||
|
// CoreHost est le hostname Docker interne du conteneur core de cette session
|
||||||
|
// (ex: "demo-abc123-core"), vers lequel l'orchestrateur proxifie les /api/*.
|
||||||
|
type Session struct {
|
||||||
|
ID string
|
||||||
|
CreatedAt time.Time
|
||||||
|
Status SessionStatus
|
||||||
|
CoreHost string
|
||||||
|
Err string
|
||||||
|
// proxy et proxyOnce : reverse-proxy cache, cree au plus une fois via
|
||||||
|
// sync.Once (evite la race entre deux requetes concurrentes sur la meme
|
||||||
|
// session). proxy est typee any pour ne pas contraindre sessions.go a
|
||||||
|
// importer net/http/httputil.
|
||||||
|
proxy any
|
||||||
|
proxyOnce sync.Once
|
||||||
|
}
|
||||||
|
|
||||||
|
// Manager gere le cycle de vie des sessions (creation, acces, cleanup).
|
||||||
|
// Thread-safe : le mutex protege la map contre les acces concurrents (HTTP
|
||||||
|
// handlers + goroutine de GC).
|
||||||
|
type Manager struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
sessions map[string]*Session
|
||||||
|
docker *DockerClient
|
||||||
|
cfg *Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func newManager(docker *DockerClient, cfg *Config) *Manager {
|
||||||
|
return &Manager{
|
||||||
|
sessions: make(map[string]*Session),
|
||||||
|
docker: docker,
|
||||||
|
cfg: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrCapacity est retournee quand MAX_SESSIONS est atteint.
|
||||||
|
var ErrCapacity = errors.New("demo at capacity")
|
||||||
|
|
||||||
|
// Create reserve un slot et lance le spawn des conteneurs en arriere-plan.
|
||||||
|
// Retourne immediatement avec Status=starting. L'etat bascule a "ready" quand
|
||||||
|
// les conteneurs sont up et que core repond a /api/config.
|
||||||
|
func (m *Manager) Create(ctx context.Context) (*Session, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
if len(m.sessions) >= m.cfg.MaxSessions {
|
||||||
|
m.mu.Unlock()
|
||||||
|
return nil, ErrCapacity
|
||||||
|
}
|
||||||
|
id := newShortID()
|
||||||
|
sess := &Session{
|
||||||
|
ID: id,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
Status: StatusStarting,
|
||||||
|
CoreHost: "demo-" + id + "-core",
|
||||||
|
}
|
||||||
|
m.sessions[id] = sess
|
||||||
|
m.mu.Unlock()
|
||||||
|
|
||||||
|
// Spawn asynchrone : l'utilisateur voit immediatement la page "preparation".
|
||||||
|
go func() {
|
||||||
|
spawnCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
if err := m.docker.SpawnTrio(spawnCtx, id, m.cfg); err != nil {
|
||||||
|
log.Printf("session %s spawn failed: %v", id, err)
|
||||||
|
m.mu.Lock()
|
||||||
|
sess.Status = StatusFailed
|
||||||
|
sess.Err = err.Error()
|
||||||
|
m.mu.Unlock()
|
||||||
|
// Nettoyage best-effort des conteneurs partiellement crees.
|
||||||
|
_ = m.docker.KillTrio(context.Background(), id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Attente que core reponde (sinon proxy retourne 502 aux premieres requetes).
|
||||||
|
if m.docker.WaitReady(spawnCtx, id, 90*time.Second) {
|
||||||
|
m.mu.Lock()
|
||||||
|
sess.Status = StatusReady
|
||||||
|
m.mu.Unlock()
|
||||||
|
log.Printf("session %s ready", id)
|
||||||
|
} else {
|
||||||
|
log.Printf("session %s never became ready", id)
|
||||||
|
m.mu.Lock()
|
||||||
|
sess.Status = StatusFailed
|
||||||
|
sess.Err = "timeout waiting for core"
|
||||||
|
m.mu.Unlock()
|
||||||
|
_ = m.docker.KillTrio(context.Background(), id)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return sess, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get renvoie la session associee a un ID, ou nil si elle n'existe plus.
|
||||||
|
func (m *Manager) Get(id string) *Session {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
return m.sessions[id]
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunGC boucle toutes les minutes pour supprimer les sessions expirees.
|
||||||
|
// A lancer en goroutine au demarrage.
|
||||||
|
func (m *Manager) RunGC(ctx context.Context) {
|
||||||
|
ticker := time.NewTicker(time.Minute)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
m.gcOnce()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) gcOnce() {
|
||||||
|
cutoff := time.Now().Add(-m.cfg.SessionTTL)
|
||||||
|
m.mu.Lock()
|
||||||
|
var expired []string
|
||||||
|
for id, s := range m.sessions {
|
||||||
|
if s.CreatedAt.Before(cutoff) {
|
||||||
|
expired = append(expired, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, id := range expired {
|
||||||
|
delete(m.sessions, id)
|
||||||
|
}
|
||||||
|
m.mu.Unlock()
|
||||||
|
|
||||||
|
for _, id := range expired {
|
||||||
|
log.Printf("session %s expired, killing containers", id)
|
||||||
|
if err := m.docker.KillTrio(context.Background(), id); err != nil {
|
||||||
|
log.Printf("kill %s: %v", id, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CleanupOrphans tue les conteneurs demo-* qui ne correspondent a aucune
|
||||||
|
// session en memoire. Appele au demarrage pour gerer un redemarrage brutal.
|
||||||
|
func (m *Manager) CleanupOrphans(ctx context.Context) {
|
||||||
|
ids, err := m.docker.ListSessionIDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("list orphans: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, id := range ids {
|
||||||
|
log.Printf("cleaning orphan session %s", id)
|
||||||
|
_ = m.docker.KillTrio(ctx, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// newShortID genere un identifiant hexadecimal de 32 caracteres (128 bits).
|
||||||
|
// 128 bits d'entropie rendent les collisions et le brute-force statistiquement
|
||||||
|
// impossibles, meme si un attaquant pouvait tenter des millions de cookies.
|
||||||
|
func newShortID() string {
|
||||||
|
b := make([]byte, 16)
|
||||||
|
_, _ = rand.Read(b)
|
||||||
|
return hex.EncodeToString(b)
|
||||||
|
}
|
||||||
17
docker-compose.e2e.yml
Normal file
17
docker-compose.e2e.yml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Override pour la CI E2E : build les images depuis les sources au lieu de les puller.
|
||||||
|
# Usage : docker compose -f docker-compose.yml -f docker-compose.e2e.yml up -d --build
|
||||||
|
services:
|
||||||
|
core:
|
||||||
|
build:
|
||||||
|
context: ./core
|
||||||
|
image: loremind-core:e2e
|
||||||
|
|
||||||
|
brain:
|
||||||
|
build:
|
||||||
|
context: ./brain
|
||||||
|
image: loremind-brain:e2e
|
||||||
|
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: ./web
|
||||||
|
image: loremind-web:e2e
|
||||||
@@ -60,7 +60,8 @@
|
|||||||
"serve": {
|
"serve": {
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
"options": {
|
"options": {
|
||||||
"buildTarget": "web:build"
|
"buildTarget": "web:build",
|
||||||
|
"proxyConfig": "proxy.conf.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
317
web/e2e/fixtures/api.ts
Normal file
317
web/e2e/fixtures/api.ts
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
import { APIRequestContext, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
export interface SeededLore {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
rootFolderId: string;
|
||||||
|
rootFolderName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed un Lore + un dossier racine via l'API backend.
|
||||||
|
* Les noms sont uniques (timestamp + random) pour éviter les collisions en parallèle.
|
||||||
|
*/
|
||||||
|
export async function seedLoreWithFolder(request: APIRequestContext): Promise<SeededLore> {
|
||||||
|
const suffix = `${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
||||||
|
const loreName = `E2E Lore ${suffix}`;
|
||||||
|
const folderName = `E2E Folder ${suffix}`;
|
||||||
|
|
||||||
|
const loreRes = await request.post('/api/lores', {
|
||||||
|
data: { name: loreName, description: 'Seeded by Playwright' },
|
||||||
|
});
|
||||||
|
expect(loreRes.ok(), `POST /api/lores -> ${loreRes.status()}`).toBeTruthy();
|
||||||
|
const lore = await loreRes.json();
|
||||||
|
|
||||||
|
const folderRes = await request.post('/api/lore-nodes', {
|
||||||
|
data: { loreId: lore.id, name: folderName, icon: 'folder', description: '' },
|
||||||
|
});
|
||||||
|
expect(folderRes.ok(), `POST /api/lore-nodes -> ${folderRes.status()}`).toBeTruthy();
|
||||||
|
const folder = await folderRes.json();
|
||||||
|
|
||||||
|
return { id: lore.id, name: loreName, rootFolderId: folder.id, rootFolderName: folderName };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Cleanup best-effort — n'échoue pas si déjà supprimé. */
|
||||||
|
export async function deleteLore(request: APIRequestContext, loreId: string): Promise<void> {
|
||||||
|
await request.delete(`/api/lores/${loreId}`).catch(() => undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLoreById(
|
||||||
|
request: APIRequestContext,
|
||||||
|
loreId: string,
|
||||||
|
): Promise<{ id: string; name: string; description: string }> {
|
||||||
|
const res = await request.get(`/api/lores/${loreId}`);
|
||||||
|
expect(res.ok(), `GET /api/lores/${loreId} -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getArcsForCampaign(
|
||||||
|
request: APIRequestContext,
|
||||||
|
campaignId: string,
|
||||||
|
): Promise<Array<{ id: string; name: string; campaignId: string }>> {
|
||||||
|
const res = await request.get(`/api/arcs?campaignId=${campaignId}`);
|
||||||
|
expect(res.ok(), `GET /api/arcs -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getChaptersForArc(
|
||||||
|
request: APIRequestContext,
|
||||||
|
arcId: string,
|
||||||
|
): Promise<Array<{ id: string; name: string; arcId: string }>> {
|
||||||
|
const res = await request.get(`/api/chapters?arcId=${arcId}`);
|
||||||
|
expect(res.ok(), `GET /api/chapters -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getScenesForChapter(
|
||||||
|
request: APIRequestContext,
|
||||||
|
chapterId: string,
|
||||||
|
): Promise<Array<{ id: string; name: string; chapterId: string }>> {
|
||||||
|
const res = await request.get(`/api/scenes?chapterId=${chapterId}`);
|
||||||
|
expect(res.ok(), `GET /api/scenes -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTemplatesForLore(
|
||||||
|
request: APIRequestContext,
|
||||||
|
loreId: string,
|
||||||
|
): Promise<Array<{ id: string; name: string }>> {
|
||||||
|
const res = await request.get(`/api/templates?loreId=${loreId}`);
|
||||||
|
expect(res.ok(), `GET /api/templates -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeededTemplate {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function seedTemplate(
|
||||||
|
request: APIRequestContext,
|
||||||
|
opts: { loreId: string; defaultNodeId: string; name?: string; fieldNames?: string[] },
|
||||||
|
): Promise<SeededTemplate> {
|
||||||
|
const templateName = opts.name ?? `E2E Template ${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
||||||
|
const fields = (opts.fieldNames ?? ['Nom', 'Description']).map((name) => ({ name, type: 'TEXT' }));
|
||||||
|
|
||||||
|
const res = await request.post('/api/templates', {
|
||||||
|
data: {
|
||||||
|
loreId: opts.loreId,
|
||||||
|
name: templateName,
|
||||||
|
description: 'Seeded by Playwright',
|
||||||
|
defaultNodeId: opts.defaultNodeId,
|
||||||
|
fields,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res.ok(), `POST /api/templates -> ${res.status()}`).toBeTruthy();
|
||||||
|
const tpl = await res.json();
|
||||||
|
return { id: tpl.id, name: templateName };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteCampaign(request: APIRequestContext, campaignId: string): Promise<void> {
|
||||||
|
await request.delete(`/api/campaigns/${campaignId}`).catch(() => undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeededCampaign {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function seedCampaign(
|
||||||
|
request: APIRequestContext,
|
||||||
|
opts: { name?: string; loreId?: string | null; playerCount?: number } = {},
|
||||||
|
): Promise<SeededCampaign> {
|
||||||
|
const name = opts.name ?? `E2E Campaign ${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
||||||
|
const res = await request.post('/api/campaigns', {
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
description: 'Seeded by Playwright',
|
||||||
|
playerCount: opts.playerCount ?? 4,
|
||||||
|
loreId: opts.loreId ?? null,
|
||||||
|
gameSystemId: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res.ok(), `POST /api/campaigns -> ${res.status()}`).toBeTruthy();
|
||||||
|
const c = await res.json();
|
||||||
|
return { id: c.id, name };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeededArc {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function seedArc(
|
||||||
|
request: APIRequestContext,
|
||||||
|
opts: { campaignId: string; name?: string; order?: number },
|
||||||
|
): Promise<SeededArc> {
|
||||||
|
const name = opts.name ?? `E2E Arc ${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
||||||
|
const res = await request.post('/api/arcs', {
|
||||||
|
data: {
|
||||||
|
campaignId: opts.campaignId,
|
||||||
|
name,
|
||||||
|
description: '',
|
||||||
|
order: opts.order ?? 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res.ok(), `POST /api/arcs -> ${res.status()}`).toBeTruthy();
|
||||||
|
const a = await res.json();
|
||||||
|
return { id: a.id, name };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeededChapter {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function seedChapter(
|
||||||
|
request: APIRequestContext,
|
||||||
|
opts: { arcId: string; name?: string; order?: number },
|
||||||
|
): Promise<SeededChapter> {
|
||||||
|
const name = opts.name ?? `E2E Chapter ${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
||||||
|
const res = await request.post('/api/chapters', {
|
||||||
|
data: { arcId: opts.arcId, name, description: '', order: opts.order ?? 1 },
|
||||||
|
});
|
||||||
|
expect(res.ok(), `POST /api/chapters -> ${res.status()}`).toBeTruthy();
|
||||||
|
const c = await res.json();
|
||||||
|
return { id: c.id, name };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getChapterById(
|
||||||
|
request: APIRequestContext,
|
||||||
|
chapterId: string,
|
||||||
|
): Promise<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
gmNotes?: string | null;
|
||||||
|
playerObjectives?: string | null;
|
||||||
|
narrativeStakes?: string | null;
|
||||||
|
}> {
|
||||||
|
const res = await request.get(`/api/chapters/${chapterId}`);
|
||||||
|
expect(res.ok(), `GET /api/chapters/${chapterId} -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeededScene {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function seedScene(
|
||||||
|
request: APIRequestContext,
|
||||||
|
opts: { chapterId: string; name?: string; order?: number },
|
||||||
|
): Promise<SeededScene> {
|
||||||
|
const name = opts.name ?? `E2E Scene ${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
||||||
|
const res = await request.post('/api/scenes', {
|
||||||
|
data: { chapterId: opts.chapterId, name, description: '', order: opts.order ?? 1 },
|
||||||
|
});
|
||||||
|
expect(res.ok(), `POST /api/scenes -> ${res.status()}`).toBeTruthy();
|
||||||
|
const s = await res.json();
|
||||||
|
return { id: s.id, name };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSceneById(
|
||||||
|
request: APIRequestContext,
|
||||||
|
sceneId: string,
|
||||||
|
): Promise<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
location?: string | null;
|
||||||
|
timing?: string | null;
|
||||||
|
atmosphere?: string | null;
|
||||||
|
playerNarration?: string | null;
|
||||||
|
gmSecretNotes?: string | null;
|
||||||
|
choicesConsequences?: string | null;
|
||||||
|
combatDifficulty?: string | null;
|
||||||
|
enemies?: string | null;
|
||||||
|
branches?: Array<{ label: string; targetSceneId: string; condition?: string }>;
|
||||||
|
}> {
|
||||||
|
const res = await request.get(`/api/scenes/${sceneId}`);
|
||||||
|
expect(res.ok(), `GET /api/scenes/${sceneId} -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getArcById(
|
||||||
|
request: APIRequestContext,
|
||||||
|
arcId: string,
|
||||||
|
): Promise<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
themes?: string | null;
|
||||||
|
stakes?: string | null;
|
||||||
|
gmNotes?: string | null;
|
||||||
|
rewards?: string | null;
|
||||||
|
resolution?: string | null;
|
||||||
|
}> {
|
||||||
|
const res = await request.get(`/api/arcs/${arcId}`);
|
||||||
|
expect(res.ok(), `GET /api/arcs/${arcId} -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCampaigns(
|
||||||
|
request: APIRequestContext,
|
||||||
|
): Promise<Array<{ id: string; name: string; loreId: string | null }>> {
|
||||||
|
const res = await request.get('/api/campaigns');
|
||||||
|
expect(res.ok(), `GET /api/campaigns -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPagesForLore(
|
||||||
|
request: APIRequestContext,
|
||||||
|
loreId: string,
|
||||||
|
): Promise<Array<{ id: string; title: string; nodeId: string; templateId: string }>> {
|
||||||
|
const res = await request.get(`/api/pages?loreId=${loreId}`);
|
||||||
|
expect(res.ok(), `GET /api/pages -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeededPage {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function seedPage(
|
||||||
|
request: APIRequestContext,
|
||||||
|
opts: { loreId: string; nodeId: string; templateId: string; title?: string },
|
||||||
|
): Promise<SeededPage> {
|
||||||
|
const title = opts.title ?? `E2E Page ${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
||||||
|
const res = await request.post('/api/pages', {
|
||||||
|
data: { loreId: opts.loreId, nodeId: opts.nodeId, templateId: opts.templateId, title },
|
||||||
|
});
|
||||||
|
expect(res.ok(), `POST /api/pages -> ${res.status()}`).toBeTruthy();
|
||||||
|
const page = await res.json();
|
||||||
|
return { id: page.id, title };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPageById(
|
||||||
|
request: APIRequestContext,
|
||||||
|
pageId: string,
|
||||||
|
): Promise<{
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
nodeId: string;
|
||||||
|
values?: Record<string, string>;
|
||||||
|
tags?: string[];
|
||||||
|
notes?: string;
|
||||||
|
}> {
|
||||||
|
const res = await request.get(`/api/pages/${pageId}`);
|
||||||
|
expect(res.ok(), `GET /api/pages/${pageId} -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTemplateById(
|
||||||
|
request: APIRequestContext,
|
||||||
|
templateId: string,
|
||||||
|
): Promise<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
defaultNodeId?: string | null;
|
||||||
|
fields: Array<{ name: string; type: string }>;
|
||||||
|
}> {
|
||||||
|
const res = await request.get(`/api/templates/${templateId}`);
|
||||||
|
expect(res.ok(), `GET /api/templates/${templateId} -> ${res.status()}`).toBeTruthy();
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
50
web/e2e/tests/campaign/arc-create.spec.ts
Normal file
50
web/e2e/tests/campaign/arc-create.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
deleteCampaign,
|
||||||
|
getArcById,
|
||||||
|
type SeededCampaign,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Arc creation', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates an arc and redirects to its view', async ({ page, request }) => {
|
||||||
|
const arcName = `Arc ${Date.now()}`;
|
||||||
|
const description = 'Synopsis test';
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/create`);
|
||||||
|
await expect(page.getByRole('heading', { name: /Créer un nouvel arc/i })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom de l'arc/i).fill(arcName);
|
||||||
|
await page.getByLabel(/Description/i).fill(description);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Créer l'arc$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/campaigns/${campaign.id}/arcs/\\d+$`));
|
||||||
|
|
||||||
|
const createdId = page.url().match(/\/arcs\/(\d+)$/)?.[1];
|
||||||
|
expect(createdId).toBeTruthy();
|
||||||
|
const persisted = await getArcById(request, createdId!);
|
||||||
|
expect(persisted.name).toBe(arcName);
|
||||||
|
expect(persisted.description).toBe(description);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('submit is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/create`);
|
||||||
|
|
||||||
|
const submit = page.getByRole('button', { name: /^Créer l'arc$/i });
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom de l'arc/i).fill('Quelque chose');
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
49
web/e2e/tests/campaign/arc-delete.spec.ts
Normal file
49
web/e2e/tests/campaign/arc-delete.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
seedArc,
|
||||||
|
deleteCampaign,
|
||||||
|
type SeededCampaign,
|
||||||
|
type SeededArc,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Arc delete', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
let arc: SeededArc;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
arc = await seedArc(request, { campaignId: campaign.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deletes an arc after accepting confirm and redirects to the campaign', async ({
|
||||||
|
page,
|
||||||
|
request,
|
||||||
|
}) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.accept());
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/edit`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/campaigns/${campaign.id}$`));
|
||||||
|
|
||||||
|
const res = await request.get(`/api/arcs/${arc.id}`);
|
||||||
|
expect(res.status()).toBe(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keeps the arc when confirm is dismissed', async ({ page, request }) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.dismiss());
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/edit`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/campaigns/${campaign.id}/arcs/${arc.id}/edit$`));
|
||||||
|
|
||||||
|
const res = await request.get(`/api/arcs/${arc.id}`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
76
web/e2e/tests/campaign/arc-edit.spec.ts
Normal file
76
web/e2e/tests/campaign/arc-edit.spec.ts
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
seedArc,
|
||||||
|
deleteCampaign,
|
||||||
|
getArcById,
|
||||||
|
type SeededCampaign,
|
||||||
|
type SeededArc,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Arc edit', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
let arc: SeededArc;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
arc = await seedArc(request, { campaignId: campaign.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('form is prefilled with the arc name', async ({ page }) => {
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/edit`);
|
||||||
|
await expect(page.getByLabel(/Titre de l'arc/i)).toHaveValue(arc.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('edits all narrative fields and persists them to API', async ({ page, request }) => {
|
||||||
|
const newName = `${arc.name} renamed`;
|
||||||
|
const values = {
|
||||||
|
description: "Un arc sombre où la trahison s'installe.",
|
||||||
|
themes: 'Trahison, rédemption, dette de sang.',
|
||||||
|
stakes: 'La survie du royaume est en jeu.',
|
||||||
|
gmNotes: 'Révéler le traître en scène 3.',
|
||||||
|
rewards: 'Relique ancienne + alliance avec le clan nordique.',
|
||||||
|
resolution: 'Le héros pardonne au traître ou le tue.',
|
||||||
|
};
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/edit`);
|
||||||
|
|
||||||
|
await page.getByLabel(/Titre de l'arc/i).fill(newName);
|
||||||
|
await page.getByLabel(/Synopsis de l'arc/i).fill(values.description);
|
||||||
|
await page.getByLabel(/Thèmes principaux/i).fill(values.themes);
|
||||||
|
await page.getByLabel(/Enjeux globaux/i).fill(values.stakes);
|
||||||
|
await page.getByLabel(/Notes et planification du MJ/i).fill(values.gmNotes);
|
||||||
|
await page.getByLabel(/Récompenses et progression/i).fill(values.rewards);
|
||||||
|
await page.getByLabel(/Dénouement prévu/i).fill(values.resolution);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/campaigns/${campaign.id}/arcs/${arc.id}$`));
|
||||||
|
|
||||||
|
const persisted = await getArcById(request, arc.id);
|
||||||
|
expect(persisted.name).toBe(newName);
|
||||||
|
expect(persisted.description).toBe(values.description);
|
||||||
|
expect(persisted.themes).toBe(values.themes);
|
||||||
|
expect(persisted.stakes).toBe(values.stakes);
|
||||||
|
expect(persisted.gmNotes).toBe(values.gmNotes);
|
||||||
|
expect(persisted.rewards).toBe(values.rewards);
|
||||||
|
expect(persisted.resolution).toBe(values.resolution);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('save button is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/edit`);
|
||||||
|
|
||||||
|
const nameField = page.getByLabel(/Titre de l'arc/i);
|
||||||
|
const saveBtn = page.getByRole('button', { name: /^Sauvegarder$/i });
|
||||||
|
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
await nameField.fill('');
|
||||||
|
await expect(saveBtn).toBeDisabled();
|
||||||
|
await nameField.fill('Valid');
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
96
web/e2e/tests/campaign/campaign-create.spec.ts
Normal file
96
web/e2e/tests/campaign/campaign-create.spec.ts
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedLoreWithFolder,
|
||||||
|
deleteLore,
|
||||||
|
deleteCampaign,
|
||||||
|
getCampaigns,
|
||||||
|
type SeededLore,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Campaign creation', () => {
|
||||||
|
const createdCampaignIds: string[] = [];
|
||||||
|
let linkedLore: SeededLore;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
linkedLore = await seedLoreWithFolder(request);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
while (createdCampaignIds.length) {
|
||||||
|
await deleteCampaign(request, createdCampaignIds.pop()!);
|
||||||
|
}
|
||||||
|
if (linkedLore?.id) await deleteLore(request, linkedLore.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates a standalone campaign (no lore, no system) and shows it in the grid', async ({
|
||||||
|
page,
|
||||||
|
request,
|
||||||
|
}) => {
|
||||||
|
const campaignName = `Campagne E2E ${Date.now()}`;
|
||||||
|
const description = 'Une campagne créée par les tests automatisés.';
|
||||||
|
|
||||||
|
await page.goto('/campaigns');
|
||||||
|
await expect(page.getByRole('heading', { name: /Vos Campagnes|Campagnes/i })).toBeVisible();
|
||||||
|
|
||||||
|
await page.locator('.campaign-card.card-new').click();
|
||||||
|
|
||||||
|
const modal = page.locator('.modal');
|
||||||
|
await expect(modal).toBeVisible();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nom de la campagne/i).fill(campaignName);
|
||||||
|
await modal.getByLabel(/Description/i).fill(description);
|
||||||
|
await modal.getByLabel(/Nombre de joueurs/i).fill('5');
|
||||||
|
|
||||||
|
await modal.getByRole('button', { name: /^Créer la campagne$/i }).click();
|
||||||
|
|
||||||
|
await expect(modal).not.toBeVisible();
|
||||||
|
|
||||||
|
const newCard = page.locator('.campaign-card', { hasText: campaignName });
|
||||||
|
await expect(newCard).toBeVisible();
|
||||||
|
|
||||||
|
const campaigns = await getCampaigns(request);
|
||||||
|
const created = campaigns.find((c) => c.name === campaignName);
|
||||||
|
expect(created).toBeDefined();
|
||||||
|
expect(created!.loreId).toBeNull();
|
||||||
|
createdCampaignIds.push(created!.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates a campaign linked to an existing lore', async ({ page, request }) => {
|
||||||
|
const campaignName = `Campagne liée ${Date.now()}`;
|
||||||
|
|
||||||
|
await page.goto('/campaigns');
|
||||||
|
await page.locator('.campaign-card.card-new').click();
|
||||||
|
|
||||||
|
const modal = page.locator('.modal');
|
||||||
|
await modal.getByLabel(/Nom de la campagne/i).fill(campaignName);
|
||||||
|
await modal.getByLabel(/Univers associé/i).selectOption({ label: linkedLore.name });
|
||||||
|
|
||||||
|
await modal.getByRole('button', { name: /^Créer la campagne$/i }).click();
|
||||||
|
await expect(modal).not.toBeVisible();
|
||||||
|
|
||||||
|
const campaigns = await getCampaigns(request);
|
||||||
|
const created = campaigns.find((c) => c.name === campaignName);
|
||||||
|
expect(created).toBeDefined();
|
||||||
|
expect(created!.loreId).toBe(linkedLore.id);
|
||||||
|
createdCampaignIds.push(created!.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('submit is disabled without a name and when player count is invalid', async ({ page }) => {
|
||||||
|
await page.goto('/campaigns');
|
||||||
|
await page.locator('.campaign-card.card-new').click();
|
||||||
|
|
||||||
|
const modal = page.locator('.modal');
|
||||||
|
const submit = modal.getByRole('button', { name: /^Créer la campagne$/i });
|
||||||
|
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nom de la campagne/i).fill('Valid name');
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nombre de joueurs/i).fill('0');
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nombre de joueurs/i).fill('3');
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
41
web/e2e/tests/campaign/campaign-delete.spec.ts
Normal file
41
web/e2e/tests/campaign/campaign-delete.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { seedCampaign, deleteCampaign, type SeededCampaign } from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Campaign delete', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deletes a campaign after accepting confirm and redirects to the list', async ({
|
||||||
|
page,
|
||||||
|
request,
|
||||||
|
}) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.accept());
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(/\/campaigns$/);
|
||||||
|
|
||||||
|
const res = await request.get(`/api/campaigns/${campaign.id}`);
|
||||||
|
expect(res.status()).toBe(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keeps the campaign when confirm is dismissed', async ({ page, request }) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.dismiss());
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/campaigns/${campaign.id}$`));
|
||||||
|
|
||||||
|
const res = await request.get(`/api/campaigns/${campaign.id}`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
54
web/e2e/tests/campaign/chapter-create.spec.ts
Normal file
54
web/e2e/tests/campaign/chapter-create.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
seedArc,
|
||||||
|
deleteCampaign,
|
||||||
|
getChapterById,
|
||||||
|
type SeededCampaign,
|
||||||
|
type SeededArc,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Chapter creation', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
let arc: SeededArc;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
arc = await seedArc(request, { campaignId: campaign.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates a chapter and redirects to its view', async ({ page, request }) => {
|
||||||
|
const chapterName = `Chapitre ${Date.now()}`;
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/create`);
|
||||||
|
await expect(page.getByRole('heading', { name: /Créer un nouveau chapitre/i })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom du chapitre/i).fill(chapterName);
|
||||||
|
await page.getByLabel(/Description/i).fill('Synopsis du chapitre');
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Créer le chapitre$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(
|
||||||
|
new RegExp(`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/\\d+$`),
|
||||||
|
);
|
||||||
|
|
||||||
|
const createdId = page.url().match(/\/chapters\/(\d+)$/)?.[1];
|
||||||
|
expect(createdId).toBeTruthy();
|
||||||
|
const persisted = await getChapterById(request, createdId!);
|
||||||
|
expect(persisted.name).toBe(chapterName);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('submit is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/create`);
|
||||||
|
|
||||||
|
const submit = page.getByRole('button', { name: /^Créer le chapitre$/i });
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom du chapitre/i).fill('OK');
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
72
web/e2e/tests/campaign/chapter-edit.spec.ts
Normal file
72
web/e2e/tests/campaign/chapter-edit.spec.ts
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
seedArc,
|
||||||
|
seedChapter,
|
||||||
|
deleteCampaign,
|
||||||
|
getChapterById,
|
||||||
|
type SeededCampaign,
|
||||||
|
type SeededArc,
|
||||||
|
type SeededChapter,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Chapter edit', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
let arc: SeededArc;
|
||||||
|
let chapter: SeededChapter;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
arc = await seedArc(request, { campaignId: campaign.id });
|
||||||
|
chapter = await seedChapter(request, { arcId: arc.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('edits all chapter fields and persists them to API', async ({ page, request }) => {
|
||||||
|
const newName = `${chapter.name} renamed`;
|
||||||
|
const values = {
|
||||||
|
description: 'Le chapitre ouvre sur un village en proie à la peur.',
|
||||||
|
gmNotes: 'Le maire cache un pacte avec les gobelins.',
|
||||||
|
playerObjectives: "Découvrir la source des disparitions.",
|
||||||
|
narrativeStakes: "La confiance du village est en jeu.",
|
||||||
|
};
|
||||||
|
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/edit`);
|
||||||
|
|
||||||
|
await expect(page.getByLabel(/Titre du chapitre/i)).toHaveValue(chapter.name);
|
||||||
|
|
||||||
|
await page.getByLabel(/Titre du chapitre/i).fill(newName);
|
||||||
|
await page.getByLabel(/Synopsis du chapitre/i).fill(values.description);
|
||||||
|
await page.getByLabel(/Notes du Maître de Jeu/i).fill(values.gmNotes);
|
||||||
|
await page.getByLabel(/Objectifs des joueurs/i).fill(values.playerObjectives);
|
||||||
|
await page.getByLabel(/Enjeux narratifs/i).fill(values.narrativeStakes);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(
|
||||||
|
new RegExp(`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}$`),
|
||||||
|
);
|
||||||
|
|
||||||
|
const persisted = await getChapterById(request, chapter.id);
|
||||||
|
expect(persisted.name).toBe(newName);
|
||||||
|
expect(persisted.description).toBe(values.description);
|
||||||
|
expect(persisted.gmNotes).toBe(values.gmNotes);
|
||||||
|
expect(persisted.playerObjectives).toBe(values.playerObjectives);
|
||||||
|
expect(persisted.narrativeStakes).toBe(values.narrativeStakes);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('save button is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto(`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/edit`);
|
||||||
|
const nameField = page.getByLabel(/Titre du chapitre/i);
|
||||||
|
const saveBtn = page.getByRole('button', { name: /^Sauvegarder$/i });
|
||||||
|
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
await nameField.fill('');
|
||||||
|
await expect(saveBtn).toBeDisabled();
|
||||||
|
await nameField.fill('OK');
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
64
web/e2e/tests/campaign/scene-create.spec.ts
Normal file
64
web/e2e/tests/campaign/scene-create.spec.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
seedArc,
|
||||||
|
seedChapter,
|
||||||
|
deleteCampaign,
|
||||||
|
getSceneById,
|
||||||
|
type SeededCampaign,
|
||||||
|
type SeededArc,
|
||||||
|
type SeededChapter,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Scene creation', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
let arc: SeededArc;
|
||||||
|
let chapter: SeededChapter;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
arc = await seedArc(request, { campaignId: campaign.id });
|
||||||
|
chapter = await seedChapter(request, { arcId: arc.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates a scene and redirects to its view', async ({ page, request }) => {
|
||||||
|
const sceneName = `Scène ${Date.now()}`;
|
||||||
|
|
||||||
|
await page.goto(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/create`,
|
||||||
|
);
|
||||||
|
await expect(page.getByRole('heading', { name: /Créer une nouvelle scène/i })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom de la scène/i).fill(sceneName);
|
||||||
|
await page.getByLabel(/Description/i).fill('Résumé rapide de la scène.');
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Créer la scène$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(
|
||||||
|
new RegExp(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/\\d+$`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const createdId = page.url().match(/\/scenes\/(\d+)$/)?.[1];
|
||||||
|
expect(createdId).toBeTruthy();
|
||||||
|
const persisted = await getSceneById(request, createdId!);
|
||||||
|
expect(persisted.name).toBe(sceneName);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('submit is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/create`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const submit = page.getByRole('button', { name: /^Créer la scène$/i });
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom de la scène/i).fill('OK');
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
147
web/e2e/tests/campaign/scene-edit.spec.ts
Normal file
147
web/e2e/tests/campaign/scene-edit.spec.ts
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
seedArc,
|
||||||
|
seedChapter,
|
||||||
|
seedScene,
|
||||||
|
deleteCampaign,
|
||||||
|
getSceneById,
|
||||||
|
type SeededCampaign,
|
||||||
|
type SeededArc,
|
||||||
|
type SeededChapter,
|
||||||
|
type SeededScene,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Scene edit', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
let arc: SeededArc;
|
||||||
|
let chapter: SeededChapter;
|
||||||
|
let scene: SeededScene;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
campaign = await seedCampaign(request);
|
||||||
|
arc = await seedArc(request, { campaignId: campaign.id });
|
||||||
|
chapter = await seedChapter(request, { arcId: arc.id });
|
||||||
|
scene = await seedScene(request, { chapterId: chapter.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('edits all text fields across sections and persists them to API', async ({ page, request }) => {
|
||||||
|
const newName = `${scene.name} renamed`;
|
||||||
|
const values = {
|
||||||
|
description: "Les PJ arrivent au village à la nuit tombée.",
|
||||||
|
location: "Taverne du Dragon d'Or",
|
||||||
|
timing: 'Soir, pleine lune',
|
||||||
|
atmosphere: 'Silence pesant, regards fuyants des villageois.',
|
||||||
|
playerNarration: 'Vous poussez la porte de la taverne…',
|
||||||
|
gmSecretNotes: 'Le tavernier est complice des bandits.',
|
||||||
|
choicesConsequences: 'Accepter = piégés à l\'étage. Refuser = filature.',
|
||||||
|
combatDifficulty: 'Moyenne, 4 bandits niveau 3',
|
||||||
|
enemies: 'Bandit chef (feuille jointe) + 3 sbires.',
|
||||||
|
};
|
||||||
|
|
||||||
|
await page.goto(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/${scene.id}/edit`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(page.getByLabel(/Titre de la scène/i)).toHaveValue(scene.name);
|
||||||
|
|
||||||
|
await page.getByLabel(/Titre de la scène/i).fill(newName);
|
||||||
|
await page.getByLabel(/Description courte/i).fill(values.description);
|
||||||
|
await page.getByLabel(/^Lieu$/i).fill(values.location);
|
||||||
|
await page.getByLabel(/^Moment$/i).fill(values.timing);
|
||||||
|
await page.getByLabel(/Ambiance et atmosphère/i).fill(values.atmosphere);
|
||||||
|
|
||||||
|
// Les sections suivantes sont fermées par défaut : on les ouvre avant de taper.
|
||||||
|
// Un clic sur le header de la section toggle son état.
|
||||||
|
await page.locator('app-expandable-section', { hasText: 'Narration pour les joueurs' }).click();
|
||||||
|
await page.getByPlaceholder(/Le texte que vous lirez aux joueurs/i).fill(values.playerNarration);
|
||||||
|
|
||||||
|
await page.locator('app-expandable-section', { hasText: 'Notes et secrets du MJ' }).click();
|
||||||
|
await page
|
||||||
|
.getByPlaceholder(/Informations cachées, indices, éléments secrets/i)
|
||||||
|
.fill(values.gmSecretNotes);
|
||||||
|
|
||||||
|
await page.locator('app-expandable-section', { hasText: 'Choix et conséquences' }).click();
|
||||||
|
await page
|
||||||
|
.getByPlaceholder(/Décrivez les différentes options/i)
|
||||||
|
.fill(values.choicesConsequences);
|
||||||
|
|
||||||
|
await page.locator('app-expandable-section', { hasText: 'Combat ou rencontre' }).click();
|
||||||
|
await page.getByLabel(/Difficulté estimée/i).fill(values.combatDifficulty);
|
||||||
|
await page.getByLabel(/Ennemis et créatures/i).fill(values.enemies);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(
|
||||||
|
new RegExp(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/${scene.id}$`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const persisted = await getSceneById(request, scene.id);
|
||||||
|
expect(persisted.name).toBe(newName);
|
||||||
|
expect(persisted.description).toBe(values.description);
|
||||||
|
expect(persisted.location).toBe(values.location);
|
||||||
|
expect(persisted.timing).toBe(values.timing);
|
||||||
|
expect(persisted.atmosphere).toBe(values.atmosphere);
|
||||||
|
expect(persisted.playerNarration).toBe(values.playerNarration);
|
||||||
|
expect(persisted.gmSecretNotes).toBe(values.gmSecretNotes);
|
||||||
|
expect(persisted.choicesConsequences).toBe(values.choicesConsequences);
|
||||||
|
expect(persisted.combatDifficulty).toBe(values.combatDifficulty);
|
||||||
|
expect(persisted.enemies).toBe(values.enemies);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('adds a narrative branch to a sibling scene and persists it', async ({ page, request }) => {
|
||||||
|
const sibling = await seedScene(request, {
|
||||||
|
chapterId: chapter.id,
|
||||||
|
name: 'Scène alternative',
|
||||||
|
order: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/${scene.id}/edit`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const branchesSection = page.locator('app-expandable-section', { hasText: 'Branches narratives' });
|
||||||
|
await branchesSection.click();
|
||||||
|
|
||||||
|
await branchesSection.getByRole('button', { name: /Ajouter une branche/i }).click();
|
||||||
|
|
||||||
|
const branchItem = branchesSection.locator('.branch-item').first();
|
||||||
|
await branchItem.getByPlaceholder(/Ex: Si les joueurs attaquent/i).fill('Si les PJ fuient');
|
||||||
|
await branchItem.locator('select').selectOption({ label: sibling.name });
|
||||||
|
await branchItem.getByPlaceholder(/Jet de Persuasion/i).fill('Sur échec initiative');
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(
|
||||||
|
new RegExp(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/${scene.id}$`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const persisted = await getSceneById(request, scene.id);
|
||||||
|
expect(persisted.branches).toHaveLength(1);
|
||||||
|
expect(persisted.branches![0].label).toBe('Si les PJ fuient');
|
||||||
|
expect(persisted.branches![0].targetSceneId).toBe(sibling.id);
|
||||||
|
expect(persisted.branches![0].condition).toBe('Sur échec initiative');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('save button is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto(
|
||||||
|
`/campaigns/${campaign.id}/arcs/${arc.id}/chapters/${chapter.id}/scenes/${scene.id}/edit`,
|
||||||
|
);
|
||||||
|
const nameField = page.getByLabel(/Titre de la scène/i);
|
||||||
|
const saveBtn = page.getByRole('button', { name: /^Sauvegarder$/i });
|
||||||
|
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
await nameField.fill('');
|
||||||
|
await expect(saveBtn).toBeDisabled();
|
||||||
|
await nameField.fill('OK');
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
77
web/e2e/tests/lore/lore-create.spec.ts
Normal file
77
web/e2e/tests/lore/lore-create.spec.ts
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { deleteLore } from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Lore creation', () => {
|
||||||
|
const createdLoreIds: string[] = [];
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
while (createdLoreIds.length) {
|
||||||
|
const id = createdLoreIds.pop()!;
|
||||||
|
await deleteLore(request, id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('opens the modal, creates a lore, and shows it in the grid', async ({ page, request }) => {
|
||||||
|
const loreName = `Univers E2E ${Date.now()}`;
|
||||||
|
const description = "Un univers créé par les tests automatisés.";
|
||||||
|
|
||||||
|
await page.goto('/lore');
|
||||||
|
|
||||||
|
await expect(page.getByRole('heading', { name: /Vos Univers/i })).toBeVisible();
|
||||||
|
|
||||||
|
await page.locator('.lore-card.card-new').click();
|
||||||
|
|
||||||
|
const modal = page.locator('.modal');
|
||||||
|
await expect(modal).toBeVisible();
|
||||||
|
await expect(modal.getByRole('heading', { name: /Créer un nouveau Lore/i })).toBeVisible();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nom de l'univers/i).fill(loreName);
|
||||||
|
await modal.getByLabel('Description').fill(description);
|
||||||
|
|
||||||
|
await modal.getByRole('button', { name: /^Créer le lore$/i }).click();
|
||||||
|
|
||||||
|
await expect(modal).not.toBeVisible();
|
||||||
|
|
||||||
|
const newCard = page.locator('.lore-card', { hasText: loreName });
|
||||||
|
await expect(newCard).toBeVisible();
|
||||||
|
await expect(newCard).toContainText(description);
|
||||||
|
|
||||||
|
const allLores = await request.get('/api/lores').then((r) => r.json());
|
||||||
|
const created = allLores.find((l: { name: string; id: string }) => l.name === loreName);
|
||||||
|
expect(created).toBeDefined();
|
||||||
|
createdLoreIds.push(created.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('submit button is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto('/lore');
|
||||||
|
await page.locator('.lore-card.card-new').click();
|
||||||
|
|
||||||
|
const modal = page.locator('.modal');
|
||||||
|
const submit = modal.getByRole('button', { name: /^Créer le lore$/i });
|
||||||
|
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nom de l'univers/i).fill('Quelque chose');
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nom de l'univers/i).fill('');
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clicking the backdrop closes the modal without creating', async ({ page }) => {
|
||||||
|
const typedButAbandoned = `Univers abandonné ${Date.now()}`;
|
||||||
|
|
||||||
|
await page.goto('/lore');
|
||||||
|
await page.locator('.lore-card.card-new').click();
|
||||||
|
|
||||||
|
const modal = page.locator('.modal');
|
||||||
|
await expect(modal).toBeVisible();
|
||||||
|
|
||||||
|
await modal.getByLabel(/Nom de l'univers/i).fill(typedButAbandoned);
|
||||||
|
|
||||||
|
await page.locator('.modal-backdrop').click({ position: { x: 5, y: 5 } });
|
||||||
|
await expect(modal).not.toBeVisible();
|
||||||
|
|
||||||
|
await expect(page.locator('.lore-card', { hasText: typedButAbandoned })).toHaveCount(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
53
web/e2e/tests/lore/lore-delete.spec.ts
Normal file
53
web/e2e/tests/lore/lore-delete.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { seedLoreWithFolder, deleteLore, type SeededLore } from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Lore delete', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
// Best-effort cleanup — ne fait rien si déjà supprimé par le test.
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deletes a lore after accepting the confirm and redirects to the list', async ({
|
||||||
|
page,
|
||||||
|
request,
|
||||||
|
}) => {
|
||||||
|
let confirmMessage = '';
|
||||||
|
page.on('dialog', async (dialog) => {
|
||||||
|
confirmMessage = dialog.message();
|
||||||
|
await dialog.accept();
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
// Attente du dialog et du retour sur la liste des lores.
|
||||||
|
await expect(page).toHaveURL(/\/lore$/);
|
||||||
|
expect(confirmMessage).toContain(seeded.name);
|
||||||
|
// Lore contient un dossier seedé : le récapitulatif doit l'indiquer.
|
||||||
|
expect(confirmMessage).toMatch(/1 dossier/i);
|
||||||
|
|
||||||
|
const res = await request.get(`/api/lores/${seeded.id}`);
|
||||||
|
expect(res.status()).toBe(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keeps the lore when the confirm is dismissed', async ({ page, request }) => {
|
||||||
|
page.on('dialog', async (dialog) => {
|
||||||
|
await dialog.dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
// On reste sur le détail, le titre du lore est toujours visible.
|
||||||
|
await expect(page.locator('.detail-header h1')).toHaveText(seeded.name);
|
||||||
|
|
||||||
|
const res = await request.get(`/api/lores/${seeded.id}`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
70
web/e2e/tests/lore/lore-detail-edit.spec.ts
Normal file
70
web/e2e/tests/lore/lore-detail-edit.spec.ts
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { seedLoreWithFolder, deleteLore, getLoreById, type SeededLore } from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Lore inline edit (on detail page)', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renames the lore inline and persists the change', async ({ page, request }) => {
|
||||||
|
const newName = `${seeded.name} renamed`;
|
||||||
|
const newDescription = 'Nouvelle description éditée via UI';
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}`);
|
||||||
|
|
||||||
|
await expect(page.locator('.detail-header h1')).toHaveText(seeded.name);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Modifier$/i }).click();
|
||||||
|
|
||||||
|
const nameInput = page.getByLabel(/^Nom$/);
|
||||||
|
const descInput = page.getByLabel(/^Description$/);
|
||||||
|
await expect(nameInput).toHaveValue(seeded.name);
|
||||||
|
|
||||||
|
await nameInput.fill(newName);
|
||||||
|
await descInput.fill(newDescription);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|
||||||
|
// Sortie du mode édition : le header bascule en mode lecture avec la nouvelle valeur.
|
||||||
|
await expect(page.locator('.detail-header h1')).toHaveText(newName);
|
||||||
|
await expect(page.locator('.detail-header .description')).toHaveText(newDescription);
|
||||||
|
|
||||||
|
const persisted = await getLoreById(request, seeded.id);
|
||||||
|
expect(persisted.name).toBe(newName);
|
||||||
|
expect(persisted.description).toBe(newDescription);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('save button is disabled when name is emptied during edit', async ({ page }) => {
|
||||||
|
await page.goto(`/lore/${seeded.id}`);
|
||||||
|
await page.getByRole('button', { name: /^Modifier$/i }).click();
|
||||||
|
|
||||||
|
const saveBtn = page.getByRole('button', { name: /^Sauvegarder$/i });
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/^Nom$/).fill('');
|
||||||
|
await expect(saveBtn).toBeDisabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/^Nom$/).fill(' ');
|
||||||
|
await expect(saveBtn).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cancel discards the in-flight edits', async ({ page, request }) => {
|
||||||
|
await page.goto(`/lore/${seeded.id}`);
|
||||||
|
await page.getByRole('button', { name: /^Modifier$/i }).click();
|
||||||
|
|
||||||
|
await page.getByLabel(/^Nom$/).fill('Name jamais sauvegardé');
|
||||||
|
await page.getByRole('button', { name: /^Annuler$/i }).click();
|
||||||
|
|
||||||
|
// Retour en mode lecture avec le nom d'origine.
|
||||||
|
await expect(page.locator('.detail-header h1')).toHaveText(seeded.name);
|
||||||
|
|
||||||
|
const persisted = await getLoreById(request, seeded.id);
|
||||||
|
expect(persisted.name).toBe(seeded.name);
|
||||||
|
});
|
||||||
|
});
|
||||||
133
web/e2e/tests/lore/page-create.spec.ts
Normal file
133
web/e2e/tests/lore/page-create.spec.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedLoreWithFolder,
|
||||||
|
seedTemplate,
|
||||||
|
deleteLore,
|
||||||
|
getPagesForLore,
|
||||||
|
type SeededLore,
|
||||||
|
type SeededTemplate,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Page creation', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
let template: SeededTemplate;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
template = await seedTemplate(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
defaultNodeId: seeded.rootFolderId,
|
||||||
|
fieldNames: ['Apparence', 'Motivation'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates an empty page from a template and redirects to edit', async ({ page, request }) => {
|
||||||
|
const pageTitle = `Maître Eldrin ${Date.now()}`;
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/create`);
|
||||||
|
|
||||||
|
await expect(page.getByRole('heading', { name: /Créer une nouvelle Page/i })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByLabel(/Titre de la page/i).fill(pageTitle);
|
||||||
|
|
||||||
|
await page.locator('.template-card', { hasText: template.name }).click();
|
||||||
|
await expect(page.locator('.template-card.selected', { hasText: template.name })).toBeVisible();
|
||||||
|
|
||||||
|
await expect(page.locator('#page-node')).toHaveValue(seeded.rootFolderId);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Créer la page$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}/pages/[^/]+/edit$`));
|
||||||
|
|
||||||
|
const pages = await getPagesForLore(request, seeded.id);
|
||||||
|
const created = pages.find((p) => p.title === pageTitle);
|
||||||
|
expect(created).toBeDefined();
|
||||||
|
expect(created?.templateId).toBe(template.id);
|
||||||
|
expect(created?.nodeId).toBe(seeded.rootFolderId);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('submit is disabled until title, template and folder are set', async ({ page, request }) => {
|
||||||
|
// On seed un 2ᵉ template pour empêcher l'auto-sélection (qui se déclenche
|
||||||
|
// quand un seul template a un defaultNodeId valide). Avec deux candidats,
|
||||||
|
// l'utilisateur doit choisir explicitement → on retrouve le comportement
|
||||||
|
// initial du test : submit disabled tant qu'un template n'est pas cliqué.
|
||||||
|
const secondFolderRes = await request.post('/api/lore-nodes', {
|
||||||
|
data: { loreId: seeded.id, name: 'Autre dossier', icon: 'folder', description: '' },
|
||||||
|
});
|
||||||
|
const secondFolderId = (await secondFolderRes.json()).id;
|
||||||
|
await seedTemplate(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
defaultNodeId: secondFolderId,
|
||||||
|
name: `Second template ${Date.now()}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/create`);
|
||||||
|
|
||||||
|
const submit = page.getByRole('button', { name: /^Créer la page$/i });
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/Titre de la page/i).fill('Un titre');
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await page.locator('.template-card', { hasText: template.name }).click();
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('entering on a folder-scoped route preselects that folder', async ({ page, request }) => {
|
||||||
|
const pageTitle = `Page scoped ${Date.now()}`;
|
||||||
|
|
||||||
|
// Dossier sans template par défaut → pas d'auto-sélection de template,
|
||||||
|
// l'utilisateur clique manuellement (ce qu'on veut tester ici).
|
||||||
|
const secondFolderRes = await request.post('/api/lore-nodes', {
|
||||||
|
data: { loreId: seeded.id, name: 'Autre dossier', icon: 'folder', description: '' },
|
||||||
|
});
|
||||||
|
expect(secondFolderRes.ok()).toBeTruthy();
|
||||||
|
const secondFolderId = (await secondFolderRes.json()).id;
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/nodes/${secondFolderId}/pages/create`);
|
||||||
|
|
||||||
|
const nodeSelect = page.locator('#page-node');
|
||||||
|
await expect(nodeSelect).toHaveValue(secondFolderId);
|
||||||
|
await expect(nodeSelect).toBeDisabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/Titre de la page/i).fill(pageTitle);
|
||||||
|
await page.locator('.template-card', { hasText: template.name }).click();
|
||||||
|
await page.getByRole('button', { name: /^Créer la page$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}/pages/[^/]+/edit$`));
|
||||||
|
|
||||||
|
const pages = await getPagesForLore(request, seeded.id);
|
||||||
|
expect(pages.find((p) => p.title === pageTitle)?.nodeId).toBe(secondFolderId);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('auto-selects the template on free route when it is the only candidate', async ({ page }) => {
|
||||||
|
// Le seed donne EXACTEMENT 1 template avec defaultNodeId valide → la
|
||||||
|
// logique d'auto-sélection doit s'enclencher au chargement.
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/create`);
|
||||||
|
|
||||||
|
await expect(page.locator('.template-card.selected', { hasText: template.name })).toBeVisible();
|
||||||
|
await expect(page.locator('#page-node')).toHaveValue(seeded.rootFolderId);
|
||||||
|
|
||||||
|
// Conséquence : juste taper un titre suffit pour activer le submit.
|
||||||
|
const submit = page.getByRole('button', { name: /^Créer la page$/i });
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
await page.getByLabel(/Titre de la page/i).fill('Auto');
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('auto-selects the template on folder-scoped route when its defaultNodeId matches', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
// Le template seedé pointe sur seeded.rootFolderId — entrer sur la route
|
||||||
|
// folder-scoped de ce dossier doit auto-sélectionner ce template.
|
||||||
|
await page.goto(`/lore/${seeded.id}/nodes/${seeded.rootFolderId}/pages/create`);
|
||||||
|
|
||||||
|
await expect(page.locator('.template-card.selected', { hasText: template.name })).toBeVisible();
|
||||||
|
await expect(page.locator('#page-node')).toHaveValue(seeded.rootFolderId);
|
||||||
|
await expect(page.locator('#page-node')).toBeDisabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
58
web/e2e/tests/lore/page-delete.spec.ts
Normal file
58
web/e2e/tests/lore/page-delete.spec.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedLoreWithFolder,
|
||||||
|
seedTemplate,
|
||||||
|
seedPage,
|
||||||
|
deleteLore,
|
||||||
|
type SeededLore,
|
||||||
|
type SeededTemplate,
|
||||||
|
type SeededPage,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Page delete', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
let template: SeededTemplate;
|
||||||
|
let pageEntity: SeededPage;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
template = await seedTemplate(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
defaultNodeId: seeded.rootFolderId,
|
||||||
|
});
|
||||||
|
pageEntity = await seedPage(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
nodeId: seeded.rootFolderId,
|
||||||
|
templateId: template.id,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deletes the page after accepting confirm', async ({ page, request }) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.accept());
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/${pageEntity.id}/edit`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
// Le composant redirige vers la racine du Lore après suppression.
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}$`));
|
||||||
|
|
||||||
|
const res = await request.get(`/api/pages/${pageEntity.id}`);
|
||||||
|
expect(res.status()).toBe(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keeps the page when confirm is dismissed', async ({ page, request }) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.dismiss());
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/${pageEntity.id}/edit`);
|
||||||
|
await page.getByRole('button', { name: /^Supprimer$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}/pages/${pageEntity.id}/edit$`));
|
||||||
|
|
||||||
|
const res = await request.get(`/api/pages/${pageEntity.id}`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
95
web/e2e/tests/lore/page-edit.spec.ts
Normal file
95
web/e2e/tests/lore/page-edit.spec.ts
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedLoreWithFolder,
|
||||||
|
seedTemplate,
|
||||||
|
seedPage,
|
||||||
|
deleteLore,
|
||||||
|
getPageById,
|
||||||
|
type SeededLore,
|
||||||
|
type SeededTemplate,
|
||||||
|
type SeededPage,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Page edit', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
let template: SeededTemplate;
|
||||||
|
let pageEntity: SeededPage;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
template = await seedTemplate(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
defaultNodeId: seeded.rootFolderId,
|
||||||
|
fieldNames: ['Apparence', 'Motivation'],
|
||||||
|
});
|
||||||
|
pageEntity = await seedPage(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
nodeId: seeded.rootFolderId,
|
||||||
|
templateId: template.id,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('edits title, dynamic fields, notes and persists to API', async ({ page, request }) => {
|
||||||
|
const newTitle = `Maître Eldrin ${Date.now()}`;
|
||||||
|
const apparence = 'Vieil homme au regard perçant.';
|
||||||
|
const motivation = 'Protéger la cité à tout prix.';
|
||||||
|
const notes = 'MJ : il connaît le secret du roi.';
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/${pageEntity.id}/edit`);
|
||||||
|
|
||||||
|
await expect(page.locator('input[name="title"]')).toHaveValue(pageEntity.title);
|
||||||
|
|
||||||
|
await page.locator('input[name="title"]').fill(newTitle);
|
||||||
|
await page.getByPlaceholder('Valeur pour Apparence...').fill(apparence);
|
||||||
|
await page.getByPlaceholder('Valeur pour Motivation...').fill(motivation);
|
||||||
|
await page.locator('textarea[name="notes"]').fill(notes);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}/pages/${pageEntity.id}$`));
|
||||||
|
|
||||||
|
const persisted = await getPageById(request, pageEntity.id);
|
||||||
|
expect(persisted.title).toBe(newTitle);
|
||||||
|
expect(persisted.values?.['Apparence']).toBe(apparence);
|
||||||
|
expect(persisted.values?.['Motivation']).toBe(motivation);
|
||||||
|
expect(persisted.notes).toBe(notes);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('adds a tag via chips input and persists it', async ({ page, request }) => {
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/${pageEntity.id}/edit`);
|
||||||
|
|
||||||
|
const chipsInput = page.locator('app-chips-input input');
|
||||||
|
await chipsInput.fill('dangereux');
|
||||||
|
await chipsInput.press('Enter');
|
||||||
|
await chipsInput.fill('ancien');
|
||||||
|
await chipsInput.press('Enter');
|
||||||
|
|
||||||
|
await expect(page.locator('app-chips-input').getByText('dangereux')).toBeVisible();
|
||||||
|
await expect(page.locator('app-chips-input').getByText('ancien')).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}/pages/${pageEntity.id}$`));
|
||||||
|
|
||||||
|
const persisted = await getPageById(request, pageEntity.id);
|
||||||
|
expect(persisted.tags).toEqual(expect.arrayContaining(['dangereux', 'ancien']));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('save button is disabled when title is empty', async ({ page }) => {
|
||||||
|
await page.goto(`/lore/${seeded.id}/pages/${pageEntity.id}/edit`);
|
||||||
|
|
||||||
|
const titleInput = page.locator('input[name="title"]');
|
||||||
|
const saveBtn = page.getByRole('button', { name: /^Sauvegarder$/i });
|
||||||
|
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
await titleInput.fill('');
|
||||||
|
await expect(saveBtn).toBeDisabled();
|
||||||
|
await titleInput.fill(' ');
|
||||||
|
await expect(saveBtn).toBeDisabled();
|
||||||
|
await titleInput.fill('OK');
|
||||||
|
await expect(saveBtn).toBeEnabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
72
web/e2e/tests/lore/template-create.spec.ts
Normal file
72
web/e2e/tests/lore/template-create.spec.ts
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { seedLoreWithFolder, deleteLore, getTemplatesForLore, type SeededLore } from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Template creation', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creates a template with default fields', async ({ page, request }) => {
|
||||||
|
const templateName = `Auberge ${Date.now()}`;
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/create`);
|
||||||
|
|
||||||
|
await expect(page.getByRole('heading', { name: /Créer un nouveau Template/i })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom du template/i).fill(templateName);
|
||||||
|
await page.getByLabel('Description').fill('Template créé via E2E');
|
||||||
|
await page.getByLabel(/Dossier par défaut/i).selectOption({ label: seeded.rootFolderName });
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Créer le template$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}$`));
|
||||||
|
|
||||||
|
const templates = await getTemplatesForLore(request, seeded.id);
|
||||||
|
expect(templates.map((t) => t.name)).toContain(templateName);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('submit is disabled when name is empty', async ({ page }) => {
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/create`);
|
||||||
|
|
||||||
|
const submit = page.getByRole('button', { name: /^Créer le template$/i });
|
||||||
|
await expect(submit).toBeDisabled();
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom du template/i).fill('Valid name');
|
||||||
|
await page.getByLabel(/Dossier par défaut/i).selectOption({ label: seeded.rootFolderName });
|
||||||
|
await expect(submit).toBeEnabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('can add and remove a custom field before creating', async ({ page, request }) => {
|
||||||
|
const templateName = `Artefact ${Date.now()}`;
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/create`);
|
||||||
|
|
||||||
|
await page.getByLabel(/Nom du template/i).fill(templateName);
|
||||||
|
await page.getByLabel(/Dossier par défaut/i).selectOption({ label: seeded.rootFolderName });
|
||||||
|
|
||||||
|
const addFieldInput = page.getByPlaceholder('+ Ajouter un champ');
|
||||||
|
await addFieldInput.fill('Pouvoir');
|
||||||
|
await addFieldInput.press('Enter');
|
||||||
|
await expect(page.locator('.fields-list .field-chip', { hasText: 'Pouvoir' })).toBeVisible();
|
||||||
|
|
||||||
|
await addFieldInput.fill('Origine');
|
||||||
|
await addFieldInput.press('Enter');
|
||||||
|
await expect(page.locator('.fields-list .field-chip', { hasText: 'Origine' })).toBeVisible();
|
||||||
|
|
||||||
|
const origineRow = page.locator('.fields-list .field-row', { hasText: 'Origine' });
|
||||||
|
await origineRow.getByRole('button', { name: 'Supprimer' }).click();
|
||||||
|
await expect(page.locator('.fields-list .field-chip', { hasText: 'Origine' })).toHaveCount(0);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Créer le template$/i }).click();
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}$`));
|
||||||
|
|
||||||
|
const templates = await getTemplatesForLore(request, seeded.id);
|
||||||
|
expect(templates.find((t) => t.name === templateName)).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
51
web/e2e/tests/lore/template-delete.spec.ts
Normal file
51
web/e2e/tests/lore/template-delete.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedLoreWithFolder,
|
||||||
|
seedTemplate,
|
||||||
|
deleteLore,
|
||||||
|
getTemplatesForLore,
|
||||||
|
type SeededLore,
|
||||||
|
type SeededTemplate,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Template delete', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
let template: SeededTemplate;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
template = await seedTemplate(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
defaultNodeId: seeded.rootFolderId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deletes the template after accepting confirm', async ({ page, request }) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.accept());
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/${template.id}`);
|
||||||
|
await page.locator('.page-header .btn-danger').click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}$`));
|
||||||
|
|
||||||
|
const templates = await getTemplatesForLore(request, seeded.id);
|
||||||
|
expect(templates.find((t) => t.id === template.id)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keeps the template when confirm is dismissed', async ({ page, request }) => {
|
||||||
|
page.on('dialog', (dialog) => dialog.dismiss());
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/${template.id}`);
|
||||||
|
await page.locator('.page-header .btn-danger').click();
|
||||||
|
|
||||||
|
// On reste sur l'écran d'édition (l'URL ne change pas).
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}/templates/${template.id}$`));
|
||||||
|
|
||||||
|
const templates = await getTemplatesForLore(request, seeded.id);
|
||||||
|
expect(templates.find((t) => t.id === template.id)).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
74
web/e2e/tests/lore/template-edit.spec.ts
Normal file
74
web/e2e/tests/lore/template-edit.spec.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedLoreWithFolder,
|
||||||
|
seedTemplate,
|
||||||
|
deleteLore,
|
||||||
|
getTemplateById,
|
||||||
|
type SeededLore,
|
||||||
|
type SeededTemplate,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
test.describe('Template edit', () => {
|
||||||
|
let seeded: SeededLore;
|
||||||
|
let template: SeededTemplate;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
seeded = await seedLoreWithFolder(request);
|
||||||
|
template = await seedTemplate(request, {
|
||||||
|
loreId: seeded.id,
|
||||||
|
defaultNodeId: seeded.rootFolderId,
|
||||||
|
fieldNames: ['Nom', 'Description'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (seeded?.id) await deleteLore(request, seeded.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('form is prefilled with the current template data', async ({ page }) => {
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/${template.id}`);
|
||||||
|
|
||||||
|
await expect(page.getByLabel(/^Nom$/)).toHaveValue(template.name);
|
||||||
|
await expect(page.getByLabel(/Dossier par défaut/i)).toHaveValue(seeded.rootFolderId);
|
||||||
|
await expect(page.locator('.fields-list .field-chip', { hasText: 'Nom' })).toBeVisible();
|
||||||
|
await expect(page.locator('.fields-list .field-chip', { hasText: 'Description' })).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renames the template and persists to API', async ({ page, request }) => {
|
||||||
|
const newName = `${template.name} renamed`;
|
||||||
|
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/${template.id}`);
|
||||||
|
|
||||||
|
const nameInput = page.getByLabel(/^Nom$/);
|
||||||
|
await nameInput.fill(newName);
|
||||||
|
await page.getByLabel(/Description/i).fill('Description mise à jour');
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}$`));
|
||||||
|
|
||||||
|
const persisted = await getTemplateById(request, template.id);
|
||||||
|
expect(persisted.name).toBe(newName);
|
||||||
|
expect(persisted.description).toBe('Description mise à jour');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('adds a new field, removes an existing one, and persists the order', async ({ page, request }) => {
|
||||||
|
await page.goto(`/lore/${seeded.id}/templates/${template.id}`);
|
||||||
|
|
||||||
|
const addInput = page.getByPlaceholder('+ Ajouter un champ');
|
||||||
|
await addInput.fill('Stats');
|
||||||
|
await addInput.press('Enter');
|
||||||
|
await expect(page.locator('.fields-list .field-chip', { hasText: 'Stats' })).toBeVisible();
|
||||||
|
|
||||||
|
const descriptionRow = page.locator('.fields-list .field-row', { hasText: 'Description' });
|
||||||
|
await descriptionRow.getByRole('button', { name: 'Supprimer' }).click();
|
||||||
|
await expect(page.locator('.fields-list .field-chip', { hasText: 'Description' })).toHaveCount(0);
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/lore/${seeded.id}$`));
|
||||||
|
|
||||||
|
const persisted = await getTemplateById(request, template.id);
|
||||||
|
const names = persisted.fields.map((f) => f.name);
|
||||||
|
expect(names).toEqual(['Nom', 'Stats']);
|
||||||
|
});
|
||||||
|
});
|
||||||
15
web/e2e/tests/smoke.spec.ts
Normal file
15
web/e2e/tests/smoke.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test.describe('Smoke', () => {
|
||||||
|
test('app loads without uncaught errors', async ({ page }) => {
|
||||||
|
const errors: string[] = [];
|
||||||
|
page.on('pageerror', (err) => errors.push(err.message));
|
||||||
|
|
||||||
|
await page.goto('/');
|
||||||
|
|
||||||
|
await expect(page.locator('app-sidebar')).toBeVisible();
|
||||||
|
await expect(page.locator('main.main-content')).toBeAttached();
|
||||||
|
|
||||||
|
expect(errors, `Page errors:\n${errors.join('\n')}`).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
68
web/package-lock.json
generated
68
web/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "loremind-web",
|
"name": "loremind-web",
|
||||||
"version": "0.4.0",
|
"version": "0.6.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "loremind-web",
|
"name": "loremind-web",
|
||||||
"version": "0.4.0",
|
"version": "0.6.5",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "^17.0.0",
|
"@angular/animations": "^17.0.0",
|
||||||
"@angular/common": "^17.0.0",
|
"@angular/common": "^17.0.0",
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
"@angular-devkit/build-angular": "^17.0.0",
|
"@angular-devkit/build-angular": "^17.0.0",
|
||||||
"@angular/cli": "^17.0.0",
|
"@angular/cli": "^17.0.0",
|
||||||
"@angular/compiler-cli": "^17.0.0",
|
"@angular/compiler-cli": "^17.0.0",
|
||||||
|
"@playwright/test": "^1.59.1",
|
||||||
"typescript": "~5.2.2"
|
"typescript": "~5.2.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3137,6 +3138,22 @@
|
|||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@playwright/test": {
|
||||||
|
"version": "1.59.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.59.1.tgz",
|
||||||
|
"integrity": "sha512-PG6q63nQg5c9rIi4/Z5lR5IVF7yU5MqmKaPOe0HSc0O2cX1fPi96sUQu5j7eo4gKCkB2AnNGoWt7y4/Xx3Kcqg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"playwright": "1.59.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"playwright": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@rollup/rollup-android-arm-eabi": {
|
"node_modules/@rollup/rollup-android-arm-eabi": {
|
||||||
"version": "4.60.1",
|
"version": "4.60.1",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.60.1.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.60.1.tgz",
|
||||||
@@ -9063,6 +9080,53 @@
|
|||||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/playwright": {
|
||||||
|
"version": "1.59.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.59.1.tgz",
|
||||||
|
"integrity": "sha512-C8oWjPR3F81yljW9o5OxcWzfh6avkVwDD2VYdwIGqTkl+OGFISgypqzfu7dOe4QNLL2aqcWBmI3PMtLIK233lw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"playwright-core": "1.59.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"playwright": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "2.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright-core": {
|
||||||
|
"version": "1.59.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.59.1.tgz",
|
||||||
|
"integrity": "sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"playwright-core": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright/node_modules/fsevents": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/postcss": {
|
"node_modules/postcss": {
|
||||||
"version": "8.4.35",
|
"version": "8.4.35",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.35.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.35.tgz",
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "loremind-web",
|
"name": "loremind-web",
|
||||||
"version": "0.6.0",
|
"version": "0.6.5",
|
||||||
"description": "LoreMind Frontend - Angular",
|
"description": "LoreMind Frontend - Angular",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"watch": "ng build --watch --configuration development",
|
"watch": "ng build --watch --configuration development",
|
||||||
"test": "ng test"
|
"test": "ng test",
|
||||||
|
"e2e": "playwright test",
|
||||||
|
"e2e:ui": "playwright test --ui",
|
||||||
|
"e2e:headed": "playwright test --headed",
|
||||||
|
"e2e:report": "playwright show-report"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -30,6 +34,7 @@
|
|||||||
"@angular-devkit/build-angular": "^17.0.0",
|
"@angular-devkit/build-angular": "^17.0.0",
|
||||||
"@angular/cli": "^17.0.0",
|
"@angular/cli": "^17.0.0",
|
||||||
"@angular/compiler-cli": "^17.0.0",
|
"@angular/compiler-cli": "^17.0.0",
|
||||||
|
"@playwright/test": "^1.59.1",
|
||||||
"typescript": "~5.2.2"
|
"typescript": "~5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
web/playwright.config.ts
Normal file
24
web/playwright.config.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { defineConfig, devices } from '@playwright/test';
|
||||||
|
|
||||||
|
const baseURL = process.env['E2E_BASE_URL'] || 'http://localhost:8081';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: './e2e/tests',
|
||||||
|
fullyParallel: true,
|
||||||
|
forbidOnly: !!process.env['CI'],
|
||||||
|
retries: process.env['CI'] ? 2 : 0,
|
||||||
|
workers: process.env['CI'] ? 1 : undefined,
|
||||||
|
reporter: process.env['CI'] ? [['html', { open: 'never' }], ['list']] : 'html',
|
||||||
|
use: {
|
||||||
|
baseURL,
|
||||||
|
trace: 'on-first-retry',
|
||||||
|
screenshot: 'only-on-failure',
|
||||||
|
video: 'retain-on-failure',
|
||||||
|
},
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'chromium',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
8
web/proxy.conf.json
Normal file
8
web/proxy.conf.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"/api": {
|
||||||
|
"target": "http://localhost:8080",
|
||||||
|
"secure": false,
|
||||||
|
"changeOrigin": true,
|
||||||
|
"logLevel": "warn"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
.main-content {
|
.main-content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 2rem;
|
// padding-top: 0 — sinon le contenu defile dans la zone de padding
|
||||||
|
// au-dessus du `.page-header` sticky (top: 0 pin sur l'edge interne du
|
||||||
|
// padding-box). Chaque page-wrapper definit deja son propre padding-top
|
||||||
|
// qui devient l'unique source d'espacement haut.
|
||||||
|
padding: 0 2rem 2rem;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
|
import { hiddenInDemoGuard } from './guards/demo-mode.guard';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{ path: 'lore', loadComponent: () => import('./lore/lore.component').then(m => m.LoreComponent) },
|
{ path: 'lore', loadComponent: () => import('./lore/lore.component').then(m => m.LoreComponent) },
|
||||||
@@ -30,6 +31,8 @@ export const routes: Routes = [
|
|||||||
{ path: 'game-systems', loadComponent: () => import('./game-systems/game-systems.component').then(m => m.GameSystemsComponent) },
|
{ path: 'game-systems', loadComponent: () => import('./game-systems/game-systems.component').then(m => m.GameSystemsComponent) },
|
||||||
{ path: 'game-systems/create', loadComponent: () => import('./game-systems/game-system-edit/game-system-edit.component').then(m => m.GameSystemEditComponent) },
|
{ path: 'game-systems/create', loadComponent: () => import('./game-systems/game-system-edit/game-system-edit.component').then(m => m.GameSystemEditComponent) },
|
||||||
{ path: 'game-systems/:id/edit', loadComponent: () => import('./game-systems/game-system-edit/game-system-edit.component').then(m => m.GameSystemEditComponent) },
|
{ path: 'game-systems/:id/edit', loadComponent: () => import('./game-systems/game-system-edit/game-system-edit.component').then(m => m.GameSystemEditComponent) },
|
||||||
{ path: 'settings', loadComponent: () => import('./settings/settings.component').then(m => m.SettingsComponent) },
|
// Routes masquees en mode demo : ajouter canActivate: [hiddenInDemoGuard]
|
||||||
|
// (a prevoir aussi sur la future route d'export VTT).
|
||||||
|
{ path: 'settings', canActivate: [hiddenInDemoGuard], loadComponent: () => import('./settings/settings.component').then(m => m.SettingsComponent) },
|
||||||
{ path: '', redirectTo: '/lore', pathMatch: 'full' }
|
{ path: '', redirectTo: '/lore', pathMatch: 'full' }
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
<form [formGroup]="form" (ngSubmit)="submit()" class="arc-form">
|
<form [formGroup]="form" (ngSubmit)="submit()" class="arc-form">
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Nom de l'arc *</label>
|
<label for="arc-create-name">Nom de l'arc *</label>
|
||||||
<input
|
<input
|
||||||
|
id="arc-create-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: L'Ombre du Nord"
|
placeholder="Ex: L'Ombre du Nord"
|
||||||
@@ -17,14 +18,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Description</label>
|
<label for="arc-create-description">Description</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="arc-create-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Décrivez l'arc narratif principal..."
|
placeholder="Décrivez l'arc narratif principal..."
|
||||||
rows="5">
|
rows="5">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Icône</label>
|
||||||
|
<app-icon-picker [options]="campaignIconOptions" [(selected)]="selectedIcon"></app-icon-picker>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
||||||
Créer l'arc
|
Créer l'arc
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { forkJoin } from 'rxjs';
|
import { forkJoin } from 'rxjs';
|
||||||
import { LucideAngularModule, BookOpen } from 'lucide-angular';
|
import { LucideAngularModule, BookOpen } from 'lucide-angular';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { Campaign } from '../../services/campaign.model';
|
import { Campaign } from '../../services/campaign.model';
|
||||||
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
||||||
|
import { IconPickerComponent } from '../../shared/icon-picker/icon-picker.component';
|
||||||
|
import { CAMPAIGN_ICON_OPTIONS } from '../campaign-icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Écran de création d'un nouvel Arc narratif (contexte Campagne).
|
* Écran de création d'un nouvel Arc narratif (contexte Campagne).
|
||||||
@@ -17,15 +20,17 @@ import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-arc-create',
|
selector: 'app-arc-create',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule],
|
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, IconPickerComponent],
|
||||||
templateUrl: './arc-create.component.html',
|
templateUrl: './arc-create.component.html',
|
||||||
styleUrls: ['./arc-create.component.scss']
|
styleUrls: ['./arc-create.component.scss']
|
||||||
})
|
})
|
||||||
export class ArcCreateComponent implements OnInit, OnDestroy {
|
export class ArcCreateComponent implements OnInit, OnDestroy {
|
||||||
readonly BookOpen = BookOpen;
|
readonly BookOpen = BookOpen;
|
||||||
|
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
|
||||||
|
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
campaignId = '';
|
campaignId = '';
|
||||||
|
selectedIcon: string | null = null;
|
||||||
private existingArcCount = 0;
|
private existingArcCount = 0;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -33,6 +38,7 @@ export class ArcCreateComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private layoutService: LayoutService
|
private layoutService: LayoutService
|
||||||
) {
|
) {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
@@ -50,7 +56,7 @@ export class ArcCreateComponent implements OnInit, OnDestroy {
|
|||||||
forkJoin({
|
forkJoin({
|
||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
||||||
this.existingArcCount = treeData.arcs.length;
|
this.existingArcCount = treeData.arcs.length;
|
||||||
|
|
||||||
@@ -78,7 +84,8 @@ export class ArcCreateComponent implements OnInit, OnDestroy {
|
|||||||
name: this.form.value.name,
|
name: this.form.value.name,
|
||||||
description: this.form.value.description,
|
description: this.form.value.description,
|
||||||
campaignId: this.campaignId,
|
campaignId: this.campaignId,
|
||||||
order: this.existingArcCount + 1
|
order: this.existingArcCount + 1,
|
||||||
|
icon: this.selectedIcon
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: (created) => this.router.navigate(['/campaigns', this.campaignId, 'arcs', created.id]),
|
next: (created) => this.router.navigate(['/campaigns', this.campaignId, 'arcs', created.id]),
|
||||||
error: () => console.error('Erreur lors de la création de l\'arc')
|
error: () => console.error('Erreur lors de la création de l\'arc')
|
||||||
|
|||||||
@@ -13,6 +13,14 @@
|
|||||||
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
||||||
Assistant IA
|
Assistant IA
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="btn-secondary" (click)="cancel()">Annuler</button>
|
||||||
|
<button type="button" class="btn-danger" (click)="delete()">
|
||||||
|
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn-primary" (click)="submit()" [disabled]="form.invalid">
|
||||||
|
Sauvegarder
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -43,8 +51,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Titre de l'arc *</label>
|
<label for="arc-edit-name">Titre de l'arc *</label>
|
||||||
<input
|
<input
|
||||||
|
id="arc-edit-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: L'Ombre du Nord"
|
placeholder="Ex: L'Ombre du Nord"
|
||||||
@@ -53,26 +62,34 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Synopsis de l'arc</label>
|
<label for="arc-edit-description">Synopsis de l'arc</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="arc-edit-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Décrivez l'histoire principale de cet arc narratif..."
|
placeholder="Décrivez l'histoire principale de cet arc narratif..."
|
||||||
rows="5">
|
rows="5">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Icône</label>
|
||||||
|
<app-icon-picker [options]="campaignIconOptions" [(selected)]="selectedIcon"></app-icon-picker>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="field-row">
|
<div class="field-row">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Thèmes principaux</label>
|
<label for="arc-edit-themes">Thèmes principaux</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="arc-edit-themes"
|
||||||
formControlName="themes"
|
formControlName="themes"
|
||||||
placeholder="Quels sont les thèmes explorés dans cet arc ? (trahison, rédemption...)"
|
placeholder="Quels sont les thèmes explorés dans cet arc ? (trahison, rédemption...)"
|
||||||
rows="4">
|
rows="4">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Enjeux globaux</label>
|
<label for="arc-edit-stakes">Enjeux globaux</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="arc-edit-stakes"
|
||||||
formControlName="stakes"
|
formControlName="stakes"
|
||||||
placeholder="Quels sont les enjeux majeurs de cet arc pour les personnages ?"
|
placeholder="Quels sont les enjeux majeurs de cet arc pour les personnages ?"
|
||||||
rows="4">
|
rows="4">
|
||||||
@@ -81,8 +98,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Notes et planification du MJ</label>
|
<label for="arc-edit-gm-notes">Notes et planification du MJ</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="arc-edit-gm-notes"
|
||||||
formControlName="gmNotes"
|
formControlName="gmNotes"
|
||||||
placeholder="Vos notes sur la direction de l'arc, les twists prévus, les révélations importantes..."
|
placeholder="Vos notes sur la direction de l'arc, les twists prévus, les révélations importantes..."
|
||||||
rows="5">
|
rows="5">
|
||||||
@@ -91,8 +109,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Récompenses et progression</label>
|
<label for="arc-edit-rewards">Récompenses et progression</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="arc-edit-rewards"
|
||||||
formControlName="rewards"
|
formControlName="rewards"
|
||||||
placeholder="Quelles récompenses les joueurs obtiendront-ils ? Objets, niveaux, connaissances, contacts..."
|
placeholder="Quelles récompenses les joueurs obtiendront-ils ? Objets, niveaux, connaissances, contacts..."
|
||||||
rows="4">
|
rows="4">
|
||||||
@@ -100,8 +119,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Dénouement prévu</label>
|
<label for="arc-edit-resolution">Dénouement prévu</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="arc-edit-resolution"
|
||||||
formControlName="resolution"
|
formControlName="resolution"
|
||||||
placeholder="Comment cet arc devrait-il se terminer ? Quelles sont les issues possibles ?"
|
placeholder="Comment cet arc devrait-il se terminer ? Quelles sont les issues possibles ?"
|
||||||
rows="4">
|
rows="4">
|
||||||
@@ -129,17 +149,6 @@
|
|||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
|
||||||
Sauvegarder
|
|
||||||
</button>
|
|
||||||
<button type="button" class="btn-secondary" (click)="cancel()">Annuler</button>
|
|
||||||
<button type="button" class="btn-danger" (click)="delete()">
|
|
||||||
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
|
|
||||||
Supprimer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { forkJoin, of } from 'rxjs';
|
|||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { LucideAngularModule, Trash2, Sparkles } from 'lucide-angular';
|
import { LucideAngularModule, Trash2, Sparkles } from 'lucide-angular';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { PageService } from '../../services/page.service';
|
import { PageService } from '../../services/page.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { PageTitleService } from '../../services/page-title.service';
|
import { PageTitleService } from '../../services/page-title.service';
|
||||||
@@ -15,6 +16,8 @@ import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper
|
|||||||
import { LoreLinkPickerComponent } from '../../shared/lore-link-picker/lore-link-picker.component';
|
import { LoreLinkPickerComponent } from '../../shared/lore-link-picker/lore-link-picker.component';
|
||||||
import { AiChatDrawerComponent } from '../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
import { AiChatDrawerComponent } from '../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
||||||
import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.component';
|
import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.component';
|
||||||
|
import { IconPickerComponent } from '../../shared/icon-picker/icon-picker.component';
|
||||||
|
import { CAMPAIGN_ICON_OPTIONS } from '../campaign-icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Écran de détail/modification d'un Arc.
|
* Écran de détail/modification d'un Arc.
|
||||||
@@ -28,13 +31,15 @@ import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-arc-edit',
|
selector: 'app-arc-edit',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, LoreLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent],
|
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, LoreLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent, IconPickerComponent],
|
||||||
templateUrl: './arc-edit.component.html',
|
templateUrl: './arc-edit.component.html',
|
||||||
styleUrls: ['./arc-edit.component.scss']
|
styleUrls: ['./arc-edit.component.scss']
|
||||||
})
|
})
|
||||||
export class ArcEditComponent implements OnInit, OnDestroy {
|
export class ArcEditComponent implements OnInit, OnDestroy {
|
||||||
readonly Trash2 = Trash2;
|
readonly Trash2 = Trash2;
|
||||||
readonly Sparkles = Sparkles;
|
readonly Sparkles = Sparkles;
|
||||||
|
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
|
||||||
|
selectedIcon: string | null = null;
|
||||||
|
|
||||||
/** État drawer chat IA (b5.7 — intégration Campagne). */
|
/** État drawer chat IA (b5.7 — intégration Campagne). */
|
||||||
chatOpen = false;
|
chatOpen = false;
|
||||||
@@ -68,6 +73,7 @@ export class ArcEditComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private pageService: PageService,
|
private pageService: PageService,
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private pageTitleService: PageTitleService
|
private pageTitleService: PageTitleService
|
||||||
@@ -105,7 +111,7 @@ export class ArcEditComponent implements OnInit, OnDestroy {
|
|||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
arc: this.campaignService.getArcById(this.arcId),
|
arc: this.campaignService.getArcById(this.arcId),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
switchMap(data => {
|
switchMap(data => {
|
||||||
const lid = data.campaign.loreId ?? null;
|
const lid = data.campaign.loreId ?? null;
|
||||||
@@ -120,6 +126,7 @@ export class ArcEditComponent implements OnInit, OnDestroy {
|
|||||||
this.loreId = loreId;
|
this.loreId = loreId;
|
||||||
this.availablePages = pages;
|
this.availablePages = pages;
|
||||||
this.relatedPageIds = [...(arc.relatedPageIds ?? [])];
|
this.relatedPageIds = [...(arc.relatedPageIds ?? [])];
|
||||||
|
this.selectedIcon = arc.icon ?? null;
|
||||||
this.illustrationImageIds = [...(arc.illustrationImageIds ?? [])];
|
this.illustrationImageIds = [...(arc.illustrationImageIds ?? [])];
|
||||||
this.mapImageIds = [...(arc.mapImageIds ?? [])];
|
this.mapImageIds = [...(arc.mapImageIds ?? [])];
|
||||||
this.pageTitleService.set(arc.name);
|
this.pageTitleService.set(arc.name);
|
||||||
@@ -165,7 +172,8 @@ export class ArcEditComponent implements OnInit, OnDestroy {
|
|||||||
resolution: this.form.value.resolution,
|
resolution: this.form.value.resolution,
|
||||||
relatedPageIds: this.relatedPageIds,
|
relatedPageIds: this.relatedPageIds,
|
||||||
illustrationImageIds: this.illustrationImageIds,
|
illustrationImageIds: this.illustrationImageIds,
|
||||||
mapImageIds: this.mapImageIds
|
mapImageIds: this.mapImageIds,
|
||||||
|
icon: this.selectedIcon
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: () => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId]),
|
next: () => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId]),
|
||||||
error: () => console.error('Erreur lors de la sauvegarde')
|
error: () => console.error('Erreur lors de la sauvegarde')
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
<header class="view-header">
|
<header class="view-header">
|
||||||
<div>
|
<div>
|
||||||
<h1>{{ arc.name }}</h1>
|
<h1>
|
||||||
|
<lucide-icon *ngIf="arc.icon" [img]="resolveCampaignIcon(arc.icon)" [size]="22" class="title-icon"></lucide-icon>
|
||||||
|
{{ arc.name }}
|
||||||
|
</h1>
|
||||||
<p class="view-subtitle">Arc narratif</p>
|
<p class="view-subtitle">Arc narratif</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="view-actions">
|
<div class="view-actions">
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
|||||||
import { forkJoin, of } from 'rxjs';
|
import { forkJoin, of } from 'rxjs';
|
||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { LucideAngularModule, Pencil, Trash2 } from 'lucide-angular';
|
import { LucideAngularModule, Pencil, Trash2 } from 'lucide-angular';
|
||||||
|
import { resolveCampaignIcon } from '../campaign-icons';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { PageService } from '../../services/page.service';
|
import { PageService } from '../../services/page.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { PageTitleService } from '../../services/page-title.service';
|
import { PageTitleService } from '../../services/page-title.service';
|
||||||
@@ -28,6 +30,7 @@ import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.
|
|||||||
export class ArcViewComponent implements OnInit, OnDestroy {
|
export class ArcViewComponent implements OnInit, OnDestroy {
|
||||||
readonly Pencil = Pencil;
|
readonly Pencil = Pencil;
|
||||||
readonly Trash2 = Trash2;
|
readonly Trash2 = Trash2;
|
||||||
|
readonly resolveCampaignIcon = resolveCampaignIcon;
|
||||||
|
|
||||||
campaignId = '';
|
campaignId = '';
|
||||||
arcId = '';
|
arcId = '';
|
||||||
@@ -42,6 +45,7 @@ export class ArcViewComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private pageService: PageService,
|
private pageService: PageService,
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private pageTitleService: PageTitleService
|
private pageTitleService: PageTitleService
|
||||||
@@ -64,7 +68,7 @@ export class ArcViewComponent implements OnInit, OnDestroy {
|
|||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
arc: this.campaignService.getArcById(this.arcId),
|
arc: this.campaignService.getArcById(this.arcId),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
switchMap(data => {
|
switchMap(data => {
|
||||||
const lid = data.campaign.loreId ?? null;
|
const lid = data.campaign.loreId ?? null;
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
<form [formGroup]="form" (ngSubmit)="submit()">
|
<form [formGroup]="form" (ngSubmit)="submit()">
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Nom de la campagne *</label>
|
<label for="campaign-name">Nom de la campagne *</label>
|
||||||
<input
|
<input
|
||||||
|
id="campaign-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: L'Ombre du Nord, Les Héritiers Oubliés..."
|
placeholder="Ex: L'Ombre du Nord, Les Héritiers Oubliés..."
|
||||||
@@ -21,8 +22,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Description / Pitch</label>
|
<label for="campaign-description">Description / Pitch</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="campaign-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Résumez l'intrigue principale de votre campagne..."
|
placeholder="Résumez l'intrigue principale de votre campagne..."
|
||||||
rows="5"
|
rows="5"
|
||||||
@@ -30,13 +32,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Nombre de joueurs</label>
|
<label for="campaign-player-count">Nombre de joueurs</label>
|
||||||
<input type="number" formControlName="playerCount" min="1" />
|
<input id="campaign-player-count" type="number" formControlName="playerCount" min="1" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Univers associé</label>
|
<label for="campaign-lore">Univers associé</label>
|
||||||
<select formControlName="loreId">
|
<select id="campaign-lore" formControlName="loreId">
|
||||||
<option value="">— Aucun univers (campagne libre) —</option>
|
<option value="">— Aucun univers (campagne libre) —</option>
|
||||||
<option *ngFor="let lore of availableLores" [value]="lore.id">{{ lore.name }}</option>
|
<option *ngFor="let lore of availableLores" [value]="lore.id">{{ lore.name }}</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -47,8 +49,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Système de JDR</label>
|
<label for="campaign-game-system">Système de JDR</label>
|
||||||
<select formControlName="gameSystemId">
|
<select id="campaign-game-system" formControlName="gameSystemId">
|
||||||
<option value="">— Aucun (campagne générique) —</option>
|
<option value="">— Aucun (campagne générique) —</option>
|
||||||
<option *ngFor="let gs of availableGameSystems" [value]="gs.id">{{ gs.name }}</option>
|
<option *ngFor="let gs of availableGameSystems" [value]="gs.id">{{ gs.name }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="detail-section characters-section">
|
<section class="detail-section characters-section" *ngIf="!editing">
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<h2>Personnages joueurs</h2>
|
<h2>Personnages joueurs</h2>
|
||||||
<button class="btn-add" (click)="createCharacter()">
|
<button class="btn-add" (click)="createCharacter()">
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="detail-section arcs-section">
|
<section class="detail-section arcs-section" *ngIf="!editing">
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<h2>Arcs narratifs</h2>
|
<h2>Arcs narratifs</h2>
|
||||||
<button class="btn-add" (click)="createArc()">
|
<button class="btn-add" (click)="createArc()">
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ export class CampaignDetailComponent implements OnInit, OnDestroy {
|
|||||||
switchMap(id => forkJoin({
|
switchMap(id => forkJoin({
|
||||||
campaign: this.campaignService.getCampaignById(id),
|
campaign: this.campaignService.getCampaignById(id),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, id).pipe(
|
treeData: loadCampaignTreeData(this.campaignService, id, this.characterService).pipe(
|
||||||
catchError(() => of({ arcs: [], chaptersByArc: {}, scenesByChapter: {} } as CampaignTreeData))
|
catchError(() => of({ arcs: [], chaptersByArc: {}, scenesByChapter: {}, characters: [] } as CampaignTreeData))
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
).subscribe(({ campaign, allCampaigns, treeData }) => {
|
).subscribe(({ campaign, allCampaigns, treeData }) => {
|
||||||
@@ -111,8 +111,8 @@ export class CampaignDetailComponent implements OnInit, OnDestroy {
|
|||||||
forkJoin({
|
forkJoin({
|
||||||
campaign: this.campaignService.getCampaignById(id),
|
campaign: this.campaignService.getCampaignById(id),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, id).pipe(
|
treeData: loadCampaignTreeData(this.campaignService, id, this.characterService).pipe(
|
||||||
catchError(() => of({ arcs: [], chaptersByArc: {}, scenesByChapter: {} } as CampaignTreeData))
|
catchError(() => of({ arcs: [], chaptersByArc: {}, scenesByChapter: {}, characters: [] } as CampaignTreeData))
|
||||||
)
|
)
|
||||||
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
||||||
this.campaign = campaign;
|
this.campaign = campaign;
|
||||||
|
|||||||
66
web/src/app/campaigns/campaign-icons.ts
Normal file
66
web/src/app/campaigns/campaign-icons.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import {
|
||||||
|
Bookmark,
|
||||||
|
Theater, Drama, Compass, Flag, Calendar, Map, Castle, Tent,
|
||||||
|
Swords, Skull, Crown, Heart, Eye, Footprints, Dice5, Hourglass,
|
||||||
|
Flame, Snowflake, Cloud, Sun, Moon, Star, Zap, Target,
|
||||||
|
Music, MessageCircle, Lock, Key as KeyIcon, Coins, Gift,
|
||||||
|
LucideIconData
|
||||||
|
} from 'lucide-angular';
|
||||||
|
|
||||||
|
// Type local equivalent a IconOption de lore-icons. Duplique volontairement
|
||||||
|
// pour eviter une dependance circulaire (lore-icons importe ce fichier).
|
||||||
|
export interface CampaignIconOption {
|
||||||
|
key: string;
|
||||||
|
icon: LucideIconData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Banque d'icones dediee aux entites narratives d'une campagne (arc, chapitre, scene).
|
||||||
|
*
|
||||||
|
* Pourquoi separe de LORE_ICON_OPTIONS ? Les icones lore sont plutot orientees
|
||||||
|
* "objets de monde" (chateau, foret, dragon...). Ici on est sur du sequencement
|
||||||
|
* narratif et de la mise en scene : ambiances, actes, decisions. Cles uniques
|
||||||
|
* (prefixees `c-` quand un nom existerait deja dans le lore) pour eviter les
|
||||||
|
* collisions avec LORE_ICON_OPTIONS — le resolver consulte les deux registres.
|
||||||
|
*/
|
||||||
|
export const CAMPAIGN_ICON_OPTIONS: CampaignIconOption[] = [
|
||||||
|
{ key: 'c-theater', icon: Theater },
|
||||||
|
{ key: 'c-drama', icon: Drama },
|
||||||
|
{ key: 'c-compass', icon: Compass },
|
||||||
|
{ key: 'c-flag', icon: Flag },
|
||||||
|
{ key: 'c-calendar', icon: Calendar },
|
||||||
|
{ key: 'c-map', icon: Map },
|
||||||
|
{ key: 'c-castle', icon: Castle },
|
||||||
|
{ key: 'c-tent', icon: Tent },
|
||||||
|
{ key: 'c-swords', icon: Swords },
|
||||||
|
{ key: 'c-skull', icon: Skull },
|
||||||
|
{ key: 'c-crown', icon: Crown },
|
||||||
|
{ key: 'c-heart', icon: Heart },
|
||||||
|
{ key: 'c-eye', icon: Eye },
|
||||||
|
{ key: 'c-footprints', icon: Footprints },
|
||||||
|
{ key: 'c-dice', icon: Dice5 },
|
||||||
|
{ key: 'c-hourglass', icon: Hourglass },
|
||||||
|
{ key: 'c-flame', icon: Flame },
|
||||||
|
{ key: 'c-snowflake', icon: Snowflake },
|
||||||
|
{ key: 'c-cloud', icon: Cloud },
|
||||||
|
{ key: 'c-sun', icon: Sun },
|
||||||
|
{ key: 'c-moon', icon: Moon },
|
||||||
|
{ key: 'c-star', icon: Star },
|
||||||
|
{ key: 'c-zap', icon: Zap },
|
||||||
|
{ key: 'c-target', icon: Target },
|
||||||
|
{ key: 'c-music', icon: Music },
|
||||||
|
{ key: 'c-message', icon: MessageCircle },
|
||||||
|
{ key: 'c-lock', icon: Lock },
|
||||||
|
{ key: 'c-key', icon: KeyIcon },
|
||||||
|
{ key: 'c-coins', icon: Coins },
|
||||||
|
{ key: 'c-gift', icon: Gift },
|
||||||
|
];
|
||||||
|
|
||||||
|
/** Icone par defaut quand une entite narrative n'en a pas. */
|
||||||
|
export const DEFAULT_CAMPAIGN_ICON: LucideIconData = Bookmark;
|
||||||
|
|
||||||
|
/** Resolveur dedie. Prefere passer par `resolveIcon` dans lore-icons qui consulte les deux. */
|
||||||
|
export function resolveCampaignIcon(key: string | null | undefined): LucideIconData {
|
||||||
|
if (!key) return DEFAULT_CAMPAIGN_ICON;
|
||||||
|
return CAMPAIGN_ICON_OPTIONS.find(o => o.key === key)?.icon ?? DEFAULT_CAMPAIGN_ICON;
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import { Observable, forkJoin, of } from 'rxjs';
|
import { Observable, forkJoin, of } from 'rxjs';
|
||||||
import { switchMap, map } from 'rxjs/operators';
|
import { switchMap, map } from 'rxjs/operators';
|
||||||
import { CampaignService } from '../services/campaign.service';
|
import { CampaignService } from '../services/campaign.service';
|
||||||
|
import { CharacterService } from '../services/character.service';
|
||||||
import { TreeItem } from '../services/layout.service';
|
import { TreeItem } from '../services/layout.service';
|
||||||
import { Arc, Chapter, Scene } from '../services/campaign.model';
|
import { Arc, Chapter, Scene } from '../services/campaign.model';
|
||||||
|
import { Character } from '../services/character.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper — charge l'arborescence complète d'une campagne (arcs -> chapitres -> scènes)
|
* Helper — charge l'arborescence complète d'une campagne (arcs -> chapitres -> scènes)
|
||||||
@@ -16,16 +18,21 @@ export interface CampaignTreeData {
|
|||||||
arcs: Arc[];
|
arcs: Arc[];
|
||||||
chaptersByArc: Record<string, Chapter[]>;
|
chaptersByArc: Record<string, Chapter[]>;
|
||||||
scenesByChapter: Record<string, Scene[]>;
|
scenesByChapter: Record<string, Scene[]>;
|
||||||
|
characters: Character[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadCampaignTreeData(
|
export function loadCampaignTreeData(
|
||||||
service: CampaignService,
|
service: CampaignService,
|
||||||
campaignId: string
|
campaignId: string,
|
||||||
|
characterService: CharacterService
|
||||||
): Observable<CampaignTreeData> {
|
): Observable<CampaignTreeData> {
|
||||||
return service.getArcs(campaignId).pipe(
|
return forkJoin({
|
||||||
switchMap(arcs => {
|
arcs: service.getArcs(campaignId),
|
||||||
|
characters: characterService.getByCampaign(campaignId)
|
||||||
|
}).pipe(
|
||||||
|
switchMap(({ arcs, characters }) => {
|
||||||
if (arcs.length === 0) {
|
if (arcs.length === 0) {
|
||||||
return of({ arcs, chaptersByArc: {}, scenesByChapter: {} });
|
return of({ arcs, chaptersByArc: {}, scenesByChapter: {}, characters });
|
||||||
}
|
}
|
||||||
const chapterCalls = arcs.map(a =>
|
const chapterCalls = arcs.map(a =>
|
||||||
service.getChapters(a.id!).pipe(map(chapters => ({ arcId: a.id!, chapters })))
|
service.getChapters(a.id!).pipe(map(chapters => ({ arcId: a.id!, chapters })))
|
||||||
@@ -40,7 +47,7 @@ export function loadCampaignTreeData(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (allChapters.length === 0) {
|
if (allChapters.length === 0) {
|
||||||
return of({ arcs, chaptersByArc, scenesByChapter: {} });
|
return of({ arcs, chaptersByArc, scenesByChapter: {}, characters });
|
||||||
}
|
}
|
||||||
const sceneCalls = allChapters.map(c =>
|
const sceneCalls = allChapters.map(c =>
|
||||||
service.getScenes(c.id!).pipe(map(scenes => ({ chapterId: c.id!, scenes })))
|
service.getScenes(c.id!).pipe(map(scenes => ({ chapterId: c.id!, scenes })))
|
||||||
@@ -49,7 +56,7 @@ export function loadCampaignTreeData(
|
|||||||
map(sceneResults => {
|
map(sceneResults => {
|
||||||
const scenesByChapter: Record<string, Scene[]> = {};
|
const scenesByChapter: Record<string, Scene[]> = {};
|
||||||
sceneResults.forEach(r => { scenesByChapter[r.chapterId] = r.scenes; });
|
sceneResults.forEach(r => { scenesByChapter[r.chapterId] = r.scenes; });
|
||||||
return { arcs, chaptersByArc, scenesByChapter };
|
return { arcs, chaptersByArc, scenesByChapter, characters };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@@ -67,9 +74,33 @@ export function buildCampaignTree(campaignId: string, data: CampaignTreeData): T
|
|||||||
// IDs préfixés par type pour éviter les collisions dans LayoutService.expanded
|
// IDs préfixés par type pour éviter les collisions dans LayoutService.expanded
|
||||||
// (chaque entité a sa propre séquence IDENTITY en base → arc.id=1 et chapter.id=1
|
// (chaque entité a sa propre séquence IDENTITY en base → arc.id=1 et chapter.id=1
|
||||||
// peuvent coexister et se marchaient sur les pieds dans le Set<string> global).
|
// peuvent coexister et se marchaient sur les pieds dans le Set<string> global).
|
||||||
|
const sortedCharacters = [...data.characters].sort(byName);
|
||||||
|
const characterItems: TreeItem[] = sortedCharacters.map(ch => ({
|
||||||
|
id: `character-${ch.id}`,
|
||||||
|
label: ch.name,
|
||||||
|
route: `/campaigns/${campaignId}/characters/${ch.id}/edit`
|
||||||
|
}));
|
||||||
|
|
||||||
|
const charactersNode: TreeItem = {
|
||||||
|
id: 'characters-root',
|
||||||
|
label: 'Personnages',
|
||||||
|
iconKey: 'users',
|
||||||
|
children: characterItems,
|
||||||
|
meta: characterItems.length ? String(characterItems.length) : undefined,
|
||||||
|
sectionHeaderBefore: 'Personnages',
|
||||||
|
// Note : si pas d'arcs, le filet au-dessus de "Personnages" est masqué par CSS
|
||||||
|
// (:first-child), ce qui est voulu — on ne veut pas de ligne seule en haut.
|
||||||
|
createActions: [{
|
||||||
|
id: 'new-character',
|
||||||
|
label: 'Nouveau PJ',
|
||||||
|
route: `/campaigns/${campaignId}/characters/create`,
|
||||||
|
actionIcon: 'plus'
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
const sortedArcs = [...data.arcs].sort(byName);
|
const sortedArcs = [...data.arcs].sort(byName);
|
||||||
|
|
||||||
return sortedArcs.map(arc => {
|
const arcNodes: TreeItem[] = sortedArcs.map((arc, idx) => {
|
||||||
const sortedChapters = [...(data.chaptersByArc[arc.id!] ?? [])].sort(byName);
|
const sortedChapters = [...(data.chaptersByArc[arc.id!] ?? [])].sort(byName);
|
||||||
|
|
||||||
const chapterItems: TreeItem[] = sortedChapters.map(ch => {
|
const chapterItems: TreeItem[] = sortedChapters.map(ch => {
|
||||||
@@ -78,11 +109,13 @@ export function buildCampaignTree(campaignId: string, data: CampaignTreeData): T
|
|||||||
const sceneItems: TreeItem[] = sortedScenes.map(sc => ({
|
const sceneItems: TreeItem[] = sortedScenes.map(sc => ({
|
||||||
id: `scene-${sc.id}`,
|
id: `scene-${sc.id}`,
|
||||||
label: sc.name,
|
label: sc.name,
|
||||||
|
iconKey: sc.icon ?? undefined,
|
||||||
route: `/campaigns/${campaignId}/arcs/${arc.id}/chapters/${ch.id}/scenes/${sc.id}`
|
route: `/campaigns/${campaignId}/arcs/${arc.id}/chapters/${ch.id}/scenes/${sc.id}`
|
||||||
}));
|
}));
|
||||||
return {
|
return {
|
||||||
id: `chapter-${ch.id}`,
|
id: `chapter-${ch.id}`,
|
||||||
label: ch.name,
|
label: ch.name,
|
||||||
|
iconKey: ch.icon ?? undefined,
|
||||||
children: sceneItems,
|
children: sceneItems,
|
||||||
route: `/campaigns/${campaignId}/arcs/${arc.id}/chapters/${ch.id}`,
|
route: `/campaigns/${campaignId}/arcs/${arc.id}/chapters/${ch.id}`,
|
||||||
createActions: [{
|
createActions: [{
|
||||||
@@ -96,8 +129,11 @@ export function buildCampaignTree(campaignId: string, data: CampaignTreeData): T
|
|||||||
return {
|
return {
|
||||||
id: `arc-${arc.id}`,
|
id: `arc-${arc.id}`,
|
||||||
label: arc.name,
|
label: arc.name,
|
||||||
|
iconKey: arc.icon ?? undefined,
|
||||||
children: chapterItems,
|
children: chapterItems,
|
||||||
route: `/campaigns/${campaignId}/arcs/${arc.id}`,
|
route: `/campaigns/${campaignId}/arcs/${arc.id}`,
|
||||||
|
sectionHeaderBefore: idx === 0 ? 'Narration' : undefined,
|
||||||
|
|
||||||
createActions: [{
|
createActions: [{
|
||||||
id: `new-chapter-${arc.id}`,
|
id: `new-chapter-${arc.id}`,
|
||||||
label: 'Nouveau chapitre',
|
label: 'Nouveau chapitre',
|
||||||
@@ -106,4 +142,6 @@ export function buildCampaignTree(campaignId: string, data: CampaignTreeData): T
|
|||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return [...arcNodes, charactersNode];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
<form [formGroup]="form" (ngSubmit)="submit()" class="chapter-form">
|
<form [formGroup]="form" (ngSubmit)="submit()" class="chapter-form">
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Nom du chapitre *</label>
|
<label for="chapter-create-name">Nom du chapitre *</label>
|
||||||
<input
|
<input
|
||||||
|
id="chapter-create-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: Chapitre 1: Les Disparitions"
|
placeholder="Ex: Chapitre 1: Les Disparitions"
|
||||||
@@ -18,14 +19,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Description</label>
|
<label for="chapter-create-description">Description</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="chapter-create-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Décrivez ce chapitre..."
|
placeholder="Décrivez ce chapitre..."
|
||||||
rows="5">
|
rows="5">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Icône</label>
|
||||||
|
<app-icon-picker [options]="campaignIconOptions" [(selected)]="selectedIcon"></app-icon-picker>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
||||||
Créer le chapitre
|
Créer le chapitre
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { forkJoin } from 'rxjs';
|
import { forkJoin } from 'rxjs';
|
||||||
import { LucideAngularModule } from 'lucide-angular';
|
import { LucideAngularModule } from 'lucide-angular';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { Campaign } from '../../services/campaign.model';
|
import { Campaign } from '../../services/campaign.model';
|
||||||
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
||||||
|
import { IconPickerComponent } from '../../shared/icon-picker/icon-picker.component';
|
||||||
|
import { CAMPAIGN_ICON_OPTIONS } from '../campaign-icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Écran de création d'un nouveau chapitre rattaché à un arc.
|
* Écran de création d'un nouveau chapitre rattaché à un arc.
|
||||||
@@ -16,11 +19,14 @@ import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-chapter-create',
|
selector: 'app-chapter-create',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule],
|
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, IconPickerComponent],
|
||||||
templateUrl: './chapter-create.component.html',
|
templateUrl: './chapter-create.component.html',
|
||||||
styleUrls: ['./chapter-create.component.scss']
|
styleUrls: ['./chapter-create.component.scss']
|
||||||
})
|
})
|
||||||
export class ChapterCreateComponent implements OnInit, OnDestroy {
|
export class ChapterCreateComponent implements OnInit, OnDestroy {
|
||||||
|
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
|
||||||
|
selectedIcon: string | null = null;
|
||||||
|
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
campaignId = '';
|
campaignId = '';
|
||||||
arcId = '';
|
arcId = '';
|
||||||
@@ -32,6 +38,7 @@ export class ChapterCreateComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private layoutService: LayoutService
|
private layoutService: LayoutService
|
||||||
) {
|
) {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
@@ -50,7 +57,7 @@ export class ChapterCreateComponent implements OnInit, OnDestroy {
|
|||||||
forkJoin({
|
forkJoin({
|
||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
||||||
const currentArc = treeData.arcs.find(a => a.id === this.arcId);
|
const currentArc = treeData.arcs.find(a => a.id === this.arcId);
|
||||||
this.arcName = currentArc?.name ?? '';
|
this.arcName = currentArc?.name ?? '';
|
||||||
@@ -80,7 +87,8 @@ export class ChapterCreateComponent implements OnInit, OnDestroy {
|
|||||||
name: this.form.value.name,
|
name: this.form.value.name,
|
||||||
description: this.form.value.description,
|
description: this.form.value.description,
|
||||||
arcId: this.arcId,
|
arcId: this.arcId,
|
||||||
order: this.existingChapterCount + 1
|
order: this.existingChapterCount + 1,
|
||||||
|
icon: this.selectedIcon
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: (created) => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', created.id]),
|
next: (created) => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', created.id]),
|
||||||
error: () => console.error('Erreur lors de la création du chapitre')
|
error: () => console.error('Erreur lors de la création du chapitre')
|
||||||
|
|||||||
@@ -13,6 +13,14 @@
|
|||||||
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
||||||
Assistant IA
|
Assistant IA
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="btn-secondary" (click)="cancel()">Annuler</button>
|
||||||
|
<button type="button" class="btn-danger" (click)="delete()">
|
||||||
|
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn-primary" (click)="submit()" [disabled]="form.invalid">
|
||||||
|
Sauvegarder
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -43,8 +51,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Titre du chapitre *</label>
|
<label for="chapter-edit-name">Titre du chapitre *</label>
|
||||||
<input
|
<input
|
||||||
|
id="chapter-edit-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: Chapitre 1: Les Disparitions"
|
placeholder="Ex: Chapitre 1: Les Disparitions"
|
||||||
@@ -53,8 +62,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Synopsis du chapitre</label>
|
<label for="chapter-edit-description">Synopsis du chapitre</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="chapter-edit-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Décrivez brièvement ce qui se passe dans ce chapitre..."
|
placeholder="Décrivez brièvement ce qui se passe dans ce chapitre..."
|
||||||
rows="5">
|
rows="5">
|
||||||
@@ -62,8 +72,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Notes du Maître de Jeu</label>
|
<label>Icône</label>
|
||||||
|
<app-icon-picker [options]="campaignIconOptions" [(selected)]="selectedIcon"></app-icon-picker>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label for="chapter-edit-gm-notes">Notes du Maître de Jeu</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="chapter-edit-gm-notes"
|
||||||
formControlName="gmNotes"
|
formControlName="gmNotes"
|
||||||
placeholder="Vos notes privées sur le déroulement du chapitre, les événements clés, les rebondissements..."
|
placeholder="Vos notes privées sur le déroulement du chapitre, les événements clés, les rebondissements..."
|
||||||
rows="6">
|
rows="6">
|
||||||
@@ -73,16 +89,18 @@
|
|||||||
|
|
||||||
<div class="field-row">
|
<div class="field-row">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Objectifs des joueurs</label>
|
<label for="chapter-edit-player-objectives">Objectifs des joueurs</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="chapter-edit-player-objectives"
|
||||||
formControlName="playerObjectives"
|
formControlName="playerObjectives"
|
||||||
placeholder="Que doivent accomplir les joueurs dans ce chapitre ?"
|
placeholder="Que doivent accomplir les joueurs dans ce chapitre ?"
|
||||||
rows="4">
|
rows="4">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Enjeux narratifs</label>
|
<label for="chapter-edit-narrative-stakes">Enjeux narratifs</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="chapter-edit-narrative-stakes"
|
||||||
formControlName="narrativeStakes"
|
formControlName="narrativeStakes"
|
||||||
placeholder="Quels sont les enjeux dramatiques ?"
|
placeholder="Quels sont les enjeux dramatiques ?"
|
||||||
rows="4">
|
rows="4">
|
||||||
@@ -111,17 +129,6 @@
|
|||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
|
||||||
Sauvegarder
|
|
||||||
</button>
|
|
||||||
<button type="button" class="btn-secondary" (click)="cancel()">Annuler</button>
|
|
||||||
<button type="button" class="btn-danger" (click)="delete()">
|
|
||||||
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
|
|
||||||
Supprimer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { forkJoin, of } from 'rxjs';
|
|||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { LucideAngularModule, Trash2, Sparkles } from 'lucide-angular';
|
import { LucideAngularModule, Trash2, Sparkles } from 'lucide-angular';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { PageService } from '../../services/page.service';
|
import { PageService } from '../../services/page.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { PageTitleService } from '../../services/page-title.service';
|
import { PageTitleService } from '../../services/page-title.service';
|
||||||
@@ -15,6 +16,8 @@ import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper
|
|||||||
import { LoreLinkPickerComponent } from '../../shared/lore-link-picker/lore-link-picker.component';
|
import { LoreLinkPickerComponent } from '../../shared/lore-link-picker/lore-link-picker.component';
|
||||||
import { AiChatDrawerComponent } from '../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
import { AiChatDrawerComponent } from '../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
||||||
import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.component';
|
import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.component';
|
||||||
|
import { IconPickerComponent } from '../../shared/icon-picker/icon-picker.component';
|
||||||
|
import { CAMPAIGN_ICON_OPTIONS } from '../campaign-icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Écran de détail/modification d'un Chapitre.
|
* Écran de détail/modification d'un Chapitre.
|
||||||
@@ -26,13 +29,15 @@ import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-chapter-edit',
|
selector: 'app-chapter-edit',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, LoreLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent],
|
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, LoreLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent, IconPickerComponent],
|
||||||
templateUrl: './chapter-edit.component.html',
|
templateUrl: './chapter-edit.component.html',
|
||||||
styleUrls: ['./chapter-edit.component.scss']
|
styleUrls: ['./chapter-edit.component.scss']
|
||||||
})
|
})
|
||||||
export class ChapterEditComponent implements OnInit, OnDestroy {
|
export class ChapterEditComponent implements OnInit, OnDestroy {
|
||||||
readonly Trash2 = Trash2;
|
readonly Trash2 = Trash2;
|
||||||
readonly Sparkles = Sparkles;
|
readonly Sparkles = Sparkles;
|
||||||
|
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
|
||||||
|
selectedIcon: string | null = null;
|
||||||
|
|
||||||
/** État drawer chat IA (b5.7 — intégration Campagne). */
|
/** État drawer chat IA (b5.7 — intégration Campagne). */
|
||||||
chatOpen = false;
|
chatOpen = false;
|
||||||
@@ -61,6 +66,7 @@ export class ChapterEditComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private pageService: PageService,
|
private pageService: PageService,
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private pageTitleService: PageTitleService
|
private pageTitleService: PageTitleService
|
||||||
@@ -98,7 +104,7 @@ export class ChapterEditComponent implements OnInit, OnDestroy {
|
|||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
chapter: this.campaignService.getChapterById(this.chapterId),
|
chapter: this.campaignService.getChapterById(this.chapterId),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
switchMap(data => {
|
switchMap(data => {
|
||||||
const lid = data.campaign.loreId ?? null;
|
const lid = data.campaign.loreId ?? null;
|
||||||
@@ -111,6 +117,7 @@ export class ChapterEditComponent implements OnInit, OnDestroy {
|
|||||||
this.loreId = loreId;
|
this.loreId = loreId;
|
||||||
this.availablePages = pages;
|
this.availablePages = pages;
|
||||||
this.relatedPageIds = [...(chapter.relatedPageIds ?? [])];
|
this.relatedPageIds = [...(chapter.relatedPageIds ?? [])];
|
||||||
|
this.selectedIcon = chapter.icon ?? null;
|
||||||
this.illustrationImageIds = [...(chapter.illustrationImageIds ?? [])];
|
this.illustrationImageIds = [...(chapter.illustrationImageIds ?? [])];
|
||||||
this.mapImageIds = [...(chapter.mapImageIds ?? [])];
|
this.mapImageIds = [...(chapter.mapImageIds ?? [])];
|
||||||
this.form.patchValue({
|
this.form.patchValue({
|
||||||
@@ -151,7 +158,8 @@ export class ChapterEditComponent implements OnInit, OnDestroy {
|
|||||||
narrativeStakes: this.form.value.narrativeStakes,
|
narrativeStakes: this.form.value.narrativeStakes,
|
||||||
relatedPageIds: this.relatedPageIds,
|
relatedPageIds: this.relatedPageIds,
|
||||||
illustrationImageIds: this.illustrationImageIds,
|
illustrationImageIds: this.illustrationImageIds,
|
||||||
mapImageIds: this.mapImageIds
|
mapImageIds: this.mapImageIds,
|
||||||
|
icon: this.selectedIcon
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: () => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId]),
|
next: () => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId]),
|
||||||
error: () => console.error('Erreur lors de la sauvegarde')
|
error: () => console.error('Erreur lors de la sauvegarde')
|
||||||
|
|||||||
@@ -16,11 +16,16 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="graph-container" *ngIf="scenes.length > 0">
|
<div class="graph-container" *ngIf="scenes.length > 0">
|
||||||
<svg [attr.width]="svgWidth" [attr.height]="svgHeight" class="graph-svg">
|
<svg #svgEl
|
||||||
|
[attr.width]="svgWidth" [attr.height]="svgHeight"
|
||||||
|
class="graph-svg"
|
||||||
|
(pointermove)="onPointerMove($event)"
|
||||||
|
(pointerup)="onPointerUp($event)"
|
||||||
|
(pointercancel)="onPointerUp($event)">
|
||||||
<defs>
|
<defs>
|
||||||
<marker id="arrowhead" viewBox="0 0 10 10" refX="9" refY="5"
|
<marker id="arrowhead" viewBox="0 0 10 10" refX="9" refY="5"
|
||||||
markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||||
<path d="M 0 0 L 10 5 L 0 10 z" fill="#6b7280" />
|
<path d="M 0 0 L 10 5 L 0 10 z" fill="#b8c0cc" />
|
||||||
</marker>
|
</marker>
|
||||||
</defs>
|
</defs>
|
||||||
|
|
||||||
@@ -28,20 +33,25 @@
|
|||||||
<g class="edge" *ngFor="let edge of edges">
|
<g class="edge" *ngFor="let edge of edges">
|
||||||
<line [attr.x1]="edge.x1" [attr.y1]="edge.y1"
|
<line [attr.x1]="edge.x1" [attr.y1]="edge.y1"
|
||||||
[attr.x2]="edge.x2" [attr.y2]="edge.y2"
|
[attr.x2]="edge.x2" [attr.y2]="edge.y2"
|
||||||
stroke="#6b7280" stroke-width="2"
|
stroke="#b8c0cc" stroke-width="2"
|
||||||
marker-end="url(#arrowhead)" />
|
marker-end="url(#arrowhead)" />
|
||||||
<text *ngIf="edge.label"
|
<text *ngIf="edge.label"
|
||||||
[attr.x]="edge.labelX"
|
[attr.x]="edge.labelX"
|
||||||
[attr.y]="edge.labelY"
|
[attr.y]="edge.labelY"
|
||||||
text-anchor="middle"
|
text-anchor="middle"
|
||||||
class="edge-label">
|
class="edge-label"
|
||||||
|
[class.dragging]="draggingLabelKey === edge.key"
|
||||||
|
(pointerdown)="onLabelPointerDown($event, edge)">
|
||||||
{{ edge.label }}
|
{{ edge.label }}
|
||||||
</text>
|
</text>
|
||||||
</g>
|
</g>
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
<g class="nodes">
|
<g class="nodes">
|
||||||
<g class="node" *ngFor="let node of nodes" (click)="openScene(node.id)">
|
<g class="node"
|
||||||
|
[class.dragging]="draggingId === node.id"
|
||||||
|
*ngFor="let node of nodes"
|
||||||
|
(pointerdown)="onPointerDown($event, node)">
|
||||||
<title>{{ node.name }}</title>
|
<title>{{ node.name }}</title>
|
||||||
<rect [attr.x]="node.x" [attr.y]="node.y"
|
<rect [attr.x]="node.x" [attr.y]="node.y"
|
||||||
[attr.width]="NODE_WIDTH" [attr.height]="NODE_HEIGHT"
|
[attr.width]="NODE_WIDTH" [attr.height]="NODE_HEIGHT"
|
||||||
@@ -57,7 +67,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
<small class="graph-hint">
|
<small class="graph-hint">
|
||||||
💡 Cliquez sur une scène pour l'ouvrir. Les scènes non reliées au point d'entrée (scène d'ordre 1) apparaissent en bas.
|
💡 Cliquez sur une scène pour l'ouvrir, ou glissez-la pour réorganiser la carte. Les scènes non reliées au point d'entrée (scène d'ordre 1) apparaissent en bas.
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
margin-bottom: 2rem;
|
margin-bottom: 2rem;
|
||||||
|
|
||||||
.subtitle {
|
.subtitle {
|
||||||
color: #6b7280;
|
color: #9ca3af;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
margin: 0.25rem 0 0;
|
margin: 0.25rem 0 0;
|
||||||
}
|
}
|
||||||
@@ -20,15 +20,17 @@
|
|||||||
.graph-empty {
|
.graph-empty {
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #6b7280;
|
color: #9ca3af;
|
||||||
background: #f9fafb;
|
background: #14141f;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
border: 1px dashed #d1d5db;
|
border: 1px dashed #374151;
|
||||||
}
|
}
|
||||||
|
|
||||||
.graph-container {
|
.graph-container {
|
||||||
background: #fafafa;
|
// Fond legerement plus sombre que la couleur des noeuds : creuse l'image
|
||||||
border: 1px solid #e5e7eb;
|
// sans aller jusqu'au noir pur (qui « brulerait » par contraste).
|
||||||
|
background: #0d0d18;
|
||||||
|
border: 1px solid #374151;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
@@ -41,14 +43,27 @@
|
|||||||
.graph-svg {
|
.graph-svg {
|
||||||
display: block;
|
display: block;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
// Empeche le browser de clipper le contenu qui depasserait le viewport SVG
|
||||||
|
// pendant un drag — le scroll du conteneur prend le relais.
|
||||||
|
overflow: visible;
|
||||||
|
// Évite que le navigateur intercepte le drag pour faire de la sélection texte
|
||||||
|
// ou du panning natif sur les nœuds.
|
||||||
|
touch-action: none;
|
||||||
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.node {
|
.node {
|
||||||
cursor: pointer;
|
cursor: grab;
|
||||||
|
// Ombre portee douce pour detacher chaque noeud du fond. Faible alpha pour
|
||||||
|
// rester subtil sur fond sombre, large diffusion pour rester organique.
|
||||||
|
filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
|
||||||
|
|
||||||
.node-box {
|
.node-box {
|
||||||
fill: #ffffff;
|
// Indigo desature : reprend la palette accent (#6c63ff) en version assombrie
|
||||||
stroke: #1f2937;
|
// pour donner du caractere aux noeuds sans saturer la vue. Bordure assortie
|
||||||
|
// un peu plus claire pour bien dessiner le contour.
|
||||||
|
fill: #1f1d3a;
|
||||||
|
stroke: #4f4a7a;
|
||||||
stroke-width: 2;
|
stroke-width: 2;
|
||||||
transition: fill 0.15s ease, stroke 0.15s ease;
|
transition: fill 0.15s ease, stroke 0.15s ease;
|
||||||
}
|
}
|
||||||
@@ -56,31 +71,47 @@
|
|||||||
.node-label {
|
.node-label {
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
fill: #1f2937;
|
fill: #f3f4f6;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover .node-box {
|
&:hover .node-box {
|
||||||
fill: #eef2ff;
|
fill: #2c2952;
|
||||||
stroke: #4f46e5;
|
stroke: #8b80ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.dragging {
|
||||||
|
cursor: grabbing;
|
||||||
|
.node-box {
|
||||||
|
fill: #2c2952;
|
||||||
|
stroke: #8b80ff;
|
||||||
|
filter: drop-shadow(0 4px 10px rgba(108, 99, 255, 0.35));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.edge-label {
|
.edge-label {
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
fill: #4b5563;
|
fill: #e5e7eb;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
// Halo blanc autour du texte pour garantir la lisibilité même s'il passe
|
cursor: grab;
|
||||||
// sur une ligne ou un autre élément.
|
// Halo sombre autour du texte pour rester lisible quand un label passe
|
||||||
|
// par-dessus une arête ou un autre nœud. Aligne sur la couleur du fond.
|
||||||
paint-order: stroke;
|
paint-order: stroke;
|
||||||
stroke: #fafafa;
|
stroke: #0d0d18;
|
||||||
stroke-width: 3px;
|
stroke-width: 4px;
|
||||||
stroke-linejoin: round;
|
stroke-linejoin: round;
|
||||||
|
|
||||||
|
&:hover { fill: #ffffff; }
|
||||||
|
&.dragging {
|
||||||
|
cursor: grabbing;
|
||||||
|
fill: #ffffff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.graph-hint {
|
.graph-hint {
|
||||||
display: block;
|
display: block;
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
color: #6b7280;
|
color: #9ca3af;
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
import { Component, OnInit, OnDestroy, ElementRef, ViewChild } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
||||||
import { forkJoin } from 'rxjs';
|
import { forkJoin } from 'rxjs';
|
||||||
import { LucideAngularModule, ArrowLeft } from 'lucide-angular';
|
import { LucideAngularModule, ArrowLeft } from 'lucide-angular';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { PageTitleService } from '../../services/page-title.service';
|
import { PageTitleService } from '../../services/page-title.service';
|
||||||
import { Campaign, Chapter, Scene } from '../../services/campaign.model';
|
import { Campaign, Chapter, Scene } from '../../services/campaign.model';
|
||||||
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
||||||
|
|
||||||
interface GraphNode { id: string; name: string; displayName: string; x: number; y: number; }
|
interface GraphNode { id: string; name: string; displayName: string; x: number; y: number; }
|
||||||
interface GraphEdge { label: string; x1: number; y1: number; x2: number; y2: number; labelX: number; labelY: number; }
|
interface GraphEdge { key: string; label: string; x1: number; y1: number; x2: number; y2: number; labelX: number; labelY: number; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vue graphique d'un chapitre : organigramme des scènes et branches narratives.
|
* Vue graphique d'un chapitre : organigramme des scènes et branches narratives.
|
||||||
@@ -44,10 +45,29 @@ export class ChapterGraphComponent implements OnInit, OnDestroy {
|
|||||||
svgWidth = 600;
|
svgWidth = 600;
|
||||||
svgHeight = 400;
|
svgHeight = 400;
|
||||||
|
|
||||||
|
@ViewChild('svgEl') svgEl?: ElementRef<SVGSVGElement>;
|
||||||
|
|
||||||
|
// Etat de drag : id du noeud manipule, offset entre le pointeur et le coin
|
||||||
|
// haut-gauche du noeud (en coords SVG), et flag indiquant qu'un mouvement
|
||||||
|
// significatif a eu lieu (pour distinguer clic vs glisser).
|
||||||
|
draggingId: string | null = null;
|
||||||
|
draggingLabelKey: string | null = null;
|
||||||
|
private dragOffsetX = 0;
|
||||||
|
private dragOffsetY = 0;
|
||||||
|
private dragMoved = false;
|
||||||
|
private readonly DRAG_THRESHOLD = 4;
|
||||||
|
|
||||||
|
// Decalage manuel applique a chaque label d'arete, indexe par cle stable
|
||||||
|
// (sourceId|targetId|branchIdx). Persiste a travers les recalculs d'aretes
|
||||||
|
// pour que le label suive son arete quand on deplace un noeud, tout en
|
||||||
|
// conservant le repositionnement manuel de l'utilisateur.
|
||||||
|
private labelOffsets = new Map<string, { dx: number; dy: number }>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private pageTitleService: PageTitleService
|
private pageTitleService: PageTitleService
|
||||||
) {}
|
) {}
|
||||||
@@ -67,7 +87,7 @@ export class ChapterGraphComponent implements OnInit, OnDestroy {
|
|||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
chapter: this.campaignService.getChapterById(this.chapterId),
|
chapter: this.campaignService.getChapterById(this.chapterId),
|
||||||
scenes: this.campaignService.getScenes(this.chapterId),
|
scenes: this.campaignService.getScenes(this.chapterId),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).subscribe(({ campaign, allCampaigns, chapter, scenes, treeData }) => {
|
}).subscribe(({ campaign, allCampaigns, chapter, scenes, treeData }) => {
|
||||||
this.chapter = chapter;
|
this.chapter = chapter;
|
||||||
this.scenes = scenes;
|
this.scenes = scenes;
|
||||||
@@ -151,7 +171,18 @@ export class ChapterGraphComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeMap = new Map(nodes.map(n => [n.id, n]));
|
this.nodes = nodes;
|
||||||
|
this.recomputeEdges();
|
||||||
|
this.svgWidth = Math.max(rowWidth + 40, 600);
|
||||||
|
this.svgHeight = (orphanLevel + 1) * (this.NODE_HEIGHT + this.V_SPACING) + 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalcule la geometrie des aretes a partir des positions courantes des noeuds.
|
||||||
|
* Appele apres le layout initial et apres chaque deplacement manuel d'un noeud.
|
||||||
|
*/
|
||||||
|
private recomputeEdges(): void {
|
||||||
|
const nodeMap = new Map(this.nodes.map(n => [n.id, n]));
|
||||||
const edges: GraphEdge[] = [];
|
const edges: GraphEdge[] = [];
|
||||||
for (const scene of this.scenes) {
|
for (const scene of this.scenes) {
|
||||||
const from = nodeMap.get(scene.id!);
|
const from = nodeMap.get(scene.id!);
|
||||||
@@ -169,19 +200,158 @@ export class ChapterGraphComponent implements OnInit, OnDestroy {
|
|||||||
const y2 = to.y;
|
const y2 = to.y;
|
||||||
// t ∈ [0.25, 0.55] : labels plutot pres de la source, echelonnes.
|
// t ∈ [0.25, 0.55] : labels plutot pres de la source, echelonnes.
|
||||||
const t = count === 1 ? 0.5 : 0.25 + (idx / (count - 1)) * 0.3;
|
const t = count === 1 ? 0.5 : 0.25 + (idx / (count - 1)) * 0.3;
|
||||||
|
const key = `${scene.id}|${b.targetSceneId}|${idx}`;
|
||||||
|
const offset = this.labelOffsets.get(key) ?? { dx: 0, dy: 0 };
|
||||||
edges.push({
|
edges.push({
|
||||||
|
key,
|
||||||
label: b.label,
|
label: b.label,
|
||||||
x1, y1, x2, y2,
|
x1, y1, x2, y2,
|
||||||
labelX: x1 + (x2 - x1) * t,
|
labelX: x1 + (x2 - x1) * t + offset.dx,
|
||||||
labelY: y1 + (y2 - y1) * t - 4
|
labelY: y1 + (y2 - y1) * t - 4 + offset.dy
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nodes = nodes;
|
|
||||||
this.edges = edges;
|
this.edges = edges;
|
||||||
this.svgWidth = Math.max(rowWidth + 40, 600);
|
}
|
||||||
this.svgHeight = (orphanLevel + 1) * (this.NODE_HEIGHT + this.V_SPACING) + 40;
|
|
||||||
|
/**
|
||||||
|
* Convertit des coordonnees ecran (PointerEvent) en coordonnees SVG via la CTM
|
||||||
|
* inverse. Necessaire car le SVG peut etre redimensionne par max-width.
|
||||||
|
*/
|
||||||
|
private toSvgCoords(evt: PointerEvent): { x: number; y: number } {
|
||||||
|
const svg = this.svgEl?.nativeElement;
|
||||||
|
if (!svg) return { x: evt.clientX, y: evt.clientY };
|
||||||
|
const pt = svg.createSVGPoint();
|
||||||
|
pt.x = evt.clientX;
|
||||||
|
pt.y = evt.clientY;
|
||||||
|
const ctm = svg.getScreenCTM();
|
||||||
|
if (!ctm) return { x: evt.clientX, y: evt.clientY };
|
||||||
|
const local = pt.matrixTransform(ctm.inverse());
|
||||||
|
return { x: local.x, y: local.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
onPointerDown(evt: PointerEvent, node: GraphNode): void {
|
||||||
|
// Bouton gauche uniquement.
|
||||||
|
if (evt.button !== 0) return;
|
||||||
|
evt.preventDefault();
|
||||||
|
const { x, y } = this.toSvgCoords(evt);
|
||||||
|
this.draggingId = node.id;
|
||||||
|
this.dragOffsetX = x - node.x;
|
||||||
|
this.dragOffsetY = y - node.y;
|
||||||
|
this.dragMoved = false;
|
||||||
|
(evt.target as Element).setPointerCapture?.(evt.pointerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
onPointerMove(evt: PointerEvent): void {
|
||||||
|
const { x, y } = this.toSvgCoords(evt);
|
||||||
|
|
||||||
|
if (this.draggingLabelKey) {
|
||||||
|
const edge = this.edges.find(e => e.key === this.draggingLabelKey);
|
||||||
|
if (!edge) return;
|
||||||
|
const newX = x - this.dragOffsetX;
|
||||||
|
const newY = y - this.dragOffsetY;
|
||||||
|
if (!this.dragMoved && Math.hypot(newX - edge.labelX, newY - edge.labelY) < this.DRAG_THRESHOLD) return;
|
||||||
|
this.dragMoved = true;
|
||||||
|
// Recalcule la position automatique courante puis stocke la difference,
|
||||||
|
// pour que l'offset reste valable meme apres deplacement d'un noeud.
|
||||||
|
const auto = this.autoLabelPosition(edge.key);
|
||||||
|
if (auto) {
|
||||||
|
this.labelOffsets.set(edge.key, { dx: newX - auto.x, dy: newY - auto.y });
|
||||||
|
}
|
||||||
|
edge.labelX = newX;
|
||||||
|
edge.labelY = newY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.draggingId) return;
|
||||||
|
const node = this.nodes.find(n => n.id === this.draggingId);
|
||||||
|
if (!node) return;
|
||||||
|
// Empeche le noeud de partir en coordonnees negatives : sinon il sort
|
||||||
|
// du viewport SVG et se fait clipper par le navigateur (le SVG a
|
||||||
|
// overflow: hidden par defaut quand on lui donne width/height explicites).
|
||||||
|
const newX = Math.max(0, x - this.dragOffsetX);
|
||||||
|
const newY = Math.max(0, y - this.dragOffsetY);
|
||||||
|
if (!this.dragMoved) {
|
||||||
|
const dx = newX - node.x;
|
||||||
|
const dy = newY - node.y;
|
||||||
|
if (Math.hypot(dx, dy) >= this.DRAG_THRESHOLD) this.dragMoved = true;
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
node.x = newX;
|
||||||
|
node.y = newY;
|
||||||
|
this.recomputeEdges();
|
||||||
|
this.fitSvgToNodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalcule la position "auto" (sans offset manuel) du label d'une arete
|
||||||
|
* a partir de sa cle. Utilise pour deriver le delta a stocker pendant le drag.
|
||||||
|
*/
|
||||||
|
private autoLabelPosition(key: string): { x: number; y: number } | null {
|
||||||
|
const [sourceId, targetId, idxStr] = key.split('|');
|
||||||
|
const idx = Number(idxStr);
|
||||||
|
const scene = this.scenes.find(s => s.id === sourceId);
|
||||||
|
if (!scene?.branches) return null;
|
||||||
|
const siblings = scene.branches.filter(b => this.nodes.some(n => n.id === b.targetSceneId));
|
||||||
|
const count = siblings.length;
|
||||||
|
if (idx >= count) return null;
|
||||||
|
const from = this.nodes.find(n => n.id === sourceId);
|
||||||
|
const to = this.nodes.find(n => n.id === targetId);
|
||||||
|
if (!from || !to) return null;
|
||||||
|
const x1 = from.x + this.NODE_WIDTH / 2;
|
||||||
|
const y1 = from.y + this.NODE_HEIGHT;
|
||||||
|
const x2 = to.x + this.NODE_WIDTH / 2;
|
||||||
|
const y2 = to.y;
|
||||||
|
const t = count === 1 ? 0.5 : 0.25 + (idx / (count - 1)) * 0.3;
|
||||||
|
return { x: x1 + (x2 - x1) * t, y: y1 + (y2 - y1) * t - 4 };
|
||||||
|
}
|
||||||
|
|
||||||
|
onLabelPointerDown(evt: PointerEvent, edge: GraphEdge): void {
|
||||||
|
if (evt.button !== 0) return;
|
||||||
|
// Empeche l'event de remonter au <g class="node"> ou au svg, sinon on
|
||||||
|
// declencherait aussi un drag de noeud.
|
||||||
|
evt.stopPropagation();
|
||||||
|
evt.preventDefault();
|
||||||
|
const { x, y } = this.toSvgCoords(evt);
|
||||||
|
this.draggingLabelKey = edge.key;
|
||||||
|
this.dragOffsetX = x - edge.labelX;
|
||||||
|
this.dragOffsetY = y - edge.labelY;
|
||||||
|
this.dragMoved = false;
|
||||||
|
(evt.target as Element).setPointerCapture?.(evt.pointerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Agrandit le SVG si un noeud s'approche du bord droit ou bas, pour eviter
|
||||||
|
* que le contenu deplace soit rogne. On ne reduit jamais en-dessous de la
|
||||||
|
* taille initiale du layout pour rester stable visuellement.
|
||||||
|
*/
|
||||||
|
private fitSvgToNodes(): void {
|
||||||
|
const margin = 40;
|
||||||
|
let maxX = 600;
|
||||||
|
let maxY = 200;
|
||||||
|
for (const n of this.nodes) {
|
||||||
|
if (n.x + this.NODE_WIDTH + margin > maxX) maxX = n.x + this.NODE_WIDTH + margin;
|
||||||
|
if (n.y + this.NODE_HEIGHT + margin > maxY) maxY = n.y + this.NODE_HEIGHT + margin;
|
||||||
|
}
|
||||||
|
if (maxX > this.svgWidth) this.svgWidth = maxX;
|
||||||
|
if (maxY > this.svgHeight) this.svgHeight = maxY;
|
||||||
|
}
|
||||||
|
|
||||||
|
onPointerUp(evt: PointerEvent): void {
|
||||||
|
if (this.draggingLabelKey) {
|
||||||
|
this.draggingLabelKey = null;
|
||||||
|
this.dragMoved = false;
|
||||||
|
(evt.target as Element).releasePointerCapture?.(evt.pointerId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.draggingId) return;
|
||||||
|
const id = this.draggingId;
|
||||||
|
const moved = this.dragMoved;
|
||||||
|
this.draggingId = null;
|
||||||
|
this.dragMoved = false;
|
||||||
|
(evt.target as Element).releasePointerCapture?.(evt.pointerId);
|
||||||
|
// Si le pointeur n'a pas reellement bouge, on traite comme un clic d'ouverture.
|
||||||
|
if (!moved) this.openScene(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private truncate(text: string): string {
|
private truncate(text: string): string {
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
<header class="view-header">
|
<header class="view-header">
|
||||||
<div>
|
<div>
|
||||||
<h1>{{ chapter.name }}</h1>
|
<h1>
|
||||||
|
<lucide-icon *ngIf="chapter.icon" [img]="resolveCampaignIcon(chapter.icon)" [size]="22" class="title-icon"></lucide-icon>
|
||||||
|
{{ chapter.name }}
|
||||||
|
</h1>
|
||||||
<p class="view-subtitle">Chapitre</p>
|
<p class="view-subtitle">Chapitre</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="view-actions">
|
<div class="view-actions">
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
|||||||
import { forkJoin, of } from 'rxjs';
|
import { forkJoin, of } from 'rxjs';
|
||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { LucideAngularModule, Pencil, Network, Trash2 } from 'lucide-angular';
|
import { LucideAngularModule, Pencil, Network, Trash2 } from 'lucide-angular';
|
||||||
|
import { resolveCampaignIcon } from '../campaign-icons';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { PageService } from '../../services/page.service';
|
import { PageService } from '../../services/page.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { PageTitleService } from '../../services/page-title.service';
|
import { PageTitleService } from '../../services/page-title.service';
|
||||||
@@ -28,6 +30,7 @@ export class ChapterViewComponent implements OnInit, OnDestroy {
|
|||||||
readonly Pencil = Pencil;
|
readonly Pencil = Pencil;
|
||||||
readonly Network = Network;
|
readonly Network = Network;
|
||||||
readonly Trash2 = Trash2;
|
readonly Trash2 = Trash2;
|
||||||
|
readonly resolveCampaignIcon = resolveCampaignIcon;
|
||||||
|
|
||||||
campaignId = '';
|
campaignId = '';
|
||||||
arcId = '';
|
arcId = '';
|
||||||
@@ -41,6 +44,7 @@ export class ChapterViewComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private pageService: PageService,
|
private pageService: PageService,
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private pageTitleService: PageTitleService
|
private pageTitleService: PageTitleService
|
||||||
@@ -67,7 +71,7 @@ export class ChapterViewComponent implements OnInit, OnDestroy {
|
|||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
chapter: this.campaignService.getChapterById(this.chapterId),
|
chapter: this.campaignService.getChapterById(this.chapterId),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
switchMap(data => {
|
switchMap(data => {
|
||||||
const lid = data.campaign.loreId ?? null;
|
const lid = data.campaign.loreId ?? null;
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
<form [formGroup]="form" (ngSubmit)="submit()" class="scene-form">
|
<form [formGroup]="form" (ngSubmit)="submit()" class="scene-form">
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Nom de la scène *</label>
|
<label for="scene-create-name">Nom de la scène *</label>
|
||||||
<input
|
<input
|
||||||
|
id="scene-create-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: Arrivée au village"
|
placeholder="Ex: Arrivée au village"
|
||||||
@@ -18,14 +19,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Description</label>
|
<label for="scene-create-description">Description</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="scene-create-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Décrivez la scène, les événements clés, les PNJ présents..."
|
placeholder="Décrivez la scène, les événements clés, les PNJ présents..."
|
||||||
rows="6">
|
rows="6">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Icône</label>
|
||||||
|
<app-icon-picker [options]="campaignIconOptions" [(selected)]="selectedIcon"></app-icon-picker>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
||||||
Créer la scène
|
Créer la scène
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { forkJoin } from 'rxjs';
|
import { forkJoin } from 'rxjs';
|
||||||
import { LucideAngularModule } from 'lucide-angular';
|
import { LucideAngularModule } from 'lucide-angular';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { Campaign } from '../../services/campaign.model';
|
import { Campaign } from '../../services/campaign.model';
|
||||||
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper';
|
||||||
|
import { IconPickerComponent } from '../../shared/icon-picker/icon-picker.component';
|
||||||
|
import { CAMPAIGN_ICON_OPTIONS } from '../campaign-icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Écran de création d'une nouvelle scène rattachée à un chapitre.
|
* Écran de création d'une nouvelle scène rattachée à un chapitre.
|
||||||
@@ -16,11 +19,14 @@ import { loadCampaignTreeData, buildCampaignTree } from '../campaign-tree.helper
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-scene-create',
|
selector: 'app-scene-create',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule],
|
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, IconPickerComponent],
|
||||||
templateUrl: './scene-create.component.html',
|
templateUrl: './scene-create.component.html',
|
||||||
styleUrls: ['./scene-create.component.scss']
|
styleUrls: ['./scene-create.component.scss']
|
||||||
})
|
})
|
||||||
export class SceneCreateComponent implements OnInit, OnDestroy {
|
export class SceneCreateComponent implements OnInit, OnDestroy {
|
||||||
|
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
|
||||||
|
selectedIcon: string | null = null;
|
||||||
|
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
campaignId = '';
|
campaignId = '';
|
||||||
arcId = '';
|
arcId = '';
|
||||||
@@ -33,6 +39,7 @@ export class SceneCreateComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private layoutService: LayoutService
|
private layoutService: LayoutService
|
||||||
) {
|
) {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
@@ -52,7 +59,7 @@ export class SceneCreateComponent implements OnInit, OnDestroy {
|
|||||||
forkJoin({
|
forkJoin({
|
||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
}).subscribe(({ campaign, allCampaigns, treeData }) => {
|
||||||
const currentChapter = (treeData.chaptersByArc[this.arcId] ?? []).find(c => c.id === this.chapterId);
|
const currentChapter = (treeData.chaptersByArc[this.arcId] ?? []).find(c => c.id === this.chapterId);
|
||||||
this.chapterName = currentChapter?.name ?? '';
|
this.chapterName = currentChapter?.name ?? '';
|
||||||
@@ -82,7 +89,8 @@ export class SceneCreateComponent implements OnInit, OnDestroy {
|
|||||||
name: this.form.value.name,
|
name: this.form.value.name,
|
||||||
description: this.form.value.description,
|
description: this.form.value.description,
|
||||||
chapterId: this.chapterId,
|
chapterId: this.chapterId,
|
||||||
order: this.existingSceneCount + 1
|
order: this.existingSceneCount + 1,
|
||||||
|
icon: this.selectedIcon
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: (created) => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId, 'scenes', created.id]),
|
next: (created) => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId, 'scenes', created.id]),
|
||||||
error: () => console.error('Erreur lors de la création de la scène')
|
error: () => console.error('Erreur lors de la création de la scène')
|
||||||
|
|||||||
@@ -13,6 +13,14 @@
|
|||||||
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
||||||
Assistant IA
|
Assistant IA
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="btn-secondary" (click)="cancel()">Annuler</button>
|
||||||
|
<button type="button" class="btn-danger" (click)="delete()">
|
||||||
|
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn-primary" (click)="submit()" [disabled]="form.invalid">
|
||||||
|
Sauvegarder
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -43,8 +51,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Titre de la scène *</label>
|
<label for="scene-edit-name">Titre de la scène *</label>
|
||||||
<input
|
<input
|
||||||
|
id="scene-edit-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: Arrivée au village"
|
placeholder="Ex: Arrivée au village"
|
||||||
@@ -53,29 +62,36 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Description courte *</label>
|
<label for="scene-edit-description">Description courte *</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="scene-edit-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Résumé en une ou deux phrases de ce qui se passe..."
|
placeholder="Résumé en une ou deux phrases de ce qui se passe..."
|
||||||
rows="3">
|
rows="3">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label>Icône</label>
|
||||||
|
<app-icon-picker [options]="campaignIconOptions" [(selected)]="selectedIcon"></app-icon-picker>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Section : Contexte et ambiance -->
|
<!-- Section : Contexte et ambiance -->
|
||||||
<app-expandable-section title="Contexte et ambiance" icon="📍" [initiallyOpen]="true">
|
<app-expandable-section title="Contexte et ambiance" icon="📍" [initiallyOpen]="true">
|
||||||
<div class="field-row">
|
<div class="field-row">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Lieu</label>
|
<label for="scene-edit-location">Lieu</label>
|
||||||
<input type="text" formControlName="location" placeholder="Ex: Taverne du Dragon d'Or" />
|
<input id="scene-edit-location" type="text" formControlName="location" placeholder="Ex: Taverne du Dragon d'Or" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Moment</label>
|
<label for="scene-edit-timing">Moment</label>
|
||||||
<input type="text" formControlName="timing" placeholder="Ex: Soir, à la tombée de la nuit" />
|
<input id="scene-edit-timing" type="text" formControlName="timing" placeholder="Ex: Soir, à la tombée de la nuit" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Ambiance et atmosphère</label>
|
<label for="scene-edit-atmosphere">Ambiance et atmosphère</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="scene-edit-atmosphere"
|
||||||
formControlName="atmosphere"
|
formControlName="atmosphere"
|
||||||
placeholder="Décrivez l'ambiance générale de la scène (sons, odeurs, lumière, émotions...)"
|
placeholder="Décrivez l'ambiance générale de la scène (sons, odeurs, lumière, émotions...)"
|
||||||
rows="4">
|
rows="4">
|
||||||
@@ -179,12 +195,13 @@
|
|||||||
<!-- Section : Combat ou rencontre -->
|
<!-- Section : Combat ou rencontre -->
|
||||||
<app-expandable-section title="Combat ou rencontre" icon="⚔️">
|
<app-expandable-section title="Combat ou rencontre" icon="⚔️">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Difficulté estimée</label>
|
<label for="scene-edit-combat-difficulty">Difficulté estimée</label>
|
||||||
<input type="text" formControlName="combatDifficulty" placeholder="Ex: Moyenne, 3 gobelins niveau 2" />
|
<input id="scene-edit-combat-difficulty" type="text" formControlName="combatDifficulty" placeholder="Ex: Moyenne, 3 gobelins niveau 2" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Ennemis et créatures</label>
|
<label for="scene-edit-enemies">Ennemis et créatures</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="scene-edit-enemies"
|
||||||
formControlName="enemies"
|
formControlName="enemies"
|
||||||
placeholder="Liste des ennemis présents dans cette scène..."
|
placeholder="Liste des ennemis présents dans cette scène..."
|
||||||
rows="4">
|
rows="4">
|
||||||
@@ -214,17 +231,6 @@
|
|||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<button type="submit" class="btn-primary" [disabled]="form.invalid">
|
|
||||||
Sauvegarder
|
|
||||||
</button>
|
|
||||||
<button type="button" class="btn-secondary" (click)="cancel()">Annuler</button>
|
|
||||||
<button type="button" class="btn-danger" (click)="delete()">
|
|
||||||
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
|
|
||||||
Supprimer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { forkJoin, of } from 'rxjs';
|
|||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { LucideAngularModule, Trash2, Sparkles } from 'lucide-angular';
|
import { LucideAngularModule, Trash2, Sparkles } from 'lucide-angular';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { PageService } from '../../services/page.service';
|
import { PageService } from '../../services/page.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { PageTitleService } from '../../services/page-title.service';
|
import { PageTitleService } from '../../services/page-title.service';
|
||||||
@@ -16,6 +17,8 @@ import { ExpandableSectionComponent } from '../../shared/expandable-section/expa
|
|||||||
import { LoreLinkPickerComponent } from '../../shared/lore-link-picker/lore-link-picker.component';
|
import { LoreLinkPickerComponent } from '../../shared/lore-link-picker/lore-link-picker.component';
|
||||||
import { AiChatDrawerComponent } from '../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
import { AiChatDrawerComponent } from '../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
||||||
import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.component';
|
import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.component';
|
||||||
|
import { IconPickerComponent } from '../../shared/icon-picker/icon-picker.component';
|
||||||
|
import { CAMPAIGN_ICON_OPTIONS } from '../campaign-icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Écran de détail/modification d'une Scène.
|
* Écran de détail/modification d'une Scène.
|
||||||
@@ -24,13 +27,15 @@ import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-scene-edit',
|
selector: 'app-scene-edit',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, ExpandableSectionComponent, LoreLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent],
|
imports: [CommonModule, ReactiveFormsModule, LucideAngularModule, ExpandableSectionComponent, LoreLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent, IconPickerComponent],
|
||||||
templateUrl: './scene-edit.component.html',
|
templateUrl: './scene-edit.component.html',
|
||||||
styleUrls: ['./scene-edit.component.scss']
|
styleUrls: ['./scene-edit.component.scss']
|
||||||
})
|
})
|
||||||
export class SceneEditComponent implements OnInit, OnDestroy {
|
export class SceneEditComponent implements OnInit, OnDestroy {
|
||||||
readonly Trash2 = Trash2;
|
readonly Trash2 = Trash2;
|
||||||
readonly Sparkles = Sparkles;
|
readonly Sparkles = Sparkles;
|
||||||
|
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
|
||||||
|
selectedIcon: string | null = null;
|
||||||
|
|
||||||
/** État drawer chat IA (b5.7 — intégration Campagne). */
|
/** État drawer chat IA (b5.7 — intégration Campagne). */
|
||||||
chatOpen = false;
|
chatOpen = false;
|
||||||
@@ -65,6 +70,7 @@ export class SceneEditComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private pageService: PageService,
|
private pageService: PageService,
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private pageTitleService: PageTitleService
|
private pageTitleService: PageTitleService
|
||||||
@@ -116,7 +122,7 @@ export class SceneEditComponent implements OnInit, OnDestroy {
|
|||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
scene: this.campaignService.getSceneById(this.sceneId),
|
scene: this.campaignService.getSceneById(this.sceneId),
|
||||||
chapterScenes: this.campaignService.getScenes(this.chapterId),
|
chapterScenes: this.campaignService.getScenes(this.chapterId),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
switchMap(data => {
|
switchMap(data => {
|
||||||
const lid = data.campaign.loreId ?? null;
|
const lid = data.campaign.loreId ?? null;
|
||||||
@@ -129,6 +135,7 @@ export class SceneEditComponent implements OnInit, OnDestroy {
|
|||||||
this.loreId = loreId;
|
this.loreId = loreId;
|
||||||
this.availablePages = pages;
|
this.availablePages = pages;
|
||||||
this.relatedPageIds = [...(scene.relatedPageIds ?? [])];
|
this.relatedPageIds = [...(scene.relatedPageIds ?? [])];
|
||||||
|
this.selectedIcon = scene.icon ?? null;
|
||||||
this.illustrationImageIds = [...(scene.illustrationImageIds ?? [])];
|
this.illustrationImageIds = [...(scene.illustrationImageIds ?? [])];
|
||||||
this.mapImageIds = [...(scene.mapImageIds ?? [])];
|
this.mapImageIds = [...(scene.mapImageIds ?? [])];
|
||||||
this.siblingScenes = chapterScenes.filter(s => s.id !== this.sceneId);
|
this.siblingScenes = chapterScenes.filter(s => s.id !== this.sceneId);
|
||||||
@@ -182,7 +189,8 @@ export class SceneEditComponent implements OnInit, OnDestroy {
|
|||||||
relatedPageIds: this.relatedPageIds,
|
relatedPageIds: this.relatedPageIds,
|
||||||
illustrationImageIds: this.illustrationImageIds,
|
illustrationImageIds: this.illustrationImageIds,
|
||||||
mapImageIds: this.mapImageIds,
|
mapImageIds: this.mapImageIds,
|
||||||
branches: this.branches
|
branches: this.branches,
|
||||||
|
icon: this.selectedIcon
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: () => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId, 'scenes', this.sceneId]),
|
next: () => this.router.navigate(['/campaigns', this.campaignId, 'arcs', this.arcId, 'chapters', this.chapterId, 'scenes', this.sceneId]),
|
||||||
error: () => console.error('Erreur lors de la sauvegarde')
|
error: () => console.error('Erreur lors de la sauvegarde')
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
<header class="view-header">
|
<header class="view-header">
|
||||||
<div>
|
<div>
|
||||||
<h1>{{ scene.name }}</h1>
|
<h1>
|
||||||
|
<lucide-icon *ngIf="scene.icon" [img]="resolveCampaignIcon(scene.icon)" [size]="22" class="title-icon"></lucide-icon>
|
||||||
|
{{ scene.name }}
|
||||||
|
</h1>
|
||||||
<p class="view-subtitle">Scène</p>
|
<p class="view-subtitle">Scène</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="view-actions">
|
<div class="view-actions">
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
|||||||
import { forkJoin, of } from 'rxjs';
|
import { forkJoin, of } from 'rxjs';
|
||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { LucideAngularModule, Pencil, Trash2 } from 'lucide-angular';
|
import { LucideAngularModule, Pencil, Trash2 } from 'lucide-angular';
|
||||||
|
import { resolveCampaignIcon } from '../campaign-icons';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { CharacterService } from '../../services/character.service';
|
||||||
import { PageService } from '../../services/page.service';
|
import { PageService } from '../../services/page.service';
|
||||||
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
import { LayoutService, GlobalItem } from '../../services/layout.service';
|
||||||
import { PageTitleService } from '../../services/page-title.service';
|
import { PageTitleService } from '../../services/page-title.service';
|
||||||
@@ -27,6 +29,7 @@ import { ImageGalleryComponent } from '../../shared/image-gallery/image-gallery.
|
|||||||
export class SceneViewComponent implements OnInit, OnDestroy {
|
export class SceneViewComponent implements OnInit, OnDestroy {
|
||||||
readonly Pencil = Pencil;
|
readonly Pencil = Pencil;
|
||||||
readonly Trash2 = Trash2;
|
readonly Trash2 = Trash2;
|
||||||
|
readonly resolveCampaignIcon = resolveCampaignIcon;
|
||||||
|
|
||||||
campaignId = '';
|
campaignId = '';
|
||||||
arcId = '';
|
arcId = '';
|
||||||
@@ -41,6 +44,7 @@ export class SceneViewComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService,
|
private campaignService: CampaignService,
|
||||||
|
private characterService: CharacterService,
|
||||||
private pageService: PageService,
|
private pageService: PageService,
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private pageTitleService: PageTitleService
|
private pageTitleService: PageTitleService
|
||||||
@@ -70,7 +74,7 @@ export class SceneViewComponent implements OnInit, OnDestroy {
|
|||||||
campaign: this.campaignService.getCampaignById(this.campaignId),
|
campaign: this.campaignService.getCampaignById(this.campaignId),
|
||||||
allCampaigns: this.campaignService.getAllCampaigns(),
|
allCampaigns: this.campaignService.getAllCampaigns(),
|
||||||
scene: this.campaignService.getSceneById(this.sceneId),
|
scene: this.campaignService.getSceneById(this.sceneId),
|
||||||
treeData: loadCampaignTreeData(this.campaignService, this.campaignId)
|
treeData: loadCampaignTreeData(this.campaignService, this.campaignId, this.characterService)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
switchMap(data => {
|
switchMap(data => {
|
||||||
const lid = data.campaign.loreId ?? null;
|
const lid = data.campaign.loreId ?? null;
|
||||||
|
|||||||
17
web/src/app/guards/demo-mode.guard.ts
Normal file
17
web/src/app/guards/demo-mode.guard.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { inject } from '@angular/core';
|
||||||
|
import { CanActivateFn, Router } from '@angular/router';
|
||||||
|
import { ConfigService } from '../services/config.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bloque l'acces aux routes sensibles quand demoMode est actif et redirige
|
||||||
|
* vers la home. Defense UX ; le verrou serveur reste la source de verite.
|
||||||
|
*/
|
||||||
|
export const hiddenInDemoGuard: CanActivateFn = () => {
|
||||||
|
const config = inject(ConfigService);
|
||||||
|
const router = inject(Router);
|
||||||
|
if (config.demoMode) {
|
||||||
|
router.navigate(['/']);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
65
web/src/app/interceptors/session-expired.interceptor.ts
Normal file
65
web/src/app/interceptors/session-expired.interceptor.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { HttpInterceptorFn, HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { catchError, throwError } from 'rxjs';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detecte la perte de session demo (orchestrateur) via les codes 401/502 sur
|
||||||
|
* les appels /api/*, affiche un overlay puis force un rechargement de la page.
|
||||||
|
* Le reload renvoie l'utilisateur sur la page "Preparation" pour creer une
|
||||||
|
* nouvelle session sans qu'il ait a faire Ctrl+Shift+R.
|
||||||
|
*
|
||||||
|
* Cet interceptor est inerte en mode normal (non-demo) : si le backend natif
|
||||||
|
* renvoie un 401 legitime, ca declenche aussi le reload, ce qui est sans
|
||||||
|
* consequence puisqu'aucun flux d'auth utilisateur n'existe encore cote app.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Module-level flag : evite de declencher overlay + reload plusieurs fois si
|
||||||
|
// plusieurs appels echouent en parallele juste apres l'expiration.
|
||||||
|
let alreadyTriggered = false;
|
||||||
|
|
||||||
|
export const sessionExpiredInterceptor: HttpInterceptorFn = (req, next) => {
|
||||||
|
return next(req).pipe(
|
||||||
|
catchError((err) => {
|
||||||
|
const isApiCall = req.url.includes('/api/');
|
||||||
|
const isSessionLoss =
|
||||||
|
err instanceof HttpErrorResponse && (err.status === 401 || err.status === 502);
|
||||||
|
|
||||||
|
if (isApiCall && isSessionLoss && !alreadyTriggered) {
|
||||||
|
alreadyTriggered = true;
|
||||||
|
showExpiredOverlay();
|
||||||
|
setTimeout(() => window.location.reload(), 2500);
|
||||||
|
}
|
||||||
|
return throwError(() => err);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
function showExpiredOverlay(): void {
|
||||||
|
const overlay = document.createElement('div');
|
||||||
|
overlay.setAttribute('data-session-expired', 'true');
|
||||||
|
overlay.style.cssText = [
|
||||||
|
'position:fixed', 'inset:0',
|
||||||
|
'background:rgba(26,22,37,0.96)',
|
||||||
|
'color:#e4def5',
|
||||||
|
'display:flex', 'flex-direction:column',
|
||||||
|
'align-items:center', 'justify-content:center',
|
||||||
|
'gap:1rem',
|
||||||
|
'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',
|
||||||
|
'z-index:99999',
|
||||||
|
'text-align:center', 'padding:2rem',
|
||||||
|
].join(';');
|
||||||
|
overlay.innerHTML = `
|
||||||
|
<div style="font-size:1.5rem;color:#b794f4;">✦ Votre session démo a expiré</div>
|
||||||
|
<div style="color:#aaa0c5;max-width:420px;line-height:1.5;">
|
||||||
|
Une nouvelle session va être préparée automatiquement.<br>
|
||||||
|
Vos données précédentes ne sont pas conservées.
|
||||||
|
</div>
|
||||||
|
<div style="
|
||||||
|
width:32px;height:32px;margin-top:0.5rem;
|
||||||
|
border:3px solid rgba(183,148,244,0.2);
|
||||||
|
border-top-color:#b794f4;border-radius:50%;
|
||||||
|
animation:sex-spin 1s linear infinite;
|
||||||
|
"></div>
|
||||||
|
<style>@keyframes sex-spin{to{transform:rotate(360deg)}}</style>
|
||||||
|
`;
|
||||||
|
document.body.appendChild(overlay);
|
||||||
|
}
|
||||||
@@ -11,8 +11,9 @@
|
|||||||
<form [formGroup]="form" (ngSubmit)="submit()">
|
<form [formGroup]="form" (ngSubmit)="submit()">
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Nom de l'univers *</label>
|
<label for="lore-name">Nom de l'univers *</label>
|
||||||
<input
|
<input
|
||||||
|
id="lore-name"
|
||||||
type="text"
|
type="text"
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
placeholder="Ex: Royaume des Ombres, Cyberpunk 2157..."
|
placeholder="Ex: Royaume des Ombres, Cyberpunk 2157..."
|
||||||
@@ -21,8 +22,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Description</label>
|
<label for="lore-description">Description</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="lore-description"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
placeholder="Décrivez brièvement votre univers, son ambiance, son genre..."
|
placeholder="Décrivez brièvement votre univers, son ambiance, son genre..."
|
||||||
rows="5"
|
rows="5"
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user