dashboard_network.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. {% extends "base.html" %}
  2. {% block title %}Vue réseau{% endblock %}
  3. {% block content %}
  4. <div class="flex items-center justify-between mb-6">
  5. <h1 class="text-xl font-bold text-gray-900">Vue réseau</h1>
  6. <div class="flex gap-2">
  7. <a href="{{ url_for('jobs.index') }}"
  8. class="text-sm text-gray-500 hover:text-gray-700 px-3 py-1.5 rounded border border-gray-200 bg-white transition">
  9. Vue locale
  10. </a>
  11. <form method="post" action="{{ url_for('network.network_sync_all') }}">
  12. <button type="submit"
  13. class="text-sm bg-blue-600 hover:bg-blue-700 text-white px-3 py-1.5 rounded transition">
  14. Synchroniser tout
  15. </button>
  16. </form>
  17. </div>
  18. </div>
  19. {% macro instance_section(inst_name, inst_url, jobs_data, inst_id=None, inst_status=None, last_seen=None) %}
  20. <div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden mb-6">
  21. <div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between gap-4">
  22. <div class="flex items-center gap-3 min-w-0">
  23. <h2 class="text-base font-semibold text-gray-800">{{ inst_name }}</h2>
  24. {% if inst_id %}
  25. {% set sc = {'online':'bg-green-100 text-green-700','error':'bg-red-100 text-red-700','offline':'bg-gray-100 text-gray-500'} %}
  26. <span class="text-xs px-2 py-0.5 rounded-full font-medium {{ sc.get(inst_status, 'bg-gray-100 text-gray-400') }}">
  27. {{ inst_status or 'unknown' }}
  28. </span>
  29. {% if last_seen %}
  30. <span class="text-xs text-gray-400 hidden sm:inline">sync {{ last_seen.strftime('%d/%m %H:%M') }}</span>
  31. {% endif %}
  32. {% else %}
  33. <span class="text-xs bg-blue-100 text-blue-700 px-2 py-0.5 rounded-full font-medium">local</span>
  34. {% endif %}
  35. {% if inst_url %}
  36. <span class="text-xs font-mono text-gray-400 truncate hidden md:inline">{{ inst_url }}</span>
  37. {% endif %}
  38. </div>
  39. {% if inst_id %}
  40. <div class="flex gap-2 shrink-0">
  41. <form method="post" action="{{ url_for('network.remote_instance_sync', inst_id=inst_id) }}">
  42. <button type="submit"
  43. class="text-xs bg-gray-50 hover:bg-gray-100 text-gray-600 px-3 py-1.5 rounded border border-gray-200 transition">
  44. Sync
  45. </button>
  46. </form>
  47. <a href="{{ url_for('network.remote_instance_edit', inst_id=inst_id) }}"
  48. class="text-xs bg-gray-50 hover:bg-gray-100 text-gray-600 px-3 py-1.5 rounded border border-gray-200 transition">
  49. Éditer
  50. </a>
  51. </div>
  52. {% endif %}
  53. </div>
  54. {% if not jobs_data %}
  55. <div class="px-6 py-8 text-center text-gray-400 text-sm">
  56. {% if inst_id %}
  57. Aucune donnée — cliquez sur "Sync" pour récupérer l'état de cette instance.
  58. {% else %}
  59. Aucun job configuré.
  60. <a href="{{ url_for('jobs.job_new') }}" class="text-blue-600 hover:underline ml-1">Créer un job →</a>
  61. {% endif %}
  62. </div>
  63. {% else %}
  64. <div class="overflow-x-auto">
  65. <table class="w-full text-sm">
  66. <thead>
  67. <tr class="text-xs text-gray-500 uppercase tracking-wide bg-gray-50">
  68. <th class="px-6 py-3 text-left font-medium">Job</th>
  69. <th class="px-6 py-3 text-left font-medium">Type</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 row in jobs_data %}
  78. <tr class="hover:bg-gray-50">
  79. <td class="px-6 py-3 font-medium text-gray-900">{{ row.name }}</td>
  80. <td class="px-6 py-3">
  81. <span class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded font-mono">{{ row.type }}</span>
  82. </td>
  83. <td class="px-6 py-3 text-xs text-gray-500">
  84. {% if row.last_run_at %}{{ row.last_run_at.strftime('%d/%m/%Y %H:%M') }}
  85. {% else %}<span class="text-gray-300">Jamais</span>{% endif %}
  86. </td>
  87. <td class="px-6 py-3">
  88. {% if row.last_status == 'success' %}
  89. <span class="bg-green-100 text-green-700 text-xs font-medium px-2 py-0.5 rounded-full">✓ succès</span>
  90. {% elif row.last_status == 'error' %}
  91. <span class="bg-red-100 text-red-700 text-xs font-medium px-2 py-0.5 rounded-full">✗ erreur</span>
  92. {% elif row.last_status == 'running' %}
  93. <span class="bg-blue-100 text-blue-700 text-xs font-medium px-2 py-0.5 rounded-full animate-pulse">⟳ en cours</span>
  94. {% else %}
  95. <span class="text-gray-300 text-xs">—</span>
  96. {% endif %}
  97. </td>
  98. <td class="px-6 py-3 text-xs text-gray-500">
  99. {% if row.last_size_human is defined %}{{ row.last_size_human }}
  100. {% elif row.size_human is defined %}{{ row.size_human }}
  101. {% else %}—{% endif %}
  102. </td>
  103. <td class="px-6 py-3 text-right">
  104. <div class="flex items-center justify-end gap-2">
  105. {% if inst_id and row.job_id %}
  106. <form method="post"
  107. action="{{ url_for('network.remote_job_run', inst_id=inst_id, job_id=row.job_id) }}"
  108. onsubmit="return confirm('Lancer « {{ row.name }} » sur {{ inst_name }} ?')">
  109. <button type="submit"
  110. class="bg-blue-50 hover:bg-blue-100 text-blue-700 text-xs font-medium px-2.5 py-1 rounded transition">
  111. ▶ Lancer
  112. </button>
  113. </form>
  114. {% elif not inst_id and row.job_id %}
  115. <form method="post"
  116. action="{{ url_for('jobs.job_run_now', job_id=row.job_id) }}"
  117. onsubmit="return confirm('Lancer « {{ row.name }} » maintenant ?')">
  118. <button type="submit"
  119. class="bg-blue-50 hover:bg-blue-100 text-blue-700 text-xs font-medium px-2.5 py-1 rounded transition">
  120. ▶ Lancer
  121. </button>
  122. </form>
  123. {% endif %}
  124. {% if inst_id and row.job_id %}
  125. <form method="post"
  126. action="{{ url_for('network.archive_pull_latest', inst_id=inst_id, remote_job_id=row.job_id) }}"
  127. onsubmit="return confirm('Rapatrier la dernière archive de « {{ row.name }} » depuis {{ inst_name }} ?')">
  128. <button type="submit"
  129. class="text-gray-400 hover:text-gray-700 text-xs px-2 py-1 rounded hover:bg-gray-100 transition">
  130. ← Rapatrier
  131. </button>
  132. </form>
  133. {% endif %}
  134. </div>
  135. </td>
  136. </tr>
  137. {% endfor %}
  138. </tbody>
  139. </table>
  140. </div>
  141. {% endif %}
  142. </div>
  143. {% endmacro %}
  144. {# ── Instance locale ─────────────────────────────────────────────── #}
  145. {{ instance_section(instance_name, instance_url, local_jobs_data) }}
  146. {# ── Instances distantes ──────────────────────────────────────────── #}
  147. {% if not instances %}
  148. <div class="bg-white rounded-xl border border-gray-200 px-6 py-10 text-center text-gray-400">
  149. <p>Aucune instance distante enregistrée.</p>
  150. <a href="{{ url_for('network.remote_instance_new') }}" class="mt-2 inline-block text-blue-600 hover:underline text-sm">
  151. Ajouter une instance →
  152. </a>
  153. </div>
  154. {% else %}
  155. {% for inst in instances %}
  156. {{ instance_section(inst.name, inst.url_display, inst.remote_runs,
  157. inst_id=inst.id, inst_status=inst.status, last_seen=inst.last_seen) }}
  158. {% endfor %}
  159. {% endif %}
  160. {% endblock %}