Merge branch 'master' into patch-1
This commit is contained in:
commit
f28a3517e6
8 changed files with 102 additions and 31 deletions
|
|
@ -49,6 +49,26 @@ module Admin
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def commercial_params
|
def commercial_params
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ class Commercial < ApplicationRecord
|
||||||
|
|
||||||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
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))
|
validates :url, format: URI::regexp(%w(http https))
|
||||||
|
|
||||||
validate :valid_url
|
validate :valid_url
|
||||||
|
|
@ -20,6 +20,29 @@ class Commercial < ApplicationRecord
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def valid_url
|
def valid_url
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,15 @@
|
||||||
%h1
|
%h1
|
||||||
Events
|
Events
|
||||||
= "(#{@events.length})" if @events.any?
|
= "(#{@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
|
- 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
|
- if can? :read, Event
|
||||||
.btn-group
|
|
||||||
.btn-group
|
.btn-group
|
||||||
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
%button.btn.btn-default.dropdown-toggle{ 'data-toggle' => 'dropdown', type: 'button', class: 'btn btn-success' }
|
||||||
Export PDF
|
Export PDF
|
||||||
|
|
@ -33,8 +37,27 @@
|
||||||
%li= link_to 'All', admin_conference_program_events_path(@conference.short_title, format: :xlsx, event_export_option: 'all')
|
%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 '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')
|
%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
|
%p.text-muted
|
||||||
All the submissions of your speakers
|
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
|
.row
|
||||||
.col-md-4
|
.col-md-4
|
||||||
= render partial: 'admin/conferences/doughnut_chart', locals: { title: 'Events state', data: @event_distribution }
|
= render partial: 'admin/conferences/doughnut_chart', locals: { title: 'Events state', data: @event_distribution }
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,8 @@
|
||||||
= humanized_money @total_price_per_ticket[ticket_id]
|
= humanized_money @total_price_per_ticket[ticket_id]
|
||||||
%br
|
%br
|
||||||
- if @tickets.any?
|
- if @tickets.any?
|
||||||
|
.btn-group
|
||||||
|
= link_to 'View all tickets', conference_physical_tickets_path(@conference.short_title), class: "btn btn-success"
|
||||||
= link_to 'Get more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"
|
= link_to 'Get more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"
|
||||||
- else
|
- else
|
||||||
You haven't bought any tickets.
|
You haven't bought any tickets.
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ elif [[ "$ID" == "centos" || "$VERSION" == "7" ]]; then
|
||||||
tar jxvf /tmp/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /tmp/ phantomjs-2.1.1-linux-x86_64/bin/phantomjs
|
tar jxvf /tmp/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /tmp/ phantomjs-2.1.1-linux-x86_64/bin/phantomjs
|
||||||
mv /tmp/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin
|
mv /tmp/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin
|
||||||
|
|
||||||
|
pushd /vagrant
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\ninstalling your bundle...\n"
|
echo -e "\ninstalling your bundle...\n"
|
||||||
|
|
@ -64,7 +65,7 @@ if [ ! -f /vagrant/config/database.yml ] && [ -f /vagrant/config/database.yml.ex
|
||||||
echo -e "\nSetting up your database from config/database.yml...\n"
|
echo -e "\nSetting up your database from config/database.yml...\n"
|
||||||
cp config/database.yml.example config/database.yml
|
cp config/database.yml.example config/database.yml
|
||||||
if [ ! -f db/development.sqlite3 ] && [ ! -f db/test.sqlite3 ]; then
|
if [ ! -f db/development.sqlite3 ] && [ ! -f db/test.sqlite3 ]; then
|
||||||
bundle exec rake db:setup
|
su - vagrant -c "cd /vagrant/; bundle exec rake db:setup"
|
||||||
else
|
else
|
||||||
echo -e "\n\nWARNING: You have already have a development/test database."
|
echo -e "\n\nWARNING: You have already have a development/test database."
|
||||||
echo -e "WARNING: Please make sure this database works in this vagrant box!\n\n"
|
echo -e "WARNING: Please make sure this database works in this vagrant box!\n\n"
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ Osem::Application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :event_types
|
resources :event_types
|
||||||
resources :difficulty_levels
|
resources :difficulty_levels
|
||||||
|
post 'mass_upload_commercials' => 'commercials#mass_upload'
|
||||||
resources :events do
|
resources :events do
|
||||||
member do
|
member do
|
||||||
patch :toggle_attendance
|
patch :toggle_attendance
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :commercial do
|
factory :commercial do
|
||||||
url 'https://www.youtube.com/watch?v=BTTygyxuGj8'
|
sequence(:url) { |n| "https://www.youtube.com/watch?v=BTTygyxuGj#{n}" }
|
||||||
|
|
||||||
factory :conference_commercial do
|
factory :conference_commercial do
|
||||||
association :commercialable, factory: :conference
|
association :commercialable, factory: :conference
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,8 @@ feature Commercial do
|
||||||
scenario 'does not update a commercial of an event with invalid data', feature: true, versioning: true, js: true do
|
scenario 'does not update a commercial of an event with invalid data', feature: true, versioning: true, js: true do
|
||||||
commercial = create(:commercial,
|
commercial = create(:commercial,
|
||||||
commercialable_id: event.id,
|
commercialable_id: event.id,
|
||||||
commercialable_type: 'Event')
|
commercialable_type: 'Event',
|
||||||
|
url: 'https://www.youtube.com/watch?v=BTTygyxuGj8')
|
||||||
visit edit_conference_program_proposal_path(conference.short_title, event.id)
|
visit edit_conference_program_proposal_path(conference.short_title, event.id)
|
||||||
click_link 'Commercials'
|
click_link 'Commercials'
|
||||||
fill_in "commercial_url_#{commercial.id}", with: 'invalid_commercial_url'
|
fill_in "commercial_url_#{commercial.id}", with: 'invalid_commercial_url'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue