@@ -72,11 +72,14 @@ PulseApp.ui.settings = (() => {
72
72
// Load current configuration
73
73
try {
74
74
await loadCurrentConfig ( ) ;
75
- renderConfigurationForm ( ) ;
76
75
} catch ( error ) {
77
76
console . error ( '[Settings] Failed to load configuration:' , error ) ;
78
- body . innerHTML = `<div class="text-red-600 dark:text-red-400">Failed to load configuration: ${ error . message } </div>` ;
77
+ // Initialize with empty config to prevent errors
78
+ currentConfig = { } ;
79
79
}
80
+
81
+ // Always render the form, even if config loading failed
82
+ renderConfigurationForm ( ) ;
80
83
}
81
84
82
85
function closeModal ( ) {
@@ -96,7 +99,8 @@ PulseApp.ui.settings = (() => {
96
99
throw new Error ( `HTTP ${ response . status } ` ) ;
97
100
}
98
101
99
- currentConfig = await response . json ( ) ;
102
+ const configData = await response . json ( ) ;
103
+ currentConfig = configData || { } ; // Ensure we never have null/undefined
100
104
console . log ( '[Settings] Current config loaded:' , currentConfig ) ;
101
105
102
106
} catch ( error ) {
@@ -109,6 +113,13 @@ PulseApp.ui.settings = (() => {
109
113
const body = document . getElementById ( 'settings-modal-body' ) ;
110
114
if ( ! body ) return ;
111
115
116
+ // Ensure currentConfig has a safe default structure
117
+ const safeConfig = currentConfig || { } ;
118
+ const proxmox = safeConfig . proxmox || { } ;
119
+ const pbs = safeConfig . pbs || { } ;
120
+ const advanced = safeConfig . advanced || { } ;
121
+ const alerts = advanced . alerts || { } ;
122
+
112
123
const html = `
113
124
<form id="settings-form" class="space-y-6">
114
125
<!-- Proxmox VE Primary Endpoint -->
@@ -120,14 +131,14 @@ PulseApp.ui.settings = (() => {
120
131
Host Address <span class="text-red-500">*</span>
121
132
</label>
122
133
<input type="text" name="PROXMOX_HOST" required
123
- value="${ currentConfig . proxmox ? .host || '' } "
134
+ value="${ proxmox . host || '' } "
124
135
placeholder="https://proxmox.example.com:8006"
125
136
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
126
137
</div>
127
138
<div>
128
139
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Port</label>
129
140
<input type="number" name="PROXMOX_PORT"
130
- value="${ currentConfig . proxmox ? .port || '' } "
141
+ value="${ proxmox . port || '' } "
131
142
placeholder="8006"
132
143
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
133
144
</div>
@@ -136,7 +147,7 @@ PulseApp.ui.settings = (() => {
136
147
Node Name
137
148
</label>
138
149
<input type="text" name="PROXMOX_NODE_NAME"
139
- value="${ currentConfig . proxmox ? .nodeName || '' } "
150
+ value="${ proxmox . nodeName || '' } "
140
151
placeholder="Display name (optional)"
141
152
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
142
153
</div>
@@ -145,7 +156,7 @@ PulseApp.ui.settings = (() => {
145
156
API Token ID <span class="text-red-500">*</span>
146
157
</label>
147
158
<input type="text" name="PROXMOX_TOKEN_ID" required
148
- value="${ currentConfig . proxmox ? .tokenId || '' } "
159
+ value="${ proxmox . tokenId || '' } "
149
160
placeholder="root@pam!token-name"
150
161
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
151
162
</div>
@@ -159,7 +170,7 @@ PulseApp.ui.settings = (() => {
159
170
</div>
160
171
<div>
161
172
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Enabled</label>
162
- <input type="checkbox" name="PROXMOX_ENABLED" ${ currentConfig . proxmox ? .enabled !== false ? 'checked' : '' }
173
+ <input type="checkbox" name="PROXMOX_ENABLED" ${ proxmox . enabled !== false ? 'checked' : '' }
163
174
class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
164
175
</div>
165
176
</div>
@@ -184,14 +195,14 @@ PulseApp.ui.settings = (() => {
184
195
<div>
185
196
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Host Address</label>
186
197
<input type="text" name="PBS_HOST"
187
- value="${ currentConfig . pbs ? .host || '' } "
198
+ value="${ pbs . host || '' } "
188
199
placeholder="https://pbs.example.com:8007"
189
200
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
190
201
</div>
191
202
<div>
192
203
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Port</label>
193
204
<input type="number" name="PBS_PORT"
194
- value="${ currentConfig . pbs ? .port || '' } "
205
+ value="${ pbs . port || '' } "
195
206
placeholder="8007"
196
207
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
197
208
</div>
@@ -200,14 +211,14 @@ PulseApp.ui.settings = (() => {
200
211
Node Name
201
212
</label>
202
213
<input type="text" name="PBS_NODE_NAME"
203
- value="${ currentConfig . pbs ? .nodeName || '' } "
214
+ value="${ pbs . nodeName || '' } "
204
215
placeholder="PBS internal hostname"
205
216
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
206
217
</div>
207
218
<div>
208
219
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">API Token ID</label>
209
220
<input type="text" name="PBS_TOKEN_ID"
210
- value="${ currentConfig . pbs ? .tokenId || '' } "
221
+ value="${ pbs . tokenId || '' } "
211
222
placeholder="root@pam!token-name"
212
223
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
213
224
</div>
@@ -241,7 +252,7 @@ PulseApp.ui.settings = (() => {
241
252
Metric Update Interval (ms)
242
253
</label>
243
254
<input type="number" name="PULSE_METRIC_INTERVAL_MS"
244
- value="${ currentConfig . advanced ? .metricInterval || '' } "
255
+ value="${ advanced . metricInterval || '' } "
245
256
placeholder="2000 (default)"
246
257
min="1000" max="60000"
247
258
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
@@ -252,7 +263,7 @@ PulseApp.ui.settings = (() => {
252
263
Discovery Interval (ms)
253
264
</label>
254
265
<input type="number" name="PULSE_DISCOVERY_INTERVAL_MS"
255
- value="${ currentConfig . advanced ? .discoveryInterval || '' } "
266
+ value="${ advanced . discoveryInterval || '' } "
256
267
placeholder="30000 (default)"
257
268
min="5000" max="300000"
258
269
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
@@ -267,22 +278,22 @@ PulseApp.ui.settings = (() => {
267
278
268
279
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-4">
269
280
<label class="flex items-center">
270
- <input type="checkbox" name="ALERT_CPU_ENABLED" ${ currentConfig . advanced ?. alerts ? .cpu ?. enabled !== false ? 'checked' : '' }
281
+ <input type="checkbox" name="ALERT_CPU_ENABLED" ${ alerts . cpu ?. enabled !== false ? 'checked' : '' }
271
282
class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
272
283
<span class="text-sm text-gray-700 dark:text-gray-300">CPU Alerts</span>
273
284
</label>
274
285
<label class="flex items-center">
275
- <input type="checkbox" name="ALERT_MEMORY_ENABLED" ${ currentConfig . advanced ?. alerts ? .memory ?. enabled !== false ? 'checked' : '' }
286
+ <input type="checkbox" name="ALERT_MEMORY_ENABLED" ${ alerts . memory ?. enabled !== false ? 'checked' : '' }
276
287
class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
277
288
<span class="text-sm text-gray-700 dark:text-gray-300">Memory Alerts</span>
278
289
</label>
279
290
<label class="flex items-center">
280
- <input type="checkbox" name="ALERT_DISK_ENABLED" ${ currentConfig . advanced ?. alerts ? .disk ?. enabled !== false ? 'checked' : '' }
291
+ <input type="checkbox" name="ALERT_DISK_ENABLED" ${ alerts . disk ?. enabled !== false ? 'checked' : '' }
281
292
class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
282
293
<span class="text-sm text-gray-700 dark:text-gray-300">Disk Alerts</span>
283
294
</label>
284
295
<label class="flex items-center">
285
- <input type="checkbox" name="ALERT_DOWN_ENABLED" ${ currentConfig . advanced ?. alerts ? .down ?. enabled !== false ? 'checked' : '' }
296
+ <input type="checkbox" name="ALERT_DOWN_ENABLED" ${ alerts . down ?. enabled !== false ? 'checked' : '' }
286
297
class="mr-2 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
287
298
<span class="text-sm text-gray-700 dark:text-gray-300">Down Alerts</span>
288
299
</label>
@@ -294,7 +305,7 @@ PulseApp.ui.settings = (() => {
294
305
CPU Threshold (%)
295
306
</label>
296
307
<input type="number" name="ALERT_CPU_THRESHOLD"
297
- value="${ currentConfig . advanced ?. alerts ? .cpu ?. threshold || '' } "
308
+ value="${ alerts . cpu ?. threshold || '' } "
298
309
placeholder="85 (default)"
299
310
min="50" max="100"
300
311
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
@@ -304,7 +315,7 @@ PulseApp.ui.settings = (() => {
304
315
Memory Threshold (%)
305
316
</label>
306
317
<input type="number" name="ALERT_MEMORY_THRESHOLD"
307
- value="${ currentConfig . advanced ?. alerts ? .memory ?. threshold || '' } "
318
+ value="${ alerts . memory ?. threshold || '' } "
308
319
placeholder="90 (default)"
309
320
min="50" max="100"
310
321
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
@@ -314,7 +325,7 @@ PulseApp.ui.settings = (() => {
314
325
Disk Threshold (%)
315
326
</label>
316
327
<input type="number" name="ALERT_DISK_THRESHOLD"
317
- value="${ currentConfig . advanced ?. alerts ? .disk ?. threshold || '' } "
328
+ value="${ alerts . disk ?. threshold || '' } "
318
329
placeholder="95 (default)"
319
330
min="50" max="100"
320
331
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
0 commit comments