dashboard_local.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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">Transfert</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">
  76. {% if job.destination %}
  77. <span class="bg-violet-50 text-violet-700 text-xs px-2 py-0.5 rounded font-medium">{{ job.destination.name }}</span>
  78. {% else %}
  79. <span class="bg-gray-100 text-gray-500 text-xs px-2 py-0.5 rounded">Local</span>
  80. {% endif %}
  81. </td>
  82. <td class="px-6 py-4 text-xs text-gray-500">
  83. {% if run and run.started_at %}
  84. {{ run.started_at.strftime('%d/%m/%Y %H:%M') }}
  85. {% else %}
  86. <span class="text-gray-300">Jamais</span>
  87. {% endif %}
  88. </td>
  89. <td class="px-6 py-4">
  90. {% if run %}
  91. {% if run.status == 'success' %}
  92. <span class="bg-green-100 text-green-700 text-xs font-medium px-2 py-0.5 rounded-full">✓ succès</span>
  93. {% elif run.status == 'error' %}
  94. <span class="bg-red-100 text-red-700 text-xs font-medium px-2 py-0.5 rounded-full">✗ erreur</span>
  95. {% elif run.status == 'running' %}
  96. <span class="bg-blue-100 text-blue-700 text-xs font-medium px-2 py-0.5 rounded-full animate-pulse">⟳ en cours</span>
  97. {% endif %}
  98. {% else %}
  99. <span class="text-gray-300 text-xs">—</span>
  100. {% endif %}
  101. </td>
  102. <td class="px-6 py-4 text-xs text-gray-500">
  103. {% if run and run.size_bytes %}{{ run.size_human }}{% else %}—{% endif %}
  104. </td>
  105. <td class="px-6 py-4 text-right">
  106. <div class="flex items-center justify-end gap-2">
  107. <form method="post" action="{{ url_for('jobs.job_run_now', job_id=job.id) }}"
  108. onsubmit="return confirm('Lancer « {{ job.name }} » maintenant ?')">
  109. <button type="submit" class="btn-primary btn-sm">▶ Lancer</button>
  110. </form>
  111. <a href="{{ url_for('jobs.job_history', job_id=job.id) }}"
  112. class="btn-secondary btn-sm">Historique</a>
  113. <a href="{{ url_for('jobs.job_edit', job_id=job.id) }}"
  114. class="btn-secondary btn-sm">Éditer</a>
  115. <form method="post" action="{{ url_for('jobs.job_toggle', job_id=job.id) }}">
  116. <button type="submit" class="btn-ghost btn-icon-sm"
  117. title="{{ 'Désactiver' if job.enabled else 'Activer' }}">
  118. {{ '⏸' if job.enabled else '▶' }}
  119. </button>
  120. </form>
  121. <form method="post" action="{{ url_for('jobs.job_delete', job_id=job.id) }}"
  122. onsubmit="return confirm('Supprimer définitivement « {{ job.name }} » et son historique ?')">
  123. <button type="submit" class="btn-danger btn-icon-sm">✕</button>
  124. </form>
  125. </div>
  126. </td>
  127. </tr>
  128. {% endfor %}
  129. </tbody>
  130. </table>
  131. </div>
  132. {% endif %}
  133. </div>
  134. {# ── Serveurs fédérés ─────────────────────────────────────────────── #}
  135. {% if instances %}
  136. <div class="mt-8">
  137. <div class="flex items-center justify-between mb-4">
  138. <h2 class="text-base font-semibold text-gray-700">Serveurs fédérés</h2>
  139. <form method="post" action="{{ url_for('network.network_sync_all') }}">
  140. <button type="submit" class="btn-secondary btn-sm">Synchroniser tout</button>
  141. </form>
  142. </div>
  143. {% for inst in instances %}
  144. {% set sc = {'online':'bg-green-100 text-green-700','error':'bg-red-100 text-red-700','offline':'bg-gray-100 text-gray-500'} %}
  145. <div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden mb-4">
  146. <div class="px-6 py-3 border-b border-gray-100 flex items-center justify-between gap-4">
  147. <div class="flex items-center gap-3">
  148. <span class="font-semibold text-gray-800 text-sm">{{ inst.name }}</span>
  149. <span class="text-xs px-2 py-0.5 rounded-full font-medium {{ sc.get(inst.status, 'bg-gray-100 text-gray-400') }}">
  150. {{ inst.status or 'unknown' }}
  151. </span>
  152. {% if inst.last_seen %}
  153. <span class="text-xs text-gray-400 hidden sm:inline">sync {{ inst.last_seen.strftime('%d/%m %H:%M') }}</span>
  154. {% endif %}
  155. <span class="text-xs font-mono text-gray-400 truncate hidden md:inline">{{ inst.url_display }}</span>
  156. </div>
  157. <div class="flex gap-2 shrink-0">
  158. <form method="post" action="{{ url_for('network.remote_instance_sync', inst_id=inst.id) }}">
  159. <button type="submit" class="btn-secondary btn-sm">Sync</button>
  160. </form>
  161. </div>
  162. </div>
  163. {% if not inst.remote_runs %}
  164. <div class="px-6 py-5 text-center text-gray-400 text-sm">
  165. Aucune donnée — cliquez sur "Sync" pour récupérer l'état.
  166. </div>
  167. {% else %}
  168. <div class="overflow-x-auto">
  169. <table class="w-full text-sm">
  170. <tbody class="divide-y divide-gray-100">
  171. {% for row in inst.remote_runs %}
  172. <tr class="hover:bg-gray-50">
  173. <td class="px-6 py-3 font-medium text-gray-900">{{ row.job_name }}</td>
  174. <td class="px-6 py-3">
  175. <span class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded font-mono">{{ row.job_type }}</span>
  176. </td>
  177. <td class="px-6 py-3 text-xs text-gray-500">
  178. {% if row.last_run_at %}{{ row.last_run_at.strftime('%d/%m/%Y %H:%M') }}
  179. {% else %}<span class="text-gray-300">Jamais</span>{% endif %}
  180. </td>
  181. <td class="px-6 py-3">
  182. {% if row.last_status == 'success' %}
  183. <span class="bg-green-100 text-green-700 text-xs font-medium px-2 py-0.5 rounded-full">✓ succès</span>
  184. {% elif row.last_status == 'error' %}
  185. <span class="bg-red-100 text-red-700 text-xs font-medium px-2 py-0.5 rounded-full">✗ erreur</span>
  186. {% elif row.last_status == 'running' %}
  187. <span class="bg-blue-100 text-blue-700 text-xs font-medium px-2 py-0.5 rounded-full animate-pulse">⟳ en cours</span>
  188. {% else %}
  189. <span class="text-gray-300 text-xs">—</span>
  190. {% endif %}
  191. </td>
  192. <td class="px-6 py-3 text-xs text-gray-500">
  193. {% if row.last_size_bytes %}{{ row.last_size_human }}{% else %}—{% endif %}
  194. </td>
  195. <td class="px-6 py-3 text-right">
  196. <div class="flex items-center justify-end gap-2">
  197. {% if row.job_id %}
  198. <form method="post"
  199. action="{{ url_for('network.remote_job_run', inst_id=inst.id, job_id=row.job_id) }}"
  200. onsubmit="return confirm('Lancer « {{ row.job_name }} » sur {{ inst.name }} ?')">
  201. <button type="submit" class="btn-primary btn-sm">▶ Lancer</button>
  202. </form>
  203. <form method="post"
  204. action="{{ url_for('network.archive_pull_latest', inst_id=inst.id, remote_job_id=row.job_id) }}"
  205. onsubmit="return confirm('Rapatrier la dernière archive de « {{ row.job_name }} » ?')">
  206. <button type="submit" class="btn-ghost btn-sm">← Rapatrier</button>
  207. </form>
  208. {% endif %}
  209. </div>
  210. </td>
  211. </tr>
  212. {% endfor %}
  213. </tbody>
  214. </table>
  215. </div>
  216. {% endif %}
  217. </div>
  218. {% endfor %}
  219. </div>
  220. {% endif %}
  221. {% endblock %}