nodebb-plugin-calendar-onekite 10.0.13 → 10.0.14
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
CHANGED
|
@@ -330,6 +330,22 @@ plugin.init = async function (params) {
|
|
|
330
330
|
isLoggedIn,
|
|
331
331
|
uid: req.uid || 0,
|
|
332
332
|
});
|
|
333
|
+
|
|
334
|
+
// Admin page route: /admin/plugins/calendar-onekite
|
|
335
|
+
const adminBuild = (middleware.admin && middleware.admin.buildHeader) ? middleware.admin.buildHeader : middleware.buildHeader;
|
|
336
|
+
router.get('/admin/plugins/calendar-onekite', ensureLoggedIn, async (req, res, next) => {
|
|
337
|
+
try {
|
|
338
|
+
const isAdmin = await user.isAdministrator(req.uid);
|
|
339
|
+
if (!isAdmin) return res.status(403).send('Forbidden');
|
|
340
|
+
next();
|
|
341
|
+
} catch (e) {
|
|
342
|
+
res.status(500).send(e.message);
|
|
343
|
+
}
|
|
344
|
+
}, adminBuild, async (req, res) => {
|
|
345
|
+
// Use NodeBB helper so ajaxify data contains template info
|
|
346
|
+
return helpers.renderAdmin(req, res, 'admin/plugins/calendar-onekite', { title: 'Calendar OneKite' });
|
|
347
|
+
});
|
|
348
|
+
|
|
333
349
|
});
|
|
334
350
|
|
|
335
351
|
// API: events
|
|
@@ -588,16 +604,6 @@ plugin.addAdminNavigation = async function (header) {
|
|
|
588
604
|
return header;
|
|
589
605
|
};
|
|
590
606
|
|
|
591
|
-
plugin.addPageRoute = async function (data) {
|
|
592
|
-
// ensure /calendar works as "page route" for theme router filter edge cases
|
|
593
|
-
data.router.get('/calendar', data.middleware.buildHeader, async (req, res) => {
|
|
594
|
-
res.render('calendar-onekite/calendar', {
|
|
595
|
-
title: 'Calendrier',
|
|
596
|
-
isLoggedIn: !!req.uid,
|
|
597
|
-
uid: req.uid || 0,
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
return data;
|
|
601
|
-
};
|
|
607
|
+
plugin.addPageRoute = async function (data) { return data; };
|
|
602
608
|
|
|
603
609
|
module.exports = plugin;
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -12,18 +12,14 @@
|
|
|
12
12
|
{
|
|
13
13
|
"hook": "filter:admin.header.build",
|
|
14
14
|
"method": "addAdminNavigation"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"hook": "filter:router.page",
|
|
18
|
-
"method": "addPageRoute"
|
|
19
15
|
}
|
|
20
16
|
],
|
|
21
17
|
"templates": "templates",
|
|
22
18
|
"staticDirs": {
|
|
23
|
-
"
|
|
19
|
+
"public": "./public"
|
|
24
20
|
},
|
|
25
21
|
"acpScripts": [
|
|
26
|
-
"public/
|
|
22
|
+
"public/lib/admin/plugins/calendar-onekite.js"
|
|
27
23
|
],
|
|
28
24
|
"scripts": [
|
|
29
25
|
"public/js/calendar-onekite.js"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* global define, $, app */
|
|
2
|
+
|
|
3
|
+
define('admin/plugins/calendar-onekite', ['settings'], function (Settings) {
|
|
4
|
+
const ACP = {};
|
|
5
|
+
|
|
6
|
+
function setStatus(html, type) {
|
|
7
|
+
const el = $('#calendar-onekite-admin-status');
|
|
8
|
+
el.html(`<div class="alert alert-${type || 'info'}">${html}</div>`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
ACP.init = function () {
|
|
12
|
+
Settings.load('calendar-onekite', $('.calendar-onekite-settings'));
|
|
13
|
+
|
|
14
|
+
$('#calendar-onekite-save').on('click', function () {
|
|
15
|
+
Settings.save('calendar-onekite', $('.calendar-onekite-settings'), function () {
|
|
16
|
+
setStatus('Sauvegardé ✅', 'success');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
$('#calendar-onekite-test-items').on('click', async function () {
|
|
21
|
+
try {
|
|
22
|
+
const res = await $.getJSON('/api/calendar-onekite/items');
|
|
23
|
+
setStatus(`Items récupérés: <strong>${(res.items || []).length}</strong>`, 'info');
|
|
24
|
+
} catch (e) {
|
|
25
|
+
const err = (e.responseJSON && e.responseJSON.error) ? e.responseJSON.error : e.statusText;
|
|
26
|
+
setStatus(`Erreur items: ${err}`, 'danger');
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
$('#calendar-onekite-purge').on('click', async function () {
|
|
31
|
+
const year = parseInt($('#calendar-onekite-purge-year').val(), 10);
|
|
32
|
+
if (!year) return setStatus('Année invalide', 'warning');
|
|
33
|
+
if (!confirm(`Purger toutes les réservations dont le début est en ${year} ?`)) return;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const res = await $.ajax({
|
|
37
|
+
url: '/api/admin/plugins/calendar-onekite/purge',
|
|
38
|
+
method: 'POST',
|
|
39
|
+
data: { year },
|
|
40
|
+
});
|
|
41
|
+
setStatus(`Purge terminée. Supprimés: <strong>${res.deleted}</strong>`, 'success');
|
|
42
|
+
} catch (e) {
|
|
43
|
+
const err = (e.responseJSON && e.responseJSON.error) ? e.responseJSON.error : e.statusText;
|
|
44
|
+
setStatus(`Erreur purge: ${err}`, 'danger');
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return ACP;
|
|
50
|
+
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Les groupes sont à renseigner par <strong>noms de groupes</strong> séparés par des virgules (ex: <code>administrators, booking-approvers</code>).
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
|
-
<
|
|
8
|
+
<div class="calendar-onekite-settings">
|
|
9
9
|
<div class="mb-3">
|
|
10
10
|
<label class="form-label">Activer le plugin</label>
|
|
11
11
|
<div class="form-check">
|
|
@@ -95,10 +95,10 @@
|
|
|
95
95
|
</div>
|
|
96
96
|
|
|
97
97
|
<div class="mt-4 d-flex gap-2">
|
|
98
|
-
<button class="btn btn-primary" type="
|
|
98
|
+
<button class="btn btn-primary" type="button" id="calendar-onekite-save">Sauvegarder</button>
|
|
99
99
|
<button class="btn btn-outline-secondary" type="button" id="calendar-onekite-test-items">Tester la récupération des items</button>
|
|
100
100
|
</div>
|
|
101
|
-
</
|
|
101
|
+
</div>
|
|
102
102
|
|
|
103
103
|
<hr class="my-4"/>
|
|
104
104
|
|