From 335608e6c444324804c1cb722fede6b11083a284 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Tue, 28 Jun 2016 18:16:06 +0300 Subject: [PATCH 01/10] Adding surveys --- Gemfile | 2 + Gemfile.lock | 12 ++-- app/assets/javascripts/application.js | 2 + app/assets/javascripts/osem-datepickers.js | 18 ++++-- app/assets/javascripts/osem-survey.js | 15 +++++ app/assets/stylesheets/application.css | 1 + .../admin/survey_questions_controller.rb | 47 ++++++++++++++ app/controllers/admin/surveys_controller.rb | 42 +++++++++++++ app/models/conference.rb | 1 + app/models/survey.rb | 6 ++ app/models/survey_question.rb | 10 +++ .../survey_questions/_answer_fields.html.haml | 4 ++ .../admin/survey_questions/_form.html.haml | 63 +++++++++++++++++++ .../survey_questions/_questions.html.haml | 27 ++++++++ .../admin/survey_questions/destroy.js.erb | 1 + .../admin/survey_questions/edit.html.haml | 1 + .../admin/survey_questions/index.html.haml | 32 ++++++++++ .../admin/survey_questions/show.html.haml | 26 ++++++++ app/views/admin/surveys/_form.html.haml | 14 +++++ app/views/admin/surveys/edit.html.haml | 1 + app/views/admin/surveys/index.html.haml | 34 ++++++++++ app/views/admin/surveys/new.html.haml | 14 +++++ app/views/admin/surveys/show.html.haml | 6 ++ app/views/layouts/_admin_sidebar.html.haml | 4 ++ config/routes.rb | 3 + db/migrate/20160627122446_create_surveys.rb | 13 ++++ .../20160628093634_create_survey_questions.rb | 13 ++++ db/schema.rb | 43 ++++++++++--- 28 files changed, 434 insertions(+), 21 deletions(-) create mode 100644 app/assets/javascripts/osem-survey.js create mode 100644 app/controllers/admin/survey_questions_controller.rb create mode 100644 app/controllers/admin/surveys_controller.rb create mode 100644 app/models/survey.rb create mode 100644 app/models/survey_question.rb create mode 100644 app/views/admin/survey_questions/_answer_fields.html.haml create mode 100644 app/views/admin/survey_questions/_form.html.haml create mode 100644 app/views/admin/survey_questions/_questions.html.haml create mode 100644 app/views/admin/survey_questions/destroy.js.erb create mode 100644 app/views/admin/survey_questions/edit.html.haml create mode 100644 app/views/admin/survey_questions/index.html.haml create mode 100644 app/views/admin/survey_questions/show.html.haml create mode 100644 app/views/admin/surveys/_form.html.haml create mode 100644 app/views/admin/surveys/edit.html.haml create mode 100644 app/views/admin/surveys/index.html.haml create mode 100644 app/views/admin/surveys/new.html.haml create mode 100644 app/views/admin/surveys/show.html.haml create mode 100644 db/migrate/20160627122446_create_surveys.rb create mode 100644 db/migrate/20160628093634_create_survey_questions.rb diff --git a/Gemfile b/Gemfile index 01bd5af1..7fcf55ca 100644 --- a/Gemfile +++ b/Gemfile @@ -105,6 +105,8 @@ source 'https://rails-assets.org' do gem 'rails-assets-bootstrap-markdown' gem 'rails-assets-to-markdown' gem 'rails-assets-markdown' + # for select with icon + gem 'rails-assets-bootstrap-select' end # as date picker diff --git a/Gemfile.lock b/Gemfile.lock index 4647f23c..1766bd94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -356,17 +356,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-deprecated_sanitizer (1.0.3) @@ -587,6 +589,7 @@ DEPENDENCIES quiet_assets rails (~> 4.2) rails-assets-bootstrap-markdown! + rails-assets-bootstrap-select! rails-assets-date.format! rails-assets-holderjs! rails-assets-jquery-smooth-scroll! @@ -620,6 +623,3 @@ DEPENDENCIES web-console (~> 2.0) webmock whenever - -BUNDLED WITH - 1.12.5 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 54c752a0..bb2f4e9e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -40,6 +40,8 @@ //= require osem-commercials //= require unobtrusive_flash //= require unobtrusive_flash_bootstrap +//= require bootstrap-select +//= require osem-survey $(document).ready(function() { $('a[disabled=disabled]').click(function(event){ diff --git a/app/assets/javascripts/osem-datepickers.js b/app/assets/javascripts/osem-datepickers.js index 1888da3e..9ab32163 100644 --- a/app/assets/javascripts/osem-datepickers.js +++ b/app/assets/javascripts/osem-datepickers.js @@ -1,6 +1,14 @@ // get current_date var today = new Date().toISOString().slice(0, 10); $(function () { + + $('.datetimepicker').datetimepicker({ + pickTime: true, + useCurrent: false, + sideBySide: true, + format: 'YYYY-MM-DD HH:mm' + }); + $("#registration-arrival-datepicker").datetimepicker({ pickTime: true, useCurrent: false, @@ -12,7 +20,7 @@ $(function () { minDate : today, defaultDate : $("#registration-arrival-datepicker").attr('start_date'), }); - + $("#registration-departure-datepicker").datetimepicker({ pickTime: true, useCurrent: false, @@ -23,7 +31,7 @@ $(function () { minDate : $("#registration-arrival-datepicker").attr('start_date'), defaultDate : $("#registration-arrival-datepicker").attr('end_date'), }); - + $("#registration-arrival-datepicker").on("dp.change",function (e) { // departure_date > start_date,arrival_date if ((new Date(e.date).getTime()) > (new Date($("#registration-arrival-datepicker").attr('start_date')).getTime())){ @@ -52,7 +60,7 @@ $(function () { useCurrent: false, format: "YYYY-MM-DD", }); - + // end_date_conference >= registration-period-Start_date >= Current_date // registration-period-Start_date <= registration-period-End_date <= End_date (of conference) $("#registration-period-start-datepicker").datetimepicker({ @@ -62,7 +70,7 @@ $(function () { minDate : today, maxDate : $("#registration-period-start-datepicker").attr('end_date'), }); - + $("#registration-period-end-datepicker").datetimepicker({ pickTime: false, useCurrent: false, @@ -70,7 +78,7 @@ $(function () { minDate: today, maxDate : $("#registration-period-start-datepicker").attr('end_date'), }); - + $("#conference-start-datepicker").on("dp.change",function (e) { $('#conference-end-datepicker').data("DateTimePicker").setMinDate(e.date); }); diff --git a/app/assets/javascripts/osem-survey.js b/app/assets/javascripts/osem-survey.js new file mode 100644 index 00000000..17c3ecb0 --- /dev/null +++ b/app/assets/javascripts/osem-survey.js @@ -0,0 +1,15 @@ +$(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'); + } + }); +}); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d0447354..93bc9cf7 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -14,4 +14,5 @@ *= require bootstrap-datetimepicker *= require leaflet *= require bootstrap3-switch + *= require bootstrap-select */ diff --git a/app/controllers/admin/survey_questions_controller.rb b/app/controllers/admin/survey_questions_controller.rb new file mode 100644 index 00000000..a4380fb6 --- /dev/null +++ b/app/controllers/admin/survey_questions_controller.rb @@ -0,0 +1,47 @@ +module Admin + class SurveyQuestionsController < Admin::BaseController + load_and_authorize_resource :conference, find_by: :short_title + load_and_authorize_resource :survey, through: :conference + load_and_authorize_resource through: :survey + + def index + end + + def show + end + + def new + @survey_question = @survey.survey_questions.new + @url = admin_conference_survey_survey_questions_path(@conference.short_title, @survey) + end + + def create + @survey.survey_questions.create(survey_question_params) + redirect_to admin_conference_survey_survey_questions_path(@conference.short_title, @survey) + 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_survey_questions_path(@conference.short_title, @survey), notice: 'Successfully updated survey question.' + else + render :edit + end + end + + # DELETE questions/1 + def destroy + end + + private + + def survey_question_params + params.require(:survey_question).permit(:title, :kind, :possible_answers, :min_choices, :max_choices, :mandatory) + end + end +end diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb new file mode 100644 index 00000000..be8d8018 --- /dev/null +++ b/app/controllers/admin/surveys_controller.rb @@ -0,0 +1,42 @@ +module Admin + class SurveysController < Admin::BaseController + load_and_authorize_resource :conference, find_by: :short_title + load_and_authorize_resource + + def index + @surveys = @conference.surveys + 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) + end + end + + def edit + @url = admin_conference_survey_path(@conference.short_title, @survey) + end + + def update + @survey.update_attributes(survey_params) + redirect_to admin_conference_surveys_path(@conference.short_title) + 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, :start_date, :end_date, :surveyable_type, :surveyable_id) + end + end +end diff --git a/app/models/conference.rb b/app/models/conference.rb index f0b73047..eb9457eb 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -34,6 +34,7 @@ class Conference < ActiveRecord::Base has_many :campaigns, dependent: :destroy has_many :commercials, as: :commercialable, dependent: :destroy has_many :subscriptions, dependent: :destroy + has_many :surveys, as: :surveyable, dependent: :destroy accepts_nested_attributes_for :venue accepts_nested_attributes_for :tickets, allow_destroy: true diff --git a/app/models/survey.rb b/app/models/survey.rb new file mode 100644 index 00000000..df05d33b --- /dev/null +++ b/app/models/survey.rb @@ -0,0 +1,6 @@ +class Survey < ActiveRecord::Base + belongs_to :surveyable, polymorphic: true + has_many :survey_questions + + validates :title, presence: true +end diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb new file mode 100644 index 00000000..07d48bfb --- /dev/null +++ b/app/models/survey_question.rb @@ -0,0 +1,10 @@ +class SurveyQuestion < ActiveRecord::Base + belongs_to :survey + + # Order of this list should not be changed without proper action! + enum type: [:boolean, :choice, :string, :text, :datetime, :numeric] + + ICONS = { boolean: 'dot-circle-o', choice: 'check-square-o', string: 'edit', text: 'align-left', datetime: 'clock-o', numeric: 'slack' } + + validates :title, presence: true +end diff --git a/app/views/admin/survey_questions/_answer_fields.html.haml b/app/views/admin/survey_questions/_answer_fields.html.haml new file mode 100644 index 00000000..5bffc9bc --- /dev/null +++ b/app/views/admin/survey_questions/_answer_fields.html.haml @@ -0,0 +1,4 @@ +.nested-fields + = f.inputs do + = f.input :title + = remove_association_link :answer, f diff --git a/app/views/admin/survey_questions/_form.html.haml b/app/views/admin/survey_questions/_form.html.haml new file mode 100644 index 00000000..f5ef3057 --- /dev/null +++ b/app/views/admin/survey_questions/_form.html.haml @@ -0,0 +1,63 @@ +.row + .col-md-12 + .page-header + - if @survey_question.new_record? + %h1 + New Survey Question + - else + %h1 + Edit Survey Question + .text-muted + = @survey_question.title + + .col-md-6 + = semantic_form_for @survey_question, url: @url do |f| + + .row + .col-md-12 + = f.input :title + = f.input :mandatory + %div.survey-possible-answers.hidden + = f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 } + %hr + .row + .col-md-6 + %label{ required: 'required' } + Type of Question: + .form-group + %select.selectpicker.form-control{ id: 'survey_question_kind', name: 'survey_question[kind]' } + - SurveyQuestion.types.each do |type| + %option{ id: "#{type.second}", 'data-icon' => "fa fa-#{SurveyQuestion::ICONS[type.first.to_sym]}" } + = type.first + .col-md-6 + .panel.panel-default + .panel-body + %p + What is your answer? + + %div.kinds.boolean + %input{type: 'radio', name: 'radio'} Yes + %br + %input{type: 'radio', name: 'radio'} No + + %div.kinds.choice.hidden + %input{ type: 'checkbox', name: 'checkbox' } Choice 1 + %br + %input{ type: 'checkbox', name: 'checkbox' } Choice 2 + %br + %input{ type: 'checkbox', name: 'checkbox' } Choice 3 + + %div.kinds.string.hidden + %input.form-control + + %div.kinds.text.hidden + %textarea.form-control{ rows: 4 } + + + %div.kinds.datetime.hidden + %input.form-control{id: 'registration-arrival-datepicker', readonly: 'readonly'} + + %div.kinds.numeric.hidden + %input.form-control{ type: 'number' } + + = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/admin/survey_questions/_questions.html.haml b/app/views/admin/survey_questions/_questions.html.haml new file mode 100644 index 00000000..8417a0ef --- /dev/null +++ b/app/views/admin/survey_questions/_questions.html.haml @@ -0,0 +1,27 @@ +%table.table.table-hover#questions + %th Enabled + %th Question + %th Type + %th Answers + %th Actions + - @questions.each do |q| + %tr + %td + = hidden_field_tag "conference[question_ids][]", nil + = check_box_tag "conference[question_ids][]", q.id, + @conference.question_ids.include?(q.id), id: dom_id(q) + %td + = q.title + %td + = q.question_type.title + %td + = q.answers.map {|a| a.title}.join(', ') + + %td + .btn-group + = link_to 'Show', admin_conference_question_path(@conference.short_title, q), class: 'btn btn-success' + = link_to 'Edit', edit_admin_conference_question_path(@conference.short_title, q), + class: 'btn btn-primary', disabled: !(can? :update, q) + = link_to 'Delete', admin_conference_question_path(@conference.short_title, q), + method: :delete, remote: true, class: 'btn btn-danger', + confirm: "Delete question '#{q.title}'?", disabled: !(can? :destroy, q) diff --git a/app/views/admin/survey_questions/destroy.js.erb b/app/views/admin/survey_questions/destroy.js.erb new file mode 100644 index 00000000..dbae0ed8 --- /dev/null +++ b/app/views/admin/survey_questions/destroy.js.erb @@ -0,0 +1 @@ +$('#myquestions').html("<%= escape_javascript(render :partial => 'questions') %>"); diff --git a/app/views/admin/survey_questions/edit.html.haml b/app/views/admin/survey_questions/edit.html.haml new file mode 100644 index 00000000..72992799 --- /dev/null +++ b/app/views/admin/survey_questions/edit.html.haml @@ -0,0 +1 @@ += render partial: 'form' diff --git a/app/views/admin/survey_questions/index.html.haml b/app/views/admin/survey_questions/index.html.haml new file mode 100644 index 00000000..1967d1d9 --- /dev/null +++ b/app/views/admin/survey_questions/index.html.haml @@ -0,0 +1,32 @@ +.row + .col-md-12 + .page-header + %h1 + Survey Questions + = "(#{@survey_questions.length})" + + - if @survey_questions.any? + %table.table + %thead + %th + %th Title + %th Kind + %th Possible Answers + %th Mandatory + %th Answers + %th Actions + %tbody + - @survey_questions.each.with_index(1) do |survey_question, index| + %tr + %td= index + %td= survey_question.title + %td= survey_question.kind + %td= survey_question.possible_answers + %td= survey_question.mandatory + %td + %td + .btn-group + = link_to 'Edit', edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), class: 'btn btn-primary' + = link_to 'Delete', admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' }, class: 'btn btn-danger' + + = link_to 'Add', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right' diff --git a/app/views/admin/survey_questions/show.html.haml b/app/views/admin/survey_questions/show.html.haml new file mode 100644 index 00000000..0f01d41d --- /dev/null +++ b/app/views/admin/survey_questions/show.html.haml @@ -0,0 +1,26 @@ +.container + .row + .col-md-12 + .page-header + %h1= @question.title + - @question.answers.each do |answer| + = answer.title + (#{answer.qanswers.find_by(question: @question).registrations.where(conference: @conference).count}) + + + .row + .col-md-12 + + %table.table.table-border.table-hover.datatable#question_users + %thead + %th Name + %th Username + %th Email + %th Answer + %tbody + - @registrations.each do |registration| + %tr + %td= registration.name + %td= registration.username + %td= registration.email + %td= registration.qanswers.find_by(question: @question).answer.title diff --git a/app/views/admin/surveys/_form.html.haml b/app/views/admin/surveys/_form.html.haml new file mode 100644 index 00000000..11d1be9f --- /dev/null +++ b/app/views/admin/surveys/_form.html.haml @@ -0,0 +1,14 @@ +.row + .col-md-12 + .page-header + %h1 New Survey + + .col-md-6 + = semantic_form_for @survey, url: @url do |f| + = f.hidden_field :surveyable_type + = f.hidden_field :surveyable_id + = f.input :title + = f.input :description, input_html: { rows: 3 } + = f.input :start_date, as: :string, input_html: { class: 'datetimepicker' } + = f.input :end_date, as: :string, input_html: { class: 'datetimepicker' } + = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/admin/surveys/edit.html.haml b/app/views/admin/surveys/edit.html.haml new file mode 100644 index 00000000..72992799 --- /dev/null +++ b/app/views/admin/surveys/edit.html.haml @@ -0,0 +1 @@ += render partial: 'form' diff --git a/app/views/admin/surveys/index.html.haml b/app/views/admin/surveys/index.html.haml new file mode 100644 index 00000000..b5f6475f --- /dev/null +++ b/app/views/admin/surveys/index.html.haml @@ -0,0 +1,34 @@ +.row + .col-md-12 + .page-header + %h1 + Surveys + = link_to 'New', new_admin_conference_survey_path(@conference.short_title, survey: { surveyable_type: 'Conference', surveyable_id: @conference.id }), class: 'btn btn-success pull-right' + %p.text-muted + Available surveys for this conference + + +- if @surveys.any? + .row + .col-md-12 + %table.table.table-hover#surveys + %thead + %th Title + %th Start Date + %th End Date + %th Actions + %tbody + - @surveys.each_with_index do |survey, index| + %tr + %td + = survey.title + %td + = survey.start_date + %td + = survey.end_date + %td + = link_to 'Edit', edit_admin_conference_survey_path(@conference.short_title, survey.id), + method: :get, class: 'btn btn-primary' + = link_to 'Delete', admin_conference_survey_path(@conference.short_title, survey.id), + method: :delete, class: 'btn btn-danger', + data: { confirm: "Do you really want to delete #{survey.title}?"} diff --git a/app/views/admin/surveys/new.html.haml b/app/views/admin/surveys/new.html.haml new file mode 100644 index 00000000..11d1be9f --- /dev/null +++ b/app/views/admin/surveys/new.html.haml @@ -0,0 +1,14 @@ +.row + .col-md-12 + .page-header + %h1 New Survey + + .col-md-6 + = semantic_form_for @survey, url: @url do |f| + = f.hidden_field :surveyable_type + = f.hidden_field :surveyable_id + = f.input :title + = f.input :description, input_html: { rows: 3 } + = f.input :start_date, as: :string, input_html: { class: 'datetimepicker' } + = f.input :end_date, as: :string, input_html: { class: 'datetimepicker' } + = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/admin/surveys/show.html.haml b/app/views/admin/surveys/show.html.haml new file mode 100644 index 00000000..b9b2019a --- /dev/null +++ b/app/views/admin/surveys/show.html.haml @@ -0,0 +1,6 @@ +%p#notice= notice + + += link_to 'Edit', edit_admin_survey_path(@admin_survey) +\| += link_to 'Back', admin_surveys_path diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index e5747bdc..d112ae5c 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -131,6 +131,10 @@ = link_to(admin_conference_emails_path(@conference.short_title)) do %span.fa.fa-envelope E-Mails + %li{ class: active_nav_li(admin_conference_surveys_path(@conference.short_title)) } + = link_to(admin_conference_surveys_path(@conference.short_title)) do + %span.fa.fa-group + Surveys - if can? :index, Role.new(resource: @conference) %li{:class=> active_nav_li(admin_conference_roles_path(@conference.short_title))} = link_to(admin_conference_roles_path(@conference.short_title)) do diff --git a/config/routes.rb b/config/routes.rb index b2180a8b..72fa4871 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,9 @@ Osem::Application.routes.draw do resources :users resources :comments, only: [:index] resources :conference do + resources :surveys do + resources :survey_questions + end resource :contact, except: [:index, :new, :create, :show, :destroy] resource :schedule, only: [:show, :update] get 'commercials/render_commercial' => 'commercials#render_commercial' diff --git a/db/migrate/20160627122446_create_surveys.rb b/db/migrate/20160627122446_create_surveys.rb new file mode 100644 index 00000000..8a57053c --- /dev/null +++ b/db/migrate/20160627122446_create_surveys.rb @@ -0,0 +1,13 @@ +class CreateSurveys < ActiveRecord::Migration + def change + create_table :surveys do |t| + t.datetime :start_date + t.datetime :end_date + t.string :title + t.text :description + t.references :surveyable, polymorphic: true, index: true + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160628093634_create_survey_questions.rb b/db/migrate/20160628093634_create_survey_questions.rb new file mode 100644 index 00000000..233a7f4d --- /dev/null +++ b/db/migrate/20160628093634_create_survey_questions.rb @@ -0,0 +1,13 @@ +class CreateSurveyQuestions < ActiveRecord::Migration + def change + create_table :survey_questions do |t| + t.references :survey + t.string :title + t.integer :kind, default: 0 + t.integer :min_choices + t.integer :max_choices + t.text :possible_answers + t.boolean :mandatory, default: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b0626d92..ae721ddd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160624151257) do +ActiveRecord::Schema.define(version: 20160628093634) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -80,23 +80,23 @@ ActiveRecord::Schema.define(version: 20160624151257) do end create_table "conferences", force: :cascade do |t| - t.string "guid", null: false - t.string "title", null: false - t.string "short_title", null: false - t.string "timezone", null: false - t.date "start_date", null: false - t.date "end_date", null: false + t.string "guid", null: false + t.string "title", null: false + t.string "short_title", null: false + t.string "timezone", null: false + t.date "start_date", null: false + t.date "end_date", null: false t.datetime "created_at" t.datetime "updated_at" t.string "logo_file_name" t.integer "revision" - t.boolean "use_vpositions", default: false - t.boolean "use_vdays", default: false + t.boolean "use_vpositions", default: false + t.boolean "use_vdays", default: false t.boolean "use_volunteers" t.string "color" t.text "events_per_week" t.text "description" - t.integer "registration_limit", default: 0 + t.integer "registration_limit", default: 0 t.string "picture" end @@ -375,6 +375,29 @@ ActiveRecord::Schema.define(version: 20160624151257) do t.datetime "updated_at" end + create_table "survey_questions", force: :cascade do |t| + t.integer "survey_id" + t.string "title" + t.integer "kind", default: 0 + t.integer "min_choices" + t.integer "max_choices" + t.text "possible_answers" + t.boolean "mandatory", default: false + end + + create_table "surveys", force: :cascade do |t| + t.datetime "start_date" + t.datetime "end_date" + t.string "title" + t.text "description" + t.integer "surveyable_id" + t.string "surveyable_type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "surveys", ["surveyable_type", "surveyable_id"], name: "index_surveys_on_surveyable_type_and_surveyable_id" + create_table "targets", force: :cascade do |t| t.integer "conference_id" t.integer "campaign_id" From 03168b4efe525b37bcae5f4d742f095ce41cb76b Mon Sep 17 00:00:00 2001 From: mdeniz Date: Wed, 29 Jun 2016 17:23:01 +0200 Subject: [PATCH 02/10] Improving surveys system: showing surveys in admin UI as they will be for the user --- app/assets/javascripts/osem-survey.js | 18 +++++ .../admin/survey_questions_controller.rb | 17 +++-- app/controllers/admin/surveys_controller.rb | 8 ++- app/models/conference.rb | 6 +- app/models/survey.rb | 2 + app/models/survey_question.rb | 33 ++++++++- .../admin/survey_questions/_form.html.haml | 67 +++++++++++++------ .../admin/survey_questions/index.html.haml | 3 +- .../admin/surveys/_survey_question.html.haml | 50 ++++++++++++++ app/views/admin/surveys/index.html.haml | 13 ++-- app/views/admin/surveys/show.html.haml | 24 +++++-- .../_registration_info.html.haml | 4 +- app/views/layouts/_admin_sidebar.html.haml | 2 +- .../20160629145954_add_target_to_surveys.rb | 5 ++ db/schema.rb | 7 +- 15 files changed, 213 insertions(+), 46 deletions(-) create mode 100644 app/views/admin/surveys/_survey_question.html.haml create mode 100644 db/migrate/20160629145954_add_target_to_surveys.rb diff --git a/app/assets/javascripts/osem-survey.js b/app/assets/javascripts/osem-survey.js index 17c3ecb0..20ed2a19 100644 --- a/app/assets/javascripts/osem-survey.js +++ b/app/assets/javascripts/osem-survey.js @@ -12,4 +12,22 @@ $(function() { $('.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 += ' ' + option.trim() + '
'; + }); + $('#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); }); diff --git a/app/controllers/admin/survey_questions_controller.rb b/app/controllers/admin/survey_questions_controller.rb index a4380fb6..2f1d016f 100644 --- a/app/controllers/admin/survey_questions_controller.rb +++ b/app/controllers/admin/survey_questions_controller.rb @@ -11,13 +11,16 @@ module Admin end def new - @survey_question = @survey.survey_questions.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.survey_questions.create(survey_question_params) - redirect_to admin_conference_survey_survey_questions_path(@conference.short_title, @survey) + if @survey.survey_questions.create(survey_question_params) + redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully created Survey Question.' + else + render :new + end end # GET questions/1/edit @@ -28,14 +31,20 @@ module Admin # PUT questions/1 def update if @survey_question.update_attributes(survey_question_params) - redirect_to admin_conference_survey_survey_questions_path(@conference.short_title, @survey), notice: 'Successfully updated survey question.' + 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 diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb index be8d8018..4e99a96d 100644 --- a/app/controllers/admin/surveys_controller.rb +++ b/app/controllers/admin/surveys_controller.rb @@ -24,8 +24,12 @@ module Admin end def update - @survey.update_attributes(survey_params) - redirect_to admin_conference_surveys_path(@conference.short_title) + 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 diff --git a/app/models/conference.rb b/app/models/conference.rb index eb9457eb..15352867 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -34,7 +34,11 @@ class Conference < ActiveRecord::Base has_many :campaigns, dependent: :destroy has_many :commercials, as: :commercialable, dependent: :destroy has_many :subscriptions, dependent: :destroy - has_many :surveys, as: :surveyable, dependent: :destroy + has_many :surveys, as: :surveyable, dependent: :destroy do + def for_registration + where(target: targets[:registration]) + end + end accepts_nested_attributes_for :venue accepts_nested_attributes_for :tickets, allow_destroy: true diff --git a/app/models/survey.rb b/app/models/survey.rb index df05d33b..d08df5dc 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -2,5 +2,7 @@ class Survey < ActiveRecord::Base belongs_to :surveyable, polymorphic: true has_many :survey_questions + enum target: [:conference, :registration] + validates :title, presence: true end diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb index 07d48bfb..1b10fdb7 100644 --- a/app/models/survey_question.rb +++ b/app/models/survey_question.rb @@ -2,9 +2,40 @@ class SurveyQuestion < ActiveRecord::Base belongs_to :survey # Order of this list should not be changed without proper action! - enum type: [:boolean, :choice, :string, :text, :datetime, :numeric] + enum kind: [:boolean, :choice, :string, :text, :datetime, :numeric] ICONS = { boolean: 'dot-circle-o', choice: 'check-square-o', string: 'edit', text: 'align-left', datetime: 'clock-o', numeric: 'slack' } validates :title, presence: true + validates :possible_answers, :max_choices, :min_choices, presence: true, if: "choice?" + validates :min_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true + validates :max_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true + + validate :max_choices_greater_than_min + + def single_choice? + choice? && max_choices == 1 && min_choices == 1 + end + + def multiple_choice? + choice? && max_choices > 1 + end + + def possible_answers=(value) + write_attribute(:possible_answers, choice? ? value : nil) + end + + def min_choices=(value) + write_attribute(:min_choices, choice? ? value : nil) + end + + def max_choices=(value) + write_attribute(:max_choices, choice? ? value : nil) + end + + private + + def max_choices_greater_than_min + errors.add(:max_choices, "Max choices should not be less than min choices") if choice? && max_choices.to_i < min_choices.to_i + end end diff --git a/app/views/admin/survey_questions/_form.html.haml b/app/views/admin/survey_questions/_form.html.haml index f5ef3057..7cd7bbdb 100644 --- a/app/views/admin/survey_questions/_form.html.haml +++ b/app/views/admin/survey_questions/_form.html.haml @@ -17,8 +17,13 @@ .col-md-12 = f.input :title = f.input :mandatory - %div.survey-possible-answers.hidden + %div.survey-possible-answers{ class: @survey_question.choice? ? '' : 'hidden'} = f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 } + .row + .col-md-6 + = f.input :min_choices + .col-md-6 + = f.input :max_choices %hr .row .col-md-6 @@ -26,38 +31,62 @@ Type of Question: .form-group %select.selectpicker.form-control{ id: 'survey_question_kind', name: 'survey_question[kind]' } - - SurveyQuestion.types.each do |type| - %option{ id: "#{type.second}", 'data-icon' => "fa fa-#{SurveyQuestion::ICONS[type.first.to_sym]}" } - = type.first + - SurveyQuestion.kinds.each do |kind| + %option{ id: "#{kind.second}", 'data-icon' => "fa fa-#{SurveyQuestion::ICONS[kind.first.to_sym]}", selected: @survey_question.kind == kind.first } + = kind.first .col-md-6 + %label + Preview: .panel.panel-default - .panel-body - %p - What is your answer? + .panel-body{id: 'survey_question_preview'} + %p{id: 'title', style: 'word-wrap: break-word'} + = @survey_question.title.blank? ? 'What is your answer?' : @survey_question.title - %div.kinds.boolean + %div.kinds.boolean{ class: @survey_question.boolean? ? '' : 'hidden'} %input{type: 'radio', name: 'radio'} Yes %br %input{type: 'radio', name: 'radio'} No - %div.kinds.choice.hidden - %input{ type: 'checkbox', name: 'checkbox' } Choice 1 - %br - %input{ type: 'checkbox', name: 'checkbox' } Choice 2 - %br - %input{ type: 'checkbox', name: 'checkbox' } Choice 3 + %div.kinds.choice{ id: '', class: @survey_question.choice? ? '' : 'hidden'} + - if @survey_question.possible_answers.blank? + - if @survey_question.single_choice? + %input{ type: 'radio', name: 'radio' } Choice 1 + %br + %input{ type: 'radio', name: 'radio' } Choice 2 + %br + %input{ type: 'radio', name: 'radio' } Choice 3 + - else + %input{ type: 'checkbox', name: 'checkbox' } Choice 1 + %br + %input{ type: 'checkbox', name: 'checkbox' } Choice 2 + %br + %input{ type: 'checkbox', name: 'checkbox' } Choice 3 + - else + - @survey_question.possible_answers.split(',').map(&:strip).each do |option| + - if @survey_question.single_choice? + %input{ type: 'radio', name: 'radio' } + = option + %br + - else + %input{ type: 'checkbox', name: 'checkbox' } + = option + %br - %div.kinds.string.hidden + %div.kinds.string{ class: @survey_question.string? ? '' : 'hidden'} %input.form-control - %div.kinds.text.hidden + %div.kinds.text{ class: @survey_question.text? ? '' : 'hidden'} %textarea.form-control{ rows: 4 } - %div.kinds.datetime.hidden - %input.form-control{id: 'registration-arrival-datepicker', readonly: 'readonly'} + %div.kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden'} + .form-group{class: 'datetimepicker'} + .input-group + .input-group-addon + %span.fa.fa-calendar + %input.form-control{readonly: 'readonly'} - %div.kinds.numeric.hidden + %div.kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden'} %input.form-control{ type: 'number' } = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/admin/survey_questions/index.html.haml b/app/views/admin/survey_questions/index.html.haml index 1967d1d9..54b1116a 100644 --- a/app/views/admin/survey_questions/index.html.haml +++ b/app/views/admin/survey_questions/index.html.haml @@ -2,7 +2,8 @@ .col-md-12 .page-header %h1 - Survey Questions + Questions for survey + = link_to @survey.title, admin_conference_survey_path(@conference.short_title, @survey) = "(#{@survey_questions.length})" - if @survey_questions.any? diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml new file mode 100644 index 00000000..399ebd27 --- /dev/null +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -0,0 +1,50 @@ +.panel.panel-default + .panel-heading + %span.badge + = index + = survey_question.title + - if survey_question.multiple_choice? + ( Select + - if survey_question.min_choices != survey_question.max_choices + a minimum of + = survey_question.min_choices + - if survey_question.min_choices != survey_question.max_choices + and a maximum of + = survey_question.max_choices + choices ) + - if survey_question.mandatory + %span.fa.fa-asterisk.text-danger + %p.pull-right + = link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do + %span.fa.fa-edit + = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do + %span.fa.fa-times + .panel-body + - if survey_question.boolean? + %input{type: 'radio', name: 'radio'} + Yes + %br + %input{type: 'radio', name: 'radio'} + No + - elsif survey_question.choice? + - survey_question.possible_answers.split(',').map(&:strip).each do |option| + - if survey_question.single_choice? + %input{ type: 'radio', name: 'radio' } + = option + %br + - else + %input{ type: 'checkbox', name: 'checkbox' } + = option + %br + - elsif survey_question.string? + %input.form-control + - elsif survey_question.text? + %textarea.form-control{ rows: 4 } + - elsif survey_question.datetime? + .form-group{class: 'datetimepicker'} + .input-group + .input-group-addon + %span.fa.fa-calendar + %input.form-control{readonly: 'readonly'} + - elsif survey_question.numeric? + %input.form-control{ type: 'number' } diff --git a/app/views/admin/surveys/index.html.haml b/app/views/admin/surveys/index.html.haml index b5f6475f..17320355 100644 --- a/app/views/admin/surveys/index.html.haml +++ b/app/views/admin/surveys/index.html.haml @@ -21,14 +21,15 @@ - @surveys.each_with_index do |survey, index| %tr %td - = survey.title + = link_to survey.title, admin_conference_survey_path(@conference.short_title, survey) %td = survey.start_date %td = survey.end_date %td - = link_to 'Edit', edit_admin_conference_survey_path(@conference.short_title, survey.id), - method: :get, class: 'btn btn-primary' - = link_to 'Delete', admin_conference_survey_path(@conference.short_title, survey.id), - method: :delete, class: 'btn btn-danger', - data: { confirm: "Do you really want to delete #{survey.title}?"} + .btn-group + = link_to 'Edit', edit_admin_conference_survey_path(@conference.short_title, survey), + class: 'btn btn-primary' + = link_to 'Delete', admin_conference_survey_path(@conference.short_title, survey), + method: :delete, class: 'btn btn-danger', + data: { confirm: "Do you really want to delete #{survey.title}?"} diff --git a/app/views/admin/surveys/show.html.haml b/app/views/admin/surveys/show.html.haml index b9b2019a..f60d3653 100644 --- a/app/views/admin/surveys/show.html.haml +++ b/app/views/admin/surveys/show.html.haml @@ -1,6 +1,18 @@ -%p#notice= notice - - -= link_to 'Edit', edit_admin_survey_path(@admin_survey) -\| -= link_to 'Back', admin_surveys_path +.row + .col-md-12 + .page-header + %h1 + Survey #{@survey.title} + = link_to 'Edit Survey', edit_admin_conference_survey_path(@conference.short_title, @survey), class: 'btn btn-primary pull-right' + %p.text-muted + From: + = @survey.start_date + to + = @survey.end_date +.row + .col-md-12 + - @survey.survey_questions.each.with_index(1) do |survey_question, index| + .row + .col-md-12 + = render partial: 'survey_question', locals: { survey_question: survey_question, index: index } + = link_to 'Add Question', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right' diff --git a/app/views/conference_registrations/_registration_info.html.haml b/app/views/conference_registrations/_registration_info.html.haml index 0bf15c71..c1015d08 100644 --- a/app/views/conference_registrations/_registration_info.html.haml +++ b/app/views/conference_registrations/_registration_info.html.haml @@ -1,5 +1,5 @@ -- if @conference.questions.any? - = render partial: 'conference_registrations/questions', locals: { f: f } +- if @conference.surveys.for_registration.any? + Something - if @conference.program.events.with_registration_open.any? || @registration.events.any? = f.inputs 'Pre-registration required for the following:' do diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index d112ae5c..ab48150f 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -133,7 +133,7 @@ E-Mails %li{ class: active_nav_li(admin_conference_surveys_path(@conference.short_title)) } = link_to(admin_conference_surveys_path(@conference.short_title)) do - %span.fa.fa-group + %span.fa.fa-list-alt Surveys - if can? :index, Role.new(resource: @conference) %li{:class=> active_nav_li(admin_conference_roles_path(@conference.short_title))} diff --git a/db/migrate/20160629145954_add_target_to_surveys.rb b/db/migrate/20160629145954_add_target_to_surveys.rb new file mode 100644 index 00000000..16c10b8d --- /dev/null +++ b/db/migrate/20160629145954_add_target_to_surveys.rb @@ -0,0 +1,5 @@ +class AddTargetToSurveys < ActiveRecord::Migration + def change + add_column :surveys, :target, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index ae721ddd..da777c4f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160628093634) do +ActiveRecord::Schema.define(version: 20160629145954) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -392,8 +392,9 @@ ActiveRecord::Schema.define(version: 20160628093634) do t.text "description" t.integer "surveyable_id" t.string "surveyable_type" - 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 "target", default: 0 end add_index "surveys", ["surveyable_type", "surveyable_id"], name: "index_surveys_on_surveyable_type_and_surveyable_id" From 157a16d8f2f25195702fc6ff42a2ea9829ebf8de Mon Sep 17 00:00:00 2001 From: Shyukri Shyukriev Date: Thu, 30 Jun 2016 12:05:00 +0200 Subject: [PATCH 03/10] Add survey replies. --- app/controllers/admin/surveys_controller.rb | 2 +- app/models/survey_question.rb | 2 ++ app/models/survey_reply.rb | 5 +++++ app/models/user.rb | 1 + db/migrate/20160630094850_create_survey_replies.rb | 11 +++++++++++ db/schema.rb | 10 +++++++++- 6 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 app/models/survey_reply.rb create mode 100644 db/migrate/20160630094850_create_survey_replies.rb diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb index 4e99a96d..fe17a51a 100644 --- a/app/controllers/admin/surveys_controller.rb +++ b/app/controllers/admin/surveys_controller.rb @@ -40,7 +40,7 @@ module Admin private def survey_params - params.require(:survey).permit(:title, :description, :start_date, :end_date, :surveyable_type, :surveyable_id) + params.require(:survey).permit(:title, :description, :target, :start_date, :end_date, :surveyable_type, :surveyable_id) end end end diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb index 1b10fdb7..a5718333 100644 --- a/app/models/survey_question.rb +++ b/app/models/survey_question.rb @@ -12,6 +12,8 @@ class SurveyQuestion < ActiveRecord::Base validates :max_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true validate :max_choices_greater_than_min + has_many :survey_replies + def single_choice? choice? && max_choices == 1 && min_choices == 1 diff --git a/app/models/survey_reply.rb b/app/models/survey_reply.rb new file mode 100644 index 00000000..67edbc84 --- /dev/null +++ b/app/models/survey_reply.rb @@ -0,0 +1,5 @@ +class SurveyReply < ActiveRecord::Base + belongs_to :user + belongs_to :survey_question + serialize :text +end diff --git a/app/models/user.rb b/app/models/user.rb index d3c847a2..4bd2d3da 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,6 +42,7 @@ class User < ActiveRecord::Base has_many :votes, dependent: :destroy has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy + has_many :survey_replies accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } diff --git a/db/migrate/20160630094850_create_survey_replies.rb b/db/migrate/20160630094850_create_survey_replies.rb new file mode 100644 index 00000000..3b8917de --- /dev/null +++ b/db/migrate/20160630094850_create_survey_replies.rb @@ -0,0 +1,11 @@ +class CreateSurveyReplies < ActiveRecord::Migration + def change + create_table :survey_replies do |t| + t.integer :survey_question_id + t.integer :user_id + t.text :text + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index da777c4f..597c4fce 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160629145954) do +ActiveRecord::Schema.define(version: 20160630094850) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -385,6 +385,14 @@ ActiveRecord::Schema.define(version: 20160629145954) do t.boolean "mandatory", default: false end + create_table "survey_replies", force: :cascade do |t| + t.integer "survey_question_id" + t.integer "user_id" + t.text "text" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "surveys", force: :cascade do |t| t.datetime "start_date" t.datetime "end_date" From 9ce4ba6f6b6de575db681ba4c0779eea91481ff6 Mon Sep 17 00:00:00 2001 From: Shyukri Shyukriev Date: Thu, 30 Jun 2016 12:09:21 +0200 Subject: [PATCH 04/10] Added target for surveys. --- app/models/conference.rb | 2 +- app/models/survey.rb | 3 +-- app/views/admin/surveys/_form.html.haml | 1 + app/views/admin/surveys/index.html.haml | 3 +++ .../_registration_info.html.haml | 2 -- .../conference_registrations/show.html.haml | 16 ++++++---------- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 15352867..4d5b2085 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -36,7 +36,7 @@ class Conference < ActiveRecord::Base has_many :subscriptions, dependent: :destroy has_many :surveys, as: :surveyable, dependent: :destroy do def for_registration - where(target: targets[:registration]) + where(target: targets[:during_registration]) end end diff --git a/app/models/survey.rb b/app/models/survey.rb index d08df5dc..ac3e04a4 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -2,7 +2,6 @@ class Survey < ActiveRecord::Base belongs_to :surveyable, polymorphic: true has_many :survey_questions - enum target: [:conference, :registration] - + enum target: [:after_conference, :during_registration] validates :title, presence: true end diff --git a/app/views/admin/surveys/_form.html.haml b/app/views/admin/surveys/_form.html.haml index 11d1be9f..061ce52f 100644 --- a/app/views/admin/surveys/_form.html.haml +++ b/app/views/admin/surveys/_form.html.haml @@ -9,6 +9,7 @@ = f.hidden_field :surveyable_id = f.input :title = f.input :description, input_html: { rows: 3 } + = f.input :target, as: :select, collection: Survey.targets.keys, label: "When to ask" = f.input :start_date, as: :string, input_html: { class: 'datetimepicker' } = f.input :end_date, as: :string, input_html: { class: 'datetimepicker' } = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/admin/surveys/index.html.haml b/app/views/admin/surveys/index.html.haml index 17320355..f1a777f5 100644 --- a/app/views/admin/surveys/index.html.haml +++ b/app/views/admin/surveys/index.html.haml @@ -14,6 +14,7 @@ %table.table.table-hover#surveys %thead %th Title + %th When %th Start Date %th End Date %th Actions @@ -22,6 +23,8 @@ %tr %td = link_to survey.title, admin_conference_survey_path(@conference.short_title, survey) + %td + = survey.target %td = survey.start_date %td diff --git a/app/views/conference_registrations/_registration_info.html.haml b/app/views/conference_registrations/_registration_info.html.haml index c1015d08..ae8bcbd0 100644 --- a/app/views/conference_registrations/_registration_info.html.haml +++ b/app/views/conference_registrations/_registration_info.html.haml @@ -1,5 +1,3 @@ -- if @conference.surveys.for_registration.any? - Something - if @conference.program.events.with_registration_open.any? || @registration.events.any? = f.inputs 'Pre-registration required for the following:' do diff --git a/app/views/conference_registrations/show.html.haml b/app/views/conference_registrations/show.html.haml index dd73e70b..add392ad 100644 --- a/app/views/conference_registrations/show.html.haml +++ b/app/views/conference_registrations/show.html.haml @@ -36,24 +36,20 @@ = @registration.departure.strftime('%A, %B %-d. %Y %H:%M') - else You haven't scheduled your departure - - if @conference.questions.any? + - if @conference.surveys.for_registration.any? .row .col-md-12 %h4 %span.fa-stack %i.fa.fa-square-o.fa-stack-2x %i.fa.fa-info.fa-stack-1x - Additional Info + Surveys + %ul - - @conference.questions.each do |q| + - @conference.surveys.for_registration.each do |survey| %li - %strong - = q.title - - if @registration.qanswers.any? - - @registration.qanswers.where(:question_id => q.id).each do |qa| - = qa.answer.title - - else - You haven't answered + = link_to survey.title, "#" + - if @registration.events.any? .row .col-md-12 From 67bccf01953fe991daf72fb7375d1e15b951a9af Mon Sep 17 00:00:00 2001 From: Shyukri Shyukriev Date: Thu, 30 Jun 2016 13:04:07 +0200 Subject: [PATCH 05/10] Showing survey for users and handling authorization --- app/controllers/survey_controller.rb | 13 +++++++++++++ app/models/ability.rb | 3 +++ .../admin/surveys/_survey_question.html.haml | 11 ++++++----- .../conference_registrations/show.html.haml | 2 +- app/views/survey/show.html.haml | 18 ++++++++++++++++++ config/routes.rb | 3 +++ 6 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 app/controllers/survey_controller.rb create mode 100644 app/views/survey/show.html.haml diff --git a/app/controllers/survey_controller.rb b/app/controllers/survey_controller.rb new file mode 100644 index 00000000..f22a4fb3 --- /dev/null +++ b/app/controllers/survey_controller.rb @@ -0,0 +1,13 @@ +class SurveyController < ApplicationController + load_resource :conference, find_by: :short_title + load_and_authorize_resource + + def show + + end + + def reply + + end + +end diff --git a/app/models/ability.rb b/app/models/ability.rb index 2c1914be..0a4ec9e2 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -92,6 +92,9 @@ class Ability # can manage the commercials of their own events can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id) + + # can view and reply a survey + can [:show, :reply], Survey, surveyable_type: 'Conference', surveyable_id: user.registrations.pluck(:conference_id) end # Abilities for signed in users with roles diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml index 399ebd27..067f0374 100644 --- a/app/views/admin/surveys/_survey_question.html.haml +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -14,11 +14,12 @@ choices ) - if survey_question.mandatory %span.fa.fa-asterisk.text-danger - %p.pull-right - = link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do - %span.fa.fa-edit - = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do - %span.fa.fa-times + - if can? :edit, @survey + %p.pull-right + = link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do + %span.fa.fa-edit + = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do + %span.fa.fa-times .panel-body - if survey_question.boolean? %input{type: 'radio', name: 'radio'} diff --git a/app/views/conference_registrations/show.html.haml b/app/views/conference_registrations/show.html.haml index add392ad..710079a4 100644 --- a/app/views/conference_registrations/show.html.haml +++ b/app/views/conference_registrations/show.html.haml @@ -48,7 +48,7 @@ %ul - @conference.surveys.for_registration.each do |survey| %li - = link_to survey.title, "#" + = link_to survey.title, conference_survey_path(@conference.short_title, survey) - if @registration.events.any? .row diff --git a/app/views/survey/show.html.haml b/app/views/survey/show.html.haml new file mode 100644 index 00000000..568089fc --- /dev/null +++ b/app/views/survey/show.html.haml @@ -0,0 +1,18 @@ +.row + .col-md-12 + .page-header + %h1 + Survey #{@survey.title} + - if can? :edit, @survey + = link_to 'Edit Survey', admin_conference_survey_path(@conference.short_title, @survey), class: 'btn btn-primary pull-right' + %p.text-muted + From: + = @survey.start_date + to + = @survey.end_date +.row + .col-md-12 + - @survey.survey_questions.each.with_index(1) do |survey_question, index| + .row + .col-md-12 + = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, index: index } diff --git a/config/routes.rb b/config/routes.rb index 72fa4871..02a46547 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,6 +96,9 @@ Osem::Application.routes.draw do end resources :conference, only: [:index, :show] do + resources :survey, only: [:show] do + post :reply + end resource :program, only: [] do resources :proposal, except: :destroy do get 'commercials/render_commercial' => 'commercials#render_commercial' From 463a242c243c71ddaa3392e732866c74d626d378 Mon Sep 17 00:00:00 2001 From: Shyukri Shyukriev Date: Thu, 30 Jun 2016 14:51:23 +0200 Subject: [PATCH 06/10] Fixing route for replying the survey --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 02a46547..4ca8adf8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -97,7 +97,7 @@ Osem::Application.routes.draw do resources :conference, only: [:index, :show] do resources :survey, only: [:show] do - post :reply + patch :reply end resource :program, only: [] do resources :proposal, except: :destroy do From f433786c61bef85e85dad2364e5742edd028d992 Mon Sep 17 00:00:00 2001 From: Shyukri Shyukriev Date: Thu, 30 Jun 2016 14:52:43 +0200 Subject: [PATCH 07/10] Changing form for surveys --- .../admin/surveys/_survey_question.html.haml | 20 +++++++++---------- app/views/survey/show.html.haml | 11 ++++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml index 067f0374..f1ab664e 100644 --- a/app/views/admin/surveys/_survey_question.html.haml +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -22,30 +22,28 @@ %span.fa.fa-times .panel-body - if survey_question.boolean? - %input{type: 'radio', name: 'radio'} - Yes + = f.input "survey_question_#{survey_question.id}", as: :radio, name: 'Yes' %br - %input{type: 'radio', name: 'radio'} - No + = f.input "survey_question_#{survey_question.id}", as: :radio, name: 'No' - elsif survey_question.choice? - survey_question.possible_answers.split(',').map(&:strip).each do |option| - if survey_question.single_choice? - %input{ type: 'radio', name: 'radio' } + %input{ type: 'radio', name: "survey_question_#{survey_question.id}" } = option %br - else - %input{ type: 'checkbox', name: 'checkbox' } + %input{ type: 'checkbox', name: "survey_question_#{survey_question.id}" } = option %br - elsif survey_question.string? - %input.form-control + %input.form-control{ name: "survey_question_#{survey_question.id}" } - elsif survey_question.text? - %textarea.form-control{ rows: 4 } + %textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" } - elsif survey_question.datetime? - .form-group{class: 'datetimepicker'} + .form-group{ class: 'datetimepicker' } .input-group .input-group-addon %span.fa.fa-calendar - %input.form-control{readonly: 'readonly'} + %input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" } - elsif survey_question.numeric? - %input.form-control{ type: 'number' } + %input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" } diff --git a/app/views/survey/show.html.haml b/app/views/survey/show.html.haml index 568089fc..aec00610 100644 --- a/app/views/survey/show.html.haml +++ b/app/views/survey/show.html.haml @@ -10,9 +10,12 @@ = @survey.start_date to = @survey.end_date + .row .col-md-12 - - @survey.survey_questions.each.with_index(1) do |survey_question, index| - .row - .col-md-12 - = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, index: index } + = semantic_form_for @survey, url: conference_survey_reply_path(@conference.short_title, @survey) do |f| + - @survey.survey_questions.each.with_index(1) do |survey_question, index| + .row + .col-md-12 + = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, index: index, f: f } + = f.submit 'Submit', class: 'btn btn-primary pull-right' From 5ca234c8fcaa688c3c0e116a8dabbf4eb5ee0bf8 Mon Sep 17 00:00:00 2001 From: mdeniz Date: Thu, 30 Jun 2016 17:25:49 +0200 Subject: [PATCH 08/10] Remove Cocoon gem --- Gemfile | 1 - Gemfile.lock | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 7fcf55ca..0849b78c 100644 --- a/Gemfile +++ b/Gemfile @@ -75,7 +75,6 @@ gem 'bootstrap-sass', '~> 3.3.4.1' gem 'autoprefixer-rails' gem 'formtastic-bootstrap' gem 'formtastic', '~> 3.1.1' -gem 'cocoon' # as the JavaScript library gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 1766bd94..73bec84c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,7 +115,6 @@ GEM cloudinary (1.1.6) aws_cf_signer rest-client - cocoon (1.2.6) coderay (1.1.0) coffee-rails (4.1.1) coffee-script (>= 2.2.0) @@ -548,7 +547,6 @@ DEPENDENCIES carrierwave-bombshelter chart-js-rails cloudinary - cocoon country_select coveralls daemons @@ -623,3 +621,6 @@ DEPENDENCIES web-console (~> 2.0) webmock whenever + +BUNDLED WITH + 1.12.5 From 933e14673c67504c95a19789b25e55a798a89c91 Mon Sep 17 00:00:00 2001 From: mdeniz Date: Thu, 30 Jun 2016 17:28:07 +0200 Subject: [PATCH 09/10] Added Submission model --- app/controllers/survey_controller.rb | 3 +- app/models/survey.rb | 1 + app/models/survey_submission.rb | 7 +++ app/models/user.rb | 1 + .../admin/surveys/_survey_question.html.haml | 45 ++++++++----------- app/views/survey/show.html.haml | 2 +- config/routes.rb | 2 +- ...0160630130731_create_survey_submissions.rb | 10 +++++ db/schema.rb | 9 +++- 9 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 app/models/survey_submission.rb create mode 100644 db/migrate/20160630130731_create_survey_submissions.rb diff --git a/app/controllers/survey_controller.rb b/app/controllers/survey_controller.rb index f22a4fb3..e4d21f8b 100644 --- a/app/controllers/survey_controller.rb +++ b/app/controllers/survey_controller.rb @@ -3,11 +3,10 @@ class SurveyController < ApplicationController load_and_authorize_resource def show - + @survey_submission = @survey.survey_submissions.new end def reply - end end diff --git a/app/models/survey.rb b/app/models/survey.rb index ac3e04a4..a98968a7 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -1,6 +1,7 @@ class Survey < ActiveRecord::Base belongs_to :surveyable, polymorphic: true has_many :survey_questions + has_many :survey_submissions enum target: [:after_conference, :during_registration] validates :title, presence: true diff --git a/app/models/survey_submission.rb b/app/models/survey_submission.rb new file mode 100644 index 00000000..af8291b1 --- /dev/null +++ b/app/models/survey_submission.rb @@ -0,0 +1,7 @@ +class SurveySubmission < ActiveRecord::Base + belongs_to :user + belongs_to :survey + has_many :survey_replies, through: :user + + accepts_nested_attributes_for :survey_replies +end diff --git a/app/models/user.rb b/app/models/user.rb index 4bd2d3da..7f1ae5ef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,6 +43,7 @@ class User < ActiveRecord::Base has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy has_many :survey_replies + has_many :survey_submissions accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml index f1ab664e..039c2ee5 100644 --- a/app/views/admin/surveys/_survey_question.html.haml +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -21,29 +21,22 @@ = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do %span.fa.fa-times .panel-body - - if survey_question.boolean? - = f.input "survey_question_#{survey_question.id}", as: :radio, name: 'Yes' - %br - = f.input "survey_question_#{survey_question.id}", as: :radio, name: 'No' - - elsif survey_question.choice? - - survey_question.possible_answers.split(',').map(&:strip).each do |option| - - if survey_question.single_choice? - %input{ type: 'radio', name: "survey_question_#{survey_question.id}" } - = option - %br - - else - %input{ type: 'checkbox', name: "survey_question_#{survey_question.id}" } - = option - %br - - elsif survey_question.string? - %input.form-control{ name: "survey_question_#{survey_question.id}" } - - elsif survey_question.text? - %textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" } - - elsif survey_question.datetime? - .form-group{ class: 'datetimepicker' } - .input-group - .input-group-addon - %span.fa.fa-calendar - %input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" } - - elsif survey_question.numeric? - %input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" } + = f.semantic_fields_for :survey_reply do |reply, index| + = reply.hidden_field :survey_question_id, value: survey_question.id + - if survey_question.boolean? + = reply.input :text, as: :radio, label: false + - elsif survey_question.choice? + - choice_type = survey_question.single_choice? ? :radio : :check_boxes + = reply.input :text, as: choice_type, label: false, collection: survey_question.possible_answers.split(',').map(&:strip) + - elsif survey_question.string? + %input.form-control{ name: "survey_question_#{survey_question.id}" } + - elsif survey_question.text? + %textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" } + - elsif survey_question.datetime? + .form-group{ class: 'datetimepicker' } + .input-group + .input-group-addon + %span.fa.fa-calendar + %input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" } + - elsif survey_question.numeric? + %input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" } diff --git a/app/views/survey/show.html.haml b/app/views/survey/show.html.haml index aec00610..d6babaa8 100644 --- a/app/views/survey/show.html.haml +++ b/app/views/survey/show.html.haml @@ -13,7 +13,7 @@ .row .col-md-12 - = semantic_form_for @survey, url: conference_survey_reply_path(@conference.short_title, @survey) do |f| + = semantic_form_for @survey_submission, url: conference_survey_reply_path(@conference.short_title, @survey) do |f| - @survey.survey_questions.each.with_index(1) do |survey_question, index| .row .col-md-12 diff --git a/config/routes.rb b/config/routes.rb index 4ca8adf8..02a46547 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -97,7 +97,7 @@ Osem::Application.routes.draw do resources :conference, only: [:index, :show] do resources :survey, only: [:show] do - patch :reply + post :reply end resource :program, only: [] do resources :proposal, except: :destroy do diff --git a/db/migrate/20160630130731_create_survey_submissions.rb b/db/migrate/20160630130731_create_survey_submissions.rb new file mode 100644 index 00000000..bcab5271 --- /dev/null +++ b/db/migrate/20160630130731_create_survey_submissions.rb @@ -0,0 +1,10 @@ +class CreateSurveySubmissions < ActiveRecord::Migration + def change + create_table :survey_submissions do |t| + t.integer :user_id + t.integer :survey_id + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 597c4fce..59ef30c8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160630094850) do +ActiveRecord::Schema.define(version: 20160630130731) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -393,6 +393,13 @@ ActiveRecord::Schema.define(version: 20160630094850) do t.datetime "updated_at", null: false end + create_table "survey_submissions", force: :cascade do |t| + t.integer "user_id" + t.integer "survey_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "surveys", force: :cascade do |t| t.datetime "start_date" t.datetime "end_date" From ed087352e21bd7f8c64566584efdd57e46c1f171 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Fri, 1 Jul 2016 16:08:48 +0300 Subject: [PATCH 10/10] Latest state --- Gemfile.lock | 3 - app/assets/javascripts/application.js | 1 - app/controllers/survey_controller.rb | 12 ---- .../survey_submissions_controller.rb | 21 +++++++ app/controllers/surveys_controller.rb | 26 +++++++++ .../admin/surveys/_survey_question.html.haml | 58 ++++++++++++------- app/views/admin/surveys/show.html.haml | 9 +-- .../_form.html.haml} | 9 +-- app/views/surveys/show.html.haml | 22 +++++++ config/routes.rb | 3 +- 10 files changed, 119 insertions(+), 45 deletions(-) delete mode 100644 app/controllers/survey_controller.rb create mode 100644 app/controllers/survey_submissions_controller.rb create mode 100644 app/controllers/surveys_controller.rb rename app/views/{survey/show.html.haml => survey_submissions/_form.html.haml} (79%) create mode 100644 app/views/surveys/show.html.haml diff --git a/Gemfile.lock b/Gemfile.lock index 73bec84c..e507d2c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -621,6 +621,3 @@ DEPENDENCIES web-console (~> 2.0) webmock whenever - -BUNDLED WITH - 1.12.5 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bb2f4e9e..d181745c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,7 +15,6 @@ //= require waypoints/jquery.waypoints //= require dataTables/jquery.dataTables //= require dataTables/bootstrap/3/jquery.dataTables.bootstrap -//= require cocoon //= require bootstrap //= require Chart //= require osem diff --git a/app/controllers/survey_controller.rb b/app/controllers/survey_controller.rb deleted file mode 100644 index e4d21f8b..00000000 --- a/app/controllers/survey_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -class SurveyController < ApplicationController - load_resource :conference, find_by: :short_title - load_and_authorize_resource - - def show - @survey_submission = @survey.survey_submissions.new - end - - def reply - end - -end diff --git a/app/controllers/survey_submissions_controller.rb b/app/controllers/survey_submissions_controller.rb new file mode 100644 index 00000000..da693116 --- /dev/null +++ b/app/controllers/survey_submissions_controller.rb @@ -0,0 +1,21 @@ +class SurveySubmissionsController < ApplicationController + load_resource :conference, find_by: :short_title + load_resource :survey + load_and_authorize_resource +# skip_before_filter :verify_authenticity_token + + def edit + end + + def update + end + + def new + end + + def update + end + + def show + end +end diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb new file mode 100644 index 00000000..668bbb32 --- /dev/null +++ b/app/controllers/surveys_controller.rb @@ -0,0 +1,26 @@ +class SurveysController < ApplicationController + load_resource :conference, find_by: :short_title + load_and_authorize_resource +# skip_before_filter :verify_authenticity_token + + def edit + end + + def update + end + + def new + end + + def update + end + + def show + @survey_submission = @survey.survey_submissions.new + end + + def reply + redirect_to :back + end + +end diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml index 039c2ee5..641684aa 100644 --- a/app/views/admin/surveys/_survey_question.html.haml +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -1,8 +1,11 @@ .panel.panel-default .panel-heading %span.badge - = index + = question_index = survey_question.title + ID + = survey_question.id + - if survey_question.multiple_choice? ( Select - if survey_question.min_choices != survey_question.max_choices @@ -21,22 +24,37 @@ = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do %span.fa.fa-times .panel-body - = f.semantic_fields_for :survey_reply do |reply, index| - = reply.hidden_field :survey_question_id, value: survey_question.id - - if survey_question.boolean? - = reply.input :text, as: :radio, label: false - - elsif survey_question.choice? - - choice_type = survey_question.single_choice? ? :radio : :check_boxes - = reply.input :text, as: choice_type, label: false, collection: survey_question.possible_answers.split(',').map(&:strip) - - elsif survey_question.string? - %input.form-control{ name: "survey_question_#{survey_question.id}" } - - elsif survey_question.text? - %textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" } - - elsif survey_question.datetime? - .form-group{ class: 'datetimepicker' } - .input-group - .input-group-addon - %span.fa.fa-calendar - %input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" } - - elsif survey_question.numeric? - %input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" } + %input{ type: 'hidden', name: "survey_question_#{survey_question.id}", value: survey_question.id } + + - if survey_question.boolean? + %input{ type: 'radio', name: "survey_question_#{survey_question.id}_reply", value: 'Yes' } + Yes + %input{ type: 'radio', name: "survey_question_#{survey_question.id}_reply", value: 'No' } + No + + - elsif survey_question.choice? + - possible_answers = survey_question.possible_answers.split(',').map(&:strip) + + - possible_answers.each do |answer| + - if survey_question.single_choice? + %input{ type: 'radio', name: "survey_question_#{survey_question.id}_reply", value: answer } + = label_tag answer + %br + - else + = hidden_field_tag "survey_submission[survey_question_#{survey_question.id}][survey_reply_ids][]", nil + = check_box_tag "survey_submission[survey_question_#{survey_question.id}][survey_reply_ids][]", possible_answers.index, false + = answer + %br + - elsif survey_question.string? + %input.form-control{ name: "survey_question_#{survey_question.id}" } + - elsif survey_question.text? + %textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" } + - elsif survey_question.datetime? + .form-group{ class: 'datetimepicker' } + .input-group + .input-group-addon + %span.fa.fa-calendar + %input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" } + - elsif survey_question.numeric? + %input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" } + diff --git a/app/views/admin/surveys/show.html.haml b/app/views/admin/surveys/show.html.haml index f60d3653..7c140fc9 100644 --- a/app/views/admin/surveys/show.html.haml +++ b/app/views/admin/surveys/show.html.haml @@ -11,8 +11,9 @@ = @survey.end_date .row .col-md-12 - - @survey.survey_questions.each.with_index(1) do |survey_question, index| - .row - .col-md-12 - = render partial: 'survey_question', locals: { survey_question: survey_question, index: index } + = semantic_form_for 'survey_submission', url: '#' do |f| + - @survey.survey_questions.each.with_index(1) do |survey_question, index| + .row + .col-md-12 + = render partial: 'survey_question', locals: { survey_question: survey_question, index: index, f: f } = link_to 'Add Question', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right' diff --git a/app/views/survey/show.html.haml b/app/views/survey_submissions/_form.html.haml similarity index 79% rename from app/views/survey/show.html.haml rename to app/views/survey_submissions/_form.html.haml index d6babaa8..b3e10620 100644 --- a/app/views/survey/show.html.haml +++ b/app/views/survey_submissions/_form.html.haml @@ -1,5 +1,5 @@ .row - .col-md-12 + .col-md-10.col-md-offset-1 .page-header %h1 Survey #{@survey.title} @@ -14,8 +14,9 @@ .row .col-md-12 = semantic_form_for @survey_submission, url: conference_survey_reply_path(@conference.short_title, @survey) do |f| - - @survey.survey_questions.each.with_index(1) do |survey_question, index| + - @survey.survey_questions.each.with_index(1) do |survey_question, question_index| .row - .col-md-12 - = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, index: index, f: f } + .col-md-10.col-md-offset-1 + + = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, question_index: question_index, f: f } = f.submit 'Submit', class: 'btn btn-primary pull-right' diff --git a/app/views/surveys/show.html.haml b/app/views/surveys/show.html.haml new file mode 100644 index 00000000..cc93e740 --- /dev/null +++ b/app/views/surveys/show.html.haml @@ -0,0 +1,22 @@ +.row + .col-md-10.col-md-offset-1 + .page-header + %h1 + Survey #{@survey.title} + - if can? :edit, @survey + = link_to 'Edit Survey', admin_conference_survey_path(@conference.short_title, @survey), class: 'btn btn-primary pull-right' + %p.text-muted + From: + = @survey.start_date + to + = @survey.end_date + +.row + .col-md-12 + = semantic_form_for @survey_submission, url: conference_survey_reply_path(@conference.short_title, @survey) do |f| + - @survey.survey_questions.each.with_index(1) do |survey_question| + .row + .col-md-10.col-md-offset-1 + = f.semantic_fields_for :survey_reply do |myreply, index| + = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, index: index, myreply: myreply } + = f.submit 'Submit', class: 'btn btn-primary pull-right' diff --git a/config/routes.rb b/config/routes.rb index 02a46547..db3c76c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,7 +96,8 @@ Osem::Application.routes.draw do end resources :conference, only: [:index, :show] do - resources :survey, only: [:show] do + resources :surveys, only: [:show] do + resource :survey_submission post :reply end resource :program, only: [] do