From db3f217bbaeee518c075af0b264003b4093d5833 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 17 Oct 2023 12:02:55 +0200 Subject: [PATCH] Implement acitvity notifications [SCI-9512] --- .../stylesheets/navigation/notifications.scss | 2 +- .../user_notifications_controller.rb | 22 +--- .../notifications/notification_item.vue | 20 ++-- .../notifications/notifications_flyout.vue | 28 +++-- .../concerns/generate_notification_model.rb | 102 +----------------- app/models/user_notification.rb | 22 ---- app/notifications/activity_notification.rb | 44 +++++--- app/notifications/base_notification.rb | 29 +++++ app/notifications/delivery_notification.rb | 3 +- app/notifications/general_notification.rb | 3 +- .../recipients/assigned_group_recipients.rb | 13 +++ .../recipients/assigned_recipients.rb | 12 +++ .../recipients/item_creator_recipients.rb | 11 ++ .../my_module_designated_recipients.rb | 31 ++++++ app/serializers/notification_serializer.rb | 82 ++++++++++++++ ...1103114_migrate_notification_to_noticed.rb | 4 + 16 files changed, 255 insertions(+), 173 deletions(-) delete mode 100644 app/models/user_notification.rb create mode 100644 app/notifications/base_notification.rb create mode 100644 app/notifications/recipients/assigned_group_recipients.rb create mode 100644 app/notifications/recipients/assigned_recipients.rb create mode 100644 app/notifications/recipients/item_creator_recipients.rb create mode 100644 app/notifications/recipients/my_module_designated_recipients.rb create mode 100644 app/serializers/notification_serializer.rb diff --git a/app/assets/stylesheets/navigation/notifications.scss b/app/assets/stylesheets/navigation/notifications.scss index 5322db761..3646bd65d 100644 --- a/app/assets/stylesheets/navigation/notifications.scss +++ b/app/assets/stylesheets/navigation/notifications.scss @@ -94,7 +94,7 @@ border-radius: 50%; color: $color-white; display: flex; - grid-row: 1 / 4; + grid-row: 1 / 5; height: 2rem; justify-content: center; margin-right: .75rem; diff --git a/app/controllers/user_notifications_controller.rb b/app/controllers/user_notifications_controller.rb index eb2c7e976..819d7ebf7 100644 --- a/app/controllers/user_notifications_controller.rb +++ b/app/controllers/user_notifications_controller.rb @@ -2,13 +2,10 @@ class UserNotificationsController < ApplicationController def index - page = (params[:page] || 1).to_i - notifications = load_notifications.page(page).per(Constants::INFINITE_SCROLL_LIMIT).without_count + page = (params.dig(:page, :number) || 1).to_i + notifications = load_notifications.page(page).per(Constants::INFINITE_SCROLL_LIMIT) - render json: { - notifications: notification_serializer(notifications), - next_page: notifications.next_page - } + render json: notifications, each_serializer: NotificationSerializer notifications.mark_as_read! end @@ -26,17 +23,4 @@ class UserNotificationsController < ApplicationController .order(created_at: :desc) end - def notification_serializer(notifications) - notifications.map do |notification| - { - id: notification.id, - type_of: notification.type, - title: notification.to_notification.title, - message: notification.to_notification.message, - created_at: I18n.l(notification.created_at, format: :full), - today: notification.created_at.today?, - checked: notification.read_at.present? - } - end - end end diff --git a/app/javascript/vue/navigation/notifications/notification_item.vue b/app/javascript/vue/navigation/notifications/notification_item.vue index 8fae78c2d..dbf7a1471 100644 --- a/app/javascript/vue/navigation/notifications/notification_item.vue +++ b/app/javascript/vue/navigation/notifications/notification_item.vue @@ -1,15 +1,23 @@ @@ -21,7 +29,7 @@ export default { }, computed: { icon() { - switch(this.notification.type_of) { + switch(this.notification.attributes.type_of) { case 'deliver': return 'fas fa-truck'; case 'assignment': diff --git a/app/javascript/vue/navigation/notifications/notifications_flyout.vue b/app/javascript/vue/navigation/notifications/notifications_flyout.vue index c5c1feb60..951a43543 100644 --- a/app/javascript/vue/navigation/notifications/notifications_flyout.vue +++ b/app/javascript/vue/navigation/notifications/notifications_flyout.vue @@ -24,6 +24,7 @@