Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tf+ 159 notification event pickup reminder #350

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ gem "sassc-rails"
# we should be able to remove this after upgrading to Ruby 3
gem 'net-http'

# Adding gem for Job queueing
gem 'sidekiq'

# Use devise as an authentication solution [https://github.com/plataformatec/devise]
gem "devise", github: "heartcombo/devise", ref: "f8d1ea90bc3" # https://steve-condylios.medium.com/how-to-set-up-devise-for-rails-7-466619f6d627
gem "devise-i18n" # https://github.com/tigrish/devise-i18n
Expand Down
17 changes: 13 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ GEM
childprocess (4.1.0)
chunky_png (1.4.0)
concurrent-ruby (1.1.10)
connection_pool (2.3.0)
crass (1.0.6)
debug (1.6.3)
irb (>= 1.3.6)
Expand Down Expand Up @@ -151,16 +152,16 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.6.2)
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.8.1)
launchy (>= 2.2, < 3)
json-jwt (1.16.1)
activesupport (>= 4.2)
aes_key_wrap
bindata
faraday (~> 2.0)
faraday-follow_redirects
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.8.1)
launchy (>= 2.2, < 3)
loofah (2.19.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -261,6 +262,8 @@ GEM
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
redis-client (0.12.1)
connection_pool
regexp_parser (2.6.0)
reline (0.3.1)
io-console (~> 0.5)
Expand Down Expand Up @@ -330,6 +333,11 @@ GEM
websocket (~> 1.0)
shoulda-matchers (5.2.0)
activesupport (>= 5.2.0)
sidekiq (7.0.3)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.11.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -425,6 +433,7 @@ DEPENDENCIES
sassc-rails
selenium-webdriver
shoulda-matchers (~> 5.0)
sidekiq
simplecov
sprockets-rails
sqlite3 (~> 1.4)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def accept_item
@job = Job.create
@job.item = @item
@job.save
ReminderNotificationJob.set(wait: 4.days).perform_later(@job)
@item.set_rental_start_time
@item.update(holder: @notification.borrower.id)
@item.save
ReminderNotificationJob.set(wait: 5.seconds).perform_later(@job)
helpers.audit_accept_lend(@item)
end
end
1 change: 1 addition & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def status_pending_pickup?
def perform_pickup_check
return unless status_pending_pickup?

PickupReminderNotification.create(item: self, receiver: holder, date: Time.zone.now, unread: true, active: true)
job = Job.find_by(item: self)
job.destroy
reset_status
Expand Down
14 changes: 14 additions & 0 deletions app/models/pickup_reminder_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class PickupReminderNotification < ApplicationRecord
acts_as :notification

belongs_to :item

def title
I18n.t "views.notifications.pickupreminder.title"
end

def description
I18n.t "views.notifications.pickupreminder.description", item: item.name
end
end

34 changes: 34 additions & 0 deletions app/views/notifications/_pickup_reminder_notification.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- Button trigger modal -->
<button type="button" class="btn btn-notification" style= "background-color: <%= notification.unread == true ? "#cce4ec" : "#dddfe0c" %> !important" data-bs-toggle="modal" data-bs-target="#<%= "notificationModal#{notification.id}" %>">
<div class="notification">
<h2 class="subtitle">
<%= notification.title %>
</h2>
<p class="body-1">
<%= notification.description %>
</p>
<p class="timestamp">
<%= notification.parse_time %>
</p>
</div>
</button>

<!-- Modal -->
<div class="modal fade" id="<%= "notificationModal#{notification.id}" %>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><%= notification.title %></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>
<%= notification.description %>
</p>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>

3 changes: 3 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ de:
removed_from_group:
title: "Aus Gruppe entfernt"
description: "Du wurdest aus der Gruppe \"%{group_name}\" entfernt."
pickupreminder:
title: "Abholungserinnerung"
description: "Du hast %{item} ausgeliehen. Bitte hole es bald ab."
no_notifications: "Du hast noch keine Nachrichten erhalten"
search:
title: "Suche"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ en:
removed_from_group:
title: "Removed from group"
description: "You have been removed from the group \"%{group_name}\"."
pickupreminder:
title: "Pickup Reminder"
description: "You have lend %{item}. Please pick it up soon."
no_notifications: "You have not received any notifications yet"
search:
title: "Search"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreatePickupReminderNotifications < ActiveRecord::Migration[7.0]
def change
create_table :pickup_reminder_notifications do |t|
t.references :item, null: false, foreign_key: true

t.timestamps
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/factories/pickup_reminder_notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :pickup_reminder_notification do
item { "MyString" }
references { "MyString" }
end
end