dashboard_local.html 16 KB

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