mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
parent
efb12b02e8
commit
32fa0bde6b
6 changed files with 97 additions and 29 deletions
|
|
@ -49,6 +49,26 @@ module Admin
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Received a file from user
|
||||
# Reads file and creates commercial for event
|
||||
# File content example:
|
||||
# EventID:MyURL
|
||||
def mass_upload
|
||||
errors = Commercial.read_file(params[:file]) if params[:file]
|
||||
|
||||
if errors.all? { |_k, v| v.blank? }
|
||||
flash[:notice] = 'Successfully added commercials.'
|
||||
else
|
||||
errors_text = ''
|
||||
errors_text << 'Unable to find event with ID: ' + errors[:no_event].join(', ') + '. ' if errors[:no_event].any?
|
||||
errors_text << 'There were some errors: ' + errors[:validation_errors].join('. ') if errors[:validation_errors].any?
|
||||
|
||||
flash[:error] = errors_text
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def commercial_params
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class Commercial < ApplicationRecord
|
|||
|
||||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
|
||||
validates :url, presence: true
|
||||
validates :url, presence: true, uniqueness: { scope: :commercialable }
|
||||
validates :url, format: URI::regexp(%w(http https))
|
||||
|
||||
validate :valid_url
|
||||
|
|
@ -20,6 +20,29 @@ class Commercial < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def self.read_file(file)
|
||||
errors = {}
|
||||
errors[:no_event] = []
|
||||
errors[:validation_errors] = []
|
||||
|
||||
file.read.each_line do |line|
|
||||
# Get the event id (text before :)
|
||||
id = line.match(/:/).pre_match.to_i
|
||||
# Get the commercial url (text after :)
|
||||
url = line.match(/:/).post_match
|
||||
event = Event.find_by(id: id)
|
||||
|
||||
# Go to next event, if the event is not found
|
||||
errors[:no_event] << id && next unless event
|
||||
|
||||
commercial = event.commercials.new(url: url)
|
||||
unless commercial.save
|
||||
errors[:validation_errors] << "Could not create commercial for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')'
|
||||
end
|
||||
end
|
||||
errors
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_url
|
||||
|
|
|
|||
|
|
@ -4,37 +4,60 @@
|
|||
%h1
|
||||
Events
|
||||
= "(#{@events.length})" if @events.any?
|
||||
.pull-right
|
||||
|
||||
.btn-group.pull-right
|
||||
%button.btn.btn-primary{ 'data-toggle' => 'modal', 'data-target' => '#mass-commercials-modal', title: 'Mass import of commercials for events' }
|
||||
Add Commercials
|
||||
|
||||
- if can? :create, Event
|
||||
=link_to 'Add Event', new_admin_conference_program_event_path(@conference.short_title), class: 'button btn btn-default btn-info'
|
||||
= link_to 'Add Event', new_admin_conference_program_event_path(@conference.short_title), class: 'button btn btn-default btn-info'
|
||||
|
||||
- if can? :read, Event
|
||||
.btn-group
|
||||
.btn-group
|
||||
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
||||
Export PDF
|
||||
%span.caret
|
||||
%ul.dropdown-menu{ role: 'menu' }
|
||||
%li= link_to 'All Events', admin_conference_program_events_path(@conference.short_title, format: :pdf, event_export_option: 'all')
|
||||
%li= link_to 'Confirmed Events', admin_conference_program_events_path(@conference.short_title, format: :pdf, event_export_option: 'confirmed')
|
||||
%li= link_to 'All Events with Comments', admin_conference_program_events_path(@conference.short_title, format: :pdf, event_export_option: 'all_with_comments')
|
||||
.btn-group
|
||||
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
||||
Export CSV
|
||||
%span.caret
|
||||
%ul.dropdown-menu{ role: 'menu' }
|
||||
%li= link_to 'All', admin_conference_program_events_path(@conference.short_title, format: :csv, event_export_option: 'all')
|
||||
%li= link_to 'Confirmed', admin_conference_program_events_path(@conference.short_title, format: :csv, event_export_option: 'confirmed')
|
||||
%li= link_to 'All with Comments', admin_conference_program_events_path(@conference.short_title, format: :csv, event_export_option: 'all_with_comments')
|
||||
.btn-group
|
||||
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
||||
Export XLS
|
||||
%span.caret
|
||||
%ul.dropdown-menu{ role: 'menu' }
|
||||
%li= link_to 'All', admin_conference_program_events_path(@conference.short_title, format: :xlsx, event_export_option: 'all')
|
||||
%li= link_to 'Confirmed', admin_conference_program_events_path(@conference.short_title, format: :xlsx, event_export_option: 'confirmed')
|
||||
%li= link_to 'All with Comments', admin_conference_program_events_path(@conference.short_title, format: :xlsx, event_export_option: 'all_with_comments')
|
||||
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
||||
Export PDF
|
||||
%span.caret
|
||||
%ul.dropdown-menu{ role: 'menu' }
|
||||
%li= link_to 'All Events', admin_conference_program_events_path(@conference.short_title, format: :pdf, event_export_option: 'all')
|
||||
%li= link_to 'Confirmed Events', admin_conference_program_events_path(@conference.short_title, format: :pdf, event_export_option: 'confirmed')
|
||||
%li= link_to 'All Events with Comments', admin_conference_program_events_path(@conference.short_title, format: :pdf, event_export_option: 'all_with_comments')
|
||||
.btn-group
|
||||
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
||||
Export CSV
|
||||
%span.caret
|
||||
%ul.dropdown-menu{ role: 'menu' }
|
||||
%li= link_to 'All', admin_conference_program_events_path(@conference.short_title, format: :csv, event_export_option: 'all')
|
||||
%li= link_to 'Confirmed', admin_conference_program_events_path(@conference.short_title, format: :csv, event_export_option: 'confirmed')
|
||||
%li= link_to 'All with Comments', admin_conference_program_events_path(@conference.short_title, format: :csv, event_export_option: 'all_with_comments')
|
||||
.btn-group
|
||||
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
||||
Export XLS
|
||||
%span.caret
|
||||
%ul.dropdown-menu{ role: 'menu' }
|
||||
%li= link_to 'All', admin_conference_program_events_path(@conference.short_title, format: :xlsx, event_export_option: 'all')
|
||||
%li= link_to 'Confirmed', admin_conference_program_events_path(@conference.short_title, format: :xlsx, event_export_option: 'confirmed')
|
||||
%li= link_to 'All with Comments', admin_conference_program_events_path(@conference.short_title, format: :xlsx, event_export_option: 'all_with_comments')
|
||||
|
||||
%p.text-muted
|
||||
All the submissions of your speakers
|
||||
|
||||
.modal#mass-commercials-modal
|
||||
.modal-dialog
|
||||
.modal-content
|
||||
.modal-header
|
||||
%h1 Add commercials to events
|
||||
.text-muted
|
||||
Upload your file with data in the following format:
|
||||
%b Event_ID:Commercial_Link
|
||||
, eg.
|
||||
%br
|
||||
%b 11:https://youtube.com/myvideo
|
||||
|
||||
.modal-body
|
||||
= semantic_form_for '', url: mass_upload_commercials_admin_conference_program_path(@conference.short_title), method: :post do |f|
|
||||
= f.input 'file', as: :file
|
||||
.modal-footer
|
||||
= f.submit 'Add', class: 'btn btn-primary'
|
||||
.row
|
||||
.col-md-4
|
||||
= render partial: 'admin/conferences/doughnut_chart', locals: { title: 'Events state', data: @event_distribution }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue