dashboard_local.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. <!-- Barre actions groupées (masquée par défaut) -->
  43. <div id="bulk-bar" class="hidden bg-blue-50 border-b border-blue-200 px-6 py-2 flex items-center gap-3 text-sm">
  44. <span class="text-blue-700 font-medium"><span id="bulk-count">0</span> sélectionné(s)</span>
  45. <button type="button" onclick="bulkAction('run')" class="btn-primary btn-sm">▶ Lancer</button>
  46. <button type="button" onclick="bulkAction('enable')" class="btn-secondary btn-sm">Activer</button>
  47. <button type="button" onclick="bulkAction('disable')" class="btn-secondary btn-sm">Désactiver</button>
  48. <button type="button" onclick="bulkAction('delete', 'Supprimer les jobs sélectionnés et leur historique ?')" class="btn-danger btn-sm">✕ Supprimer</button>
  49. </div>
  50. {% if not jobs %}
  51. <div class="px-6 py-12 text-center text-gray-400">
  52. <p class="text-lg">Aucun job configuré.</p>
  53. <a href="{{ url_for('jobs.job_new') }}" class="mt-3 inline-block text-blue-600 hover:underline text-sm">
  54. Créer le premier job →
  55. </a>
  56. </div>
  57. {% else %}
  58. <div class="overflow-x-auto">
  59. <table class="w-full text-sm">
  60. <thead>
  61. <tr class="text-xs text-gray-500 uppercase tracking-wide bg-gray-50">
  62. <th class="px-4 py-3 w-8">
  63. <input type="checkbox" id="select-all" class="rounded border-gray-300 text-blue-600">
  64. </th>
  65. <th class="px-6 py-3 text-left font-medium">Nom</th>
  66. <th class="px-6 py-3 text-left font-medium">Type</th>
  67. <th class="px-6 py-3 text-left font-medium">Planification</th>
  68. <th class="px-6 py-3 text-left font-medium">Transfert</th>
  69. <th class="px-6 py-3 text-left font-medium">Dernière exéc.</th>
  70. <th class="px-6 py-3 text-left font-medium">Statut</th>
  71. <th class="px-6 py-3 text-left font-medium">Taille</th>
  72. <th class="px-6 py-3 text-right font-medium">Actions</th>
  73. </tr>
  74. </thead>
  75. <tbody class="divide-y divide-gray-100">
  76. {% for job in jobs %}
  77. {% set run = last_runs.get(job.id) %}
  78. <tr class="hover:bg-gray-50 {% if not job.enabled %}opacity-50{% endif %}">
  79. <td class="px-4 py-4">
  80. <input type="checkbox" class="job-checkbox rounded border-gray-300 text-blue-600" value="{{ job.id }}">
  81. </td>
  82. <td class="px-6 py-4 font-medium text-gray-900">{{ job.name }}</td>
  83. <td class="px-6 py-4">
  84. <span class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded font-mono">
  85. {{ job.type }}
  86. </span>
  87. </td>
  88. <td class="px-6 py-4 font-mono text-xs text-gray-600">
  89. {% if job.cron_expr %}{{ job.cron_expr }}
  90. {% else %}<span class="bg-gray-100 text-gray-500 text-xs px-2 py-0.5 rounded font-sans">Manuel</span>{% endif %}
  91. </td>
  92. <td class="px-6 py-4">
  93. {% if job.job_destinations %}
  94. <div class="flex flex-wrap gap-1">
  95. {% for jd in job.job_destinations %}
  96. {% set obj = jd.resolved %}{% if obj %}
  97. {% if jd.dest_type == 'ssh' %}
  98. <span class="bg-violet-50 text-violet-700 text-xs px-2 py-0.5 rounded font-medium" title="{{ obj.remote_str }}">SSH · {{ obj.name }}</span>
  99. {% else %}
  100. <span class="bg-blue-50 text-blue-700 text-xs px-2 py-0.5 rounded font-medium" title="{{ obj.url }}">HTTP · {{ obj.name }}</span>
  101. {% endif %}
  102. {% endif %}
  103. {% endfor %}
  104. </div>
  105. {% else %}
  106. <span class="bg-gray-100 text-gray-500 text-xs px-2 py-0.5 rounded">Local</span>
  107. {% endif %}
  108. </td>
  109. <td class="px-6 py-4 text-xs text-gray-500">
  110. {% if run and run.started_at %}
  111. {{ run.started_at.strftime('%d/%m/%Y %H:%M') }}
  112. {% else %}
  113. <span class="text-gray-300">Jamais</span>
  114. {% endif %}
  115. </td>
  116. <td class="px-6 py-4">
  117. {% if run %}
  118. {% if run.status == 'success' %}
  119. <span class="bg-green-100 text-green-700 text-xs font-medium px-2 py-0.5 rounded-full">✓ succès</span>
  120. {% elif run.status == 'error' %}
  121. <span class="bg-red-100 text-red-700 text-xs font-medium px-2 py-0.5 rounded-full">✗ erreur</span>
  122. {% elif run.status == 'running' %}
  123. <span class="bg-blue-100 text-blue-700 text-xs font-medium px-2 py-0.5 rounded-full animate-pulse">⟳ en cours</span>
  124. {% endif %}
  125. {% else %}
  126. <span class="text-gray-300 text-xs">—</span>
  127. {% endif %}
  128. </td>
  129. <td class="px-6 py-4 text-xs text-gray-500">
  130. {% if run and run.size_bytes %}{{ run.size_human }}{% else %}—{% endif %}
  131. </td>
  132. <td class="px-6 py-4 text-right">
  133. <div class="flex items-center justify-end gap-2">
  134. <form method="post" action="{{ url_for('jobs.job_run_now', job_id=job.id) }}"
  135. onsubmit="return confirm('Lancer « {{ job.name }} » maintenant ?')">
  136. <button type="submit" class="btn-primary btn-sm">▶</button>
  137. </form>
  138. <a href="{{ url_for('jobs.job_history', job_id=job.id) }}"
  139. class="btn-secondary btn-sm">Historique</a>
  140. <a href="{{ url_for('jobs.job_edit', job_id=job.id) }}"
  141. class="btn-secondary btn-sm">Éditer</a>
  142. <form method="post" action="{{ url_for('jobs.job_toggle', job_id=job.id) }}">
  143. <button type="submit" class="btn-ghost btn-icon-sm"
  144. title="{{ 'Désactiver' if job.enabled else 'Activer' }}">
  145. {{ '⏸' if job.enabled else '▶' }}
  146. </button>
  147. </form>
  148. <form method="post" action="{{ url_for('jobs.job_delete', job_id=job.id) }}"
  149. onsubmit="return confirm('Supprimer définitivement « {{ job.name }} » et son historique ?')">
  150. <button type="submit" class="btn-danger btn-icon-sm">✕</button>
  151. </form>
  152. </div>
  153. </td>
  154. </tr>
  155. {% endfor %}
  156. </tbody>
  157. </table>
  158. </div>
  159. {% endif %}
  160. </div>
  161. {# ── Serveurs fédérés ─────────────────────────────────────────────── #}
  162. {% if instances %}
  163. <div class="mt-8">
  164. <div class="flex items-center justify-between mb-4">
  165. <h2 class="text-base font-semibold text-gray-700">Serveurs fédérés</h2>
  166. <form method="post" action="{{ url_for('network.network_sync_all') }}">
  167. <button type="submit" class="btn-secondary btn-sm">Synchroniser tout</button>
  168. </form>
  169. </div>
  170. {% for inst in instances %}
  171. {% set sc = {'online':'bg-green-100 text-green-700','error':'bg-red-100 text-red-700','offline':'bg-gray-100 text-gray-500'} %}
  172. <div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden mb-4">
  173. <div class="px-6 py-3 border-b border-gray-100 flex items-center justify-between gap-4">
  174. <div class="flex items-center gap-3">
  175. <span class="font-semibold text-gray-800 text-sm">{{ inst.name }}</span>
  176. <span class="text-xs px-2 py-0.5 rounded-full font-medium {{ sc.get(inst.status, 'bg-gray-100 text-gray-400') }}">
  177. {{ inst.status or 'unknown' }}
  178. </span>
  179. {% if inst.last_seen %}
  180. <span class="text-xs text-gray-400 hidden sm:inline">sync {{ inst.last_seen.strftime('%d/%m %H:%M') }}</span>
  181. {% endif %}
  182. <span class="text-xs font-mono text-gray-400 truncate hidden md:inline">{{ inst.url_display }}</span>
  183. </div>
  184. <div class="flex gap-2 shrink-0">
  185. <form method="post" action="{{ url_for('network.remote_instance_sync', inst_id=inst.id) }}">
  186. <button type="submit" class="btn-secondary btn-sm">Sync</button>
  187. </form>
  188. </div>
  189. </div>
  190. {% if not inst.remote_runs %}
  191. <div class="px-6 py-5 text-center text-gray-400 text-sm">
  192. Aucune donnée — cliquez sur "Sync" pour récupérer l'état.
  193. </div>
  194. {% else %}
  195. <div class="overflow-x-auto">
  196. <table class="w-full text-sm">
  197. <thead>
  198. <tr class="text-xs text-gray-500 uppercase tracking-wide bg-gray-50">
  199. <th class="px-6 py-3 text-left font-medium">Nom</th>
  200. <th class="px-6 py-3 text-left font-medium">Type</th>
  201. <th class="px-6 py-3 text-left font-medium">Dernière exéc.</th>
  202. <th class="px-6 py-3 text-left font-medium">Statut</th>
  203. <th class="px-6 py-3 text-left font-medium">Taille</th>
  204. <th class="px-6 py-3 text-right font-medium">Actions</th>
  205. </tr>
  206. </thead>
  207. <tbody class="divide-y divide-gray-100">
  208. {% for row in inst.remote_runs %}
  209. <tr class="hover:bg-gray-50">
  210. <td class="px-6 py-3 font-medium text-gray-900">{{ row.job_name }}</td>
  211. <td class="px-6 py-3">
  212. <span class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded font-mono">{{ row.job_type }}</span>
  213. </td>
  214. <td class="px-6 py-3 text-xs text-gray-500">
  215. {% if row.last_run_at %}{{ row.last_run_at.strftime('%d/%m/%Y %H:%M') }}
  216. {% else %}<span class="text-gray-300">Jamais</span>{% endif %}
  217. </td>
  218. <td class="px-6 py-3">
  219. {% if row.last_status == 'success' %}
  220. <span class="bg-green-100 text-green-700 text-xs font-medium px-2 py-0.5 rounded-full">✓ succès</span>
  221. {% elif row.last_status == 'error' %}
  222. <span class="bg-red-100 text-red-700 text-xs font-medium px-2 py-0.5 rounded-full">✗ erreur</span>
  223. {% elif row.last_status == 'running' %}
  224. <span class="bg-blue-100 text-blue-700 text-xs font-medium px-2 py-0.5 rounded-full animate-pulse">⟳ en cours</span>
  225. {% else %}
  226. <span class="text-gray-300 text-xs">—</span>
  227. {% endif %}
  228. </td>
  229. <td class="px-6 py-3 text-xs text-gray-500">
  230. {% if row.last_size_bytes %}{{ row.last_size_human }}{% else %}—{% endif %}
  231. </td>
  232. <td class="px-6 py-3 text-right">
  233. <div class="flex items-center justify-end gap-2">
  234. {% if row.job_id %}
  235. <form method="post"
  236. action="{{ url_for('network.remote_job_run', inst_id=inst.id, job_id=row.job_id) }}"
  237. onsubmit="return confirm('Lancer « {{ row.job_name }} » sur {{ inst.name }} ?')">
  238. <button type="submit" class="btn-primary btn-sm">▶ Lancer</button>
  239. </form>
  240. <form method="post"
  241. action="{{ url_for('network.archive_pull_latest', inst_id=inst.id, remote_job_id=row.job_id) }}"
  242. onsubmit="return confirm('Rapatrier la dernière archive de « {{ row.job_name }} » ?')">
  243. <button type="submit" class="btn-ghost btn-sm">← Rapatrier</button>
  244. </form>
  245. {% endif %}
  246. </div>
  247. </td>
  248. </tr>
  249. {% endfor %}
  250. </tbody>
  251. </table>
  252. </div>
  253. {% endif %}
  254. </div>
  255. {% endfor %}
  256. </div>
  257. {% endif %}
  258. {% endblock %}
  259. {% block scripts %}
  260. <script>
  261. (function() {
  262. const selectAll = document.getElementById('select-all');
  263. const checkboxes = () => [...document.querySelectorAll('.job-checkbox')];
  264. const bulkBar = document.getElementById('bulk-bar');
  265. const bulkCount = document.getElementById('bulk-count');
  266. function updateBar() {
  267. const checked = checkboxes().filter(c => c.checked);
  268. bulkCount.textContent = checked.length;
  269. if (checked.length > 0) bulkBar.classList.remove('hidden');
  270. else bulkBar.classList.add('hidden');
  271. }
  272. if (selectAll) {
  273. selectAll.addEventListener('change', function() {
  274. checkboxes().forEach(c => c.checked = this.checked);
  275. updateBar();
  276. });
  277. }
  278. document.addEventListener('change', function(e) {
  279. if (!e.target.classList.contains('job-checkbox')) return;
  280. const all = checkboxes();
  281. if (selectAll) {
  282. selectAll.checked = all.every(c => c.checked);
  283. selectAll.indeterminate = all.some(c => c.checked) && !all.every(c => c.checked);
  284. }
  285. updateBar();
  286. });
  287. window.bulkAction = function(action, confirmMsg) {
  288. const checked = checkboxes().filter(c => c.checked);
  289. if (!checked.length) return;
  290. if (confirmMsg && !confirm(confirmMsg)) return;
  291. const form = document.createElement('form');
  292. form.method = 'POST';
  293. form.action = '{{ url_for("jobs.jobs_bulk") }}';
  294. const ai = document.createElement('input');
  295. ai.type = 'hidden'; ai.name = 'action'; ai.value = action;
  296. form.appendChild(ai);
  297. checked.forEach(c => {
  298. const inp = document.createElement('input');
  299. inp.type = 'hidden'; inp.name = 'job_ids'; inp.value = c.value;
  300. form.appendChild(inp);
  301. });
  302. document.body.appendChild(form);
  303. form.submit();
  304. };
  305. })();
  306. </script>
  307. {% endblock %}