Fixed notifications that would not be remembered as hidden + various improvements

This commit is contained in:
Djamil Legato
2020-12-21 15:29:42 -08:00
parent 06719a23dd
commit 72116dcbca
9 changed files with 46 additions and 17 deletions

View File

@@ -1,8 +1,11 @@
# v1.10.0
## mm/dd/mmmm
1. [](#improved)
* Various notifications improvements
1. [](#bugfix)
* Fixed missed highlight on the selected page in Parents field
* Fixed notifications that would not be remembered as hidden
# v1.10.0-rc.20
## 12/14/2020

View File

@@ -1577,10 +1577,14 @@ class Admin
{
$last_checked = null;
$filename = $this->grav['locator']->findResource('user://data/notifications/' . md5($this->grav['user']->username) . YAML_EXT, true, true);
$userStatus = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
$notifications_file = CompiledYamlFile::instance($filename);
$notifications_content = (array)$notifications_file->content();
$userStatus_file = CompiledYamlFile::instance($userStatus);
$userStatus_content = (array)$userStatus_file->content();
$last_checked = $notifications_content['last_checked'] ?? null;
$notifications = $notifications_content['data'] ?? array();
$timeout = $this->grav['config']->get('system.session.timeout', 1800);
@@ -1643,6 +1647,27 @@ class Admin
$notifications_file->save();
}
foreach ($notifications as $location => $list) {
$notifications[$location] = array_filter($list, function ($notification) use ($userStatus_content) {
$element = $userStatus_content[$notification['id']] ?? null;
if (isset($element)) {
if (isset($notification['reappear_after'])) {
$now = new \DateTime();
$hidden_on = new \DateTime($element);
$hidden_on->modify($notification['reappear_after']);
if ($now >= $hidden_on) {
return true;
}
}
return false;
}
return true;
});
}
return $notifications;
}

View File

@@ -551,11 +551,12 @@ class AdminController extends AdminBaseController
return false;
}
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT,
true, true);
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
$file = CompiledYamlFile::instance($filename);
$data = (array)$file->content();
$data[] = $notification_id;
$date = new \DateTime();
$data[$notification_id] = $date->format('r');
$file->save($data);
$this->admin->json_response = [

View File

@@ -138,7 +138,7 @@ export default notifications;
if (canFetchNotifications()) {
notifications.fetch();
/* Hide a notification and store it hidden
/* Hide a notification and store it hidden */
// <a href="#" data-notification-action="hide-notification" data-notification-id="${notification.id}" class="close hide-notification"><i class="fa fa-close"></i></a>
$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
let notification_id = $(event.target).parents('.hide-notification').data('notification-id');
@@ -149,7 +149,6 @@ if (canFetchNotifications()) {
$(event.target).parents('.single-notification').hide();
});
*/
$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
const target = $(event.currentTarget);

View File

@@ -1243,16 +1243,17 @@ var notifications = new Notifications();
if (canFetchNotifications()) {
notifications.fetch();
/* Hide a notification and store it hidden
/* Hide a notification and store it hidden */
// <a href="#" data-notification-action="hide-notification" data-notification-id="${notification.id}" class="close hide-notification"><i class="fa fa-close"></i></a>
$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
let notification_id = $(event.target).parents('.hide-notification').data('notification-id');
let url = `${config.base_url_relative}/notifications.json/task${config.param_sep}hideNotification/notification_id${config.param_sep}${notification_id}`;
request(url, { method: 'post' }, () => {});
$(event.target).parents('.single-notification').hide();
});
*/
external_jQuery_default()(document).on('click', '[data-notification-action="hide-notification"]', function (event) {
var notification_id = external_jQuery_default()(event.target).parents('.hide-notification').data('notification-id');
var url = "".concat(external_GravAdmin_namespaceObject.config.base_url_relative, "/notifications.json/task").concat(external_GravAdmin_namespaceObject.config.param_sep, "hideNotification/notification_id").concat(external_GravAdmin_namespaceObject.config.param_sep).concat(notification_id);
utils_request(url, {
method: 'post'
}, function () {});
external_jQuery_default()(event.target).parents('.single-notification').hide();
});
external_jQuery_default()(document).on('click', '[data-notification-action="hide-notification"]', function (event) {
var target = external_jQuery_default()(event.currentTarget);
var notification = target.parent();

View File

@@ -1,6 +1,6 @@
{% for entry_id, entry in notifications %}
<div class="alert {{ entry.type }} position-dashboard">
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry_id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry.id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
{{ entry.message|raw }}
</div>
{% endfor %}

View File

@@ -1,6 +1,6 @@
{% for entry_id, entry in notifications %}
<div class="alert {{ entry.type }} position-plugins">
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry_id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry.id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
{{ entry.message|raw }}
</div>
{% endfor %}

View File

@@ -1,6 +1,6 @@
{% for entry_id, entry in notifications %}
<div class="alert {{ entry.type }} position-themes">
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry_id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry.id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
{{ entry.message|raw }}
</div>
{% endfor %}

View File

@@ -1,6 +1,6 @@
{% for entry_id, entry in notifications %}
<div class="alert {{ entry.type }} position-top">
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry_id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
<a href="#" data-notification-action="hide-notification" data-notification-id="{{ entry.id }}" class="close hide-notification"><i class="fa fa-close"></i></a>
{{ entry.message|raw }}
</div>
{% endfor %}