archives_overview.html 15 KB

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