dashboard_local.html 17 KB

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