mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-01 10:56:08 +01:00
Fixed notifications that would not be remembered as hidden + various improvements
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
# v1.10.0
|
# v1.10.0
|
||||||
## mm/dd/mmmm
|
## mm/dd/mmmm
|
||||||
|
|
||||||
|
1. [](#improved)
|
||||||
|
* Various notifications improvements
|
||||||
1. [](#bugfix)
|
1. [](#bugfix)
|
||||||
* Fixed missed highlight on the selected page in Parents field
|
* Fixed missed highlight on the selected page in Parents field
|
||||||
|
* Fixed notifications that would not be remembered as hidden
|
||||||
|
|
||||||
# v1.10.0-rc.20
|
# v1.10.0-rc.20
|
||||||
## 12/14/2020
|
## 12/14/2020
|
||||||
|
|||||||
@@ -1577,10 +1577,14 @@ class Admin
|
|||||||
{
|
{
|
||||||
$last_checked = null;
|
$last_checked = null;
|
||||||
$filename = $this->grav['locator']->findResource('user://data/notifications/' . md5($this->grav['user']->username) . YAML_EXT, true, true);
|
$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_file = CompiledYamlFile::instance($filename);
|
||||||
$notifications_content = (array)$notifications_file->content();
|
$notifications_content = (array)$notifications_file->content();
|
||||||
|
|
||||||
|
$userStatus_file = CompiledYamlFile::instance($userStatus);
|
||||||
|
$userStatus_content = (array)$userStatus_file->content();
|
||||||
|
|
||||||
$last_checked = $notifications_content['last_checked'] ?? null;
|
$last_checked = $notifications_content['last_checked'] ?? null;
|
||||||
$notifications = $notifications_content['data'] ?? array();
|
$notifications = $notifications_content['data'] ?? array();
|
||||||
$timeout = $this->grav['config']->get('system.session.timeout', 1800);
|
$timeout = $this->grav['config']->get('system.session.timeout', 1800);
|
||||||
@@ -1643,6 +1647,27 @@ class Admin
|
|||||||
$notifications_file->save();
|
$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;
|
return $notifications;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -551,11 +551,12 @@ class AdminController extends AdminBaseController
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT,
|
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
|
||||||
true, true);
|
|
||||||
$file = CompiledYamlFile::instance($filename);
|
$file = CompiledYamlFile::instance($filename);
|
||||||
$data = (array)$file->content();
|
$data = (array)$file->content();
|
||||||
$data[] = $notification_id;
|
|
||||||
|
$date = new \DateTime();
|
||||||
|
$data[$notification_id] = $date->format('r');
|
||||||
$file->save($data);
|
$file->save($data);
|
||||||
|
|
||||||
$this->admin->json_response = [
|
$this->admin->json_response = [
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ export default notifications;
|
|||||||
if (canFetchNotifications()) {
|
if (canFetchNotifications()) {
|
||||||
notifications.fetch();
|
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>
|
// <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) => {
|
$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
|
||||||
let notification_id = $(event.target).parents('.hide-notification').data('notification-id');
|
let notification_id = $(event.target).parents('.hide-notification').data('notification-id');
|
||||||
@@ -149,7 +149,6 @@ if (canFetchNotifications()) {
|
|||||||
|
|
||||||
$(event.target).parents('.single-notification').hide();
|
$(event.target).parents('.single-notification').hide();
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
|
$(document).on('click', '[data-notification-action="hide-notification"]', (event) => {
|
||||||
const target = $(event.currentTarget);
|
const target = $(event.currentTarget);
|
||||||
|
|||||||
17
themes/grav/js/admin.min.js
vendored
17
themes/grav/js/admin.min.js
vendored
@@ -1243,16 +1243,17 @@ var notifications = new Notifications();
|
|||||||
|
|
||||||
if (canFetchNotifications()) {
|
if (canFetchNotifications()) {
|
||||||
notifications.fetch();
|
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>
|
// <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) {
|
external_jQuery_default()(document).on('click', '[data-notification-action="hide-notification"]', function (event) {
|
||||||
var target = external_jQuery_default()(event.currentTarget);
|
var target = external_jQuery_default()(event.currentTarget);
|
||||||
var notification = target.parent();
|
var notification = target.parent();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% for entry_id, entry in notifications %}
|
{% for entry_id, entry in notifications %}
|
||||||
<div class="alert {{ entry.type }} position-dashboard">
|
<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 }}
|
{{ entry.message|raw }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% for entry_id, entry in notifications %}
|
{% for entry_id, entry in notifications %}
|
||||||
<div class="alert {{ entry.type }} position-plugins">
|
<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 }}
|
{{ entry.message|raw }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% for entry_id, entry in notifications %}
|
{% for entry_id, entry in notifications %}
|
||||||
<div class="alert {{ entry.type }} position-themes">
|
<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 }}
|
{{ entry.message|raw }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% for entry_id, entry in notifications %}
|
{% for entry_id, entry in notifications %}
|
||||||
<div class="alert {{ entry.type }} position-top">
|
<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 }}
|
{{ entry.message|raw }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user