Skip to content

Commit

Permalink
Merge branch 'dev' into 555_show_agreement_letter_upload_form_only_wh…
Browse files Browse the repository at this point in the history
…en_accepted
  • Loading branch information
Blaidd-Drwg committed Feb 8, 2017
2 parents fdb1a34 + 0113297 commit 3784ac4
Show file tree
Hide file tree
Showing 25 changed files with 248 additions and 74 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ gem 'mini_magick'
# Ical generator
gem 'icalendar'

# Pattern generator
gem 'geo_pattern'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
Expand Down
4 changes: 0 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ GEM
codeclimate-test-reporter (1.0.3)
simplecov
coderay (1.1.1)
color (1.8)
combine_pdf (0.2.32)
ruby-rc4 (>= 0.1.5)
commonjs (0.2.7)
Expand Down Expand Up @@ -117,8 +116,6 @@ GEM
railties (>= 3.0.0)
figaro (1.1.1)
thor (~> 0.14)
geo_pattern (1.4.0)
color (~> 1.5)
globalid (0.3.7)
activesupport (>= 4.1.0)
has_scope (0.7.0)
Expand Down Expand Up @@ -334,7 +331,6 @@ DEPENDENCIES
devise_openid_authenticatable
factory_girl_rails
figaro
geo_pattern
has_scope
icalendar
jquery-rails
Expand Down
Binary file added app/assets/images/stock_photos/DSC02540.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stock_photos/Sommercamp-12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stock_photos/Sommercamp-28.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stock_photos/Sommercamp-42.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stock_photos/Sommercamp-47.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion app/assets/stylesheets/custom_bootstrap/custom_bootstrap.less
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ a:hover h1, a:hover h2, a:hover h3, a:hover h4 {
input.form-control {
font-family: @font-family-serif;
}
.control-label {
word-wrap: break-word;
}


.event-date {
Expand All @@ -231,4 +234,16 @@ input.form-control {
}
}

@import "custom_bootstrap/multi-select.css";

@import "multi-select.css";

.image-buttons .btn {
height: 100px;
width: 100px;
background-size: cover;
background-position: center;
border: 3px solid @body-bg;
}
.image-buttons .btn.active {
border: 3px solid @brand-primary;
}
6 changes: 4 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
require 'rubygems'
require 'zip'
require 'carrierwave'
require "event_image_upload_helper"

class EventsController < ApplicationController
include EventImageUploadHelper

before_action :set_event, only: [:show, :edit, :update, :destroy, :participants,
:participants_pdf, :print_applications, :print_applications_eating_habits, :badges, :print_badges]
Expand Down Expand Up @@ -34,7 +36,7 @@ def show

# GET /events/new
def new
@event = Event.new
@event = Event.new image: stock_photo_paths.first
end

# GET /events/1/edit
Expand Down Expand Up @@ -264,7 +266,7 @@ def set_event
end

def event_params
params.require(:event).permit(:name, :description, :image, :max_participants, :organizer, :knowledge_level, :application_deadline, :published, :hidden, :custom_application_fields => [], date_ranges_attributes: [:start_date, :end_date, :id])
params.require(:event).permit(:name, :description, :image, :custom_image, :custom_image_cache, :max_participants, :organizer, :knowledge_level, :application_deadline, :published, :hidden, :custom_application_fields => [], date_ranges_attributes: [:start_date, :end_date, :id])
end

def add_event_query_conditions(query)
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,4 @@ def resource
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end

# Generates a nice looking pattern in one of the HPI colors
# for the given string.
def geopattern(string)
colors = ['#B1073A', '#DE6207', '#F7A900']
color = colors[Digest::SHA1.hexdigest(string).to_i(16) % colors.size]
GeoPattern.generate(string, color: color)
end
end
16 changes: 16 additions & 0 deletions app/helpers/event_image_upload_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module EventImageUploadHelper
# @return [Array] paths to all stock photos
def stock_photo_paths
Dir.glob('app/assets/images/stock_photos/*').map do |image|
'stock_photos/' + image.split('/').last
end
end

# Given a path returns the string stripped from all invalid chars in an id
#
# @param path [String] the path to be stripped
# @return [String] the id
def path_to_id(path)
path.gsub(/[^A-Za-z0-9._-]/, '')
end
end
19 changes: 17 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Event < ActiveRecord::Base

serialize :custom_application_fields, Array

mount_uploader :image, EventImageUploader
mount_uploader :custom_image, EventImageUploader

has_many :application_letters
has_many :agreement_letters
Expand All @@ -38,10 +38,25 @@ class Event < ActiveRecord::Base
validates :published, exclusion: { in: [nil] }
validate :check_image_dimensions

after_validation :update_image

# if we uploaded a custom image, we want it to be synced to the "official"
# image slot. only do this if we actually uploaded one and that image is valid
def update_image
if custom_image.filename.present? and errors[:custom_image].empty?
self.image = '/' + custom_image.list_view.store_path
end
end

# Use the image dimensions as returned from our uploader
# to verify that the image has sufficient size
def check_image_dimensions
errors.add(:image, I18n.t("events.errors.image_too_small")) if image.upload_width.present? && image.upload_height.present? && (image.upload_width < 200 || image.upload_height < 155)
if custom_image.upload_width.present? &&
custom_image.upload_height.present? &&
(custom_image.upload_width < 200 || custom_image.upload_height < 155)
errors.add(:custom_image, I18n.t("events.errors.image_too_small"))
custom_image.remove!
end
end


Expand Down
4 changes: 2 additions & 2 deletions app/uploaders/event_image_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EventImageUploader < CarrierWave::Uploader::Base
# Return the directory that images will be uploaded to
# @return [String] the path relative to the `public` folder
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
"uploads/#{model.class.to_s.underscore}/#{mounted_as}"
end

before :cache, :capture_size_before_cache
Expand All @@ -32,7 +32,7 @@ def capture_size_before_cache(new_file)
end

version :thumb do
process resize_to_fill: [50, 50]
process resize_to_fill: [100, 100]
end

# white list of extensions which are allowed to be uploaded
Expand Down
4 changes: 2 additions & 2 deletions app/views/application_letters/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
</div>

<% if @application_letter.event
@application_letter.event.custom_application_fields.each do |field_name| %>
@application_letter.event.custom_application_fields.zip(@application_letter.custom_application_fields).each do |field_name, field_value| %>
<div class="form-group">
<%= label_tag "custom_application_fields[]", field_name, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= text_field_tag "custom_application_fields[]", nil, :class => 'form-control' %> <%=f.error_span("custom_application_fields[]") %>
<%= text_field_tag "custom_application_fields[]", field_value, :class => 'form-control' %> <%=f.error_span("custom_application_fields[]") %>
</div>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_event.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="event-preview media clearfix">
<%= image_tag event.image_url(:list_view), class: "img-rounded img-responsive img-float-corner-tr center-block" if event.image_url%>
<%= image_tag event.image, class: "img-responsive img-float-corner-tr center-block", width: 200 if event.image.present? %>
<div class="media-left">
<%= render "events/event_date_large", event: event %>
</div>
Expand Down
11 changes: 1 addition & 10 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@
</div>
</div>

<div class="form-group">
<%= f.label :image, :class => 'control-label col-lg-2' %>
<%= image_tag(@event.image_url) if @event.image? %>
<div class="col-lg-10">
<%= f.error_span(:image) %>
<%= I18n.t :"events.image_upload.upload_local_file" %><br/>
<%= f.file_field :image %>
</div>
</div>

<div class="form-group">
<%= f.label :max_participants, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
Expand Down Expand Up @@ -118,6 +108,7 @@
<%=f.error_span(:application_deadline) %>
</div>
</div>
<%= render 'image_upload', form: f %>
<%= (render 'custom_application_fields_input', form: f) if @event.new_record? %>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
Expand Down
34 changes: 34 additions & 0 deletions app/views/events/_image_upload.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<div class="form-group">
<%= form.label :image, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<div class="image-buttons" data-toggle="buttons">

<% if @event.custom_image? %>
<% val = @event.custom_image_url(:list_view) %>
<label class="btn <%= 'active' if val == @event.image %>" style="background-image: url(<%= image_path(@event.custom_image_url(:thumb)) %>)">
<%= form.radio_button :image, val, id: path_to_id(val), autocomplete: 'off' %>
</label>
<% end %>
<% stock_photo_paths.each do |image| %>
<label class="btn <%= 'active' if image == @event.image %>" style="background-image: url(<%= image_path(image) %>)">
<%= form.radio_button :image, image, id: path_to_id(image), autocomplete: 'off' %>
</label>
<% end %>

</div>

<div class="panel panel-default m-t-1">
<div class="panel-body">
<strong><p><%= I18n.t 'events.image_upload.upload_local_file' %></p></strong>
<%= form.file_field :custom_image %>
<%= form.hidden_field :custom_image_cache %>
<p class="help-block"><%= t 'events.errors.image_too_small' %></p>
<%= form.error_span(:custom_image) %>
</div>
</div>
<%= form.error_span(:image) %>
</div>
</div>

1 change: 0 additions & 1 deletion app/views/events/_show_event_large.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</div>
<h1><%= @event.name %></h1>
</div>
<div id="wsp-event-show-banner" style="background-image: <%= geopattern(@event.name).to_data_uri %>"></div>
<div class="row">
<div class="col-md-1 col-md-offset-1 text-center col-sm-2">
<%= render "event_date_large", event: @event %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170207133819_add_custom_image_to_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCustomImageToEvents < ActiveRecord::Migration
def change
add_column :events, :custom_image, :string
end
end
26 changes: 14 additions & 12 deletions db/sample_data/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def event_programmierkurs
application_deadline: Date.tomorrow,
published: true,
hidden: true,
custom_application_fields: ['Lieblingsapp', 'Klassenstufe', 'Mit welchen Programmiersprachen hast du bereits Erfahrungen gesammelt']

custom_application_fields: ['Lieblingsapp', 'Klassenstufe', 'Mit welchen Programmiersprachen hast du bereits Erfahrungen gesammelt'],
image: 'stock_photos/DSC02540.jpg'
)
end

