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

187216987 add event by csv #375

Merged
merged 27 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1cfa242
Merge branch '18712145-add-ticket-purchase-currency-selector' of gith…
Edge7481 Mar 15, 2024
f90435e
Update .codeclimate.yml
warrenlet Feb 23, 2024
29b0d55
merge
warrenlet Mar 15, 2024
a1c116d
Merge branch '187121440_Materials_Bulk_Upload'
warrenlet Mar 15, 2024
4c6c4ee
Merge branch '187153142-impl-currency-for-payments-page'
warrenlet Mar 15, 2024
4537e98
Merge remote-tracking branch 'origin/187153142-impl-currency-for-paym…
warrenlet Mar 15, 2024
bf76578
merge
warrenlet Mar 15, 2024
f19a779
Merge branch 'main' of github.com:cs169/snapcon
warrenlet Mar 18, 2024
4a4df63
Add upload csv schedule button
warrenlet Mar 19, 2024
2022ffb
Add comment code to enable button funcionality
warrenlet Mar 28, 2024
6a89df6
Upload CSV Added
Apr 22, 2024
4389a31
add upload CSV function
Apr 23, 2024
99f5306
Merge pull request #34 from cs169/187391447-schedule-jump-to-time-button
Edge7481 Apr 26, 2024
25f99fb
Merge pull request #35 from cs169/187436622-commercials-embed-snap
Edge7481 Apr 26, 2024
25e381f
Resolve merge conflicts by regenerating schema.rb
Apr 26, 2024
0e228b8
Fix RuboCop offenses in schedules controller
Apr 28, 2024
645f95a
Fix RuboCop offenses in schedules controller2
Apr 28, 2024
3842184
Fix RuboCop offenses in schedules controller3
Apr 28, 2024
6ba98dd
Refactored for add event by csv
Apr 28, 2024
c847c3a
Fix RuboCop offenses in schedules controller
Apr 28, 2024
cf52a84
Fix code style issues
Apr 28, 2024
b7999bc
Fix code style issues
Apr 28, 2024
78563c1
merge commerical updates
cycomachead Jul 20, 2024
92fa560
fix commericals function call
cycomachead Jul 20, 2024
d602335
merge
cycomachead Jul 20, 2024
021a24b
Fixup events admin table
cycomachead Jul 20, 2024
3619bfb
Fixup db schema
cycomachead Jul 20, 2024
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
2 changes: 1 addition & 1 deletion app/assets/javascripts/osem-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ $(document).ready( function() {
var now = new Date();
var closestEventId = null;
var smallestDiff = Infinity;
var i=0
var i = 0;

$('.event-item').each(function() {

Expand Down
56 changes: 56 additions & 0 deletions app/controllers/admin/schedules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Admin
class SchedulesController < Admin::BaseController
# By authorizing 'conference' resource, we can ensure there will be no unauthorized access to
# the schedule of a conference, which should not be accessed in the first place
before_action :set_conference
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource :schedule, through: :program, except: %i[new create]
Expand Down Expand Up @@ -68,8 +69,63 @@ def destroy
end
end

def upload_csv
authorize! :update, @conference
return flash[:alert] = 'No file was attached!' unless file_present?

if process_csv
flash[:notice] = 'Schedule uploaded successfully!'
else
flash[:alert] = 'Failed to process CSV file.'
end

redirect_to admin_conference_schedules_path(@conference)
end

private

def set_conference
@conference = Conference.find_by!(short_title: params[:conference_id])
end

def file_present?
params[:schedule] && params[:schedule][:file].present?
end

def process_csv
file = params[:schedule][:file]
CSV.foreach(file.path, headers: true) do |row|
process_row(row)
end
true
rescue StandardError => e
Rails.logger.error "CSV Processing Error: #{e.message}"
false
end

def process_row(row)
event_date = parse_date(row['Date'])
event_time = parse_time(row['Start_Time'])
event_start_time = combine_datetime(event_date, event_time)

room = Room.find_or_create_by(name: row['Room'])
event = Event.find_by(id: row['Event_ID'])

event&.update(start_time: event_start_time, room: room)
end

def parse_date(date_str)
Date.strptime(date_str, '%m/%d/%y')
end

def parse_time(time_str)
Time.parse(time_str)
end

def combine_datetime(date, time)
DateTime.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone)
end

def schedule_params
params.require(:schedule).permit(:track_id) if params[:schedule]
end
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/events/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
%th Rating
%th Submitter
%th Speakers
%th Volunteers
- if @program.languages.present?
%th Language
%th Requires Registration
Expand Down
27 changes: 27 additions & 0 deletions app/views/admin/schedules/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@
.col-md-12
.page-header
%h1= "#{@conference.title} Schedule"

.btn-group.pull-right
%button.btn.btn-primary{ title: 'Mass import of schedule for events',
data: { toggle: 'modal', target: '#mass-schedule-modal' } }
Upload with CSV file

%p.text-muted
Create the schedules for the conference
= render 'schedules/event_types_key', event_types: @event_types, favourites: false

.modal#mass-schedule-modal
.modal-dialog
.modal-content
.modal-header
%h1
Schedule events
.modal-body
= form_for :schedule, url: upload_csv_admin_conference_schedules_path(@conference), html: { multipart: true }, method: :post do |f|
.form-group
= f.file_field :file, as: :file
%span.help-block
Upload your CSV file with data in the following format:
%b Event_ID, Start_Time, Date, Room
for instance:
%pre
Event_ID, Start_Time, Date, Room
osemdemo, 10:00, 6/1/2024, Australia
osemdemo, 11:00, 6/2/2024, Brazil
.modal-footer
= f.submit 'Upload', class: 'btn btn-primary'

- if @rooms.present?
.row
.col-md-2
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
resource :ticket_scanning, only: [:create]
resources :comments, only: [:index]
resources :conferences do
resources :schedules do
collection do
post :upload_csv
end
end
resources :surveys do
resources :survey_questions, except: :index
end
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20240308190204_add_currency_to_payments.rb

This file was deleted.

5 changes: 0 additions & 5 deletions db/migrate/20240315025823_add_currency_to_ticket_purchases.rb

This file was deleted.

2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@
t.integer "status", default: 0, null: false
t.integer "user_id", null: false
t.integer "conference_id", null: false
t.string "currency"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.string "currency"
end

create_table "physical_tickets", force: :cascade do |t|
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion spec/features/event_schedules_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe EventSchedule, js: true do
describe EventSchedule, :js do
Timecop.return
let(:test_date) { Time.current }
let!(:conference) do
Expand Down
Loading