now redirects to answer set if already taken.

This commit is contained in:
Harry Bomrah 2015-11-30 18:11:58 +08:00
parent 19cc1e2fb3
commit 7c511361ff
5 changed files with 35 additions and 8 deletions

View File

@ -25,8 +25,12 @@ class Admin::SurveysController < OrbitAdminController
end end
def answer_sets def answer_sets
if can_edit_or_delete?(@survey)
@table_fields = ['survey.taken_by', 'survey.taken_date'] @table_fields = ['survey.taken_by', 'survey.taken_date']
@survey_answers = @survey.survey_answers.desc(:created_at).page(params[:page]).per(15) @survey_answers = @survey.survey_answers.desc(:created_at).page(params[:page]).per(15)
else
render_401
end
end end
def answer_set def answer_set

View File

@ -5,8 +5,9 @@ class SurveysController < ApplicationController
def index def index
questionnairesurveys = QuestionnaireSurvey.any_of( {:postdate.lte => Time.now} ).desc(:postdate).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) questionnairesurveys = QuestionnaireSurvey.any_of( {:postdate.lte => Time.now} ).desc(:postdate).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
current_user = OrbitHelper.current_user
surveys = questionnairesurveys.collect do |a| surveys = questionnairesurveys.collect do |a|
answer_present = (current_user.nil? ? false : (a.survey_answers.where(:user => current_user.id).count > 0 ? true : false))
if !OrbitHelper.params[:page_no].blank? if !OrbitHelper.params[:page_no].blank?
title = ('<a href="'+ OrbitHelper.url_to_show(a.to_param) + "?method=show_data&page_no=#{OrbitHelper.params[:page_no]}" + '">' + a.title + '</a>').html_safe title = ('<a href="'+ OrbitHelper.url_to_show(a.to_param) + "?method=show_data&page_no=#{OrbitHelper.params[:page_no]}" + '">' + a.title + '</a>').html_safe
@ -18,7 +19,8 @@ class SurveysController < ApplicationController
"title" => title, "title" => title,
"time_range" => QuestionnaireSurvey.time_range(a), "time_range" => QuestionnaireSurvey.time_range(a),
"write" => QuestionnaireSurvey.write(a), "write" => QuestionnaireSurvey.write(a),
"result" => QuestionnaireSurvey.result(a) "result" => QuestionnaireSurvey.result(a),
"answer_present" => answer_present
} }
end end
{ {
@ -40,9 +42,13 @@ class SurveysController < ApplicationController
params = OrbitHelper.params params = OrbitHelper.params
survey = QuestionnaireSurvey.find_by(uid: params[:uid]) survey = QuestionnaireSurvey.find_by(uid: params[:uid])
current_user = OrbitHelper.current_user
answer_present = (current_user.nil? ? false : (survey.survey_answers.where(:user => current_user.id).count > 0 ? true : false))
link_to_answer_set = (answer_present ? "/admin/surveys/#{survey.survey_answers.where(:user => current_user.id).first.id.to_s}/answer_set" : "")
{ {
'survey' => survey, 'survey' => survey,
'answer_present' => answer_present,
'link_to_answer_set' => link_to_answer_set,
'time_range' => QuestionnaireSurvey.time_range(survey) 'time_range' => QuestionnaireSurvey.time_range(survey)
} }
@ -66,7 +72,9 @@ class SurveysController < ApplicationController
else else
questions = survey.survey_questions.all.entries questions = survey.survey_questions.all.entries
current_user = OrbitHelper.current_user
answer_present = (current_user.nil? ? false : (survey.survey_answers.where(:user => current_user.id).count > 0 ? true : false))
link_to_answer_set = (answer_present ? "/admin/surveys/#{survey.survey_answers.where(:user => current_user.id).first.id.to_s}/answer_set" : "")
if survey.jump_mode if survey.jump_mode
answers = Hash[questions.collect{ |o| [o.id.to_s, o.id.to_s] }] answers = Hash[questions.collect{ |o| [o.id.to_s, o.id.to_s] }]
jumpable_questions = questions.select{ |q| q.jumpable? && q.can_set_jump? } jumpable_questions = questions.select{ |q| q.jumpable? && q.can_set_jump? }
@ -75,8 +83,10 @@ class SurveysController < ApplicationController
{ {
'survey' => survey, 'survey' => survey,
'redirect_url' => '', 'redirect_url' => '',
'link_to_answer_set' => link_to_answer_set,
'questions' => questions, 'questions' => questions,
'answers' => answers, 'answers' => answers,
'answer_present' => answer_present,
'jump_tos_map' => jump_tos_map 'jump_tos_map' => jump_tos_map
} }

View File

@ -80,9 +80,11 @@
</div> </div>
<% end %> <% end %>
</div> </div>
<% if can_edit_or_delete?(@survey) %>
<div class="action"> <div class="action">
<a href="/admin/surveys/<%= @survey.id.to_s %>/answer_sets" class="btn btn-primary">Back to answer sets</a> <a href="/admin/surveys/<%= @survey.id.to_s %>/answer_sets" class="btn btn-primary">Back to answer sets</a>
</div> </div>
<% end %>
</div> </div>

View File

@ -6,7 +6,7 @@
@questions = data["questions"] @questions = data["questions"]
@jump_tos_map = data["jump_tos_map"] @jump_tos_map = data["jump_tos_map"]
@answers = data["answers"] @answers = data["answers"]
answer_present = data['answer_present']
@redirect_url = data["redirect_url"] @redirect_url = data["redirect_url"]
%> %>
@ -15,6 +15,11 @@
<script type="text/javascript"> <script type="text/javascript">
window.location.href = "<%= new_session_path %>"; window.location.href = "<%= new_session_path %>";
</script> </script>
<% elsif answer_present %>
<script type="text/javascript">
alert("Survey already taken.");
window.location.href = "<%= data['link_to_answer_set'] %>"
</script>
<% end %> <% end %>

View File

@ -4,6 +4,8 @@
data = action_data data = action_data
@survey = data["survey"] @survey = data["survey"]
@time_range = data["time_range"] @time_range = data["time_range"]
answer_present = data["answer_present"]
link_to_answer_set = data["link_to_answer_set"]
%> %>
<article class="show-survey" id="spen-survey"> <article class="show-survey" id="spen-survey">
@ -31,5 +33,9 @@
<% 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 %>
<% if !answer_present %>
<%= link_to "Take survey", OrbitHelper.url_to_show(@survey.to_param), :class => 'btn btn-primary' %> <%= link_to "Take survey", OrbitHelper.url_to_show(@survey.to_param), :class => 'btn btn-primary' %>
<% else %>
<%= link_to "View answers", link_to_answer_set, :class => "btn btn-primary" %>
<% end %>