Expand All @@ -41,8 +41,8 @@ def event_mintcamp
application_deadline: Date.tomorrow,
hidden: false,
published: true,
custom_application_fields: ['Klassenstufe', 'Mit welchen Programmiersprachen hast du bereits Erfahrungen gesammelt']

custom_application_fields: ['Klassenstufe', 'Mit welchen Programmiersprachen hast du bereits Erfahrungen gesammelt'],
image: 'stock_photos/Sommercamp-28.jpg'
)
end

Expand All @@ -63,8 +63,8 @@ def event_bechersaeuberungsevent
application_deadline: Date.yesterday.prev_day(2),
published: true,
hidden: false,
custom_application_fields: ['Lieblings-Becherart', 'Kannst du eine eigene Spülmaschine mitbringen?']

custom_application_fields: ['Lieblings-Becherart', 'Kannst du eine eigene Spülmaschine mitbringen?'],
image: 'stock_photos/Sommercamp-12.jpg'
)
end

Expand All @@ -84,8 +84,8 @@ def event_gongakrobatik
date_ranges: [date_range_long],
application_deadline: Date.tomorrow,
hidden: false,
published: true

published: true,
image: 'stock_photos/Sommercamp-42.jpg'
)
end

Expand All @@ -112,7 +112,8 @@ def event_batterie_akustik
application_deadline: Date.tomorrow,
published: false,
hidden: false,
custom_application_fields: ['Spielst du gerne in deiner Freizeit mit Batterien?']
custom_application_fields: ['Spielst du gerne in deiner Freizeit mit Batterien?'],
image: 'stock_photos/Sommercamp-47.jpg'
)
end

