From 182aa2d4c93c3023a1acb7c743bf066ea060ab44 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 12 Aug 2023 11:51:29 +0200 Subject: [PATCH] use asynchronous report sending, fix #1 --- js/service.js | 29 +++++++++++++++++++++++++++++ src/Backend.php | 20 ++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 js/service.js diff --git a/js/service.js b/js/service.js new file mode 100644 index 0000000..72a3063 --- /dev/null +++ b/js/service.js @@ -0,0 +1,29 @@ +/*global $, dotclear */ +'use strict'; + +dotclear.adminDotclearWatchSendReport = () => { + dotclear.services( + 'adminDotclearWatchSendReport', + (data) => { + try { + const response = JSON.parse(data); + if (response?.success) { + } else { + console.log(dotclear.debug && response?.message ? response.message : 'Dotclear REST server error'); + return; + } + } catch (e) { + console.log(e); + } + }, + (error) => { + console.log(error); + }, + true, // Use GET method + { json: 1 }, + ); +}; + +$(() => { + dotclear.adminDotclearWatchSendReport(); +}); \ No newline at end of file diff --git a/src/Backend.php b/src/Backend.php index 2e31831..ba1e202 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -30,13 +30,25 @@ class Backend extends Process return false; } - //My::addBackendMenuItem(); - dcCore::app()->addBehaviors([ - 'adminDashboardHeaders' => [Utils::class, 'sendReport'], - 'adminPageFooterV2' => [Utils::class, 'addMark'], + 'adminDashboardHeaders' => function (): string { + return My::jsLoad('service', dcCore::app()->getVersion(My::id())); + }, + 'adminPageFooterV2' => [Utils::class, 'addMark'], ]); + dcCore::app()->rest->addFunction( + 'adminDotclearWatchSendReport', + function (): array { + Utils::sendReport(); + + return [ + 'ret' => true, + 'msg' => 'report sent', + ]; + }, + ); + return true; } }