From 3545fc97f95624c6cfcad9c3a29fbf7459789504 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 4 Dec 2024 12:19:06 -0800 Subject: [PATCH] add JS to dismiss whats new notification + start on notification dot css --- assets/css/admin-style.css | 8 ++++++++ assets/js/admin.js | 11 +++++++++++ classes/WpMatomo/Admin/WhatsNewNotifications.php | 7 +++---- .../WpMatomo/Admin/views/whats-new-notifications.php | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/assets/css/admin-style.css b/assets/css/admin-style.css index 9bff75670..0be656bd5 100644 --- a/assets/css/admin-style.css +++ b/assets/css/admin-style.css @@ -161,3 +161,11 @@ table.matomo-tracking-form th { -ms-transform: translateX(1.03em); transform: translateX(1.03em); } + +#toplevel_page_matomo a { + position: relative; +} + +#toplevel_page_matomo a.matomo-notification-dot { + // TODO +} diff --git a/assets/js/admin.js b/assets/js/admin.js index 38cd113c4..2ed02139e 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -45,4 +45,15 @@ window.jQuery(document).ready(function ($) { }); }); } + + // whats new notice dismiss + if (typeof mtmWhatsNewNotificationAjax !== undefined && mtmWhatsNewNotificationAjax.ajax_url) { + $('body').on('click', '.matomo-whats-new .notice-dismiss', function (e) { + $.post(mtmWhatsNewNotificationAjax.ajax_url, { + _ajax_nonce: mtmWhatsNewNotificationAjax.nonce, + action: 'mtm_dismiss_whats_new', + matomo_notification: $(e.target).closest('.matomo-whats-new').data('notification-id'), + }); + }); + } }); diff --git a/classes/WpMatomo/Admin/WhatsNewNotifications.php b/classes/WpMatomo/Admin/WhatsNewNotifications.php index e66e3355b..fe592b5f7 100644 --- a/classes/WpMatomo/Admin/WhatsNewNotifications.php +++ b/classes/WpMatomo/Admin/WhatsNewNotifications.php @@ -52,7 +52,6 @@ public function on_admin_notices() { public function on_admin_enqueue_scripts() { $this->mark_current_page_as_seen(); - // TODO: javascript part wp_localize_script( 'matomo-admin-js', 'mtmWhatsNewNotificationAjax', @@ -63,7 +62,7 @@ public function on_admin_enqueue_scripts() { ); // TODO: javascript part - $unseen_notifications = $this->get_unseen_notifications(); + $unseen_notifications = $this->get_unseen_notification_pages(); wp_localize_script( 'matomo-admin-js', 'mtmUnseenWhatsNewNotifications', @@ -134,7 +133,7 @@ private function mark_current_page_as_seen() { $this->save_notification_statuses( $statuses ); } - private function get_unseen_notifications() { + private function get_unseen_notification_pages() { $matomo_notifications = $this->get_current_notifications(); $matomo_statuses = $this->get_notification_statuses(); @@ -144,7 +143,7 @@ private function get_unseen_notifications() { if ( ! isset( $matomo_statuses[ $id ] ) || self::STATUS_UNSEEN === $matomo_statuses[ $id ] ) { - $matomo_unseen_notifications[] = $id; + $matomo_unseen_notifications[] = $notification['notification_marker_page']; } } return $matomo_unseen_notifications; diff --git a/classes/WpMatomo/Admin/views/whats-new-notifications.php b/classes/WpMatomo/Admin/views/whats-new-notifications.php index 16fc60b64..6921843d0 100644 --- a/classes/WpMatomo/Admin/views/whats-new-notifications.php +++ b/classes/WpMatomo/Admin/views/whats-new-notifications.php @@ -14,7 +14,7 @@ /** @var int[] $matomo_statuses */ foreach ( $matomo_notifications as $matomo_notification ) { ?> -
+