12 changed files with 98 additions and 5 deletions
@ -0,0 +1,15 @@
|
||||
<div class="app-unread-notification"> |
||||
<div class="govuk-width-container"> |
||||
<br> |
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-three-quarters govuk-body"> |
||||
<p class="govuk-!-font-weight-bold"><%= oldest_unread_notification.title %></p> |
||||
<%= govuk_link_to oldest_unread_notification.link_text, notification_path(oldest_unread_notification), class: "govuk-link--inverse govuk-!-font-weight-bold"%> |
||||
</div> |
||||
<p class="govuk-grid-column-one-quarter govuk-!-text-align-right "> |
||||
<%= govuk_link_to "Dismiss", notification_dismiss_path(oldest_unread_notification), class: "govuk-link--inverse"%> |
||||
</p> |
||||
</div> |
||||
<br> |
||||
</div> |
||||
</div> |
||||
@ -0,0 +1,12 @@
|
||||
class UnreadNotification < ViewComponent::Base |
||||
attr_reader :current_user |
||||
|
||||
def initialize(current_user:) |
||||
@current_user = current_user |
||||
super |
||||
end |
||||
|
||||
def oldest_unread_notification |
||||
Notification.unread_by(@current_user).first |
||||
end |
||||
end |
||||
@ -0,0 +1,8 @@
|
||||
class NotificationsController < ApplicationController |
||||
|
||||
def dismiss |
||||
Notification.find(params[:notification_id]).mark_as_read! for: current_user |
||||
|
||||
redirect_to root_path |
||||
end |
||||
end |
||||
@ -0,0 +1,7 @@
|
||||
.app-unread-notification { |
||||
background-color: govuk-colour("blue"); |
||||
} |
||||
|
||||
.app-unread-notification p { |
||||
color: govuk-colour("white"); |
||||
} |
||||
@ -0,0 +1,3 @@
|
||||
class Notification < ApplicationRecord |
||||
acts_as_readable |
||||
end |
||||
@ -0,0 +1,24 @@
|
||||
class UnreadMigration < ActiveRecord::Migration[6.0] |
||||
def self.up |
||||
create_table ReadMark, force: true, options: create_options do |t| |
||||
t.references :readable, polymorphic: { null: false } |
||||
t.references :reader, polymorphic: { null: false } |
||||
t.datetime :timestamp, null: false |
||||
end |
||||
|
||||
add_index ReadMark, [:reader_id, :reader_type, :readable_type, :readable_id], name: 'read_marks_reader_readable_index', unique: true |
||||
end |
||||
|
||||
def self.down |
||||
drop_table ReadMark |
||||
end |
||||
|
||||
def self.create_options |
||||
options = '' |
||||
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) \ |
||||
&& ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) |
||||
options = 'DEFAULT CHARSET=latin1' |
||||
end |
||||
options |
||||
end |
||||
end |
||||
Loading…
Reference in new issue