Expand All @@ -136,7 +137,8 @@ def event_bachlorpodium
date_ranges: [date_range_singleday1, date_range_singleday2, date_range_singleday3],
application_deadline: Date.tomorrow,
hidden: true,
published: true
published: true,
image: 'stock_photos/DSC02540.jpg'
)
end

Expand All @@ -160,7 +162,7 @@ def event_summer_camp
date_ranges: [date_range_summer_camp],
application_deadline: Date.tomorrow,
hidden: false,
published: true

published: true,
image: 'stock_photos/Sommercamp-47.jpg'
)
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170203180638) do
ActiveRecord::Schema.define(version: 20170207133819) do

create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand Down Expand Up @@ -85,6 +85,7 @@
t.string "image"
t.boolean "rejections_have_been_sent", default: false
t.boolean "acceptances_have_been_sent", default: false
t.string "custom_image"
end

create_table "participant_groups", force: :cascade do |t|
Expand Down
10 changes: 10 additions & 0 deletions spec/features/application_letters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
expect(page).to have_text("#{field_name}: value #{index}")
end
end

it "displays values I entered in custom fields when I edit the application later" do
letter = FactoryGirl.create(:application_letter)
login_as(letter.user, :scope => :user)
visit edit_application_letter_path(letter)

letter.custom_application_fields.each do |field|
expect(page).to have_css("input[value='#{field}']")
end
end
end

%i[pupil coach].each do |role|
Expand Down
Loading

0 comments on commit 3784ac4

Please sign in to comment.