dashboard_local.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {% extends "base.html" %}
  2. {% block title %}Dashboard{% endblock %}
  3. {% block content %}
  4. {# ── Statistiques rapides ─────────────────────────────────────────────────── #}
  5. {% set total = jobs | length %}
  6. {% set enabled_count = jobs | selectattr('enabled') | list | length %}
  7. {% set recent_runs = last_runs.values() | select | list %}
  8. {% set success_count = recent_runs | selectattr('status', 'equalto', 'success') | list | length %}
  9. {% set error_count = recent_runs | selectattr('status', 'equalto', 'error') | list | length %}
  10. {% set running_count = recent_runs | selectattr('status', 'equalto', 'running') | list | length %}
  11. <div class="grid grid-cols-2 sm:grid-cols-4 gap-4 mb-8">
  12. <div class="bg-white rounded-xl border border-gray-200 px-5 py-4">
  13. <p class="text-xs text-gray-500 uppercase tracking-wide">Jobs</p>
  14. <p class="text-3xl font-bold text-gray-800 mt-1">{{ total }}</p>
  15. <p class="text-xs text-gray-400 mt-1">{{ enabled_count }} actifs</p>
  16. </div>
  17. <div class="bg-white rounded-xl border border-gray-200 px-5 py-4">
  18. <p class="text-xs text-gray-500 uppercase tracking-wide">Succès</p>
  19. <p class="text-3xl font-bold text-green-600 mt-1">{{ success_count }}</p>
  20. <p class="text-xs text-gray-400 mt-1">dernière exécution</p>
  21. </div>
  22. <div class="bg-white rounded-xl border border-gray-200 px-5 py-4">
  23. <p class="text-xs text-gray-500 uppercase tracking-wide">Erreurs</p>
  24. <p class="text-3xl font-bold {% if error_count > 0 %}text-red-600{% else %}text-gray-400{% endif %} mt-1">
  25. {{ error_count }}
  26. </p>
  27. <p class="text-xs text-gray-400 mt-1">dernière exécution</p>
  28. </div>
  29. <div class="bg-white rounded-xl border border-gray-200 px-5 py-4">
  30. <p class="text-xs text-gray-500 uppercase tracking-wide">En cours</p>
  31. <p class="text-3xl font-bold {% if running_count > 0 %}text-blue-600{% else %}text-gray-400{% endif %} mt-1">
  32. {{ running_count }}
  33. </p>
  34. <p class="text-xs text-gray-400 mt-1">actuellement</p>
  35. </div>
  36. </div>
  37. {# ── Table des jobs ───────────────────────────────────────────────────────── #}
  38. <div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
  39. <div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between">
  40. <h2 class="text-base font-semibold text-gray-800">Jobs de sauvegarde</h2>
  41. </div>
  42. {% if not jobs %}
  43. <div class="px-6 py-12 text-center text-gray-400">
  44. <p class="text-lg">Aucun job configuré.</p>
  45. <a href="{{ url_for('jobs.job_new') }}" class="mt-3 inline-block text-blue-600 hover:underline text-sm">
  46. Créer le premier job →
  47. </a>
  48. </div>
  49. {% else %}
  50. <div class="overflow-x-auto">
  51. <table class="w-full text-sm">
  52. <thead>
  53. <tr class="text-xs text-gray-500 uppercase tracking-wide bg-gray-50">
  54. <th class="px-6 py-3 text-left font-medium">Nom</th>
  55. <th class="px-6 py-3 text-left font-medium">Type</th>
  56. <th class="px-6 py-3 text-left font-medium">Planification</th>
  57. <th class="px-6 py-3 text-left font-medium">Prochaine exéc.</th>
  58. <th class="px-6 py-3 text-left font-medium">Dernière exéc.</th>
  59. <th class="px-6 py-3 text-left font-medium">Statut</th>
  60. <th class="px-6 py-3 text-left font-medium">Taille</th>
  61. <th class="px-6 py-3 text-right font-medium">Actions</th>
  62. </tr>
  63. </thead>
  64. <tbody class="divide-y divide-gray-100">
  65. {% for job in jobs %}
  66. {% set run = last_runs.get(job.id) %}
  67. <tr class="hover:bg-gray-50 {% if not job.enabled %}opacity-50{% endif %}">
  68. <td class="px-6 py-4 font-medium text-gray-900">{{ job.name }}</td>
  69. <td class="px-6 py-4">
  70. <span class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded font-mono">
  71. {{ job.type }}
  72. </span>
  73. </td>
  74. <td class="px-6 py-4 font-mono text-xs text-gray-600">{{ job.cron_expr }}</td>
  75. <td class="px-6 py-4 text-xs text-gray-500">
  76. {% set next = job.next_run() %}
  77. {% if next and job.enabled %}
  78. {{ next.strftime('%d/%m %H:%M') }}
  79. {% else %}
  80. <span class="text-gray-300">—</span>
  81. {% endif %}
  82. </td>
  83. <td class="px-6 py-4 text-xs text-gray-500">
  84. {% if run and run.started_at %}
  85. {{ run.started_at.strftime('%d/%m/%Y %H:%M') }}
  86. {% else %}
  87. <span class="text-gray-300">Jamais</span>
  88. {% endif %}
  89. </td>
  90. <td class="px-6 py-4">
  91. {% if run %}
  92. {% if run.status == 'success' %}
  93. <span class="bg-green-100 text-green-700 text-xs font-medium px-2 py-0.5 rounded-full">✓ succès</span>
  94. {% elif run.status == 'error' %}
  95. <span class="bg-red-100 text-red-700 text-xs font-medium px-2 py-0.5 rounded-full">✗ erreur</span>
  96. {% elif run.status == 'running' %}
  97. <span class="bg-blue-100 text-blue-700 text-xs font-medium px-2 py-0.5 rounded-full animate-pulse">⟳ en cours</span>
  98. {% endif %}
  99. {% else %}
  100. <span class="text-gray-300 text-xs">—</span>
  101. {% endif %}
  102. </td>
  103. <td class="px-6 py-4 text-xs text-gray-500">
  104. {% if run and run.size_bytes %}{{ run.size_human }}{% else %}—{% endif %}
  105. </td>
  106. <td class="px-6 py-4 text-right">
  107. <div class="flex items-center justify-end gap-2">
  108. <form method="post" action="{{ url_for('jobs.job_run_now', job_id=job.id) }}"
  109. onsubmit="return confirm('Lancer « {{ job.name }} » maintenant ?')">
  110. <button type="submit"
  111. class="bg-blue-50 hover:bg-blue-100 text-blue-700 text-xs font-medium px-2.5 py-1 rounded transition">
  112. ▶ Lancer
  113. </button>
  114. </form>
  115. <a href="{{ url_for('jobs.job_history', job_id=job.id) }}"
  116. class="text-gray-400 hover:text-gray-700 text-xs px-2 py-1 rounded hover:bg-gray-100 transition">
  117. Historique
  118. </a>
  119. <a href="{{ url_for('jobs.job_edit', job_id=job.id) }}"
  120. class="text-gray-400 hover:text-gray-700 text-xs px-2 py-1 rounded hover:bg-gray-100 transition">
  121. Éditer
  122. </a>
  123. <form method="post" action="{{ url_for('jobs.job_toggle', job_id=job.id) }}">
  124. <button type="submit"
  125. class="text-gray-400 hover:text-gray-700 text-xs px-2 py-1 rounded hover:bg-gray-100 transition"
  126. title="{{ 'Désactiver' if job.enabled else 'Activer' }}">
  127. {{ '⏸' if job.enabled else '▶' }}
  128. </button>
  129. </form>
  130. <form method="post" action="{{ url_for('jobs.job_delete', job_id=job.id) }}"
  131. onsubmit="return confirm('Supprimer définitivement « {{ job.name }} » et son historique ?')">
  132. <button type="submit"
  133. class="text-red-300 hover:text-red-600 text-xs px-2 py-1 rounded hover:bg-red-50 transition">
  134. </button>
  135. </form>
  136. </div>
  137. </td>
  138. </tr>
  139. {% endfor %}
  140. </tbody>
  141. </table>
  142. </div>
  143. {% endif %}
  144. </div>
  145. {% endblock %}