Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c6b642975 | ||
|
|
d926545e3d | ||
|
|
b323c681f8 | ||
|
|
e7063b31e3 | ||
|
|
ab658f27b0 | ||
|
|
c2947cfef8 | ||
|
|
67ac4cc68f |
@@ -111,6 +111,11 @@ public class SessionService {
|
|||||||
return sessionRepository.findActive();
|
return sessionRepository.findActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Toutes les sessions en cours, la plus récente d'abord (raccourci « Séance en cours »). */
|
||||||
|
public List<Session> getAllActive() {
|
||||||
|
return sessionRepository.findAllActive();
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Session> getActiveByPlaythrough(String playthroughId) {
|
public Optional<Session> getActiveByPlaythrough(String playthroughId) {
|
||||||
return sessionRepository.findActiveByPlaythroughId(playthroughId);
|
return sessionRepository.findActiveByPlaythroughId(playthroughId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.NetworkSnapshot;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verdict « une tablette peut-elle joindre ce PC ? », calculé à partir des faits lus sur
|
||||||
|
* le système. Logique pure (testable sans Windows).
|
||||||
|
*
|
||||||
|
* @param supported vérification possible (Windows)
|
||||||
|
* @param ready rien ne bloque côté PC
|
||||||
|
* @param publicNetworks réseaux connectés classés « Public » que le pare-feu ne laisse pas passer
|
||||||
|
* @param firewallAllowed une règle active autorise l'application sur les réseaux privés
|
||||||
|
* @param firewallBlocked une règle active BLOQUE l'application (ex. « Annuler » dans la fenêtre Windows)
|
||||||
|
* @param program exécutable concerné
|
||||||
|
*/
|
||||||
|
public record NetworkReadiness(
|
||||||
|
boolean supported,
|
||||||
|
boolean ready,
|
||||||
|
List<String> publicNetworks,
|
||||||
|
boolean firewallAllowed,
|
||||||
|
boolean firewallBlocked,
|
||||||
|
String program
|
||||||
|
) {
|
||||||
|
|
||||||
|
static final String PUBLIC = "Public";
|
||||||
|
static final String PRIVATE = "Private";
|
||||||
|
|
||||||
|
public static NetworkReadiness evaluate(NetworkSnapshot snapshot) {
|
||||||
|
if (snapshot == null || !snapshot.supported()) {
|
||||||
|
return new NetworkReadiness(false, false, List.of(), false, false, null);
|
||||||
|
}
|
||||||
|
List<NetworkSnapshot.FirewallRule> rules = snapshot.rules() == null ? List.of() : snapshot.rules();
|
||||||
|
boolean allowedPrivate = covers(rules, "Allow", PRIVATE);
|
||||||
|
boolean blockedPrivate = covers(rules, "Block", PRIVATE);
|
||||||
|
boolean publicOpen = covers(rules, "Allow", PUBLIC) && !covers(rules, "Block", PUBLIC);
|
||||||
|
|
||||||
|
List<String> publicNetworks = (snapshot.networks() == null ? List.<NetworkSnapshot.Network>of() : snapshot.networks())
|
||||||
|
.stream()
|
||||||
|
.filter(n -> PUBLIC.equalsIgnoreCase(n.category()))
|
||||||
|
.map(n -> n.name() != null && !n.name().isBlank() ? n.name() : n.alias())
|
||||||
|
.toList();
|
||||||
|
// Un réseau public n'est un obstacle que si le pare-feu ne l'ouvre pas explicitement.
|
||||||
|
List<String> blockingPublic = publicOpen ? List.of() : publicNetworks;
|
||||||
|
|
||||||
|
boolean ready = allowedPrivate && !blockedPrivate && blockingPublic.isEmpty();
|
||||||
|
return new NetworkReadiness(true, ready, blockingPublic, allowedPrivate, blockedPrivate, snapshot.program());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Une règle ACTIVE de cette action couvre-t-elle ce profil (« Any » couvre tout) ? */
|
||||||
|
private static boolean covers(List<NetworkSnapshot.FirewallRule> rules, String action, String profile) {
|
||||||
|
return rules.stream()
|
||||||
|
.filter(r -> action.equalsIgnoreCase(r.action()) && "True".equalsIgnoreCase(r.enabled()))
|
||||||
|
.anyMatch(r -> profiles(r.profile()).stream().anyMatch(p -> p.equals("any") || p.equals(profile.toLowerCase(Locale.ROOT))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> profiles(String raw) {
|
||||||
|
if (raw == null) return List.of();
|
||||||
|
return Arrays.stream(raw.split(","))
|
||||||
|
.map(s -> s.trim().toLowerCase(Locale.ROOT))
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/** Vue publique d'un appareil appairé (jamais l'empreinte du jeton). */
|
||||||
|
public record PairedDevice(String id, String name, String userAgent, Instant createdAt, Instant lastSeenAt) {
|
||||||
|
|
||||||
|
static PairedDevice of(RemoteDevice d) {
|
||||||
|
return new PairedDevice(d.getId(), d.getName(), d.getUserAgent(), d.getCreatedAt(), d.getLastSeenAt());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/** Code d'appairage à 6 chiffres affiché sur le PC (usage unique). */
|
||||||
|
public record PairingCode(String code, Instant expiresAt) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
/** Appairage refusé : code absent, faux, expiré, ou trop d'essais. Message prêt à afficher. */
|
||||||
|
public class PairingRejectedException extends RuntimeException {
|
||||||
|
|
||||||
|
public PairingRejectedException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Résultat d'un appairage réussi.
|
||||||
|
*
|
||||||
|
* @param token jeton d'appareil en clair : à poser en cookie, jamais renvoyé dans le corps
|
||||||
|
* @param device l'appareil enregistré
|
||||||
|
*/
|
||||||
|
public record PairingResult(String token, PairedDevice device) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,261 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteAccessConfig;
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.LanConnector;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteAccessConfigRepository;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteDeviceRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.HexFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accès distant à l'application de bureau (tablette / téléphone sur le réseau local).
|
||||||
|
* <p>
|
||||||
|
* Modèle de confiance : le connecteur habituel reste limité à la machine (127.0.0.1) et
|
||||||
|
* n'exige rien, comme avant. Quand le MJ active l'accès distant, un SECOND connecteur
|
||||||
|
* s'ouvre sur le réseau local ; tout ce qui y arrive doit présenter un jeton d'appareil,
|
||||||
|
* obtenu en saisissant un code à 6 chiffres affiché sur le PC (usage unique, 5 minutes,
|
||||||
|
* 5 essais). Les Paramètres restent réservés à la machine (filtre {@code RemoteAccessFilter}).
|
||||||
|
* <p>
|
||||||
|
* Uniquement en mode bureau (profil {@code local}) : en Docker, rien de tout ceci n'existe.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Profile("local")
|
||||||
|
public class RemoteAccessService {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteAccessService.class);
|
||||||
|
|
||||||
|
static final Duration CODE_TTL = Duration.ofMinutes(5);
|
||||||
|
static final int CODE_MAX_ATTEMPTS = 5;
|
||||||
|
/** Garde-fou anti force brute tous codes confondus : au-delà, plus aucun essai pendant 1 min. */
|
||||||
|
static final int GLOBAL_MAX_FAILURES_PER_MINUTE = 20;
|
||||||
|
/** On ne réécrit « vu pour la dernière fois » qu'au plus une fois par minute et par appareil. */
|
||||||
|
static final Duration TOUCH_INTERVAL = Duration.ofMinutes(1);
|
||||||
|
static final int DEVICE_NAME_MAX = 100;
|
||||||
|
static final int USER_AGENT_MAX = 300;
|
||||||
|
|
||||||
|
private final RemoteAccessConfigRepository configRepository;
|
||||||
|
private final RemoteDeviceRepository deviceRepository;
|
||||||
|
private final LanConnector lanConnector;
|
||||||
|
private final int localPort;
|
||||||
|
private final Clock clock;
|
||||||
|
private final SecureRandom random = new SecureRandom();
|
||||||
|
|
||||||
|
private PairingCode currentCode;
|
||||||
|
private int attemptsLeft;
|
||||||
|
private final Deque<Instant> recentFailures = new ArrayDeque<>();
|
||||||
|
private String lastError;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RemoteAccessService(RemoteAccessConfigRepository configRepository,
|
||||||
|
RemoteDeviceRepository deviceRepository,
|
||||||
|
LanConnector lanConnector,
|
||||||
|
@Value("${server.port:8080}") int localPort) {
|
||||||
|
this(configRepository, deviceRepository, lanConnector, localPort, Clock.systemUTC());
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteAccessService(RemoteAccessConfigRepository configRepository,
|
||||||
|
RemoteDeviceRepository deviceRepository,
|
||||||
|
LanConnector lanConnector,
|
||||||
|
int localPort,
|
||||||
|
Clock clock) {
|
||||||
|
this.configRepository = configRepository;
|
||||||
|
this.deviceRepository = deviceRepository;
|
||||||
|
this.lanConnector = lanConnector;
|
||||||
|
this.localPort = localPort;
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Réglage -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Au démarrage : rouvre le connecteur si l'accès distant était activé. Ne bloque jamais le lancement. */
|
||||||
|
public synchronized void applySavedConfig() {
|
||||||
|
RemoteAccessConfig config = currentConfig();
|
||||||
|
if (!config.enabled()) return;
|
||||||
|
try {
|
||||||
|
lanConnector.start(config.port());
|
||||||
|
lastError = null;
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
lastError = e.getMessage();
|
||||||
|
log.warn("Accès distant activé mais connecteur impossible à ouvrir : {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Active ou désactive l'accès distant. À l'activation, le connecteur est ouvert AVANT
|
||||||
|
* d'enregistrer le réglage : un port occupé laisse l'accès désactivé.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException port hors plage ou identique au port local
|
||||||
|
* @throws IllegalStateException port déjà occupé
|
||||||
|
*/
|
||||||
|
public synchronized RemoteAccessStatus configure(boolean enabled, int port) {
|
||||||
|
if (port < 1024 || port > 65535) {
|
||||||
|
throw new IllegalArgumentException("Le port doit être compris entre 1024 et 65535.");
|
||||||
|
}
|
||||||
|
if (port == localPort) {
|
||||||
|
throw new IllegalArgumentException("Choisissez un port différent de celui de l'application (" + localPort + ").");
|
||||||
|
}
|
||||||
|
if (enabled) {
|
||||||
|
lanConnector.start(port);
|
||||||
|
} else {
|
||||||
|
lanConnector.stop();
|
||||||
|
currentCode = null;
|
||||||
|
}
|
||||||
|
lastError = null;
|
||||||
|
configRepository.save(new RemoteAccessConfig(enabled, port));
|
||||||
|
return status();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized RemoteAccessStatus status() {
|
||||||
|
RemoteAccessConfig config = currentConfig();
|
||||||
|
int running = lanConnector.runningPort();
|
||||||
|
List<String> urls = running > 0
|
||||||
|
? lanConnector.lanAddresses().stream().map(ip -> "http://" + ip + ":" + running).toList()
|
||||||
|
: List.of();
|
||||||
|
List<PairedDevice> devices = deviceRepository.findAll().stream()
|
||||||
|
.sorted(Comparator.comparing(RemoteDevice::getCreatedAt, Comparator.nullsLast(Comparator.naturalOrder())))
|
||||||
|
.map(PairedDevice::of)
|
||||||
|
.toList();
|
||||||
|
return new RemoteAccessStatus(config.enabled(), config.port(), running > 0, urls, lastError, devices);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemoteAccessConfig currentConfig() {
|
||||||
|
return configRepository.find().orElseGet(RemoteAccessConfig::disabledByDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Appairage -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nouveau code d'appairage (remplace le précédent).
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException si l'accès distant n'est pas ouvert
|
||||||
|
*/
|
||||||
|
public synchronized PairingCode newPairingCode() {
|
||||||
|
if (lanConnector.runningPort() <= 0) {
|
||||||
|
throw new IllegalStateException("Activez d'abord l'accès depuis le réseau local.");
|
||||||
|
}
|
||||||
|
String code = String.format("%06d", random.nextInt(1_000_000));
|
||||||
|
currentCode = new PairingCode(code, clock.instant().plus(CODE_TTL));
|
||||||
|
attemptsLeft = CODE_MAX_ATTEMPTS;
|
||||||
|
return currentCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Échange un code valide contre un jeton d'appareil (à poser en cookie). Le code est
|
||||||
|
* consommé : un second appareil demande un nouveau code.
|
||||||
|
*
|
||||||
|
* @throws PairingRejectedException code absent, faux, expiré ou trop d'essais
|
||||||
|
*/
|
||||||
|
public synchronized PairingResult pair(String code, String deviceName, String userAgent) {
|
||||||
|
Instant now = clock.instant();
|
||||||
|
pruneFailures(now);
|
||||||
|
if (recentFailures.size() >= GLOBAL_MAX_FAILURES_PER_MINUTE) {
|
||||||
|
throw new PairingRejectedException("Trop d'essais. Patientez une minute.");
|
||||||
|
}
|
||||||
|
if (currentCode == null || now.isAfter(currentCode.expiresAt())) {
|
||||||
|
currentCode = null;
|
||||||
|
recordFailure(now);
|
||||||
|
throw new PairingRejectedException("Aucun code valide : affichez un nouveau code sur le PC.");
|
||||||
|
}
|
||||||
|
if (code == null || !constantTimeEquals(code.trim(), currentCode.code())) {
|
||||||
|
recordFailure(now);
|
||||||
|
if (--attemptsLeft <= 0) {
|
||||||
|
currentCode = null;
|
||||||
|
throw new PairingRejectedException("Trop d'essais : affichez un nouveau code sur le PC.");
|
||||||
|
}
|
||||||
|
throw new PairingRejectedException("Code incorrect.");
|
||||||
|
}
|
||||||
|
currentCode = null;
|
||||||
|
|
||||||
|
String token = newToken();
|
||||||
|
RemoteDevice device = deviceRepository.save(RemoteDevice.builder()
|
||||||
|
.name(clean(deviceName, DEVICE_NAME_MAX, "Appareil"))
|
||||||
|
.tokenHash(sha256(token))
|
||||||
|
.userAgent(clean(userAgent, USER_AGENT_MAX, null))
|
||||||
|
.createdAt(now)
|
||||||
|
.lastSeenAt(now)
|
||||||
|
.build());
|
||||||
|
log.info("Accès distant : appareil appairé « {} »", device.getName());
|
||||||
|
return new PairingResult(token, PairedDevice.of(device));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Appareil correspondant au jeton présenté, s'il est connu (sinon : appairage requis). */
|
||||||
|
public Optional<RemoteDevice> authenticate(String token) {
|
||||||
|
if (token == null || token.isBlank()) return Optional.empty();
|
||||||
|
Optional<RemoteDevice> device = deviceRepository.findByTokenHash(sha256(token));
|
||||||
|
device.ifPresent(d -> {
|
||||||
|
Instant now = clock.instant();
|
||||||
|
if (d.getLastSeenAt() == null || d.getLastSeenAt().plus(TOUCH_INTERVAL).isBefore(now)) {
|
||||||
|
deviceRepository.touch(d.getId(), now);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Coupe l'accès d'un appareil. */
|
||||||
|
public boolean revoke(String deviceId) {
|
||||||
|
return deviceRepository.deleteById(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Port du connecteur réseau ouvert, ou -1 (pour le filtre : qui vient « de l'extérieur » ?). */
|
||||||
|
public int lanPort() {
|
||||||
|
return lanConnector.runningPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Outils -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private void recordFailure(Instant now) {
|
||||||
|
recentFailures.addLast(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pruneFailures(Instant now) {
|
||||||
|
Instant limit = now.minus(Duration.ofMinutes(1));
|
||||||
|
while (!recentFailures.isEmpty() && recentFailures.peekFirst().isBefore(limit)) {
|
||||||
|
recentFailures.removeFirst();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String newToken() {
|
||||||
|
byte[] bytes = new byte[32];
|
||||||
|
random.nextBytes(bytes);
|
||||||
|
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String sha256(String value) {
|
||||||
|
try {
|
||||||
|
byte[] digest = MessageDigest.getInstance("SHA-256").digest(value.getBytes(StandardCharsets.UTF_8));
|
||||||
|
return HexFormat.of().formatHex(digest);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new IllegalStateException("SHA-256 indisponible", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean constantTimeEquals(String a, String b) {
|
||||||
|
return MessageDigest.isEqual(a.getBytes(StandardCharsets.UTF_8), b.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String clean(String value, int max, String fallback) {
|
||||||
|
if (value == null || value.isBlank()) return fallback;
|
||||||
|
String trimmed = value.strip();
|
||||||
|
return trimmed.length() > max ? trimmed.substring(0, max) : trimmed;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* État de l'accès distant, pour l'écran Paramètres du PC.
|
||||||
|
*
|
||||||
|
* @param enabled accès activé (réglage enregistré)
|
||||||
|
* @param port port réseau dédié
|
||||||
|
* @param running connecteur réseau effectivement ouvert
|
||||||
|
* @param urls adresses à taper sur la tablette (une par interface réseau locale)
|
||||||
|
* @param lastError dernière erreur d'ouverture (ex. port occupé au démarrage), ou null
|
||||||
|
* @param devices appareils appairés
|
||||||
|
*/
|
||||||
|
public record RemoteAccessStatus(
|
||||||
|
boolean enabled,
|
||||||
|
int port,
|
||||||
|
boolean running,
|
||||||
|
List<String> urls,
|
||||||
|
String lastError,
|
||||||
|
List<PairedDevice> devices
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -21,6 +21,9 @@ public interface SessionRepository {
|
|||||||
/** Retourne UNE session active dans l'app (sémantique « legacy » — multi-actives possibles). */
|
/** Retourne UNE session active dans l'app (sémantique « legacy » — multi-actives possibles). */
|
||||||
Optional<Session> findActive();
|
Optional<Session> findActive();
|
||||||
|
|
||||||
|
/** Toutes les sessions en cours (toutes Parties confondues), la plus récente d'abord. */
|
||||||
|
List<Session> findAllActive();
|
||||||
|
|
||||||
/** Retourne la session active du Playthrough donné, s'il y en a une. */
|
/** Retourne la session active du Playthrough donné, s'il y en a une. */
|
||||||
Optional<Session> findActiveByPlaythroughId(String playthroughId);
|
Optional<Session> findActiveByPlaythroughId(String playthroughId);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.loremind.domain.remoteaccess;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Faits bruts sur la machine hôte, lus par le système (pas d'interprétation ici) :
|
||||||
|
* réseaux connectés avec leur catégorie Windows, et règles ENTRANTES du pare-feu qui
|
||||||
|
* visent l'exécutable de l'application.
|
||||||
|
*
|
||||||
|
* @param supported vérification possible sur ce système (Windows uniquement)
|
||||||
|
* @param program exécutable visé par les règles (DM Loremind.exe en bureau)
|
||||||
|
* @param networks réseaux connectés
|
||||||
|
* @param rules règles entrantes du pare-feu pour ce programme
|
||||||
|
*/
|
||||||
|
public record NetworkSnapshot(boolean supported, String program, List<Network> networks, List<FirewallRule> rules) {
|
||||||
|
|
||||||
|
/** Catégorie Windows : {@code Public}, {@code Private} ou {@code DomainAuthenticated}. */
|
||||||
|
public record Network(String name, String alias, String category) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param action {@code Allow} ou {@code Block}
|
||||||
|
* @param profile profils couverts : {@code Any}, ou liste comme {@code Private, Public}
|
||||||
|
* @param enabled {@code True} / {@code False}
|
||||||
|
*/
|
||||||
|
public record FirewallRule(String action, String profile, String enabled) {}
|
||||||
|
|
||||||
|
public static NetworkSnapshot unsupported() {
|
||||||
|
return new NetworkSnapshot(false, null, List.of(), List.of());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.loremind.domain.remoteaccess;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Réglage de l'accès distant (singleton) : activé ou non, et port réseau ouvert
|
||||||
|
* sur le réseau local quand il l'est.
|
||||||
|
*
|
||||||
|
* @param enabled accès depuis le réseau local autorisé
|
||||||
|
* @param port port réseau dédié (distinct du port local de l'application)
|
||||||
|
*/
|
||||||
|
public record RemoteAccessConfig(boolean enabled, int port) {
|
||||||
|
|
||||||
|
/** Port proposé par défaut : libre en pratique, et distinct du 8080 local. */
|
||||||
|
public static final int DEFAULT_PORT = 8765;
|
||||||
|
|
||||||
|
public static RemoteAccessConfig disabledByDefault() {
|
||||||
|
return new RemoteAccessConfig(false, DEFAULT_PORT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.loremind.domain.remoteaccess;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appareil (tablette, téléphone) autorisé à accéder à l'application de bureau depuis
|
||||||
|
* le réseau local, après appairage par code.
|
||||||
|
* <p>
|
||||||
|
* <b>Sécurité :</b> seule l'empreinte SHA-256 du jeton est conservée ; le jeton en
|
||||||
|
* clair n'existe que dans le cookie de l'appareil. Révoquer = supprimer la ligne.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class RemoteDevice {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/** Nom choisi à l'appairage (« Tablette de Léa »), pour s'y retrouver dans la liste. */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** Empreinte SHA-256 (hex) du jeton d'appareil. */
|
||||||
|
private String tokenHash;
|
||||||
|
|
||||||
|
private String userAgent;
|
||||||
|
|
||||||
|
private Instant createdAt;
|
||||||
|
|
||||||
|
private Instant lastSeenAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.loremind.domain.remoteaccess.ports;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.NetworkSnapshot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Port vers le système hôte pour que l'accès distant fonctionne vraiment : sans règle
|
||||||
|
* de pare-feu, ou sur un réseau classé « Public », Windows jette en silence les requêtes
|
||||||
|
* de la tablette (elle charge sans fin).
|
||||||
|
*/
|
||||||
|
public interface HostNetworkAccess {
|
||||||
|
|
||||||
|
/** Résultat de la demande d'autorisation dans le pare-feu. */
|
||||||
|
enum FirewallFixOutcome { APPLIED, CANCELLED, FAILED, UNSUPPORTED }
|
||||||
|
|
||||||
|
/** Lecture seule, sans droits administrateur. */
|
||||||
|
NetworkSnapshot inspect();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Autorise l'application en entrée sur les réseaux privés. Passe par la confirmation
|
||||||
|
* administrateur du système (UAC) : bloque jusqu'à la réponse de l'utilisateur.
|
||||||
|
*/
|
||||||
|
FirewallFixOutcome allowThroughFirewall();
|
||||||
|
|
||||||
|
/** Ouvre la page des réglages réseau du système (pour passer un Wi-Fi en « Privé »). */
|
||||||
|
void openNetworkSettings();
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.loremind.domain.remoteaccess.ports;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Port vers le « second guichet » réseau de l'application de bureau : un connecteur
|
||||||
|
* HTTP ouvert sur le réseau local (toutes interfaces) à côté du connecteur habituel,
|
||||||
|
* qui reste limité à la machine (127.0.0.1).
|
||||||
|
* <p>
|
||||||
|
* Tout ce qui arrive par ce connecteur vient d'un autre appareil (ou de la machine
|
||||||
|
* elle-même via son adresse réseau) et doit présenter un jeton d'appareil.
|
||||||
|
*/
|
||||||
|
public interface LanConnector {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ouvre le connecteur sur ce port (le referme d'abord s'il tournait sur un autre).
|
||||||
|
*
|
||||||
|
* @throws IllegalStateException si le port est déjà occupé ou ne peut pas être ouvert
|
||||||
|
*/
|
||||||
|
void start(int port);
|
||||||
|
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
/** Port du connecteur ouvert, ou -1 s'il est fermé. */
|
||||||
|
int runningPort();
|
||||||
|
|
||||||
|
/** Adresses IPv4 de la machine sur le réseau local (pour composer l'URL à taper). */
|
||||||
|
List<String> lanAddresses();
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.loremind.domain.remoteaccess.ports;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteAccessConfig;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/** Port de persistance du réglage d'accès distant (singleton). */
|
||||||
|
public interface RemoteAccessConfigRepository {
|
||||||
|
|
||||||
|
Optional<RemoteAccessConfig> find();
|
||||||
|
|
||||||
|
RemoteAccessConfig save(RemoteAccessConfig config);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.loremind.domain.remoteaccess.ports;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/** Port de persistance des appareils appairés. */
|
||||||
|
public interface RemoteDeviceRepository {
|
||||||
|
|
||||||
|
RemoteDevice save(RemoteDevice device);
|
||||||
|
|
||||||
|
Optional<RemoteDevice> findByTokenHash(String tokenHash);
|
||||||
|
|
||||||
|
List<RemoteDevice> findAll();
|
||||||
|
|
||||||
|
void touch(String id, Instant lastSeenAt);
|
||||||
|
|
||||||
|
boolean deleteById(String id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.loremind.infrastructure.desktop;
|
||||||
|
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessService;
|
||||||
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/** Mode bureau : rouvre l'accès distant au démarrage s'il avait été activé. */
|
||||||
|
@Component
|
||||||
|
@Profile("local")
|
||||||
|
public class RemoteAccessBootstrap {
|
||||||
|
|
||||||
|
private final RemoteAccessService remoteAccessService;
|
||||||
|
|
||||||
|
public RemoteAccessBootstrap(RemoteAccessService remoteAccessService) {
|
||||||
|
this.remoteAccessService = remoteAccessService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
|
public void reopenIfEnabled() {
|
||||||
|
remoteAccessService.applySavedConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,6 +70,13 @@ public class SystemTrayManager {
|
|||||||
open.addActionListener(e -> DesktopSingleInstance.openAppInBrowser());
|
open.addActionListener(e -> DesktopSingleInstance.openAppInBrowser());
|
||||||
popup.add(open);
|
popup.add(open);
|
||||||
|
|
||||||
|
// Acces distant : ouvre la section Parametres ou l'on active l'acces
|
||||||
|
// depuis une tablette et ou l'on affiche le code d'appairage.
|
||||||
|
MenuItem remote = new MenuItem("Connecter une tablette…");
|
||||||
|
remote.addActionListener(e -> DesktopSingleInstance.openUrl(
|
||||||
|
"http://localhost:" + DesktopUserConfig.runningPort() + "/settings?section=remote-access"));
|
||||||
|
popup.add(remote);
|
||||||
|
|
||||||
popup.addSeparator();
|
popup.addSeparator();
|
||||||
|
|
||||||
// Reglages : ouvre loremind.properties (port, identifiants admin) dans
|
// Reglages : ouvre loremind.properties (port, identifiants admin) dans
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package com.loremind.infrastructure.desktop;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.ports.LanConnector;
|
||||||
|
import org.apache.catalina.connector.Connector;
|
||||||
|
import org.apache.catalina.startup.Tomcat;
|
||||||
|
import org.apache.coyote.http11.AbstractHttp11Protocol;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
|
||||||
|
import org.springframework.boot.web.server.WebServer;
|
||||||
|
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Second connecteur HTTP de Tomcat, ouvert À CHAUD sur toutes les interfaces quand le MJ
|
||||||
|
* active l'accès distant (mode bureau uniquement).
|
||||||
|
* <p>
|
||||||
|
* Pourquoi un second connecteur plutôt que d'ouvrir le principal : le connecteur habituel
|
||||||
|
* reste sur 127.0.0.1 (aucun changement de comportement, pas d'alerte du pare-feu Windows
|
||||||
|
* chez qui n'active rien), et le port d'arrivée suffit à distinguer une requête locale d'une
|
||||||
|
* requête venue du réseau (cf. {@code RemoteAccessFilter}). Ouverture et fermeture sans
|
||||||
|
* redémarrer l'application.
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Profile("local")
|
||||||
|
public class TomcatLanConnector implements LanConnector {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(TomcatLanConnector.class);
|
||||||
|
|
||||||
|
/** Interfaces à ignorer pour composer l'URL : réseaux virtuels (VM, WSL, Docker, VPN…). */
|
||||||
|
private static final List<String> VIRTUAL_HINTS = List.of(
|
||||||
|
"virtual", "vmware", "vbox", "hyper-v", "vethernet", "docker", "wsl", "loopback", "tap-", "tun");
|
||||||
|
|
||||||
|
private final ApplicationContext context;
|
||||||
|
private Connector connector;
|
||||||
|
|
||||||
|
public TomcatLanConnector(ApplicationContext context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void start(int port) {
|
||||||
|
if (connector != null && connector.getPort() == port) return;
|
||||||
|
stop();
|
||||||
|
ensurePortFree(port);
|
||||||
|
|
||||||
|
Tomcat tomcat = tomcat();
|
||||||
|
Connector main = tomcat.getConnector();
|
||||||
|
Connector lan = new Connector(main.getProtocolHandlerClassName());
|
||||||
|
lan.setPort(port);
|
||||||
|
lan.setProperty("address", "0.0.0.0");
|
||||||
|
// Mêmes limites d'upload que le connecteur principal (imports PDF volumineux).
|
||||||
|
lan.setMaxPostSize(main.getMaxPostSize());
|
||||||
|
if (main.getProtocolHandler() instanceof AbstractHttp11Protocol<?> mainProtocol
|
||||||
|
&& lan.getProtocolHandler() instanceof AbstractHttp11Protocol<?> lanProtocol) {
|
||||||
|
lanProtocol.setMaxSwallowSize(mainProtocol.getMaxSwallowSize());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
tomcat.getService().addConnector(lan); // démarre le connecteur : le service tourne déjà
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new IllegalStateException("Impossible d'ouvrir le port " + port + " : " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
connector = lan;
|
||||||
|
log.info("Accès distant : connecteur réseau ouvert sur le port {}", port);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void stop() {
|
||||||
|
if (connector == null) return;
|
||||||
|
try {
|
||||||
|
tomcat().getService().removeConnector(connector);
|
||||||
|
connector.destroy();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Fermeture du connecteur réseau incomplète : {}", e.getMessage());
|
||||||
|
}
|
||||||
|
log.info("Accès distant : connecteur réseau fermé (port {})", connector.getPort());
|
||||||
|
connector = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized int runningPort() {
|
||||||
|
return connector != null ? connector.getPort() : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> lanAddresses() {
|
||||||
|
try {
|
||||||
|
return Collections.list(NetworkInterface.getNetworkInterfaces()).stream()
|
||||||
|
.filter(TomcatLanConnector::isPhysicalAndUp)
|
||||||
|
.flatMap(nic -> Collections.list(nic.getInetAddresses()).stream())
|
||||||
|
.filter(a -> a instanceof Inet4Address && a.isSiteLocalAddress())
|
||||||
|
.map(a -> a.getHostAddress())
|
||||||
|
.distinct()
|
||||||
|
// Box domestique d'abord (192.168.x), puis 10.x / 172.16-31.x.
|
||||||
|
.sorted(Comparator.comparing((String ip) -> !ip.startsWith("192.168.")).thenComparing(ip -> ip))
|
||||||
|
.toList();
|
||||||
|
} catch (SocketException e) {
|
||||||
|
log.warn("Lecture des interfaces réseau impossible : {}", e.getMessage());
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isPhysicalAndUp(NetworkInterface nic) {
|
||||||
|
try {
|
||||||
|
if (!nic.isUp() || nic.isLoopback() || nic.isVirtual() || nic.isPointToPoint()) return false;
|
||||||
|
} catch (SocketException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String label = (nic.getName() + " " + nic.getDisplayName()).toLowerCase(Locale.ROOT);
|
||||||
|
return VIRTUAL_HINTS.stream().noneMatch(label::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Vérification préalable pour un message clair (sinon Tomcat ne log qu'une trace obscure). */
|
||||||
|
private static void ensurePortFree(int port) {
|
||||||
|
try (ServerSocket probe = new ServerSocket()) {
|
||||||
|
probe.setReuseAddress(false);
|
||||||
|
probe.bind(new InetSocketAddress(port));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Le port " + port + " est déjà utilisé par une autre application.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tomcat tomcat() {
|
||||||
|
if (context instanceof ServletWebServerApplicationContext web) {
|
||||||
|
WebServer server = web.getWebServer();
|
||||||
|
if (server instanceof TomcatWebServer tomcatServer) {
|
||||||
|
return tomcatServer.getTomcat();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Serveur web embarqué indisponible.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,208 @@
|
|||||||
|
package com.loremind.infrastructure.desktop;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.loremind.domain.remoteaccess.NetworkSnapshot;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.HostNetworkAccess;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accès au réseau et au pare-feu de Windows pour l'accès distant (mode bureau).
|
||||||
|
* <p>
|
||||||
|
* Lecture via PowerShell, sans droits administrateur. L'autorisation dans le pare-feu
|
||||||
|
* passe par {@code Start-Process -Verb RunAs} : Windows affiche sa confirmation
|
||||||
|
* administrateur (UAC) et l'utilisateur garde la main. La règle créée n'ouvre DM Loremind
|
||||||
|
* qu'aux réseaux PRIVÉS ; un Wi-Fi classé « Public » reste à basculer par l'utilisateur
|
||||||
|
* (réglage système, jamais modifié par l'application).
|
||||||
|
* <p>
|
||||||
|
* Les scripts sont passés en {@code -EncodedCommand} (UTF-16LE base64) : aucun problème de
|
||||||
|
* guillemets ni d'accents. Le seul paramètre variable est le chemin de l'exécutable,
|
||||||
|
* fourni par le système (pas par l'utilisateur), et échappé pour une chaîne PowerShell.
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Profile("local")
|
||||||
|
public class WindowsHostNetworkAccess implements HostNetworkAccess {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WindowsHostNetworkAccess.class);
|
||||||
|
|
||||||
|
static final String RULE_NAME = "DM Loremind (accès tablette)";
|
||||||
|
private static final long INSPECT_TIMEOUT_S = 20;
|
||||||
|
/** Le temps pour l'utilisateur de lire et de répondre à la fenêtre UAC. */
|
||||||
|
private static final long ELEVATION_TIMEOUT_S = 180;
|
||||||
|
/** Code Windows ERROR_CANCELLED : l'utilisateur a refusé la confirmation administrateur. */
|
||||||
|
private static final int EXIT_CANCELLED = 1223;
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
public WindowsHostNetworkAccess(ObjectMapper objectMapper) {
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkSnapshot inspect() {
|
||||||
|
String program = currentProgram();
|
||||||
|
if (!isWindows() || program == null) return NetworkSnapshot.unsupported();
|
||||||
|
try {
|
||||||
|
String json = runPowerShell(inspectScript(program), INSPECT_TIMEOUT_S).output();
|
||||||
|
return parseSnapshot(objectMapper, program, json);
|
||||||
|
} catch (IOException | RuntimeException e) {
|
||||||
|
log.warn("Accès distant : lecture du réseau / pare-feu impossible : {}", e.getMessage());
|
||||||
|
return NetworkSnapshot.unsupported();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return NetworkSnapshot.unsupported();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FirewallFixOutcome allowThroughFirewall() {
|
||||||
|
String program = currentProgram();
|
||||||
|
if (!isWindows() || program == null) return FirewallFixOutcome.UNSUPPORTED;
|
||||||
|
String outer = "try {\n"
|
||||||
|
+ " $p = Start-Process -FilePath 'powershell.exe' -Verb RunAs -WindowStyle Hidden -Wait -PassThru "
|
||||||
|
+ "-ArgumentList @('-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-EncodedCommand','"
|
||||||
|
+ encode(allowScript(program)) + "')\n"
|
||||||
|
+ " exit $p.ExitCode\n"
|
||||||
|
+ "} catch { exit " + EXIT_CANCELLED + " }\n";
|
||||||
|
try {
|
||||||
|
int exit = runPowerShell(outer, ELEVATION_TIMEOUT_S).exitCode();
|
||||||
|
FirewallFixOutcome outcome = exit == 0 ? FirewallFixOutcome.APPLIED
|
||||||
|
: exit == EXIT_CANCELLED ? FirewallFixOutcome.CANCELLED : FirewallFixOutcome.FAILED;
|
||||||
|
log.info("Accès distant : autorisation pare-feu → {}", outcome);
|
||||||
|
return outcome;
|
||||||
|
} catch (IOException | RuntimeException e) {
|
||||||
|
log.warn("Accès distant : autorisation pare-feu impossible : {}", e.getMessage());
|
||||||
|
return FirewallFixOutcome.FAILED;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return FirewallFixOutcome.FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openNetworkSettings() {
|
||||||
|
if (!isWindows()) return;
|
||||||
|
try {
|
||||||
|
// « État du réseau » : le réseau connecté et son bouton « Propriétés » (type de profil).
|
||||||
|
new ProcessBuilder("cmd", "/c", "start", "", "ms-settings:network-status").start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Ouverture des réglages réseau impossible : {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Scripts --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Réseaux connectés + règles entrantes visant ce programme (chemins avec %VARIABLES% compris). */
|
||||||
|
static String inspectScript(String program) {
|
||||||
|
return "$ErrorActionPreference = 'SilentlyContinue'\n"
|
||||||
|
// Sortie en UTF-8 : sinon la page de codes de la console abîme les noms de réseau accentués.
|
||||||
|
+ "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8\n"
|
||||||
|
+ "$p = '" + psQuote(program) + "'\n"
|
||||||
|
+ "$nets =@(Get-NetConnectionProfile | ForEach-Object { [pscustomobject]@{ name = $_.Name; "
|
||||||
|
+ "alias = $_.InterfaceAlias; category = $_.NetworkCategory.ToString() } })\n"
|
||||||
|
+ "$rules = @(Get-NetFirewallApplicationFilter | Where-Object { $_.Program -and "
|
||||||
|
+ "([Environment]::ExpandEnvironmentVariables($_.Program) -ieq $p) } | Get-NetFirewallRule | "
|
||||||
|
+ "Where-Object { $_.Direction.ToString() -eq 'Inbound' } | ForEach-Object { [pscustomobject]@{ "
|
||||||
|
+ "action = $_.Action.ToString(); profile = $_.Profile.ToString(); enabled = $_.Enabled.ToString() } })\n"
|
||||||
|
+ "[pscustomobject]@{ networks = $nets; rules = $rules } | ConvertTo-Json -Depth 4 -Compress\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exécuté ÉLEVÉ : retire les blocages entrants visant CE programme (créés par un « Annuler »
|
||||||
|
* dans la fenêtre du pare-feu, ils l'emporteraient sur toute autorisation), remplace notre
|
||||||
|
* propre règle si elle existe, puis autorise sur les réseaux privés uniquement.
|
||||||
|
*/
|
||||||
|
static String allowScript(String program) {
|
||||||
|
String name = psQuote(RULE_NAME);
|
||||||
|
return "try {\n"
|
||||||
|
+ " $p = '" + psQuote(program) + "'\n"
|
||||||
|
+ " Get-NetFirewallApplicationFilter | Where-Object { $_.Program -and "
|
||||||
|
+ "([Environment]::ExpandEnvironmentVariables($_.Program) -ieq $p) } | Get-NetFirewallRule | "
|
||||||
|
+ "Where-Object { $_.Direction.ToString() -eq 'Inbound' -and $_.Action.ToString() -eq 'Block' } | "
|
||||||
|
+ "Remove-NetFirewallRule\n"
|
||||||
|
+ " Get-NetFirewallRule -DisplayName '" + name + "' -ErrorAction SilentlyContinue | Remove-NetFirewallRule\n"
|
||||||
|
+ " New-NetFirewallRule -DisplayName '" + name + "' -Direction Inbound -Program $p -Action Allow "
|
||||||
|
+ "-Profile Private -ErrorAction Stop | Out-Null\n"
|
||||||
|
+ " exit 0\n"
|
||||||
|
+ "} catch { exit 2 }\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static NetworkSnapshot parseSnapshot(ObjectMapper mapper, String program, String json) throws IOException {
|
||||||
|
JsonNode root = mapper.readTree(json == null || json.isBlank() ? "{}" : json.trim());
|
||||||
|
List<NetworkSnapshot.Network> networks = new ArrayList<>();
|
||||||
|
for (JsonNode n : array(root.path("networks"))) {
|
||||||
|
networks.add(new NetworkSnapshot.Network(text(n, "name"), text(n, "alias"), text(n, "category")));
|
||||||
|
}
|
||||||
|
List<NetworkSnapshot.FirewallRule> rules = new ArrayList<>();
|
||||||
|
for (JsonNode r : array(root.path("rules"))) {
|
||||||
|
rules.add(new NetworkSnapshot.FirewallRule(text(r, "action"), text(r, "profile"), text(r, "enabled")));
|
||||||
|
}
|
||||||
|
return new NetworkSnapshot(true, program, networks, rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ConvertTo-Json écrit un objet seul (pas un tableau) quand la liste n'a qu'un élément. */
|
||||||
|
private static Iterable<JsonNode> array(JsonNode node) {
|
||||||
|
if (node == null || node.isMissingNode() || node.isNull()) return List.of();
|
||||||
|
return node.isArray() ? node : List.of(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String text(JsonNode node, String field) {
|
||||||
|
JsonNode v = node.get(field);
|
||||||
|
return v == null || v.isNull() ? null : v.asText();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String psQuote(String value) {
|
||||||
|
return value.replace("'", "''");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String encode(String script) {
|
||||||
|
return Base64.getEncoder().encodeToString(script.getBytes(StandardCharsets.UTF_16LE));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Exécution ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private record Result(int exitCode, String output) {}
|
||||||
|
|
||||||
|
private static Result runPowerShell(String script, long timeoutSeconds) throws IOException, InterruptedException {
|
||||||
|
Process process = new ProcessBuilder("powershell.exe", "-NoProfile", "-NonInteractive",
|
||||||
|
"-ExecutionPolicy", "Bypass", "-EncodedCommand", encode(script))
|
||||||
|
.redirectError(ProcessBuilder.Redirect.DISCARD)
|
||||||
|
.start();
|
||||||
|
process.getOutputStream().close();
|
||||||
|
// Lecture en parallèle : un tampon de sortie plein bloquerait le processus avant sa fin.
|
||||||
|
CompletableFuture<String> output = CompletableFuture.supplyAsync(() -> {
|
||||||
|
try (InputStream out = process.getInputStream()) {
|
||||||
|
return new String(out.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!process.waitFor(timeoutSeconds, TimeUnit.SECONDS)) {
|
||||||
|
process.destroyForcibly();
|
||||||
|
throw new IOException("PowerShell n'a pas répondu en " + timeoutSeconds + " s");
|
||||||
|
}
|
||||||
|
return new Result(process.exitValue(), output.join());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isWindows() {
|
||||||
|
return System.getProperty("os.name", "").toLowerCase(Locale.ROOT).startsWith("windows");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Exécutable du processus courant : DM Loremind.exe en bureau (java.exe en développement). */
|
||||||
|
private static String currentProgram() {
|
||||||
|
return ProcessHandle.current().info().command().orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package com.loremind.infrastructure.persistence.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entité JPA du réglage d'accès distant (migration V25). Singleton : une seule ligne,
|
||||||
|
* {@code id = "current"}, comme la licence.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "remote_access_config")
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class RemoteAccessConfigJpaEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private Instant updatedAt;
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package com.loremind.infrastructure.persistence.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/** Entité JPA d'un appareil appairé pour l'accès distant (migration V25). */
|
||||||
|
@Entity
|
||||||
|
@Table(name = "remote_devices")
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class RemoteDeviceJpaEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 100)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "token_hash", nullable = false, length = 64, unique = true)
|
||||||
|
private String tokenHash;
|
||||||
|
|
||||||
|
@Column(name = "user_agent", length = 300)
|
||||||
|
private String userAgent;
|
||||||
|
|
||||||
|
@Column(name = "created_at", nullable = false, updatable = false)
|
||||||
|
private Instant createdAt;
|
||||||
|
|
||||||
|
@Column(name = "last_seen_at")
|
||||||
|
private Instant lastSeenAt;
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package com.loremind.infrastructure.persistence.jpa;
|
||||||
|
|
||||||
|
import com.loremind.infrastructure.persistence.entity.RemoteAccessConfigJpaEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface RemoteAccessConfigJpaRepository extends JpaRepository<RemoteAccessConfigJpaEntity, String> {
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package com.loremind.infrastructure.persistence.jpa;
|
||||||
|
|
||||||
|
import com.loremind.infrastructure.persistence.entity.RemoteDeviceJpaEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface RemoteDeviceJpaRepository extends JpaRepository<RemoteDeviceJpaEntity, Long> {
|
||||||
|
|
||||||
|
Optional<RemoteDeviceJpaEntity> findByTokenHash(String tokenHash);
|
||||||
|
|
||||||
|
/** Mise à jour ciblée (pas de relecture de l'entité à chaque requête d'une tablette). */
|
||||||
|
@Modifying
|
||||||
|
@Transactional
|
||||||
|
@Query("update RemoteDeviceJpaEntity d set d.lastSeenAt = :seenAt where d.id = :id")
|
||||||
|
void touch(@Param("id") Long id, @Param("seenAt") Instant seenAt);
|
||||||
|
}
|
||||||
+2
@@ -17,5 +17,7 @@ public interface SessionJpaRepository extends JpaRepository<SessionJpaEntity, Lo
|
|||||||
|
|
||||||
Optional<SessionJpaEntity> findFirstByEndedAtIsNull();
|
Optional<SessionJpaEntity> findFirstByEndedAtIsNull();
|
||||||
|
|
||||||
|
List<SessionJpaEntity> findByEndedAtIsNullOrderByStartedAtDesc();
|
||||||
|
|
||||||
Optional<SessionJpaEntity> findFirstByPlaythroughIdAndEndedAtIsNull(Long playthroughId);
|
Optional<SessionJpaEntity> findFirstByPlaythroughIdAndEndedAtIsNull(Long playthroughId);
|
||||||
}
|
}
|
||||||
|
|||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.loremind.infrastructure.persistence.postgres;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteAccessConfig;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteAccessConfigRepository;
|
||||||
|
import com.loremind.infrastructure.persistence.entity.RemoteAccessConfigJpaEntity;
|
||||||
|
import com.loremind.infrastructure.persistence.jpa.RemoteAccessConfigJpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class PostgresRemoteAccessConfigRepository implements RemoteAccessConfigRepository {
|
||||||
|
|
||||||
|
static final String CURRENT_ID = "current";
|
||||||
|
|
||||||
|
private final RemoteAccessConfigJpaRepository jpa;
|
||||||
|
|
||||||
|
public PostgresRemoteAccessConfigRepository(RemoteAccessConfigJpaRepository jpa) {
|
||||||
|
this.jpa = jpa;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<RemoteAccessConfig> find() {
|
||||||
|
return jpa.findById(CURRENT_ID).map(e -> new RemoteAccessConfig(e.isEnabled(), e.getPort()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteAccessConfig save(RemoteAccessConfig config) {
|
||||||
|
jpa.save(RemoteAccessConfigJpaEntity.builder()
|
||||||
|
.id(CURRENT_ID)
|
||||||
|
.enabled(config.enabled())
|
||||||
|
.port(config.port())
|
||||||
|
.updatedAt(Instant.now())
|
||||||
|
.build());
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
package com.loremind.infrastructure.persistence.postgres;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteDeviceRepository;
|
||||||
|
import com.loremind.infrastructure.persistence.entity.RemoteDeviceJpaEntity;
|
||||||
|
import com.loremind.infrastructure.persistence.jpa.RemoteDeviceJpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class PostgresRemoteDeviceRepository implements RemoteDeviceRepository {
|
||||||
|
|
||||||
|
private final RemoteDeviceJpaRepository jpa;
|
||||||
|
|
||||||
|
public PostgresRemoteDeviceRepository(RemoteDeviceJpaRepository jpa) {
|
||||||
|
this.jpa = jpa;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteDevice save(RemoteDevice device) {
|
||||||
|
RemoteDeviceJpaEntity entity = RemoteDeviceJpaEntity.builder()
|
||||||
|
.id(device.getId() != null ? Long.parseLong(device.getId()) : null)
|
||||||
|
.name(device.getName())
|
||||||
|
.tokenHash(device.getTokenHash())
|
||||||
|
.userAgent(device.getUserAgent())
|
||||||
|
.createdAt(device.getCreatedAt() != null ? device.getCreatedAt() : Instant.now())
|
||||||
|
.lastSeenAt(device.getLastSeenAt())
|
||||||
|
.build();
|
||||||
|
return toDomain(jpa.save(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<RemoteDevice> findByTokenHash(String tokenHash) {
|
||||||
|
return jpa.findByTokenHash(tokenHash).map(this::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RemoteDevice> findAll() {
|
||||||
|
return jpa.findAll().stream().map(this::toDomain).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touch(String id, Instant lastSeenAt) {
|
||||||
|
jpa.touch(Long.parseLong(id), lastSeenAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteById(String id) {
|
||||||
|
Long key = Long.parseLong(id);
|
||||||
|
if (!jpa.existsById(key)) return false;
|
||||||
|
jpa.deleteById(key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemoteDevice toDomain(RemoteDeviceJpaEntity e) {
|
||||||
|
return RemoteDevice.builder()
|
||||||
|
.id(String.valueOf(e.getId()))
|
||||||
|
.name(e.getName())
|
||||||
|
.tokenHash(e.getTokenHash())
|
||||||
|
.userAgent(e.getUserAgent())
|
||||||
|
.createdAt(e.getCreatedAt())
|
||||||
|
.lastSeenAt(e.getLastSeenAt())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -52,6 +52,13 @@ public class PostgresSessionRepository implements SessionRepository {
|
|||||||
return jpaRepository.findFirstByEndedAtIsNull().map(this::toDomain);
|
return jpaRepository.findFirstByEndedAtIsNull().map(this::toDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Session> findAllActive() {
|
||||||
|
return jpaRepository.findByEndedAtIsNullOrderByStartedAtDesc().stream()
|
||||||
|
.map(this::toDomain)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Session> findActiveByPlaythroughId(String playthroughId) {
|
public Optional<Session> findActiveByPlaythroughId(String playthroughId) {
|
||||||
return jpaRepository.findFirstByPlaythroughIdAndEndedAtIsNull(Long.parseLong(playthroughId))
|
return jpaRepository.findFirstByPlaythroughIdAndEndedAtIsNull(Long.parseLong(playthroughId))
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.loremind.infrastructure.web.config;
|
||||||
|
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessService;
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Garde de l'accès distant (mode bureau). Ne concerne QUE les requêtes arrivées par le
|
||||||
|
* connecteur réseau local (port dédié) : celles du connecteur habituel (127.0.0.1) passent
|
||||||
|
* sans changement.
|
||||||
|
* <ul>
|
||||||
|
* <li>front statique (hors {@code /api/}) : libre — la tablette doit pouvoir afficher l'écran d'appairage ;</li>
|
||||||
|
* <li>{@code /api/config}, {@code /api/version}, appairage : libres ;</li>
|
||||||
|
* <li>administration (Paramètres, données, mises à jour, licence) : refusée, toujours, même appairé ;</li>
|
||||||
|
* <li>tout le reste de l'API : cookie d'appareil valide, sinon 401 {@code remote_pairing_required}.</li>
|
||||||
|
* </ul>
|
||||||
|
* Pas un {@code @Component} : instancié par {@link SecurityConfig} pour ne pas être enregistré
|
||||||
|
* deux fois (chaîne de sécurité + filtre servlet automatique).
|
||||||
|
*/
|
||||||
|
public class RemoteAccessFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
public static final String DEVICE_COOKIE = "lm_device";
|
||||||
|
|
||||||
|
private static final List<String> PUBLIC_PATHS = List.of(
|
||||||
|
"/api/config", "/api/version", "/api/remote-access/pair", "/api/remote-access/session");
|
||||||
|
private static final List<String> LOCAL_ONLY_PREFIXES = List.of(
|
||||||
|
"/api/settings", "/api/admin", "/api/license");
|
||||||
|
|
||||||
|
private final RemoteAccessService remoteAccessService;
|
||||||
|
|
||||||
|
public RemoteAccessFilter(RemoteAccessService remoteAccessService) {
|
||||||
|
this.remoteAccessService = remoteAccessService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
if (!isFromLan(request, remoteAccessService.lanPort())) {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String path = request.getRequestURI();
|
||||||
|
if (!path.startsWith("/api/") || PUBLIC_PATHS.contains(path)) {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (LOCAL_ONLY_PREFIXES.stream().anyMatch(path::startsWith)) {
|
||||||
|
reject(response, HttpServletResponse.SC_FORBIDDEN, "remote_forbidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (remoteAccessService.authenticate(deviceToken(request)).isPresent()) {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reject(response, HttpServletResponse.SC_UNAUTHORIZED, "remote_pairing_required");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Arrivée par le connecteur réseau local ? (le port d'arrivée suffit : l'autre connecteur est sur 127.0.0.1). */
|
||||||
|
public static boolean isFromLan(HttpServletRequest request, int lanPort) {
|
||||||
|
return lanPort > 0 && request.getLocalPort() == lanPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String deviceToken(HttpServletRequest request) {
|
||||||
|
Cookie[] cookies = request.getCookies();
|
||||||
|
if (cookies == null) return null;
|
||||||
|
for (Cookie cookie : cookies) {
|
||||||
|
if (DEVICE_COOKIE.equals(cookie.getName())) return cookie.getValue();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void reject(HttpServletResponse response, int status, String error) throws IOException {
|
||||||
|
response.setStatus(status);
|
||||||
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
response.getWriter().write("{\"error\":\"" + error + "\"}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.loremind.infrastructure.web.config;
|
package com.loremind.infrastructure.web.config;
|
||||||
|
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessService;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -14,6 +16,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration Spring Security.
|
* Configuration Spring Security.
|
||||||
@@ -24,6 +27,9 @@ import org.springframework.security.web.SecurityFilterChain;
|
|||||||
* l'UI elle-meme n'est pas authentifiee (trust model : reseau local ou
|
* l'UI elle-meme n'est pas authentifiee (trust model : reseau local ou
|
||||||
* reverse-proxy front amont).
|
* reverse-proxy front amont).
|
||||||
* <p>
|
* <p>
|
||||||
|
* Mode bureau : l'acces depuis une tablette passe par un connecteur reseau dedie,
|
||||||
|
* garde par {@link RemoteAccessFilter} (jeton d'appareil obtenu par code d'appairage).
|
||||||
|
* <p>
|
||||||
* Fail-closed : refuse de demarrer si admin.password n'est pas defini.
|
* Fail-closed : refuse de demarrer si admin.password n'est pas defini.
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -58,7 +64,15 @@ public class SecurityConfig {
|
|||||||
// S4502 : API stateless en HTTP Basic sans cookie — CSRF sans objet (voir javadoc de classe).
|
// S4502 : API stateless en HTTP Basic sans cookie — CSRF sans objet (voir javadoc de classe).
|
||||||
@SuppressWarnings("java:S4502")
|
@SuppressWarnings("java:S4502")
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http,
|
||||||
|
ObjectProvider<RemoteAccessService> remoteAccess) throws Exception {
|
||||||
|
// Mode bureau : garde de l'accès distant (tablette sur le réseau local), placée AVANT
|
||||||
|
// le HTTP Basic pour qu'un appareil du réseau ne puisse même pas tenter le mot de
|
||||||
|
// passe admin. Absente en Docker (le service n'existe que sous le profil local).
|
||||||
|
RemoteAccessService remoteAccessService = remoteAccess.getIfAvailable();
|
||||||
|
if (remoteAccessService != null) {
|
||||||
|
http.addFilterBefore(new RemoteAccessFilter(remoteAccessService), BasicAuthenticationFilter.class);
|
||||||
|
}
|
||||||
http
|
http
|
||||||
// API stateless : pas de session, pas de cookie => CSRF sans objet.
|
// API stateless : pas de session, pas de cookie => CSRF sans objet.
|
||||||
// Les credentials HTTP Basic sont envoyes a chaque requete, donc
|
// Les credentials HTTP Basic sont envoyes a chaque requete, donc
|
||||||
|
|||||||
+14
-2
@@ -13,15 +13,18 @@ import com.loremind.domain.campaigncontext.ports.NpcRepository;
|
|||||||
import com.loremind.domain.campaigncontext.ports.QuestRepository;
|
import com.loremind.domain.campaigncontext.ports.QuestRepository;
|
||||||
import com.loremind.domain.campaigncontext.ports.RandomTableRepository;
|
import com.loremind.domain.campaigncontext.ports.RandomTableRepository;
|
||||||
import com.loremind.domain.campaigncontext.ports.SceneRepository;
|
import com.loremind.domain.campaigncontext.ports.SceneRepository;
|
||||||
|
import com.loremind.domain.playcontext.ports.PlaythroughRepository;
|
||||||
import com.loremind.infrastructure.web.dto.campaigncontext.ArcDTO;
|
import com.loremind.infrastructure.web.dto.campaigncontext.ArcDTO;
|
||||||
import com.loremind.infrastructure.web.dto.campaigncontext.ChapterDTO;
|
import com.loremind.infrastructure.web.dto.campaigncontext.ChapterDTO;
|
||||||
import com.loremind.infrastructure.web.dto.campaigncontext.NpcDTO;
|
import com.loremind.infrastructure.web.dto.campaigncontext.NpcDTO;
|
||||||
import com.loremind.infrastructure.web.dto.campaigncontext.QuestDTO;
|
import com.loremind.infrastructure.web.dto.campaigncontext.QuestDTO;
|
||||||
import com.loremind.infrastructure.web.dto.campaigncontext.RandomTableDTO;
|
import com.loremind.infrastructure.web.dto.campaigncontext.RandomTableDTO;
|
||||||
import com.loremind.infrastructure.web.dto.campaigncontext.SceneDTO;
|
import com.loremind.infrastructure.web.dto.campaigncontext.SceneDTO;
|
||||||
|
import com.loremind.infrastructure.web.dto.playcontext.PlaythroughDTO;
|
||||||
import com.loremind.infrastructure.web.mapper.ArcMapper;
|
import com.loremind.infrastructure.web.mapper.ArcMapper;
|
||||||
import com.loremind.infrastructure.web.mapper.ChapterMapper;
|
import com.loremind.infrastructure.web.mapper.ChapterMapper;
|
||||||
import com.loremind.infrastructure.web.mapper.NpcMapper;
|
import com.loremind.infrastructure.web.mapper.NpcMapper;
|
||||||
|
import com.loremind.infrastructure.web.mapper.PlaythroughMapper;
|
||||||
import com.loremind.infrastructure.web.mapper.QuestMapper;
|
import com.loremind.infrastructure.web.mapper.QuestMapper;
|
||||||
import com.loremind.infrastructure.web.mapper.RandomTableMapper;
|
import com.loremind.infrastructure.web.mapper.RandomTableMapper;
|
||||||
import com.loremind.infrastructure.web.mapper.SceneMapper;
|
import com.loremind.infrastructure.web.mapper.SceneMapper;
|
||||||
@@ -37,7 +40,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Endpoint AGRÉGÉ de l'arbre de campagne : tout ce dont la sidebar a besoin en UNE
|
* Endpoint AGRÉGÉ de l'arbre de campagne : tout ce dont la sidebar a besoin en UNE
|
||||||
* requête HTTP — arcs → chapitres → scènes, PNJ, tables, ennemis, quêtes et readiness.
|
* requête HTTP — arcs → chapitres → scènes, PNJ, tables, ennemis, quêtes, parties et readiness.
|
||||||
*
|
*
|
||||||
* <p>Remplace la rafale d'appels du front (~1 + N arcs + M chapitres + 5 listes ≈ 15-20
|
* <p>Remplace la rafale d'appels du front (~1 + N arcs + M chapitres + 5 listes ≈ 15-20
|
||||||
* requêtes À CHAQUE navigation) : la latence HTTP par appel dominait le temps de rendu
|
* requêtes À CHAQUE navigation) : la latence HTTP par appel dominait le temps de rendu
|
||||||
@@ -56,6 +59,7 @@ public class CampaignTreeController {
|
|||||||
private final RandomTableRepository randomTableRepository;
|
private final RandomTableRepository randomTableRepository;
|
||||||
private final EnemyRepository enemyRepository;
|
private final EnemyRepository enemyRepository;
|
||||||
private final QuestRepository questRepository;
|
private final QuestRepository questRepository;
|
||||||
|
private final PlaythroughRepository playthroughRepository;
|
||||||
private final CampaignReadinessService readinessService;
|
private final CampaignReadinessService readinessService;
|
||||||
private final ArcMapper arcMapper;
|
private final ArcMapper arcMapper;
|
||||||
private final ChapterMapper chapterMapper;
|
private final ChapterMapper chapterMapper;
|
||||||
@@ -63,6 +67,7 @@ public class CampaignTreeController {
|
|||||||
private final NpcMapper npcMapper;
|
private final NpcMapper npcMapper;
|
||||||
private final RandomTableMapper randomTableMapper;
|
private final RandomTableMapper randomTableMapper;
|
||||||
private final QuestMapper questMapper;
|
private final QuestMapper questMapper;
|
||||||
|
private final PlaythroughMapper playthroughMapper;
|
||||||
|
|
||||||
// S107 (trop de paramètres) : constructeur d'INJECTION pur, sans logique — l'endpoint
|
// S107 (trop de paramètres) : constructeur d'INJECTION pur, sans logique — l'endpoint
|
||||||
// est un agrégat volontaire (une requête pour toute la sidebar), il consomme donc
|
// est un agrégat volontaire (une requête pour toute la sidebar), il consomme donc
|
||||||
@@ -77,13 +82,15 @@ public class CampaignTreeController {
|
|||||||
RandomTableRepository randomTableRepository,
|
RandomTableRepository randomTableRepository,
|
||||||
EnemyRepository enemyRepository,
|
EnemyRepository enemyRepository,
|
||||||
QuestRepository questRepository,
|
QuestRepository questRepository,
|
||||||
|
PlaythroughRepository playthroughRepository,
|
||||||
CampaignReadinessService readinessService,
|
CampaignReadinessService readinessService,
|
||||||
ArcMapper arcMapper,
|
ArcMapper arcMapper,
|
||||||
ChapterMapper chapterMapper,
|
ChapterMapper chapterMapper,
|
||||||
SceneMapper sceneMapper,
|
SceneMapper sceneMapper,
|
||||||
NpcMapper npcMapper,
|
NpcMapper npcMapper,
|
||||||
RandomTableMapper randomTableMapper,
|
RandomTableMapper randomTableMapper,
|
||||||
QuestMapper questMapper) {
|
QuestMapper questMapper,
|
||||||
|
PlaythroughMapper playthroughMapper) {
|
||||||
this.campaignRepository = campaignRepository;
|
this.campaignRepository = campaignRepository;
|
||||||
this.arcRepository = arcRepository;
|
this.arcRepository = arcRepository;
|
||||||
this.chapterRepository = chapterRepository;
|
this.chapterRepository = chapterRepository;
|
||||||
@@ -92,6 +99,7 @@ public class CampaignTreeController {
|
|||||||
this.randomTableRepository = randomTableRepository;
|
this.randomTableRepository = randomTableRepository;
|
||||||
this.enemyRepository = enemyRepository;
|
this.enemyRepository = enemyRepository;
|
||||||
this.questRepository = questRepository;
|
this.questRepository = questRepository;
|
||||||
|
this.playthroughRepository = playthroughRepository;
|
||||||
this.readinessService = readinessService;
|
this.readinessService = readinessService;
|
||||||
this.arcMapper = arcMapper;
|
this.arcMapper = arcMapper;
|
||||||
this.chapterMapper = chapterMapper;
|
this.chapterMapper = chapterMapper;
|
||||||
@@ -99,6 +107,7 @@ public class CampaignTreeController {
|
|||||||
this.npcMapper = npcMapper;
|
this.npcMapper = npcMapper;
|
||||||
this.randomTableMapper = randomTableMapper;
|
this.randomTableMapper = randomTableMapper;
|
||||||
this.questMapper = questMapper;
|
this.questMapper = questMapper;
|
||||||
|
this.playthroughMapper = playthroughMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,6 +122,7 @@ public class CampaignTreeController {
|
|||||||
List<RandomTableDTO> randomTables,
|
List<RandomTableDTO> randomTables,
|
||||||
List<Enemy> enemies,
|
List<Enemy> enemies,
|
||||||
List<QuestDTO> quests,
|
List<QuestDTO> quests,
|
||||||
|
List<PlaythroughDTO> playthroughs,
|
||||||
CampaignReadinessAssessment readiness
|
CampaignReadinessAssessment readiness
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -147,6 +157,8 @@ public class CampaignTreeController {
|
|||||||
enemyRepository.findByCampaignId(campaignId),
|
enemyRepository.findByCampaignId(campaignId),
|
||||||
questRepository.findByCampaignId(campaignId).stream()
|
questRepository.findByCampaignId(campaignId).stream()
|
||||||
.map(questMapper::toDTO).toList(),
|
.map(questMapper::toDTO).toList(),
|
||||||
|
playthroughRepository.findByCampaignId(campaignId).stream()
|
||||||
|
.map(playthroughMapper::toDTO).toList(),
|
||||||
readinessService.assess(campaignId)));
|
readinessService.assess(campaignId)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
package com.loremind.infrastructure.web.controller;
|
||||||
|
|
||||||
|
import com.loremind.application.remoteaccess.NetworkReadiness;
|
||||||
|
import com.loremind.application.remoteaccess.PairingCode;
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessService;
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessStatus;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.HostNetworkAccess;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Réglage de l'accès distant, côté PC (mode bureau). Sous {@code /api/settings} : réservé
|
||||||
|
* à l'admin (HTTP Basic) ET à la machine elle-même ({@code RemoteAccessFilter} refuse ces
|
||||||
|
* routes à tout appareil du réseau, même appairé). 404 en Docker (profil {@code local} absent).
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@Profile("local")
|
||||||
|
@RequestMapping("/api/settings/remote-access")
|
||||||
|
public class RemoteAccessAdminController {
|
||||||
|
|
||||||
|
private final RemoteAccessService remoteAccessService;
|
||||||
|
private final HostNetworkAccess hostNetworkAccess;
|
||||||
|
|
||||||
|
public RemoteAccessAdminController(RemoteAccessService remoteAccessService, HostNetworkAccess hostNetworkAccess) {
|
||||||
|
this.remoteAccessService = remoteAccessService;
|
||||||
|
this.hostNetworkAccess = hostNetworkAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record ConfigureRequest(boolean enabled, int port) {}
|
||||||
|
|
||||||
|
/** Réponse du bouton « Autoriser dans le pare-feu » : ce qui s'est passé + le nouvel état. */
|
||||||
|
public record FirewallFixResponse(HostNetworkAccess.FirewallFixOutcome outcome, NetworkReadiness readiness) {}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public RemoteAccessStatus status() {
|
||||||
|
return remoteAccessService.status();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
public RemoteAccessStatus configure(@RequestBody ConfigureRequest request) {
|
||||||
|
return remoteAccessService.configure(request.enabled(), request.port());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/pairing-code")
|
||||||
|
public PairingCode newPairingCode() {
|
||||||
|
return remoteAccessService.newPairingCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Une tablette peut-elle joindre ce PC ? (type de réseau, règle du pare-feu) */
|
||||||
|
@GetMapping("/network-check")
|
||||||
|
public NetworkReadiness networkCheck() {
|
||||||
|
return NetworkReadiness.evaluate(hostNetworkAccess.inspect());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ajoute la règle du pare-feu ; attend la réponse de l'utilisateur à la confirmation Windows (UAC). */
|
||||||
|
@PostMapping("/firewall-rule")
|
||||||
|
public FirewallFixResponse allowThroughFirewall() {
|
||||||
|
HostNetworkAccess.FirewallFixOutcome outcome = hostNetworkAccess.allowThroughFirewall();
|
||||||
|
return new FirewallFixResponse(outcome, NetworkReadiness.evaluate(hostNetworkAccess.inspect()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ouvre les réglages réseau de Windows (pour passer un Wi-Fi « Public » en « Privé »). */
|
||||||
|
@PostMapping("/open-network-settings")
|
||||||
|
public ResponseEntity<Void> openNetworkSettings() {
|
||||||
|
hostNetworkAccess.openNetworkSettings();
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/devices/{id}")
|
||||||
|
public ResponseEntity<Void> revoke(@PathVariable String id) {
|
||||||
|
return remoteAccessService.revoke(id) ? ResponseEntity.noContent().build() : ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Port occupé, accès non ouvert… : conflit d'état, message prêt à afficher. */
|
||||||
|
@ExceptionHandler(IllegalStateException.class)
|
||||||
|
public ResponseEntity<Map<String, String>> conflict(IllegalStateException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(Map.of("error", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
package com.loremind.infrastructure.web.controller;
|
||||||
|
|
||||||
|
import com.loremind.application.remoteaccess.PairedDevice;
|
||||||
|
import com.loremind.application.remoteaccess.PairingRejectedException;
|
||||||
|
import com.loremind.application.remoteaccess.PairingResult;
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessService;
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
import com.loremind.infrastructure.web.config.RemoteAccessFilter;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseCookie;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appairage d'une tablette (mode bureau) : seules routes d'API joignables depuis le réseau
|
||||||
|
* sans jeton (avec {@code /api/config} et {@code /api/version}).
|
||||||
|
* <p>
|
||||||
|
* Le jeton est posé en cookie {@code HttpOnly} + {@code SameSite=Strict} : envoyé
|
||||||
|
* automatiquement par le navigateur (y compris pour les {@code <img>}), illisible par le
|
||||||
|
* JavaScript de la page, et jamais joint à une requête venue d'un autre site (anti-CSRF).
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@Profile("local")
|
||||||
|
@RequestMapping("/api/remote-access")
|
||||||
|
public class RemotePairingController {
|
||||||
|
|
||||||
|
static final Duration COOKIE_LIFETIME = Duration.ofDays(365);
|
||||||
|
|
||||||
|
private final RemoteAccessService remoteAccessService;
|
||||||
|
|
||||||
|
public RemotePairingController(RemoteAccessService remoteAccessService) {
|
||||||
|
this.remoteAccessService = remoteAccessService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record PairRequest(String code, String deviceName) {}
|
||||||
|
|
||||||
|
/** Ce que le front a besoin de savoir pour décider d'afficher l'écran d'appairage. */
|
||||||
|
public record SessionInfo(boolean remote, boolean paired, String deviceName) {}
|
||||||
|
|
||||||
|
@PostMapping("/pair")
|
||||||
|
public ResponseEntity<PairedDevice> pair(@RequestBody PairRequest request,
|
||||||
|
@RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
|
||||||
|
PairingResult result = remoteAccessService.pair(request.code(), request.deviceName(), userAgent);
|
||||||
|
ResponseCookie cookie = ResponseCookie.from(RemoteAccessFilter.DEVICE_COOKIE, result.token())
|
||||||
|
.httpOnly(true)
|
||||||
|
.sameSite("Strict")
|
||||||
|
.path("/")
|
||||||
|
.maxAge(COOKIE_LIFETIME)
|
||||||
|
.build();
|
||||||
|
return ResponseEntity.ok().header(HttpHeaders.SET_COOKIE, cookie.toString()).body(result.device());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/session")
|
||||||
|
public SessionInfo session(HttpServletRequest request) {
|
||||||
|
boolean remote = RemoteAccessFilter.isFromLan(request, remoteAccessService.lanPort());
|
||||||
|
if (!remote) return new SessionInfo(false, true, null);
|
||||||
|
Optional<RemoteDevice> device = remoteAccessService.authenticate(RemoteAccessFilter.deviceToken(request));
|
||||||
|
return new SessionInfo(true, device.isPresent(), device.map(RemoteDevice::getName).orElse(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(PairingRejectedException.class)
|
||||||
|
public ResponseEntity<Map<String, String>> rejected(PairingRejectedException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("error", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
-4
@@ -56,11 +56,23 @@ public class SessionController {
|
|||||||
.orElse(ResponseEntity.noContent().build());
|
.orElse(ResponseEntity.noContent().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste des sessions. {@code active=true} : uniquement celles en cours, toutes Parties
|
||||||
|
* confondues, la plus récente d'abord (raccourci « Séance en cours » du menu, rafraîchi
|
||||||
|
* à chaque navigation — évite de rapatrier tout l'historique).
|
||||||
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<List<SessionDTO>> getSessions(@RequestParam(value = "playthroughId", required = false) String playthroughId) {
|
public ResponseEntity<List<SessionDTO>> getSessions(
|
||||||
List<Session> sessions = (playthroughId == null || playthroughId.isBlank())
|
@RequestParam(value = "playthroughId", required = false) String playthroughId,
|
||||||
? sessionService.getAll()
|
@RequestParam(value = "active", defaultValue = "false") boolean active) {
|
||||||
: sessionService.getByPlaythroughId(playthroughId);
|
List<Session> sessions;
|
||||||
|
if (active) {
|
||||||
|
sessions = sessionService.getAllActive();
|
||||||
|
} else if (playthroughId == null || playthroughId.isBlank()) {
|
||||||
|
sessions = sessionService.getAll();
|
||||||
|
} else {
|
||||||
|
sessions = sessionService.getByPlaythroughId(playthroughId);
|
||||||
|
}
|
||||||
List<SessionDTO> dtos = sessions.stream()
|
List<SessionDTO> dtos = sessions.stream()
|
||||||
.map(sessionMapper::toDTO)
|
.map(sessionMapper::toDTO)
|
||||||
.toList();
|
.toList();
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
-- Accès distant à l'application de bureau (tablette / téléphone sur le réseau local).
|
||||||
|
-- remote_access_config : réglage singleton (id = 'current') — activé ou non, port réseau.
|
||||||
|
-- remote_devices : appareils appairés par code ; seule l'EMPREINTE SHA-256 du jeton
|
||||||
|
-- est stockée (le jeton lui-même ne vit que dans le cookie de l'appareil).
|
||||||
|
-- Tables présentes partout (Docker compris) mais utilisées uniquement en mode bureau.
|
||||||
|
-- Compatible Postgres et H2 (MODE=PostgreSQL).
|
||||||
|
create table remote_access_config (
|
||||||
|
id varchar(32) not null,
|
||||||
|
enabled boolean not null,
|
||||||
|
port integer not null,
|
||||||
|
updated_at timestamp(6) with time zone not null,
|
||||||
|
primary key (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
create table remote_devices (
|
||||||
|
id bigint generated by default as identity,
|
||||||
|
name varchar(100) not null,
|
||||||
|
token_hash varchar(64) not null,
|
||||||
|
user_agent varchar(300),
|
||||||
|
created_at timestamp(6) with time zone not null,
|
||||||
|
last_seen_at timestamp(6) with time zone,
|
||||||
|
primary key (id)
|
||||||
|
);
|
||||||
|
create unique index ux_remote_device_token on remote_devices (token_hash);
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.NetworkSnapshot;
|
||||||
|
import com.loremind.domain.remoteaccess.NetworkSnapshot.FirewallRule;
|
||||||
|
import com.loremind.domain.remoteaccess.NetworkSnapshot.Network;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/** Test du verdict « une tablette peut-elle joindre ce PC ? » à partir des faits lus sur Windows. */
|
||||||
|
class NetworkReadinessTest {
|
||||||
|
|
||||||
|
private static final Network HOME_PRIVATE = new Network("Bbox-Maison", "Wi-Fi", "Private");
|
||||||
|
private static final Network HOME_PUBLIC = new Network("Bbox-Maison", "Wi-Fi", "Public");
|
||||||
|
private static final FirewallRule ALLOW_PRIVATE = new FirewallRule("Allow", "Private", "True");
|
||||||
|
|
||||||
|
private static NetworkReadiness eval(List<Network> networks, List<FirewallRule> rules) {
|
||||||
|
return NetworkReadiness.evaluate(new NetworkSnapshot(true, "C:\\DM Loremind.exe", networks, rules));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void unsupported_whenNotWindows() {
|
||||||
|
NetworkReadiness r = NetworkReadiness.evaluate(NetworkSnapshot.unsupported());
|
||||||
|
assertFalse(r.supported());
|
||||||
|
assertFalse(r.ready());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ready_onPrivateNetwork_withAllowRule() {
|
||||||
|
NetworkReadiness r = eval(List.of(HOME_PRIVATE), List.of(ALLOW_PRIVATE));
|
||||||
|
assertTrue(r.ready());
|
||||||
|
assertTrue(r.firewallAllowed());
|
||||||
|
assertTrue(r.publicNetworks().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void notReady_withoutAnyRule_evenOnPrivateNetwork() {
|
||||||
|
// Cas réel du 2026-10-17 : Wi-Fi passé en privé, mais aucune règle → la tablette charge sans fin.
|
||||||
|
NetworkReadiness r = eval(List.of(HOME_PRIVATE), List.of());
|
||||||
|
assertFalse(r.ready());
|
||||||
|
assertFalse(r.firewallAllowed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void notReady_onPublicNetwork_evenWithPrivateRule() {
|
||||||
|
NetworkReadiness r = eval(List.of(HOME_PUBLIC), List.of(ALLOW_PRIVATE));
|
||||||
|
assertFalse(r.ready());
|
||||||
|
assertEquals(List.of("Bbox-Maison"), r.publicNetworks());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void publicNetwork_isNotAnObstacle_whenPublicExplicitlyAllowed() {
|
||||||
|
NetworkReadiness r = eval(List.of(HOME_PUBLIC), List.of(new FirewallRule("Allow", "Private, Public", "True")));
|
||||||
|
assertTrue(r.ready());
|
||||||
|
assertTrue(r.publicNetworks().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void blockRule_winsOverAllow() {
|
||||||
|
NetworkReadiness r = eval(List.of(HOME_PRIVATE),
|
||||||
|
List.of(ALLOW_PRIVATE, new FirewallRule("Block", "Any", "True")));
|
||||||
|
assertFalse(r.ready());
|
||||||
|
assertTrue(r.firewallBlocked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void disabledRules_areIgnored_andAnyCoversPrivate() {
|
||||||
|
assertFalse(eval(List.of(HOME_PRIVATE), List.of(new FirewallRule("Allow", "Private", "False"))).ready());
|
||||||
|
assertTrue(eval(List.of(HOME_PRIVATE), List.of(new FirewallRule("Allow", "Any", "True"))).ready());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void publicNetwork_withoutName_usesInterfaceAlias() {
|
||||||
|
NetworkReadiness r = eval(List.of(new Network(null, "Wi-Fi", "Public")), List.of(ALLOW_PRIVATE));
|
||||||
|
assertEquals(List.of("Wi-Fi"), r.publicNetworks());
|
||||||
|
}
|
||||||
|
}
|
||||||
+258
@@ -0,0 +1,258 @@
|
|||||||
|
package com.loremind.application.remoteaccess;
|
||||||
|
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteAccessConfig;
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.LanConnector;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteAccessConfigRepository;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteDeviceRepository;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test unitaire de {@link RemoteAccessService} avec des doublures en mémoire (pas de Mockito :
|
||||||
|
* l'état des appareils et du connecteur doit vraiment évoluer d'un appel à l'autre).
|
||||||
|
*/
|
||||||
|
class RemoteAccessServiceTest {
|
||||||
|
|
||||||
|
private static final int LOCAL_PORT = 8080;
|
||||||
|
|
||||||
|
private MutableClock clock;
|
||||||
|
private FakeLan lan;
|
||||||
|
private InMemoryDevices devices;
|
||||||
|
private InMemoryConfig config;
|
||||||
|
private RemoteAccessService service;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
clock = new MutableClock(Instant.parse("2026-10-17T10:00:00Z"));
|
||||||
|
lan = new FakeLan();
|
||||||
|
devices = new InMemoryDevices();
|
||||||
|
config = new InMemoryConfig();
|
||||||
|
service = new RemoteAccessService(config, devices, lan, LOCAL_PORT, clock);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String freshCode() {
|
||||||
|
service.configure(true, 8765);
|
||||||
|
return service.newPairingCode().code();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Réglage ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void disabledByDefault_noConnector() {
|
||||||
|
RemoteAccessStatus status = service.status();
|
||||||
|
assertFalse(status.enabled());
|
||||||
|
assertFalse(status.running());
|
||||||
|
assertEquals(RemoteAccessConfig.DEFAULT_PORT, status.port());
|
||||||
|
assertTrue(status.urls().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void enable_opensConnector_persists_andListsUrls() {
|
||||||
|
RemoteAccessStatus status = service.configure(true, 8765);
|
||||||
|
|
||||||
|
assertEquals(8765, lan.port);
|
||||||
|
assertTrue(status.running());
|
||||||
|
assertEquals(List.of("http://192.168.1.20:8765"), status.urls());
|
||||||
|
assertEquals(new RemoteAccessConfig(true, 8765), config.saved);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void enable_onBusyPort_staysDisabled() {
|
||||||
|
lan.busy = true;
|
||||||
|
assertThrows(IllegalStateException.class, () -> service.configure(true, 8765));
|
||||||
|
assertNull(config.saved);
|
||||||
|
assertFalse(service.status().enabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void rejects_portOutOfRange_orSameAsLocalPort() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> service.configure(true, 80));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> service.configure(true, LOCAL_PORT));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void disable_closesConnector_andInvalidatesPendingCode() {
|
||||||
|
String code = freshCode();
|
||||||
|
service.configure(false, 8765);
|
||||||
|
|
||||||
|
assertEquals(-1, lan.port);
|
||||||
|
assertThrows(PairingRejectedException.class, () -> service.pair(code, "Tablette", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applySavedConfig_reopensOnBoot_withoutCrashingOnBusyPort() {
|
||||||
|
config.saved = new RemoteAccessConfig(true, 8765);
|
||||||
|
lan.busy = true;
|
||||||
|
|
||||||
|
service.applySavedConfig();
|
||||||
|
|
||||||
|
assertEquals(-1, lan.port);
|
||||||
|
assertNotNull(service.status().lastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Appairage ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pairingCode_requiresOpenConnector() {
|
||||||
|
assertThrows(IllegalStateException.class, () -> service.newPairingCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pairingCode_isSixDigits() {
|
||||||
|
assertTrue(freshCode().matches("\\d{6}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pair_withRightCode_issuesToken_storesOnlyItsHash_andConsumesTheCode() {
|
||||||
|
String code = freshCode();
|
||||||
|
|
||||||
|
PairingResult result = service.pair(code, " Tablette de Léa ", "Mozilla/5.0 (iPad)");
|
||||||
|
|
||||||
|
assertEquals("Tablette de Léa", result.device().name());
|
||||||
|
RemoteDevice stored = devices.items.get(0);
|
||||||
|
assertNotEquals(result.token(), stored.getTokenHash());
|
||||||
|
assertEquals(RemoteAccessService.sha256(result.token()), stored.getTokenHash());
|
||||||
|
assertTrue(service.authenticate(result.token()).isPresent());
|
||||||
|
// Code à usage unique.
|
||||||
|
assertThrows(PairingRejectedException.class, () -> service.pair(code, "Autre", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pair_rejectsExpiredCode() {
|
||||||
|
String code = freshCode();
|
||||||
|
clock.advance(RemoteAccessService.CODE_TTL.plusSeconds(1));
|
||||||
|
assertThrows(PairingRejectedException.class, () -> service.pair(code, "Tablette", null));
|
||||||
|
assertTrue(devices.items.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pair_invalidatesCodeAfterTooManyWrongAttempts() {
|
||||||
|
String code = freshCode();
|
||||||
|
String wrong = code.equals("000000") ? "111111" : "000000";
|
||||||
|
for (int i = 0; i < RemoteAccessService.CODE_MAX_ATTEMPTS; i++) {
|
||||||
|
assertThrows(PairingRejectedException.class, () -> service.pair(wrong, "Tablette", null));
|
||||||
|
}
|
||||||
|
// Même le bon code ne passe plus : il faut en afficher un nouveau.
|
||||||
|
assertThrows(PairingRejectedException.class, () -> service.pair(code, "Tablette", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pair_globalThrottle_blocksBurstAcrossCodes() {
|
||||||
|
for (int i = 0; i < RemoteAccessService.GLOBAL_MAX_FAILURES_PER_MINUTE; i++) {
|
||||||
|
assertThrows(PairingRejectedException.class, () -> service.pair("123456", "x", null));
|
||||||
|
}
|
||||||
|
String code = freshCode();
|
||||||
|
PairingRejectedException blocked =
|
||||||
|
assertThrows(PairingRejectedException.class, () -> service.pair(code, "Tablette", null));
|
||||||
|
assertTrue(blocked.getMessage().contains("minute"));
|
||||||
|
|
||||||
|
clock.advance(Duration.ofMinutes(2));
|
||||||
|
assertDoesNotThrow(() -> service.pair(code, "Tablette", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deviceName_defaultsAndIsTruncated() {
|
||||||
|
PairingResult unnamed = service.pair(freshCode(), " ", null);
|
||||||
|
assertEquals("Appareil", unnamed.device().name());
|
||||||
|
|
||||||
|
PairingResult longName = service.pair(service.newPairingCode().code(), "x".repeat(300), null);
|
||||||
|
assertEquals(RemoteAccessService.DEVICE_NAME_MAX, longName.device().name().length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Authentification & révocation ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void authenticate_unknownOrBlankToken_isEmpty() {
|
||||||
|
assertTrue(service.authenticate(null).isEmpty());
|
||||||
|
assertTrue(service.authenticate("").isEmpty());
|
||||||
|
assertTrue(service.authenticate("inconnu").isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void authenticate_touchesLastSeen_atMostOncePerMinute() {
|
||||||
|
String token = service.pair(freshCode(), "Tablette", null).token();
|
||||||
|
devices.touches = 0;
|
||||||
|
|
||||||
|
service.authenticate(token);
|
||||||
|
assertEquals(0, devices.touches);
|
||||||
|
|
||||||
|
clock.advance(Duration.ofMinutes(2));
|
||||||
|
service.authenticate(token);
|
||||||
|
assertEquals(1, devices.touches);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void revoke_cutsAccess() {
|
||||||
|
PairingResult result = service.pair(freshCode(), "Tablette", null);
|
||||||
|
|
||||||
|
assertTrue(service.revoke(result.device().id()));
|
||||||
|
assertTrue(service.authenticate(result.token()).isEmpty());
|
||||||
|
assertFalse(service.revoke(result.device().id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Doublures ---
|
||||||
|
|
||||||
|
private static final class MutableClock extends Clock {
|
||||||
|
private Instant now;
|
||||||
|
|
||||||
|
MutableClock(Instant now) { this.now = now; }
|
||||||
|
|
||||||
|
void advance(Duration d) { now = now.plus(d); }
|
||||||
|
|
||||||
|
@Override public Instant instant() { return now; }
|
||||||
|
@Override public java.time.ZoneId getZone() { return ZoneOffset.UTC; }
|
||||||
|
@Override public Clock withZone(java.time.ZoneId zone) { return this; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class FakeLan implements LanConnector {
|
||||||
|
int port = -1;
|
||||||
|
boolean busy;
|
||||||
|
|
||||||
|
@Override public void start(int p) {
|
||||||
|
if (busy) throw new IllegalStateException("Le port " + p + " est déjà utilisé par une autre application.");
|
||||||
|
port = p;
|
||||||
|
}
|
||||||
|
@Override public void stop() { port = -1; }
|
||||||
|
@Override public int runningPort() { return port; }
|
||||||
|
@Override public List<String> lanAddresses() { return List.of("192.168.1.20"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class InMemoryConfig implements RemoteAccessConfigRepository {
|
||||||
|
RemoteAccessConfig saved;
|
||||||
|
|
||||||
|
@Override public Optional<RemoteAccessConfig> find() { return Optional.ofNullable(saved); }
|
||||||
|
@Override public RemoteAccessConfig save(RemoteAccessConfig c) { saved = c; return c; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class InMemoryDevices implements RemoteDeviceRepository {
|
||||||
|
final List<RemoteDevice> items = new ArrayList<>();
|
||||||
|
int touches;
|
||||||
|
private int nextId = 1;
|
||||||
|
|
||||||
|
@Override public RemoteDevice save(RemoteDevice d) {
|
||||||
|
d.setId(String.valueOf(nextId++));
|
||||||
|
items.add(d);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
@Override public Optional<RemoteDevice> findByTokenHash(String h) {
|
||||||
|
return items.stream().filter(d -> d.getTokenHash().equals(h)).findFirst();
|
||||||
|
}
|
||||||
|
@Override public List<RemoteDevice> findAll() { return List.copyOf(items); }
|
||||||
|
@Override public void touch(String id, Instant at) {
|
||||||
|
touches++;
|
||||||
|
items.stream().filter(d -> d.getId().equals(id)).forEach(d -> d.setLastSeenAt(at));
|
||||||
|
}
|
||||||
|
@Override public boolean deleteById(String id) { return items.removeIf(d -> d.getId().equals(id)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
+193
@@ -0,0 +1,193 @@
|
|||||||
|
package com.loremind.infrastructure.desktop;
|
||||||
|
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessService;
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteAccessConfig;
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.LanConnector;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteAccessConfigRepository;
|
||||||
|
import com.loremind.domain.remoteaccess.ports.RemoteDeviceRepository;
|
||||||
|
import com.loremind.infrastructure.web.config.RemoteAccessFilter;
|
||||||
|
import com.loremind.infrastructure.web.controller.RemotePairingController;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test d'intégration de l'accès distant sur un VRAI Tomcat : ouverture à chaud du second
|
||||||
|
* connecteur, garde du filtre, appairage par code avec pose du cookie, puis fermeture.
|
||||||
|
* Contexte Spring minimal (ni base, ni sécurité) : seules les briques de l'accès distant.
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = TomcatLanConnectorIntegrationTest.App.class,
|
||||||
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
|
properties = "spring.main.banner-mode=off")
|
||||||
|
class TomcatLanConnectorIntegrationTest {
|
||||||
|
|
||||||
|
@SpringBootConfiguration
|
||||||
|
@EnableAutoConfiguration(exclude = {
|
||||||
|
DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, FlywayAutoConfiguration.class,
|
||||||
|
SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class})
|
||||||
|
@Import(App.Ping.class)
|
||||||
|
static class App {
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
static class Ping {
|
||||||
|
@GetMapping("/api/ping")
|
||||||
|
String ping() { return "pong"; }
|
||||||
|
|
||||||
|
@GetMapping("/api/settings/secret")
|
||||||
|
String secret() { return "admin"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
TomcatLanConnector lanConnector(ApplicationContext context) {
|
||||||
|
return new TomcatLanConnector(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
RemoteAccessService remoteAccessService(LanConnector lan) {
|
||||||
|
return new RemoteAccessService(new InMemoryConfig(), new InMemoryDevices(), lan, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** En @Bean : un @Import ignorerait la classe, annotée @Profile("local"). */
|
||||||
|
@Bean
|
||||||
|
RemotePairingController remotePairingController(RemoteAccessService service) {
|
||||||
|
return new RemotePairingController(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
FilterRegistrationBean<RemoteAccessFilter> remoteAccessFilter(RemoteAccessService service) {
|
||||||
|
return new FilterRegistrationBean<>(new RemoteAccessFilter(service));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@LocalServerPort private int localPort;
|
||||||
|
@Autowired private RemoteAccessService service;
|
||||||
|
@Autowired private TomcatLanConnector lan;
|
||||||
|
|
||||||
|
private final HttpClient http = HttpClient.newHttpClient();
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void closeLan() {
|
||||||
|
lan.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpResponse<String> get(int port, String path, String cookie) throws Exception {
|
||||||
|
HttpRequest.Builder req = HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + port + path)).GET();
|
||||||
|
if (cookie != null) req.header("Cookie", cookie);
|
||||||
|
return http.send(req.build(), HttpResponse.BodyHandlers.ofString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpResponse<String> post(int port, String path, String json) throws Exception {
|
||||||
|
return http.send(HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + port + path))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(json)).build(), HttpResponse.BodyHandlers.ofString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int freePort() throws IOException {
|
||||||
|
try (ServerSocket s = new ServerSocket(0)) {
|
||||||
|
return s.getLocalPort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void lanConnector_guardsApi_pairsWithCode_andClosesCleanly() throws Exception {
|
||||||
|
// Connecteur habituel : inchangé, aucun jeton demandé.
|
||||||
|
assertEquals(200, get(localPort, "/api/ping", null).statusCode());
|
||||||
|
|
||||||
|
int lanPort = freePort();
|
||||||
|
assertTrue(service.configure(true, lanPort).running());
|
||||||
|
|
||||||
|
// Depuis le réseau : appairage exigé, administration interdite.
|
||||||
|
HttpResponse<String> unpaired = get(lanPort, "/api/ping", null);
|
||||||
|
assertEquals(401, unpaired.statusCode());
|
||||||
|
assertTrue(unpaired.body().contains("remote_pairing_required"));
|
||||||
|
assertEquals(403, get(lanPort, "/api/settings/secret", null).statusCode());
|
||||||
|
|
||||||
|
// Mauvais code puis bon code : le bon pose un cookie HttpOnly + SameSite=Strict.
|
||||||
|
assertEquals(403, post(lanPort, "/api/remote-access/pair", "{\"code\":\"abcdef\",\"deviceName\":\"x\"}").statusCode());
|
||||||
|
String code = service.newPairingCode().code();
|
||||||
|
HttpResponse<String> paired = post(lanPort, "/api/remote-access/pair",
|
||||||
|
"{\"code\":\"" + code + "\",\"deviceName\":\"Tablette de test\"}");
|
||||||
|
assertEquals(200, paired.statusCode());
|
||||||
|
String setCookie = paired.headers().firstValue("Set-Cookie").orElseThrow();
|
||||||
|
assertTrue(setCookie.startsWith(RemoteAccessFilter.DEVICE_COOKIE + "="));
|
||||||
|
assertTrue(setCookie.contains("HttpOnly"));
|
||||||
|
assertTrue(setCookie.contains("SameSite=Strict"));
|
||||||
|
String cookie = setCookie.split(";", 2)[0];
|
||||||
|
|
||||||
|
HttpResponse<String> authorized = get(lanPort, "/api/ping", cookie);
|
||||||
|
assertEquals(200, authorized.statusCode());
|
||||||
|
assertEquals("pong", authorized.body());
|
||||||
|
assertEquals(403, get(lanPort, "/api/settings/secret", cookie).statusCode());
|
||||||
|
assertTrue(get(lanPort, "/api/remote-access/session", cookie).body().contains("\"paired\":true"));
|
||||||
|
|
||||||
|
// Désactivation : le port réseau se ferme, le connecteur local continue.
|
||||||
|
service.configure(false, lanPort);
|
||||||
|
assertThrows(ConnectException.class, () -> get(lanPort, "/api/ping", cookie));
|
||||||
|
assertEquals(200, get(localPort, "/api/ping", null).statusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void busyPort_isReportedClearly() throws Exception {
|
||||||
|
try (ServerSocket occupied = new ServerSocket(0)) {
|
||||||
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||||
|
() -> service.configure(true, occupied.getLocalPort()));
|
||||||
|
assertTrue(e.getMessage().contains("déjà utilisé"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Doublures de persistance ---
|
||||||
|
|
||||||
|
static final class InMemoryConfig implements RemoteAccessConfigRepository {
|
||||||
|
private RemoteAccessConfig saved;
|
||||||
|
|
||||||
|
@Override public Optional<RemoteAccessConfig> find() { return Optional.ofNullable(saved); }
|
||||||
|
@Override public RemoteAccessConfig save(RemoteAccessConfig c) { saved = c; return c; }
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class InMemoryDevices implements RemoteDeviceRepository {
|
||||||
|
private final List<RemoteDevice> items = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override public synchronized RemoteDevice save(RemoteDevice d) {
|
||||||
|
d.setId(String.valueOf(items.size() + 1));
|
||||||
|
items.add(d);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
@Override public synchronized Optional<RemoteDevice> findByTokenHash(String h) {
|
||||||
|
return items.stream().filter(d -> d.getTokenHash().equals(h)).findFirst();
|
||||||
|
}
|
||||||
|
@Override public synchronized List<RemoteDevice> findAll() { return List.copyOf(items); }
|
||||||
|
@Override public void touch(String id, Instant at) { /* sans objet ici */ }
|
||||||
|
@Override public synchronized boolean deleteById(String id) { return items.removeIf(d -> d.getId().equals(id)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
package com.loremind.infrastructure.desktop;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.loremind.domain.remoteaccess.NetworkSnapshot;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledOnOs;
|
||||||
|
import org.junit.jupiter.api.condition.OS;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test de {@link WindowsHostNetworkAccess} : lecture du JSON de PowerShell (objet seul ou
|
||||||
|
* tableau), contenu des scripts, et — sur Windows seulement — un vrai appel en lecture seule.
|
||||||
|
*/
|
||||||
|
class WindowsHostNetworkAccessTest {
|
||||||
|
|
||||||
|
private final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parse_handlesSingleObjectsAndArrays() throws Exception {
|
||||||
|
// ConvertTo-Json écrit un objet (pas un tableau) quand il n'y a qu'un élément.
|
||||||
|
String json = "{\"networks\":{\"name\":\"Bbox\",\"alias\":\"Wi-Fi\",\"category\":\"Private\"},"
|
||||||
|
+ "\"rules\":[{\"action\":\"Allow\",\"profile\":\"Private\",\"enabled\":\"True\"},"
|
||||||
|
+ "{\"action\":\"Block\",\"profile\":\"Public\",\"enabled\":\"True\"}]}";
|
||||||
|
|
||||||
|
NetworkSnapshot s = WindowsHostNetworkAccess.parseSnapshot(mapper, "C:\\app.exe", json);
|
||||||
|
|
||||||
|
assertTrue(s.supported());
|
||||||
|
assertEquals(1, s.networks().size());
|
||||||
|
assertEquals("Private", s.networks().get(0).category());
|
||||||
|
assertEquals(2, s.rules().size());
|
||||||
|
assertEquals("Block", s.rules().get(1).action());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parse_handlesEmptyLists_andEmptyOutput() throws Exception {
|
||||||
|
NetworkSnapshot empty = WindowsHostNetworkAccess.parseSnapshot(mapper, "C:\\app.exe", "{\"networks\":[],\"rules\":[]}");
|
||||||
|
assertTrue(empty.networks().isEmpty());
|
||||||
|
assertTrue(empty.rules().isEmpty());
|
||||||
|
|
||||||
|
NetworkSnapshot blank = WindowsHostNetworkAccess.parseSnapshot(mapper, "C:\\app.exe", " ");
|
||||||
|
assertTrue(blank.networks().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void scripts_quoteThePath_andOnlyOpenPrivateNetworks() {
|
||||||
|
String path = "C:\\Users\\l'MJ\\DM Loremind.exe";
|
||||||
|
String allow = WindowsHostNetworkAccess.allowScript(path);
|
||||||
|
|
||||||
|
assertTrue(allow.contains("'C:\\Users\\l''MJ\\DM Loremind.exe'"), "apostrophe doublée dans la chaîne PowerShell");
|
||||||
|
assertTrue(allow.contains("-Profile Private"));
|
||||||
|
assertFalse(allow.contains("Public"), "la règle ne doit jamais ouvrir les réseaux publics");
|
||||||
|
assertTrue(allow.contains("Remove-NetFirewallRule"), "les blocages de CE programme sont retirés");
|
||||||
|
assertTrue(WindowsHostNetworkAccess.inspectScript(path).contains("ConvertTo-Json"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void encode_isUtf16LeBase64_asExpectedByEncodedCommand() {
|
||||||
|
String encoded = WindowsHostNetworkAccess.encode("é");
|
||||||
|
assertEquals("é", new String(Base64.getDecoder().decode(encoded), StandardCharsets.UTF_16LE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledOnOs(OS.WINDOWS)
|
||||||
|
void inspect_readsTheRealSystem_onWindows() {
|
||||||
|
NetworkSnapshot s = new WindowsHostNetworkAccess(mapper).inspect();
|
||||||
|
assertTrue(s.supported(), "PowerShell doit répondre en lecture seule sur Windows");
|
||||||
|
assertNotNull(s.program());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,6 +73,15 @@ class FlywayMigrationTest {
|
|||||||
"values ('C', 0, now(), now())");
|
"values ('C', 0, now(), now())");
|
||||||
st.executeUpdate("insert into arcs (name, campaign_id, \"order\", type, created_at, updated_at) " +
|
st.executeUpdate("insert into arcs (name, campaign_id, \"order\", type, created_at, updated_at) " +
|
||||||
"select 'Quêtes libres', id, 9999, 'SYSTEM', now(), now() from campaigns");
|
"select 'Quêtes libres', id, 9999, 'SYSTEM', now(), now() from campaigns");
|
||||||
|
|
||||||
|
// V25 : accès distant — réglage singleton + appareils, empreinte de jeton unique.
|
||||||
|
st.executeUpdate("insert into remote_access_config (id, enabled, port, updated_at) " +
|
||||||
|
"values ('current', true, 8765, now())");
|
||||||
|
st.executeUpdate("insert into remote_devices (name, token_hash, created_at) values ('Tablette', 'abc', now())");
|
||||||
|
assertThrows(SQLException.class,
|
||||||
|
() -> st.executeUpdate("insert into remote_devices (name, token_hash, created_at) " +
|
||||||
|
"values ('Doublon', 'abc', now())"),
|
||||||
|
"remote_devices.token_hash doit être unique (V25)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package com.loremind.infrastructure.web.config;
|
||||||
|
|
||||||
|
import com.loremind.application.remoteaccess.RemoteAccessService;
|
||||||
|
import com.loremind.domain.remoteaccess.RemoteDevice;
|
||||||
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
import org.springframework.mock.web.MockFilterChain;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test unitaire de {@link RemoteAccessFilter} : ce qui passe et ce qui est refusé selon
|
||||||
|
* le connecteur d'arrivée (local / réseau), le chemin et le cookie d'appareil.
|
||||||
|
*/
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
|
class RemoteAccessFilterTest {
|
||||||
|
|
||||||
|
private static final int LOCAL_PORT = 8080;
|
||||||
|
private static final int LAN_PORT = 8765;
|
||||||
|
|
||||||
|
@Mock private RemoteAccessService service;
|
||||||
|
private RemoteAccessFilter filter;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
filter = new RemoteAccessFilter(service);
|
||||||
|
when(service.lanPort()).thenReturn(LAN_PORT);
|
||||||
|
when(service.authenticate("bon-jeton")).thenReturn(Optional.of(RemoteDevice.builder().id("1").name("Tablette").build()));
|
||||||
|
when(service.authenticate(null)).thenReturn(Optional.empty());
|
||||||
|
when(service.authenticate("mauvais")).thenReturn(Optional.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Outcome(boolean passed, int status, String body) {}
|
||||||
|
|
||||||
|
private Outcome run(int localPort, String path, String token) throws Exception {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", path);
|
||||||
|
request.setLocalPort(localPort);
|
||||||
|
if (token != null) request.setCookies(new Cookie(RemoteAccessFilter.DEVICE_COOKIE, token));
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
MockFilterChain chain = new MockFilterChain();
|
||||||
|
filter.doFilter(request, response, chain);
|
||||||
|
return new Outcome(chain.getRequest() != null, response.getStatus(), response.getContentAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void localConnector_isUntouched_evenForSettings() throws Exception {
|
||||||
|
assertTrue(run(LOCAL_PORT, "/api/campaigns", null).passed());
|
||||||
|
assertTrue(run(LOCAL_PORT, "/api/settings", null).passed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void lanClosed_meansEverythingIsLocal() throws Exception {
|
||||||
|
when(service.lanPort()).thenReturn(-1);
|
||||||
|
assertTrue(run(LOCAL_PORT, "/api/campaigns", null).passed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void lan_staticFrontAndPublicApi_passWithoutToken() throws Exception {
|
||||||
|
assertTrue(run(LAN_PORT, "/", null).passed());
|
||||||
|
assertTrue(run(LAN_PORT, "/pair", null).passed());
|
||||||
|
assertTrue(run(LAN_PORT, "/main-ABC123.js", null).passed());
|
||||||
|
assertTrue(run(LAN_PORT, "/api/config", null).passed());
|
||||||
|
assertTrue(run(LAN_PORT, "/api/remote-access/pair", null).passed());
|
||||||
|
assertTrue(run(LAN_PORT, "/api/remote-access/session", null).passed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void lan_api_requiresValidDeviceToken() throws Exception {
|
||||||
|
Outcome none = run(LAN_PORT, "/api/campaigns", null);
|
||||||
|
assertFalse(none.passed());
|
||||||
|
assertEquals(401, none.status());
|
||||||
|
assertTrue(none.body().contains("remote_pairing_required"));
|
||||||
|
|
||||||
|
assertEquals(401, run(LAN_PORT, "/api/images/42", "mauvais").status());
|
||||||
|
assertTrue(run(LAN_PORT, "/api/campaigns", "bon-jeton").passed());
|
||||||
|
assertTrue(run(LAN_PORT, "/api/images/42", "bon-jeton").passed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void lan_adminRoutes_areAlwaysForbidden_evenWhenPaired() throws Exception {
|
||||||
|
for (String path : new String[]{"/api/settings", "/api/settings/remote-access", "/api/admin/data/export", "/api/license"}) {
|
||||||
|
Outcome outcome = run(LAN_PORT, path, "bon-jeton");
|
||||||
|
assertFalse(outcome.passed(), path);
|
||||||
|
assertEquals(403, outcome.status(), path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -11,6 +11,8 @@ import com.loremind.domain.campaigncontext.ports.CampaignRepository;
|
|||||||
import com.loremind.domain.campaigncontext.ports.ChapterRepository;
|
import com.loremind.domain.campaigncontext.ports.ChapterRepository;
|
||||||
import com.loremind.domain.campaigncontext.ports.QuestRepository;
|
import com.loremind.domain.campaigncontext.ports.QuestRepository;
|
||||||
import com.loremind.domain.campaigncontext.ports.SceneRepository;
|
import com.loremind.domain.campaigncontext.ports.SceneRepository;
|
||||||
|
import com.loremind.domain.playcontext.Playthrough;
|
||||||
|
import com.loremind.domain.playcontext.ports.PlaythroughRepository;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -39,6 +41,7 @@ class CampaignTreeControllerTest {
|
|||||||
@Autowired private ChapterRepository chapterRepository;
|
@Autowired private ChapterRepository chapterRepository;
|
||||||
@Autowired private SceneRepository sceneRepository;
|
@Autowired private SceneRepository sceneRepository;
|
||||||
@Autowired private QuestRepository questRepository;
|
@Autowired private QuestRepository questRepository;
|
||||||
|
@Autowired private PlaythroughRepository playthroughRepository;
|
||||||
|
|
||||||
private String campaignId;
|
private String campaignId;
|
||||||
private String arcId;
|
private String arcId;
|
||||||
@@ -52,6 +55,7 @@ class CampaignTreeControllerTest {
|
|||||||
chapterId = chapterRepository.save(Chapter.builder().arcId(arcId).name("Chap").order(0).build()).getId();
|
chapterId = chapterRepository.save(Chapter.builder().arcId(arcId).name("Chap").order(0).build()).getId();
|
||||||
sceneRepository.save(Scene.builder().chapterId(chapterId).name("Scène").order(0).build());
|
sceneRepository.save(Scene.builder().chapterId(chapterId).name("Scène").order(0).build());
|
||||||
questRepository.save(Quest.builder().campaignId(campaignId).arcId(arcId).name("Quête").order(0).build());
|
questRepository.save(Quest.builder().campaignId(campaignId).arcId(arcId).name("Quête").order(0).build());
|
||||||
|
playthroughRepository.save(Playthrough.builder().campaignId(campaignId).name("Partie 1").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -65,6 +69,8 @@ class CampaignTreeControllerTest {
|
|||||||
.andExpect(jsonPath("$.scenesByChapter." + chapterId + "[0].name").value("Scène"))
|
.andExpect(jsonPath("$.scenesByChapter." + chapterId + "[0].name").value("Scène"))
|
||||||
.andExpect(jsonPath("$.quests", hasSize(1)))
|
.andExpect(jsonPath("$.quests", hasSize(1)))
|
||||||
.andExpect(jsonPath("$.quests[0].arcId").value(arcId))
|
.andExpect(jsonPath("$.quests[0].arcId").value(arcId))
|
||||||
|
.andExpect(jsonPath("$.playthroughs", hasSize(1)))
|
||||||
|
.andExpect(jsonPath("$.playthroughs[0].name").value("Partie 1"))
|
||||||
.andExpect(jsonPath("$.readiness.campaignId").value(campaignId))
|
.andExpect(jsonPath("$.readiness.campaignId").value(campaignId))
|
||||||
.andExpect(jsonPath("$.readiness.gaps").isArray());
|
.andExpect(jsonPath("$.readiness.gaps").isArray());
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -20,6 +20,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.everyItem;
|
||||||
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||||
@@ -98,6 +103,21 @@ class SessionControllerTest {
|
|||||||
.andExpect(jsonPath("$").isArray());
|
.andExpect(jsonPath("$").isArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getSessions_activeOnly_excludesEnded() throws Exception {
|
||||||
|
Session running = saveSession();
|
||||||
|
Session ended = sessionRepository.save(Session.builder()
|
||||||
|
.name("ended").playthroughId(playthroughId)
|
||||||
|
.startedAt(FIXED_TIME.minusHours(2))
|
||||||
|
.endedAt(FIXED_TIME.minusHours(1))
|
||||||
|
.build());
|
||||||
|
mockMvc.perform(get("/api/sessions").param("active", "true"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$[*].active", everyItem(is(true))))
|
||||||
|
.andExpect(jsonPath("$[*].id", hasItem(running.getId())))
|
||||||
|
.andExpect(jsonPath("$[*].id", not(hasItem(ended.getId()))));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getActive_global_returnsActive() throws Exception {
|
void getActive_global_returnsActive() throws Exception {
|
||||||
saveSession();
|
saveSession();
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
"zone.js"
|
"zone.js"
|
||||||
],
|
],
|
||||||
"tsConfig": "tsconfig.json",
|
"tsConfig": "tsconfig.json",
|
||||||
|
"allowedCommonJsDependencies": [
|
||||||
|
"qrcode"
|
||||||
|
],
|
||||||
"assets": [
|
"assets": [
|
||||||
"src/favicon.ico",
|
"src/favicon.ico",
|
||||||
"src/assets"
|
"src/assets"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { Page, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un bloc Texte au builder de template (grille de blocs) et le renomme.
|
||||||
|
*
|
||||||
|
* Le builder n'a plus de champ « + Ajouter un champ » : un clic sur un type de
|
||||||
|
* la palette ajoute en bas de la grille un bloc au nom par défaut (« Texte »,
|
||||||
|
* « Texte 2 »…), qu'on renomme dans son en-tête. Le nom est validé au blur.
|
||||||
|
*/
|
||||||
|
export async function addTextBlock(page: Page, name: string): Promise<void> {
|
||||||
|
const blocks = page.locator('.grid-block');
|
||||||
|
const before = await blocks.count();
|
||||||
|
|
||||||
|
await page.locator('.palette-item', { hasText: /^\s*Texte\s*$/ }).click();
|
||||||
|
await expect(blocks).toHaveCount(before + 1);
|
||||||
|
|
||||||
|
const nameInput = blocks.last().locator('.block-name-input');
|
||||||
|
await nameInput.fill(name);
|
||||||
|
await nameInput.blur();
|
||||||
|
await expect(page.locator(`.grid-block[data-block-name="${name}"]`)).toBeVisible();
|
||||||
|
}
|
||||||
@@ -113,7 +113,10 @@ test.describe('Scene edit', () => {
|
|||||||
|
|
||||||
const branchItem = branchesSection.locator('.branch-item').first();
|
const branchItem = branchesSection.locator('.branch-item').first();
|
||||||
await branchItem.getByPlaceholder(/Ex: Si les joueurs attaquent/i).fill('Si les PJ fuient');
|
await branchItem.getByPlaceholder(/Ex: Si les joueurs attaquent/i).fill('Si les PJ fuient');
|
||||||
await branchItem.locator('select').selectOption({ label: sibling.name });
|
// Une branche a 2 selects (scène cible + type de lien) : on vise celui qui liste la scène.
|
||||||
|
await branchItem
|
||||||
|
.locator('select', { has: page.locator('option', { hasText: sibling.name }) })
|
||||||
|
.selectOption({ label: sibling.name });
|
||||||
await branchItem.getByPlaceholder(/Jet de Persuasion/i).fill('Sur échec initiative');
|
await branchItem.getByPlaceholder(/Jet de Persuasion/i).fill('Sur échec initiative');
|
||||||
|
|
||||||
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
await page.getByRole('button', { name: /^Sauvegarder$/i }).click();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
import { seedLoreWithFolder, deleteLore, getTemplatesForLore, type SeededLore } from '../../fixtures/api';
|
import { seedLoreWithFolder, deleteLore, getTemplatesForLore, type SeededLore } from '../../fixtures/api';
|
||||||
|
import { addTextBlock } from '../../fixtures/template-builder';
|
||||||
|
|
||||||
test.describe('Template creation', () => {
|
test.describe('Template creation', () => {
|
||||||
let seeded: SeededLore;
|
let seeded: SeededLore;
|
||||||
@@ -50,14 +51,8 @@ test.describe('Template creation', () => {
|
|||||||
await page.getByLabel(/Nom du template/i).fill(templateName);
|
await page.getByLabel(/Nom du template/i).fill(templateName);
|
||||||
await page.getByLabel(/Dossier par défaut/i).selectOption({ label: seeded.rootFolderName });
|
await page.getByLabel(/Dossier par défaut/i).selectOption({ label: seeded.rootFolderName });
|
||||||
|
|
||||||
const addFieldInput = page.getByPlaceholder('+ Ajouter un champ');
|
await addTextBlock(page, 'Pouvoir');
|
||||||
await addFieldInput.fill('Pouvoir');
|
await addTextBlock(page, 'Origine');
|
||||||
await addFieldInput.press('Enter');
|
|
||||||
await expect(page.locator('.grid-block[data-block-name="Pouvoir"]')).toBeVisible();
|
|
||||||
|
|
||||||
await addFieldInput.fill('Origine');
|
|
||||||
await addFieldInput.press('Enter');
|
|
||||||
await expect(page.locator('.grid-block[data-block-name="Origine"]')).toBeVisible();
|
|
||||||
|
|
||||||
const origineBlock = page.locator('.grid-block[data-block-name="Origine"]');
|
const origineBlock = page.locator('.grid-block[data-block-name="Origine"]');
|
||||||
await origineBlock.getByRole('button', { name: 'Supprimer' }).click();
|
await origineBlock.getByRole('button', { name: 'Supprimer' }).click();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
type SeededLore,
|
type SeededLore,
|
||||||
type SeededTemplate,
|
type SeededTemplate,
|
||||||
} from '../../fixtures/api';
|
} from '../../fixtures/api';
|
||||||
|
import { addTextBlock } from '../../fixtures/template-builder';
|
||||||
|
|
||||||
test.describe('Template edit', () => {
|
test.describe('Template edit', () => {
|
||||||
let seeded: SeededLore;
|
let seeded: SeededLore;
|
||||||
@@ -55,10 +56,9 @@ test.describe('Template edit', () => {
|
|||||||
test('adds a new field, removes an existing one, and persists the order', async ({ page, request }) => {
|
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}`);
|
await page.goto(`/lore/${seeded.id}/templates/${template.id}`);
|
||||||
|
|
||||||
const addInput = page.getByPlaceholder('+ Ajouter un champ');
|
// Attendre les champs existants (chargés en asynchrone) avant d'en ajouter un.
|
||||||
await addInput.fill('Stats');
|
await expect(page.locator('.grid-block[data-block-name="Description"]')).toBeVisible();
|
||||||
await addInput.press('Enter');
|
await addTextBlock(page, 'Stats');
|
||||||
await expect(page.locator('.grid-block[data-block-name="Stats"]')).toBeVisible();
|
|
||||||
|
|
||||||
const descriptionBlock = page.locator('.grid-block[data-block-name="Description"]');
|
const descriptionBlock = page.locator('.grid-block[data-block-name="Description"]');
|
||||||
await descriptionBlock.getByRole('button', { name: 'Supprimer' }).click();
|
await descriptionBlock.getByRole('button', { name: 'Supprimer' }).click();
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
import { test, expect, type APIRequestContext, type Page } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
seedCampaign,
|
||||||
|
seedArc,
|
||||||
|
seedChapter,
|
||||||
|
seedScene,
|
||||||
|
deleteCampaign,
|
||||||
|
type SeededCampaign,
|
||||||
|
type SeededArc,
|
||||||
|
type SeededChapter,
|
||||||
|
type SeededScene,
|
||||||
|
} from '../../fixtures/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shell responsive au viewport téléphone (projet Playwright « mobile », 375 px).
|
||||||
|
*
|
||||||
|
* Sous 1024 px, le menu principal et l'arborescence deviennent des tiroirs
|
||||||
|
* off-canvas ouverts depuis une barre haute. On vérifie :
|
||||||
|
* - qu'aucun écran clé ne défile horizontalement — ni le document, ni
|
||||||
|
* `main.main-content` (le conteneur qui défile réellement : un débordement
|
||||||
|
* y produirait une barre horizontale sans toucher au document) ;
|
||||||
|
* - que la navigation reste accessible au doigt (ouverture, navigation,
|
||||||
|
* fermeture au changement de route / Échap / clic extérieur).
|
||||||
|
*/
|
||||||
|
|
||||||
|
async function expectNoHorizontalScroll(page: Page): Promise<void> {
|
||||||
|
const m = await page.evaluate(() => {
|
||||||
|
const main = document.querySelector('main.main-content');
|
||||||
|
return {
|
||||||
|
doc: document.documentElement.scrollWidth,
|
||||||
|
vw: window.innerWidth,
|
||||||
|
mainScroll: main?.scrollWidth ?? 0,
|
||||||
|
mainClient: main?.clientWidth ?? 0,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(m.doc, 'scroll horizontal du document').toBeLessThanOrEqual(m.vw);
|
||||||
|
expect(m.mainScroll, 'scroll horizontal de main.main-content').toBeLessThanOrEqual(m.mainClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function seedPlaythroughWithSession(
|
||||||
|
request: APIRequestContext,
|
||||||
|
campaignId: string,
|
||||||
|
): Promise<{ playthroughId: string; sessionId: string }> {
|
||||||
|
const ptRes = await request.post('/api/playthroughs', {
|
||||||
|
data: { campaignId, name: `E2E Partie ${Date.now()}`, description: 'Seeded by Playwright' },
|
||||||
|
});
|
||||||
|
expect(ptRes.ok(), `POST /api/playthroughs -> ${ptRes.status()}`).toBeTruthy();
|
||||||
|
const pt = await ptRes.json();
|
||||||
|
|
||||||
|
const clockRes = await request.post(`/api/playthroughs/${pt.id}/clocks`, {
|
||||||
|
data: { name: 'Le rituel du nécromancien', description: '', segments: 6 },
|
||||||
|
});
|
||||||
|
expect(clockRes.ok(), `POST clocks -> ${clockRes.status()}`).toBeTruthy();
|
||||||
|
|
||||||
|
const sRes = await request.post('/api/sessions', { data: { playthroughId: pt.id } });
|
||||||
|
expect(sRes.ok(), `POST /api/sessions -> ${sRes.status()}`).toBeTruthy();
|
||||||
|
const session = await sRes.json();
|
||||||
|
|
||||||
|
const eRes = await request.post(`/api/sessions/${session.id}/entries`, {
|
||||||
|
data: { type: 'NOTE', content: 'Les PJ arrivent à Brumecombe sous la pluie.', occurredAt: null },
|
||||||
|
});
|
||||||
|
expect(eRes.ok(), `POST entries -> ${eRes.status()}`).toBeTruthy();
|
||||||
|
|
||||||
|
return { playthroughId: pt.id, sessionId: session.id };
|
||||||
|
}
|
||||||
|
|
||||||
|
test.describe('Shell mobile (375 px)', () => {
|
||||||
|
test('liste des campagnes : pas de scroll horizontal, menu en tiroir', async ({ page }) => {
|
||||||
|
await page.goto('/campaigns');
|
||||||
|
await expect(page.getByRole('heading', { name: /Vos Campagnes/i })).toBeVisible();
|
||||||
|
await expectNoHorizontalScroll(page);
|
||||||
|
|
||||||
|
// Le menu principal est hors écran tant que le tiroir est fermé.
|
||||||
|
const menu = page.locator('app-sidebar');
|
||||||
|
await expect(menu).toBeHidden();
|
||||||
|
|
||||||
|
// Le libellé du burger alterne Ouvrir / Fermer : on le cible par aria-controls.
|
||||||
|
const burger = page.locator('button[aria-controls="app-main-nav"]');
|
||||||
|
await expect(burger).toHaveAccessibleName('Ouvrir le menu');
|
||||||
|
await burger.tap();
|
||||||
|
await expect(menu).toBeVisible();
|
||||||
|
await expect(burger).toHaveAttribute('aria-expanded', 'true');
|
||||||
|
await expect(burger).toHaveAccessibleName('Fermer le menu');
|
||||||
|
|
||||||
|
// Échap referme et rend le focus au bouton burger.
|
||||||
|
await page.keyboard.press('Escape');
|
||||||
|
await expect(menu).toBeHidden();
|
||||||
|
await expect(burger).toBeFocused();
|
||||||
|
|
||||||
|
// Clic hors du tiroir (voile) : referme aussi.
|
||||||
|
await burger.tap();
|
||||||
|
await expect(menu).toBeVisible();
|
||||||
|
await page.mouse.click(360, 400);
|
||||||
|
await expect(menu).toBeHidden();
|
||||||
|
|
||||||
|
// Navigation depuis le tiroir : la page change et le tiroir se ferme.
|
||||||
|
await burger.tap();
|
||||||
|
await menu.getByRole('button', { name: 'Lore', exact: true }).tap();
|
||||||
|
await expect(page).toHaveURL(/\/lore$/);
|
||||||
|
await expect(page.getByRole('heading', { name: /Vos Univers/i })).toBeVisible();
|
||||||
|
await expect(menu).toBeHidden();
|
||||||
|
await expectNoHorizontalScroll(page);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('avec une campagne', () => {
|
||||||
|
let campaign: SeededCampaign;
|
||||||
|
let arc: SeededArc;
|
||||||
|
let chapter: SeededChapter;
|
||||||
|
let scene: SeededScene;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ request }) => {
|
||||||
|
// Nom long volontaire : c'est lui qui faisait déborder l'en-tête du hub.
|
||||||
|
campaign = await seedCampaign(request, {
|
||||||
|
name: `E2E La Chute de la Maison Valcourt — campagne longue ${Date.now()}`,
|
||||||
|
});
|
||||||
|
arc = await seedArc(request, { campaignId: campaign.id });
|
||||||
|
chapter = await seedChapter(request, { arcId: arc.id });
|
||||||
|
scene = await seedScene(request, { chapterId: chapter.id, name: 'La taverne du Corbeau Borgne' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ request }) => {
|
||||||
|
if (campaign?.id) await deleteCampaign(request, campaign.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('hub campagne → scène via l’arborescence en tiroir', async ({ page }) => {
|
||||||
|
await page.goto(`/campaigns/${campaign.id}`);
|
||||||
|
await expect(page.getByRole('heading', { level: 1, name: campaign.name })).toBeVisible();
|
||||||
|
await expectNoHorizontalScroll(page);
|
||||||
|
|
||||||
|
// L'arborescence s'ouvre depuis la barre haute (bouton titré par la campagne).
|
||||||
|
const tree = page.locator('app-secondary-sidebar');
|
||||||
|
await expect(tree).toBeHidden();
|
||||||
|
await page.getByRole('button', { name: "Ouvrir l'arborescence" }).tap();
|
||||||
|
await expect(tree).toBeVisible();
|
||||||
|
|
||||||
|
// Déplie « Scènes » puis l'arc / le chapitre jusqu'à la scène, au doigt.
|
||||||
|
for (const label of [/Scènes/, new RegExp(arc.name), new RegExp(chapter.name)]) {
|
||||||
|
const row = tree.locator('.tree-row', { has: page.locator('.tree-btn', { hasText: label }) }).first();
|
||||||
|
if (await tree.getByRole('button', { name: scene.name }).isVisible()) break;
|
||||||
|
const chevron = row.locator('.chevron-btn');
|
||||||
|
if (await chevron.count()) await chevron.tap();
|
||||||
|
}
|
||||||
|
await tree.getByRole('button', { name: scene.name }).tap();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/scenes/${scene.id}$`));
|
||||||
|
await expect(page.getByRole('heading', { level: 1, name: scene.name })).toBeVisible();
|
||||||
|
await expect(tree).toBeHidden();
|
||||||
|
await expectNoHorizontalScroll(page);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('écran de séance : journal et horloges lisibles sans scroll horizontal', async ({ page, request }) => {
|
||||||
|
const { sessionId } = await seedPlaythroughWithSession(request, campaign.id);
|
||||||
|
|
||||||
|
await page.goto(`/sessions/${sessionId}`);
|
||||||
|
await expect(page.getByText('Les PJ arrivent à Brumecombe sous la pluie.')).toBeVisible();
|
||||||
|
await expect(page.getByText('Le rituel du nécromancien')).toBeVisible();
|
||||||
|
await expectNoHorizontalScroll(page);
|
||||||
|
|
||||||
|
// Le menu reste accessible depuis la séance.
|
||||||
|
await page.getByRole('button', { name: 'Ouvrir le menu' }).tap();
|
||||||
|
await expect(page.locator('app-sidebar')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Generated
+254
-47
@@ -22,6 +22,7 @@
|
|||||||
"dompurify": "^3.4.1",
|
"dompurify": "^3.4.1",
|
||||||
"lucide-angular": "^1.0.0",
|
"lucide-angular": "^1.0.0",
|
||||||
"marked": "^18.0.2",
|
"marked": "^18.0.2",
|
||||||
|
"qrcode": "^1.5.4",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.0",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
"zone.js": "~0.15.1"
|
"zone.js": "~0.15.1"
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
"@emnapi/runtime": "^1.11.0",
|
"@emnapi/runtime": "^1.11.0",
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@playwright/test": "^1.59.1",
|
"@playwright/test": "^1.59.1",
|
||||||
|
"@types/qrcode": "^1.5.6",
|
||||||
"@vitest/coverage-v8": "^4.1.9",
|
"@vitest/coverage-v8": "^4.1.9",
|
||||||
"angular-eslint": "21.4.0",
|
"angular-eslint": "21.4.0",
|
||||||
"eslint": "^10.3.0",
|
"eslint": "^10.3.0",
|
||||||
@@ -570,7 +572,6 @@
|
|||||||
"integrity": "sha512-BaUSLSyS+43fzDoJkTMkGqNdCXq3fGnUZsfXTmrlZPJf5AYFbgAlAPGZXDJyoNWw43fux+DafdlrlKcYUSgSIw==",
|
"integrity": "sha512-BaUSLSyS+43fzDoJkTMkGqNdCXq3fGnUZsfXTmrlZPJf5AYFbgAlAPGZXDJyoNWw43fux+DafdlrlKcYUSgSIw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular-eslint/bundled-angular-compiler": "21.4.0",
|
"@angular-eslint/bundled-angular-compiler": "21.4.0",
|
||||||
"eslint-scope": "9.1.2"
|
"eslint-scope": "9.1.2"
|
||||||
@@ -601,7 +602,6 @@
|
|||||||
"integrity": "sha512-zOW8FFa9qfbVkZ5TulxDkl1C3+gEjWfAAD5Z2MycA6pjVJQlLYPiTAGq+flOQ3yZfTT0z6kd5rejQMXWI81Dvg==",
|
"integrity": "sha512-zOW8FFa9qfbVkZ5TulxDkl1C3+gEjWfAAD5Z2MycA6pjVJQlLYPiTAGq+flOQ3yZfTT0z6kd5rejQMXWI81Dvg==",
|
||||||
"deprecated": "@angular/animations is deprecated. Use `animate.enter` and `animate.leave` instead. For more information see: https://v22.angular.dev/guide/animations.",
|
"deprecated": "@angular/animations is deprecated. Use `animate.enter` and `animate.leave` instead. For more information see: https://v22.angular.dev/guide/animations.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -734,7 +734,6 @@
|
|||||||
"integrity": "sha512-WOZF4p0SnrmBpNeiOA2pdp9OBvGnOSLWbGdRLXJykyseIiEn7+N+GZp+ZA1aNZB4SWolpYCZfTYwkpo6Sf/LXg==",
|
"integrity": "sha512-WOZF4p0SnrmBpNeiOA2pdp9OBvGnOSLWbGdRLXJykyseIiEn7+N+GZp+ZA1aNZB4SWolpYCZfTYwkpo6Sf/LXg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular-devkit/architect": "0.2102.18",
|
"@angular-devkit/architect": "0.2102.18",
|
||||||
"@angular-devkit/core": "21.2.18",
|
"@angular-devkit/core": "21.2.18",
|
||||||
@@ -769,7 +768,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/common/-/common-21.2.17.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/common/-/common-21.2.17.tgz",
|
||||||
"integrity": "sha512-hqAQxRfi5ldFE42suAXRcY+JCANrUh7fuSQ/DtZ7L896id5BT/exuv6dWNBC1PyAfQmRbpD5Pt6/pd+tNLyhDQ==",
|
"integrity": "sha512-hqAQxRfi5ldFE42suAXRcY+JCANrUh7fuSQ/DtZ7L896id5BT/exuv6dWNBC1PyAfQmRbpD5Pt6/pd+tNLyhDQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -786,7 +784,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-21.2.17.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-21.2.17.tgz",
|
||||||
"integrity": "sha512-p+NdjYiwAz9Zmu2yul0LlMXaFjMISVVa24+/MVMoKFeQeI82QE8jDywPlnOSHQHvdCcQVpS7saeEriZzX3JuBQ==",
|
"integrity": "sha512-p+NdjYiwAz9Zmu2yul0LlMXaFjMISVVa24+/MVMoKFeQeI82QE8jDywPlnOSHQHvdCcQVpS7saeEriZzX3JuBQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -800,7 +797,6 @@
|
|||||||
"integrity": "sha512-KithZ3b0HBFH0NbUcswBcjpN9y09vLbarMD7qmGWTnGUBk4W8cn4sbT8zJyv9CRKg9ZcuUBeJYKUfUPn/u/5OQ==",
|
"integrity": "sha512-KithZ3b0HBFH0NbUcswBcjpN9y09vLbarMD7qmGWTnGUBk4W8cn4sbT8zJyv9CRKg9ZcuUBeJYKUfUPn/u/5OQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "7.29.0",
|
"@babel/core": "7.29.0",
|
||||||
"@jridgewell/sourcemap-codec": "^1.4.14",
|
"@jridgewell/sourcemap-codec": "^1.4.14",
|
||||||
@@ -881,7 +877,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/core/-/core-21.2.17.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/core/-/core-21.2.17.tgz",
|
||||||
"integrity": "sha512-wYHpwIdnUnjQFOJJNqRcGx7LS3u64jT+R9L0TnMR/ViBM9dQgGYImlSikkftg2yrFCNo5aKRxhG2LLskQurVdg==",
|
"integrity": "sha512-wYHpwIdnUnjQFOJJNqRcGx7LS3u64jT+R9L0TnMR/ViBM9dQgGYImlSikkftg2yrFCNo5aKRxhG2LLskQurVdg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -926,7 +921,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-21.2.17.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-21.2.17.tgz",
|
||||||
"integrity": "sha512-ROdSliejY37g1EphYmweYdm5cHM8HY3X4tbWt4ubxmhTyYgfN3nxrxfGQ/n7Mz5tDY9VXVLIGDgjLOGYOo4uTQ==",
|
"integrity": "sha512-ROdSliejY37g1EphYmweYdm5cHM8HY3X4tbWt4ubxmhTyYgfN3nxrxfGQ/n7Mz5tDY9VXVLIGDgjLOGYOo4uTQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -1012,7 +1006,6 @@
|
|||||||
"integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==",
|
"integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.29.7",
|
"@babel/code-frame": "^7.29.7",
|
||||||
"@babel/generator": "^7.29.7",
|
"@babel/generator": "^7.29.7",
|
||||||
@@ -2746,7 +2739,6 @@
|
|||||||
"integrity": "sha512-TC8MkTuZUtcTSiFeuC0ksCh9QIJ5+F21MvZ4Wn4ORfYaFJ/0dsiudv5tVkejgwZlwQ39jL9WWDe2lz8x0WglOA==",
|
"integrity": "sha512-TC8MkTuZUtcTSiFeuC0ksCh9QIJ5+F21MvZ4Wn4ORfYaFJ/0dsiudv5tVkejgwZlwQ39jL9WWDe2lz8x0WglOA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emnapi/wasi-threads": "1.2.2",
|
"@emnapi/wasi-threads": "1.2.2",
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
@@ -2758,7 +2750,6 @@
|
|||||||
"integrity": "sha512-kyOl3X0DuTiT1h2ft8r2fYO8JYtU9a9Xis/zBSiGArNaagCOWx90N1k2wxp18czFDH+OgcWGb5ZP/XMt3dcyPA==",
|
"integrity": "sha512-kyOl3X0DuTiT1h2ft8r2fYO8JYtU9a9Xis/zBSiGArNaagCOWx90N1k2wxp18czFDH+OgcWGb5ZP/XMt3dcyPA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
@@ -3663,7 +3654,6 @@
|
|||||||
"integrity": "sha512-Dx/y9bCQcXLI5ooQ5KyvA4FTgeo2jYj/7plWfV5Ak5wDPKQZgudKez2ixyfz7tKXzcJciTxqLeK7R9HItwiByg==",
|
"integrity": "sha512-Dx/y9bCQcXLI5ooQ5KyvA4FTgeo2jYj/7plWfV5Ak5wDPKQZgudKez2ixyfz7tKXzcJciTxqLeK7R9HItwiByg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@inquirer/checkbox": "^4.3.2",
|
"@inquirer/checkbox": "^4.3.2",
|
||||||
"@inquirer/confirm": "^5.1.21",
|
"@inquirer/confirm": "^5.1.21",
|
||||||
@@ -4903,7 +4893,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@ngx-translate/core/-/core-18.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@ngx-translate/core/-/core-18.0.0.tgz",
|
||||||
"integrity": "sha512-Z9u9AXaeuyeHHimivvJQvhal/LJNB+5tlH+FimSU4QQ61FrtRDqgyn6nfFbc6Cb+59NDZdsh4QeTJyPCldFUwA==",
|
"integrity": "sha512-Z9u9AXaeuyeHHimivvJQvhal/LJNB+5tlH+FimSU4QQ61FrtRDqgyn6nfFbc6Cb+59NDZdsh4QeTJyPCldFUwA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -6540,6 +6529,16 @@
|
|||||||
"undici-types": "~8.3.0"
|
"undici-types": "~8.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/qrcode": {
|
||||||
|
"version": "1.5.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/qrcode/-/qrcode-1.5.6.tgz",
|
||||||
|
"integrity": "sha512-te7NQcV2BOvdj2b1hCAHzAoMNuj65kNBMz0KBaxM6c3VGBOhU0dURQKOtH8CFNI/dsKkwlv32p26qYQTWoB5bw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/qs": {
|
"node_modules/@types/qs": {
|
||||||
"version": "6.15.1",
|
"version": "6.15.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz",
|
||||||
@@ -7211,7 +7210,6 @@
|
|||||||
"integrity": "sha512-xyLtl9DUBBFrcJS4x2pIqGLH68/tC2uOa4Z7pUteW09D3bXnnXUom4dyPikzWgB7llmIc1zoeI3aoUdC4rPK/Q==",
|
"integrity": "sha512-xyLtl9DUBBFrcJS4x2pIqGLH68/tC2uOa4Z7pUteW09D3bXnnXUom4dyPikzWgB7llmIc1zoeI3aoUdC4rPK/Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
||||||
},
|
},
|
||||||
@@ -7254,7 +7252,6 @@
|
|||||||
"integrity": "sha512-fUKaeAvrTuQg/Tgt3nliAUSZHJM6DlCcfyEmxCvlX8kieWSStBX+5O5Fnidtc3i2JrH+9c/GL4RY2iasd/GPTA==",
|
"integrity": "sha512-fUKaeAvrTuQg/Tgt3nliAUSZHJM6DlCcfyEmxCvlX8kieWSStBX+5O5Fnidtc3i2JrH+9c/GL4RY2iasd/GPTA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@eslint-community/eslint-utils": "^4.9.1",
|
"@eslint-community/eslint-utils": "^4.9.1",
|
||||||
"@typescript-eslint/scope-manager": "8.63.0",
|
"@typescript-eslint/scope-manager": "8.63.0",
|
||||||
@@ -7323,7 +7320,6 @@
|
|||||||
"integrity": "sha512-IM49HmthevbgAO4anp1hwtoT9wYe59w0LR00gr+eagHE+ZJ5lK4sLPeO0ubgoJcwLk6dehU3R24N+FbEEKDc8g==",
|
"integrity": "sha512-IM49HmthevbgAO4anp1hwtoT9wYe59w0LR00gr+eagHE+ZJ5lK4sLPeO0ubgoJcwLk6dehU3R24N+FbEEKDc8g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bcoe/v8-coverage": "^1.0.2",
|
"@bcoe/v8-coverage": "^1.0.2",
|
||||||
"@vitest/utils": "4.1.10",
|
"@vitest/utils": "4.1.10",
|
||||||
@@ -7681,7 +7677,6 @@
|
|||||||
"integrity": "sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==",
|
"integrity": "sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"acorn": "bin/acorn"
|
"acorn": "bin/acorn"
|
||||||
},
|
},
|
||||||
@@ -7757,7 +7752,6 @@
|
|||||||
"integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==",
|
"integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"fast-uri": "^3.0.1",
|
"fast-uri": "^3.0.1",
|
||||||
@@ -8303,7 +8297,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"baseline-browser-mapping": "^2.10.42",
|
"baseline-browser-mapping": "^2.10.42",
|
||||||
"caniuse-lite": "^1.0.30001800",
|
"caniuse-lite": "^1.0.30001800",
|
||||||
@@ -8447,6 +8440,15 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/camelcase": {
|
||||||
|
"version": "5.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
|
||||||
|
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001802",
|
"version": "1.0.30001802",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001802.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001802.tgz",
|
||||||
@@ -8673,7 +8675,6 @@
|
|||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color-name": "~1.1.4"
|
"color-name": "~1.1.4"
|
||||||
@@ -8686,7 +8687,6 @@
|
|||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/colorette": {
|
"node_modules/colorette": {
|
||||||
@@ -9038,6 +9038,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/decamelize": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/deep-is": {
|
"node_modules/deep-is": {
|
||||||
"version": "0.1.4",
|
"version": "0.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
|
||||||
@@ -9127,6 +9136,12 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/dijkstrajs": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/dijkstrajs/-/dijkstrajs-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/dns-packet": {
|
"node_modules/dns-packet": {
|
||||||
"version": "5.6.1",
|
"version": "5.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.6.1.tgz",
|
||||||
@@ -9469,7 +9484,6 @@
|
|||||||
"integrity": "sha512-6lVbcqSodALYo+4ELD0heG6lFiFxnLMuLkiMi2qV8LMp54N8tE8FT1GMH+ev4Ti00nFjNze2+Su6DsV5OQW3Dg==",
|
"integrity": "sha512-6lVbcqSodALYo+4ELD0heG6lFiFxnLMuLkiMi2qV8LMp54N8tE8FT1GMH+ev4Ti00nFjNze2+Su6DsV5OQW3Dg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
@@ -9800,7 +9814,6 @@
|
|||||||
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
|
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"accepts": "^2.0.0",
|
"accepts": "^2.0.0",
|
||||||
"body-parser": "^2.2.1",
|
"body-parser": "^2.2.1",
|
||||||
@@ -10137,7 +10150,6 @@
|
|||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
||||||
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
|
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
|
||||||
"dev": true,
|
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "6.* || 8.* || >= 10.*"
|
"node": "6.* || 8.* || >= 10.*"
|
||||||
@@ -10332,7 +10344,6 @@
|
|||||||
"integrity": "sha512-YwUvVpSF7m1yOblFPrU3Hbo8XhPheBoiyfGuII6z19LnOr6JpDnyyp7LFNrfV56wS8tpvtBFGRISHN02pDdLOA==",
|
"integrity": "sha512-YwUvVpSF7m1yOblFPrU3Hbo8XhPheBoiyfGuII6z19LnOr6JpDnyyp7LFNrfV56wS8tpvtBFGRISHN02pDdLOA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.9.0"
|
"node": ">=16.9.0"
|
||||||
}
|
}
|
||||||
@@ -11221,7 +11232,6 @@
|
|||||||
"integrity": "sha512-j1n1IuTX1VQjIy3tT7cyGbX7nvQOsFLoIqobZv4ttI5axP923gA44zUj6miiA6R5Aoms4sEGVIIcucXUbRI14g==",
|
"integrity": "sha512-j1n1IuTX1VQjIy3tT7cyGbX7nvQOsFLoIqobZv4ttI5axP923gA44zUj6miiA6R5Aoms4sEGVIIcucXUbRI14g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"copy-anything": "^2.0.1",
|
"copy-anything": "^2.0.1",
|
||||||
"parse-node-version": "^1.0.1",
|
"parse-node-version": "^1.0.1",
|
||||||
@@ -12627,6 +12637,15 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/p-try": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
|
||||||
|
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/pacote": {
|
"node_modules/pacote": {
|
||||||
"version": "21.5.1",
|
"version": "21.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/pacote/-/pacote-21.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/pacote/-/pacote-21.5.1.tgz",
|
||||||
@@ -12787,7 +12806,6 @@
|
|||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
|
||||||
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
|
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@@ -12959,6 +12977,15 @@
|
|||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/pngjs": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.13.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/postcss": {
|
"node_modules/postcss": {
|
||||||
"version": "8.5.12",
|
"version": "8.5.12",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.12.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.12.tgz",
|
||||||
@@ -12979,7 +13006,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^3.3.11",
|
"nanoid": "^3.3.11",
|
||||||
"picocolors": "^1.1.1",
|
"picocolors": "^1.1.1",
|
||||||
@@ -13231,6 +13257,177 @@
|
|||||||
"node": ">=16.0.0"
|
"node": ">=16.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/qrcode": {
|
||||||
|
"version": "1.5.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",
|
||||||
|
"integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"dijkstrajs": "^1.0.1",
|
||||||
|
"pngjs": "^5.0.0",
|
||||||
|
"yargs": "^15.3.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"qrcode": "bin/qrcode"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.13.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/ansi-regex": {
|
||||||
|
"version": "5.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
|
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/cliui": {
|
||||||
|
"version": "6.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
|
||||||
|
"integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"string-width": "^4.2.0",
|
||||||
|
"strip-ansi": "^6.0.0",
|
||||||
|
"wrap-ansi": "^6.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/emoji-regex": {
|
||||||
|
"version": "8.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||||
|
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/find-up": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"locate-path": "^5.0.0",
|
||||||
|
"path-exists": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/is-fullwidth-code-point": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/locate-path": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"p-locate": "^4.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/p-limit": {
|
||||||
|
"version": "2.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
|
||||||
|
"integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"p-try": "^2.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/p-locate": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"p-limit": "^2.2.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/string-width": {
|
||||||
|
"version": "4.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||||
|
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"emoji-regex": "^8.0.0",
|
||||||
|
"is-fullwidth-code-point": "^3.0.0",
|
||||||
|
"strip-ansi": "^6.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/strip-ansi": {
|
||||||
|
"version": "6.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||||
|
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-regex": "^5.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/y18n": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/yargs": {
|
||||||
|
"version": "15.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz",
|
||||||
|
"integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"cliui": "^6.0.0",
|
||||||
|
"decamelize": "^1.2.0",
|
||||||
|
"find-up": "^4.1.0",
|
||||||
|
"get-caller-file": "^2.0.1",
|
||||||
|
"require-directory": "^2.1.1",
|
||||||
|
"require-main-filename": "^2.0.0",
|
||||||
|
"set-blocking": "^2.0.0",
|
||||||
|
"string-width": "^4.2.0",
|
||||||
|
"which-module": "^2.0.0",
|
||||||
|
"y18n": "^4.0.0",
|
||||||
|
"yargs-parser": "^18.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qrcode/node_modules/yargs-parser": {
|
||||||
|
"version": "18.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz",
|
||||||
|
"integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"camelcase": "^5.0.0",
|
||||||
|
"decamelize": "^1.2.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/qs": {
|
"node_modules/qs": {
|
||||||
"version": "6.15.3",
|
"version": "6.15.3",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.3.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.3.tgz",
|
||||||
@@ -13406,6 +13603,15 @@
|
|||||||
"regjsparser": "bin/parser"
|
"regjsparser": "bin/parser"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/require-directory": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/require-from-string": {
|
"node_modules/require-from-string": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
||||||
@@ -13416,6 +13622,12 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/require-main-filename": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/requires-port": {
|
"node_modules/requires-port": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||||
@@ -13643,7 +13855,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
|
||||||
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.1.0"
|
"tslib": "^2.1.0"
|
||||||
}
|
}
|
||||||
@@ -13682,7 +13893,6 @@
|
|||||||
"integrity": "sha512-fDz1zJpd5GycprAbu4Q2PV/RprsRtKC/0z82z0JLgdytmcq0+ujJbJ/09bPGDxCLkKY3Np5cRAOcWiVkLXJURg==",
|
"integrity": "sha512-fDz1zJpd5GycprAbu4Q2PV/RprsRtKC/0z82z0JLgdytmcq0+ujJbJ/09bPGDxCLkKY3Np5cRAOcWiVkLXJURg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chokidar": "^4.0.0",
|
"chokidar": "^4.0.0",
|
||||||
"immutable": "^5.0.2",
|
"immutable": "^5.0.2",
|
||||||
@@ -14048,6 +14258,12 @@
|
|||||||
"url": "https://opencollective.com/express"
|
"url": "https://opencollective.com/express"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/set-blocking": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/setprototypeof": {
|
"node_modules/setprototypeof": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||||
@@ -14808,8 +15024,7 @@
|
|||||||
"version": "2.8.1",
|
"version": "2.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
||||||
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
||||||
"license": "0BSD",
|
"license": "0BSD"
|
||||||
"peer": true
|
|
||||||
},
|
},
|
||||||
"node_modules/tsyringe": {
|
"node_modules/tsyringe": {
|
||||||
"version": "4.10.0",
|
"version": "4.10.0",
|
||||||
@@ -14905,7 +15120,6 @@
|
|||||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
@@ -14920,7 +15134,6 @@
|
|||||||
"integrity": "sha512-pJw051uomb3ZeCzGTpRb8RbEqB5Y4WWet8gl/GcTlU35BSx0PVdZ86/bqkQCyKKuraVQEK7r6kBHQXF+fBhkoQ==",
|
"integrity": "sha512-pJw051uomb3ZeCzGTpRb8RbEqB5Y4WWet8gl/GcTlU35BSx0PVdZ86/bqkQCyKKuraVQEK7r6kBHQXF+fBhkoQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "8.59.2",
|
"@typescript-eslint/eslint-plugin": "8.59.2",
|
||||||
"@typescript-eslint/parser": "8.59.2",
|
"@typescript-eslint/parser": "8.59.2",
|
||||||
@@ -15259,7 +15472,6 @@
|
|||||||
"integrity": "sha512-4XP60spRGjSZFf1qYH+dJIkK2znL3zQfl9KkOV9MkkRR/3Dls0dxaBsQPTloEc5BLXWPL9vsOxopxyKoMmDueg==",
|
"integrity": "sha512-4XP60spRGjSZFf1qYH+dJIkK2znL3zQfl9KkOV9MkkRR/3Dls0dxaBsQPTloEc5BLXWPL9vsOxopxyKoMmDueg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.27.0 || ^0.28.0",
|
"esbuild": "^0.27.0 || ^0.28.0",
|
||||||
"fdir": "^6.5.0",
|
"fdir": "^6.5.0",
|
||||||
@@ -15350,7 +15562,6 @@
|
|||||||
"integrity": "sha512-R9jUTe5S4Qb0HCd4TNqpC7oGcrMssMRGXLW80ubjWsW9VH5GF8y1Y0SFLY9AbqSk6nt0PnOx4H4WNJYZ13GUPw==",
|
"integrity": "sha512-R9jUTe5S4Qb0HCd4TNqpC7oGcrMssMRGXLW80ubjWsW9VH5GF8y1Y0SFLY9AbqSk6nt0PnOx4H4WNJYZ13GUPw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitest/expect": "4.1.10",
|
"@vitest/expect": "4.1.10",
|
||||||
"@vitest/mocker": "4.1.10",
|
"@vitest/mocker": "4.1.10",
|
||||||
@@ -15473,7 +15684,6 @@
|
|||||||
"integrity": "sha512-dRXm0a2qcHPUBEzVk8uph0xWSjV/xZxenQQbLwnwP7caQCYpqG1qddwlyEkIDkYn0K8tvmcrZ+bOrzoQ3HxCDw==",
|
"integrity": "sha512-dRXm0a2qcHPUBEzVk8uph0xWSjV/xZxenQQbLwnwP7caQCYpqG1qddwlyEkIDkYn0K8tvmcrZ+bOrzoQ3HxCDw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/eslint-scope": "^3.7.7",
|
"@types/eslint-scope": "^3.7.7",
|
||||||
"@types/estree": "^1.0.8",
|
"@types/estree": "^1.0.8",
|
||||||
@@ -16187,6 +16397,12 @@
|
|||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/which-module": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/why-is-node-running": {
|
"node_modules/why-is-node-running": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",
|
||||||
@@ -16225,7 +16441,6 @@
|
|||||||
"version": "6.2.0",
|
"version": "6.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
|
||||||
"integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
|
"integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-styles": "^4.0.0",
|
"ansi-styles": "^4.0.0",
|
||||||
@@ -16240,7 +16455,6 @@
|
|||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@@ -16250,7 +16464,6 @@
|
|||||||
"version": "4.3.0",
|
"version": "4.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color-convert": "^2.0.1"
|
"color-convert": "^2.0.1"
|
||||||
@@ -16266,14 +16479,12 @@
|
|||||||
"version": "8.0.0",
|
"version": "8.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||||
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
|
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/wrap-ansi/node_modules/is-fullwidth-code-point": {
|
"node_modules/wrap-ansi/node_modules/is-fullwidth-code-point": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||||
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@@ -16283,7 +16494,6 @@
|
|||||||
"version": "4.2.3",
|
"version": "4.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||||
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"emoji-regex": "^8.0.0",
|
"emoji-regex": "^8.0.0",
|
||||||
@@ -16298,7 +16508,6 @@
|
|||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||||
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-regex": "^5.0.1"
|
"ansi-regex": "^5.0.1"
|
||||||
@@ -16477,7 +16686,6 @@
|
|||||||
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
@@ -16496,8 +16704,7 @@
|
|||||||
"version": "0.15.1",
|
"version": "0.15.1",
|
||||||
"resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.15.1.tgz",
|
"resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.15.1.tgz",
|
||||||
"integrity": "sha512-XE96n56IQpJM7NAoXswY3XRLcWFW83xe0BiAOeMD7K5k5xecOeul3Qcpx6GqEeeHNkW5DWL5zOyTbEfB4eti8w==",
|
"integrity": "sha512-XE96n56IQpJM7NAoXswY3XRLcWFW83xe0BiAOeMD7K5k5xecOeul3Qcpx6GqEeeHNkW5DWL5zOyTbEfB4eti8w==",
|
||||||
"license": "MIT",
|
"license": "MIT"
|
||||||
"peer": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
"dompurify": "^3.4.1",
|
"dompurify": "^3.4.1",
|
||||||
"lucide-angular": "^1.0.0",
|
"lucide-angular": "^1.0.0",
|
||||||
"marked": "^18.0.2",
|
"marked": "^18.0.2",
|
||||||
|
"qrcode": "^1.5.4",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.0",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
"zone.js": "~0.15.1"
|
"zone.js": "~0.15.1"
|
||||||
@@ -46,6 +47,7 @@
|
|||||||
"@emnapi/runtime": "^1.11.0",
|
"@emnapi/runtime": "^1.11.0",
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@playwright/test": "^1.59.1",
|
"@playwright/test": "^1.59.1",
|
||||||
|
"@types/qrcode": "^1.5.6",
|
||||||
"@vitest/coverage-v8": "^4.1.9",
|
"@vitest/coverage-v8": "^4.1.9",
|
||||||
"angular-eslint": "21.4.0",
|
"angular-eslint": "21.4.0",
|
||||||
"eslint": "^10.3.0",
|
"eslint": "^10.3.0",
|
||||||
|
|||||||
@@ -30,7 +30,21 @@ export default defineConfig({
|
|||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
name: 'chromium',
|
name: 'chromium',
|
||||||
|
testIgnore: /responsive\//,
|
||||||
use: { ...devices['Desktop Chrome'] },
|
use: { ...devices['Desktop Chrome'] },
|
||||||
},
|
},
|
||||||
|
// Téléphone (375 px, tactile) : shell en tiroirs, absence de scroll horizontal.
|
||||||
|
// Chromium « Desktop Chrome » redimensionné plutôt qu'un preset d'appareil :
|
||||||
|
// même navigateur que la CI (seul chromium y est installé), largeur exacte.
|
||||||
|
{
|
||||||
|
name: 'mobile',
|
||||||
|
testMatch: /responsive\/.*\.spec\.ts/,
|
||||||
|
use: {
|
||||||
|
...devices['Desktop Chrome'],
|
||||||
|
viewport: { width: 375, height: 812 },
|
||||||
|
isMobile: true,
|
||||||
|
hasTouch: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,52 @@
|
|||||||
<app-update-banner></app-update-banner>
|
<app-update-banner></app-update-banner>
|
||||||
|
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<app-sidebar></app-sidebar>
|
<!-- Barre haute (< 1024 px) : ouvre les tiroirs menu / arborescence. Masquée en CSS sur desktop. -->
|
||||||
|
<header class="mobile-topbar">
|
||||||
|
<button #mainToggle type="button" class="topbar-btn"
|
||||||
|
aria-controls="app-main-nav"
|
||||||
|
[attr.aria-expanded]="openDrawer() === 'main'"
|
||||||
|
[attr.aria-label]="(openDrawer() === 'main' ? 'mobileShell.closeMenu' : 'mobileShell.openMenu') | translate"
|
||||||
|
(click)="toggleDrawer('main')">
|
||||||
|
<lucide-icon [img]="openDrawer() === 'main' ? X : Menu" [size]="20"></lucide-icon>
|
||||||
|
</button>
|
||||||
|
@if (sidebarConfig$ | async; as config) {
|
||||||
|
<button #treeToggle type="button" class="topbar-btn topbar-tree"
|
||||||
|
aria-controls="app-tree-nav"
|
||||||
|
[attr.aria-expanded]="openDrawer() === 'tree'"
|
||||||
|
[attr.aria-label]="(openDrawer() === 'tree' ? 'mobileShell.closeTree' : 'mobileShell.openTree') | translate"
|
||||||
|
(click)="toggleDrawer('tree')">
|
||||||
|
<lucide-icon [img]="PanelLeft" [size]="18"></lucide-icon>
|
||||||
|
<span class="topbar-title">{{ config.title }}</span>
|
||||||
|
</button>
|
||||||
|
} @else {
|
||||||
|
<span class="topbar-brand">
|
||||||
|
<img src="assets/logo.png" alt="" />
|
||||||
|
<span>DM Loremind</span>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
<!-- Séance en cours : un tap y ramène (visible seulement si une séance tourne). -->
|
||||||
|
<app-active-session-shortcut compact class="topbar-session"></app-active-session-shortcut>
|
||||||
|
<button type="button" class="topbar-btn topbar-search"
|
||||||
|
[attr.aria-label]="'mobileShell.search' | translate"
|
||||||
|
(click)="openSearch()">
|
||||||
|
<lucide-icon [img]="Search" [size]="18"></lucide-icon>
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<app-sidebar id="app-main-nav"
|
||||||
|
[class.drawer-open]="openDrawer() === 'main'"
|
||||||
|
[attr.role]="isCompact() ? 'dialog' : null"
|
||||||
|
[attr.aria-modal]="isCompact() && openDrawer() === 'main' ? 'true' : null"
|
||||||
|
[attr.aria-label]="'mobileShell.mainNav' | translate"></app-sidebar>
|
||||||
|
|
||||||
@if (sidebarConfig$ | async; as config) {
|
@if (sidebarConfig$ | async; as config) {
|
||||||
<app-secondary-sidebar
|
<app-secondary-sidebar id="app-tree-nav"
|
||||||
|
[class.drawer-open]="openDrawer() === 'tree'"
|
||||||
|
[attr.role]="isCompact() ? 'dialog' : null"
|
||||||
|
[attr.aria-modal]="isCompact() && openDrawer() === 'tree' ? 'true' : null"
|
||||||
|
[attr.aria-label]="'mobileShell.treeNav' | translate"
|
||||||
|
[drawerMode]="isCompact()"
|
||||||
[title]="config.title"
|
[title]="config.title"
|
||||||
[titleRoute]="config.titleRoute || null"
|
[titleRoute]="config.titleRoute || null"
|
||||||
[items]="config.items"
|
[items]="config.items"
|
||||||
@@ -16,7 +58,11 @@
|
|||||||
</app-secondary-sidebar>
|
</app-secondary-sidebar>
|
||||||
}
|
}
|
||||||
|
|
||||||
<main class="main-content">
|
@if (openDrawer()) {
|
||||||
|
<div class="drawer-backdrop" aria-hidden="true" (click)="closeDrawer()"></div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<main #mainContent class="main-content" tabindex="-1">
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,14 +1,144 @@
|
|||||||
|
// Points de rupture du shell (cf. styles/_responsive.scss) :
|
||||||
|
// - >= 1024 px : colonnes fixes (menu + arborescence + contenu) ;
|
||||||
|
// - < 1024 px : barre haute + menu et arborescence en tiroirs off-canvas ;
|
||||||
|
// - < 768 px : une seule colonne, marges réduites.
|
||||||
|
$compact: 1023.98px;
|
||||||
|
$phone: 767.98px;
|
||||||
|
$topbar-height: 52px;
|
||||||
|
|
||||||
.app-container {
|
.app-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
height: 100dvh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.main-content {
|
.main-content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
// min-width: 0 — sans ça un contenu large (tableau, graphe) élargit la colonne
|
||||||
|
// flex au lieu de défiler dedans, et toute la page déborde horizontalement.
|
||||||
|
min-width: 0;
|
||||||
// padding-top: 0 — sinon le contenu defile dans la zone de padding
|
// 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
|
// 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
|
// padding-box). Chaque page-wrapper definit deja son propre padding-top
|
||||||
// qui devient l'unique source d'espacement haut.
|
// qui devient l'unique source d'espacement haut.
|
||||||
padding: 0 2rem 2rem;
|
padding: 0 2rem 2rem;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
|
// Focus programmatique après navigation depuis un tiroir : pas d'anneau visible.
|
||||||
|
&:focus { outline: none; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-topbar,
|
||||||
|
.drawer-backdrop { display: none; }
|
||||||
|
|
||||||
|
@media (max-width: $compact) {
|
||||||
|
.app-container { flex-direction: column; }
|
||||||
|
|
||||||
|
.mobile-topbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25rem;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
height: $topbar-height;
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
background: #0f0f1a;
|
||||||
|
border-bottom: 1px solid #1e1e3a;
|
||||||
|
position: relative;
|
||||||
|
z-index: 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
min-width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
padding: 0 0.6rem;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
color: #d1d5db;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover, &[aria-expanded='true'] { background: #1f2937; color: white; }
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: -2px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Le bouton arborescence porte le titre de la section (campagne, lore) et prend
|
||||||
|
// toute la place disponible : c'est la cible la plus utilisée au doigt.
|
||||||
|
.topbar-tree {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
justify-content: flex-start;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar-title {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar-brand {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
min-width: 0;
|
||||||
|
padding-left: 0.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: white;
|
||||||
|
|
||||||
|
img { width: 1.5rem; height: 1.5rem; border-radius: 5px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Les deux sidebars deviennent des tiroirs : hors flux, cachés à gauche.
|
||||||
|
// visibility: hidden (retardée le temps de l'animation) les sort aussi de
|
||||||
|
// l'ordre de tabulation quand ils sont fermés.
|
||||||
|
app-sidebar,
|
||||||
|
app-secondary-sidebar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 150;
|
||||||
|
max-width: 88vw;
|
||||||
|
transform: translateX(-100%);
|
||||||
|
visibility: hidden;
|
||||||
|
transition: transform 0.25s ease, visibility 0s linear 0.25s;
|
||||||
|
box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
|
||||||
|
|
||||||
|
&.drawer-open {
|
||||||
|
transform: none;
|
||||||
|
visibility: visible;
|
||||||
|
transition: transform 0.25s ease;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-backdrop {
|
||||||
|
display: block;
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 149;
|
||||||
|
background: rgba(0, 0, 0, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 0 1.25rem 1.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: $phone) {
|
||||||
|
.main-content { padding: 0 0.75rem 1.25rem; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
app-sidebar,
|
||||||
|
app-secondary-sidebar,
|
||||||
|
app-sidebar.drawer-open,
|
||||||
|
app-secondary-sidebar.drawer-open { transition: none; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,43 @@
|
|||||||
import { Component, HostListener } from '@angular/core';
|
import { Component, ElementRef, HostListener, effect, inject, signal, viewChild } from '@angular/core';
|
||||||
import { AsyncPipe } from '@angular/common';
|
import { AsyncPipe } from '@angular/common';
|
||||||
import { RouterOutlet } from '@angular/router';
|
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
||||||
|
import { BreakpointObserver } from '@angular/cdk/layout';
|
||||||
|
import { NavigationEnd, NavigationSkipped, Router, RouterOutlet } from '@angular/router';
|
||||||
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
|
import { LucideAngularModule, Menu, PanelLeft, Search, X } from 'lucide-angular';
|
||||||
|
import { filter, map } from 'rxjs';
|
||||||
import { SidebarComponent } from './sidebar/sidebar.component';
|
import { SidebarComponent } from './sidebar/sidebar.component';
|
||||||
import { SecondarySidebarComponent } from './shared/secondary-sidebar/secondary-sidebar.component';
|
import { SecondarySidebarComponent } from './shared/secondary-sidebar/secondary-sidebar.component';
|
||||||
import { GlobalSearchComponent } from './shared/global-search/global-search.component';
|
import { GlobalSearchComponent } from './shared/global-search/global-search.component';
|
||||||
import { UpdateBannerComponent } from './shared/update-banner/update-banner.component';
|
import { UpdateBannerComponent } from './shared/update-banner/update-banner.component';
|
||||||
import { ConfirmDialogHostComponent } from './shared/confirm-dialog/confirm-dialog-host.component';
|
import { ConfirmDialogHostComponent } from './shared/confirm-dialog/confirm-dialog-host.component';
|
||||||
import { WritingCoachPanelComponent } from './shared/writing-coach/writing-coach-panel.component';
|
import { WritingCoachPanelComponent } from './shared/writing-coach/writing-coach-panel.component';
|
||||||
|
import { ActiveSessionShortcutComponent } from './sessions/active-session-shortcut/active-session-shortcut.component';
|
||||||
import { LayoutService } from './services/layout.service';
|
import { LayoutService } from './services/layout.service';
|
||||||
import { GlobalSearchService } from './services/global-search.service';
|
import { GlobalSearchService } from './services/global-search.service';
|
||||||
import { VersionCheckerService } from './services/version-checker.service';
|
import { VersionCheckerService } from './services/version-checker.service';
|
||||||
|
|
||||||
|
/** Sous cette largeur, les deux sidebars deviennent des tiroirs off-canvas (tablette, téléphone). */
|
||||||
|
const COMPACT_QUERY = '(max-width: 1023.98px)';
|
||||||
|
|
||||||
|
/** Tiroir ouvert en mode compact : menu principal, arborescence secondaire, ou aucun. */
|
||||||
|
type ShellDrawer = 'main' | 'tree' | null;
|
||||||
|
|
||||||
|
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
imports: [
|
imports: [
|
||||||
RouterOutlet,
|
RouterOutlet,
|
||||||
|
LucideAngularModule,
|
||||||
|
TranslatePipe,
|
||||||
SidebarComponent,
|
SidebarComponent,
|
||||||
SecondarySidebarComponent,
|
SecondarySidebarComponent,
|
||||||
GlobalSearchComponent,
|
GlobalSearchComponent,
|
||||||
UpdateBannerComponent,
|
UpdateBannerComponent,
|
||||||
ConfirmDialogHostComponent,
|
ConfirmDialogHostComponent,
|
||||||
WritingCoachPanelComponent,
|
WritingCoachPanelComponent,
|
||||||
|
ActiveSessionShortcutComponent,
|
||||||
AsyncPipe
|
AsyncPipe
|
||||||
],
|
],
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
@@ -29,6 +46,29 @@ import { VersionCheckerService } from './services/version-checker.service';
|
|||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
readonly sidebarConfig$ = this.layoutService.secondarySidebar$;
|
readonly sidebarConfig$ = this.layoutService.secondarySidebar$;
|
||||||
|
|
||||||
|
readonly Menu = Menu;
|
||||||
|
readonly PanelLeft = PanelLeft;
|
||||||
|
readonly Search = Search;
|
||||||
|
readonly X = X;
|
||||||
|
|
||||||
|
private readonly breakpoints = inject(BreakpointObserver);
|
||||||
|
private readonly router = inject(Router);
|
||||||
|
|
||||||
|
/** True sous 1024 px : barre haute + tiroirs au lieu des colonnes fixes. */
|
||||||
|
readonly isCompact = toSignal(
|
||||||
|
this.breakpoints.observe(COMPACT_QUERY).pipe(map(state => state.matches)),
|
||||||
|
{ initialValue: this.breakpoints.isMatched(COMPACT_QUERY) }
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Tiroir ouvert (mode compact uniquement). */
|
||||||
|
readonly openDrawer = signal<ShellDrawer>(null);
|
||||||
|
|
||||||
|
private readonly mainDrawerRef = viewChild(SidebarComponent, { read: ElementRef });
|
||||||
|
private readonly treeDrawerRef = viewChild(SecondarySidebarComponent, { read: ElementRef });
|
||||||
|
private readonly mainToggleRef = viewChild<ElementRef<HTMLButtonElement>>('mainToggle');
|
||||||
|
private readonly treeToggleRef = viewChild<ElementRef<HTMLButtonElement>>('treeToggle');
|
||||||
|
private readonly mainContentRef = viewChild<ElementRef<HTMLElement>>('mainContent');
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private layoutService: LayoutService,
|
private layoutService: LayoutService,
|
||||||
private globalSearch: GlobalSearchService,
|
private globalSearch: GlobalSearchService,
|
||||||
@@ -38,6 +78,48 @@ export class AppComponent {
|
|||||||
// Si une nouvelle version est deployee pendant la session, l'UpdateBanner
|
// Si une nouvelle version est deployee pendant la session, l'UpdateBanner
|
||||||
// s'affichera automatiquement.
|
// s'affichera automatiquement.
|
||||||
versionChecker.start();
|
versionChecker.start();
|
||||||
|
|
||||||
|
// Retour en largeur desktop : les tiroirs n'ont plus de sens, on les referme.
|
||||||
|
effect(() => {
|
||||||
|
if (!this.isCompact()) this.openDrawer.set(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Une navigation (y compris vers l'URL courante, NavigationSkipped) referme le
|
||||||
|
// tiroir : on choisit une page, on veut la voir. Le focus part sur le contenu.
|
||||||
|
this.router.events.pipe(
|
||||||
|
filter(e => e instanceof NavigationEnd || e instanceof NavigationSkipped),
|
||||||
|
takeUntilDestroyed(),
|
||||||
|
).subscribe(() => {
|
||||||
|
if (!this.openDrawer()) return;
|
||||||
|
this.openDrawer.set(null);
|
||||||
|
this.mainContentRef()?.nativeElement.focus({ preventScroll: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
// La recherche globale passe au-dessus : inutile de laisser le tiroir ouvert dessous.
|
||||||
|
this.globalSearch.open$.pipe(filter(Boolean), takeUntilDestroyed()).subscribe(() => this.openDrawer.set(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleDrawer(drawer: Exclude<ShellDrawer, null>): void {
|
||||||
|
if (this.openDrawer() === drawer) {
|
||||||
|
this.closeDrawer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.openDrawer.set(drawer);
|
||||||
|
// Focus sur le premier élément du tiroir une fois rendu visible.
|
||||||
|
setTimeout(() => this.focusables(this.drawerElement())[0]?.focus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ferme le tiroir et rend le focus au bouton de la barre haute qui l'a ouvert. */
|
||||||
|
closeDrawer(): void {
|
||||||
|
const drawer = this.openDrawer();
|
||||||
|
if (!drawer) return;
|
||||||
|
this.openDrawer.set(null);
|
||||||
|
const toggle = drawer === 'main' ? this.mainToggleRef() : this.treeToggleRef();
|
||||||
|
toggle?.nativeElement.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
openSearch(): void {
|
||||||
|
this.globalSearch.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('document:keydown', ['$event'])
|
@HostListener('document:keydown', ['$event'])
|
||||||
@@ -46,6 +128,45 @@ export class AppComponent {
|
|||||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'k') {
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'k') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.globalSearch.toggle();
|
this.globalSearch.toggle();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.openDrawer()) return;
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
event.preventDefault();
|
||||||
|
this.closeDrawer();
|
||||||
|
} else if (event.key === 'Tab') {
|
||||||
|
this.trapFocus(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Garde le focus clavier dans le tiroir ouvert (comportement de modale). */
|
||||||
|
private trapFocus(event: KeyboardEvent): void {
|
||||||
|
const drawer = this.drawerElement();
|
||||||
|
const items = this.focusables(drawer);
|
||||||
|
if (!drawer || !items.length) return;
|
||||||
|
const first = items[0];
|
||||||
|
const last = items[items.length - 1];
|
||||||
|
const active = document.activeElement as HTMLElement | null;
|
||||||
|
const inside = !!active && drawer.contains(active);
|
||||||
|
if (event.shiftKey && (active === first || !inside)) {
|
||||||
|
event.preventDefault();
|
||||||
|
last.focus();
|
||||||
|
} else if (!event.shiftKey && (active === last || !inside)) {
|
||||||
|
event.preventDefault();
|
||||||
|
first.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private drawerElement(): HTMLElement | null {
|
||||||
|
const drawer = this.openDrawer();
|
||||||
|
if (drawer === 'main') return this.mainDrawerRef()?.nativeElement ?? null;
|
||||||
|
if (drawer === 'tree') return this.treeDrawerRef()?.nativeElement ?? null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private focusables(root: HTMLElement | null): HTMLElement[] {
|
||||||
|
if (!root) return [];
|
||||||
|
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE))
|
||||||
|
.filter(el => el.offsetParent !== null || el.getClientRects().length > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ export const routes: Routes = [
|
|||||||
{ 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) },
|
||||||
// Routes masquees en mode demo : ajouter canActivate: [hiddenInDemoGuard]
|
// Routes masquees en mode demo : ajouter canActivate: [hiddenInDemoGuard]
|
||||||
// (a prevoir aussi sur la future route d'export VTT).
|
// (a prevoir aussi sur la future route d'export VTT).
|
||||||
|
// Accès distant (mode bureau) : appairage d'une tablette par code.
|
||||||
|
{ path: 'pair', loadComponent: () => import('./remote-access/remote-pair/remote-pair.component').then(m => m.RemotePairComponent) },
|
||||||
{ path: 'settings', canActivate: [hiddenInDemoGuard], loadComponent: () => import('./settings/settings.component').then(m => m.SettingsComponent) },
|
{ path: 'settings', canActivate: [hiddenInDemoGuard], loadComponent: () => import('./settings/settings.component').then(m => m.SettingsComponent) },
|
||||||
{ path: '', redirectTo: '/lore', pathMatch: 'full' }
|
{ path: '', redirectTo: '/lore', pathMatch: 'full' }
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -23,6 +23,29 @@ describe('buildCampaignTree', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('place un nœud « Parties » en tête (avant la narration), une entrée par partie', () => {
|
||||||
|
const tree = buildCampaignTree('c1', data({
|
||||||
|
arcs: [{ id: 'a1', name: 'Arc', type: 'LINEAR' }] as never,
|
||||||
|
chaptersByArc: { a1: [{ id: 'ch1', name: 'C1' }, { id: 'ch2', name: 'C2' }] } as never,
|
||||||
|
playthroughs: [
|
||||||
|
{ id: 'p1', campaignId: 'c1', name: 'Table du mardi' },
|
||||||
|
{ id: 'p2', campaignId: 'c1', name: 'Table du jeudi' },
|
||||||
|
],
|
||||||
|
}), t);
|
||||||
|
expect(tree[0].id).toBe('playthroughs-root');
|
||||||
|
expect(tree[0].sectionHeaderBefore).toBe('campaignTree.sectionPlay');
|
||||||
|
expect(tree[0].meta).toBe('2');
|
||||||
|
expect(tree[0].children!.map((c) => c.route)).toEqual([
|
||||||
|
'/campaigns/c1/playthroughs/p1', '/campaigns/c1/playthroughs/p2',
|
||||||
|
]);
|
||||||
|
expect(tree[1].id).toBe('arc-a1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pas de nœud « Parties » sans partie', () => {
|
||||||
|
const tree = buildCampaignTree('c1', data({ playthroughs: [] }), t);
|
||||||
|
expect(tree.some((n) => n.id === 'playthroughs-root')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('trie les arcs par ordre manuel (champ order, réagencé au glisser-déposer)', () => {
|
it('trie les arcs par ordre manuel (champ order, réagencé au glisser-déposer)', () => {
|
||||||
const arcs = [
|
const arcs = [
|
||||||
{ id: 'a', name: 'Final', order: 2 },
|
{ id: 'a', name: 'Final', order: 2 },
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { RandomTableService } from '../services/random-table.service';
|
|||||||
import { EnemyService } from '../services/enemy.service';
|
import { EnemyService } from '../services/enemy.service';
|
||||||
import { TreeItem, TreeCreateAction, SecondarySidebarConfig, GlobalItem, ReorderKind } from '../services/layout.service';
|
import { TreeItem, TreeCreateAction, SecondarySidebarConfig, GlobalItem, ReorderKind } from '../services/layout.service';
|
||||||
import { groupByFolder, byOrder } from '../shared/folder-grouping.util';
|
import { groupByFolder, byOrder } from '../shared/folder-grouping.util';
|
||||||
import { Arc, Chapter, Scene, Campaign, Quest } from '../services/campaign.model';
|
import { Arc, Chapter, Scene, Campaign, Quest, Playthrough } from '../services/campaign.model';
|
||||||
import { Npc } from '../services/npc.model';
|
import { Npc } from '../services/npc.model';
|
||||||
import { RandomTable } from '../services/random-table.model';
|
import { RandomTable } from '../services/random-table.model';
|
||||||
import { Enemy } from '../services/enemy.model';
|
import { Enemy } from '../services/enemy.model';
|
||||||
@@ -34,6 +34,8 @@ export interface CampaignTreeData {
|
|||||||
quests?: Quest[];
|
quests?: Quest[];
|
||||||
/** Bilan de readiness complet — évite un fetch séparé pour le panneau du hub. */
|
/** Bilan de readiness complet — évite un fetch séparé pour le panneau du hub. */
|
||||||
readiness?: CampaignReadinessAssessment | null;
|
readiness?: CampaignReadinessAssessment | null;
|
||||||
|
/** Parties (Playthroughs) — nœud « Parties » en tête d'arbre (accès direct aux séances). Optionnel. */
|
||||||
|
playthroughs?: Playthrough[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadCampaignTreeData(
|
export function loadCampaignTreeData(
|
||||||
@@ -56,13 +58,14 @@ export function loadCampaignTreeData(
|
|||||||
randomTables: tree.randomTables ?? [],
|
randomTables: tree.randomTables ?? [],
|
||||||
enemies: tree.enemies ?? [],
|
enemies: tree.enemies ?? [],
|
||||||
quests: tree.quests ?? [],
|
quests: tree.quests ?? [],
|
||||||
|
playthroughs: tree.playthroughs ?? [],
|
||||||
gaps: tree.readiness?.gaps ?? [],
|
gaps: tree.readiness?.gaps ?? [],
|
||||||
readiness: tree.readiness ?? null
|
readiness: tree.readiness ?? null
|
||||||
} as CampaignTreeData)),
|
} as CampaignTreeData)),
|
||||||
// Dégradation gracieuse : sidebar vide plutôt qu'écran cassé si le back est indisponible.
|
// Dégradation gracieuse : sidebar vide plutôt qu'écran cassé si le back est indisponible.
|
||||||
catchError(() => of({
|
catchError(() => of({
|
||||||
arcs: [], chaptersByArc: {}, scenesByChapter: {},
|
arcs: [], chaptersByArc: {}, scenesByChapter: {},
|
||||||
npcs: [], randomTables: [], enemies: [], quests: [], gaps: [], readiness: null
|
npcs: [], randomTables: [], enemies: [], quests: [], playthroughs: [], gaps: [], readiness: null
|
||||||
} as CampaignTreeData))
|
} as CampaignTreeData))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -459,7 +462,31 @@ export function buildCampaignTree(
|
|||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
return [...narrationNodes, questsNode, npcsNode, enemiesNode, tablesNode, notebooksNode, catalogsNode, importNode];
|
// Parties (Playthroughs) : EN TÊTE d'arbre, avant la narration — c'est par une Partie
|
||||||
|
// qu'on lance/reprend une séance ; enfouies en bas du hub, on finissait par les manquer.
|
||||||
|
const playthroughItems: TreeItem[] = (data.playthroughs ?? [])
|
||||||
|
.filter(p => !!p.id)
|
||||||
|
.map(p => ({
|
||||||
|
id: `playthrough-${p.id}`,
|
||||||
|
label: p.name,
|
||||||
|
iconKey: 'c-dice',
|
||||||
|
route: `/campaigns/${campaignId}/playthroughs/${p.id}`
|
||||||
|
}));
|
||||||
|
const playthroughsNode: TreeItem | null = playthroughItems.length ? {
|
||||||
|
id: 'playthroughs-root',
|
||||||
|
label: translate.instant('campaignTree.playthroughs'),
|
||||||
|
iconKey: 'c-dice',
|
||||||
|
children: playthroughItems,
|
||||||
|
meta: String(playthroughItems.length),
|
||||||
|
// Libellé → hub (bloc « Jouer » + liste des Parties) ; chevron → une Partie par nœud.
|
||||||
|
route: `/campaigns/${campaignId}`,
|
||||||
|
sectionHeaderBefore: translate.instant('campaignTree.sectionPlay')
|
||||||
|
} : null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
...(playthroughsNode ? [playthroughsNode] : []),
|
||||||
|
...narrationNodes, questsNode, npcsNode, enemiesNode, tablesNode, notebooksNode, catalogsNode, importNode
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,6 +59,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
<!-- ============ Jouer : reprendre / démarrer une séance (accès direct) ============ -->
|
||||||
|
@if (!editing && campaign.id) {
|
||||||
|
<app-campaign-play-block
|
||||||
|
[playthroughs]="playthroughs"
|
||||||
|
[creatingPlaythrough]="newPlaythroughInFlight"
|
||||||
|
(createPlaythrough)="createPlaythrough()">
|
||||||
|
</app-campaign-play-block>
|
||||||
|
}
|
||||||
<!-- ============ Guidage co-MJ : « Prochaines étapes » (Pilier B) ============ -->
|
<!-- ============ Guidage co-MJ : « Prochaines étapes » (Pilier B) ============ -->
|
||||||
@if (!editing && campaign.id) {
|
@if (!editing && campaign.id) {
|
||||||
<app-readiness-panel [campaignId]="campaign.id" [assessment]="readiness"></app-readiness-panel>
|
<app-readiness-panel [campaignId]="campaign.id" [assessment]="readiness"></app-readiness-panel>
|
||||||
|
|||||||
@@ -173,16 +173,28 @@
|
|||||||
border-bottom: 1px solid #1f2937;
|
border-bottom: 1px solid #1f2937;
|
||||||
margin-bottom: 1.5rem;
|
margin-bottom: 1.5rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 1.5rem;
|
gap: 1rem 1.5rem;
|
||||||
|
|
||||||
.header-texts { flex: 1; min-width: 0; }
|
// Le bloc titre réclame ~280 px ; s'il ne les a pas à côté des actions
|
||||||
|
// (tablette, desktop étroit), les actions passent dessous et s'y répartissent.
|
||||||
|
.header-texts { flex: 1 1 280px; min-width: 0; }
|
||||||
|
|
||||||
.header-actions {
|
.header-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
flex-shrink: 0;
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Téléphone : l'en-tête (titre + 5 actions) mangerait la moitié de l'écran
|
||||||
|
// s'il restait collé en haut pendant le défilement.
|
||||||
|
@media (max-width: 767.98px) {
|
||||||
|
position: static;
|
||||||
|
|
||||||
|
h1 { overflow-wrap: anywhere; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variante mode édition : champs empilés verticalement.
|
// Variante mode édition : champs empilés verticalement.
|
||||||
@@ -295,8 +307,10 @@
|
|||||||
|
|
||||||
.section-header {
|
.section-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap; // écran étroit : les actions passent sous le titre au lieu de déborder
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
margin-bottom: 1.5rem;
|
margin-bottom: 1.5rem;
|
||||||
|
|
||||||
h2 { color: #d1d5db; font-size: 1rem; font-weight: 600; }
|
h2 { color: #d1d5db; font-size: 1rem; font-weight: 600; }
|
||||||
@@ -304,6 +318,7 @@
|
|||||||
|
|
||||||
.section-header-actions {
|
.section-header-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,11 +33,12 @@ import { FolderGroup, groupByFolder, byOrder } from '../../../shared/folder-grou
|
|||||||
import { CampaignReadinessAssessment } from '../../../services/readiness.model';
|
import { CampaignReadinessAssessment } from '../../../services/readiness.model';
|
||||||
import { ReadinessPanelComponent } from '../../../shared/readiness-panel/readiness-panel.component';
|
import { ReadinessPanelComponent } from '../../../shared/readiness-panel/readiness-panel.component';
|
||||||
import { WritingReviewPanelComponent } from '../../../shared/writing-review/writing-review-panel.component';
|
import { WritingReviewPanelComponent } from '../../../shared/writing-review/writing-review-panel.component';
|
||||||
|
import { CampaignPlayBlockComponent } from '../campaign-play-block/campaign-play-block.component';
|
||||||
import { FoundryExportDialogComponent } from '../foundry-export-dialog/foundry-export-dialog.component';
|
import { FoundryExportDialogComponent } from '../foundry-export-dialog/foundry-export-dialog.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-campaign-detail',
|
selector: 'app-campaign-detail',
|
||||||
imports: [FormsModule, LucideAngularModule, RouterLink, TranslatePipe, CdkDropList, CdkDrag, ReadinessPanelComponent, WritingReviewPanelComponent, FoundryExportDialogComponent],
|
imports: [FormsModule, LucideAngularModule, RouterLink, TranslatePipe, CdkDropList, CdkDrag, ReadinessPanelComponent, WritingReviewPanelComponent, CampaignPlayBlockComponent, FoundryExportDialogComponent],
|
||||||
templateUrl: './campaign-detail.component.html',
|
templateUrl: './campaign-detail.component.html',
|
||||||
styleUrls: ['./campaign-detail.component.scss']
|
styleUrls: ['./campaign-detail.component.scss']
|
||||||
})
|
})
|
||||||
@@ -95,14 +96,6 @@ export class CampaignDetailComponent implements OnInit, OnDestroy {
|
|||||||
editPlaythroughName = '';
|
editPlaythroughName = '';
|
||||||
/** Sessions de jeu (passées et en cours) liées à cette campagne. */
|
/** Sessions de jeu (passées et en cours) liées à cette campagne. */
|
||||||
sessions: Session[] = [];
|
sessions: Session[] = [];
|
||||||
/**
|
|
||||||
* Session active globale (toutes campagnes confondues).
|
|
||||||
* Sert à désactiver le bouton "Lancer" si une session tourne déjà ailleurs.
|
|
||||||
* Null si aucune session active dans l'app.
|
|
||||||
*/
|
|
||||||
activeSessionGlobal: Session | null = null;
|
|
||||||
/** Indicateur de lancement en cours pour éviter les double-clics. */
|
|
||||||
startingSession = false;
|
|
||||||
|
|
||||||
/** Parties (Playthroughs) de cette campagne. */
|
/** Parties (Playthroughs) de cette campagne. */
|
||||||
playthroughs: Playthrough[] = [];
|
playthroughs: Playthrough[] = [];
|
||||||
@@ -215,6 +208,18 @@ export class CampaignDetailComponent implements OnInit, OnDestroy {
|
|||||||
this.chapterCountByArc = this.computeChapterCounts(treeData);
|
this.chapterCountByArc = this.computeChapterCounts(treeData);
|
||||||
this.showLayout(allCampaigns, treeData);
|
this.showLayout(allCampaigns, treeData);
|
||||||
this.pageTitleService.set(campaign.name);
|
this.pageTitleService.set(campaign.name);
|
||||||
|
this.openEditFromQueryParam();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `?edit=system` (lien « Choisir le système » de l'onglet Règles en séance) : ouvre
|
||||||
|
* directement l'édition inline, puis retire le paramètre pour qu'un rechargement
|
||||||
|
* ne la rouvre pas.
|
||||||
|
*/
|
||||||
|
private openEditFromQueryParam(): void {
|
||||||
|
if (!this.route.snapshot.queryParamMap.has('edit')) return;
|
||||||
|
this.startEdit();
|
||||||
|
this.router.navigate([], { relativeTo: this.route, queryParams: { edit: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<section class="play-block" [class.play-block--live]="target.kind === 'resume'" [attr.aria-label]="'playAccess.block.title' | translate">
|
||||||
|
<div class="play-head">
|
||||||
|
<lucide-icon [img]="Play" [size]="16" class="play-head-icon"></lucide-icon>
|
||||||
|
<h2 class="play-title">{{ 'playAccess.block.title' | translate }}</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (target.kind === 'resume') {
|
||||||
|
<ul class="play-rows">
|
||||||
|
@for (r of target.sessions; track r.session.id) {
|
||||||
|
<li class="play-row">
|
||||||
|
<span class="live-dot" aria-hidden="true"></span>
|
||||||
|
<div class="play-row-texts">
|
||||||
|
<span class="play-row-label">{{ 'playAccess.block.running' | translate }}</span>
|
||||||
|
<span class="play-row-sub">{{ r.session.name }} · {{ r.playthrough.name }}</span>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn-primary play-btn" (click)="resume(r.session)">
|
||||||
|
<lucide-icon [img]="Play" [size]="15"></lucide-icon>
|
||||||
|
{{ 'playAccess.block.resume' | translate }}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
} @else if (target.kind === 'start') {
|
||||||
|
<div class="play-row">
|
||||||
|
<div class="play-row-texts">
|
||||||
|
@if (target.playthroughs.length > 1) {
|
||||||
|
<label class="play-row-label" for="play-block-playthrough">{{ 'playAccess.block.playthroughLabel' | translate }}</label>
|
||||||
|
<select id="play-block-playthrough" class="play-select" [(ngModel)]="selectedPlaythroughId">
|
||||||
|
@for (p of target.playthroughs; track p.id) {
|
||||||
|
<option [value]="p.id">{{ p.name }}</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
} @else {
|
||||||
|
<span class="play-row-label">{{ 'playAccess.block.nextSession' | translate }}</span>
|
||||||
|
<span class="play-row-sub">{{ target.playthroughs[0].name }}</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn-primary play-btn" [disabled]="starting" (click)="start()">
|
||||||
|
<lucide-icon [img]="Play" [size]="15"></lucide-icon>
|
||||||
|
{{ (starting ? 'playAccess.block.starting' : 'playAccess.block.start') | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<div class="play-row">
|
||||||
|
<div class="play-row-texts">
|
||||||
|
<span class="play-row-sub">{{ 'playAccess.block.noPlaythrough' | translate }}</span>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn-primary play-btn" [disabled]="creatingPlaythrough" (click)="createPlaythrough.emit()">
|
||||||
|
<lucide-icon [img]="Plus" [size]="15"></lucide-icon>
|
||||||
|
{{ 'playAccess.block.createPlaythrough' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</section>
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
:host { display: block; }
|
||||||
|
|
||||||
|
.play-block {
|
||||||
|
margin: 0 0 1.25rem;
|
||||||
|
padding: 0.8rem 0.9rem;
|
||||||
|
background: #0d1117;
|
||||||
|
border: 1px solid #2d2a5a;
|
||||||
|
border-radius: 10px;
|
||||||
|
|
||||||
|
&--live { border-color: rgba(16, 185, 129, 0.55); background: rgba(16, 185, 129, 0.05); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
margin-bottom: 0.55rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-head-icon { color: #a5a0ff; }
|
||||||
|
.play-block--live .play-head-icon { color: #34d399; }
|
||||||
|
|
||||||
|
.play-title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.92rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-rows {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-row-texts {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.2rem;
|
||||||
|
flex: 1 1 12rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-row-label {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #9ca3af;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-row-sub {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #e5e7eb;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-select {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 22rem;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0.45rem 0.6rem;
|
||||||
|
background: #111827;
|
||||||
|
color: #e5e7eb;
|
||||||
|
border: 1px solid #374151;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0.55rem 1.1rem;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-block--live .play-btn {
|
||||||
|
background: #059669;
|
||||||
|
&:hover:not(:disabled) { background: #047857; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.live-dot {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 9px;
|
||||||
|
height: 9px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #10b981;
|
||||||
|
animation: live-pulse 2s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes live-pulse {
|
||||||
|
0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
|
||||||
|
70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
|
||||||
|
100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.live-dot { animation: none; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Téléphone : bouton pleine largeur sous le texte.
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.play-btn { flex: 1 1 100%; }
|
||||||
|
.play-select { max-width: none; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import { Component, DestroyRef, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
|
||||||
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
|
import { LucideAngularModule, Play, Plus } from 'lucide-angular';
|
||||||
|
import { ActiveSessionsService } from '../../../services/active-sessions.service';
|
||||||
|
import { SessionService } from '../../../services/session.service';
|
||||||
|
import { Playthrough } from '../../../services/campaign.model';
|
||||||
|
import { Session } from '../../../services/session.model';
|
||||||
|
import { PlayTarget, computePlayTarget } from './play-target.util';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bloc « Jouer » en tête du hub campagne : reprendre la séance en cours, ou en démarrer
|
||||||
|
* une sur la Partie la plus récente (ou en créer une s'il n'y en a aucune). La liste
|
||||||
|
* complète des Parties reste en bas du hub ; ce bloc n'est qu'un accès direct.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'app-campaign-play-block',
|
||||||
|
imports: [FormsModule, LucideAngularModule, TranslatePipe],
|
||||||
|
templateUrl: './campaign-play-block.component.html',
|
||||||
|
styleUrls: ['./campaign-play-block.component.scss']
|
||||||
|
})
|
||||||
|
export class CampaignPlayBlockComponent implements OnInit, OnChanges {
|
||||||
|
readonly Play = Play;
|
||||||
|
readonly Plus = Plus;
|
||||||
|
|
||||||
|
@Input() playthroughs: Playthrough[] = [];
|
||||||
|
/** Création de Partie déléguée au hub (même nom par défaut, même navigation). */
|
||||||
|
@Input() creatingPlaythrough = false;
|
||||||
|
@Output() createPlaythrough = new EventEmitter<void>();
|
||||||
|
|
||||||
|
target: PlayTarget = { kind: 'create' };
|
||||||
|
selectedPlaythroughId = '';
|
||||||
|
starting = false;
|
||||||
|
|
||||||
|
private activeSessions: Session[] = [];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private activeSessionsService: ActiveSessionsService,
|
||||||
|
private sessionService: SessionService,
|
||||||
|
private router: Router,
|
||||||
|
private destroyRef: DestroyRef
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.activeSessionsService.active$.pipe(takeUntilDestroyed(this.destroyRef))
|
||||||
|
.subscribe(list => {
|
||||||
|
this.activeSessions = list.map(e => e.session);
|
||||||
|
this.recompute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges(): void {
|
||||||
|
this.recompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private recompute(): void {
|
||||||
|
this.target = computePlayTarget(this.playthroughs, this.activeSessions);
|
||||||
|
if (this.target.kind === 'start') {
|
||||||
|
const ids = this.target.playthroughs.map(p => p.id);
|
||||||
|
if (!ids.includes(this.selectedPlaythroughId)) {
|
||||||
|
this.selectedPlaythroughId = this.target.defaultPlaythroughId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resume(session: Session): void {
|
||||||
|
this.router.navigate(['/sessions', session.id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
start(): void {
|
||||||
|
if (this.starting || !this.selectedPlaythroughId) return;
|
||||||
|
this.starting = true;
|
||||||
|
this.sessionService.startSession(this.selectedPlaythroughId).subscribe({
|
||||||
|
next: s => { this.starting = false; this.router.navigate(['/sessions', s.id]); },
|
||||||
|
error: () => { this.starting = false; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { computePlayTarget, sortPlaythroughsRecentFirst } from './play-target.util';
|
||||||
|
import { Playthrough } from '../../../services/campaign.model';
|
||||||
|
import { Session } from '../../../services/session.model';
|
||||||
|
|
||||||
|
const pt = (id: string, createdAt?: string): Playthrough => ({ id, campaignId: 'c1', name: `P${id}`, createdAt });
|
||||||
|
const session = (id: string, playthroughId: string, startedAt: string, active = true): Session => ({
|
||||||
|
id, name: `S${id}`, playthroughId, startedAt, endedAt: active ? null : startedAt,
|
||||||
|
createdAt: startedAt, updatedAt: startedAt, active
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('sortPlaythroughsRecentFirst', () => {
|
||||||
|
it('trie par date de création décroissante', () => {
|
||||||
|
const r = sortPlaythroughsRecentFirst([pt('1', '2026-01-01'), pt('2', '2026-03-01'), pt('3', '2026-02-01')]);
|
||||||
|
expect(r.map(p => p.id)).toEqual(['2', '3', '1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sans dates : la dernière de la liste est la plus récente', () => {
|
||||||
|
expect(sortPlaythroughsRecentFirst([pt('1'), pt('2')]).map(p => p.id)).toEqual(['2', '1']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('computePlayTarget', () => {
|
||||||
|
it('aucune partie → create', () => {
|
||||||
|
expect(computePlayTarget([], [])).toEqual({ kind: 'create' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pas de séance en cours → start sur la partie la plus récente', () => {
|
||||||
|
const t = computePlayTarget([pt('1', '2026-01-01'), pt('2', '2026-05-01')], []);
|
||||||
|
expect(t.kind).toBe('start');
|
||||||
|
if (t.kind === 'start') {
|
||||||
|
expect(t.defaultPlaythroughId).toBe('2');
|
||||||
|
expect(t.playthroughs.map(p => p.id)).toEqual(['2', '1']);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignore les séances des autres campagnes et les séances terminées', () => {
|
||||||
|
const t = computePlayTarget([pt('1')], [session('a', 'other', '2026-01-01'), session('b', '1', '2026-01-01', false)]);
|
||||||
|
expect(t.kind).toBe('start');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('séance(s) en cours sur la campagne → resume, la plus récente d\'abord', () => {
|
||||||
|
const t = computePlayTarget([pt('1'), pt('2')], [
|
||||||
|
session('a', '1', '2026-01-01T10:00:00'),
|
||||||
|
session('b', '2', '2026-01-02T10:00:00'),
|
||||||
|
session('c', 'other', '2026-01-03T10:00:00')
|
||||||
|
]);
|
||||||
|
expect(t.kind).toBe('resume');
|
||||||
|
if (t.kind === 'resume') {
|
||||||
|
expect(t.sessions.map(s => s.session.id)).toEqual(['b', 'a']);
|
||||||
|
expect(t.sessions[0].playthrough.id).toBe('2');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { Playthrough } from '../../../services/campaign.model';
|
||||||
|
import { Session } from '../../../services/session.model';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ce que propose le bloc « Jouer » du hub campagne :
|
||||||
|
* - resume : une (ou plusieurs) séance(s) tourne(nt) sur une Partie de la campagne ;
|
||||||
|
* - start : aucune séance en cours → démarrer sur une Partie (la plus récente par défaut) ;
|
||||||
|
* - create : aucune Partie → en créer une d'abord.
|
||||||
|
*/
|
||||||
|
export type PlayTarget =
|
||||||
|
| { kind: 'resume'; sessions: { session: Session; playthrough: Playthrough }[] }
|
||||||
|
| { kind: 'start'; playthroughs: Playthrough[]; defaultPlaythroughId: string }
|
||||||
|
| { kind: 'create' };
|
||||||
|
|
||||||
|
const timeOf = (p: Playthrough): number => {
|
||||||
|
const t = Date.parse(p.createdAt ?? p.updatedAt ?? '');
|
||||||
|
return Number.isNaN(t) ? 0 : t;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Parties de la plus récente à la plus ancienne (création ; à défaut, ordre d'origine). */
|
||||||
|
export function sortPlaythroughsRecentFirst(playthroughs: Playthrough[]): Playthrough[] {
|
||||||
|
return playthroughs
|
||||||
|
.map((p, i) => ({ p, i }))
|
||||||
|
.sort((a, b) => (timeOf(b.p) - timeOf(a.p)) || (b.i - a.i))
|
||||||
|
.map(x => x.p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Décide du bloc « Jouer » à partir des Parties de la campagne et des séances en cours
|
||||||
|
* de TOUTE l'appli (filtrées ici sur les Parties de la campagne, plus récente d'abord).
|
||||||
|
*/
|
||||||
|
export function computePlayTarget(playthroughs: Playthrough[], activeSessions: Session[]): PlayTarget {
|
||||||
|
const withId = playthroughs.filter((p): p is Playthrough & { id: string } => !!p.id);
|
||||||
|
if (withId.length === 0) return { kind: 'create' };
|
||||||
|
|
||||||
|
const byId = new Map(withId.map(p => [p.id, p]));
|
||||||
|
const running = activeSessions
|
||||||
|
.filter(s => s.active && byId.has(s.playthroughId))
|
||||||
|
.sort((a, b) => Date.parse(b.startedAt) - Date.parse(a.startedAt))
|
||||||
|
.map(session => ({ session, playthrough: byId.get(session.playthroughId)! }));
|
||||||
|
if (running.length > 0) return { kind: 'resume', sessions: running };
|
||||||
|
|
||||||
|
const sorted = sortPlaythroughsRecentFirst(withId);
|
||||||
|
return { kind: 'start', playthroughs: sorted, defaultPlaythroughId: sorted[0].id! };
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 3rem;
|
margin-bottom: 3rem;
|
||||||
|
|
||||||
|
@media (max-width: 767.98px) { margin-bottom: 1.5rem; }
|
||||||
|
|
||||||
.hero-icon { display: block; margin-bottom: 1rem; color: #6c63ff; }
|
.hero-icon { display: block; margin-bottom: 1rem; color: #6c63ff; }
|
||||||
|
|
||||||
h1 { font-size: 2rem; font-weight: 700; color: white; margin-bottom: 0.5rem; }
|
h1 { font-size: 2rem; font-weight: 700; color: white; margin-bottom: 0.5rem; }
|
||||||
@@ -19,7 +21,9 @@
|
|||||||
|
|
||||||
.campaigns-grid {
|
.campaigns-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
// 3 colonnes sur desktop (max-width 900px), moins dès que la carte passerait
|
||||||
|
// sous 240 px : 2 sur tablette portrait, 1 sur téléphone.
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
|
||||||
gap: 1.5rem;
|
gap: 1.5rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 900px;
|
max-width: 900px;
|
||||||
|
|||||||
@@ -308,3 +308,10 @@
|
|||||||
color: #9ca3af;
|
color: #9ca3af;
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Écrans sans survol (tactile) : poignées de liaison et de renommage visibles
|
||||||
|
// en permanence (elles n'apparaissaient qu'au survol du nœud).
|
||||||
|
@media (hover: none) {
|
||||||
|
.node .node-connect { opacity: 0.9; }
|
||||||
|
.node .node-rename { opacity: 1; }
|
||||||
|
}
|
||||||
|
|||||||
+8
-1
@@ -12,7 +12,14 @@
|
|||||||
h1 { margin: 0 0 0.2rem; font-size: 1.6rem; }
|
h1 { margin: 0 0 0.2rem; font-size: 1.6rem; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-info { flex: 1; }
|
.header-info { flex: 1; min-width: 0; }
|
||||||
|
|
||||||
|
// Téléphone : Retour et Supprimer sur la 1re ligne, titre + description en
|
||||||
|
// pleine largeur dessous (sinon le titre tombe à un mot par ligne).
|
||||||
|
@media (max-width: 767.98px) {
|
||||||
|
.page-header .header-actions { margin-left: auto; flex: 0 0 auto; }
|
||||||
|
.header-info { order: 1; flex-basis: 100%; }
|
||||||
|
}
|
||||||
|
|
||||||
.subtitle {
|
.subtitle {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { HttpErrorResponse, HttpInterceptorFn } from '@angular/common/http';
|
||||||
|
import { inject } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { catchError, throwError } from 'rxjs';
|
||||||
|
import { REMOTE_PAIRING_REQUIRED } from '../services/remote-access.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accès distant (tablette sur le réseau local) : quand le Core répond
|
||||||
|
* `401 remote_pairing_required`, l'appareil n'est pas (ou plus) appairé — on bascule
|
||||||
|
* sur l'écran d'appairage en retenant la page demandée. Inerte sur le PC et en Docker,
|
||||||
|
* où ce code d'erreur n'existe pas.
|
||||||
|
*/
|
||||||
|
export const remotePairingInterceptor: HttpInterceptorFn = (req, next) => {
|
||||||
|
const router = inject(Router);
|
||||||
|
return next(req).pipe(
|
||||||
|
catchError((err) => {
|
||||||
|
if (err instanceof HttpErrorResponse && err.status === 401 && err.error?.error === REMOTE_PAIRING_REQUIRED
|
||||||
|
&& !router.url.startsWith('/pair')) {
|
||||||
|
router.navigate(['/pair'], { queryParams: { returnUrl: router.url } });
|
||||||
|
}
|
||||||
|
return throwError(() => err);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -287,3 +287,8 @@
|
|||||||
}
|
}
|
||||||
.canvas { width: 100%; }
|
.canvas { width: 100%; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Écrans sans survol (tactile) : poignée de redimensionnement pleinement visible.
|
||||||
|
@media (hover: none) {
|
||||||
|
.rh-se::after { opacity: 1; }
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,11 +46,16 @@
|
|||||||
padding: 1rem 0;
|
padding: 1rem 0;
|
||||||
border-bottom: 1px solid #1f2937;
|
border-bottom: 1px solid #1f2937;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 1.5rem;
|
gap: 1rem 1.5rem;
|
||||||
|
|
||||||
.header-texts { flex: 1; min-width: 0; }
|
// Téléphone : titre + actions empilés prendraient trop de hauteur en sticky.
|
||||||
|
@media (max-width: 767.98px) { position: static; }
|
||||||
|
|
||||||
|
// ~280 px réservés au titre : sinon les actions passent dessous.
|
||||||
|
.header-texts { flex: 1 1 280px; min-width: 0; }
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
@@ -60,6 +65,7 @@
|
|||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: white;
|
color: white;
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
|
||||||
.title-icon { color: #6c63ff; }
|
.title-icon { color: #6c63ff; }
|
||||||
}
|
}
|
||||||
@@ -71,8 +77,9 @@
|
|||||||
|
|
||||||
.header-actions {
|
.header-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
flex-shrink: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,18 +24,24 @@
|
|||||||
padding: 1rem 0;
|
padding: 1rem 0;
|
||||||
border-bottom: 1px solid #1f2937;
|
border-bottom: 1px solid #1f2937;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 1.5rem;
|
gap: 1rem 1.5rem;
|
||||||
|
|
||||||
|
// Téléphone : titre + actions empilés prendraient trop de hauteur en sticky.
|
||||||
|
@media (max-width: 767.98px) { position: static; }
|
||||||
margin-bottom: 1.5rem;
|
margin-bottom: 1.5rem;
|
||||||
|
|
||||||
.header-texts { flex: 1; min-width: 0; }
|
// ~280 px réservés au titre : sinon les actions passent dessous.
|
||||||
|
.header-texts { flex: 1 1 280px; min-width: 0; }
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 1.75rem;
|
font-size: 1.75rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: white;
|
color: white;
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
|
|
||||||
.description {
|
.description {
|
||||||
@@ -46,8 +52,9 @@
|
|||||||
|
|
||||||
.header-actions {
|
.header-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
flex-shrink: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variante mode édition : input / textarea en colonne.
|
// Variante mode édition : input / textarea en colonne.
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 3rem;
|
margin-bottom: 3rem;
|
||||||
|
|
||||||
|
@media (max-width: 767.98px) { margin-bottom: 1.5rem; }
|
||||||
|
|
||||||
.hero-icon { display: block; margin-bottom: 1rem; color: #6c63ff; }
|
.hero-icon { display: block; margin-bottom: 1rem; color: #6c63ff; }
|
||||||
|
|
||||||
h1 { font-size: 2rem; font-weight: 700; color: white; margin-bottom: 0.5rem; }
|
h1 { font-size: 2rem; font-weight: 700; color: white; margin-bottom: 0.5rem; }
|
||||||
@@ -19,7 +21,9 @@
|
|||||||
|
|
||||||
.lore-grid {
|
.lore-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
// 3 colonnes sur desktop (max-width 900px), moins dès que la carte passerait
|
||||||
|
// sous 240 px : 2 sur tablette portrait, 1 sur téléphone.
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
|
||||||
gap: 1.5rem;
|
gap: 1.5rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 900px;
|
max-width: 900px;
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<div class="pair-screen">
|
||||||
|
<main class="pair-card">
|
||||||
|
<div class="pair-icon" aria-hidden="true">
|
||||||
|
<lucide-icon [img]="Tablet" [size]="28"></lucide-icon>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (onHost) {
|
||||||
|
<h1>{{ 'remoteAccess.pair.onHostTitle' | translate }}</h1>
|
||||||
|
<p class="pair-text">{{ 'remoteAccess.pair.onHostText' | translate }}</p>
|
||||||
|
<a class="btn-primary pair-link" [routerLink]="['/settings']" [queryParams]="{ section: 'remote-access' }">
|
||||||
|
{{ 'remoteAccess.pair.onHostLink' | translate }}
|
||||||
|
</a>
|
||||||
|
} @else {
|
||||||
|
<h1>{{ 'remoteAccess.pair.title' | translate }}</h1>
|
||||||
|
<p class="pair-text">{{ 'remoteAccess.pair.text' | translate }}</p>
|
||||||
|
|
||||||
|
<form class="pair-form" (ngSubmit)="submit()">
|
||||||
|
<div class="field">
|
||||||
|
<label for="pair-code">{{ 'remoteAccess.pair.codeLabel' | translate }}</label>
|
||||||
|
<!-- Pas de ngModel : on réécrit le champ à chaque frappe pour n'y laisser
|
||||||
|
que des chiffres (ngModel ne rafraîchit pas la vue si la valeur nettoyée ne change pas).
|
||||||
|
Pas de maxlength : il couperait « 123 456 » collé AVANT le nettoyage. -->
|
||||||
|
<input id="pair-code" name="code" class="code-input"
|
||||||
|
inputmode="numeric" autocomplete="one-time-code"
|
||||||
|
[value]="code" (input)="onCodeInput($event)"
|
||||||
|
placeholder="000000" />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="pair-name">{{ 'remoteAccess.pair.nameLabel' | translate }}</label>
|
||||||
|
<input id="pair-name" name="deviceName" maxlength="100" [(ngModel)]="deviceName" />
|
||||||
|
<p class="field-hint">{{ 'remoteAccess.pair.nameHint' | translate }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (error) {
|
||||||
|
<p class="pair-error" role="alert">{{ error }}</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<button type="submit" class="btn-primary pair-submit" [disabled]="!canSubmit">
|
||||||
|
<lucide-icon [img]="Check" [size]="16"></lucide-icon>
|
||||||
|
{{ (submitting ? 'remoteAccess.pair.submitting' : 'remoteAccess.pair.submit') | translate }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
// Recouvre tout le shell (menus compris) : sans appairage, rien d'autre n'est utilisable.
|
||||||
|
.pair-screen {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 2000;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 1rem;
|
||||||
|
background: #0a0a14;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pair-card {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 420px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 1.75rem 1.5rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: #111827;
|
||||||
|
border: 1px solid #1f2937;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.35rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: white;
|
||||||
|
text-wrap: balance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pair-icon {
|
||||||
|
width: 52px;
|
||||||
|
height: 52px;
|
||||||
|
border-radius: 12px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
background: rgba(108, 99, 255, 0.15);
|
||||||
|
color: #a5b4fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pair-text {
|
||||||
|
margin: 0;
|
||||||
|
color: #d1d5db;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
line-height: 1.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pair-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gros chiffres espacés : se lit et se tape facilement au doigt.
|
||||||
|
.code-input {
|
||||||
|
font-size: 1.8rem !important;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
letter-spacing: 0.5em;
|
||||||
|
text-align: center;
|
||||||
|
padding: 0.6rem 0 0.6rem 0.5em !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pair-error {
|
||||||
|
margin: 0;
|
||||||
|
color: #fca5a5;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pair-submit,
|
||||||
|
.pair-link {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
min-height: 48px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import { Component, OnInit, inject } from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||||
|
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||||
|
import { LucideAngularModule, Tablet, Check } from 'lucide-angular';
|
||||||
|
|
||||||
|
import { RemoteAccessService } from '../../services/remote-access.service';
|
||||||
|
import { guessDeviceKey, normalizeCode, safeReturnUrl } from './remote-pair.helpers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Écran d'appairage d'une tablette (accès distant, mode bureau). Recouvre toute l'appli :
|
||||||
|
* tant que l'appareil n'est pas reconnu, rien d'autre n'est accessible depuis le réseau.
|
||||||
|
* Le QR code affiché sur le PC ouvre `/pair?code=123456` : le code est alors pré-rempli.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'app-remote-pair',
|
||||||
|
imports: [FormsModule, RouterLink, TranslatePipe, LucideAngularModule],
|
||||||
|
templateUrl: './remote-pair.component.html',
|
||||||
|
styleUrls: ['./remote-pair.component.scss']
|
||||||
|
})
|
||||||
|
export class RemotePairComponent implements OnInit {
|
||||||
|
readonly Tablet = Tablet;
|
||||||
|
readonly Check = Check;
|
||||||
|
|
||||||
|
private readonly route = inject(ActivatedRoute);
|
||||||
|
private readonly router = inject(Router);
|
||||||
|
private readonly remoteAccess = inject(RemoteAccessService);
|
||||||
|
private readonly translate = inject(TranslateService);
|
||||||
|
|
||||||
|
code = '';
|
||||||
|
deviceName = '';
|
||||||
|
submitting = false;
|
||||||
|
error: string | null = null;
|
||||||
|
/** Ouvert sur le PC lui-même : rien à appairer. */
|
||||||
|
onHost = false;
|
||||||
|
private returnUrl = '/';
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
const params = this.route.snapshot.queryParamMap;
|
||||||
|
this.code = normalizeCode(params.get('code'));
|
||||||
|
this.returnUrl = safeReturnUrl(params.get('returnUrl'));
|
||||||
|
this.deviceName = this.translate.instant(guessDeviceKey(navigator.userAgent));
|
||||||
|
|
||||||
|
this.remoteAccess.session().subscribe(session => {
|
||||||
|
if (!session.remote) this.onHost = true;
|
||||||
|
else if (session.paired) this.router.navigateByUrl(this.returnUrl);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get canSubmit(): boolean {
|
||||||
|
return /^\d{6}$/.test(this.code) && !this.submitting;
|
||||||
|
}
|
||||||
|
|
||||||
|
onCodeInput(event: Event): void {
|
||||||
|
const input = event.target as HTMLInputElement;
|
||||||
|
this.code = normalizeCode(input.value);
|
||||||
|
input.value = this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
submit(): void {
|
||||||
|
if (!this.canSubmit) return;
|
||||||
|
this.submitting = true;
|
||||||
|
this.error = null;
|
||||||
|
this.remoteAccess.pair(this.code, this.deviceName).subscribe({
|
||||||
|
next: () => {
|
||||||
|
this.remoteAccess.resetSession();
|
||||||
|
this.router.navigateByUrl(this.returnUrl);
|
||||||
|
},
|
||||||
|
error: (err: HttpErrorResponse) => {
|
||||||
|
this.submitting = false;
|
||||||
|
this.error = this.translate.instant(err.status === 403 ? 'remoteAccess.pair.rejected' : 'remoteAccess.pair.failed');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { guessDeviceKey, normalizeCode, safeReturnUrl } from './remote-pair.helpers';
|
||||||
|
|
||||||
|
describe('safeReturnUrl', () => {
|
||||||
|
it('keeps internal paths', () => {
|
||||||
|
expect(safeReturnUrl('/campaigns/7')).toBe('/campaigns/7');
|
||||||
|
expect(safeReturnUrl('/sessions/19?tab=dice')).toBe('/sessions/19?tab=dice');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects external or looping targets', () => {
|
||||||
|
for (const bad of [null, '', 'https://evil.example', '//evil.example', '/\\evil.example', '/pair', '/pair?code=1']) {
|
||||||
|
expect(safeReturnUrl(bad)).toBe('/');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('guessDeviceKey', () => {
|
||||||
|
it('recognizes tablets, phones and the rest', () => {
|
||||||
|
expect(guessDeviceKey('Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X)')).toBe('remoteAccess.pair.defaultTablet');
|
||||||
|
expect(guessDeviceKey('Mozilla/5.0 (Linux; Android 14; SM-X710) Safari')).toBe('remoteAccess.pair.defaultTablet');
|
||||||
|
expect(guessDeviceKey('Mozilla/5.0 (Linux; Android 14; Pixel 8) Mobile Safari')).toBe('remoteAccess.pair.defaultPhone');
|
||||||
|
expect(guessDeviceKey('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0)')).toBe('remoteAccess.pair.defaultPhone');
|
||||||
|
expect(guessDeviceKey('Mozilla/5.0 (Windows NT 10.0; Win64; x64)')).toBe('remoteAccess.pair.defaultDevice');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('normalizeCode', () => {
|
||||||
|
it('keeps at most six digits', () => {
|
||||||
|
expect(normalizeCode('123 456')).toBe('123456');
|
||||||
|
expect(normalizeCode('12a3-45678')).toBe('123456');
|
||||||
|
expect(normalizeCode(null)).toBe('');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Logique pure de l'écran d'appairage (testée sans Angular).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Uniquement un chemin interne : jamais d'URL absolue (pas de redirection vers un autre site). */
|
||||||
|
export function safeReturnUrl(value: string | null): string {
|
||||||
|
return value && value.startsWith('/') && !value.startsWith('//') && !value.startsWith('/\\')
|
||||||
|
&& !value.startsWith('/pair') ? value : '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nom proposé par défaut pour l'appareil (clé i18n), d'après le navigateur. */
|
||||||
|
export function guessDeviceKey(userAgent: string): string {
|
||||||
|
const ua = userAgent.toLowerCase();
|
||||||
|
if (ua.includes('ipad') || (ua.includes('android') && !ua.includes('mobile')) || ua.includes('tablet')) {
|
||||||
|
return 'remoteAccess.pair.defaultTablet';
|
||||||
|
}
|
||||||
|
if (ua.includes('iphone') || ua.includes('android')) return 'remoteAccess.pair.defaultPhone';
|
||||||
|
return 'remoteAccess.pair.defaultDevice';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ne garde que les chiffres, 6 au plus (saisie du code ou paramètre d'URL du QR code). */
|
||||||
|
export function normalizeCode(value: string | null | undefined): string {
|
||||||
|
return (value ?? '').replace(/\D/g, '').slice(0, 6);
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { NavigationEnd, Router } from '@angular/router';
|
||||||
|
import { BehaviorSubject, Observable, forkJoin, merge, of } from 'rxjs';
|
||||||
|
import { catchError, filter, map, startWith, switchMap } from 'rxjs/operators';
|
||||||
|
import { SessionService } from './session.service';
|
||||||
|
import { PlaythroughService } from './playthrough.service';
|
||||||
|
import { CampaignService } from './campaign.service';
|
||||||
|
import { Session } from './session.model';
|
||||||
|
|
||||||
|
/** Séance en cours enrichie de quoi l'identifier (Partie + Campagne). */
|
||||||
|
export interface ActiveSessionEntry {
|
||||||
|
session: Session;
|
||||||
|
playthroughName: string | null;
|
||||||
|
campaignId: string | null;
|
||||||
|
campaignName: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlaythroughLabel {
|
||||||
|
playthroughName: string | null;
|
||||||
|
campaignId: string | null;
|
||||||
|
campaignName: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* État partagé des séances en cours (toutes Parties confondues), la plus récente d'abord.
|
||||||
|
*
|
||||||
|
* <p>Alimente le raccourci « Séance en cours » du menu principal et le bloc « Jouer »
|
||||||
|
* du hub campagne : une séance ne doit plus se perdre au fond d'une page. Rafraîchi à
|
||||||
|
* chaque navigation et après chaque démarrage/fin/suppression ({@link SessionService.changed$}).
|
||||||
|
* Les libellés Partie/Campagne sont mis en cache (une séance active change rarement de Partie).</p>
|
||||||
|
*/
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class ActiveSessionsService {
|
||||||
|
private readonly subject = new BehaviorSubject<ActiveSessionEntry[]>([]);
|
||||||
|
readonly active$: Observable<ActiveSessionEntry[]> = this.subject.asObservable();
|
||||||
|
|
||||||
|
private readonly labels = new Map<string, PlaythroughLabel>();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
router: Router,
|
||||||
|
private sessionService: SessionService,
|
||||||
|
private playthroughService: PlaythroughService,
|
||||||
|
private campaignService: CampaignService
|
||||||
|
) {
|
||||||
|
merge(
|
||||||
|
router.events.pipe(filter(e => e instanceof NavigationEnd)),
|
||||||
|
this.sessionService.changed$
|
||||||
|
).pipe(
|
||||||
|
startWith(null),
|
||||||
|
// switchMap : une navigation rapide annule le fetch précédent (pas de réponse périmée).
|
||||||
|
switchMap(() => this.fetch())
|
||||||
|
).subscribe(list => this.subject.next(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Force un rafraîchissement (ex. après une action hors SessionService). */
|
||||||
|
refresh(): void {
|
||||||
|
this.fetch().subscribe(list => this.subject.next(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetch(): Observable<ActiveSessionEntry[]> {
|
||||||
|
return this.sessionService.getActiveSessions().pipe(
|
||||||
|
// Back indisponible / ancienne version : on garde l'état connu plutôt que de faire clignoter.
|
||||||
|
catchError(() => of(null)),
|
||||||
|
switchMap(sessions => {
|
||||||
|
if (!sessions) return of(this.subject.value);
|
||||||
|
if (sessions.length === 0) return of([] as ActiveSessionEntry[]);
|
||||||
|
return forkJoin(sessions.map(s => this.labelOf(s.playthroughId).pipe(
|
||||||
|
map(label => ({ session: s, ...label }))
|
||||||
|
)));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private labelOf(playthroughId: string): Observable<PlaythroughLabel> {
|
||||||
|
const cached = this.labels.get(playthroughId);
|
||||||
|
if (cached) return of(cached);
|
||||||
|
const unknown: PlaythroughLabel = { playthroughName: null, campaignId: null, campaignName: null };
|
||||||
|
return this.playthroughService.getById(playthroughId).pipe(
|
||||||
|
switchMap(p => this.campaignService.getCampaignById(p.campaignId).pipe(
|
||||||
|
map(c => ({ playthroughName: p.name, campaignId: p.campaignId, campaignName: c.name })),
|
||||||
|
catchError(() => of({ ...unknown, playthroughName: p.name, campaignId: p.campaignId }))
|
||||||
|
)),
|
||||||
|
map(label => { this.labels.set(playthroughId, label); return label; }),
|
||||||
|
catchError(() => of(unknown))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { Campaign, CampaignCreate, Arc, ArcCreate, Chapter, ChapterCreate, Scene, SceneCreate, Quest } from './campaign.model';
|
import { Campaign, CampaignCreate, Arc, ArcCreate, Chapter, ChapterCreate, Scene, SceneCreate, Quest, Playthrough } from './campaign.model';
|
||||||
import { CampaignReadinessAssessment } from './readiness.model';
|
import { CampaignReadinessAssessment } from './readiness.model';
|
||||||
import { Npc } from './npc.model';
|
import { Npc } from './npc.model';
|
||||||
import { RandomTable } from './random-table.model';
|
import { RandomTable } from './random-table.model';
|
||||||
@@ -19,6 +19,8 @@ export interface CampaignTreeResponse {
|
|||||||
randomTables: RandomTable[];
|
randomTables: RandomTable[];
|
||||||
enemies: Enemy[];
|
enemies: Enemy[];
|
||||||
quests: Quest[];
|
quests: Quest[];
|
||||||
|
/** Parties (Playthroughs) de la campagne — nœud « Parties » de l'arbre. */
|
||||||
|
playthroughs?: Playthrough[];
|
||||||
readiness: CampaignReadinessAssessment;
|
readiness: CampaignReadinessAssessment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Observable, catchError, of, shareReplay } from 'rxjs';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accès distant à l'application de bureau (tablette / téléphone sur le réseau local).
|
||||||
|
* Côté PC : réglage, code d'appairage, appareils (routes /api/settings/remote-access,
|
||||||
|
* réservées à la machine). Côté tablette : appairage et état de la session.
|
||||||
|
* En Docker ces routes n'existent pas (404) : l'écran Paramètres masque alors la section.
|
||||||
|
*/
|
||||||
|
export interface PairedDevice {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
userAgent?: string | null;
|
||||||
|
createdAt?: string | null;
|
||||||
|
lastSeenAt?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RemoteAccessStatus {
|
||||||
|
enabled: boolean;
|
||||||
|
port: number;
|
||||||
|
running: boolean;
|
||||||
|
urls: string[];
|
||||||
|
lastError?: string | null;
|
||||||
|
devices: PairedDevice[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PairingCode {
|
||||||
|
code: string;
|
||||||
|
expiresAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Une tablette peut-elle joindre ce PC ? (Windows : type de réseau + pare-feu) */
|
||||||
|
export interface NetworkReadiness {
|
||||||
|
supported: boolean;
|
||||||
|
ready: boolean;
|
||||||
|
/** Réseaux connectés classés « Public » que le pare-feu ne laisse pas passer. */
|
||||||
|
publicNetworks: string[];
|
||||||
|
firewallAllowed: boolean;
|
||||||
|
firewallBlocked: boolean;
|
||||||
|
program?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FirewallFixOutcome = 'APPLIED' | 'CANCELLED' | 'FAILED' | 'UNSUPPORTED';
|
||||||
|
|
||||||
|
export interface FirewallFixResponse {
|
||||||
|
outcome: FirewallFixOutcome;
|
||||||
|
readiness: NetworkReadiness;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RemoteSession {
|
||||||
|
/** Requête arrivée par le réseau local (tablette) plutôt que depuis le PC. */
|
||||||
|
remote: boolean;
|
||||||
|
paired: boolean;
|
||||||
|
deviceName?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Réponse d'erreur du filtre / des contrôleurs. */
|
||||||
|
export const REMOTE_PAIRING_REQUIRED = 'remote_pairing_required';
|
||||||
|
export const REMOTE_FORBIDDEN = 'remote_forbidden';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class RemoteAccessService {
|
||||||
|
|
||||||
|
private readonly adminUrl = '/api/settings/remote-access';
|
||||||
|
private session$?: Observable<RemoteSession>;
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
status(): Observable<RemoteAccessStatus> {
|
||||||
|
return this.http.get<RemoteAccessStatus>(this.adminUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
configure(enabled: boolean, port: number): Observable<RemoteAccessStatus> {
|
||||||
|
return this.http.put<RemoteAccessStatus>(this.adminUrl, { enabled, port });
|
||||||
|
}
|
||||||
|
|
||||||
|
newPairingCode(): Observable<PairingCode> {
|
||||||
|
return this.http.post<PairingCode>(`${this.adminUrl}/pairing-code`, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
revoke(deviceId: string): Observable<void> {
|
||||||
|
return this.http.delete<void>(`${this.adminUrl}/devices/${deviceId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
networkCheck(): Observable<NetworkReadiness> {
|
||||||
|
return this.http.get<NetworkReadiness>(`${this.adminUrl}/network-check`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Attend la réponse de l'utilisateur à la confirmation administrateur de Windows. */
|
||||||
|
allowThroughFirewall(): Observable<FirewallFixResponse> {
|
||||||
|
return this.http.post<FirewallFixResponse>(`${this.adminUrl}/firewall-rule`, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
openNetworkSettings(): Observable<void> {
|
||||||
|
return this.http.post<void>(`${this.adminUrl}/open-network-settings`, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
pair(code: string, deviceName: string): Observable<PairedDevice> {
|
||||||
|
return this.http.post<PairedDevice>('/api/remote-access/pair', { code, deviceName });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suis-je une tablette ? Mis en cache pour la durée de la page. Sans la route (Docker,
|
||||||
|
* ancienne version), on se considère sur la machine elle-même.
|
||||||
|
*/
|
||||||
|
session(): Observable<RemoteSession> {
|
||||||
|
this.session$ ??= this.http.get<RemoteSession>('/api/remote-access/session').pipe(
|
||||||
|
catchError(() => of({ remote: false, paired: true } as RemoteSession)),
|
||||||
|
shareReplay(1)
|
||||||
|
);
|
||||||
|
return this.session$;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** À appeler après un appairage : l'état de session a changé. */
|
||||||
|
resetSession(): void {
|
||||||
|
this.session$ = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable, Subject, tap } from 'rxjs';
|
||||||
import { Session } from './session.model';
|
import { Session } from './session.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,11 +13,23 @@ import { Session } from './session.model';
|
|||||||
export class SessionService {
|
export class SessionService {
|
||||||
private apiUrl = '/api/sessions';
|
private apiUrl = '/api/sessions';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Émet après chaque mutation qui change l'ensemble des séances en cours
|
||||||
|
* (démarrage, fin, renommage, suppression) — écouté par {@link ActiveSessionsService}
|
||||||
|
* pour rafraîchir le raccourci « Séance en cours » sans attendre une navigation.
|
||||||
|
*/
|
||||||
|
readonly changed$ = new Subject<void>();
|
||||||
|
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
/** Lance une nouvelle session sur la Partie (Playthrough) donnée. */
|
/** Lance une nouvelle session sur la Partie (Playthrough) donnée. */
|
||||||
startSession(playthroughId: string): Observable<Session> {
|
startSession(playthroughId: string): Observable<Session> {
|
||||||
return this.http.post<Session>(this.apiUrl, { playthroughId });
|
return this.http.post<Session>(this.apiUrl, { playthroughId }).pipe(tap(() => this.changed$.next()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Toutes les séances en cours (toutes Parties confondues), la plus récente d'abord. */
|
||||||
|
getActiveSessions(): Observable<Session[]> {
|
||||||
|
return this.http.get<Session[]>(this.apiUrl, { params: new HttpParams().set('active', 'true') });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,15 +61,15 @@ export class SessionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
endSession(id: string): Observable<Session> {
|
endSession(id: string): Observable<Session> {
|
||||||
return this.http.post<Session>(`${this.apiUrl}/${id}/end`, {});
|
return this.http.post<Session>(`${this.apiUrl}/${id}/end`, {}).pipe(tap(() => this.changed$.next()));
|
||||||
}
|
}
|
||||||
|
|
||||||
renameSession(id: string, name: string): Observable<Session> {
|
renameSession(id: string, name: string): Observable<Session> {
|
||||||
return this.http.patch<Session>(`${this.apiUrl}/${id}`, { name });
|
return this.http.patch<Session>(`${this.apiUrl}/${id}`, { name }).pipe(tap(() => this.changed$.next()));
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSession(id: string): Observable<void> {
|
deleteSession(id: string): Observable<void> {
|
||||||
return this.http.delete<void>(`${this.apiUrl}/${id}`);
|
return this.http.delete<void>(`${this.apiUrl}/${id}`).pipe(tap(() => this.changed$.next()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Épingle (sceneId) ou dés-épingle (null) la scène courante — mode cockpit. */
|
/** Épingle (sceneId) ou dés-épingle (null) la scène courante — mode cockpit. */
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
@if (entries.length > 0) {
|
||||||
|
<div class="active-shortcut">
|
||||||
|
<button type="button" class="shortcut-main"
|
||||||
|
[class.shortcut-main--current]="entries.length === 1 && isCurrent(entries[0])"
|
||||||
|
[attr.aria-expanded]="entries.length > 1 ? expanded : null"
|
||||||
|
[title]="(entries.length === 1 ? 'playAccess.shortcut.openTitle' : 'playAccess.shortcut.listTitle') | translate"
|
||||||
|
[attr.aria-label]="compact ? ((entries.length === 1 ? 'playAccess.shortcut.openTitle' : 'playAccess.shortcut.listTitle') | translate) : null"
|
||||||
|
(click)="onMainClick()">
|
||||||
|
<span class="live-dot" aria-hidden="true"></span>
|
||||||
|
@if (compact) {
|
||||||
|
@if (entries.length > 1) {
|
||||||
|
<span class="compact-count" aria-hidden="true">{{ entries.length }}</span>
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
<span class="shortcut-texts">
|
||||||
|
<span class="shortcut-label">
|
||||||
|
@if (entries.length === 1) {
|
||||||
|
{{ 'playAccess.shortcut.one' | translate }}
|
||||||
|
} @else {
|
||||||
|
{{ 'playAccess.shortcut.many' | translate:{ n: entries.length } }}
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
@if (entries.length === 1) {
|
||||||
|
<span class="shortcut-sub">{{ entries[0].session.name }}</span>
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
@if (entries.length > 1 && !compact) {
|
||||||
|
<lucide-icon class="shortcut-icon" [img]="expanded ? ChevronUp : ChevronDown" [size]="14"></lucide-icon>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
@if (expanded && entries.length > 1) {
|
||||||
|
<ul class="shortcut-list">
|
||||||
|
@for (e of entries; track e.session.id) {
|
||||||
|
<li>
|
||||||
|
<button type="button" class="shortcut-item" [class.shortcut-item--current]="isCurrent(e)" (click)="open(e)">
|
||||||
|
<span class="shortcut-item-name">{{ e.session.name }}</span>
|
||||||
|
@if (contextOf(e)) {
|
||||||
|
<span class="shortcut-item-ctx">{{ contextOf(e) }}</span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
:host { display: block; }
|
||||||
|
|
||||||
|
.active-shortcut {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.25rem;
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-main {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 44px; // cible tactile
|
||||||
|
padding: 0.45rem 0.5rem 0.45rem 0.6rem;
|
||||||
|
background: rgba(16, 185, 129, 0.1);
|
||||||
|
border: 1px solid rgba(16, 185, 129, 0.45);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: #d1fae5;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
transition: background 0.15s, border-color 0.15s;
|
||||||
|
|
||||||
|
&:hover { background: rgba(16, 185, 129, 0.18); border-color: #10b981; }
|
||||||
|
&:focus-visible { outline: 2px solid #10b981; outline-offset: 2px; }
|
||||||
|
|
||||||
|
&--current { background: rgba(16, 185, 129, 0.22); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.live-dot {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #10b981;
|
||||||
|
box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
|
||||||
|
animation: live-pulse 2s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes live-pulse {
|
||||||
|
0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
|
||||||
|
70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
|
||||||
|
100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.live-dot { animation: none; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-texts {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-label {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.25;
|
||||||
|
overflow-wrap: anywhere; // sidebar étroite : passe à la ligne plutôt que de tronquer
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-sub {
|
||||||
|
font-size: 0.72rem;
|
||||||
|
color: #6ee7b7;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-icon { flex: 0 0 auto; color: #6ee7b7; }
|
||||||
|
|
||||||
|
.shortcut-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.1rem;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 44px;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0.4rem 0.7rem;
|
||||||
|
background: #161628;
|
||||||
|
border: 1px solid #2a2a45;
|
||||||
|
border-radius: 6px;
|
||||||
|
color: #e5e7eb;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
&:hover { border-color: #10b981; }
|
||||||
|
&:focus-visible { outline: 2px solid #10b981; outline-offset: 2px; }
|
||||||
|
&--current { border-color: #10b981; background: rgba(16, 185, 129, 0.12); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-item-name,
|
||||||
|
.shortcut-item-ctx {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shortcut-item-name { font-size: 0.8rem; font-weight: 500; }
|
||||||
|
.shortcut-item-ctx { font-size: 0.7rem; color: #9ca3af; }
|
||||||
|
|
||||||
|
// --- Mode compact (barre haute mobile) ----------------------------------------------
|
||||||
|
:host(.compact) {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.active-shortcut { margin-top: 0; }
|
||||||
|
|
||||||
|
.shortcut-main {
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.3rem;
|
||||||
|
width: auto;
|
||||||
|
min-width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
padding: 0 0.55rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.live-dot { width: 10px; height: 10px; }
|
||||||
|
|
||||||
|
.shortcut-list {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 6px);
|
||||||
|
right: 0;
|
||||||
|
z-index: 30;
|
||||||
|
width: min(280px, calc(100vw - 2rem));
|
||||||
|
padding: 0.4rem;
|
||||||
|
background: #0f0f1a;
|
||||||
|
border: 1px solid #2a2a45;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-count {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #d1fae5;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import { Component, DestroyRef, ElementRef, HostBinding, HostListener, Input, OnInit, booleanAttribute } from '@angular/core';
|
||||||
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
|
import { NavigationEnd, Router } from '@angular/router';
|
||||||
|
import { filter } from 'rxjs/operators';
|
||||||
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
|
import { LucideAngularModule, ChevronDown, ChevronUp } from 'lucide-angular';
|
||||||
|
import { ActiveSessionEntry, ActiveSessionsService } from '../../services/active-sessions.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raccourci « Séance en cours » du menu principal : visible dès qu'une séance tourne,
|
||||||
|
* un clic y ramène depuis n'importe quel écran. Plusieurs séances (plusieurs tables) :
|
||||||
|
* le bouton déplie la liste, la plus récente en tête.
|
||||||
|
*
|
||||||
|
* <p>Composant autonome (styles propres). En mode {@code compact} (barre haute mobile) :
|
||||||
|
* une pastille de 44 px, et la liste s'ouvre en menu déroulant (Échap / tap à côté la ferme).</p>
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'app-active-session-shortcut',
|
||||||
|
imports: [LucideAngularModule, TranslatePipe],
|
||||||
|
templateUrl: './active-session-shortcut.component.html',
|
||||||
|
styleUrls: ['./active-session-shortcut.component.scss']
|
||||||
|
})
|
||||||
|
export class ActiveSessionShortcutComponent implements OnInit {
|
||||||
|
readonly ChevronDown = ChevronDown;
|
||||||
|
readonly ChevronUp = ChevronUp;
|
||||||
|
|
||||||
|
/** Barre haute mobile : pastille seule, liste en menu déroulant. */
|
||||||
|
@Input({ transform: booleanAttribute }) @HostBinding('class.compact') compact = false;
|
||||||
|
|
||||||
|
entries: ActiveSessionEntry[] = [];
|
||||||
|
expanded = false;
|
||||||
|
currentUrl = '';
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private activeSessions: ActiveSessionsService,
|
||||||
|
private router: Router,
|
||||||
|
private destroyRef: DestroyRef,
|
||||||
|
private host: ElementRef<HTMLElement>
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.currentUrl = this.router.url;
|
||||||
|
this.router.events.pipe(
|
||||||
|
filter((e): e is NavigationEnd => e instanceof NavigationEnd),
|
||||||
|
takeUntilDestroyed(this.destroyRef)
|
||||||
|
).subscribe(e => {
|
||||||
|
this.currentUrl = e.urlAfterRedirects;
|
||||||
|
this.expanded = false;
|
||||||
|
});
|
||||||
|
this.activeSessions.active$.pipe(takeUntilDestroyed(this.destroyRef))
|
||||||
|
.subscribe(list => {
|
||||||
|
this.entries = list;
|
||||||
|
if (list.length < 2) this.expanded = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostListener('document:click', ['$event'])
|
||||||
|
onDocumentClick(event: MouseEvent): void {
|
||||||
|
if (this.compact && this.expanded && !this.host.nativeElement.contains(event.target as Node)) {
|
||||||
|
this.expanded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostListener('document:keydown.escape')
|
||||||
|
onEscape(): void {
|
||||||
|
if (this.expanded) this.expanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Une seule séance : on y va ; plusieurs : on déplie la liste. */
|
||||||
|
onMainClick(): void {
|
||||||
|
if (this.entries.length === 1) {
|
||||||
|
this.open(this.entries[0]);
|
||||||
|
} else {
|
||||||
|
this.expanded = !this.expanded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open(entry: ActiveSessionEntry): void {
|
||||||
|
this.router.navigate(['/sessions', entry.session.id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
isCurrent(entry: ActiveSessionEntry): boolean {
|
||||||
|
return this.currentUrl.split(/[?#]/)[0] === `/sessions/${entry.session.id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** « Partie · Campagne » (ce qui est connu). */
|
||||||
|
contextOf(entry: ActiveSessionEntry): string {
|
||||||
|
return [entry.playthroughName, entry.campaignName].filter(Boolean).join(' · ');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="composer">
|
<div class="composer">
|
||||||
<textarea
|
<textarea #composerInput
|
||||||
class="composer-input"
|
class="composer-input"
|
||||||
[(ngModel)]="input"
|
[(ngModel)]="input"
|
||||||
name="aiChatInput"
|
name="aiChatInput"
|
||||||
|
|||||||
@@ -37,11 +37,14 @@ export class SessionAiChatPanelComponent implements OnChanges, OnDestroy {
|
|||||||
|
|
||||||
@Input() sessionId!: string;
|
@Input() sessionId!: string;
|
||||||
@Input() canSaveToJournal = true;
|
@Input() canSaveToJournal = true;
|
||||||
|
/** Question à préremplir (ex. depuis l'onglet Règles) — le MJ la relit avant d'envoyer. */
|
||||||
|
@Input() prefill: string | null = null;
|
||||||
|
|
||||||
/** Émis quand le MJ clique "Ajouter au journal" sur une réponse. */
|
/** Émis quand le MJ clique "Ajouter au journal" sur une réponse. */
|
||||||
@Output() saveToJournal = new EventEmitter<string>();
|
@Output() saveToJournal = new EventEmitter<string>();
|
||||||
|
|
||||||
@ViewChild('messagesContainer') messagesContainer?: ElementRef<HTMLDivElement>;
|
@ViewChild('messagesContainer') messagesContainer?: ElementRef<HTMLDivElement>;
|
||||||
|
@ViewChild('composerInput') composerInput?: ElementRef<HTMLTextAreaElement>;
|
||||||
|
|
||||||
messages: ChatMessage[] = [];
|
messages: ChatMessage[] = [];
|
||||||
currentAssistantText = '';
|
currentAssistantText = '';
|
||||||
@@ -54,6 +57,16 @@ export class SessionAiChatPanelComponent implements OnChanges, OnDestroy {
|
|||||||
constructor(private aiChat: AiChatService, private translate: TranslateService) {}
|
constructor(private aiChat: AiChatService, private translate: TranslateService) {}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if (changes['prefill'] && this.prefill) {
|
||||||
|
this.input = this.prefill;
|
||||||
|
// Après rendu : focus + curseur en fin de texte, prêt à compléter ou envoyer.
|
||||||
|
setTimeout(() => {
|
||||||
|
const el = this.composerInput?.nativeElement;
|
||||||
|
if (!el) return;
|
||||||
|
el.focus();
|
||||||
|
el.setSelectionRange(el.value.length, el.value.length);
|
||||||
|
});
|
||||||
|
}
|
||||||
// Reset complet si on change de session (changement d'instance jouée).
|
// Reset complet si on change de session (changement d'instance jouée).
|
||||||
if (changes['sessionId'] && !changes['sessionId'].firstChange) {
|
if (changes['sessionId'] && !changes['sessionId'].firstChange) {
|
||||||
this.cancelStream();
|
this.cancelStream();
|
||||||
|
|||||||
@@ -64,12 +64,14 @@
|
|||||||
gap: 1.5rem;
|
gap: 1.5rem;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
|
||||||
.header-texts { flex: 1; min-width: 0; }
|
// ~280 px réservés au titre : sinon les actions passent dessous (téléphone).
|
||||||
|
.header-texts { flex: 1 1 280px; min-width: 0; }
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
font-size: 1.75rem;
|
font-size: 1.75rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: white;
|
color: white;
|
||||||
@@ -90,7 +92,8 @@
|
|||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
padding: 0.4rem 0.75rem;
|
padding: 0.4rem 0.75rem;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
min-width: 280px;
|
min-width: min(280px, 100%);
|
||||||
|
flex: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +122,9 @@
|
|||||||
|
|
||||||
.header-actions {
|
.header-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
flex-shrink: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─────────────── Boutons ───────────────
|
// ─────────────── Boutons ───────────────
|
||||||
@@ -176,6 +180,9 @@
|
|||||||
border: 1px solid #1f2937;
|
border: 1px solid #1f2937;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 1.5rem 1.75rem;
|
padding: 1.5rem 1.75rem;
|
||||||
|
|
||||||
|
// Téléphone : la carte garde sa bordure mais rend la place au contenu.
|
||||||
|
@media (max-width: 767.98px) { padding: 1rem 0.85rem; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.timeline-section h2 {
|
.timeline-section h2 {
|
||||||
|
|||||||
@@ -8,6 +8,13 @@
|
|||||||
<lucide-icon [img]="Timer" [size]="14"></lucide-icon>
|
<lucide-icon [img]="Timer" [size]="14"></lucide-icon>
|
||||||
{{ 'sessionReferencePanel.tabPlay' | translate }}
|
{{ 'sessionReferencePanel.tabPlay' | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
class="ref-tab"
|
||||||
|
[class.ref-tab--active]="activeTab === 'rules'"
|
||||||
|
(click)="selectTab('rules')">
|
||||||
|
<lucide-icon [img]="BookOpen" [size]="14"></lucide-icon>
|
||||||
|
{{ 'sessionRules.tab' | translate }}
|
||||||
|
</button>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="ref-tab"
|
class="ref-tab"
|
||||||
[class.ref-tab--active]="activeTab === 'ai'"
|
[class.ref-tab--active]="activeTab === 'ai'"
|
||||||
@@ -72,10 +79,19 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<!-- ====== Règles du système (lecture + recherche instantanée, sans IA) ====== -->
|
||||||
|
@if (activeTab === 'rules') {
|
||||||
|
<app-session-rules-panel
|
||||||
|
[campaignId]="campaignId"
|
||||||
|
(askAi)="onAskAiFromRules($event)">
|
||||||
|
</app-session-rules-panel>
|
||||||
|
}
|
||||||
|
|
||||||
<!-- ====== IA ====== -->
|
<!-- ====== IA ====== -->
|
||||||
@if (activeTab === 'ai') {
|
@if (activeTab === 'ai') {
|
||||||
<app-session-ai-chat-panel
|
<app-session-ai-chat-panel
|
||||||
[sessionId]="sessionId"
|
[sessionId]="sessionId"
|
||||||
|
[prefill]="aiPrefill"
|
||||||
[canSaveToJournal]="canAddToJournal"
|
[canSaveToJournal]="canAddToJournal"
|
||||||
(saveToJournal)="onAiSaveToJournal($event)">
|
(saveToJournal)="onAiSaveToJournal($event)">
|
||||||
</app-session-ai-chat-panel>
|
</app-session-ai-chat-panel>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// ─────────────── Tabs ───────────────
|
// ─────────────── Tabs ───────────────
|
||||||
.ref-tabs {
|
.ref-tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap; // 6 onglets : on passe sur 2 rangs plutôt que de rogner « Scènes ».
|
flex-wrap: wrap; // 8 onglets : 3 rangs plutôt que de rogner « Scènes ».
|
||||||
background: #111827;
|
background: #111827;
|
||||||
border-bottom: 1px solid #1f2937;
|
border-bottom: 1px solid #1f2937;
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,9 @@
|
|||||||
|
|
||||||
&:hover { color: #e5e7eb; background: rgba(108, 99, 255, 0.06); }
|
&:hover { color: #e5e7eb; background: rgba(108, 99, 255, 0.06); }
|
||||||
|
|
||||||
|
// Écran tactile : cible de 44 px (le rang d'onglets reste compact à la souris).
|
||||||
|
@media (pointer: coarse) { min-height: 44px; }
|
||||||
|
|
||||||
&--active {
|
&--active {
|
||||||
color: #c4bdff;
|
color: #c4bdff;
|
||||||
border-bottom-color: #6c63ff;
|
border-bottom-color: #6c63ff;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||||
|
|
||||||
import { TranslatePipe } from '@ngx-translate/core';
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
import { LucideAngularModule, User, Drama, Swords, Dices, ExternalLink, Sparkles, Table2, Package, ChevronDown, ChevronRight, Timer, Pin } from 'lucide-angular';
|
import { LucideAngularModule, User, Drama, Swords, Dices, ExternalLink, Sparkles, Table2, Package, ChevronDown, ChevronRight, Timer, Pin, BookOpen } from 'lucide-angular';
|
||||||
import { catchError, of } from 'rxjs';
|
import { catchError, of } from 'rxjs';
|
||||||
import { CampaignService } from '../../services/campaign.service';
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
import { CharacterService } from '../../services/character.service';
|
import { CharacterService } from '../../services/character.service';
|
||||||
@@ -20,8 +20,9 @@ import { SessionRandomTablesPanelComponent } from '../session-random-tables-pane
|
|||||||
import { SessionItemCatalogsPanelComponent } from '../session-item-catalogs-panel/session-item-catalogs-panel.component';
|
import { SessionItemCatalogsPanelComponent } from '../session-item-catalogs-panel/session-item-catalogs-panel.component';
|
||||||
import { ClocksManagerComponent } from '../../shared/clocks-manager/clocks-manager.component';
|
import { ClocksManagerComponent } from '../../shared/clocks-manager/clocks-manager.component';
|
||||||
import { PlaythroughFlagsManagerComponent } from '../../shared/playthrough-flags-manager/playthrough-flags-manager.component';
|
import { PlaythroughFlagsManagerComponent } from '../../shared/playthrough-flags-manager/playthrough-flags-manager.component';
|
||||||
|
import { SessionRulesPanelComponent } from '../session-rules-panel/session-rules-panel.component';
|
||||||
|
|
||||||
type TabId = 'play' | 'dice' | 'tables' | 'objects' | 'characters' | 'scenes' | 'ai';
|
type TabId = 'play' | 'rules' | 'dice' | 'tables' | 'objects' | 'characters' | 'scenes' | 'ai';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Panneau latéral du mode jeu : référence rapide en lecture seule.
|
* Panneau latéral du mode jeu : référence rapide en lecture seule.
|
||||||
@@ -35,7 +36,7 @@ type TabId = 'play' | 'dice' | 'tables' | 'objects' | 'characters' | 'scenes' |
|
|||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-session-reference-panel',
|
selector: 'app-session-reference-panel',
|
||||||
imports: [LucideAngularModule, TranslatePipe, SessionDicePanelComponent, SessionAiChatPanelComponent, SessionRandomTablesPanelComponent, SessionItemCatalogsPanelComponent, ClocksManagerComponent, PlaythroughFlagsManagerComponent],
|
imports: [LucideAngularModule, TranslatePipe, SessionDicePanelComponent, SessionAiChatPanelComponent, SessionRandomTablesPanelComponent, SessionItemCatalogsPanelComponent, ClocksManagerComponent, PlaythroughFlagsManagerComponent, SessionRulesPanelComponent],
|
||||||
templateUrl: './session-reference-panel.component.html',
|
templateUrl: './session-reference-panel.component.html',
|
||||||
styleUrls: ['./session-reference-panel.component.scss']
|
styleUrls: ['./session-reference-panel.component.scss']
|
||||||
})
|
})
|
||||||
@@ -52,6 +53,7 @@ export class SessionReferencePanelComponent implements OnChanges {
|
|||||||
readonly ChevronRight = ChevronRight;
|
readonly ChevronRight = ChevronRight;
|
||||||
readonly Timer = Timer;
|
readonly Timer = Timer;
|
||||||
readonly Pin = Pin;
|
readonly Pin = Pin;
|
||||||
|
readonly BookOpen = BookOpen;
|
||||||
|
|
||||||
@Input() campaignId!: string;
|
@Input() campaignId!: string;
|
||||||
/** Partie active — nécessaire pour charger les PJ (refonte Playthrough). */
|
/** Partie active — nécessaire pour charger les PJ (refonte Playthrough). */
|
||||||
@@ -68,6 +70,8 @@ export class SessionReferencePanelComponent implements OnChanges {
|
|||||||
|
|
||||||
// « Partie » par défaut : l'état de jeu (horloges + faits) est le réflexe à la table.
|
// « Partie » par défaut : l'état de jeu (horloges + faits) est le réflexe à la table.
|
||||||
activeTab: TabId = 'play';
|
activeTab: TabId = 'play';
|
||||||
|
/** Question préremplie dans l'onglet IA (depuis l'onglet Règles) ; consommée à l'ouverture. */
|
||||||
|
aiPrefill: string | null = null;
|
||||||
|
|
||||||
characters: Character[] = [];
|
characters: Character[] = [];
|
||||||
npcs: Npc[] = [];
|
npcs: Npc[] = [];
|
||||||
@@ -106,6 +110,7 @@ export class SessionReferencePanelComponent implements OnChanges {
|
|||||||
|
|
||||||
selectTab(tab: TabId): void {
|
selectTab(tab: TabId): void {
|
||||||
this.activeTab = tab;
|
this.activeTab = tab;
|
||||||
|
this.aiPrefill = null;
|
||||||
if (tab === 'characters') this.ensureCharactersLoaded();
|
if (tab === 'characters') this.ensureCharactersLoaded();
|
||||||
if (tab === 'scenes') this.ensureTreeLoaded();
|
if (tab === 'scenes') this.ensureTreeLoaded();
|
||||||
}
|
}
|
||||||
@@ -191,6 +196,12 @@ export class SessionReferencePanelComponent implements OnChanges {
|
|||||||
return [...(this.treeData?.scenesByChapter[chapter.id!] ?? [])].sort(byOrder);
|
return [...(this.treeData?.scenesByChapter[chapter.id!] ?? [])].sort(byOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Onglet Règles → « Demander à l'IA » : bascule sur l'IA, question préremplie. */
|
||||||
|
onAskAiFromRules(question: string): void {
|
||||||
|
this.activeTab = 'ai';
|
||||||
|
this.aiPrefill = question || null;
|
||||||
|
}
|
||||||
|
|
||||||
onDiceRolled(result: DiceRollResult): void {
|
onDiceRolled(result: DiceRollResult): void {
|
||||||
this.rolled.emit(result);
|
this.rolled.emit(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import {
|
||||||
|
normalizeForSearch, parseRuleSections, searchTerms, filterRuleSections, blocksToMarkdown,
|
||||||
|
highlightText, highlightHtml
|
||||||
|
} from './rules-reference.util';
|
||||||
|
|
||||||
|
const RULES = [
|
||||||
|
'Ce système se joue avec des d20.',
|
||||||
|
'',
|
||||||
|
'## Combat',
|
||||||
|
"L'initiative se lance au début du combat.",
|
||||||
|
'',
|
||||||
|
'### Attaque d\'opportunité',
|
||||||
|
'',
|
||||||
|
'Quand un ennemi quitte votre allonge, vous pouvez attaquer.',
|
||||||
|
'',
|
||||||
|
'## Magie',
|
||||||
|
'Les sorts coûtent des points de mana.',
|
||||||
|
'',
|
||||||
|
'```',
|
||||||
|
'## pas un titre (bloc de code)',
|
||||||
|
'```',
|
||||||
|
'',
|
||||||
|
'## Équipement',
|
||||||
|
'| Objet | Prix |',
|
||||||
|
'| --- | --- |',
|
||||||
|
'| Épée | 10 po |',
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
describe('normalizeForSearch', () => {
|
||||||
|
it('ignore casse et accents', () => {
|
||||||
|
expect(normalizeForSearch('Équipement Écuyer')).toBe('equipement ecuyer');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('apostrophe typographique et ligatures', () => {
|
||||||
|
expect(normalizeForSearch('L’Œil du cœur')).toBe("l'oeil du coeur");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseRuleSections', () => {
|
||||||
|
const sections = parseRuleSections(RULES, 'Généralités');
|
||||||
|
|
||||||
|
it('découpe sur les H2, garde le préambule sous le titre fourni', () => {
|
||||||
|
expect(sections.map(s => s.title)).toEqual(['Généralités', 'Combat', 'Magie', 'Équipement']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ne coupe pas sur un « ## » dans un bloc de code', () => {
|
||||||
|
const magie = sections.find(s => s.title === 'Magie')!;
|
||||||
|
expect(magie.blocks).toHaveLength(2);
|
||||||
|
expect(magie.blocks[1].markdown).toContain('## pas un titre');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rattache un sous-titre isolé au bloc suivant', () => {
|
||||||
|
const combat = sections.find(s => s.title === 'Combat')!;
|
||||||
|
expect(combat.blocks).toHaveLength(2);
|
||||||
|
expect(combat.blocks[1].markdown.startsWith("### Attaque d'opportunité")).toBe(true);
|
||||||
|
expect(combat.blocks[1].markdown).toContain('allonge');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('garde un tableau en un seul bloc', () => {
|
||||||
|
const equip = sections.find(s => s.title === 'Équipement')!;
|
||||||
|
expect(equip.blocks).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pas de préambule vide ; markdown vide → aucune section', () => {
|
||||||
|
expect(parseRuleSections('## A\ntexte', 'Intro').map(s => s.title)).toEqual(['A']);
|
||||||
|
expect(parseRuleSections('', 'Intro')).toEqual([]);
|
||||||
|
expect(parseRuleSections(null, 'Intro')).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepte les fins de ligne Windows', () => {
|
||||||
|
expect(parseRuleSections('## A\r\nun\r\n\r\ndeux', 'I')[0].blocks).toHaveLength(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('listes', () => {
|
||||||
|
const md = [
|
||||||
|
'## Classes',
|
||||||
|
'Classes jouables :',
|
||||||
|
'- **Barbare** : d12 PV.',
|
||||||
|
'- **Magicien** : d6 PV,',
|
||||||
|
' livre de sorts.',
|
||||||
|
'- **Roublard** : d8 PV.',
|
||||||
|
].join('\n');
|
||||||
|
const [classes] = parseRuleSections(md, 'I');
|
||||||
|
|
||||||
|
it('un bloc par item de premier niveau, continuation indentée incluse', () => {
|
||||||
|
expect(classes.blocks.map(b => b.markdown)).toEqual([
|
||||||
|
'- **Barbare** : d12 PV.',
|
||||||
|
'- **Magicien** : d6 PV,\n livre de sorts.',
|
||||||
|
'- **Roublard** : d8 PV.',
|
||||||
|
]);
|
||||||
|
expect(classes.blocks.every(b => b.context === 'Classes jouables :')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('la recherche ne garde que l\'item, le contexte reste cherchable', () => {
|
||||||
|
const r = filterRuleSections([classes], searchTerms('magicien'));
|
||||||
|
expect(r[0].blocks.map(b => b.markdown)).toEqual(['- **Magicien** : d6 PV,\n livre de sorts.']);
|
||||||
|
expect(filterRuleSections([classes], searchTerms('jouables roublard'))[0].blocks).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rendu : contexte une seule fois, items consécutifs en liste serrée', () => {
|
||||||
|
expect(blocksToMarkdown(classes.blocks)).toBe(
|
||||||
|
'Classes jouables :\n\n- **Barbare** : d12 PV.\n- **Magicien** : d6 PV,\n livre de sorts.\n- **Roublard** : d8 PV.'
|
||||||
|
);
|
||||||
|
expect(blocksToMarkdown([classes.blocks[2]])).toBe('Classes jouables :\n\n- **Roublard** : d8 PV.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('une liste d\'un seul item reste un bloc normal', () => {
|
||||||
|
const [s] = parseRuleSections('## A\nIntro\n- seul', 'I');
|
||||||
|
expect(s.blocks).toHaveLength(1);
|
||||||
|
expect(s.blocks[0].group).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('searchTerms', () => {
|
||||||
|
it('normalise, ignore les mots d\'une lettre et les doublons', () => {
|
||||||
|
expect(searchTerms(' Épée a ÉPÉE sort ')).toEqual(['epee', 'sort']);
|
||||||
|
expect(searchTerms('')).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('filterRuleSections', () => {
|
||||||
|
const sections = parseRuleSections(RULES, 'Généralités');
|
||||||
|
|
||||||
|
it('sans terme : tout', () => {
|
||||||
|
expect(filterRuleSections(sections, [])).toHaveLength(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ne garde que les blocs qui correspondent', () => {
|
||||||
|
const r = filterRuleSections(sections, searchTerms('opportunite'));
|
||||||
|
expect(r).toHaveLength(1);
|
||||||
|
expect(r[0].section.title).toBe('Combat');
|
||||||
|
expect(r[0].blocks).toHaveLength(1);
|
||||||
|
expect(r[0].titleMatch).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('le titre de section sert de contexte (ET entre les termes)', () => {
|
||||||
|
const r = filterRuleSections(sections, searchTerms('combat allonge'));
|
||||||
|
expect(r.map(m => m.section.title)).toEqual(['Combat']);
|
||||||
|
expect(r[0].blocks.map(b => b.markdown)).toEqual([expect.stringContaining('allonge')]);
|
||||||
|
expect(filterRuleSections(sections, searchTerms('magie allonge'))).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('titre correspondant : section entière, placée en tête', () => {
|
||||||
|
const r = filterRuleSections(sections, searchTerms('magie'));
|
||||||
|
expect(r[0].section.title).toBe('Magie');
|
||||||
|
expect(r[0].titleMatch).toBe(true);
|
||||||
|
expect(r[0].blocks).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cherche dans les tableaux, sans accents', () => {
|
||||||
|
expect(filterRuleSections(sections, searchTerms('epee'))[0].section.title).toBe('Équipement');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('highlightText', () => {
|
||||||
|
it('surligne sans tenir compte des accents ni de la casse, en gardant le texte d\'origine', () => {
|
||||||
|
expect(highlightText('Une Épée et une epee', ['epee'])).toBe('Une <mark>Épée</mark> et une <mark>epee</mark>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fusionne les correspondances qui se chevauchent', () => {
|
||||||
|
expect(highlightText('initiative', ['init', 'itia'])).toBe('<mark>initia</mark>tive');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('surligne une ligature trouvée par sa forme simple', () => {
|
||||||
|
expect(highlightText('Le cœur', ['coeur'])).toBe('Le <mark>cœur</mark>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('échappe le HTML', () => {
|
||||||
|
expect(highlightText('a < b & sort', ['sort'])).toBe('a < b & <mark>sort</mark>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gère une forme décomposée (NFD) dans le texte', () => {
|
||||||
|
const decomposed = 'Épée'.normalize('NFD');
|
||||||
|
expect(highlightText(decomposed, ['epee'])).toBe(`<mark>${decomposed}</mark>`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('highlightHtml', () => {
|
||||||
|
it('ne touche ni aux balises ni aux attributs', () => {
|
||||||
|
const html = '<p><a href="/sort">Le sort</a> & la <strong>magie</strong></p>';
|
||||||
|
expect(highlightHtml(html, ['sort', 'magie'])).toBe(
|
||||||
|
'<p><a href="/sort">Le <mark>sort</mark></a> & la <strong><mark>magie</mark></strong></p>'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('décode les entités avant de chercher', () => {
|
||||||
|
expect(highlightHtml('<p>l'attaque</p>', ["l'attaque"])).toBe("<p><mark>l'attaque</mark></p>");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sans terme : HTML inchangé', () => {
|
||||||
|
expect(highlightHtml('<p>x</p>', [])).toBe('<p>x</p>');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,308 @@
|
|||||||
|
/**
|
||||||
|
* Logique PURE de l'onglet « Règles » du mode jeu : découpage du markdown de règles
|
||||||
|
* d'un GameSystem en sections H2 puis en blocs, recherche instantanée (sans IA,
|
||||||
|
* hors ligne) insensible à la casse et aux accents, surlignage dans le HTML rendu.
|
||||||
|
*
|
||||||
|
* Le découpage H2 reste cohérent avec l'éditeur de système et le parser Java
|
||||||
|
* (`^##\s+…$`) ; à la différence de ceux-ci, le texte avant le premier H2 n'est pas
|
||||||
|
* perdu (on le présente sous un titre fourni par l'appelant) et un `## ` à
|
||||||
|
* l'intérieur d'un bloc de code ne coupe pas la section.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Bloc lisible d'une section (paragraphe, liste, tableau… séparé par une ligne vide). */
|
||||||
|
export interface RuleBlock {
|
||||||
|
markdown: string;
|
||||||
|
/** Texte brut normalisé (minuscules, sans accents ni syntaxe markdown) pour la recherche. */
|
||||||
|
searchText: string;
|
||||||
|
/** Item de liste : ce qui précède la liste (sous-titre, phrase d'introduction). */
|
||||||
|
context?: string;
|
||||||
|
/** Item de liste : identifiant de la liste d'origine (regroupement au rendu). */
|
||||||
|
group?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RuleSection {
|
||||||
|
/** Identifiant DOM stable pour l'affichage (ancre du sommaire). */
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
/** Titre normalisé pour la recherche. */
|
||||||
|
searchTitle: string;
|
||||||
|
blocks: RuleBlock[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RuleMatch {
|
||||||
|
section: RuleSection;
|
||||||
|
/** Blocs à afficher : tous si le titre correspond, sinon seulement ceux qui correspondent. */
|
||||||
|
blocks: RuleBlock[];
|
||||||
|
titleMatch: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Signes combinants (accents) isolés par la décomposition NFD. */
|
||||||
|
const DIACRITICS = /\p{M}/gu;
|
||||||
|
const NBSP = String.fromCharCode(0xa0);
|
||||||
|
const H2 = /^##\s+(\S.*)$/;
|
||||||
|
const FENCE = /^\s*(```|~~~)/;
|
||||||
|
const HEADING_ONLY = /^#{3,6}\s+\S/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minuscules + sans accents : « Écuyer » et « ecuyer » se trouvent mutuellement.
|
||||||
|
* Apostrophes typographiques et ligatures (œ, æ) ramenées à leur forme simple :
|
||||||
|
* les règles importées d'un PDF en sont pleines, la saisie au clavier jamais.
|
||||||
|
*/
|
||||||
|
export function normalizeForSearch(text: string): string {
|
||||||
|
return text.normalize('NFD').replace(DIACRITICS, '').toLowerCase()
|
||||||
|
.replace(/[‘’ʼ]/g, "'")
|
||||||
|
.replace(/œ/g, 'oe')
|
||||||
|
.replace(/æ/g, 'ae');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retire les cibles de liens/images markdown (`](url)`) — parcours linéaire plutôt
|
||||||
|
* qu'une regex à quantificateurs imbriqués (backtracking sur un gros livre de règles).
|
||||||
|
*/
|
||||||
|
function stripLinkTargets(markdown: string): string {
|
||||||
|
let out = '';
|
||||||
|
let pos = 0;
|
||||||
|
for (let open = markdown.indexOf('](', pos); open !== -1; open = markdown.indexOf('](', pos)) {
|
||||||
|
const close = markdown.indexOf(')', open + 2);
|
||||||
|
if (close === -1) break;
|
||||||
|
out += markdown.slice(pos, open);
|
||||||
|
pos = close + 1;
|
||||||
|
}
|
||||||
|
return out + markdown.slice(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Retire la syntaxe markdown courante pour ne chercher que dans le texte lu. */
|
||||||
|
function plainText(markdown: string): string {
|
||||||
|
return stripLinkTargets(markdown)
|
||||||
|
.replace(/[*_`~#>|![\]<]/g, ' ')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function toBlock(markdown: string): RuleBlock {
|
||||||
|
return { markdown, searchText: normalizeForSearch(plainText(markdown)) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Début d'item de liste de PREMIER niveau (pas d'indentation). */
|
||||||
|
const LIST_ITEM = /^(?:[-*+]|\d{1,3}[.)])\s+\S/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Une liste devient un bloc PAR ITEM (la recherche « magicien » ne montre que la ligne
|
||||||
|
* du Magicien, pas les onze classes). Ce qui précède la liste (sous-titre, « Exemples : »)
|
||||||
|
* devient le contexte de chaque item : cherchable, et réaffiché une fois au rendu.
|
||||||
|
*/
|
||||||
|
function splitList(block: string, group: number): RuleBlock[] {
|
||||||
|
const lines = block.split('\n');
|
||||||
|
const first = lines.findIndex(l => LIST_ITEM.test(l));
|
||||||
|
if (first === -1) return [toBlock(block)];
|
||||||
|
const items: string[] = [];
|
||||||
|
for (const line of lines.slice(first)) {
|
||||||
|
if (LIST_ITEM.test(line) || items.length === 0) items.push(line);
|
||||||
|
else items[items.length - 1] += `\n${line}`;
|
||||||
|
}
|
||||||
|
if (items.length < 2) return [toBlock(block)];
|
||||||
|
const context = lines.slice(0, first).join('\n').trim() || undefined;
|
||||||
|
return items.map(item => ({
|
||||||
|
markdown: item,
|
||||||
|
searchText: normalizeForSearch(plainText(context ? `${context} ${item}` : item)),
|
||||||
|
context,
|
||||||
|
group
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Markdown à rendre pour une suite de blocs : les items consécutifs d'une même liste
|
||||||
|
* restent une liste serrée, et le contexte d'une liste n'est affiché qu'une fois.
|
||||||
|
*/
|
||||||
|
export function blocksToMarkdown(blocks: RuleBlock[]): string {
|
||||||
|
let out = '';
|
||||||
|
let previousGroup: number | undefined;
|
||||||
|
for (const b of blocks) {
|
||||||
|
const sameList = b.group !== undefined && b.group === previousGroup;
|
||||||
|
if (!sameList && b.context) out += (out ? '\n\n' : '') + b.context;
|
||||||
|
if (out) out += sameList ? '\n' : '\n\n';
|
||||||
|
out += b.markdown;
|
||||||
|
previousGroup = b.group;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Découpe le contenu d'une section en blocs (lignes vides hors blocs de code). */
|
||||||
|
function splitBlocks(lines: string[]): RuleBlock[] {
|
||||||
|
const raw: string[] = [];
|
||||||
|
let current: string[] = [];
|
||||||
|
let inFence = false;
|
||||||
|
const flush = () => {
|
||||||
|
const text = current.join('\n').trim();
|
||||||
|
if (text) raw.push(text);
|
||||||
|
current = [];
|
||||||
|
};
|
||||||
|
for (const line of lines) {
|
||||||
|
if (FENCE.test(line)) inFence = !inFence;
|
||||||
|
if (!inFence && line.trim() === '') { flush(); continue; }
|
||||||
|
current.push(line);
|
||||||
|
}
|
||||||
|
flush();
|
||||||
|
|
||||||
|
// Un sous-titre seul (### …) est rattaché au bloc qui le suit : un résultat de
|
||||||
|
// recherche garde ainsi son contexte.
|
||||||
|
const merged: string[] = [];
|
||||||
|
let pendingHeading = '';
|
||||||
|
for (const block of raw) {
|
||||||
|
const text = pendingHeading ? `${pendingHeading}\n\n${block}` : block;
|
||||||
|
pendingHeading = '';
|
||||||
|
if (HEADING_ONLY.test(block) && !block.includes('\n')) pendingHeading = text;
|
||||||
|
else merged.push(text);
|
||||||
|
}
|
||||||
|
if (pendingHeading) merged.push(pendingHeading);
|
||||||
|
return merged.flatMap((block, i) => splitList(block, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Découpe le markdown de règles en sections H2.
|
||||||
|
* @param preambleTitle titre donné au texte placé avant le premier H2 (s'il y en a).
|
||||||
|
*/
|
||||||
|
export function parseRuleSections(markdown: string | null | undefined, preambleTitle: string): RuleSection[] {
|
||||||
|
if (!markdown?.trim()) return [];
|
||||||
|
const groups: { title: string; lines: string[] }[] = [];
|
||||||
|
let current: { title: string; lines: string[] } = { title: preambleTitle, lines: [] };
|
||||||
|
let inFence = false;
|
||||||
|
|
||||||
|
for (const line of markdown.replace(/\r\n?/g, '\n').split('\n')) {
|
||||||
|
if (FENCE.test(line)) inFence = !inFence;
|
||||||
|
const match = inFence ? null : H2.exec(line);
|
||||||
|
if (match) {
|
||||||
|
groups.push(current);
|
||||||
|
current = { title: match[1].trim(), lines: [] };
|
||||||
|
} else {
|
||||||
|
current.lines.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
groups.push(current);
|
||||||
|
|
||||||
|
return groups
|
||||||
|
.map((g, i) => ({ g, i }))
|
||||||
|
// Le préambule n'existe que s'il a du contenu ; une vraie section vide reste (son titre informe).
|
||||||
|
.filter(({ g, i }) => i > 0 || g.lines.some(l => l.trim()))
|
||||||
|
.map(({ g, i }) => ({
|
||||||
|
id: `rules-section-${i}`,
|
||||||
|
title: g.title,
|
||||||
|
searchTitle: normalizeForSearch(g.title),
|
||||||
|
blocks: splitBlocks(g.lines)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Termes de recherche normalisés (mots d'au moins 2 caractères, sans doublon). */
|
||||||
|
export function searchTerms(query: string | null | undefined): string[] {
|
||||||
|
const words = normalizeForSearch(query ?? '').split(/\s+/).filter(w => w.length >= 2);
|
||||||
|
return [...new Set(words)];
|
||||||
|
}
|
||||||
|
|
||||||
|
const containsAll = (haystack: string, terms: string[]) => terms.every(t => haystack.includes(t));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filtre les sections : un bloc correspond si TOUS les termes figurent dans le titre
|
||||||
|
* de sa section ou dans son texte (« combat initiative » trouve le paragraphe sur
|
||||||
|
* l'initiative de la section Combat). Sections dont le titre correspond en tête.
|
||||||
|
* Sans terme : toutes les sections, tous les blocs.
|
||||||
|
*/
|
||||||
|
export function filterRuleSections(sections: RuleSection[], terms: string[]): RuleMatch[] {
|
||||||
|
if (terms.length === 0) {
|
||||||
|
return sections.map(section => ({ section, blocks: section.blocks, titleMatch: false }));
|
||||||
|
}
|
||||||
|
const matches: RuleMatch[] = [];
|
||||||
|
for (const section of sections) {
|
||||||
|
if (containsAll(section.searchTitle, terms)) {
|
||||||
|
matches.push({ section, blocks: section.blocks, titleMatch: true });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const blocks = section.blocks.filter(b => containsAll(`${section.searchTitle} ${b.searchText}`, terms));
|
||||||
|
if (blocks.length > 0) matches.push({ section, blocks, titleMatch: false });
|
||||||
|
}
|
||||||
|
return [...matches.filter(m => m.titleMatch), ...matches.filter(m => !m.titleMatch)];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── Surlignage ───────────────
|
||||||
|
|
||||||
|
const ENTITIES: Record<string, string> = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: NBSP };
|
||||||
|
|
||||||
|
function decodeEntities(text: string): string {
|
||||||
|
return text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (whole, code: string) => {
|
||||||
|
if (code[0] === '#') {
|
||||||
|
const n = code[1].toLowerCase() === 'x' ? parseInt(code.slice(2), 16) : parseInt(code.slice(1), 10);
|
||||||
|
return Number.isFinite(n) ? String.fromCodePoint(n) : whole;
|
||||||
|
}
|
||||||
|
return ENTITIES[code.toLowerCase()] ?? whole;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(text: string): string {
|
||||||
|
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replaceAll(NBSP, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Surligne les termes dans un texte brut ; renvoie du HTML échappé. */
|
||||||
|
export function highlightText(text: string, terms: string[]): string {
|
||||||
|
if (terms.length === 0 || !text) return escapeHtml(text);
|
||||||
|
// Texte normalisé + correspondance index normalisé → index d'origine
|
||||||
|
// (un caractère accentué peut se décomposer en plusieurs points de code).
|
||||||
|
let norm = '';
|
||||||
|
const origStart: number[] = [];
|
||||||
|
const origEnd: number[] = [];
|
||||||
|
let i = 0;
|
||||||
|
for (const ch of text) {
|
||||||
|
const n = normalizeForSearch(ch);
|
||||||
|
origStart.push(...new Array<number>(n.length).fill(i));
|
||||||
|
origEnd.push(...new Array<number>(n.length).fill(i + ch.length));
|
||||||
|
norm += n;
|
||||||
|
i += ch.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ranges: [number, number][] = [];
|
||||||
|
for (const term of terms) {
|
||||||
|
let from = norm.indexOf(term);
|
||||||
|
while (from !== -1) {
|
||||||
|
ranges.push([origStart[from], origEnd[from + term.length - 1]]);
|
||||||
|
from = norm.indexOf(term, from + term.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ranges.length === 0) return escapeHtml(text);
|
||||||
|
|
||||||
|
ranges.sort((a, b) => a[0] - b[0]);
|
||||||
|
const merged: [number, number][] = [];
|
||||||
|
for (const r of ranges) {
|
||||||
|
const last = merged[merged.length - 1];
|
||||||
|
if (last && r[0] <= last[1]) last[1] = Math.max(last[1], r[1]);
|
||||||
|
else merged.push([r[0], r[1]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let out = '';
|
||||||
|
let pos = 0;
|
||||||
|
for (const [start, end] of merged) {
|
||||||
|
out += escapeHtml(text.slice(pos, start)) + '<mark>' + escapeHtml(text.slice(start, end)) + '</mark>';
|
||||||
|
pos = end;
|
||||||
|
}
|
||||||
|
return out + escapeHtml(text.slice(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Surligne les termes dans du HTML DÉJÀ assaini (sortie DOMPurify) : seuls les nœuds
|
||||||
|
* texte sont touchés, jamais les balises ni leurs attributs. N'ajoute que des
|
||||||
|
* `<mark>` autour de texte ré-échappé : le résultat reste sûr.
|
||||||
|
*/
|
||||||
|
export function highlightHtml(html: string, terms: string[]): string {
|
||||||
|
if (terms.length === 0 || !html) return html;
|
||||||
|
// Parcours linéaire texte / balise (pas de regex à backtracking sur un gros HTML).
|
||||||
|
let out = '';
|
||||||
|
let pos = 0;
|
||||||
|
while (pos < html.length) {
|
||||||
|
const tagStart = html.indexOf('<', pos);
|
||||||
|
const textEnd = tagStart === -1 ? html.length : tagStart;
|
||||||
|
if (textEnd > pos) out += highlightText(decodeEntities(html.slice(pos, textEnd)), terms);
|
||||||
|
if (tagStart === -1) break;
|
||||||
|
const tagEnd = html.indexOf('>', tagStart);
|
||||||
|
if (tagEnd === -1) { out += html.slice(tagStart); break; }
|
||||||
|
out += html.slice(tagStart, tagEnd + 1);
|
||||||
|
pos = tagEnd + 1;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
<div class="rules-panel">
|
||||||
|
@switch (state) {
|
||||||
|
@case ('loading') {
|
||||||
|
<p class="rules-hint">{{ 'common.loading' | translate }}</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
@case ('noSystem') {
|
||||||
|
<div class="rules-empty">
|
||||||
|
<lucide-icon [img]="BookOpen" [size]="22" class="rules-empty-icon"></lucide-icon>
|
||||||
|
<p>{{ 'sessionRules.noSystem' | translate }}</p>
|
||||||
|
<button type="button" class="rules-btn" (click)="openInNewTab(chooseSystemUrl)">
|
||||||
|
<lucide-icon [img]="ExternalLink" [size]="14"></lucide-icon>
|
||||||
|
{{ 'sessionRules.chooseSystem' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@case ('noRules') {
|
||||||
|
<div class="rules-empty">
|
||||||
|
<lucide-icon [img]="BookOpen" [size]="22" class="rules-empty-icon"></lucide-icon>
|
||||||
|
<p>{{ 'sessionRules.noRules' | translate:{ name: gameSystem?.name } }}</p>
|
||||||
|
<button type="button" class="rules-btn" (click)="openInNewTab(editRulesUrl)">
|
||||||
|
<lucide-icon [img]="ExternalLink" [size]="14"></lucide-icon>
|
||||||
|
{{ 'sessionRules.addRules' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@case ('ready') {
|
||||||
|
<!-- Barre : recherche instantanée + bascule vers l'IA -->
|
||||||
|
<div class="rules-toolbar">
|
||||||
|
<div class="rules-search">
|
||||||
|
<lucide-icon [img]="Search" [size]="15" class="rules-search-icon"></lucide-icon>
|
||||||
|
<input type="search" class="rules-search-input"
|
||||||
|
[ngModel]="query" (ngModelChange)="onQueryChange($event)"
|
||||||
|
(keydown.escape)="clearQuery()"
|
||||||
|
[placeholder]="'sessionRules.searchPlaceholder' | translate"
|
||||||
|
[attr.aria-label]="'sessionRules.searchPlaceholder' | translate"
|
||||||
|
autocomplete="off" spellcheck="false" />
|
||||||
|
@if (query) {
|
||||||
|
<button type="button" class="rules-icon-btn" (click)="clearQuery()" [title]="'sessionRules.clear' | translate" [attr.aria-label]="'sessionRules.clear' | translate">
|
||||||
|
<lucide-icon [img]="X" [size]="15"></lucide-icon>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<button type="button" class="rules-btn rules-btn--ai" (click)="askAiAboutQuery()" [title]="'sessionRules.askAiTitle' | translate">
|
||||||
|
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
||||||
|
{{ 'sessionRules.askAi' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="rules-meta">
|
||||||
|
{{ gameSystem?.name }}
|
||||||
|
@if (searching && matches.length > 0) {
|
||||||
|
· {{ (matches.length === 1 ? 'sessionRules.resultsOne' : 'sessionRules.resultsMany') | translate:{ n: matches.length } }}
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
@if (matches.length === 0) {
|
||||||
|
<div class="rules-empty rules-empty--compact">
|
||||||
|
<p>{{ 'sessionRules.noResult' | translate:{ q: query.trim() } }}</p>
|
||||||
|
<button type="button" class="rules-btn rules-btn--ai" (click)="askAiAboutQuery()">
|
||||||
|
<lucide-icon [img]="Sparkles" [size]="14"></lucide-icon>
|
||||||
|
{{ 'sessionRules.askAiInstead' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<!-- Sommaire (sections H2 ; épinglées en tête hors recherche) -->
|
||||||
|
<nav class="rules-toc" [attr.aria-label]="'sessionRules.toc' | translate">
|
||||||
|
<button type="button" class="rules-toc-head" (click)="tocOpen = !tocOpen" [attr.aria-expanded]="tocOpen">
|
||||||
|
<lucide-icon [img]="tocOpen ? ChevronDown : ChevronRight" [size]="13"></lucide-icon>
|
||||||
|
{{ 'sessionRules.toc' | translate }}
|
||||||
|
<span class="rules-count">{{ matches.length }}</span>
|
||||||
|
</button>
|
||||||
|
@if (tocOpen) {
|
||||||
|
<div class="rules-toc-list">
|
||||||
|
@for (m of matches; track m.section.id) {
|
||||||
|
<button type="button" class="rules-chip" [class.rules-chip--pinned]="isPinned(m)" (click)="jumpTo(m)">
|
||||||
|
@if (isPinned(m)) {
|
||||||
|
<lucide-icon [img]="Pin" [size]="11"></lucide-icon>
|
||||||
|
}
|
||||||
|
<span class="rules-chip-label">{{ m.section.title }}</span>
|
||||||
|
@if (searching && !m.titleMatch) {
|
||||||
|
<span class="rules-chip-count">{{ m.blocks.length }}</span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Sections repliables -->
|
||||||
|
<div class="rules-sections">
|
||||||
|
@for (m of matches; track m.section.id) {
|
||||||
|
<article class="rules-section" [id]="m.section.id" [class.rules-section--open]="isOpen(m)">
|
||||||
|
<div class="rules-section-head">
|
||||||
|
<button type="button" class="rules-section-toggle" (click)="toggle(m)" [attr.aria-expanded]="isOpen(m)">
|
||||||
|
<lucide-icon [img]="isOpen(m) ? ChevronDown : ChevronRight" [size]="14" class="rules-chevron"></lucide-icon>
|
||||||
|
<span class="rules-section-title">{{ m.section.title }}</span>
|
||||||
|
@if (searching && !m.titleMatch) {
|
||||||
|
<span class="rules-count">{{ m.blocks.length }} / {{ m.section.blocks.length }}</span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
<button type="button" class="rules-icon-btn" [class.rules-icon-btn--on]="isPinned(m)"
|
||||||
|
[attr.aria-pressed]="isPinned(m)"
|
||||||
|
[title]="(isPinned(m) ? 'sessionRules.unpin' : 'sessionRules.pin') | translate"
|
||||||
|
[attr.aria-label]="(isPinned(m) ? 'sessionRules.unpin' : 'sessionRules.pin') | translate"
|
||||||
|
(click)="togglePin(m)">
|
||||||
|
<lucide-icon [img]="isPinned(m) ? PinOff : Pin" [size]="14"></lucide-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@if (isOpen(m)) {
|
||||||
|
<div class="rules-section-body">
|
||||||
|
@if (m.blocks.length > 0) {
|
||||||
|
<div class="rules-markdown" [innerHTML]="html(m)"></div>
|
||||||
|
} @else {
|
||||||
|
<p class="rules-hint">{{ 'sessionRules.emptySection' | translate }}</p>
|
||||||
|
}
|
||||||
|
<button type="button" class="rules-link" (click)="askAiAboutSection(m)">
|
||||||
|
<lucide-icon [img]="Sparkles" [size]="12"></lucide-icon>
|
||||||
|
{{ 'sessionRules.askAiSection' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</article>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<button type="button" class="rules-link rules-link--footer" (click)="openInNewTab(editRulesUrl)">
|
||||||
|
<lucide-icon [img]="ExternalLink" [size]="12"></lucide-icon>
|
||||||
|
{{ 'sessionRules.editRules' | translate }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,358 @@
|
|||||||
|
:host { display: block; min-width: 0; }
|
||||||
|
|
||||||
|
.rules-panel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.75rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-hint {
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-style: italic;
|
||||||
|
text-align: center;
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── États vides ───────────────
|
||||||
|
.rules-empty {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.6rem;
|
||||||
|
padding: 1.25rem 0.5rem;
|
||||||
|
text-align: center;
|
||||||
|
color: #9ca3af;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
|
||||||
|
p { margin: 0; line-height: 1.45; }
|
||||||
|
|
||||||
|
&--compact { padding: 0.75rem 0.5rem; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-empty-icon { color: #6b7280; }
|
||||||
|
|
||||||
|
// ─────────────── Boutons ───────────────
|
||||||
|
.rules-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0.45rem 0.85rem;
|
||||||
|
background: #1f2937;
|
||||||
|
border: 1px solid #374151;
|
||||||
|
border-radius: 8px;
|
||||||
|
color: #e5e7eb;
|
||||||
|
font-size: 0.82rem;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
&:hover { background: #273244; border-color: #6c63ff; }
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: 2px; }
|
||||||
|
|
||||||
|
&--ai {
|
||||||
|
background: rgba(108, 99, 255, 0.14);
|
||||||
|
border-color: rgba(108, 99, 255, 0.5);
|
||||||
|
color: #c4bdff;
|
||||||
|
&:hover { background: rgba(108, 99, 255, 0.24); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-icon-btn {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
color: #6b7280;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover { color: #e5e7eb; background: rgba(255, 255, 255, 0.05); }
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: -2px; }
|
||||||
|
&--on { color: #fbbf24; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-link {
|
||||||
|
align-self: flex-start;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.35rem;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0 0.25rem;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #a5b4fc;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover { text-decoration: underline; }
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: 2px; }
|
||||||
|
|
||||||
|
&--footer { color: #6b7280; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── Barre de recherche ───────────────
|
||||||
|
.rules-toolbar {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-search {
|
||||||
|
flex: 1 1 12rem;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background: #111827;
|
||||||
|
border: 1px solid #374151;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding-left: 0.6rem;
|
||||||
|
|
||||||
|
&:focus-within { border-color: #6c63ff; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-search-icon { color: #6b7280; flex: 0 0 auto; }
|
||||||
|
|
||||||
|
.rules-search-input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 42px;
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
color: #e5e7eb;
|
||||||
|
font-size: 1rem; // 16 px : pas de zoom automatique au focus sur tablette/iPhone
|
||||||
|
|
||||||
|
&::-webkit-search-cancel-button { display: none; } // notre propre bouton « effacer »
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-meta {
|
||||||
|
margin: -0.25rem 0 0;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
color: #6b7280;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-count {
|
||||||
|
margin-left: auto;
|
||||||
|
font-size: 0.7rem;
|
||||||
|
font-weight: 400;
|
||||||
|
color: #6b7280;
|
||||||
|
text-transform: none;
|
||||||
|
letter-spacing: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── Sommaire ───────────────
|
||||||
|
.rules-toc {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-toc-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #9ca3af;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.4px;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
&:hover { color: #d1d5db; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-toc-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.35rem;
|
||||||
|
max-height: 9.5rem; // un long sommaire ne mange pas tout le panneau
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-chip {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.3rem;
|
||||||
|
max-width: 100%;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0.3rem 0.7rem;
|
||||||
|
background: #111827;
|
||||||
|
border: 1px solid #1f2937;
|
||||||
|
border-radius: 999px;
|
||||||
|
color: #d1d5db;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover { border-color: #6c63ff; }
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: 2px; }
|
||||||
|
&--pinned { border-color: rgba(251, 191, 36, 0.5); color: #fde68a; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-chip-label {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-chip-count {
|
||||||
|
font-size: 0.68rem;
|
||||||
|
background: rgba(250, 204, 21, 0.18);
|
||||||
|
color: #fde68a;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── Sections ───────────────
|
||||||
|
.rules-sections {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-section {
|
||||||
|
background: #111827;
|
||||||
|
border: 1px solid #1f2937;
|
||||||
|
border-radius: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
scroll-margin-top: 0.5rem;
|
||||||
|
|
||||||
|
&--open { border-color: #2d3748; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-section-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-section-toggle {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 0.4rem 0.4rem 0.4rem 0.7rem;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #e5e7eb;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
font-weight: 600;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: -2px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-chevron { flex: 0 0 auto; color: #6b7280; }
|
||||||
|
|
||||||
|
.rules-section-title {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rules-section-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.25rem;
|
||||||
|
padding: 0 0.85rem 0.35rem;
|
||||||
|
border-top: 1px solid #1f2937;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rendu markdown (HTML injecté → ::ng-deep, limité à ce conteneur).
|
||||||
|
.rules-markdown {
|
||||||
|
padding-top: 0.6rem;
|
||||||
|
color: #d1d5db;
|
||||||
|
font-size: 0.86rem;
|
||||||
|
line-height: 1.55;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
::ng-deep {
|
||||||
|
> :first-child { margin-top: 0; }
|
||||||
|
> :last-child { margin-bottom: 0; }
|
||||||
|
|
||||||
|
p { margin: 0 0 0.6em; }
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
margin: 0.9em 0 0.35em;
|
||||||
|
color: #f3f4f6;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.25;
|
||||||
|
}
|
||||||
|
h1, h2 { font-size: 0.98rem; }
|
||||||
|
h3 { font-size: 0.92rem; }
|
||||||
|
h4, h5, h6 { font-size: 0.86rem; }
|
||||||
|
|
||||||
|
strong { color: #f3f4f6; }
|
||||||
|
ul, ol { margin: 0.3em 0 0.6em; padding-left: 1.3em; }
|
||||||
|
li { margin: 0.15em 0; }
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
margin: 0.4em 0;
|
||||||
|
padding: 0.2em 0.8em;
|
||||||
|
border-left: 3px solid #3a3a5a;
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background: #0b0b15;
|
||||||
|
border: 1px solid #2a2a3d;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0 0.25em;
|
||||||
|
font-size: 0.82em;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background: #0b0b15;
|
||||||
|
border: 1px solid #2a2a3d;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 0.6em 0.75em;
|
||||||
|
overflow-x: auto;
|
||||||
|
code { background: none; border: 0; padding: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Les tableaux défilent dans leur boîte : jamais de scroll horizontal de page.
|
||||||
|
table {
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: auto;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin: 0.4em 0 0.7em;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
th, td {
|
||||||
|
border: 1px solid #2a2a3d;
|
||||||
|
padding: 0.3em 0.55em;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
th { background: #161b26; color: #f3f4f6; }
|
||||||
|
|
||||||
|
a { color: #a5b4fc; }
|
||||||
|
img { max-width: 100%; height: auto; }
|
||||||
|
|
||||||
|
mark {
|
||||||
|
background: rgba(250, 204, 21, 0.3);
|
||||||
|
color: #fef9c3;
|
||||||
|
border-radius: 2px;
|
||||||
|
padding: 0 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
import { Component, EventEmitter, Input, OnChanges, OnDestroy, Output, SimpleChanges } from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
||||||
|
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||||
|
import {
|
||||||
|
LucideAngularModule, Search, X, Sparkles, ChevronDown, ChevronRight, Pin, PinOff, BookOpen, ExternalLink
|
||||||
|
} from 'lucide-angular';
|
||||||
|
import DOMPurify from 'dompurify';
|
||||||
|
import { marked } from 'marked';
|
||||||
|
import { Subscription, of } from 'rxjs';
|
||||||
|
import { catchError, switchMap } from 'rxjs/operators';
|
||||||
|
import { CampaignService } from '../../services/campaign.service';
|
||||||
|
import { GameSystemService } from '../../services/game-system.service';
|
||||||
|
import { GameSystem } from '../../services/game-system.model';
|
||||||
|
import {
|
||||||
|
RuleMatch, RuleSection, blocksToMarkdown, filterRuleSections, highlightHtml, parseRuleSections, searchTerms
|
||||||
|
} from './rules-reference.util';
|
||||||
|
|
||||||
|
type RulesState = 'loading' | 'noSystem' | 'noRules' | 'ready';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Onglet « Règles » du mode jeu : les règles du système de la campagne sous la main,
|
||||||
|
* lisibles et cherchables INSTANTANÉMENT (sans IA, hors ligne).
|
||||||
|
*
|
||||||
|
* <p>Sommaire des sections H2, sections repliables, recherche qui filtre jusqu'au
|
||||||
|
* paragraphe et surligne, sections épinglées (par système, dans le navigateur).
|
||||||
|
* « Demander à l'IA » bascule sur l'onglet IA avec la question préremplie.</p>
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'app-session-rules-panel',
|
||||||
|
imports: [FormsModule, LucideAngularModule, TranslatePipe],
|
||||||
|
templateUrl: './session-rules-panel.component.html',
|
||||||
|
styleUrls: ['./session-rules-panel.component.scss']
|
||||||
|
})
|
||||||
|
export class SessionRulesPanelComponent implements OnChanges, OnDestroy {
|
||||||
|
readonly Search = Search;
|
||||||
|
readonly X = X;
|
||||||
|
readonly Sparkles = Sparkles;
|
||||||
|
readonly ChevronDown = ChevronDown;
|
||||||
|
readonly ChevronRight = ChevronRight;
|
||||||
|
readonly Pin = Pin;
|
||||||
|
readonly PinOff = PinOff;
|
||||||
|
readonly BookOpen = BookOpen;
|
||||||
|
readonly ExternalLink = ExternalLink;
|
||||||
|
|
||||||
|
@Input() campaignId = '';
|
||||||
|
/** Question (éventuellement vide) à poser dans l'onglet IA. */
|
||||||
|
@Output() askAi = new EventEmitter<string>();
|
||||||
|
|
||||||
|
state: RulesState = 'loading';
|
||||||
|
gameSystem: GameSystem | null = null;
|
||||||
|
sections: RuleSection[] = [];
|
||||||
|
matches: RuleMatch[] = [];
|
||||||
|
|
||||||
|
query = '';
|
||||||
|
terms: string[] = [];
|
||||||
|
tocOpen = true;
|
||||||
|
|
||||||
|
/** Sections dépliées hors recherche (repliées par défaut, sauf les épinglées). */
|
||||||
|
private opened = new Set<string>();
|
||||||
|
/** Sections repliées À LA MAIN pendant une recherche (sinon tout résultat est déplié). */
|
||||||
|
private collapsedInSearch = new Set<string>();
|
||||||
|
/** Titres épinglés (le titre survit aux réimports, pas l'index). */
|
||||||
|
private pinned = new Set<string>();
|
||||||
|
private htmlCache = new Map<string, SafeHtml>();
|
||||||
|
private searchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
private loadSub: Subscription | null = null;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private campaignService: CampaignService,
|
||||||
|
private gameSystemService: GameSystemService,
|
||||||
|
private translate: TranslateService,
|
||||||
|
private sanitizer: DomSanitizer
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if (changes['campaignId']) this.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.loadSub?.unsubscribe();
|
||||||
|
if (this.searchTimer) clearTimeout(this.searchTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private load(): void {
|
||||||
|
this.loadSub?.unsubscribe();
|
||||||
|
this.state = 'loading';
|
||||||
|
this.gameSystem = null;
|
||||||
|
this.sections = [];
|
||||||
|
this.matches = [];
|
||||||
|
if (!this.campaignId) return;
|
||||||
|
this.loadSub = this.campaignService.getCampaignById(this.campaignId).pipe(
|
||||||
|
switchMap(c => c.gameSystemId
|
||||||
|
? this.gameSystemService.getById(c.gameSystemId).pipe(catchError(() => of(null)))
|
||||||
|
: of(null)),
|
||||||
|
catchError(() => of(null))
|
||||||
|
).subscribe(gs => this.applySystem(gs));
|
||||||
|
}
|
||||||
|
|
||||||
|
private applySystem(gs: GameSystem | null): void {
|
||||||
|
this.gameSystem = gs;
|
||||||
|
if (!gs) { this.state = 'noSystem'; return; }
|
||||||
|
this.sections = parseRuleSections(gs.rulesMarkdown, this.translate.instant('sessionRules.preamble'));
|
||||||
|
if (this.sections.length === 0) { this.state = 'noRules'; return; }
|
||||||
|
this.pinned = this.readPins();
|
||||||
|
this.opened = new Set(this.sections.filter(s => this.pinned.has(s.title)).map(s => s.id));
|
||||||
|
this.htmlCache.clear();
|
||||||
|
this.state = 'ready';
|
||||||
|
this.recompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── Recherche ───────────────
|
||||||
|
|
||||||
|
onQueryChange(value: string): void {
|
||||||
|
this.query = value;
|
||||||
|
if (this.searchTimer) clearTimeout(this.searchTimer);
|
||||||
|
// Petit délai : un gros livre de règles reste fluide pendant la frappe.
|
||||||
|
this.searchTimer = setTimeout(() => this.applyQuery(), 120);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearQuery(): void {
|
||||||
|
this.query = '';
|
||||||
|
this.applyQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
private applyQuery(): void {
|
||||||
|
this.searchTimer = null;
|
||||||
|
const terms = searchTerms(this.query);
|
||||||
|
if (terms.join(' ') === this.terms.join(' ')) return;
|
||||||
|
this.terms = terms;
|
||||||
|
this.collapsedInSearch.clear();
|
||||||
|
this.htmlCache.clear();
|
||||||
|
this.recompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private recompute(): void {
|
||||||
|
const matches = filterRuleSections(this.sections, this.terms);
|
||||||
|
// Hors recherche : épinglées en tête (ordre du livre conservé dans chaque groupe).
|
||||||
|
this.matches = this.terms.length
|
||||||
|
? matches
|
||||||
|
: [...matches.filter(m => this.isPinned(m)), ...matches.filter(m => !this.isPinned(m))];
|
||||||
|
}
|
||||||
|
|
||||||
|
get searching(): boolean {
|
||||||
|
return this.terms.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
get pinnedCount(): number {
|
||||||
|
return this.matches.filter(m => this.isPinned(m)).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── Sections ───────────────
|
||||||
|
|
||||||
|
isOpen(m: RuleMatch): boolean {
|
||||||
|
return this.searching ? !this.collapsedInSearch.has(m.section.id) : this.opened.has(m.section.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle(m: RuleMatch): void {
|
||||||
|
const set = this.searching ? this.collapsedInSearch : this.opened;
|
||||||
|
const id = m.section.id;
|
||||||
|
if (set.has(id)) set.delete(id);
|
||||||
|
else set.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sommaire : déplie la section et la fait défiler en haut du panneau. */
|
||||||
|
jumpTo(m: RuleMatch): void {
|
||||||
|
if (!this.isOpen(m)) this.toggle(m);
|
||||||
|
setTimeout(() => document.getElementById(m.section.id)?.scrollIntoView({ block: 'start', behavior: 'smooth' }));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** HTML de la section (blocs retenus), assaini puis surligné ; mis en cache par recherche. */
|
||||||
|
html(m: RuleMatch): SafeHtml {
|
||||||
|
const key = `${m.section.id}|${m.blocks.length}`;
|
||||||
|
const cached = this.htmlCache.get(key);
|
||||||
|
if (cached) return cached;
|
||||||
|
const markdown = blocksToMarkdown(m.blocks);
|
||||||
|
const raw = marked.parse(markdown, { async: false, gfm: true, breaks: true }) as string;
|
||||||
|
const clean = DOMPurify.sanitize(raw);
|
||||||
|
// Revue sécurité : le bypass est sûr ICI — le HTML sort de DOMPurify et le surlignage
|
||||||
|
// n'ajoute que des <mark> autour de texte ré-échappé (cf. highlightHtml).
|
||||||
|
// eslint-disable-next-line sonarjs/no-angular-bypass-sanitization
|
||||||
|
const safe = this.sanitizer.bypassSecurityTrustHtml(highlightHtml(clean, this.terms));
|
||||||
|
this.htmlCache.set(key, safe);
|
||||||
|
return safe;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── Épingles (localStorage, par système) ───────────────
|
||||||
|
|
||||||
|
isPinned(m: RuleMatch): boolean {
|
||||||
|
return this.pinned.has(m.section.title);
|
||||||
|
}
|
||||||
|
|
||||||
|
togglePin(m: RuleMatch): void {
|
||||||
|
const title = m.section.title;
|
||||||
|
if (this.pinned.has(title)) this.pinned.delete(title);
|
||||||
|
else this.pinned.add(title);
|
||||||
|
this.writePins();
|
||||||
|
if (!this.searching) this.recompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private pinsKey(): string | null {
|
||||||
|
return this.gameSystem?.id ? `loremind.sessionRules.pinned.${this.gameSystem.id}` : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private readPins(): Set<string> {
|
||||||
|
const key = this.pinsKey();
|
||||||
|
if (!key) return new Set();
|
||||||
|
try {
|
||||||
|
const parsed: unknown = JSON.parse(localStorage.getItem(key) ?? '[]');
|
||||||
|
return new Set(Array.isArray(parsed) ? parsed.filter((x): x is string => typeof x === 'string') : []);
|
||||||
|
} catch {
|
||||||
|
return new Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private writePins(): void {
|
||||||
|
const key = this.pinsKey();
|
||||||
|
if (!key) return;
|
||||||
|
try {
|
||||||
|
localStorage.setItem(key, JSON.stringify([...this.pinned]));
|
||||||
|
} catch {
|
||||||
|
// Stockage indisponible (navigation privée…) : l'épingle vaut pour cet affichage seulement.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────── IA & liens ───────────────
|
||||||
|
|
||||||
|
askAiAboutQuery(): void {
|
||||||
|
const q = this.query.trim();
|
||||||
|
this.askAi.emit(q ? this.translate.instant('sessionRules.askTemplate', { q }) : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
askAiAboutSection(m: RuleMatch): void {
|
||||||
|
this.askAi.emit(this.translate.instant('sessionRules.askSectionTemplate', { title: m.section.title }));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nouvel onglet : on ne quitte pas l'écran de séance (même règle que les fiches). */
|
||||||
|
openInNewTab(path: string): void {
|
||||||
|
window.open(path, '_blank', 'noopener');
|
||||||
|
}
|
||||||
|
|
||||||
|
get chooseSystemUrl(): string {
|
||||||
|
return `/campaigns/${this.campaignId}?edit=system`;
|
||||||
|
}
|
||||||
|
|
||||||
|
get editRulesUrl(): string {
|
||||||
|
return `/game-systems/${this.gameSystem?.id}/edit`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
@if (status; as s) {
|
||||||
|
<section class="card remote-access" id="remote-access">
|
||||||
|
<h2>{{ 'remoteAccess.settings.title' | translate }}</h2>
|
||||||
|
<p class="hint">{{ 'remoteAccess.settings.hint' | translate }}</p>
|
||||||
|
|
||||||
|
@if (error || s.lastError) {
|
||||||
|
<div class="alert alert-error" role="alert">
|
||||||
|
<lucide-icon [img]="AlertCircle" [size]="16"></lucide-icon>
|
||||||
|
<span>{{ error || s.lastError }}</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<label class="switch-row">
|
||||||
|
<input type="checkbox" [ngModel]="s.enabled" (ngModelChange)="toggle($event)" [disabled]="busy" />
|
||||||
|
<span>{{ 'remoteAccess.settings.enable' | translate }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
@if (!s.enabled) {
|
||||||
|
<p class="note">
|
||||||
|
<lucide-icon [img]="ShieldCheck" [size]="15"></lucide-icon>
|
||||||
|
{{ 'remoteAccess.settings.firewallNote' | translate }}
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (s.running) {
|
||||||
|
<div class="remote-block">
|
||||||
|
<h3>{{ 'remoteAccess.settings.addressTitle' | translate }}</h3>
|
||||||
|
@if (s.urls.length > 0) {
|
||||||
|
<ul class="url-list">
|
||||||
|
@for (url of s.urls; track url) {
|
||||||
|
<li><code>{{ url }}</code></li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
} @else {
|
||||||
|
<p class="note">{{ 'remoteAccess.settings.noAddress' | translate }}</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (network?.supported) {
|
||||||
|
<div class="remote-block network-check" [class.ok]="network!.ready">
|
||||||
|
<h3>{{ 'remoteAccess.network.title' | translate }}</h3>
|
||||||
|
@if (network!.ready) {
|
||||||
|
<p class="check-ok">
|
||||||
|
<lucide-icon [img]="CheckCircle2" [size]="16"></lucide-icon>
|
||||||
|
{{ 'remoteAccess.network.ready' | translate }}
|
||||||
|
</p>
|
||||||
|
} @else {
|
||||||
|
@if (network!.publicNetworks.length > 0) {
|
||||||
|
<div class="check-item">
|
||||||
|
<p class="check-problem">{{ 'remoteAccess.network.publicProblem' | translate: { names: network!.publicNetworks.join(', ') } }}</p>
|
||||||
|
<p class="note">{{ 'remoteAccess.network.publicHowTo' | translate }}</p>
|
||||||
|
<button type="button" class="btn-secondary" (click)="openNetworkSettings()">
|
||||||
|
<lucide-icon [img]="Settings2" [size]="15"></lucide-icon>
|
||||||
|
{{ 'remoteAccess.network.openSettings' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (firewallNeedsFix) {
|
||||||
|
<div class="check-item">
|
||||||
|
<p class="check-problem">
|
||||||
|
{{ (network!.firewallBlocked ? 'remoteAccess.network.firewallBlocked' : 'remoteAccess.network.firewallMissing') | translate }}
|
||||||
|
</p>
|
||||||
|
<button type="button" class="btn-primary" (click)="allowFirewall()" [disabled]="fixing">
|
||||||
|
<lucide-icon [img]="ShieldCheck" [size]="16"></lucide-icon>
|
||||||
|
{{ (fixing ? 'remoteAccess.network.fixing' : 'remoteAccess.network.allowFirewall') | translate }}
|
||||||
|
</button>
|
||||||
|
<p class="note">{{ 'remoteAccess.network.uacNote' | translate }}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@if (fixMessage) {
|
||||||
|
<p class="fix-message" role="status">{{ fixMessage }}</p>
|
||||||
|
}
|
||||||
|
<button type="button" class="btn-link" (click)="checkNetwork()" [disabled]="checking">
|
||||||
|
<lucide-icon [img]="RefreshCw" [size]="14"></lucide-icon>
|
||||||
|
{{ (checking ? 'remoteAccess.network.checking' : 'remoteAccess.network.recheck') | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="remote-block">
|
||||||
|
<h3>{{ 'remoteAccess.settings.pairTitle' | translate }}</h3>
|
||||||
|
@if (pairing) {
|
||||||
|
<div class="pairing">
|
||||||
|
@if (qrDataUrl) {
|
||||||
|
<img class="qr" [src]="qrDataUrl" [alt]="'remoteAccess.settings.qrAlt' | translate" width="220" height="220" />
|
||||||
|
}
|
||||||
|
<div class="pairing-info">
|
||||||
|
<p class="pairing-steps">{{ 'remoteAccess.settings.pairSteps' | translate }}</p>
|
||||||
|
<div class="code" [attr.aria-label]="'remoteAccess.settings.codeAria' | translate: { code: pairing.code }">
|
||||||
|
{{ pairing.code.slice(0, 3) }} {{ pairing.code.slice(3) }}
|
||||||
|
</div>
|
||||||
|
<p class="expires">{{ 'remoteAccess.settings.expiresIn' | translate: { time: countdownLabel } }}</p>
|
||||||
|
<button type="button" class="btn-secondary" (click)="newCode()" [disabled]="busy">
|
||||||
|
<lucide-icon [img]="RefreshCw" [size]="14"></lucide-icon>
|
||||||
|
{{ 'remoteAccess.settings.newCode' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<button type="button" class="btn-primary" (click)="newCode()" [disabled]="busy">
|
||||||
|
<lucide-icon [img]="Tablet" [size]="16"></lucide-icon>
|
||||||
|
{{ 'remoteAccess.settings.connectDevice' | translate }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="remote-block">
|
||||||
|
<h3>{{ 'remoteAccess.settings.devicesTitle' | translate }}</h3>
|
||||||
|
@if (s.devices.length === 0) {
|
||||||
|
<p class="note">{{ 'remoteAccess.settings.noDevices' | translate }}</p>
|
||||||
|
} @else {
|
||||||
|
<ul class="device-list">
|
||||||
|
@for (d of s.devices; track d.id) {
|
||||||
|
<li>
|
||||||
|
<div class="device-info">
|
||||||
|
<span class="device-name">{{ d.name }}</span>
|
||||||
|
<span class="device-meta">{{ 'remoteAccess.settings.lastSeen' | translate: { date: formatDate(d.lastSeenAt) } }}</span>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn-icon-danger" (click)="revoke(d)"
|
||||||
|
[title]="'remoteAccess.settings.revoke' | translate"
|
||||||
|
[attr.aria-label]="('remoteAccess.settings.revoke' | translate) + ' : ' + d.name">
|
||||||
|
<lucide-icon [img]="Trash2" [size]="16"></lucide-icon>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<details class="advanced">
|
||||||
|
<summary>{{ 'remoteAccess.settings.advanced' | translate }}</summary>
|
||||||
|
<div class="port-row">
|
||||||
|
<label for="remote-port">{{ 'remoteAccess.settings.portLabel' | translate }}</label>
|
||||||
|
<input id="remote-port" type="number" min="1024" max="65535" [(ngModel)]="port" />
|
||||||
|
<button type="button" class="btn-secondary" (click)="applyPort()" [disabled]="busy || port === s.port">
|
||||||
|
{{ 'remoteAccess.settings.applyPort' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="note">{{ 'remoteAccess.settings.outsideNote' | translate }}</p>
|
||||||
|
</details>
|
||||||
|
</section>
|
||||||
|
}
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
// Complète les styles partagés de la page Paramètres (.card, .hint, .alert).
|
||||||
|
.remote-access {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin: 0 0 0.5rem;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.03em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgba(255, 255, 255, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
min-height: 44px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.7rem;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
input { accent-color: #6c63ff; width: 20px; height: 20px; margin: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.note {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.45rem;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: rgba(255, 255, 255, 0.6);
|
||||||
|
|
||||||
|
lucide-icon { flex-shrink: 0; margin-top: 0.15rem; color: #86efac; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.remote-block {
|
||||||
|
padding-top: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-list {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-size: 1.05rem;
|
||||||
|
color: #c7d2fe;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pairing {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr {
|
||||||
|
border-radius: 8px;
|
||||||
|
background: white;
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pairing-info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pairing-steps {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: rgba(255, 255, 255, 0.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
.code {
|
||||||
|
font-size: 2.2rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.expires {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: rgba(255, 255, 255, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-list {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.4rem;
|
||||||
|
|
||||||
|
li {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.55rem 0.75rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(255, 255, 255, 0.03);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-name { font-weight: 600; overflow-wrap: anywhere; }
|
||||||
|
.device-meta { font-size: 0.8rem; color: rgba(255, 255, 255, 0.5); }
|
||||||
|
|
||||||
|
.btn-icon-danger {
|
||||||
|
justify-content: center;
|
||||||
|
width: 44px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: transparent;
|
||||||
|
color: #fca5a5;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover { background: rgba(239, 68, 68, 0.12); }
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced {
|
||||||
|
summary {
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
min-height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[open] summary { margin-bottom: 0.75rem; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.port-row {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.6rem;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 8rem;
|
||||||
|
padding: 0.6rem 0.8rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid #374151;
|
||||||
|
background: #1f2937;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Vérification du réseau (pare-feu / réseau public) ---------------------------------
|
||||||
|
.network-check {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.9rem 1rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(245, 158, 11, 0.35);
|
||||||
|
background: rgba(245, 158, 11, 0.06);
|
||||||
|
|
||||||
|
&.ok {
|
||||||
|
border-color: rgba(34, 197, 94, 0.35);
|
||||||
|
background: rgba(34, 197, 94, 0.06);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.check-ok {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
margin: 0;
|
||||||
|
color: #86efac;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.check-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.check-problem {
|
||||||
|
margin: 0;
|
||||||
|
color: #fde68a;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fix-message {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
color: rgba(255, 255, 255, 0.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-link {
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
color: #a5b4fc;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
cursor: pointer;
|
||||||
|
min-height: 32px !important;
|
||||||
|
|
||||||
|
&:hover:not(:disabled) { text-decoration: underline; }
|
||||||
|
&:disabled { opacity: 0.6; cursor: wait; }
|
||||||
|
&:focus-visible { outline: 2px solid #6c63ff; border-radius: 4px; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
import { Component, ElementRef, OnDestroy, OnInit, inject } from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||||
|
import { LucideAngularModule, Tablet, Trash2, RefreshCw, AlertCircle, ShieldCheck, CheckCircle2, Settings2 } from 'lucide-angular';
|
||||||
|
import QRCode from 'qrcode';
|
||||||
|
|
||||||
|
import {
|
||||||
|
NetworkReadiness, PairedDevice, PairingCode, RemoteAccessService, RemoteAccessStatus
|
||||||
|
} from '../../services/remote-access.service';
|
||||||
|
import { ConfirmDialogService } from '../../shared/confirm-dialog/confirm-dialog.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paramètres > Accès depuis une tablette (mode bureau). Active le connecteur réseau local,
|
||||||
|
* affiche l'adresse + un code d'appairage (et son QR code), liste les appareils appairés.
|
||||||
|
* Masquée quand le Core ne connaît pas ces routes (Docker : 404).
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'app-remote-access-section',
|
||||||
|
imports: [FormsModule, TranslatePipe, LucideAngularModule],
|
||||||
|
templateUrl: './remote-access-section.component.html',
|
||||||
|
styleUrls: ['../settings.component.scss', './remote-access-section.component.scss']
|
||||||
|
})
|
||||||
|
export class RemoteAccessSectionComponent implements OnInit, OnDestroy {
|
||||||
|
readonly Tablet = Tablet;
|
||||||
|
readonly Trash2 = Trash2;
|
||||||
|
readonly RefreshCw = RefreshCw;
|
||||||
|
readonly AlertCircle = AlertCircle;
|
||||||
|
readonly ShieldCheck = ShieldCheck;
|
||||||
|
readonly CheckCircle2 = CheckCircle2;
|
||||||
|
readonly Settings2 = Settings2;
|
||||||
|
|
||||||
|
private readonly remoteAccess = inject(RemoteAccessService);
|
||||||
|
private readonly translate = inject(TranslateService);
|
||||||
|
private readonly confirmDialog = inject(ConfirmDialogService);
|
||||||
|
private readonly route = inject(ActivatedRoute);
|
||||||
|
private readonly host = inject(ElementRef<HTMLElement>);
|
||||||
|
|
||||||
|
/** Null tant que non chargé, ou si la fonctionnalité n'existe pas (Docker). */
|
||||||
|
status: RemoteAccessStatus | null = null;
|
||||||
|
port = 0;
|
||||||
|
busy = false;
|
||||||
|
error: string | null = null;
|
||||||
|
|
||||||
|
/** Pare-feu et type de réseau (Windows) : null tant que non vérifié ou accès fermé. */
|
||||||
|
network: NetworkReadiness | null = null;
|
||||||
|
checking = false;
|
||||||
|
fixing = false;
|
||||||
|
fixMessage: string | null = null;
|
||||||
|
|
||||||
|
pairing: PairingCode | null = null;
|
||||||
|
qrDataUrl: string | null = null;
|
||||||
|
secondsLeft = 0;
|
||||||
|
private countdown?: ReturnType<typeof setInterval>;
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.remoteAccess.status().subscribe({
|
||||||
|
next: status => {
|
||||||
|
this.apply(status);
|
||||||
|
if (this.route.snapshot.queryParamMap.get('section') === 'remote-access') {
|
||||||
|
setTimeout(() => this.host.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'start' }));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: () => { this.status = null; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.stopCountdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
get primaryUrl(): string | null {
|
||||||
|
return this.status?.urls[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle(enabled: boolean): void {
|
||||||
|
this.save(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
applyPort(): void {
|
||||||
|
this.save(this.status?.enabled ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private save(enabled: boolean): void {
|
||||||
|
if (!this.status || this.busy) return;
|
||||||
|
this.busy = true;
|
||||||
|
this.error = null;
|
||||||
|
this.remoteAccess.configure(enabled, Number(this.port)).subscribe({
|
||||||
|
next: status => {
|
||||||
|
this.busy = false;
|
||||||
|
this.apply(status);
|
||||||
|
if (!status.running) this.clearPairing();
|
||||||
|
},
|
||||||
|
error: (err: HttpErrorResponse) => {
|
||||||
|
this.busy = false;
|
||||||
|
this.error = err.error?.error ?? this.translate.instant('remoteAccess.settings.saveError');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
newCode(): void {
|
||||||
|
if (this.busy) return;
|
||||||
|
this.busy = true;
|
||||||
|
this.error = null;
|
||||||
|
this.remoteAccess.newPairingCode().subscribe({
|
||||||
|
next: async code => {
|
||||||
|
this.busy = false;
|
||||||
|
this.pairing = code;
|
||||||
|
this.startCountdown();
|
||||||
|
await this.renderQr(code.code);
|
||||||
|
},
|
||||||
|
error: (err: HttpErrorResponse) => {
|
||||||
|
this.busy = false;
|
||||||
|
this.error = err.error?.error ?? this.translate.instant('remoteAccess.settings.codeError');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async revoke(device: PairedDevice): Promise<void> {
|
||||||
|
const ok = await this.confirmDialog.confirm({
|
||||||
|
title: this.translate.instant('remoteAccess.settings.revokeTitle'),
|
||||||
|
message: this.translate.instant('remoteAccess.settings.revokeMessage', { name: device.name }),
|
||||||
|
confirmLabel: this.translate.instant('remoteAccess.settings.revoke'),
|
||||||
|
variant: 'danger'
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
this.remoteAccess.revoke(device.id).subscribe({
|
||||||
|
next: () => {
|
||||||
|
if (this.status) this.status = { ...this.status, devices: this.status.devices.filter(d => d.id !== device.id) };
|
||||||
|
},
|
||||||
|
error: () => { this.error = this.translate.instant('remoteAccess.settings.revokeError'); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh(): void {
|
||||||
|
this.remoteAccess.status().subscribe({ next: s => this.apply(s), error: () => undefined });
|
||||||
|
}
|
||||||
|
|
||||||
|
formatDate(value?: string | null): string {
|
||||||
|
if (!value) return '—';
|
||||||
|
const lang = this.translate.currentLang;
|
||||||
|
return new Date(value).toLocaleString(lang ? String(lang) : undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
||||||
|
}
|
||||||
|
|
||||||
|
private apply(status: RemoteAccessStatus): void {
|
||||||
|
this.status = status;
|
||||||
|
this.port = status.port;
|
||||||
|
if (status.running) {
|
||||||
|
this.checkNetwork();
|
||||||
|
} else {
|
||||||
|
this.network = null;
|
||||||
|
this.fixMessage = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Vérification du réseau (Windows) ----------------------------------------------
|
||||||
|
|
||||||
|
/** Sans règle de pare-feu, ou sur un réseau « Public », la tablette charge sans fin : on le dit. */
|
||||||
|
checkNetwork(): void {
|
||||||
|
if (this.checking) return;
|
||||||
|
this.checking = true;
|
||||||
|
this.remoteAccess.networkCheck().subscribe({
|
||||||
|
next: r => { this.checking = false; this.network = r; },
|
||||||
|
error: () => { this.checking = false; this.network = null; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Windows affiche sa confirmation administrateur : la requête attend la réponse. */
|
||||||
|
allowFirewall(): void {
|
||||||
|
if (this.fixing) return;
|
||||||
|
this.fixing = true;
|
||||||
|
this.fixMessage = null;
|
||||||
|
this.remoteAccess.allowThroughFirewall().subscribe({
|
||||||
|
next: res => {
|
||||||
|
this.fixing = false;
|
||||||
|
this.network = res.readiness;
|
||||||
|
this.fixMessage = this.translate.instant(`remoteAccess.network.fix.${res.outcome}`);
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
this.fixing = false;
|
||||||
|
this.fixMessage = this.translate.instant('remoteAccess.network.fix.FAILED');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openNetworkSettings(): void {
|
||||||
|
this.remoteAccess.openNetworkSettings().subscribe({ error: () => undefined });
|
||||||
|
}
|
||||||
|
|
||||||
|
get firewallNeedsFix(): boolean {
|
||||||
|
return !!this.network && (!this.network.firewallAllowed || this.network.firewallBlocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Le QR code ouvre directement l'écran d'appairage avec le code pré-rempli. */
|
||||||
|
private async renderQr(code: string): Promise<void> {
|
||||||
|
this.qrDataUrl = null;
|
||||||
|
if (!this.primaryUrl) return;
|
||||||
|
try {
|
||||||
|
this.qrDataUrl = await QRCode.toDataURL(`${this.primaryUrl}/pair?code=${code}`,
|
||||||
|
{ margin: 1, width: 220, color: { dark: '#111827', light: '#ffffff' } });
|
||||||
|
} catch {
|
||||||
|
this.qrDataUrl = null; // le code et l'adresse restent affichés
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private startCountdown(): void {
|
||||||
|
this.stopCountdown();
|
||||||
|
const tick = () => {
|
||||||
|
const left = this.pairing ? Math.max(0, Math.round((Date.parse(this.pairing.expiresAt) - Date.now()) / 1000)) : 0;
|
||||||
|
this.secondsLeft = left;
|
||||||
|
if (left === 0) {
|
||||||
|
this.clearPairing();
|
||||||
|
this.refresh(); // l'appareil vient peut-être de s'appairer
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tick();
|
||||||
|
this.countdown = setInterval(tick, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private stopCountdown(): void {
|
||||||
|
if (this.countdown) clearInterval(this.countdown);
|
||||||
|
this.countdown = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
private clearPairing(): void {
|
||||||
|
this.stopCountdown();
|
||||||
|
this.pairing = null;
|
||||||
|
this.qrDataUrl = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get countdownLabel(): string {
|
||||||
|
const m = Math.floor(this.secondsLeft / 60);
|
||||||
|
const s = String(this.secondsLeft % 60).padStart(2, '0');
|
||||||
|
return `${m}:${s}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user