mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
commit
dcae196d2b
16 changed files with 115 additions and 13 deletions
3
Gemfile
3
Gemfile
|
|
@ -80,6 +80,9 @@ gem 'cocoon'
|
|||
# as the JavaScript library
|
||||
gem 'jquery-rails'
|
||||
|
||||
# for languages validation
|
||||
gem 'iso-639'
|
||||
|
||||
# frontend javascripts
|
||||
source 'https://rails-assets.org' do
|
||||
# for placeholder images
|
||||
|
|
|
|||
|
|
@ -219,6 +219,7 @@ GEM
|
|||
i18n_data (0.7.0)
|
||||
inversion (0.12.3)
|
||||
loggability (~> 0.4)
|
||||
iso-639 (0.2.5)
|
||||
jquery-datatables-rails (2.2.3)
|
||||
jquery-rails
|
||||
sass-rails
|
||||
|
|
@ -561,6 +562,7 @@ DEPENDENCIES
|
|||
guard-rspec (~> 4.2.8)
|
||||
haml-rails
|
||||
hoptoad_notifier (~> 2.3)
|
||||
iso-639
|
||||
jquery-datatables-rails (~> 2.2.1)
|
||||
jquery-rails
|
||||
leaflet-rails
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ module Admin
|
|||
private
|
||||
|
||||
def program_params
|
||||
params.require(:program).permit(:rating, :schedule_public, :schedule_fluid)
|
||||
params.require(:program).permit(:rating, :schedule_public, :schedule_fluid, :languages)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,10 +20,12 @@ class ProposalController < ApplicationController
|
|||
def new
|
||||
@user = User.new
|
||||
@url = conference_program_proposal_index_path(@conference.short_title)
|
||||
@languages = @program.languages_list
|
||||
end
|
||||
|
||||
def edit
|
||||
@url = conference_program_proposal_path(@conference.short_title, params[:id])
|
||||
@languages = @program.languages_list
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
@ -144,7 +146,7 @@ class ProposalController < ApplicationController
|
|||
def event_params
|
||||
params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id,
|
||||
:title, :subtitle, :abstract, :description,
|
||||
:require_registration, :max_attendees)
|
||||
:require_registration, :max_attendees, :language)
|
||||
end
|
||||
|
||||
def user_params
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ class Program < ActiveRecord::Base
|
|||
|
||||
before_create :create_event_types
|
||||
before_create :create_difficulty_levels
|
||||
validate :check_languages_format
|
||||
|
||||
##
|
||||
# Checcks if the program has rating enabled
|
||||
|
|
@ -82,6 +83,10 @@ class Program < ActiveRecord::Base
|
|||
(!conference.email_settings.program_schedule_public_subject.blank? && !conference.email_settings.program_schedule_public_body.blank?)
|
||||
end
|
||||
|
||||
def languages_list
|
||||
self.languages.split(',').map {|l| ISO_639.find(l).english_name} if self.languages.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
|
|
@ -112,4 +117,20 @@ class Program < ActiveRecord::Base
|
|||
color: '#EF6E69')
|
||||
true
|
||||
end
|
||||
|
||||
##
|
||||
# Check if languages string has the right format. Used as validation.
|
||||
#
|
||||
def check_languages_format
|
||||
return unless self.languages.present?
|
||||
# All white spaces are removed to allow languages to be separated by ',' and ', '. The languages string without spaces is saved
|
||||
self.languages = self.languages.delete(' ').downcase
|
||||
errors.add(:languages, 'must be two letters separated by commas') && return unless
|
||||
self.languages.match(/^$|(\A[a-z][a-z](,[a-z][a-z])*\z)/).present?
|
||||
languages_array = self.languages.split(',')
|
||||
# We check that languages are not repeated
|
||||
errors.add(:languages, "can't be repeated") && return unless languages_array.uniq!.nil?
|
||||
# We check if every language is a valid ISO 639-1 language
|
||||
errors.add(:languages, 'must be ISO 639-1 valid codes') unless languages_array.select{ |x| ISO_639.find(x).nil? }.empty?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -98,6 +98,14 @@
|
|||
off_text: 'No' }
|
||||
- if @event.require_registration
|
||||
= registered_text(@event)
|
||||
|
||||
-if @program.languages.present?
|
||||
%tr
|
||||
%td
|
||||
%b Language
|
||||
%td
|
||||
= @event.language
|
||||
|
||||
- if !@event.room.nil?
|
||||
%tr
|
||||
%td
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@
|
|||
%b Submitter
|
||||
%th
|
||||
%b Speaker
|
||||
-if @program.languages.present?
|
||||
%th
|
||||
%b Language
|
||||
%th
|
||||
%b Requires Registration
|
||||
%th
|
||||
|
|
@ -83,6 +86,10 @@
|
|||
- else
|
||||
Unknown speaker
|
||||
|
||||
-if @program.languages.present?
|
||||
%td
|
||||
= event.language
|
||||
|
||||
%td.text-center{'data-order' => "#{event.require_registration}"}
|
||||
= check_box_tag @conference.short_title, event.id, event.require_registration,
|
||||
method: :patch, url: "/admin/conference/#{@conference.short_title}/program/events/#{event.id}?event[require_registration]=",
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
%h1 Program
|
||||
.row
|
||||
.col-md-8
|
||||
= semantic_form_for(@program, :url => admin_conference_program_path(@conference.short_title),:html => {:multipart => true}) do |f|
|
||||
= semantic_form_for(@program, url: admin_conference_program_path(@conference.short_title), html: {multipart: true}) do |f|
|
||||
= f.input :schedule_public, label: "Show Schedule on the home and splash page"
|
||||
= f.input :schedule_fluid, label: "Allow submitters to change their event after it is scheduled"
|
||||
= f.input :rating, :hint => "Enter the number of different rating levels you want to have for voting on proposals. Enter 0 if you do not want to vote on proposals."
|
||||
= f.input :rating, hint: 'Enter the number of different rating levels you want to have for voting on proposals. Enter 0 if you do not want to vote on proposals.'
|
||||
= f.input :languages, hint: "Enter the languages allowed for events as values of #{link_to('ISO 639-1', 'http://www.loc.gov/standards/iso639-2/php/code_list.php', target: "_blank")} language codes separated with commas. The first language would be the default language. Leave it blank if you do not want to specify languages.".html_safe
|
||||
%p.text-right
|
||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
||||
= f.action :submit, as: :button, button_html: {class: 'btn btn-primary'}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@
|
|||
Difficulty Levels:
|
||||
%dd
|
||||
= difficulty_levels(@conference)
|
||||
%dt
|
||||
Languages:
|
||||
%dd
|
||||
= @program.languages
|
||||
%dt
|
||||
Public Schedule
|
||||
%dd#schedule_public
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@
|
|||
data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length }]},
|
||||
include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' }
|
||||
|
||||
- if @program.languages.present?
|
||||
= f.input :language, as: :select,
|
||||
collection: @languages,
|
||||
include_blank: false, label: 'Language', input_html: { class: 'select-help-toggle' }
|
||||
|
||||
- @conference.program.event_types.each do |event_type|
|
||||
%span{ class: 'help-block select-help-text event_event_type_id collapse', id: "#{event_type.id}-help" }
|
||||
= event_type.description
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@
|
|||
data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length }]},
|
||||
include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' }
|
||||
|
||||
- if @program.languages.present?
|
||||
= f.input :language, as: :select,
|
||||
collection: @languages,
|
||||
include_blank: false, label: 'Language', input_html: { class: 'select-help-toggle' }
|
||||
|
||||
- @program.event_types.each do |event_type|
|
||||
%span{ class: 'help-block event_event_type_id collapse', id: "#{event_type.id}-help" }
|
||||
= event_type.description
|
||||
|
|
|
|||
5
db/migrate/20160320220630_add_languages_to_program.rb
Normal file
5
db/migrate/20160320220630_add_languages_to_program.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddLanguagesToProgram < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :programs, :languages, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -266,6 +266,7 @@ ActiveRecord::Schema.define(version: 20160427104236) do
|
|||
t.boolean "schedule_fluid", default: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "languages"
|
||||
end
|
||||
|
||||
create_table "qanswers", force: :cascade do |t|
|
||||
|
|
|
|||
|
|
@ -58,4 +58,37 @@ describe Program do
|
|||
expect(conference.program.difficulty_levels.count).to eq 3
|
||||
end
|
||||
end
|
||||
|
||||
describe 'languages' do
|
||||
it "is not valid if languages aren't two letters separated by commas" do
|
||||
program.languages = 'eng, De es'
|
||||
expect(program.valid?).to eq false
|
||||
expect(program.errors[:languages]).to eq ['must be two letters separated by commas']
|
||||
end
|
||||
|
||||
it 'is not valid if languages are repeated' do
|
||||
program.languages = 'en,de,es,en'
|
||||
expect(program.valid?).to eq false
|
||||
expect(program.errors[:languages]).to eq ["can't be repeated"]
|
||||
end
|
||||
|
||||
it "is not valid if languages aren't ISO 639-1 valid codes" do
|
||||
program.languages = 'en,hh,yu,zi,oo'
|
||||
expect(program.valid?).to eq false
|
||||
expect(program.errors[:languages]).to eq ['must be ISO 639-1 valid codes']
|
||||
end
|
||||
|
||||
it 'is valid otherwise' do
|
||||
program.languages = 'en,De, ES, ru,el'
|
||||
expect(program.valid?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#languages_list' do
|
||||
it 'returns the list of readable languages' do
|
||||
program.languages = 'en,de,fr,ru,zh'
|
||||
expect(program.languages_list).to eq %w(English German French Russian Chinese)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ require 'spec_helper'
|
|||
describe 'admin/events/index' do
|
||||
let!(:conference) { create(:conference) }
|
||||
let!(:program) { conference.program }
|
||||
let!(:event1) { create(:event, program: conference.program, title: 'event1') }
|
||||
let!(:event2) { create(:event, program: conference.program, title: 'event2') }
|
||||
let!(:event1) { create(:event, program: conference.program, title: 'event1', language: 'English') }
|
||||
let!(:event2) { create(:event, program: conference.program, title: 'event2', language: 'German') }
|
||||
|
||||
it 'renders all conference events' do
|
||||
assign(:conference, conference)
|
||||
assign(:program, conference.program)
|
||||
program.languages = 'en,de'
|
||||
assign(:events, [ event1, event2 ])
|
||||
assign(:event_types, [ create(:event_type, program: conference.program), create(:event_type, program: conference.program) ])
|
||||
assign(:tracks, [ create(:track, program: conference.program), create(:track, program: conference.program) ])
|
||||
|
|
@ -20,18 +21,21 @@ describe 'admin/events/index' do
|
|||
expect(rendered).to have_selector('table thead th:nth-of-type(2)', text: 'Title')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(3)', text: 'Submitter')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(4)', text: 'Speaker')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(5)', text: 'Requires Registration')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(6)', text: 'Highlight')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(7)', text: 'Type')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(8)', text: 'Track')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(9)', text: 'Difficulty')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(10)', text: 'State')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(5)', text: 'Language')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(6)', text: 'Requires Registration')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(7)', text: 'Highlight')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(8)', text: 'Type')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(9)', text: 'Track')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(10)', text: 'Difficulty')
|
||||
expect(rendered).to have_selector('table thead th:nth-of-type(11)', text: 'State')
|
||||
|
||||
expect(conference.program.events.count).to eq 2
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(1) td:nth-of-type(1)', text: event1.id)
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(1) td:nth-of-type(2)', text: 'event1')
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(1) td:nth-of-type(5)', text: 'English')
|
||||
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(2) td:nth-of-type(1)', text: event2.id)
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(2) td:nth-of-type(2)', text: 'event2')
|
||||
expect(rendered).to have_selector('table tr:nth-of-type(2) td:nth-of-type(5)', text: 'German')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,5 +12,6 @@ describe 'admin/programs/show' do
|
|||
expect(rendered).to have_css('dt', text: 'Tracks:')
|
||||
expect(rendered).to have_css('dt', text: 'Difficulty Levels:')
|
||||
expect(rendered).to have_css('dd', text: 'Easy, Medium and Hard')
|
||||
expect(rendered).to have_css('dt', text: 'Languages:')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue