Skip to content

Commit

Permalink
Merge pull request #60 from gdbrowne85/Carlos_testing
Browse files Browse the repository at this point in the history
Fairwell Cucumbers
  • Loading branch information
Carmeisel101 authored Apr 25, 2024
2 parents c297b88 + 791c0b1 commit 5802a42
Show file tree
Hide file tree
Showing 33 changed files with 351 additions and 294 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ ruby '3.2.2'
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'aws-sdk-rails'
gem 'bootsnap', require: false # Reduces boot times through caching; required in config/boot.rb
gem 'google-apis-calendar_v3', '~> 0.33.0'
gem 'importmap-rails'
gem 'jbuilder'
gem 'particles-js-rails'
gem 'puma', '~> 5.0'
gem 'rails', '~> 7.0.8'
gem 'rake', '13.1.0'
gem 'roo', '~> 2.10.1'
gem 'particles-js-rails'
gem 'google-apis-calendar_v3', '~> 0.33.0'
gem 'signet', '~> 0.16.0'
gem 'sprockets-rails' # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem 'stimulus-rails'
Expand Down Expand Up @@ -61,5 +61,6 @@ group :test do
gem 'rspec'
gem 'selenium-webdriver'
gem 'simplecov', require: false
gem 'timecop'
gem 'webdrivers'
end
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ GEM
ffi (~> 1.1)
thor (1.2.2)
thread_safe (0.3.6)
timecop (0.9.8)
timeout (0.4.0)
trailblazer-option (0.1.2)
tty-which (0.5.0)
Expand Down Expand Up @@ -549,6 +550,7 @@ DEPENDENCIES
sprockets-rails
sqlite3 (~> 1.4)
stimulus-rails
timecop
turbo-rails
tzinfo-data
web-console
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def create_event
end
new_event.attendees = attendees
end

calendar_id = params[:calendar_id] || 'primary'
service.insert_event(calendar_id, new_event)

flash[:notice] = 'Series event added successfully!'
end
else
else
start_datetime = DateTime.parse("#{@event_info.date}T#{@event_info.start_time}:00").strftime('%Y-%m-%dT%H:%M:%S.%LZ')
end_datetime = DateTime.parse("#{@event_info.date}T#{@event_info.end_time}:00").strftime('%Y-%m-%dT%H:%M:%S.%LZ')

Expand All @@ -73,7 +73,7 @@ def create_event
attendees = []
@event.attendee_infos.each do |attendee_info|
attendees << Google::Apis::CalendarV3::EventAttendee.new(email: attendee_info.email,
display_name: attendee_info.name, response_status: attendee_info.is_attending == 'yes' ? 'accepted' : 'needsAction')
display_name: attendee_info.name, response_status: attendee_info.is_attending == 'yes' ? 'accepted' : 'needsAction')
end
new_event.attendees = attendees
end
Expand All @@ -82,9 +82,8 @@ def create_event
service.insert_event(calendar_id, new_event)

flash[:notice] = 'Event added successfully!'
end
end
redirect_to eventsList_url

rescue Google::Apis::Error
redirect_to redirect_path
end
Expand Down
88 changes: 44 additions & 44 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ def create
max_capacity = event_params[:max_capacity]
reminder_time = event_params[:reminder_time]
user_input = event_params[:user_input]

parsed_data = []
created_by = session[:user_email]

date = Time.now if date.nil?

@event = Event.new(
name: name,
created_by: created_by
name:,
created_by:
)

@event_info = EventInfo.new(
name: name,
venue: venue,
date: date,
start_time: start_time,
end_time: end_time,
reminder_time: reminder_time,
max_capacity: max_capacity
name:,
venue:,
date:,
start_time:,
end_time:,
reminder_time:,
max_capacity:
)

if csv_file.present? && File.extname(csv_file.path) == '.csv'
@event.csv_file.attach(csv_file)
# Parse the CSV data
Expand All @@ -72,19 +72,19 @@ def create
parsed_data << row
end
end

if user_input.present?
emails = user_input.split(',').map(&:strip)
emails.each do |email|
parsed_data << { 'Email' => email }
end
end

respond_to do |format|
if @event.save
# Create time_slot data if applicable
@event.update(event_params.extract!(:time_slots_attributes))

# Save the other events reference to the event
if parsed_data.nil?
# Handle the case when parsed_data is nil
Expand All @@ -95,21 +95,19 @@ def create
parsed_data.each do |row|
email = row['Email']
priority = row['Priority']

@attendee = AttendeeInfo.new(
email: email,
email:,
event_id: @event.id,
email_token: SecureRandom.uuid,
priority: priority
priority:
)
unless @attendee.save
puts "Validation errors: #{@attendee.errors.full_messages}"
end
puts "Validation errors: #{@attendee.errors.full_messages}" unless @attendee.save
end
end

@event_info.event_id = @event.id

if @event_info.save
invite_attendees(@event.id)
format.html { redirect_to eventdashboard_path, notice: 'Event was successfully created.' }
Expand All @@ -121,7 +119,6 @@ def create
end
end
end


# PATCH/PUT /events/1 or /events/1.json
def update
Expand Down Expand Up @@ -285,46 +282,48 @@ def attendees_at_or_over_capacity
def invite_attendees(event_id)
@event = Event.find(event_id)
@event_info = @event.event_info

yes_attendees = @event.attendee_infos.where(is_attending: 'yes')

send_reminders_to_attendees

send_reminders_to_no_response_attendees

if @event_info.max_capacity.present? && @event_info.max_capacity != yes_attendees.count
attendees_to_invite = @event.attendee_infos.where(email_sent: false).limit(@event_info.max_capacity)
attendees_to_invite.each do |attendee|
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token, event: @event).invite_email.deliver
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token,
event: @event).invite_email.deliver
attendee.update(email_sent: true, email_sent_time: DateTime.now)
end
elsif !@event_info.max_capacity.present?
@event.attendee_infos.where(email_sent: false).each do |attendee|
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token, event: @event).invite_email.deliver
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token,
event: @event).invite_email.deliver
attendee.update(email_sent: true, email_sent_time: DateTime.now)
end
end
end

def send_reminders_to_attendees
# event = Event.find(event_id)
# event_info = event.event_info
events_to_remind = EventInfo.where('reminder_time <= ?', DateTime.now)

events_to_remind.each do |event_info|
event = Event.find(event_info.event_id)

# Find attendees who responded "yes" and haven't been sent a reminder email yet
yes_attendees = event.attendee_infos.where(is_attending: 'yes', email_sent: true, reminder_email_sent: false)

# Send emails to those attendees who have already responded "yes"
yes_attendees.each do |attendee|
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token, event: event).reminder_email.deliver
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token,
event:).reminder_email.deliver
attendee.update(reminder_email_sent: true)
end
end
end


def number_of_emails_sent
@event.attendee_infos.where(email_sent: true).count
Expand All @@ -337,18 +336,19 @@ def send_reminders_to_no_response_attendees

events_to_remind.each do |event_info|
event = Event.find(event_info.event_id)

# Find attendees who have not responded yet and have been sent the initial email but no reminder
no_response_attendees = event.attendee_infos.where(is_attending: nil, email_sent: true, reminder_email_sent: false)

# Send reminder emails to these attendees
no_response_attendees = event.attendee_infos.where(is_attending: nil, email_sent: true,
reminder_email_sent: false)

# Send reminder emails to these attendees
no_response_attendees.each do |attendee|
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token, event: event).reminder_email.deliver
EventRemainderMailer.with(email: attendee.email, token: attendee.email_token,
event:).reminder_email.deliver
attendee.update(reminder_email_sent: true)
end
end
end


def series_event
@event = Event.new
Expand All @@ -368,4 +368,4 @@ def event_params
params.require(:event).permit(:name, :venue, :date, :start_time, :end_time, :max_capacity, :reminder_time,
:csv_file, :user_input, time_slots_attributes: %i[id date start_time end_time _destroy])
end
end
end
9 changes: 3 additions & 6 deletions app/controllers/login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def login
redirect_to home_path # Redirect to dashboard without logging in
else
@user = User.find_by(email: params[:email])
if @user && @user.authenticate(params[:password])
if @user&.authenticate(params[:password])
session[:user_email] = @user.email
redirect_to home_path # Redirect to dashboard after successful login

Expand All @@ -35,13 +35,10 @@ def login
render 'new' # Render the login page again with an error message
end
end
end
end

def logout
reset_session # Clear the session to ensure user is logged out
reset_session # Clear the session to ensure user is logged out
redirect_to signin_path, notice: 'You have been successfully logged out.' # Redirect to login page with a notice
end
end



52 changes: 26 additions & 26 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
# app/helpers/events_helper.rb

module EventsHelper
def readable_status(status)
case status
when 'awaiting_reply'
'Invitation sent - awaiting reply'
when 'replied_attending'
'Replied - attending'
when 'replied_not_attending'
'Replied - not attending'
else
'Unknown Status'
end
end
def status_class(status)
case status
when 'awaiting_reply'
'status-awaiting-reply'
when 'replied_attending'
'status-attending'
when 'replied_not_attending'
'status-not-attending'
else
'status-unknown' # Optionally handle unknown or default cases
end
end
end
def readable_status(status)
case status
when 'awaiting_reply'
'Invitation sent - awaiting reply'
when 'replied_attending'
'Replied - attending'
when 'replied_not_attending'
'Replied - not attending'
else
'Unknown Status'
end
end

def status_class(status)
case status
when 'awaiting_reply'
'status-awaiting-reply'
when 'replied_attending'
'status-attending'
when 'replied_not_attending'
'status-not-attending'
else
'status-unknown' # Optionally handle unknown or default cases
end
end
end
2 changes: 1 addition & 1 deletion app/mailers/event_remainder_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def remainder_email(csv_file_path)
CSV.foreach(csv_file_path, headers: true) do |row|
email = row['email'] # Assuming 'email' is a column in your CSV

mail(to: email, subject: 'Email Invitation') #.deliver not necessary, mail already sends email when method returns, that's why we were getting 2 emails instead of one
mail(to: email, subject: 'Email Invitation') # .deliver not necessary, mail already sends email when method returns, that's why we were getting 2 emails instead of one
end
elsif File.extname(csv_file_path) == '.xlsx'
workbook = Roo::Excelx.new(csv_file_path)
Expand Down
1 change: 1 addition & 0 deletions app/models/attendee_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AttendeeInfo < ApplicationRecord
after_initialize :set_default_status, if: :new_record?

private

def set_default_status
self.status ||= :awaiting_reply
end
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240416013531_add_created_by_to_events.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddCreatedByToEvents < ActiveRecord::Migration[7.0]
def change
add_column :events, :created_by, :string
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240417182831_add_reminder_time_to_events.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddReminderTimeToEvents < ActiveRecord::Migration[7.0]
def change
add_column :events, :reminder_time, :datetime
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240418034650_add_status_to_attendee_infos.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddStatusToAttendeeInfos < ActiveRecord::Migration[7.0]
def change
add_column :attendee_infos, :status, :integer, default: 1
Expand Down
Loading

0 comments on commit 5802a42

Please sign in to comment.