Add popups to statistics

This commit is contained in:
grandeljay 2022-11-28 11:07:25 +01:00
parent d391d77c5b
commit 5260e2dcc8
4 changed files with 39 additions and 5 deletions

View file

@ -28,6 +28,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
$response['data'] = array(); $response['data'] = array();
foreach ($tables as $table) { foreach ($tables as $table) {
/** Get count */
$count = new Cache\Query( $count = new Cache\Query(
'SELECT COUNT(`id`) AS "count" 'SELECT COUNT(`id`) AS "count"
FROM `' . $table . '`;', FROM `' . $table . '`;',
@ -35,6 +36,20 @@ switch ($_SERVER['REQUEST_METHOD']) {
); );
$response['data'][$table] = $count->get(); $response['data'][$table] = $count->get();
/** Get last modified */
$user_time_zome = new \IntlDateFormatter(
$_SESSION['user']->getLocale()
);
$user_time_zome = $user_time_zome->getTimeZoneId();
$datetimeFormatter = new \IntlDateFormatter(
$_SESSION['user']->getLocale(),
\IntlDateFormatter::RELATIVE_FULL,
\IntlDateFormatter::SHORT,
$user_time_zome
);
$response['data']['modified'] = $datetimeFormatter->format($count->getLastModified());
} }
} else { } else {
$table = Sanitiser::getTable($_GET['table']); $table = Sanitiser::getTable($_GET['table']);

View file

@ -20,7 +20,7 @@ $(function() {
var observerCallbackWishes = (entries, observer) => { var observerCallbackWishes = (entries, observer) => {
entries.forEach(entry => { entries.forEach(entry => {
if (entry.isIntersecting) { if (entry.isIntersecting) {
showStatistic($('#wishes .value'), response.data.wishes.count, 0); showStatistic($('#wishes .value'), response.data.wishes.count, 0, response.data.modified);
observerWishes.unobserve(document.querySelector('#wishes')); observerWishes.unobserve(document.querySelector('#wishes'));
} }
@ -29,7 +29,7 @@ $(function() {
var observerCallbackWishlists = (entries, observer) => { var observerCallbackWishlists = (entries, observer) => {
entries.forEach(entry => { entries.forEach(entry => {
if (entry.isIntersecting) { if (entry.isIntersecting) {
showStatistic($('#wishlists .value'), response.data.wishlists.count, 0); showStatistic($('#wishlists .value'), response.data.wishlists.count, 0, response.data.modified);
observerWishlists.unobserve(document.querySelector('#wishlists')); observerWishlists.unobserve(document.querySelector('#wishlists'));
} }
@ -38,7 +38,7 @@ $(function() {
var observerCallbackUsers = (entries, observer) => { var observerCallbackUsers = (entries, observer) => {
entries.forEach(entry => { entries.forEach(entry => {
if (entry.isIntersecting) { if (entry.isIntersecting) {
showStatistic($('#users .value'), response.data.users.count, 0); showStatistic($('#users .value'), response.data.users.count, 0, response.data.modified);
observerUsers.unobserve(document.querySelector('#users')); observerUsers.unobserve(document.querySelector('#users'));
} }
@ -66,7 +66,7 @@ $(function() {
}); });
}); });
function showStatistic(elementStatistic, amount, timeout) { function showStatistic(elementStatistic, amount, timeout, modified) {
const duration = 2000; const duration = 2000;
const intervalInitial = 42; const intervalInitial = 42;
@ -97,4 +97,14 @@ function showStatistic(elementStatistic, amount, timeout) {
}, },
timeout timeout
); );
/** Set Popup */
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
$(elementStatistic).popup({
'title' : wishthis.strings.popup.last_modified,
'content' : modified,
'position' : 'right center',
'variation' : isDarkMode ? '' : 'inverted',
});
} }

View file

@ -147,6 +147,10 @@ global $options;
} }
} }
}, },
'popup' : {
'last_modified' : '<?= __('Last modified') ?>',
}
} }
/** /**

View file

@ -21,7 +21,7 @@ class Cache
protected function getAge(): int protected function getAge(): int
{ {
return time() - filemtime($this->getFilepath()); return time() - $this->getLastModified();
} }
protected function getIdentifier(): string protected function getIdentifier(): string
@ -65,6 +65,11 @@ class Cache
return file_exists($this->getFilepath()); return file_exists($this->getFilepath());
} }
public function getLastModified(): int
{
return filemtime($this->getFilepath());
}
public function generateCache(): bool public function generateCache(): bool
{ {
return !$this->exists() return !$this->exists()