job_form.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. {% extends "base.html" %}
  2. {% block title %}{{ 'Éditer' if job else 'Nouveau job' }}{% endblock %}
  3. {% block content %}
  4. <div class="max-w-2xl">
  5. <h1 class="text-xl font-bold text-gray-900 mb-6">
  6. {{ 'Éditer « ' + job.name + ' »' if job else 'Nouveau job de sauvegarde' }}
  7. </h1>
  8. <form method="post"
  9. action="{{ url_for('job_edit', job_id=job.id) if job else url_for('job_new') }}"
  10. class="space-y-6">
  11. {# ── Infos générales ── #}
  12. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  13. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Général</h2>
  14. <div>
  15. <label class="block text-sm font-medium text-gray-700 mb-1">Nom du job</label>
  16. <input type="text" name="name" required
  17. value="{{ job.name if job else '' }}"
  18. placeholder="ex: Nextcloud quotidien"
  19. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  20. </div>
  21. <div>
  22. <label class="block text-sm font-medium text-gray-700 mb-1">Type</label>
  23. <select name="type" id="job-type"
  24. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  25. {% for val, label in [('ynh_app','Application YunoHost'), ('ynh_system','Système YunoHost'),
  26. ('mysql','MySQL'), ('postgresql','PostgreSQL'),
  27. ('custom_dir','Répertoire custom (Phase 2)')] %}
  28. <option value="{{ val }}"
  29. {% if job and job.type == val %}selected{% endif %}
  30. {% if val == 'custom_dir' %}disabled class="text-gray-400"{% endif %}>
  31. {{ label }}
  32. </option>
  33. {% endfor %}
  34. </select>
  35. </div>
  36. {# Type-specific config : ynh_app #}
  37. <div id="cfg-ynh_app" class="type-cfg space-y-3">
  38. <div>
  39. <label class="block text-sm font-medium text-gray-700 mb-1">Application YunoHost</label>
  40. <select name="app_id"
  41. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  42. {% set current_app_id = (job.config_json | fromjson).get('app_id', '') if job and job.config_json else '' %}
  43. {% for ynh_app in ynh_apps %}
  44. <option value="{{ ynh_app.id }}"
  45. {% if ynh_app.id == current_app_id %}selected{% endif %}>
  46. {{ ynh_app.id }}{% if ynh_app.label %} — {{ ynh_app.label }}{% endif %}
  47. </option>
  48. {% endfor %}
  49. {% if not ynh_apps %}
  50. <option value="">Aucune application trouvée</option>
  51. {% endif %}
  52. </select>
  53. </div>
  54. <div class="flex items-center gap-2">
  55. {% set core_only = (job.config_json | fromjson).get('core_only', False) if job and job.config_json else False %}
  56. <input type="checkbox" name="core_only" value="1" id="core_only"
  57. {% if core_only %}checked{% endif %}
  58. class="rounded border-gray-300 text-blue-600">
  59. <label for="core_only" class="text-sm text-gray-700">
  60. Core only (BACKUP_CORE_ONLY=1) — exclut les données utilisateur
  61. </label>
  62. </div>
  63. </div>
  64. {# Type-specific config : ynh_system (rien de spécifique) #}
  65. <div id="cfg-ynh_system" class="type-cfg hidden">
  66. <p class="text-sm text-gray-500 bg-gray-50 rounded-lg p-3">
  67. Sauvegarde la configuration système YunoHost complète.
  68. Aucun paramètre supplémentaire.
  69. </p>
  70. </div>
  71. {# Type-specific config : mysql #}
  72. {% set db_cfg = (job.config_json | fromjson) if job and job.config_json else {} %}
  73. <div id="cfg-mysql" class="type-cfg hidden space-y-3">
  74. <div>
  75. <label class="block text-sm font-medium text-gray-700 mb-1">Nom de la base de données</label>
  76. <input type="text" name="db_database"
  77. value="{{ db_cfg.get('database', '') if job and job.type == 'mysql' else '' }}"
  78. placeholder="ex: nextcloud"
  79. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
  80. <p class="text-xs text-gray-400 mt-1">
  81. Le dump est exécuté avec <code class="bg-gray-100 px-1 rounded">sudo mysqldump</code> — aucun mot de passe requis.
  82. </p>
  83. </div>
  84. </div>
  85. {# Type-specific config : postgresql #}
  86. <div id="cfg-postgresql" class="type-cfg hidden space-y-3">
  87. <div>
  88. <label class="block text-sm font-medium text-gray-700 mb-1">Nom de la base de données</label>
  89. <input type="text" name="db_database"
  90. value="{{ db_cfg.get('database', '') if job and job.type == 'postgresql' else '' }}"
  91. placeholder="ex: gitea"
  92. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
  93. <p class="text-xs text-gray-400 mt-1">
  94. Le dump est exécuté avec <code class="bg-gray-100 px-1 rounded">sudo -u postgres pg_dump</code> — aucun mot de passe requis.
  95. </p>
  96. </div>
  97. </div>
  98. </div>
  99. {# ── Planification ── #}
  100. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  101. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Planification</h2>
  102. <div>
  103. <label class="block text-sm font-medium text-gray-700 mb-1">Expression cron</label>
  104. <input type="text" name="cron_expr" required
  105. value="{{ job.cron_expr if job else '0 3 * * *' }}"
  106. placeholder="0 3 * * *"
  107. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
  108. <p class="text-xs text-gray-400 mt-1">
  109. Format : minute heure jour mois jour_semaine
  110. — ex: <code class="bg-gray-100 px-1 rounded">0 3 * * *</code> = tous les jours à 3h
  111. · <code class="bg-gray-100 px-1 rounded">0 3 * * 1</code> = chaque lundi à 3h
  112. </p>
  113. </div>
  114. </div>
  115. {# ── Rétention ── #}
  116. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  117. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Rétention</h2>
  118. <div class="grid grid-cols-2 gap-4">
  119. <div>
  120. <label class="block text-sm font-medium text-gray-700 mb-1">Mode</label>
  121. <select name="retention_mode"
  122. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  123. {% for val, label in [('count','Count — N dernières archives'),
  124. ('daily','Daily — 1 par jour sur N jours'),
  125. ('gfs','GFS — Grand/Père/Fils (Phase 4)')] %}
  126. <option value="{{ val }}"
  127. {% if job and job.retention_mode == val %}selected{% endif %}
  128. {% if val == 'gfs' %}disabled class="text-gray-400"{% endif %}>
  129. {{ label }}
  130. </option>
  131. {% endfor %}
  132. </select>
  133. </div>
  134. <div>
  135. <label class="block text-sm font-medium text-gray-700 mb-1">Valeur</label>
  136. <input type="number" name="retention_value" min="1" max="365" required
  137. value="{{ job.retention_value if job else 7 }}"
  138. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  139. </div>
  140. </div>
  141. </div>
  142. {# ── Options ── #}
  143. <div class="bg-white rounded-xl border border-gray-200 p-6">
  144. <div class="flex items-center gap-3">
  145. <input type="checkbox" name="enabled" value="1" id="enabled"
  146. {% if not job or job.enabled %}checked{% endif %}
  147. class="rounded border-gray-300 text-blue-600">
  148. <label for="enabled" class="text-sm font-medium text-gray-700">Job activé</label>
  149. </div>
  150. </div>
  151. {# ── Actions ── #}
  152. <div class="flex gap-3">
  153. <button type="submit"
  154. class="bg-blue-600 hover:bg-blue-700 text-white px-5 py-2 rounded-lg font-medium text-sm transition">
  155. {{ 'Enregistrer' if job else 'Créer le job' }}
  156. </button>
  157. <a href="{{ url_for('index') }}"
  158. class="bg-white hover:bg-gray-50 text-gray-700 border border-gray-300 px-5 py-2 rounded-lg font-medium text-sm transition">
  159. Annuler
  160. </a>
  161. </div>
  162. </form>
  163. </div>
  164. <script>
  165. function showTypeConfig() {
  166. document.querySelectorAll('.type-cfg').forEach(el => el.classList.add('hidden'));
  167. const type = document.getElementById('job-type').value;
  168. const el = document.getElementById('cfg-' + type);
  169. if (el) el.classList.remove('hidden');
  170. }
  171. document.getElementById('job-type').addEventListener('change', showTypeConfig);
  172. showTypeConfig();
  173. </script>
  174. {% endblock %}