dashboard_local.html 17 KB

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