Skip to content

Commit

Permalink
add JS to dismiss whats new notification + start on notification dot css
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Dec 4, 2024
1 parent a354b8b commit 3545fc9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions assets/css/admin-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
});
}
});
7 changes: 3 additions & 4 deletions classes/WpMatomo/Admin/WhatsNewNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion classes/WpMatomo/Admin/views/whats-new-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/** @var int[] $matomo_statuses */

foreach ( $matomo_notifications as $matomo_notification ) { ?>
<div class="notice notice-info matomo-whats-new is-dismissible">
<div class="notice notice-info matomo-whats-new is-dismissible" data-notification-id="<?php esc_attr_e( $matomo_notification['id'] ); ?>">
<p>
<?php
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
Expand Down

0 comments on commit 3545fc9

Please sign in to comment.