Skip to content

Commit

Permalink
Merge branch 'dev' into 87_US_2.10_Role_Management_Page
Browse files Browse the repository at this point in the history
  • Loading branch information
nstrelow committed Jan 18, 2017
2 parents 1641d01 + 873a45c commit 589f1ed
Show file tree
Hide file tree
Showing 63 changed files with 227 additions and 22 deletions.
Binary file added app/assets/images/event-detail.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/images/sample_images/copyright.md
@@ -0,0 +1,3 @@
#Disclaimer

All pictures in this directory were downloaded from Pixabay.com in January 2017under CC0 Public Domain License.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/assets/javascripts/events.js
Expand Up @@ -14,6 +14,15 @@ jQuery(function() {
});
});

function addCustomApplicationField() {
$(CUSTOM_APPLICATION_FIELD_TEMPLATE)
.insertBefore('#add-custom-application-fields');
}

function removeCustomApplicationField(button) {
$(button).parents('.input-group').remove();
}

function addEventDatePicker() {
var picker = $('#event-add-date-picker');

Expand Down
4 changes: 3 additions & 1 deletion app/assets/stylesheets/events.css
Expand Up @@ -52,6 +52,8 @@
.event-date {
text-align: center;
line-height: 3em;
}
.event-list .event-date {
margin-right: 15px;
float: left;
}
Expand All @@ -70,7 +72,7 @@
margin: -1.2em 0;
}
@media (max-width: 768px) {
.event-date {
.event-list .event-date {
float: none;
margin-bottom: 15px;
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Expand Up @@ -250,7 +250,7 @@ def set_event

# Only allow a trusted parameter "white list" through.
def event_params
params.require(:event).permit(:name, :description, :max_participants, :participants_are_unlimited, :kind, :organizer, :knowledge_level, :application_deadline, date_ranges_attributes: [:start_date, :end_date, :id])
params.require(:event).permit(:name, :description, :max_participants, :participants_are_unlimited, :kind, :organizer, :knowledge_level, :application_deadline, :custom_application_fields => [], date_ranges_attributes: [:start_date, :end_date, :id])
end

# Generate all names to print from the query-params
Expand Down
3 changes: 2 additions & 1 deletion app/models/ability.rb
Expand Up @@ -43,14 +43,15 @@ def initialize(user)
# Pupils can upload their letters of agreement
can [:create], AgreementLetter
can [:new, :create], Request
cannot :view_personal_details, ApplicationLetter, user: { id: !user.id }
end
if user.role? :coach
# Coaches can view Applications and participants for and view, upload and download materials for Event
can [:view_applicants, :view_participants, :view_material, :upload_material, :print_applications, :download_material], Event
can [:view_and_add_notes, :show], ApplicationLetter
can [:print_applications], Event
can :manage, Request
cannot [:check], ApplicationLetter
cannot :check, ApplicationLetter
end
if user.role? :organizer
can [:index, :show], Profile
Expand Down
2 changes: 1 addition & 1 deletion app/models/date_range.rb
Expand Up @@ -35,7 +35,7 @@ def validate_end_not_before_start

def to_s
if start_date == end_date
start_date
I18n.l(start_date)
else
I18n.l(start_date) + ' ' + I18n.t('date_range.pronouns.to') + ' ' + I18n.l(end_date)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/event.rb
Expand Up @@ -17,6 +17,8 @@ class Event < ActiveRecord::Base
UNREASONABLY_LONG_DATE_SPAN = 300
TRUNCATE_DESCRIPTION_TEXT_LENGTH = 250

serialize :custom_application_fields, Array

has_many :application_letters
has_many :agreement_letters
has_many :date_ranges
Expand Down
12 changes: 9 additions & 3 deletions app/views/application_letters/show.html.erb
Expand Up @@ -3,15 +3,21 @@
<h1><%=t '.title', :default => model_class.model_name.human.titleize %></h1>
</div>

<h3><%= @application_letter.user.profile.name %></h3>
<% if can? :show, @application_letter.user.profile %>
<h3><%= link_to @application_letter.user.profile.name, profile_path(@application_letter.user.profile) %></h3>
<% else %>
<h3><%= @application_letter.user.profile.name %></h3>
<% end %>

<dl class="dl-horizontal" id="applicant_details">
<dt><strong><%= Profile.human_attribute_name(:gender) %>:</strong></dt>
<dd><%= @application_letter.user.profile.gender %></dd>
<dt><strong><%= t('.age_when_event_starts') %>:</strong></dt>
<dd><%= @application_letter.user.profile.age_at_time(@application_letter.event.start_date) %></dd>
<dt><strong><%= Profile.human_attribute_name(:address) %>:</strong></dt>
<dd><%= @application_letter.user.profile.address %></dd>
<% if can? :view_personal_details, ApplicationLetter %>
<dt><strong><%= Profile.human_attribute_name(:address) %>:</strong></dt>
<dd><%= @application_letter.user.profile.address %></dd>
<% end %>
<dt><strong><%= User.human_attribute_name(:accepted_application_count) %>:</strong></dt>
<dd><%= @application_letter.user.accepted_applications_count(@application_letter.event) %></dd>
<dt><strong><%= User.human_attribute_name(:rejected_application_count) %>:</strong></dt>
Expand Down
10 changes: 10 additions & 0 deletions app/views/date_ranges/_date_range.html.erb
@@ -0,0 +1,10 @@
<p>
<% if date_range.start_date == date_range.end_date %>
<strong><%= l date_range.start_date %></strong>
<% else %>
<strong><%= l date_range.start_date %></strong>
<%= t 'date_range.pronouns.to' %>
<strong><%= l date_range.end_date %></strong>
<% end %>
</p>

25 changes: 25 additions & 0 deletions app/views/events/_custom_application_fields_input.html.erb
@@ -0,0 +1,25 @@
<div class="form-group">
<%= form.label :custom_application_fields, :class => 'control-label col-lg-2' %>
<div class="col-lg-10" id="custom-application-fields">
<% def custom_application_field_template(value = nil)
'<div class="input-group m-b-1">' +
(text_field_tag :"event[custom_application_fields][]", value, :class => 'form-control', placeholder: I18n.t('.events.form.label_of_custom_field')) +
'<span class="input-group-btn">' +
'<a class="btn btn-default" onclick="removeCustomApplicationField(event.target)">' +
'<span class="glyphicon glyphicon-remove"></span>' +
'</a>' +
'</span>' +
'</div>'
end %>
<%= @event.custom_application_fields
.map { |f| custom_application_field_template f }
.reduce(:+)
.html_safe unless @event.custom_application_fields.blank? %>
<%= link_to I18n.t('.events.form.add_field'), 'javascript:addCustomApplicationField()', id: 'add-custom-application-fields', class: 'btn btn-default btn-xs' %>
<p class="help-block"><%= I18n.t '.events.form.custom_application_fields_cant_be_changed_later' %></p>
</div>
<script>var CUSTOM_APPLICATION_FIELD_TEMPLATE = '<%= custom_application_field_template.gsub("\n", "").html_safe %>';</script>
</div>

8 changes: 1 addition & 7 deletions app/views/events/_event.html.erb
@@ -1,12 +1,6 @@
<div class="event-preview <%= 'event-past' if event.is_past %> clearfix">
<%= image_tag "example.png", class: "img-rounded img-responsive img-float-corner-tr center-block" %>
<div class="event-date">
<span class="event-day"><%= l event.start_date, format: "%d" %></span>
<span class="event-month"><%= l event.start_date, format: "%b" %></span>
<% if event.start_date.year != Time.now.year %>
<span class="event-year"><%= event.start_date.year %></span>
<% end %>
</div>
<%= render "events/event_date_large", event: event %>

<h3>
<%= event.name %>
Expand Down
7 changes: 7 additions & 0 deletions app/views/events/_event_date_large.html.erb
@@ -0,0 +1,7 @@
<div class="event-date text-center">
<span class="event-day"><%= l event.start_date, format: "%d" %></span>
<span class="event-month"><%= l event.start_date, format: "%b" %></span>
<% if event.start_date.year != Time.now.year %>
<span class="event-year"><%= event.start_date.year %></span>
<% end %>
</div>
2 changes: 2 additions & 0 deletions app/views/events/_form.html.erb
Expand Up @@ -89,6 +89,8 @@
</div>
</div>

<%= (render 'custom_application_fields_input', form: f) if @event.new_record? %>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<% if @event.draft == false %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/events/_show_event.html.erb
Expand Up @@ -24,6 +24,16 @@
<dd><%= @event.knowledge_level %></dd>
<dt><strong><%= model_class.human_attribute_name(:application_deadline) %>:</strong></dt>
<dd> <%= I18n.l(@event.application_deadline) + ' ' + I18n.t('midnight') %></dd>
<% if can? :manage, Event %>
<dt><strong><%= model_class.human_attribute_name(:custom_application_fields) %>:</strong></dt>
<dd>
<ul>
<% @event.custom_application_fields.each do |field| %>
<li><%= field %></li>
<% end %>
</ul>
</dd>
<% end %>
</dl>
<%= link_to t('.new', :default => t("helpers.links.apply")), new_application_letter_path(:event_id => @event.id),
:class => 'btn btn-info' %>
43 changes: 43 additions & 0 deletions app/views/events/_show_event_large.html.erb
@@ -0,0 +1,43 @@
<%- model_class = Event -%>
<div>
<div class="pull-right">
<%= link_to t("helpers.links.apply"), new_application_letter_path(:event_id => @event.id), class: "btn btn-success btn-sm" %>
<%= link_to t('.edit', :default => t('helpers.links.edit')), edit_event_path(@event),
:class => 'btn btn-default btn-sm' if can? :edit, @event %>
</div>
<h1><%= @event.name %></h1>
</div>
<%= image_tag "event-detail.png", class: "img-rounded img-responsive center-block m-t-1 m-b-1" %>
<div class="row">
<div class="col-md-1 col-md-offset-1 text-center col-sm-2">
<%= render "event_date_large", event: @event %>
<div class="m-t-1">
<%= render @event.date_ranges %>
</div>
</div>
<div class="col-md-7 col-sm-10">
<%= markdown @event.description %>
</div>
<div class="col-md-2 col-sm-offset-2">
<dl>
<dt><strong><%= model_class.human_attribute_name(:knowledge_level) %>:</strong></dt>
<dd><%= @event.knowledge_level %></dd>
<dt><strong><%= model_class.human_attribute_name(:max_participants) %>:</strong></dt>
<dd><%= @event.max_participants %></dd>
<dt><strong><%= model_class.human_attribute_name(:organizer) %>:</strong></dt>
<dd><%= @event.organizer %></dd>
<dt><strong><%= model_class.human_attribute_name(:application_deadline) %>:</strong></dt>
<dd> <%= I18n.l(@event.application_deadline) + ' ' + I18n.t('midnight') %></dd>
<% if can? :manage, Event %>
<dt><strong><%= model_class.human_attribute_name(:custom_application_fields) %>:</strong></dt>
<dd>
<ul>
<% @event.custom_application_fields.each do |field| %>
<li><%= field %></li>
<% end %>
</ul>
</dd>
<% end %>
</dl>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/events/show.html.erb
Expand Up @@ -11,7 +11,7 @@
</div>
<% end %>
<%= render :partial => 'show_event' %>
<%= render :partial => 'show_event_large' %>
<% if can? :view_applicants, Event %>
<%= render :partial => 'applicants_overview' %>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/de.events.yml
Expand Up @@ -95,6 +95,9 @@ de:
draft: "Speichern"
publish: "Veröffentlichen"
update: "Aktualisieren"
add_field: "Neues Feld hinzufügen"
label_of_custom_field: "Name des eigenen Felds"
custom_application_fields_cant_be_changed_later: "Die eigenen Felder für die Bewerbung können nach dem ersten Speichern nicht mehr geändert werden."
add_timespan: "Zeitspanne hinzufügen"
email:
templates: "Vorlagen"
Expand Down Expand Up @@ -123,6 +126,7 @@ de:
draft: "Entwurf"
organizer: "Veranstalter"
knowledge_level: "Kenntnisstand"
custom_application_fields: "Eigene Bewerbungs-Felder"
date_ranges:
one: "Zeitspanne"
other: "Zeitspannen"
Expand Down
@@ -0,0 +1,5 @@
class AddCustomApplicationFieldsToEvent < ActiveRecord::Migration
def change
add_column :events, :custom_application_fields, :text
end
end
7 changes: 4 additions & 3 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170114132153) do
ActiveRecord::Schema.define(version: 20170118132170) do

create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand Down Expand Up @@ -76,6 +76,7 @@
t.date "application_deadline"
t.boolean "application_status_locked"
t.boolean "participants_are_unlimited", default: false
t.text "custom_application_fields"
end

create_table "profiles", force: :cascade do |t|
Expand All @@ -98,8 +99,8 @@
add_index "profiles", ["user_id"], name: "index_profiles_on_user_id"

create_table "requests", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "form_of_address"
t.string "first_name"
t.string "last_name"
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/events_controller_spec.rb
Expand Up @@ -325,6 +325,7 @@
event = Event.create! valid_attributes
expect(assigns(:event).organizer).to eq(event.organizer)
expect(assigns(:event).knowledge_level).to eq(event.knowledge_level)
expect(assigns(:event).custom_application_fields).to eq(event.custom_application_fields)
end

it "redirects to the created event" do
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/date_ranges.rb
Expand Up @@ -23,5 +23,10 @@
start_date Date.current.prev_day(3)
end_date Date.yesterday
end

trait :on_single_day do
start_date Date.tomorrow
end_date Date.tomorrow
end
end
end
1 change: 1 addition & 0 deletions spec/factories/events.rb
Expand Up @@ -22,6 +22,7 @@
organizer "Workshop-Organizer"
knowledge_level "Workshop-Knowledge Level"
application_deadline Date.tomorrow
custom_application_fields ["Field 1", "Field 2", "Field 3"]
date_ranges { build_list :date_range, 1 }

trait :with_two_date_ranges do
Expand Down
25 changes: 25 additions & 0 deletions spec/features/application_letters_spec.rb
Expand Up @@ -149,6 +149,31 @@
expect(page).to have_text('Bewerbung erstellen')
end

%i[coach organizer].each do |role|
it "logged in as #{role} I cannot see personal details" do
login(role)
expect(page).to_not have_text(@application_letter.user.profile.address)
expect(page).to_not have_text(@application_letter.user.profile.school)
end
end

it "logged in as admin I can see personal details" do
login(:admin)
expect(page).to have_text(@application_letter.user.profile.address)
end

it "logged in as admin I cannot see the school of an applicant" do
login(:admin)
expect(page).to_not have_text(@application_letter.user.profile.school)
end

%i[organizer admin].each do |role|
it "logged in as #{role} I can click on the applicants name" do
login(role)
expect(page).to have_link(@application_letter.user.profile.name, :href => profile_path(@application_letter.user.profile))
end
end

def login(role)
@event = FactoryGirl.create(:event)
@profile = FactoryGirl.create(:profile)
Expand Down

0 comments on commit 589f1ed

Please sign in to comment.