archives_overview.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. {% extends "base.html" %}
  2. {% block title %}Vue globale des archives{% endblock %}
  3. {% macro archive_actions(arch, loc) %}
  4. <div class="flex items-center justify-end gap-1">
  5. {% if loc.type == "local" %}
  6. <a href="{{ url_for('jobs.archive_restore', archive_name=arch.name) }}" class="btn-secondary btn-sm">↩ Restaurer</a>
  7. {% else %}
  8. <form method="post" action="{{ url_for('overview.overview_pull') }}"
  9. onsubmit="return confirm('Rapatrier « {{ arch.name }} » en local ?')">
  10. <input type="hidden" name="name" value="{{ arch.name }}">
  11. <input type="hidden" name="loc_type" value="{{ loc.type }}">
  12. {% if loc.type == "ssh" %}<input type="hidden" name="dest_id" value="{{ loc.dest_id }}">{% endif %}
  13. {% if loc.type == "instance" %}<input type="hidden" name="instance_id" value="{{ loc.instance_id }}">{% endif %}
  14. <button type="submit" class="btn-ghost btn-sm">← Rapatrier</button>
  15. </form>
  16. {% endif %}
  17. <form method="post" action="{{ url_for('overview.overview_delete') }}"
  18. onsubmit="return confirm('Supprimer « {{ arch.name }} » ?')">
  19. <input type="hidden" name="name" value="{{ arch.name }}">
  20. <input type="hidden" name="loc_type" value="{{ loc.type }}">
  21. {% if loc.type == "ssh" %}<input type="hidden" name="dest_id" value="{{ loc.dest_id }}">{% endif %}
  22. {% if loc.type == "instance" %}<input type="hidden" name="instance_id" value="{{ loc.instance_id }}">{% endif %}
  23. <button type="submit" class="btn-danger btn-icon-sm">✕</button>
  24. </form>
  25. </div>
  26. {% endmacro %}
  27. {% block content %}
  28. <div class="space-y-6">
  29. <!-- En-tête -->
  30. <div class="flex items-center justify-between">
  31. <div>
  32. <h1 class="text-2xl font-bold text-gray-900">Vue globale des archives</h1>
  33. <p class="text-sm text-gray-500 mt-1">Toutes les destinations — local, SSH et instances fédérées</p>
  34. </div>
  35. <a href="{{ url_for('overview.overview') }}" class="btn-ghost btn-sm">↻ Rafraîchir</a>
  36. </div>
  37. <!-- Onglets -->
  38. <div class="flex gap-1 bg-gray-100 rounded-lg p-1 w-fit">
  39. <button id="tab-jobs" onclick="switchTab('jobs')"
  40. class="px-4 py-2 text-sm font-medium rounded-md transition">
  41. Par job
  42. </button>
  43. <button id="tab-dests" onclick="switchTab('dests')"
  44. class="px-4 py-2 text-sm font-medium rounded-md transition">
  45. Par destination
  46. </button>
  47. </div>
  48. <!-- ================================================================
  49. VUE PAR JOB (défaut)
  50. ================================================================ -->
  51. <div id="view-jobs" class="space-y-6">
  52. {% if not jobs_view %}
  53. <div class="text-center text-sm text-gray-400 py-12">Aucun job configuré.</div>
  54. {% endif %}
  55. {% for item in jobs_view %}
  56. <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
  57. <!-- En-tête du job -->
  58. <div class="px-6 py-4 bg-gray-50 border-b border-gray-200 flex items-center gap-3 flex-wrap">
  59. <span class="font-semibold text-gray-800">{{ item.job.name }}</span>
  60. {% if item.detail %}
  61. <span class="font-semibold text-gray-800">: {{ item.detail }}</span>
  62. {% endif %}
  63. <span class="text-xs bg-gray-100 text-gray-500 px-2 py-0.5 rounded-full">{{ item.job.type }}</span>
  64. <span class="text-xs bg-green-50 text-green-700 border border-green-200 px-2 py-0.5 rounded-full">
  65. rétention : {{ item.retention_label }}
  66. </span>
  67. <!-- Compteur de réplication -->
  68. {% set ns = namespace(copies=0) %}
  69. {% for loc in item.locations %}
  70. {% if not loc.error and loc.archives %}{% set ns.copies = ns.copies + 1 %}{% endif %}
  71. {% endfor %}
  72. {% set total = item.locations | length %}
  73. <span class="ml-auto text-xs font-semibold px-2.5 py-1 rounded-full
  74. {% if ns.copies == total %}bg-green-100 text-green-700
  75. {% elif ns.copies == 0 %}bg-red-100 text-red-600
  76. {% else %}bg-amber-100 text-amber-700{% endif %}">
  77. {{ ns.copies }}/{{ total }} destination{% if total > 1 %}s{% endif %}
  78. </span>
  79. </div>
  80. <!-- Destinations pour ce job -->
  81. <div class="divide-y divide-gray-100">
  82. {% for loc in item.locations %}
  83. <div class="px-6 py-4">
  84. <!-- Ligne d'en-tête destination -->
  85. <div class="flex items-center justify-between mb-3 flex-wrap gap-2">
  86. <div class="flex items-center gap-2">
  87. {% if loc.type == "local" %}
  88. <span class="inline-flex items-center bg-blue-100 text-blue-700 text-xs font-semibold px-2.5 py-1 rounded-full">Local</span>
  89. {% elif loc.type == "ssh" %}
  90. <span class="inline-flex items-center bg-slate-100 text-slate-700 text-xs font-semibold px-2.5 py-1 rounded-full">SSH</span>
  91. {% else %}
  92. <span class="inline-flex items-center bg-purple-100 text-purple-700 text-xs font-semibold px-2.5 py-1 rounded-full">Instance</span>
  93. {% endif %}
  94. <span class="text-sm text-gray-700">{{ loc.label }}</span>
  95. {% if not loc.error %}
  96. <span class="text-xs px-2 py-0.5 rounded-full
  97. {% if loc.archives %}bg-green-50 text-green-700 border border-green-200
  98. {% else %}bg-gray-100 text-gray-400{% endif %}">
  99. {{ loc.archives | length }} archive{% if loc.archives | length != 1 %}s{% endif %}
  100. </span>
  101. {% endif %}
  102. </div>
  103. {% if not loc.error %}
  104. <form method="post" action="{{ url_for('overview.overview_retention') }}"
  105. onsubmit="return confirm('Appliquer la rétention pour « {{ item.job.name }} » sur cette destination ?')">
  106. <input type="hidden" name="job_id" value="{{ item.job.id }}">
  107. <input type="hidden" name="loc_type" value="{{ loc.type }}">
  108. {% if loc.type == "ssh" %}<input type="hidden" name="dest_id" value="{{ loc.dest_id }}">{% endif %}
  109. {% if loc.type == "instance" %}<input type="hidden" name="instance_id" value="{{ loc.instance_id }}">{% endif %}
  110. <button type="submit" class="btn-secondary btn-sm">↺ Appliquer la rétention</button>
  111. </form>
  112. {% endif %}
  113. </div>
  114. <!-- Contenu : erreur / archives / vide -->
  115. {% if loc.error %}
  116. <div class="flex items-start gap-2 text-sm text-red-700 bg-red-50 px-4 py-3 rounded-lg">
  117. <span class="shrink-0">⚠</span><span>{{ loc.error }}</span>
  118. </div>
  119. {% elif loc.archives %}
  120. <div class="rounded-lg border border-gray-100 overflow-hidden">
  121. <table class="w-full text-sm">
  122. <thead class="bg-gray-50 text-xs text-gray-500 uppercase tracking-wide">
  123. <tr>
  124. <th class="text-left px-4 py-2 font-medium">Archive</th>
  125. <th class="text-right px-4 py-2 font-medium">Taille</th>
  126. <th class="text-right px-4 py-2 font-medium">Date</th>
  127. <th class="px-4 py-2"></th>
  128. </tr>
  129. </thead>
  130. <tbody class="divide-y divide-gray-50">
  131. {% for arch in loc.archives %}
  132. <tr class="hover:bg-gray-50 transition">
  133. <td class="px-4 py-2.5 font-mono text-xs text-gray-700">{{ arch.name }}</td>
  134. <td class="px-4 py-2.5 text-right text-gray-500 tabular-nums">{{ arch.size_human }}</td>
  135. <td class="px-4 py-2.5 text-right text-gray-500 tabular-nums">{{ arch.date_str }}</td>
  136. <td class="px-4 py-2.5 text-right">
  137. {{ archive_actions(arch, loc) }}
  138. </td>
  139. </tr>
  140. {% endfor %}
  141. </tbody>
  142. </table>
  143. </div>
  144. {% else %}
  145. <div class="text-sm text-gray-400 italic">Aucune archive sur cette destination.</div>
  146. {% endif %}
  147. </div>
  148. {% endfor %}
  149. </div>
  150. </div>
  151. {% endfor %}
  152. </div><!-- fin #view-jobs -->
  153. <!-- ================================================================
  154. VUE PAR DESTINATION (existante)
  155. ================================================================ -->
  156. <div id="view-dests" class="hidden space-y-8">
  157. {% for loc in locations %}
  158. <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
  159. <div class="px-6 py-4 bg-gray-50 border-b border-gray-200 flex items-center gap-3">
  160. {% if loc.type == "local" %}
  161. <span class="inline-flex items-center gap-1 bg-blue-100 text-blue-700 text-xs font-semibold px-2.5 py-1 rounded-full">Local</span>
  162. {% elif loc.type == "ssh" %}
  163. <span class="inline-flex items-center gap-1 bg-slate-100 text-slate-700 text-xs font-semibold px-2.5 py-1 rounded-full">SSH</span>
  164. {% else %}
  165. <span class="inline-flex items-center gap-1 bg-purple-100 text-purple-700 text-xs font-semibold px-2.5 py-1 rounded-full">Instance</span>
  166. {% endif %}
  167. <span class="font-semibold text-gray-800">{{ loc.label }}</span>
  168. {% if loc.type == "instance" and loc.instance_url is defined %}
  169. <span class="text-xs text-gray-400">{{ loc.instance_url }}</span>
  170. {% endif %}
  171. </div>
  172. {% if loc.error %}
  173. <div class="px-6 py-5 flex items-start gap-3 text-sm text-red-700 bg-red-50">
  174. <span class="text-base shrink-0">⚠</span>
  175. <span>{{ loc.error }}</span>
  176. </div>
  177. {% else %}
  178. {% set ns = namespace(has_content=false) %}
  179. {% for group in loc.groups %}
  180. {% if group.archives %}{% set ns.has_content = true %}{% endif %}
  181. {% endfor %}
  182. {% if loc.orphaned %}{% set ns.has_content = true %}{% endif %}
  183. {% if not ns.has_content %}
  184. <div class="px-6 py-8 text-center text-sm text-gray-400">
  185. Aucune archive sur cette destination.
  186. </div>
  187. {% else %}
  188. <div class="divide-y divide-gray-100">
  189. {% for group in loc.groups %}
  190. {% if group.archives %}
  191. <div class="px-6 py-4">
  192. <div class="flex items-center justify-between mb-3">
  193. <div class="flex items-center gap-2">
  194. <span class="font-medium text-gray-800">{{ group.job.name }}</span>
  195. {% if group.detail %}
  196. <span class="font-mono text-xs text-gray-400">{{ group.detail }}</span>
  197. {% endif %}
  198. <span class="text-xs bg-gray-100 text-gray-500 px-2 py-0.5 rounded-full">{{ group.job.type }}</span>
  199. <span class="text-xs bg-green-50 text-green-700 border border-green-200 px-2 py-0.5 rounded-full">
  200. rétention : {{ group.retention_label }}
  201. </span>
  202. </div>
  203. <form method="post" action="{{ url_for('overview.overview_retention') }}"
  204. onsubmit="return confirm('Appliquer la rétention pour « {{ group.job.name }} » sur cette destination ?')">
  205. <input type="hidden" name="job_id" value="{{ group.job.id }}">
  206. <input type="hidden" name="loc_type" value="{{ loc.type }}">
  207. {% if loc.type == "ssh" %}<input type="hidden" name="dest_id" value="{{ loc.dest_id }}">{% endif %}
  208. {% if loc.type == "instance" %}<input type="hidden" name="instance_id" value="{{ loc.instance_id }}">{% endif %}
  209. <button type="submit" class="btn-secondary btn-sm">↺ Appliquer la rétention</button>
  210. </form>
  211. </div>
  212. <div class="rounded-lg border border-gray-100 overflow-hidden">
  213. <table class="w-full text-sm">
  214. <thead class="bg-gray-50 text-xs text-gray-500 uppercase tracking-wide">
  215. <tr>
  216. <th class="text-left px-4 py-2 font-medium">Archive</th>
  217. <th class="text-right px-4 py-2 font-medium">Taille</th>
  218. <th class="text-right px-4 py-2 font-medium">Date</th>
  219. <th class="px-4 py-2"></th>
  220. </tr>
  221. </thead>
  222. <tbody class="divide-y divide-gray-50">
  223. {% for arch in group.archives %}
  224. <tr class="hover:bg-gray-50 transition">
  225. <td class="px-4 py-2.5 font-mono text-xs text-gray-700">{{ arch.name }}</td>
  226. <td class="px-4 py-2.5 text-right text-gray-500 tabular-nums">{{ arch.size_human }}</td>
  227. <td class="px-4 py-2.5 text-right text-gray-500 tabular-nums">{{ arch.date_str }}</td>
  228. <td class="px-4 py-2.5 text-right">
  229. {{ archive_actions(arch, loc) }}
  230. </td>
  231. </tr>
  232. {% endfor %}
  233. </tbody>
  234. </table>
  235. </div>
  236. </div>
  237. {% endif %}
  238. {% endfor %}
  239. {% if loc.orphaned %}
  240. <div class="px-6 py-4">
  241. <div class="flex items-center gap-2 mb-3">
  242. <span class="font-medium text-gray-500">Sans job associé</span>
  243. <span class="text-xs bg-yellow-50 text-yellow-700 border border-yellow-200 px-2 py-0.5 rounded-full">
  244. {{ loc.orphaned | length }} archive(s)
  245. </span>
  246. </div>
  247. <div class="rounded-lg border border-gray-100 overflow-hidden">
  248. <table class="w-full text-sm">
  249. <tbody class="divide-y divide-gray-50">
  250. {% for arch in loc.orphaned %}
  251. <tr class="hover:bg-gray-50 transition">
  252. <td class="px-4 py-2.5 font-mono text-xs text-gray-700">{{ arch.name }}</td>
  253. <td class="px-4 py-2.5 text-right text-gray-500 tabular-nums">{{ arch.size_human }}</td>
  254. <td class="px-4 py-2.5 text-right text-gray-500 tabular-nums">{{ arch.date_str }}</td>
  255. <td class="px-4 py-2.5 text-right">
  256. {{ archive_actions(arch, loc) }}
  257. </td>
  258. </tr>
  259. {% endfor %}
  260. </tbody>
  261. </table>
  262. </div>
  263. </div>
  264. {% endif %}
  265. </div>
  266. {% endif %}
  267. {% endif %}
  268. </div>
  269. {% endfor %}
  270. </div><!-- fin #view-dests -->
  271. </div>
  272. {% endblock %}
  273. {% block scripts %}
  274. <script>
  275. function switchTab(name) {
  276. const isJobs = name === 'jobs';
  277. document.getElementById('view-jobs').classList.toggle('hidden', !isJobs);
  278. document.getElementById('view-dests').classList.toggle('hidden', isJobs);
  279. ['jobs', 'dests'].forEach(function(t) {
  280. var btn = document.getElementById('tab-' + t);
  281. var active = t === name;
  282. btn.classList.toggle('bg-white', active);
  283. btn.classList.toggle('text-gray-900', active);
  284. btn.classList.toggle('shadow-sm', active);
  285. btn.classList.toggle('font-semibold', active);
  286. btn.classList.toggle('text-gray-500', !active);
  287. btn.classList.toggle('hover:text-gray-700', !active);
  288. });
  289. try { localStorage.setItem('overview-tab', name); } catch(e) {}
  290. }
  291. // Restaurer l'onglet préféré (ou 'jobs' par défaut)
  292. var savedTab = 'jobs';
  293. try { savedTab = localStorage.getItem('overview-tab') || 'jobs'; } catch(e) {}
  294. switchTab(savedTab);
  295. </script>
  296. {% endblock %}