added functionality to take survey only after login and also can see the results of each user
This commit is contained in:
parent
babd165eca
commit
19cc1e2fb3
|
@ -2,7 +2,7 @@ class Admin::SurveysController < OrbitAdminController
|
||||||
include Admin::SurveysHelper
|
include Admin::SurveysHelper
|
||||||
|
|
||||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||||
before_action :set_survey, only: [:edit, :destroy, :export, :set_answers, :jump, :duplicate_it]
|
before_action :set_survey, only: [:edit, :destroy, :export, :set_answers, :jump, :duplicate_it, :answer_sets]
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
@ -24,6 +24,17 @@ class Admin::SurveysController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def answer_sets
|
||||||
|
@table_fields = ['survey.taken_by', 'survey.taken_date']
|
||||||
|
@survey_answers = @survey.survey_answers.desc(:created_at).page(params[:page]).per(15)
|
||||||
|
end
|
||||||
|
|
||||||
|
def answer_set
|
||||||
|
@survey_answer = SurveyAnswer.find(params["id"]) rescue nil
|
||||||
|
@survey = @survey_answer.questionnaire_survey if !@survey_answer.nil?
|
||||||
|
@user = @survey_answer.user.nil? ? nil : (User.find(@survey_answer.user) rescue nil)
|
||||||
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@survey = QuestionnaireSurvey.new
|
@survey = QuestionnaireSurvey.new
|
||||||
@primary_locale = I18n.locale.to_s
|
@primary_locale = I18n.locale.to_s
|
||||||
|
|
|
@ -91,6 +91,7 @@ class SurveysController < ApplicationController
|
||||||
|
|
||||||
answer = params[:answer]
|
answer = params[:answer]
|
||||||
@answer_model = @survey.survey_answers.new
|
@answer_model = @survey.survey_answers.new
|
||||||
|
@answer_model.user = current_user.id if !current_user.nil?
|
||||||
@survey.survey_questions.each do |question|
|
@survey.survey_questions.each do |question|
|
||||||
qid = question.id.to_s
|
qid = question.id.to_s
|
||||||
if question.is_required && answer[qid].blank? && !@survey.jump_mode #&& (! @survey.jump_mode || ( @survey.jump_mode && question.jumpable? ) )
|
if question.is_required && answer[qid].blank? && !@survey.jump_mode #&& (! @survey.jump_mode || ( @survey.jump_mode && question.jumpable? ) )
|
||||||
|
|
|
@ -21,6 +21,7 @@ class QuestionnaireSurvey
|
||||||
field :deadline, :type => DateTime
|
field :deadline, :type => DateTime
|
||||||
|
|
||||||
field :is_hidden, :type => Boolean, :default => false
|
field :is_hidden, :type => Boolean, :default => false
|
||||||
|
field :needs_login, :type => Boolean, :default => false
|
||||||
|
|
||||||
field :result_type, :type => Integer, :default => 0
|
field :result_type, :type => Integer, :default => 0
|
||||||
field :extern_link
|
field :extern_link
|
||||||
|
|
|
@ -2,6 +2,8 @@ class SurveyAnswer
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
field :user, type: BSON::ObjectId
|
||||||
|
|
||||||
belongs_to :questionnaire_survey
|
belongs_to :questionnaire_survey
|
||||||
|
|
||||||
end
|
end
|
|
@ -69,16 +69,25 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label muted" for="account"><%= t('survey.postdate') %></label>
|
<label class="control-label muted" for="account"><%= t('survey.postdate') %></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.datetime_picker :postdate, :no_label => true %>
|
<%= f.datetime_picker :postdate, :value => @survey.postdate, :new_record => @survey.new_record? %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- end date -->
|
<!-- end date -->
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label muted" for="account"><%= t('survey.deadline') %></label>
|
<label class="control-label muted" for="account"><%= t('survey.deadline') %></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.datetime_picker :deadline, :no_label => true %>
|
<%= f.datetime_picker :deadline, :value => @survey.deadline, :new_record => @survey.new_record? %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- needs login -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :needs_login, t("survey.needs_login"), :class=>"control-label muted" %>
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox">
|
||||||
|
<%= f.check_box :needs_login %>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- redirect mode -->
|
<!-- redirect mode -->
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
|
|
|
@ -39,7 +39,13 @@
|
||||||
</td>
|
</td>
|
||||||
<td><%= (survey.postdate) ? (format_value survey.postdate) : t(:no_deadline) %></td>
|
<td><%= (survey.postdate) ? (format_value survey.postdate) : t(:no_deadline) %></td>
|
||||||
<td><%= (survey.deadline) ? (format_value survey.deadline) : t(:no_deadline) %></td>
|
<td><%= (survey.deadline) ? (format_value survey.deadline) : t(:no_deadline) %></td>
|
||||||
<td><%= survey.survey_answers.count %></td>
|
<td>
|
||||||
|
<% if survey.needs_login %>
|
||||||
|
<a href="/admin/surveys/<%=survey.id.to_s%>/answer_sets"> <%= survey.survey_answers.count %></a>
|
||||||
|
<% else %>
|
||||||
|
<%= survey.survey_answers.count %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td><%= survey.update_user.user_name rescue ''%></td>
|
<td><%= survey.update_user.user_name rescue ''%></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
<% content_for :page_specific_css do %>
|
||||||
|
<style>
|
||||||
|
.answer-set .title{
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
.answer-set .title i{
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
.answer-set .set{
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
padding: 15px 0px;
|
||||||
|
}
|
||||||
|
.set {
|
||||||
|
color: #7E7D7D;
|
||||||
|
}
|
||||||
|
.set .qa{
|
||||||
|
padding: 15px 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
.set .qa .init{
|
||||||
|
margin-right: 5px;
|
||||||
|
width: 30px;
|
||||||
|
border-right: 3px solid #7E7D7D;
|
||||||
|
display: inline-block;
|
||||||
|
font-weight: bold;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
.set .question{
|
||||||
|
font-size: 16px;
|
||||||
|
border-bottom: 1px solid #cecece;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
.set .answer{
|
||||||
|
font-size: 16px;
|
||||||
|
padding-top: 5px;
|
||||||
|
word-break: break-all;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
.set .radiogroup{
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="answer-set">
|
||||||
|
<div class="title">
|
||||||
|
<h3><%= @survey.title %></h3>
|
||||||
|
<% if !@user.nil? %>
|
||||||
|
<h5><i class="icon icons-user"></i><%= @user.name %></h5>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="set">
|
||||||
|
<% @survey.survey_questions.each_with_index do |sq, index| %>
|
||||||
|
<div class="qa">
|
||||||
|
<div class="question">
|
||||||
|
<span class="init">Q<%= (index + 1).to_s %></span> <%= sq.title %>
|
||||||
|
</div>
|
||||||
|
<div class="answer">
|
||||||
|
<span class="init">A</span>
|
||||||
|
<% case sq.type %>
|
||||||
|
<% when SurveyQuestion::Radio, SurveyQuestion::Select %>
|
||||||
|
<%= @survey_answer[sq.id.to_s] rescue "" %>
|
||||||
|
<% when SurveyQuestion::Check %>
|
||||||
|
<%= @survey_answer[sq.id.to_s].join(", ") rescue "" %>
|
||||||
|
<% when SurveyQuestion::Radiogroup %>
|
||||||
|
<div class="radiogroup">
|
||||||
|
<% sq.survey_question_options.each do |sqo| %>
|
||||||
|
<% if !@survey_answer[sq.id.to_s].nil? %>
|
||||||
|
<%= sqo.name %> : <%= @survey_answer[sq.id.to_s][sqo.id.to_s] %> <br />
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% when SurveyQuestion::Oneline, SurveyQuestion::Multiline %>
|
||||||
|
<%= @survey_answer[sq.id.to_s] rescue "" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="action">
|
||||||
|
<a href="/admin/surveys/<%= @survey.id.to_s %>/answer_sets" class="btn btn-primary">Back to answer sets</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<h3><%= @survey.title %></h3>
|
||||||
|
<table class="table main-list">
|
||||||
|
<thead>
|
||||||
|
<tr class="sort-header">
|
||||||
|
<% @table_fields.each do |f| %>
|
||||||
|
<%= thead(f) %>
|
||||||
|
<% end %>
|
||||||
|
<th class="span2"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @survey_answers.each do |sa| %>
|
||||||
|
<tr>
|
||||||
|
<% user = sa.user.nil? ? nil : (User.find(sa.user) rescue nil) %>
|
||||||
|
<% if !user.nil? %>
|
||||||
|
<td><%= user.name %></td>
|
||||||
|
<% else %>
|
||||||
|
<td> </td>
|
||||||
|
<% end %>
|
||||||
|
<td><%= sa.created_at.strftime("%y-%M-%d %h:%m") rescue nil %></td>
|
||||||
|
<td><a href="/admin/surveys/<%= sa.id.to_s %>/answer_set"><%= t("survey.view_answers") %></a></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<%=
|
||||||
|
content_tag :div, class: "bottomnav clearfix" do
|
||||||
|
content_tag :div, paginate(@survey_answers), class: "pagination pagination-centered"
|
||||||
|
end
|
||||||
|
%>
|
|
@ -11,6 +11,13 @@
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
|
||||||
|
<% if @survey.needs_login && current_user.nil? %>
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.location.href = "<%= new_session_path %>";
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
<% if !@redirect_url.blank? %>
|
<% if !@redirect_url.blank? %>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -22,7 +29,7 @@
|
||||||
<% unless @survey.deadline && Time.now > @survey.deadline %>
|
<% unless @survey.deadline && Time.now > @survey.deadline %>
|
||||||
|
|
||||||
<div class="o-question">
|
<div class="o-question">
|
||||||
<%= form_for :answer, :method => :put, :url => survey_path(@survey, :standalone => true), :html => {:class => 'survey clear'} do |f| %>
|
<%= form_for :answer, :method => :put, :url => survey_path(@survey), :html => {:class => 'survey clear'} do |f| %>
|
||||||
<h3 class="o-question-topic"><%= @survey.title %></h3>
|
<h3 class="o-question-topic"><%= @survey.title %></h3>
|
||||||
<div class="o-question-description">
|
<div class="o-question-description">
|
||||||
<%= @survey.description %>
|
<%= @survey.description %>
|
||||||
|
|
|
@ -26,9 +26,10 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<% if !params[:page_no].blank? %>
|
<% if !params[:page_no].blank? %>
|
||||||
<%= link_to t('back'), page_for_survey+"?page_no=#{params[:page_no]}", :class => 'btn btn-primary' %>
|
<%= link_to t('back'), page_for_survey+"?page_no=#{params[:page_no]}", :class => 'btn btn-primary' %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t('back'), page_for_survey, :class => 'btn btn-primary' %>
|
<%= link_to t('back'), page_for_survey, :class => 'btn btn-primary' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= link_to "Take survey", OrbitHelper.url_to_show(@survey.to_param), :class => 'btn btn-primary' %>
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ en:
|
||||||
survey:
|
survey:
|
||||||
survey: Survey
|
survey: Survey
|
||||||
title: Title
|
title: Title
|
||||||
|
needs_login: User need to login
|
||||||
|
|
||||||
time_range: Date Range
|
time_range: Date Range
|
||||||
write: Write
|
write: Write
|
||||||
|
@ -18,6 +19,9 @@ en:
|
||||||
question: Question
|
question: Question
|
||||||
is_external: The survey is an external link
|
is_external: The survey is an external link
|
||||||
add: Add Question
|
add: Add Question
|
||||||
|
taken_by: Taken By
|
||||||
|
taken_date: Taken On
|
||||||
|
view_answers: View Answers
|
||||||
|
|
||||||
result_type: Result Type (Frontend)
|
result_type: Result Type (Frontend)
|
||||||
extern_link: External Link
|
extern_link: External Link
|
||||||
|
|
|
@ -6,7 +6,7 @@ zh_tw:
|
||||||
survey:
|
survey:
|
||||||
survey: 問卷調查
|
survey: 問卷調查
|
||||||
title: 問卷標題
|
title: 問卷標題
|
||||||
|
needs_login: User need to login
|
||||||
time_range: 問卷期間
|
time_range: 問卷期間
|
||||||
write: 填問卷
|
write: 填問卷
|
||||||
result: 結果
|
result: 結果
|
||||||
|
@ -22,6 +22,9 @@ zh_tw:
|
||||||
question: 問題
|
question: 問題
|
||||||
is_external: 這份問卷為外部連結
|
is_external: 這份問卷為外部連結
|
||||||
add: 新增題目
|
add: 新增題目
|
||||||
|
taken_by: Taken By
|
||||||
|
taken_date: Taken On
|
||||||
|
view_answers: View Answers
|
||||||
|
|
||||||
result_type: 前端結果表示方式
|
result_type: 前端結果表示方式
|
||||||
extern_link: 外部連結
|
extern_link: 外部連結
|
||||||
|
|
|
@ -13,6 +13,8 @@ Rails.application.routes.draw do
|
||||||
get 'set_answers'
|
get 'set_answers'
|
||||||
get 'jump'
|
get 'jump'
|
||||||
get 'duplicate_it'
|
get 'duplicate_it'
|
||||||
|
get 'answer_sets'
|
||||||
|
get 'answer_set'
|
||||||
end
|
end
|
||||||
resources :answers, :controller => :surveys_answers do
|
resources :answers, :controller => :surveys_answers do
|
||||||
collection do
|
collection do
|
||||||
|
|
Loading…
Reference in New Issue