archives_overview.html 16 KB

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