use asynchronous report sending, fix #1

master
Jean-Christian Paul Denis 2023-08-12 11:51:29 +02:00
parent 2441981717
commit 182aa2d4c9
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
2 changed files with 45 additions and 4 deletions

29
js/service.js 100644
View File

@ -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();
});

View File

@ -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;
}
}