Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cs169/snapcon
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenlet committed Apr 15, 2024
2 parents b932d80 + adc8282 commit 773adb5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
30 changes: 21 additions & 9 deletions app/controllers/admin/commercials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,34 @@ def mass_upload

if !params[:file]
flash[:error] = 'Empty file detected while adding materials to Event'
elsif errors.all? { |_k, v| v.blank? }
flash[:notice] = 'Successfully added materials.'
else
errors_text = ''
errors_text += 'Unable to find event with ID: ' + errors[:no_event].join(', ') + '. ' if errors[:no_event].any?
if errors[:validation_errors].any?
errors_text += 'There were some errors: ' + errors[:validation_errors].join('. ')
end
elsif errors.present?
errors_text = aggregate_errors(errors)
flash[:notice] = if errors_text.length > 4096
'Errors are too long to be displayed. Please check the logs.'
else
errors_text
end

flash[:error] = errors_text
else
flash[:notice] = 'Successfully added materials.'
end
redirect_back(fallback_location: root_path)
end

private

# Aggregate errors and ensure that they do not exceed 4 KB in total size
def aggregate_errors(errors)
errors_text = ''
if errors[:no_event].any?
errors_text += 'Unable to find events with IDs: ' + errors[:no_event].join(', ') + '. '
end
if errors[:validation_errors].any?
errors_text += 'Validation errors: ' + errors[:validation_errors].join('. ')
end
errors_text
end

def commercial_params
params.require(:commercial).permit(:title, :url)
end
Expand Down
1 change: 0 additions & 1 deletion app/models/commercial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#
require 'csv'


class Commercial < ApplicationRecord
require 'oembed'

Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/events/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
for instance:
%pre
Event_ID,Title,URL
1,title,https://youtube.com/myvideo
2,title,https://vimeo.com/myvideo
1,Session Recording,https://youtube.com/myvideo
2,Demo Video,https://vimeo.com/myvideo
.modal-footer
= f.submit nil, class: 'btn btn-primary'
.row
Expand Down

0 comments on commit 773adb5

Please sign in to comment.