| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * Partial: carte d'un projet
- * Variables attendues dans le scope :
- * - $map : tableau associatif représentant la carte
- */
- ?>
- <div class="col-lg-4 col-md-6">
- <div class="card h-100 map-card" data-map-id="<?php echo $map['id']; ?>">
- <div class="card-body d-flex flex-column">
- <!-- En-tête de la carte -->
- <div class="d-flex align-items-start justify-content-between mb-3">
- <div class="flex-grow-1">
- <h6 class="card-title mb-1">
- <?php echo htmlspecialchars($map['name']); ?>
- <small class="text-muted fw-normal">(ID: <?php echo $map['id']; ?>)</small>
- </h6>
- <small class="text-muted">
- <i class="bi bi-calendar me-1"></i>
- <?php echo date('d/m/Y H:i', strtotime($map['created_at'])); ?>
- </small>
- </div>
- <div class="dropdown">
- <button class="btn btn-sm btn-outline-secondary" type="button" id="dropdownMap<?php echo $map['id']; ?>" data-bs-toggle="dropdown" aria-expanded="false">
- <i class="bi bi-three-dots-vertical"></i>
- </button>
- <ul class="dropdown-menu" aria-labelledby="dropdownMap<?php echo $map['id']; ?>">
- <li>
- <a class="dropdown-item" href="/projects/<?php echo $map['id']; ?>/edit">
- <i class="bi bi-pencil me-2"></i>Modifier
- </a>
- </li>
- <li>
- <a class="dropdown-item" href="#" onclick="duplicateMap(<?php echo $map['id']; ?>)">
- <i class="bi bi-copy me-2"></i>Dupliquer
- </a>
- </li>
- <li><hr class="dropdown-divider"></li>
- <li>
- <!-- Bouton suppression (JS) + fallback form POST pour progressive enhancement -->
- <a class="dropdown-item text-danger" href="#" onclick="deleteMap(<?php echo $map['id']; ?>, <?php echo json_encode($map['name']); ?>)">
- <i class="bi bi-trash me-2"></i>Supprimer
- </a>
- </li>
- </ul>
- </div>
- </div>
- <!-- Informations de la carte -->
- <div class="mb-3">
- <div class="row text-center">
- <div class="col-6">
- <small class="text-muted d-block">Dimensions</small>
- <strong><?php echo $map['width']; ?> × <?php echo $map['height']; ?></strong>
- </div>
- <div class="col-6">
- <small class="text-muted d-block">Taille</small>
- <strong><?php echo number_format($map['width'] * $map['height']); ?> cases</strong>
- </div>
- </div>
- </div>
- <!-- Aperçu des tuiles du template (si disponible dans les métadonnées) -->
- <?php
- $templateId = null;
- if (!empty($map['data'])) {
- $raw = is_string($map['data']) ? json_decode($map['data'], true) : $map['data'];
- if (is_array($raw)) {
- // chercher un champ template à la racine
- if (!empty($raw['template'])) $templateId = $raw['template'];
- // ou dans statistics
- if (!$templateId && !empty($raw['statistics']['template'])) $templateId = $raw['statistics']['template'];
- }
- }
- if ($templateId) {
- require_once __DIR__ . '/../Models/Templates/TemplateFactory.php';
- $available = TemplateFactory::listAvailable();
- if (!empty($available[$templateId]['class'])) {
- $class = $available[$templateId]['class'];
- try {
- $defs = method_exists($class, 'tileDefinitions') ? $class::tileDefinitions() : [];
- } catch (Throwable $e) {
- $defs = [];
- }
- if (!empty($defs)) {
- echo '<div class="mb-3">';
- echo '<small class="text-muted d-block">Tuiles (' . htmlspecialchars($available[$templateId]['name']) . ')</small>';
- echo '<div class="d-flex gap-2 flex-wrap mt-2">';
- foreach ($defs as $td) {
- $color = htmlspecialchars($td['color'] ?? '#ccc');
- $name = htmlspecialchars($td['name'] ?? $td['id'] ?? '');
- echo '<div style="min-width:60px;text-align:center;">';
- echo '<div style="width:28px;height:20px;margin:0 auto;border:1px solid rgba(0,0,0,0.08);background:' . $color . ';border-radius:3px"></div>';
- echo '<div style="font-size:0.8rem;color:#333">' . $name . '</div>';
- echo '</div>';
- }
- echo '</div></div>';
- }
- }
- }
- ?>
- <!-- Description -->
- <?php if (!empty($map['description'])): ?>
- <p class="card-text small text-muted mb-3">
- <?php echo htmlspecialchars(substr($map['description'], 0, 100)); ?>
- <?php if (strlen($map['description']) > 100): ?>...<?php endif; ?>
- </p>
- <?php endif; ?>
- <!-- Actions principales -->
- <div class="mt-auto">
- <div class="mb-2">
- <a class="btn btn-outline-primary btn-sm w-100" href="/?load=<?php echo $map['id']; ?>">
- <i class="bi bi-folder-open me-1"></i>Ouvrir ce projet
- </a>
- </div>
- <!-- Actions secondaires déplacées dans le dropdown - ne rien afficher ici -->
- <div style="height:0; visibility:hidden;" aria-hidden="true"></div>
- </div>
- <!-- Fallback form pour suppression si JS désactivé -->
- <form method="POST" action="/projects/delete" class="d-none" id="delete-form-<?php echo $map['id']; ?>">
- <input type="hidden" name="id" value="<?php echo $map['id']; ?>">
- <noscript>
- <button type="submit" class="btn btn-danger btn-sm mt-2">Supprimer (JS désactivé)</button>
- </noscript>
- </form>
- </div>
- </div>
- </div>
|