job_form.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. ('custom_dir','Répertoire custom (Phase 2)'), ('mysql','MySQL (Phase 2)'),
  27. ('postgresql','PostgreSQL (Phase 2)')] %}
  28. <option value="{{ val }}"
  29. {% if job and job.type == val %}selected{% endif %}
  30. {% if val in ('custom_dir','mysql','postgresql') %}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. </div>
  72. {# ── Planification ── #}
  73. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  74. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Planification</h2>
  75. <div>
  76. <label class="block text-sm font-medium text-gray-700 mb-1">Expression cron</label>
  77. <input type="text" name="cron_expr" required
  78. value="{{ job.cron_expr if job else '0 3 * * *' }}"
  79. placeholder="0 3 * * *"
  80. 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">
  81. <p class="text-xs text-gray-400 mt-1">
  82. Format : minute heure jour mois jour_semaine
  83. — ex: <code class="bg-gray-100 px-1 rounded">0 3 * * *</code> = tous les jours à 3h
  84. · <code class="bg-gray-100 px-1 rounded">0 3 * * 1</code> = chaque lundi à 3h
  85. </p>
  86. </div>
  87. </div>
  88. {# ── Rétention ── #}
  89. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  90. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Rétention</h2>
  91. <div class="grid grid-cols-2 gap-4">
  92. <div>
  93. <label class="block text-sm font-medium text-gray-700 mb-1">Mode</label>
  94. <select name="retention_mode"
  95. 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">
  96. {% for val, label in [('count','Count — N dernières archives'),
  97. ('daily','Daily — 1 par jour sur N jours'),
  98. ('gfs','GFS — Grand/Père/Fils (Phase 4)')] %}
  99. <option value="{{ val }}"
  100. {% if job and job.retention_mode == val %}selected{% endif %}
  101. {% if val == 'gfs' %}disabled class="text-gray-400"{% endif %}>
  102. {{ label }}
  103. </option>
  104. {% endfor %}
  105. </select>
  106. </div>
  107. <div>
  108. <label class="block text-sm font-medium text-gray-700 mb-1">Valeur</label>
  109. <input type="number" name="retention_value" min="1" max="365" required
  110. value="{{ job.retention_value if job else 7 }}"
  111. 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">
  112. </div>
  113. </div>
  114. </div>
  115. {# ── Options ── #}
  116. <div class="bg-white rounded-xl border border-gray-200 p-6">
  117. <div class="flex items-center gap-3">
  118. <input type="checkbox" name="enabled" value="1" id="enabled"
  119. {% if not job or job.enabled %}checked{% endif %}
  120. class="rounded border-gray-300 text-blue-600">
  121. <label for="enabled" class="text-sm font-medium text-gray-700">Job activé</label>
  122. </div>
  123. </div>
  124. {# ── Actions ── #}
  125. <div class="flex gap-3">
  126. <button type="submit"
  127. class="bg-blue-600 hover:bg-blue-700 text-white px-5 py-2 rounded-lg font-medium text-sm transition">
  128. {{ 'Enregistrer' if job else 'Créer le job' }}
  129. </button>
  130. <a href="{{ url_for('index') }}"
  131. 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">
  132. Annuler
  133. </a>
  134. </div>
  135. </form>
  136. </div>
  137. <script>
  138. function showTypeConfig() {
  139. document.querySelectorAll('.type-cfg').forEach(el => el.classList.add('hidden'));
  140. const type = document.getElementById('job-type').value;
  141. const el = document.getElementById('cfg-' + type);
  142. if (el) el.classList.remove('hidden');
  143. }
  144. document.getElementById('job-type').addEventListener('change', showTypeConfig);
  145. showTypeConfig();
  146. </script>
  147. {% endblock %}