Fix bug.
This commit is contained in:
parent
dedbe340ac
commit
9b6e011286
|
@ -185,9 +185,14 @@ class QuestionnaireSurvey
|
||||||
survey_answers = survey_answers.to_a
|
survey_answers = survey_answers.to_a
|
||||||
chart_data = {}
|
chart_data = {}
|
||||||
answers =(0...survey_answers.count).map{{}}
|
answers =(0...survey_answers.count).map{{}}
|
||||||
|
agree_trans = I18n.t("survey.true")
|
||||||
|
disagree_trans = I18n.t("survey.false")
|
||||||
survey_answers.each_with_index do |answer,i|
|
survey_answers.each_with_index do |answer,i|
|
||||||
answers[i]["name"] = User.find(answer.user).member_name rescue ""
|
answers[i]["name"] = User.find(answer.user).member_name rescue ""
|
||||||
answers[i]["agree"] = I18n.t("self.#{answer.consent_used}")
|
answers[i]["time"] = answer.created_at.strftime((I18n.locale == :zh_tw ? "%Y/%m/%d %H:%M" : "%h %d, %Y - %H:%M"))
|
||||||
|
if self.enable_consent_feature
|
||||||
|
answers[i]["agree"] = (answer.consent_used ? agree_trans : disagree_trans)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
SurveysHelper.set_locale(I18n.locale)
|
SurveysHelper.set_locale(I18n.locale)
|
||||||
survey_questions.each do |question|
|
survey_questions.each do |question|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class SurveyAnswer
|
||||||
if answer_group.nil?
|
if answer_group.nil?
|
||||||
answer_group = SurveyAnswerGroup.new(info)
|
answer_group = SurveyAnswerGroup.new(info)
|
||||||
end
|
end
|
||||||
answer_group.last_modified = self.updated_at
|
answer_group.last_modified = self.created_at
|
||||||
answer_group.survey_answer_ids << self.id
|
answer_group.survey_answer_ids << self.id
|
||||||
answer_group.save
|
answer_group.save
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ class SurveyAnswer
|
||||||
after_save do
|
after_save do
|
||||||
answer_group = SurveyAnswerGroup.where(:questionnaire_survey_id=>self.questionnaire_survey.id,:user=>user).first
|
answer_group = SurveyAnswerGroup.where(:questionnaire_survey_id=>self.questionnaire_survey.id,:user=>user).first
|
||||||
if answer_group
|
if answer_group
|
||||||
answer_group.last_modified = self.updated_at
|
answer_group.last_modified = self.created_at
|
||||||
answer_group.save
|
answer_group.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if type == "result_chart" %>
|
<% if type == "result_chart" %>
|
||||||
|
<% @survey_answers.options = {} %>
|
||||||
<div style="clear: both;"></div>
|
<div style="clear: both;"></div>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#tooltip{
|
#tooltip{
|
||||||
|
@ -94,7 +95,7 @@
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
<% if @survey.need_assign_color %>
|
<% if @survey.need_assign_color %>
|
||||||
<% data = @survey_answers.order_by(:updated_at=>1).group_by(&:color).map{|k,sas| [k, sas.map{|sa| [sa.updated_at.to_i * 1000 , sa.scored_points ]} ] }.to_h %>
|
<% data = @survey_answers.order_by(:created_at=>1).group_by(&:color).map{|k,sas| [k, sas.map{|sa| [sa.created_at.to_i * 1000 , sa.scored_points ]} ] }.to_h %>
|
||||||
var min_time = <%= data.map{|k,d| d[0][0] rescue 0}.min %>;
|
var min_time = <%= data.map{|k,d| d[0][0] rescue 0}.min %>;
|
||||||
var max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
var max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
||||||
<% all_data = data.values.flatten(1) %>
|
<% all_data = data.values.flatten(1) %>
|
||||||
|
@ -102,7 +103,7 @@
|
||||||
var min_y = <%= y_data.min.to_i %>;
|
var min_y = <%= y_data.min.to_i %>;
|
||||||
var max_y = <%= y_data.max.to_i %>;
|
var max_y = <%= y_data.max.to_i %>;
|
||||||
<% else %>
|
<% else %>
|
||||||
<% data = @survey_answers.order_by(:updated_at=>1).map{|sa| [sa.updated_at.to_i * 1000 , sa.scored_points ]} %>
|
<% data = @survey_answers.order_by(:created_at=>1).map{|sa| [sa.created_at.to_i * 1000 , sa.scored_points ]} %>
|
||||||
var min_time = <%= data[0][0] rescue 0 %>;
|
var min_time = <%= data[0][0] rescue 0 %>;
|
||||||
var max_time = <%= data[-1][0] rescue 0 %>;
|
var max_time = <%= data[-1][0] rescue 0 %>;
|
||||||
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
||||||
|
@ -224,7 +225,7 @@
|
||||||
var x = item.datapoint[0].toFixed(2),
|
var x = item.datapoint[0].toFixed(2),
|
||||||
y = item.datapoint[1].toFixed(0);
|
y = item.datapoint[1].toFixed(0);
|
||||||
var date = new moment(Math.round(x));
|
var date = new moment(Math.round(x));
|
||||||
var tp = "(" + date.format("yyyy/MM/DD hh:mm") + ")"
|
var tp = "(" + date.format("yyyy/MM/DD HH:mm") + ")"
|
||||||
$("#tooltip").html("<%=t("survey.type.0")%>: "+y+"<br>"+tp);
|
$("#tooltip").html("<%=t("survey.type.0")%>: "+y+"<br>"+tp);
|
||||||
var left = 0;
|
var left = 0;
|
||||||
var content_width = tp.length*8.2
|
var content_width = tp.length*8.2
|
||||||
|
@ -261,7 +262,7 @@
|
||||||
<% else %>
|
<% else %>
|
||||||
<td>NA</td>
|
<td>NA</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<td><%= (@is_answer_list ? sa.updated_at : sa.last_modified).strftime("%h %d, %Y - %H:%M") rescue nil %></td>
|
<td><%= (@is_answer_list ? sa.created_at : sa.last_modified).strftime((I18n.locale == :zh_tw ? "%Y/%m/%d %H:%M" : "%h %d, %Y - %H:%M")) rescue nil %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if @answer_repeat && !@is_answer_list %>
|
<% if @answer_repeat && !@is_answer_list %>
|
||||||
<a class="btn btn-primary" href="/admin/surveys/<%= sa.id.to_s %>/answer_list"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)</a>
|
<a class="btn btn-primary" href="/admin/surveys/<%= sa.id.to_s %>/answer_list"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)</a>
|
||||||
|
|
|
@ -4,8 +4,12 @@ wb = xlsx_package.workbook
|
||||||
title = survey.title
|
title = survey.title
|
||||||
title = "WorkSheet1" if title.blank?
|
title = "WorkSheet1" if title.blank?
|
||||||
wb.add_worksheet(name: title) do |sheet|
|
wb.add_worksheet(name: title) do |sheet|
|
||||||
row = [I18n.t("survey.taken_by"), I18n.t("survey.consent_to_be_used_for_research")]
|
row = [I18n.t("survey.taken_by"), I18n.t("survey.taken_date")]
|
||||||
row2 = ["", ""]
|
row2 = ["", ""]
|
||||||
|
if survey.enable_consent_feature
|
||||||
|
row << survey.consent_contents
|
||||||
|
row2 << ""
|
||||||
|
end
|
||||||
survey_questions.each_with_index do |question, i|
|
survey_questions.each_with_index do |question, i|
|
||||||
qnum = question.title.match(/^\d+./).nil? ? "#{i+1}. " : ""
|
qnum = question.title.match(/^\d+./).nil? ? "#{i+1}. " : ""
|
||||||
start_col = row2.count
|
start_col = row2.count
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
<% if @survey.need_assign_color %>
|
<% if @survey.need_assign_color %>
|
||||||
<% data = @survey_answers.order_by(:updated_at=>1).group_by(&:color).map{|k,sas| [k, sas.map{|sa| [sa.updated_at.to_i * 1000 , sa.scored_points ]} ] }.to_h %>
|
<% data = @survey_answers.order_by(:created_at=>1).group_by(&:color).map{|k,sas| [k, sas.map{|sa| [sa.created_at.to_i * 1000 , sa.scored_points ]} ] }.to_h %>
|
||||||
var min_time = <%= data.map{|k,d| d[0][0] rescue 0}.min %>;
|
var min_time = <%= data.map{|k,d| d[0][0] rescue 0}.min %>;
|
||||||
var max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
var max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
||||||
<% all_data = data.values.flatten(1) %>
|
<% all_data = data.values.flatten(1) %>
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
var min_y = <%= y_data.min.to_i %>;
|
var min_y = <%= y_data.min.to_i %>;
|
||||||
var max_y = <%= y_data.max.to_i %>;
|
var max_y = <%= y_data.max.to_i %>;
|
||||||
<% else %>
|
<% else %>
|
||||||
<% data = @survey_answers.order_by(:updated_at=>1).map{|sa| [sa.updated_at.to_i * 1000 , sa.scored_points ]} %>
|
<% data = @survey_answers.order_by(:created_at=>1).map{|sa| [sa.created_at.to_i * 1000 , sa.scored_points ]} %>
|
||||||
var min_time = <%= data[0][0] rescue 0 %>;
|
var min_time = <%= data[0][0] rescue 0 %>;
|
||||||
var max_time = <%= data[-1][0] rescue 0 %>;
|
var max_time = <%= data[-1][0] rescue 0 %>;
|
||||||
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
||||||
|
@ -207,7 +207,7 @@
|
||||||
var x = item.datapoint[0].toFixed(2),
|
var x = item.datapoint[0].toFixed(2),
|
||||||
y = item.datapoint[1].toFixed(0);
|
y = item.datapoint[1].toFixed(0);
|
||||||
var date = new moment(Math.round(x));
|
var date = new moment(Math.round(x));
|
||||||
var tp = "(" + date.format("yyyy/MM/DD hh:mm") + ")"
|
var tp = "(" + date.format("yyyy/MM/DD HH:mm") + ")"
|
||||||
$("#tooltip").html("<%=t("survey.type.0")%>: "+y+"<br>"+tp);
|
$("#tooltip").html("<%=t("survey.type.0")%>: "+y+"<br>"+tp);
|
||||||
var left = 0;
|
var left = 0;
|
||||||
var content_width = tp.length*8.2
|
var content_width = tp.length*8.2
|
||||||
|
@ -245,7 +245,7 @@
|
||||||
<% else %>
|
<% else %>
|
||||||
<td>NA</td>
|
<td>NA</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<td><%= (@is_answer_list ? sa.updated_at : sa.last_modified).strftime("%h %d, %Y - %H:%M") rescue nil %></td>
|
<td><%= (@is_answer_list ? sa.created_at : sa.last_modified).strftime((I18n.locale == :zh_tw ? "%Y/%m/%d %H:%M" : "%h %d, %Y - %H:%M")) rescue nil %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if @answer_repeat && !@is_answer_list %>
|
<% if @answer_repeat && !@is_answer_list %>
|
||||||
<a class="btn btn-primary" href="/admin/surveys/<%= sa.id.to_s %>/answer_list" title="<%= t("survey.view") %>"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)</a>
|
<a class="btn btn-primary" href="/admin/surveys/<%= sa.id.to_s %>/answer_list" title="<%= t("survey.view") %>"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)</a>
|
||||||
|
|
|
@ -4,8 +4,8 @@ zh_tw:
|
||||||
survey: 問卷調查
|
survey: 問卷調查
|
||||||
|
|
||||||
survey:
|
survey:
|
||||||
'true': 是
|
'true': 已勾選
|
||||||
'false': 否
|
'false': 未勾選
|
||||||
consent_to_be_used_for_research: "同意填答結果被用於研究"
|
consent_to_be_used_for_research: "同意填答結果被用於研究"
|
||||||
agree: 同意
|
agree: 同意
|
||||||
consent_contents: '"同意書"內容'
|
consent_contents: '"同意書"內容'
|
||||||
|
|
Loading…
Reference in New Issue