Skip to content

Commit

Permalink
Merge e09eb8c into 30ba7b1
Browse files Browse the repository at this point in the history
  • Loading branch information
differentreality committed Mar 31, 2018
2 parents 30ba7b1 + e09eb8c commit 90a1404
Show file tree
Hide file tree
Showing 61 changed files with 1,143 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .haml-lint_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ linters:
- "app/views/admin/sponsors/index.html.haml"
- "app/views/admin/sponsorship_levels/_form.html.haml"
- "app/views/admin/sponsorship_levels/index.html.haml"
- "app/views/admin/surveys/index.html.haml"
- "app/views/admin/surveys/show.html.haml"
- "app/views/admin/targets/_form.html.haml"
- "app/views/admin/targets/index.html.haml"
- "app/views/admin/tickets/_form.html.haml"
Expand Down Expand Up @@ -161,6 +163,9 @@ linters:
- "app/views/schedules/events.html.haml"
- "app/views/schedules/show.html.haml"
- "app/views/schedules/show.xml.haml"
- "app/views/surveys/*"
- "app/views/admin/surveys/*"
- "app/views/admin/survey_questions/*.html.haml"
- "app/views/shared/_changelog_actions.haml"
- "app/views/shared/_dynamic_association.html.haml"
- "app/views/shared/_media_item.html.haml"
Expand Down Expand Up @@ -210,6 +215,8 @@ linters:
- "app/views/admin/splashpages/_form.html.haml"
- "app/views/admin/sponsors/_form.html.haml"
- "app/views/admin/sponsorship_levels/_form.html.haml"
- "app/views/admin/survey_questions/*"
- "app/views/admin/surveys/*"
- "app/views/admin/tickets/_form.html.haml"
- "app/views/admin/tracks/_form.html.haml"
- "app/views/admin/users/_form.html.haml"
Expand Down Expand Up @@ -447,3 +454,5 @@ linters:
- "app/views/conferences/_gallery.html.haml"
- "app/views/layouts/_navigation.html.haml"
- "app/views/schedules/events.html.haml"
- "app/views/admin/survey_questions/*"
- "app/views/admin/surveys/*"
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ source 'https://rails-assets.org' do
gem 'rails-assets-waypoints'
# for markdown editors
gem 'rails-assets-bootstrap-markdown'
# for select with icon
gem 'rails-assets-bootstrap-select'
gem 'rails-assets-markdown'
gem 'rails-assets-to-markdown'
end
Expand All @@ -121,6 +123,7 @@ gem 'jquery-datatables-rails', '~> 2.2.1'

# for charts
gem 'chart-js-rails'
gem 'chartkick'

# for displaying maps
gem 'leaflet-rails'
Expand Down
11 changes: 8 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ GEM
fastimage
chart-js-rails (0.0.6)
railties (> 3.1)
chartkick (2.2.5)
chronic (0.10.2)
chunky_png (1.3.8)
climate_control (0.2.0)
Expand Down Expand Up @@ -381,17 +382,19 @@ GEM
rails-assets-jquery (>= 1.9.1, < 3)
rails-assets-bootstrap-markdown (2.10.0)
rails-assets-bootstrap (~> 3)
rails-assets-bootstrap-select (1.10.0)
rails-assets-jquery (>= 1.8)
rails-assets-date.format (1.2.3)
rails-assets-holderjs (2.9.3)
rails-assets-jquery (2.2.1)
rails-assets-jquery (2.2.4)
rails-assets-jquery-smooth-scroll (1.7.2)
rails-assets-jquery (>= 1.4.2)
rails-assets-markdown (0.5.0)
rails-assets-momentjs (2.11.2)
rails-assets-momentjs (2.13.0)
rails-assets-spectrum (1.8.0)
rails-assets-jquery (>= 1.7.2)
rails-assets-tinycolor (1.3.0)
rails-assets-to-markdown (1.3.0)
rails-assets-to-markdown (3.0.0)
rails-assets-trianglify (0.4.0)
rails-assets-waypoints (4.0.0)
rails-controller-testing (1.0.2)
Expand Down Expand Up @@ -591,6 +594,7 @@ DEPENDENCIES
carrierwave
carrierwave-bombshelter
chart-js-rails
chartkick
climate_control
cloudinary
cocoon
Expand Down Expand Up @@ -641,6 +645,7 @@ DEPENDENCIES
puma (~> 3.0)
rails (~> 5.0.5)
rails-assets-bootstrap-markdown!
rails-assets-bootstrap-select!
rails-assets-date.format!
rails-assets-holderjs!
rails-assets-jquery-smooth-scroll!
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require cocoon
//= require bootstrap
//= require Chart
//= require osem
//= require osem-dashboard
//= require ahoy
Expand All @@ -47,6 +46,8 @@
//= require unobtrusive_flash_bootstrap
//= require countable
//= require selectize
//= require bootstrap-select
//= require osem-survey

