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"