mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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
|
||||
|
||||
##
|
||||
# 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 }
|
||||
|
|
|
|||
|
|
@ -104,7 +104,9 @@
|
|||
= humanized_money @total_price_per_ticket[ticket_id]
|
||||
%br
|
||||
- if @tickets.any?
|
||||
= link_to 'Get more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"
|
||||
.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"
|
||||
- else
|
||||
You haven't bought any tickets.
|
||||
= link_to 'Please get some tickets to support us!', conference_tickets_path(@conference.short_title)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
mv /tmp/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin
|
||||
|
||||
pushd /vagrant
|
||||
fi
|
||||
|
||||
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"
|
||||
cp config/database.yml.example config/database.yml
|
||||
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
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ Osem::Application.routes.draw do
|
|||
end
|
||||
resources :event_types
|
||||
resources :difficulty_levels
|
||||
post 'mass_upload_commercials' => 'commercials#mass_upload'
|
||||
resources :events do
|
||||
member do
|
||||
patch :toggle_attendance
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
FactoryGirl.define 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
|
||||
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
|
||||
commercial = create(:commercial,
|
||||
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)
|
||||
click_link 'Commercials'
|
||||
fill_in "commercial_url_#{commercial.id}", with: 'invalid_commercial_url'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue