Skip to content

Commit f020687

Browse files
committed
ui(settings): show init .env.local prompt and button when /api/env returns empty or errors
1 parent a3baad8 commit f020687

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

ui/static/js/app.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,42 @@ async function loadEnv() {
2222
const container = document.getElementById('env-form');
2323
container.innerHTML = '';
2424

25+
// If API failed or returned empty, still offer to initialize .env.local
26+
if (!data || (Array.isArray(data) && data.length === 0)) {
27+
const msg = document.createElement('div');
28+
msg.style.marginBottom = '8px';
29+
msg.style.color = '#b33';
30+
msg.innerText = 'Aucun paramètre trouvé — vous pouvez initialiser .env.local à partir du modèle.';
31+
container.appendChild(msg);
32+
// Show init button (reuse existing init endpoint flow)
33+
const initDiv = document.createElement('div');
34+
initDiv.style.marginTop = '10px';
35+
initDiv.innerHTML = `<button id="btn-init-env" class="secondary">Initialiser .env.local</button> <span style="color:#888; font-size:12px; margin-left:8px;">Crée .env.local à partir de .env.example</span>`;
36+
container.appendChild(initDiv);
37+
document.getElementById('btn-init-env').addEventListener('click', async () => {
38+
if (!confirm('Créer .env.local à partir de .env.example ?')) return;
39+
const btn = document.getElementById('btn-init-env');
40+
btn.disabled = true;
41+
btn.innerText = 'Initialisation...';
42+
try {
43+
const r = await fetch('/api/env/init', {method: 'POST'});
44+
const j = await r.json();
45+
if (j.error) alert('Erreur: ' + j.error);
46+
else {
47+
alert('.env.local créé');
48+
// reload form
49+
loadEnv();
50+
}
51+
} catch (e) {
52+
alert('Request failed: ' + e);
53+
} finally {
54+
btn.disabled = false;
55+
btn.innerText = 'Initialiser .env.local';
56+
}
57+
});
58+
return;
59+
}
60+
2561
// data is now an array of {key, value, desc}
2662
data.forEach(item => {
2763
const div = document.createElement('div');

0 commit comments

Comments
 (0)