nodebb-plugin-equipment-calendar 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +14 -42
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/public/templates/admin/plugins/equipment-calendar.tpl +3 -17
package/library.js
CHANGED
|
@@ -29,7 +29,7 @@ const DEFAULT_SETTINGS = {
|
|
|
29
29
|
notifyGroup: 'administrators',
|
|
30
30
|
// JSON array of items: [{ "id": "cam1", "name": "Caméra A", "price": 5000, "location": "Stock A", "active": true }]
|
|
31
31
|
itemsJson: '[]',
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
ha_itemsFormType: '',
|
|
34
34
|
ha_itemsFormSlug: '',
|
|
35
35
|
|
|
@@ -275,47 +275,20 @@ async function fetchHelloAssoItems(settings) {
|
|
|
275
275
|
return out;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
function parseItems(itemsJson) {
|
|
279
|
-
try {
|
|
280
|
-
const arr = JSON.parse(itemsJson || '[]');
|
|
281
|
-
if (!Array.isArray(arr)) return [];
|
|
282
|
-
return arr.map(it => ({
|
|
283
|
-
id: String(it.id || '').trim(),
|
|
284
|
-
name: String(it.name || '').trim(),
|
|
285
|
-
price: Number(it.price || 0),
|
|
286
|
-
location: String(it.location || '').trim(),
|
|
287
|
-
active: it.active !== false,
|
|
288
|
-
})).filter(it => it.id && it.name);
|
|
289
|
-
} catch (e) {
|
|
290
|
-
return [];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
278
|
|
|
294
|
-
async function getActiveItems(settings) {
|
|
295
|
-
const source = String(settings.itemsSource || 'manual');
|
|
296
|
-
if (source === 'helloasso') {
|
|
297
|
-
const rawItems = await fetchHelloAssoItems(settings); return (rawItems || []).map((it) => {
|
|
298
|
-
const id = String(it.id || it.itemId || it.reference || it.slug || it.name || '').trim();
|
|
299
|
-
const name = String(it.name || it.label || it.title || id).trim();
|
|
300
|
-
// Price handling is not displayed in the public calendar, keep a field if you want later
|
|
301
|
-
const priceRaw =
|
|
302
|
-
(it.price && (it.price.value || it.price.amount)) ||
|
|
303
|
-
(it.amount && (it.amount.value || it.amount)) ||
|
|
304
|
-
it.price;
|
|
305
|
-
const price = (typeof priceRaw === 'number' ? priceRaw : parseInt(priceRaw, 10)) || 0;
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
id: id || name,
|
|
309
|
-
name,
|
|
310
|
-
price,
|
|
311
|
-
active: true,
|
|
312
|
-
source: 'helloasso',
|
|
313
|
-
};
|
|
314
|
-
}).filter(i => i.id);
|
|
315
|
-
}
|
|
316
279
|
|
|
317
|
-
|
|
318
|
-
|
|
280
|
+
async function getActiveItems() {
|
|
281
|
+
const settings = await getSettings();
|
|
282
|
+
const rawItems = await fetchHelloAssoItems(settings);
|
|
283
|
+
// Normalize
|
|
284
|
+
const items = (Array.isArray(rawItems) ? rawItems : []).map((it) => ({
|
|
285
|
+
id: String(it.id || '').trim(),
|
|
286
|
+
name: String(it.name || '').trim(),
|
|
287
|
+
price: String(it.price || '0').trim(),
|
|
288
|
+
active: true,
|
|
289
|
+
})).filter(it => it.id && it.name);
|
|
290
|
+
|
|
291
|
+
return items;
|
|
319
292
|
}
|
|
320
293
|
|
|
321
294
|
async function getSettings() {
|
|
@@ -1426,8 +1399,7 @@ async function handleAdminSave(req, res) {
|
|
|
1426
1399
|
creatorGroups: String(req.body.creatorGroups || DEFAULT_SETTINGS.creatorGroups),
|
|
1427
1400
|
approverGroup: String(req.body.approverGroup || DEFAULT_SETTINGS.approverGroup),
|
|
1428
1401
|
notifyGroup: String(req.body.notifyGroup || DEFAULT_SETTINGS.notifyGroup),
|
|
1429
|
-
itemsJson:
|
|
1430
|
-
itemsSource: String(req.body.itemsSource || DEFAULT_SETTINGS.itemsSource),
|
|
1402
|
+
itemsJson: '[]',
|
|
1431
1403
|
ha_itemsFormType: String(req.body.ha_itemsFormType || DEFAULT_SETTINGS.ha_itemsFormType),
|
|
1432
1404
|
ha_itemsFormSlug: String(req.body.ha_itemsFormSlug || DEFAULT_SETTINGS.ha_itemsFormSlug),
|
|
1433
1405
|
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -33,23 +33,9 @@
|
|
|
33
33
|
</div>
|
|
34
34
|
</div>
|
|
35
35
|
|
|
36
|
+
|
|
36
37
|
<div class="card card-body mb-3">
|
|
37
|
-
<h5>
|
|
38
|
-
|
|
39
|
-
<div class="mb-3">
|
|
40
|
-
<label class="form-label">Source du matériel</label>
|
|
41
|
-
<select class="form-select" name="itemsSource">
|
|
42
|
-
<option value="manual" {{{ if view_itemsSourceManual }}}selected{{{ end }}}>Manuel (JSON)</option>
|
|
43
|
-
<option value="helloasso" {{{ if view_itemsSourceHelloasso }}}selected{{{ end }}}>HelloAsso (catalogue)</option>
|
|
44
|
-
</select>
|
|
45
|
-
</div>
|
|
46
|
-
|
|
47
|
-
<div class="mb-3">
|
|
48
|
-
<label class="form-label">Matériel (JSON) — utilisé si Source = Manuel</label>
|
|
49
|
-
<textarea class="form-control" name="itemsJson" rows="8">{settings.itemsJson}</textarea>
|
|
50
|
-
<div class="form-text">Format: <code>[{"id":"cam1","name":"Caméra","price":50,"active":true}]</code> — <code>price</code> en euros (unitaire / jour).</div>
|
|
51
|
-
</div>
|
|
52
|
-
|
|
38
|
+
<h5>Paiement</h5>
|
|
53
39
|
<div class="mb-0">
|
|
54
40
|
<label class="form-label">Timeout paiement (minutes)</label>
|
|
55
41
|
<input class="form-control" type="number" min="1" name="paymentTimeoutMinutes" value="{settings.paymentTimeoutMinutes}">
|
|
@@ -57,7 +43,7 @@
|
|
|
57
43
|
</div>
|
|
58
44
|
</div>
|
|
59
45
|
|
|
60
|
-
|
|
46
|
+
<div class="card card-body mb-3">
|
|
61
47
|
<h5>HelloAsso</h5>
|
|
62
48
|
|
|
63
49
|
<div class="mb-3">
|