$(document).ready(function() {
$('a[disabled=disabled]').click(function(event){
Expand Down
7 changes: 7 additions & 0 deletions app/assets/javascripts/osem-datepickers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ $(function () {
format: 'YYYY-MM-DD HH:mm'
});

$('.datetimepicker').datetimepicker({
pickTime: true,
useCurrent: false,
sideBySide: true,
format: 'YYYY-MM-DD HH:mm'
});

$("#registration-arrival-datepicker").datetimepicker({
pickTime: true,
useCurrent: false,
Expand Down
33 changes: 33 additions & 0 deletions app/assets/javascripts/osem-survey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
$(function() {
$('.selectpicker').on('changed.bs.select', function (e, clickedIndex) {
$('.kinds').addClass('hidden');
var selected = $('.selectpicker').find('option:selected').val();
$('.' + selected).removeClass('hidden');

if (selected == 'choice') {
$('.survey-possible-answers').removeClass('hidden');
}
else
{
$('.survey-possible-answers').addClass('hidden');
}
});
$('#survey_question_title').on('keyup', function(){
$('#survey_question_preview #title').text($(this).val())
});

function render_possible_answers_preview() {
var options_html = '';
var options_array = $('#survey_question_possible_answers').val().split(',');
var input_type = ($('#survey_question_min_choices').val() == 1 &&
$('#survey_question_max_choices').val() == 1) ? 'radio' : 'checkbox';
$.each(options_array, function(index, option) {
options_html += '<input type="' + input_type + '" name="preview_option"/> ' + option.trim() + '<br/>';
});
$('#survey_question_preview .choice').html(options_html)
};

$('#survey_question_possible_answers').on('keyup', render_possible_answers_preview);
$('#survey_question_min_choices').on('change', render_possible_answers_preview);
$('#survey_question_max_choices').on('change', render_possible_answers_preview);
});
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
*= require selectize
*= require selectize.bootstrap3
*= require mastodon
*= require bootstrap-select
*/
52 changes: 52 additions & 0 deletions app/controllers/admin/survey_questions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module Admin
class SurveyQuestionsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :survey
load_and_authorize_resource through: :survey

def new
@survey_question = @survey.survey_questions.new(min_choices: 1, max_choices: 1)
@url = admin_conference_survey_survey_questions_path(@conference.short_title, @survey)
end

def create
@survey_question = @survey.survey_questions.new(survey_question_params)
if @survey_question.save
redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully created Survey Question.'
else
@url = admin_conference_survey_survey_questions_path(@conference.short_title, @survey)
render :new
end
end

# GET questions/1/edit
def edit
@url = admin_conference_survey_survey_question_path(@conference.short_title, @survey, @survey_question)
end

# PUT questions/1
def update
if @survey_question.update_attributes(survey_question_params)
redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully updated Survey Question.'
else
@url = admin_conference_survey_survey_question_path(@conference.short_title, @survey, @survey_question)
render :edit
end
end

# DELETE questions/1
def destroy
if @survey_question.destroy
redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully deleted Survey Question.'
else
redirect_to admin_conference_survey_path(@conference.short_title, @survey), error: "Can't delete this Survey Question"
end
end

private

def survey_question_params
params.require(:survey_question).permit(:title, :kind, :possible_answers, :min_choices, :max_choices, :mandatory)
end
end
end
48 changes: 48 additions & 0 deletions app/controllers/admin/surveys_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Admin
class SurveysController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource

def index
@surveys = @conference.surveys + Survey.where(surveyable: @conference.program.events)
end

def new
@survey = Survey.new(survey_params)
@url = admin_conference_surveys_path(@conference.short_title)
end

def create
@survey = Survey.new(survey_params)
if @survey.save
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), notice: 'Successfully created survey'
else
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), error: 'Could not create survey.' + @survey.errors.full_messates.to_sentence
end
end

def edit
@url = admin_conference_survey_path(@conference.short_title, @survey)
end

def update
if @survey.update_attributes(survey_params)
redirect_to admin_conference_surveys_path(@conference.short_title)
else
@url = admin_conference_survey_path(@conference.short_title, @survey)
render action: :edit
end
end

def destroy
@survey.destroy
redirect_to admin_conference_surveys_path(@conference.short_title)
end

private

def survey_params
params.require(:survey).permit(:title, :description, :target, :start_date, :end_date, :surveyable_type, :surveyable_id)
end
end
end
1 change: 1 addition & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def index
def show
@event_schedule = @event.event_schedules.find_by(schedule_id: @program.selected_schedule_id)
@speakers_ordered = @event.speakers_ordered
@surveys_after_event = @event.surveys.after_event.select(&:active?)
end

def new
Expand Down
43 changes: 43 additions & 0 deletions app/controllers/surveys_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class SurveysController < ApplicationController
load_resource :conference, find_by: :short_title
load_and_authorize_resource except: :reply
load_resource only: :reply
skip_authorization_check only: :reply

def index
@surveys = @conference.surveys.select(&:active?)
end

def show
@survey_submission = @survey.survey_submissions.new
end

def reply
unless can? :reply, @survey
redirect_to conference_survey_path(@conference, @survey), alert: 'This survey is currently closed'
return
end

survey_submission = params[:survey_submission]

@survey.survey_questions.each do |survey_question|
reply = survey_question.survey_replies.find_by(user: current_user)
reply_text = survey_submission[survey_question.id.to_s].reject(&:blank?).join(',')

if reply
reply.update_attributes(text: reply_text) unless reply.text == reply_text
else
survey_question.survey_replies.create!(text: reply_text, user: current_user)
end

user_survey_submission = @survey.survey_submissions.find_by(user: current_user)
if user_survey_submission
user_survey_submission.update_attributes(updated_at: Time.current)
else
@survey.survey_submissions.create!(user: current_user)
end
end

redirect_to :back
end
end
15 changes: 15 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def not_signed_in
can [:show, :events], Schedule do |schedule|
schedule.program.schedule_public
end

can [:index, :show], Survey, surveyable_type: 'Conference'
end
end

Expand Down Expand Up @@ -102,6 +104,19 @@ def signed_in(user)
# can manage the commercials of their own events
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)

# can view and reply to a survey
can [:index, :show, :reply], Survey, surveyable_type: 'Conference'
can [:index, :show, :reply], Survey, surveyable_type: 'Registration', surveyable_id: user.registrations.pluck(:conference_id)

# TODO this needs to check for more, eg.
# if survey target is after_conference, check whether or not the conference is over
# if not, do not allow replies.

# do not allow replies before the start_date or after the end_date of survey
cannot :reply, Survey do |survey|
survey.start_date > Time.current || survey.end_date < Time.current
end

can [:destroy], Openid

can [:new, :create], Track do |track|
Expand Down
21 changes: 21 additions & 0 deletions app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ def for_registration
through: :program,
source: :events
has_many :event_types, through: :program

has_many :surveys, as: :surveyable, dependent: :destroy do
def for_registration
where(target: targets[:during_registration])
end

def after_conference
where(target: targets[:after_conference])
end
end
accepts_nested_attributes_for :venue
accepts_nested_attributes_for :tickets, allow_destroy: true
accepts_nested_attributes_for :sponsorship_levels, allow_destroy: true
Expand Down Expand Up @@ -773,6 +783,16 @@ def to_param
short_title
end

##
# Returns true or false, if the event is already over or not
#
# ====Returns
# * +true+ -> If the event is over
# * +false+ -> If the event is not over yet
def ended?
end_date < Time.current
end

private

# Returns a different html colour for every i and consecutive colors are
Expand Down Expand Up @@ -1223,3 +1243,4 @@ def calculate_items_per_week(start_week, weeks, items)
result
end
end
# rubocop:enable Metrics/ClassLength
Loading

0 comments on commit 90a1404

Please sign in to comment.