federation.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. {% extends "base.html" %}
  2. {% block title %}Fédération{% endblock %}
  3. {% block content %}
  4. <div class="flex items-center justify-between mb-6">
  5. <h1 class="text-xl font-bold text-gray-900">Fédération</h1>
  6. <div class="flex gap-2">
  7. <a href="{{ url_for('network.remote_instance_new') }}" class="btn-secondary btn-sm">+ Ajouter une instance</a>
  8. <form method="post" action="{{ url_for('network.network_sync_all') }}">
  9. <button type="submit" class="btn-primary btn-sm">Synchroniser tout</button>
  10. </form>
  11. </div>
  12. </div>
  13. {# ── Onglets ─────────────────────────────────────────────────────── #}
  14. <div class="flex border-b border-gray-200 mb-6 gap-1">
  15. <button id="tab-btn-reseau" onclick="setTab('reseau')"
  16. class="tab-btn px-4 py-2 text-sm font-medium border-b-2 border-blue-600 text-blue-600 -mb-px">
  17. Vue réseau
  18. </button>
  19. <button id="tab-btn-instances" onclick="setTab('instances')"
  20. class="tab-btn px-4 py-2 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 -mb-px">
  21. Instances ({{ instances | length }})
  22. </button>
  23. </div>
  24. {# ══════════════════ PANNEAU : VUE RÉSEAU ══════════════════════════ #}
  25. <div id="pane-reseau">
  26. {% macro instance_section(inst_name, inst_url, jobs_data, inst_id=None, inst_status=None, last_seen=None) %}
  27. <div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden mb-6">
  28. <div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between gap-4">
  29. <div class="flex items-center gap-3 min-w-0">
  30. <h2 class="text-base font-semibold text-gray-800">{{ inst_name }}</h2>
  31. {% if inst_id %}
  32. {% set sc = {'online':'bg-green-100 text-green-700','error':'bg-red-100 text-red-700','offline':'bg-gray-100 text-gray-500'} %}
  33. <span class="text-xs px-2 py-0.5 rounded-full font-medium {{ sc.get(inst_status, 'bg-gray-100 text-gray-400') }}">
  34. {{ inst_status or 'unknown' }}
  35. </span>
  36. {% if last_seen %}
  37. <span class="text-xs text-gray-400 hidden sm:inline">sync {{ last_seen.strftime('%d/%m %H:%M') }}</span>
  38. {% endif %}
  39. {% else %}
  40. <span class="text-xs bg-blue-100 text-blue-700 px-2 py-0.5 rounded-full font-medium">local</span>
  41. {% endif %}
  42. {% if inst_url %}
  43. <span class="text-xs font-mono text-gray-400 truncate hidden md:inline">{{ inst_url }}</span>
  44. {% endif %}
  45. </div>
  46. {% if inst_id %}
  47. <div class="flex gap-2 shrink-0">
  48. <form method="post" action="{{ url_for('network.remote_instance_sync', inst_id=inst_id) }}">
  49. <button type="submit" class="btn-secondary btn-sm">Sync</button>
  50. </form>
  51. <a href="{{ url_for('network.remote_instance_edit', inst_id=inst_id) }}"
  52. class="btn-secondary btn-sm">Éditer</a>
  53. </div>
  54. {% endif %}
  55. </div>
  56. {% if not jobs_data %}
  57. <div class="px-6 py-8 text-center text-gray-400 text-sm">
  58. {% if inst_id %}
  59. Aucune donnée — cliquez sur "Sync" pour récupérer l'état de cette instance.
  60. {% else %}
  61. Aucun job configuré.
  62. <a href="{{ url_for('jobs.job_new') }}" class="text-blue-600 hover:underline ml-1">Créer un job →</a>
  63. {% endif %}
  64. </div>
  65. {% else %}
  66. <div class="overflow-x-auto">
  67. <table class="w-full text-sm">
  68. <thead>
  69. <tr class="text-xs text-gray-500 uppercase tracking-wide bg-gray-50">
  70. <th class="px-6 py-3 text-left font-medium">Job</th>
  71. <th class="px-6 py-3 text-left font-medium">Type</th>
  72. <th class="px-6 py-3 text-left font-medium">Dernière exéc.</th>
  73. <th class="px-6 py-3 text-left font-medium">Statut</th>
  74. <th class="px-6 py-3 text-left font-medium">Taille</th>
  75. <th class="px-6 py-3 text-right font-medium">Actions</th>
  76. </tr>
  77. </thead>
  78. <tbody class="divide-y divide-gray-100">
  79. {% for row in jobs_data %}
  80. <tr class="hover:bg-gray-50">
  81. <td class="px-6 py-3 font-medium text-gray-900">{{ row.name }}</td>
  82. <td class="px-6 py-3">
  83. <span class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded font-mono">{{ row.type }}</span>
  84. </td>
  85. <td class="px-6 py-3 text-xs text-gray-500">
  86. {% if row.last_run_at %}{{ row.last_run_at.strftime('%d/%m/%Y %H:%M') }}
  87. {% else %}<span class="text-gray-300">Jamais</span>{% endif %}
  88. </td>
  89. <td class="px-6 py-3">
  90. {% if row.last_status == 'success' %}
  91. <span class="bg-green-100 text-green-700 text-xs font-medium px-2 py-0.5 rounded-full">✓ succès</span>
  92. {% elif row.last_status == 'error' %}
  93. <span class="bg-red-100 text-red-700 text-xs font-medium px-2 py-0.5 rounded-full">✗ erreur</span>
  94. {% elif row.last_status == 'running' %}
  95. <span class="bg-blue-100 text-blue-700 text-xs font-medium px-2 py-0.5 rounded-full animate-pulse">⟳ en cours</span>
  96. {% else %}
  97. <span class="text-gray-300 text-xs">—</span>
  98. {% endif %}
  99. </td>
  100. <td class="px-6 py-3 text-xs text-gray-500">
  101. {% if row.last_size_human is defined %}{{ row.last_size_human }}
  102. {% elif row.size_human is defined %}{{ row.size_human }}
  103. {% else %}—{% endif %}
  104. </td>
  105. <td class="px-6 py-3 text-right">
  106. <div class="flex items-center justify-end gap-2">
  107. {% if inst_id and row.job_id %}
  108. <form method="post"
  109. action="{{ url_for('network.remote_job_run', inst_id=inst_id, job_id=row.job_id) }}"
  110. onsubmit="return confirm('Lancer « {{ row.name }} » sur {{ inst_name }} ?')">
  111. <button type="submit" class="btn-primary btn-sm">▶ Lancer</button>
  112. </form>
  113. {% elif not inst_id and row.job_id %}
  114. <form method="post"
  115. action="{{ url_for('jobs.job_run_now', job_id=row.job_id) }}"
  116. onsubmit="return confirm('Lancer « {{ row.name }} » maintenant ?')">
  117. <button type="submit" class="btn-primary btn-sm">▶ Lancer</button>
  118. </form>
  119. {% endif %}
  120. {% if inst_id and row.job_id %}
  121. <form method="post"
  122. action="{{ url_for('network.archive_pull_latest', inst_id=inst_id, remote_job_id=row.job_id) }}"
  123. onsubmit="return confirm('Rapatrier la dernière archive de « {{ row.name }} » depuis {{ inst_name }} ?')">
  124. <button type="submit" class="btn-ghost btn-sm">← Rapatrier</button>
  125. </form>
  126. {% endif %}
  127. </div>
  128. </td>
  129. </tr>
  130. {% endfor %}
  131. </tbody>
  132. </table>
  133. </div>
  134. {% endif %}
  135. </div>
  136. {% endmacro %}
  137. {{ instance_section(instance_name, instance_url, local_jobs_data) }}
  138. {% if not instances %}
  139. <div class="bg-white rounded-xl border border-gray-200 px-6 py-10 text-center text-gray-400">
  140. <p>Aucune instance distante enregistrée.</p>
  141. <a href="{{ url_for('network.remote_instance_new') }}" class="mt-2 inline-block text-blue-600 hover:underline text-sm">
  142. Ajouter une instance →
  143. </a>
  144. </div>
  145. {% else %}
  146. {% for inst in instances %}
  147. {{ instance_section(inst.name, inst.url_display, inst.remote_runs,
  148. inst_id=inst.id, inst_status=inst.status, last_seen=inst.last_seen) }}
  149. {% endfor %}
  150. {% endif %}
  151. </div>{# /pane-reseau #}
  152. {# ══════════════════ PANNEAU : INSTANCES ══════════════════════════ #}
  153. <div id="pane-instances" class="hidden">
  154. {% if not instances %}
  155. <div class="bg-white rounded-xl border border-gray-200 px-6 py-12 text-center text-gray-400">
  156. <p class="text-lg">Aucune instance distante configurée.</p>
  157. <p class="text-sm mt-2">Ajoutez une instance pour voir son état et déclencher des sauvegardes à distance.</p>
  158. <a href="{{ url_for('network.remote_instance_new') }}" class="mt-4 inline-block text-blue-600 hover:underline text-sm">
  159. Ajouter une première instance →
  160. </a>
  161. </div>
  162. {% else %}
  163. <div class="space-y-4">
  164. {% for inst in instances %}
  165. {% set status_color = {
  166. 'online': 'bg-green-100 text-green-700',
  167. 'error': 'bg-red-100 text-red-700',
  168. 'offline': 'bg-gray-100 text-gray-500',
  169. }.get(inst.status, 'bg-gray-100 text-gray-400') %}
  170. <div class="bg-white rounded-xl border border-gray-200 shadow-sm p-5">
  171. <div class="flex items-start justify-between gap-4">
  172. <div class="space-y-2 min-w-0 flex-1">
  173. <div class="flex items-center gap-2 flex-wrap">
  174. <span class="font-semibold text-gray-900">{{ inst.name }}</span>
  175. <span class="text-xs px-2 py-0.5 rounded-full font-medium {{ status_color }}">
  176. {{ inst.status or 'unknown' }}
  177. </span>
  178. {% if inst.last_seen %}
  179. <span class="text-xs text-gray-400">vu {{ inst.last_seen.strftime('%d/%m %H:%M') }}</span>
  180. {% endif %}
  181. </div>
  182. <p class="text-sm font-mono text-gray-500">{{ inst.url_display }}</p>
  183. {% if inst.remote_runs %}
  184. <div class="mt-3 border-t border-gray-100 pt-3">
  185. <p class="text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2">
  186. Jobs ({{ inst.remote_runs | length }})
  187. </p>
  188. <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2">
  189. {% for rr in inst.remote_runs %}
  190. {% set run_color = {
  191. 'success': 'text-green-600',
  192. 'error': 'text-red-600',
  193. 'running': 'text-blue-600',
  194. }.get(rr.last_status, 'text-gray-400') %}
  195. <div class="text-xs bg-gray-50 rounded-lg px-3 py-2 space-y-0.5">
  196. <p class="font-medium text-gray-800 truncate">{{ rr.job_name }}</p>
  197. <p class="text-gray-400">{{ rr.job_type }}</p>
  198. {% if rr.last_run_at %}
  199. <p class="{{ run_color }} font-medium">
  200. {{ rr.last_status }} — {{ rr.last_run_at.strftime('%d/%m %H:%M') }}
  201. </p>
  202. {% else %}
  203. <p class="text-gray-300">jamais exécuté</p>
  204. {% endif %}
  205. {% if rr.last_size_bytes %}
  206. <p class="text-gray-400">{{ rr.last_size_human }}</p>
  207. {% endif %}
  208. </div>
  209. {% endfor %}
  210. </div>
  211. </div>
  212. {% endif %}
  213. </div>
  214. <div class="flex items-center gap-2 shrink-0 flex-wrap justify-end">
  215. <form method="post" action="{{ url_for('network.remote_instance_test', inst_id=inst.id) }}">
  216. <button type="submit" class="btn-secondary btn-sm">Tester</button>
  217. </form>
  218. <form method="post" action="{{ url_for('network.remote_instance_sync', inst_id=inst.id) }}">
  219. <button type="submit" class="btn-secondary btn-sm">Synchroniser</button>
  220. </form>
  221. <a href="{{ url_for('network.remote_instance_edit', inst_id=inst.id) }}"
  222. class="btn-secondary btn-sm">Éditer</a>
  223. <form method="post" action="{{ url_for('network.remote_instance_delete', inst_id=inst.id) }}"
  224. onsubmit="return confirm('Supprimer l\'instance « {{ inst.name }} » ?')">
  225. <button type="submit" class="btn-danger btn-icon-sm">✕</button>
  226. </form>
  227. </div>
  228. </div>
  229. </div>
  230. {% endfor %}
  231. </div>
  232. {% endif %}
  233. </div>{# /pane-instances #}
  234. <script>
  235. function setTab(name) {
  236. ['reseau', 'instances'].forEach(function(t) {
  237. const pane = document.getElementById('pane-' + t);
  238. const btn = document.getElementById('tab-btn-' + t);
  239. const active = t === name;
  240. pane.classList.toggle('hidden', !active);
  241. btn.classList.toggle('border-blue-600', active);
  242. btn.classList.toggle('text-blue-600', active);
  243. btn.classList.toggle('border-transparent', !active);
  244. btn.classList.toggle('text-gray-500', !active);
  245. });
  246. history.replaceState(null, '', location.pathname + '?tab=' + name);
  247. }
  248. // Restore tab from URL
  249. const urlTab = new URLSearchParams(location.search).get('tab');
  250. if (urlTab === 'instances') setTab('instances');
  251. </script>
  252. {% endblock %}