From 0b97a39d459fdd0d815203022eaf9345e9101562 Mon Sep 17 00:00:00 2001 From: saparatayev Date: Fri, 3 Dec 2021 14:24:48 +0500 Subject: [PATCH] feat: adjust notifications plugin to notifications frontend --- modules/system/lang/en/validation.php | 3 ++ modules/system/lang/ru/validation.php | 3 ++ modules/system/lang/tm/validation.php | 3 ++ .../rainlab/notify/models/Notification.php | 54 +++++++++++++++++++ .../userplus/assets/css/notifications.css | 8 ++- .../userplus/assets/js/notifications.js | 27 +++------- .../userplus/components/Notifications.php | 17 ++++++ .../components/notifications/default.htm | 29 +--------- .../components/notifications/desktop.htm | 14 +++++ .../components/notifications/mobile.htm | 14 +++++ .../notifications/notifications-list.htm | 31 +++++------ themes/birzha/config/lang.yaml | 6 +++ themes/birzha/layouts/default.htm | 4 ++ themes/birzha/layouts/static.htm | 4 ++ themes/birzha/pages/kabinet/messages.htm | 2 +- themes/birzha/partials/header.htm | 21 +++++--- 16 files changed, 167 insertions(+), 73 deletions(-) create mode 100644 plugins/rainlab/userplus/components/notifications/desktop.htm create mode 100644 plugins/rainlab/userplus/components/notifications/mobile.htm diff --git a/modules/system/lang/en/validation.php b/modules/system/lang/en/validation.php index 2ddb5cdc9..d901dc6b0 100644 --- a/modules/system/lang/en/validation.php +++ b/modules/system/lang/en/validation.php @@ -136,6 +136,9 @@ return [ 'no_user' => 'A user was not found.', 'post_delete_confirm' => 'This post has been published. Do you really want to delete this post? The data cannot be recovered', 'thanks_for_posting' => 'Thank you for your request!', + 'new_message' => 'New message', + 'payment_reviewed' => 'Payment has been reviewed', + 'product_reviewed' => 'Post has been reviewed', /* |-------------------------------------------------------------------------- diff --git a/modules/system/lang/ru/validation.php b/modules/system/lang/ru/validation.php index e7cdf4ce0..a285baa6d 100644 --- a/modules/system/lang/ru/validation.php +++ b/modules/system/lang/ru/validation.php @@ -136,6 +136,9 @@ return [ 'no_user' => 'Пользователь не найден.', 'post_delete_confirm' => 'Это объявление уже размещено на сайте. Вы действительно хотите удалить это объявление? Данные нельзя будет восстановить.', 'thanks_for_posting' => 'Спасибо за оставленный вами запрос!', + 'new_message' => 'Новое сообщение', + 'payment_reviewed' => 'Платеж рассмотрен', + 'product_reviewed' => 'Объявление рассмотрено', /* |-------------------------------------------------------------------------- diff --git a/modules/system/lang/tm/validation.php b/modules/system/lang/tm/validation.php index 5af29feae..05789248b 100644 --- a/modules/system/lang/tm/validation.php +++ b/modules/system/lang/tm/validation.php @@ -138,6 +138,9 @@ return [ 'no_user' => 'Beýle ulanyjy ýok.', 'post_delete_confirm' => 'Bu bildiriş saýtda ýerleşdirilen. Bu bildirişi pozmak isleýärsiňizmi? Soň bu bildirişi dikeldip bolmaz.', 'thanks_for_posting' => 'Ugradan ýüzlenmäňiz üçin sag boluň!', + 'new_message' => 'Täze hat', + 'payment_reviewed' => 'Töleg gözden geçirildi', + 'product_reviewed' => 'Bildiriş gözden geçirildi', /* |-------------------------------------------------------------------------- diff --git a/plugins/rainlab/notify/models/Notification.php b/plugins/rainlab/notify/models/Notification.php index 1eec197ee..79a772d54 100644 --- a/plugins/rainlab/notify/models/Notification.php +++ b/plugins/rainlab/notify/models/Notification.php @@ -1,7 +1,11 @@ body); } + + /** + * Get the description of the notification + * + * @return string + */ + public function getDescriptionAttribute() + { + $e = new $this->event_type; + + if($e instanceof MessageReceivedEvent) { + + return trans('validation.new_message'); + + } elseif($e instanceof ProductReviewedEvent) { + + return trans('validation.product_reviewed'); + + } elseif($e instanceof PaymentReviewedEvent) { + + return trans('validation.payment_reviewed'); + } + + return 'Unknown type notification'; + } + + /** + * Get the link where to redirect when the notification is clicked + * + * @return string + */ + public function getLinkAttribute() + { + $e = new $this->event_type; + + if($e instanceof MessageReceivedEvent) { + + return \Url::to('/messages'); + + } elseif($e instanceof ProductReviewedEvent) { + + return \Url::to('/my-posts'); + + } elseif($e instanceof PaymentReviewedEvent) { + + return \Url::to('/balance'); + } + + return \Url::to('/'); + } } diff --git a/plugins/rainlab/userplus/assets/css/notifications.css b/plugins/rainlab/userplus/assets/css/notifications.css index b895fb74c..234271f55 100644 --- a/plugins/rainlab/userplus/assets/css/notifications.css +++ b/plugins/rainlab/userplus/assets/css/notifications.css @@ -27,12 +27,16 @@ float: right; margin: 0 5px; } -.rainlab-userplus .notifications-content .notifications-loading { +.rainlab-userplus .notifications-content .notifications-loading, +.notification_area .notifications-loading, +.accord_notification .notifications-loading { padding: 20px; font-size: 24px; text-align: center; } -.rainlab-userplus .notifications-content .no-notifications { +.rainlab-userplus .notifications-content .no-notifications, +.notification_area .no-notifications, +.accord_notification .no-notifications { text-align: center; padding: 25px; margin: 0; diff --git a/plugins/rainlab/userplus/assets/js/notifications.js b/plugins/rainlab/userplus/assets/js/notifications.js index 012579c3d..1faba4289 100644 --- a/plugins/rainlab/userplus/assets/js/notifications.js +++ b/plugins/rainlab/userplus/assets/js/notifications.js @@ -1,24 +1,13 @@ function toggleNotificationsPopover(el) { - if ($(el).closest('form').toggleClass('active').hasClass('active')) { + + if($(el).next().hasClass('notification_area')) { $(el).request('onLoadNotifications', { - update: { '@notifications-list': '#notificationsContent' } + update: { '@notifications-list': '#notification_area' } + }) + } else if($(el).next().hasClass('accord_notification')) { + $(el).request('onLoadNotifications', { + update: { '@notifications-list': '#accord_notification' } }) } -} - -function loadOlderNotifications(el) { - var $form = $(el).closest('form'), - height = $('ul.notifications', $form).get(0).scrollHeight - - $(el).request('onLoadOlderNotifications', { - update: { '@notifications-list': '#notificationsContent' } - }).done(function() { - $('ul.notifications', $form).animate({ scrollTop: height }, 200) - }) -} - -function markNotificationsAsRead(el) { - $(el).request('onMarkAllNotificationsAsRead', { - update: { '@notifications-list': '#notificationsContent' } - }) + } diff --git a/plugins/rainlab/userplus/components/Notifications.php b/plugins/rainlab/userplus/components/Notifications.php index c02985da2..f8decf030 100644 --- a/plugins/rainlab/userplus/components/Notifications.php +++ b/plugins/rainlab/userplus/components/Notifications.php @@ -4,6 +4,7 @@ use Auth; use Carbon\Carbon; use Cms\Classes\ComponentBase; use ApplicationException; +use Illuminate\Support\Facades\Redirect; class Notifications extends ComponentBase { @@ -28,6 +29,13 @@ class Notifications extends ComponentBase 'comment' => 'Inject the JavaScript and Stylesheet used by the default component markup', 'type' => 'checkbox', 'default' => true + ], + 'frontend' => [ + 'title' => 'Frontend block', + 'description' => 'Choose where in the page to display', + 'type' => 'dropdown', + 'options' => ['desktop','mobile'], + 'default' => 'desktop' ] ]; } @@ -92,6 +100,15 @@ class Notifications extends ComponentBase $this->page['notifications'] = $this->unreadNotifications(); } + public function onMarkNotificationAsRead() + { + $this->getUnreadQuery() + ->where('id', \Input::get('notification_id')) + ->update(['read_at' => Carbon::now()]); + + return Redirect::to(\Input::get('redirect_link')); + } + // // Helpers // diff --git a/plugins/rainlab/userplus/components/notifications/default.htm b/plugins/rainlab/userplus/components/notifications/default.htm index f1ab7bc33..e4a211559 100644 --- a/plugins/rainlab/userplus/components/notifications/default.htm +++ b/plugins/rainlab/userplus/components/notifications/default.htm @@ -1,28 +1 @@ -
- - -
-
-

Notifications

- - - - Mark all as read - -
- -
-
- -
-
-
-
+{% partial __SELF__~"::"~__SELF__.property('frontend') %} diff --git a/plugins/rainlab/userplus/components/notifications/desktop.htm b/plugins/rainlab/userplus/components/notifications/desktop.htm new file mode 100644 index 000000000..504793da6 --- /dev/null +++ b/plugins/rainlab/userplus/components/notifications/desktop.htm @@ -0,0 +1,14 @@ +
+
+
+ bell +
+

{{ 'auth.notifications'|_ }}

+
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/plugins/rainlab/userplus/components/notifications/mobile.htm b/plugins/rainlab/userplus/components/notifications/mobile.htm new file mode 100644 index 000000000..b01979003 --- /dev/null +++ b/plugins/rainlab/userplus/components/notifications/mobile.htm @@ -0,0 +1,14 @@ +
+
+ bell +
+

+ {{ 'auth.notifications'|_ }} +

+
+ +
+
+ +
+
\ No newline at end of file diff --git a/plugins/rainlab/userplus/components/notifications/notifications-list.htm b/plugins/rainlab/userplus/components/notifications/notifications-list.htm index 371f150bb..707a308d1 100644 --- a/plugins/rainlab/userplus/components/notifications/notifications-list.htm +++ b/plugins/rainlab/userplus/components/notifications/notifications-list.htm @@ -1,23 +1,20 @@ {% if notifications.total %} - - - {% if notifications.lastItem() < notifications.total %} - - {% endif %} + {% endfor %} - {% else %} -

There are no notifications for you

+

{{ 'auth.no_notifications'|_ }}

{% endif %} diff --git a/themes/birzha/config/lang.yaml b/themes/birzha/config/lang.yaml index 7da9c6acc..8ea068659 100644 --- a/themes/birzha/config/lang.yaml +++ b/themes/birzha/config/lang.yaml @@ -16,6 +16,8 @@ en: auth.messages: Messages auth.logout: Logout auth.add_announce: Add announcement + auth.notifications: Notifications + auth.no_notifications: There are no notifications account.company: Company account.legalization_number: Legalization number account.save: Save @@ -149,6 +151,8 @@ ru: auth.messages: Сообщения auth.logout: Выйти auth.add_announce: Добавить объявление + auth.notifications: Уведомления + auth.no_notifications: Нет уведомлений account.company: Компания account.legalization_number: Номер легализации account.save: Ýatla @@ -282,6 +286,8 @@ tm: auth.messages: Hatlar auth.logout: Çykyş auth.add_announce: Bildiriş goş + auth.notifications: Habarnamalar + auth.no_notifications: Habarnamalar ýok account.company: Şereket account.legalization_number: Legalizasiýa nomeri account.save: Ýatla diff --git a/themes/birzha/layouts/default.htm b/themes/birzha/layouts/default.htm index b21825c67..386de7242 100644 --- a/themes/birzha/layouts/default.htm +++ b/themes/birzha/layouts/default.htm @@ -14,6 +14,10 @@ view = "signin" [session] security = "all" + +[notifications] +recordsPerPage = 7 +includeAssets = 1 ==
@@ -209,6 +208,8 @@ code = "main-top"

+ {% component 'notifications' frontend='mobile' %} +
@@ -309,11 +310,19 @@ code = "main-top" {% endif %}
-
- {% for code, name in locales %} - {{ code }} - {% endfor %} + +
@@ -368,4 +377,4 @@ code = "main-top"
-{% endif %} +{% endif %} \ No newline at end of file