diff --git a/CHANGELOG.md b/CHANGELOG.md index a663f87c..041682f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/classes/plugin/Admin.php b/classes/plugin/Admin.php index 124b64b4..c32487d3 100644 --- a/classes/plugin/Admin.php +++ b/classes/plugin/Admin.php @@ -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; } diff --git a/classes/plugin/AdminController.php b/classes/plugin/AdminController.php index 93b97505..9f19f1a0 100644 --- a/classes/plugin/AdminController.php +++ b/classes/plugin/AdminController.php @@ -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 = [ diff --git a/themes/grav/app/updates/notifications.js b/themes/grav/app/updates/notifications.js index b58b1153..046dff87 100644 --- a/themes/grav/app/updates/notifications.js +++ b/themes/grav/app/updates/notifications.js @@ -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 */ // $(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); diff --git a/themes/grav/js/admin.min.js b/themes/grav/js/admin.min.js index 156349da..9d7b71c9 100644 --- a/themes/grav/js/admin.min.js +++ b/themes/grav/js/admin.min.js @@ -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 */ // - $(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(); diff --git a/themes/grav/templates/partials/notification-dashboard-block.html.twig b/themes/grav/templates/partials/notification-dashboard-block.html.twig index 77233b87..9bd8f45d 100644 --- a/themes/grav/templates/partials/notification-dashboard-block.html.twig +++ b/themes/grav/templates/partials/notification-dashboard-block.html.twig @@ -1,6 +1,6 @@ {% for entry_id, entry in notifications %}