Fix bug.
change result chart to year seperated. Add color recover to default feature. change consent checkbox to required.
This commit is contained in:
parent
9b6e011286
commit
cc4131c05e
|
@ -234,6 +234,9 @@ class Admin::SurveysController < OrbitAdminController
|
|||
end
|
||||
|
||||
def delete_section
|
||||
@section = SurveySection.find(params[:id])
|
||||
@section.destroy
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
def create_section
|
||||
|
|
|
@ -300,7 +300,9 @@ class SurveysController < ApplicationController
|
|||
end
|
||||
end
|
||||
@answer_model.save!
|
||||
params[:url] = params[:show_page_url]
|
||||
show_page = (OrbitHelper.page.nil? rescue true) ? Page.where(:page_id=>params["page_id"]).first : OrbitHelper.page
|
||||
show_page_url = show_page.get_url rescue show_page.url
|
||||
params[:url] = show_page_url
|
||||
OrbitHelper.set_params(params,current_user)
|
||||
redirect_to OrbitHelper.url_to_show(@survey.to_param) + "?method=answer_success&ans=#{@answer_model.id.to_s}"
|
||||
else
|
||||
|
|
|
@ -67,17 +67,17 @@ class QuestionnaireSurvey
|
|||
end
|
||||
def check_need_update
|
||||
if self.result_criteria_changed?
|
||||
old_colors = self.result_criteria_was.map{|c| c["color"].blank? ? '#ffffff' : c["color"]}
|
||||
new_colors = self.result_criteria.map{|c| c["color"].blank? ? '#ffffff' : c["color"]}
|
||||
old_colors = self.result_criteria_was.map{|c| c["color"].blank? ? '#ffffff' : c["color"]} rescue []
|
||||
new_colors = self.result_criteria.map{|c| c["color"].blank? ? '#ffffff' : c["color"]} rescue []
|
||||
new_colors_uniq_count = new_colors.uniq.count
|
||||
self.need_assign_color = (new_colors_uniq_count > 1)
|
||||
if old_colors != new_colors
|
||||
self.need_update_color = true
|
||||
elsif new_colors_uniq_count > 1
|
||||
old_questions = self.result_criteria_was.map{|c| c["questions"]}
|
||||
old_range = self.result_criteria_was.map{|c| c["range"]}
|
||||
new_questions = self.result_criteria.map{|c| c["questions"]}
|
||||
new_range = self.result_criteria.map{|c| c["range"]}
|
||||
old_questions = self.result_criteria_was.map{|c| c["questions"]} rescue []
|
||||
old_range = self.result_criteria_was.map{|c| c["range"]} rescue []
|
||||
new_questions = self.result_criteria.map{|c| c["questions"]} rescue []
|
||||
new_range = self.result_criteria.map{|c| c["range"]} rescue []
|
||||
if old_questions != new_questions || old_range != new_range
|
||||
self.need_update_color = true
|
||||
end
|
||||
|
@ -193,6 +193,7 @@ class QuestionnaireSurvey
|
|||
if self.enable_consent_feature
|
||||
answers[i]["agree"] = (answer.consent_used ? agree_trans : disagree_trans)
|
||||
end
|
||||
answers[i]["scored_points"] = answer.scored_points
|
||||
end
|
||||
SurveysHelper.set_locale(I18n.locale)
|
||||
survey_questions.each do |question|
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
<% @survey_answers.options = {} %>
|
||||
<div style="clear: both;"></div>
|
||||
<style type="text/css">
|
||||
#tooltip{
|
||||
.tooltip{
|
||||
position: absolute;
|
||||
background: #ffffff;
|
||||
z-index: 1;
|
||||
|
@ -65,16 +65,13 @@
|
|||
padding: 2px;
|
||||
display: none;
|
||||
font-weight: bold;
|
||||
font-size: 1em;
|
||||
opacity: 1;
|
||||
}
|
||||
.flot_wrapper{
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
<div class="flot_wrapper">
|
||||
<span id="tooltip"></span>
|
||||
<div class="legend-container"></div>
|
||||
<div id="resultchart-container" class="flot-placeholder"></div>
|
||||
</div>
|
||||
<%= javascript_include_tag "survey/jquery.colorhelpers.js" %>
|
||||
<%= javascript_include_tag "survey/jquery.canvaswrapper.js" %>
|
||||
<%= javascript_include_tag "survey/jquery.flot_3.0.js" %>
|
||||
|
@ -93,140 +90,168 @@
|
|||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
<% if @survey.need_assign_color %>
|
||||
<% 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 max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
||||
<% all_data = data.values.flatten(1) %>
|
||||
<% y_data = all_data.map{|v| v[1]} %>
|
||||
var min_y = <%= y_data.min.to_i %>;
|
||||
var max_y = <%= y_data.max.to_i %>;
|
||||
<% else %>
|
||||
<% 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 max_time = <%= data[-1][0] rescue 0 %>;
|
||||
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
||||
var max_y = <%= data.map{|a| a[1]}.max.to_i %>;
|
||||
<% end %>
|
||||
var xaxes = [{
|
||||
mode: "time",
|
||||
axisLabelUseCanvas: false,
|
||||
timeformat: "%Y/%m/%d",
|
||||
timezone: "browser",
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
// min: min_time,
|
||||
// max: max_time,
|
||||
axisLabel: "<%=t("survey.taken_date")%>",
|
||||
position: "bottom",
|
||||
}];
|
||||
var yaxes = [{
|
||||
use_min_force: false, //modify at jquery_flot_3.0.js
|
||||
axisLabelUseCanvas: false,
|
||||
showTickLabels: 'all',
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
// min: min_y,
|
||||
// max: max_y,
|
||||
axisLabel: "<%=t("survey.result_score")%>",
|
||||
position: "left",
|
||||
axisLabelFontSizePixels: 12,
|
||||
axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
|
||||
axisLabelPadding: 5
|
||||
}];
|
||||
var options = {
|
||||
series: {
|
||||
lines: {
|
||||
show: true,
|
||||
lineWidth: 2,
|
||||
steps: false , //畫斜線
|
||||
is_sort: true
|
||||
<% @survey_answers = @survey_answers.order_by(:created_at=>1) %>
|
||||
<% last_year = @survey_answers.last.created_at.year %>
|
||||
<% first_year = @survey_answers.first.created_at.year %>
|
||||
<% all_years = (first_year..last_year).to_a.reverse %>
|
||||
<% all_years.each do |year|%>
|
||||
<% start_d = DateTime.parse("#{year}/1/1 #{Time.zone}") %>
|
||||
<% end_d = start_d.end_of_year %>
|
||||
<% survey_answers_sep = @survey_answers.where(:created_at.gte=>start_d).and(:created_at.lte=>end_d) %>
|
||||
<% next if survey_answers_sep.count == 0 %>
|
||||
<div class="flot_wrapper" id="<%=year%>_block">
|
||||
<h4 style="text-align: center;"><%= year %></h4>
|
||||
<span class="tooltip"></span>
|
||||
<div class="legend-container"></div>
|
||||
<div class="flot-placeholder"></div>
|
||||
</div>
|
||||
<script>
|
||||
(function(){
|
||||
<% if @survey.need_assign_color %>
|
||||
<% data = survey_answers_sep.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 max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
||||
<% all_data = data.values.flatten(1) %>
|
||||
<% y_data = all_data.map{|v| v[1]} %>
|
||||
var min_y = <%= y_data.min.to_i %>;
|
||||
var max_y = <%= y_data.max.to_i %>;
|
||||
<% else %>
|
||||
<% data = survey_answers_sep.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 max_time = <%= data[-1][0] rescue 0 %>;
|
||||
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
||||
var max_y = <%= data.map{|a| a[1]}.max.to_i %>;
|
||||
<% end %>
|
||||
var xaxes = [{
|
||||
mode: "time",
|
||||
axisLabelUseCanvas: false,
|
||||
timeformat: "%Y/%m/%d",
|
||||
timezone: "browser",
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
points: {
|
||||
radius: 5,
|
||||
show: true,
|
||||
fillColor: '#ffffff'
|
||||
// min: min_time,
|
||||
// max: max_time,
|
||||
axisLabel: "<%=t("survey.taken_date")%>",
|
||||
position: "bottom",
|
||||
}];
|
||||
var yaxes = [{
|
||||
use_min_force: false, //modify at jquery_flot_3.0.js
|
||||
axisLabelUseCanvas: false,
|
||||
showTickLabels: 'all',
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
downsample: {
|
||||
threshold: 0
|
||||
// min: min_y,
|
||||
// max: max_y,
|
||||
axisLabel: "<%=t("survey.result_score")%>",
|
||||
position: "left",
|
||||
axisLabelFontSizePixels: 12,
|
||||
axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
|
||||
axisLabelPadding: 5
|
||||
}];
|
||||
var options = {
|
||||
series: {
|
||||
lines: {
|
||||
show: true,
|
||||
lineWidth: 2,
|
||||
steps: false , //畫斜線
|
||||
is_sort: true
|
||||
},
|
||||
points: {
|
||||
radius: 5,
|
||||
show: true,
|
||||
fillColor: '#ffffff'
|
||||
},
|
||||
downsample: {
|
||||
threshold: 0
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
hoverable: true,
|
||||
clickable: true,
|
||||
show: true
|
||||
},
|
||||
xaxes: xaxes,
|
||||
yaxes: yaxes,
|
||||
zoom: {
|
||||
interactive: true
|
||||
},
|
||||
pan: {
|
||||
interactive: true,
|
||||
enableTouch: true
|
||||
},
|
||||
colors: ["#708fff"], //["#708fff","#ffc107","#96478c","#1e7e34"],
|
||||
polycolors: ["#3f66f4"],//["#3f66f4","#ffc107","#dc3545","#1e7e34"],
|
||||
// legend: {
|
||||
// show: true,
|
||||
// noColumns: 1
|
||||
// },
|
||||
bar: {
|
||||
zero: false
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
hoverable: true,
|
||||
clickable: true,
|
||||
show: true
|
||||
},
|
||||
xaxes: xaxes,
|
||||
yaxes: yaxes,
|
||||
zoom: {
|
||||
interactive: true
|
||||
},
|
||||
pan: {
|
||||
interactive: true,
|
||||
enableTouch: true
|
||||
},
|
||||
colors: ["#708fff"], //["#708fff","#ffc107","#96478c","#1e7e34"],
|
||||
polycolors: ["#3f66f4"],//["#3f66f4","#ffc107","#dc3545","#1e7e34"],
|
||||
// legend: {
|
||||
// show: true,
|
||||
// noColumns: 1
|
||||
// },
|
||||
bar: {
|
||||
zero: false
|
||||
}
|
||||
};
|
||||
<% all_colors = @survey.result_criteria.map{|c| c["color"]}.select{|c| c.present?}.uniq %>
|
||||
var points_fillColor = "#ffffff";
|
||||
var need_split_data = false;
|
||||
<% if all_colors.count == 1 %>
|
||||
points_fillColor = "<%=all_colors[0]%>";
|
||||
<% end %>
|
||||
// options['legend']['container'] = $('.legend-container')[0];
|
||||
<% if @survey.need_assign_color %>
|
||||
options["series"]["lines"]["show"] = false;
|
||||
<% label_name = @user.member_name rescue "NA" %>
|
||||
var chart_data = <%= ([{"label"=> label_name, "data"=> all_data,
|
||||
"color"=> "#708fff",
|
||||
"lines"=> {
|
||||
"show"=> true,
|
||||
"lineWidth"=> 2,
|
||||
"steps"=> false ,
|
||||
"is_sort"=> true
|
||||
}}] + data.map{|color,d| tmp_color=(color.blank? ? "#ffffff" : color);{"label"=>label_name, "data"=>d, "color"=> (tmp_color == "#ffffff" ? "#708fff" : tmp_color), "points"=>{
|
||||
"show"=> true,
|
||||
"fillColor"=> tmp_color
|
||||
}}}).to_json.html_safe %>;
|
||||
<% else %>
|
||||
var chart_data = [{"label": "<%=@user.member_name rescue "NA" %>", "data": <%= data.to_json.html_safe %>,"points": {
|
||||
show: true,
|
||||
fillColor: points_fillColor
|
||||
}}];
|
||||
<% end %>
|
||||
};
|
||||
<% all_colors = @survey.result_criteria.map{|c| c["color"]}.select{|c| c.present?}.uniq %>
|
||||
var points_fillColor = "#ffffff";
|
||||
var need_split_data = false;
|
||||
<% if all_colors.count == 1 %>
|
||||
points_fillColor = "<%=all_colors[0]%>";
|
||||
<% end %>
|
||||
// options['legend']['container'] = $('.legend-container')[0];
|
||||
<% if @survey.need_assign_color %>
|
||||
options["series"]["lines"]["show"] = false;
|
||||
<% label_name = @user.member_name rescue "NA" %>
|
||||
var chart_data = <%= ([{"label"=> label_name, "data"=> all_data,
|
||||
"color"=> "#708fff",
|
||||
"lines"=> {
|
||||
"show"=> true,
|
||||
"lineWidth"=> 2,
|
||||
"steps"=> false ,
|
||||
"is_sort"=> true
|
||||
}}] + data.map{|color,d| tmp_color=(color.blank? ? "#ffffff" : color);{"label"=>label_name, "data"=>d, "color"=> (tmp_color == "#ffffff" ? "#708fff" : tmp_color), "points"=>{
|
||||
"show"=> true,
|
||||
"fillColor"=> tmp_color
|
||||
}}}).to_json.html_safe %>;
|
||||
<% else %>
|
||||
var chart_data = [{"label": "<%=@user.member_name rescue "NA" %>", "data": <%= data.to_json.html_safe %>,"points": {
|
||||
show: true,
|
||||
fillColor: points_fillColor
|
||||
}}];
|
||||
<% end %>
|
||||
$(document).ready(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#<%=year%>_block .flot-placeholder").height(chart_height).plot(chart_data,options);
|
||||
})
|
||||
$(window).resize(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#<%=year%>_block .flot-placeholder").height(chart_height).plot(chart_data,options);
|
||||
})
|
||||
})();
|
||||
</script>
|
||||
<% end %>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#resultchart-container").height(chart_height).plot(chart_data,options);
|
||||
$(".flot-placeholder").bind("plothover", function (event, pos, item) {
|
||||
if (!pos.x || !pos.y) {
|
||||
return;
|
||||
}
|
||||
if (!item) {
|
||||
$("#tooltip").hide();
|
||||
$(this).siblings(".tooltip").hide();
|
||||
}
|
||||
});
|
||||
$(".flot-placeholder").bind("plotclick", function (event, pos, item) {
|
||||
if (!pos.x || !pos.y) {
|
||||
if (!pos.x || !pos.y || item == null) {
|
||||
return;
|
||||
}
|
||||
var tooltip = $(this).siblings(".tooltip");
|
||||
console.log(tooltip)
|
||||
var x = item.datapoint[0].toFixed(2),
|
||||
y = item.datapoint[1].toFixed(0);
|
||||
var date = new moment(Math.round(x));
|
||||
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 content_width = tp.length*8.2
|
||||
if (content_width+item.pageX+5>$(window).width()){
|
||||
|
@ -235,14 +260,10 @@
|
|||
left = item.pageX - content_width / 2;
|
||||
}
|
||||
var offset = $(this).parents(".flot_wrapper").eq(0).offset();
|
||||
$("#tooltip").css({top: item.pageY+5-offset.top, left: left-offset.left})
|
||||
tooltip.css({top: item.pageY+5-offset.top, left: left-offset.left})
|
||||
.fadeIn(200);
|
||||
});
|
||||
})
|
||||
$(window).resize(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#resultchart-container").height(chart_height).plot(chart_data,options);
|
||||
})
|
||||
</script>
|
||||
<% else %>
|
||||
<table class="table main-list">
|
||||
|
@ -254,6 +275,8 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @is_answer_list = true if !@answer_repeat%>
|
||||
<% answers_nil = @survey_answers.nil? %>
|
||||
<% (@survey_answer_groups || @survey_answers).each do |sa| %>
|
||||
<tr>
|
||||
<% user = sa.user.nil? ? nil : (User.find(sa.user) rescue nil) %>
|
||||
|
@ -268,6 +291,7 @@
|
|||
<a class="btn btn-primary" href="/admin/surveys/<%= sa.id.to_s %>/answer_list"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)</a>
|
||||
<button class="btn btn-primary export-xls" data-href="/admin/surveys/<%= sa.id.to_s %>/export_answers"><%= t("survey.export") %></button>
|
||||
<% else %>
|
||||
<% sa = sa.survey_answers.last if answers_nil %>
|
||||
<% if @survey.result_type == QuestionnaireSurvey::ResultCriteria %>
|
||||
<% tmp_msgs = []
|
||||
answer_model_attrs = sa.attributes
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
border-bottom: 2px solid;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
input.color_input{
|
||||
height: 2em;
|
||||
}
|
||||
</style>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
|
@ -115,7 +118,8 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<div class="criteria" style="margin-left:0px;display:block;margin-bottom:50px;">
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> Color : <input type="color" name="questionnaire_survey[result_criteria][<%= idx %>][color]" value="<%=criteria["color"].blank? ? "#ffffff" : criteria["color"] %>"></label>
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> Color : <input class="color_input" type="color" name="questionnaire_survey[result_criteria][<%= idx %>][color]" value="<%=criteria["color"].blank? ? "#ffffff" : criteria["color"] %>"></label>
|
||||
<button type="button" class="btn btn-primary btn-small recover_to_default"><%=I18n.t("survey.recover_to_default")%></button>
|
||||
</div>
|
||||
<div class="criteria">
|
||||
<label for="" class="radio inline">
|
||||
|
@ -151,7 +155,7 @@
|
|||
<% [0,1].each do |i| %>
|
||||
html += '<option value="<%=i%>"><%=t("survey.type.#{i}")%></option>'
|
||||
<% end %>
|
||||
html += '</select></label></div><div data-critera-number="criteria_{index}" class="criteria" style="width:800px;"><label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][{index}][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][{index}][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><a href="" style="margin-left:5px;" class="btn btn-primary delete-critera"><i class="icon icon-trash"></i></a><span class="radio inline">Save to add text</span></div><div class="criteria" style="margin-left:0px;display:block;"><label style="padding-left:0px;" for="" class="radio inline"> Color : <input type="color" name="questionnaire_survey[result_criteria][{index}][color]" value="#ffffff"></label></div></div>';
|
||||
html += '</select></label></div><div data-critera-number="criteria_{index}" class="criteria" style="width:800px;"><label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][{index}][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][{index}][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><a href="" style="margin-left:5px;" class="btn btn-primary delete-critera"><i class="icon icon-trash"></i></a><span class="radio inline">Save to add text</span></div><div class="criteria" style="margin-left:0px;display:block;"><label style="padding-left:0px;" for="" class="radio inline"> Color : <input class="color_input" type="color" name="questionnaire_survey[result_criteria][{index}][color]" value="#ffffff"></label><button type="button" class="btn btn-primary btn-small recover_to_default"><%=I18n.t("survey.recover_to_default")%></button></div></div>';
|
||||
|
||||
$("#add-criteria").on("click",function(){
|
||||
var newhtml = html.replace(/{index}/g,index);
|
||||
|
@ -160,7 +164,9 @@
|
|||
$("#criterias").append(newhtml);
|
||||
return false;
|
||||
})
|
||||
|
||||
$(document).on("click", ".recover_to_default", function(){
|
||||
$(this).siblings("label").find(".color_input").val("#ffffff");
|
||||
})
|
||||
$(document).on("click", ".delete-critera" ,function(){
|
||||
$(this).parent().parent().remove();
|
||||
return false;
|
||||
|
|
|
@ -10,6 +10,8 @@ wb.add_worksheet(name: title) do |sheet|
|
|||
row << survey.consent_contents
|
||||
row2 << ""
|
||||
end
|
||||
row << I18n.t("survey.type.0")
|
||||
row2 << ""
|
||||
survey_questions.each_with_index do |question, i|
|
||||
qnum = question.title.match(/^\d+./).nil? ? "#{i+1}. " : ""
|
||||
start_col = row2.count
|
||||
|
|
|
@ -37,9 +37,10 @@
|
|||
</div>
|
||||
<% end %>
|
||||
<% if type == "result_chart" %>
|
||||
<% @survey_answers.options = {} %>
|
||||
<div style="clear: both;"></div>
|
||||
<style type="text/css">
|
||||
#tooltip{
|
||||
.tooltip{
|
||||
position: absolute;
|
||||
background: #ffffff;
|
||||
z-index: 1;
|
||||
|
@ -47,13 +48,13 @@
|
|||
padding: 2px;
|
||||
display: none;
|
||||
font-weight: bold;
|
||||
font-size: 1em;
|
||||
opacity: 1;
|
||||
}
|
||||
.flot_wrapper{
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
<div class="flot_wrapper">
|
||||
<span id="tooltip"></span>
|
||||
<div class="legend-container"></div>
|
||||
<div id="resultchart-container" class="flot-placeholder"></div>
|
||||
</div>
|
||||
<%= javascript_include_tag "survey/jquery.colorhelpers.js" %>
|
||||
<%= javascript_include_tag "survey/jquery.canvaswrapper.js" %>
|
||||
<%= javascript_include_tag "survey/jquery.flot_3.0.js" %>
|
||||
|
@ -71,144 +72,169 @@
|
|||
.axisLabels {
|
||||
font-weight: bold;
|
||||
}
|
||||
.flot_wrapper{
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
<% if @survey.need_assign_color %>
|
||||
<% 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 max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
||||
<% all_data = data.values.flatten(1) %>
|
||||
<% y_data = all_data.map{|v| v[1]} %>
|
||||
var min_y = <%= y_data.min.to_i %>;
|
||||
var max_y = <%= y_data.max.to_i %>;
|
||||
<% else %>
|
||||
<% 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 max_time = <%= data[-1][0] rescue 0 %>;
|
||||
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
||||
var max_y = <%= data.map{|a| a[1]}.max.to_i %>;
|
||||
<% end %>
|
||||
var xaxes = [{
|
||||
mode: "time",
|
||||
axisLabelUseCanvas: false,
|
||||
timeformat: "%Y/%m/%d",
|
||||
timezone: "browser",
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
// min: min_time,
|
||||
// max: max_time,
|
||||
axisLabel: "<%=t("survey.taken_date")%>",
|
||||
position: "bottom",
|
||||
}];
|
||||
var yaxes = [{
|
||||
use_min_force: false, //modify at jquery_flot_3.0.js
|
||||
axisLabelUseCanvas: false,
|
||||
showTickLabels: 'all',
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
// min: min_y,
|
||||
// max: max_y,
|
||||
axisLabel: "<%=t("survey.result_score")%>",
|
||||
position: "left",
|
||||
axisLabelFontSizePixels: 12,
|
||||
axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
|
||||
axisLabelPadding: 5
|
||||
}];
|
||||
var options = {
|
||||
series: {
|
||||
lines: {
|
||||
show: true,
|
||||
lineWidth: 2,
|
||||
steps: false , //畫斜線
|
||||
is_sort: true
|
||||
<% @survey_answers = @survey_answers.order_by(:created_at=>1) %>
|
||||
<% last_year = @survey_answers.last.created_at.year %>
|
||||
<% first_year = @survey_answers.first.created_at.year %>
|
||||
<% all_years = (first_year..last_year).to_a.reverse %>
|
||||
<% all_years.each do |year|%>
|
||||
<% start_d = DateTime.parse("#{year}/1/1 #{Time.zone}") %>
|
||||
<% end_d = start_d.end_of_year %>
|
||||
<% survey_answers_sep = @survey_answers.where(:created_at.gte=>start_d).and(:created_at.lte=>end_d) %>
|
||||
<% next if survey_answers_sep.count == 0 %>
|
||||
<div class="flot_wrapper" id="<%=year%>_block">
|
||||
<h4 style="text-align: center;"><%= year %></h4>
|
||||
<span class="tooltip"></span>
|
||||
<div class="legend-container"></div>
|
||||
<div class="flot-placeholder"></div>
|
||||
</div>
|
||||
<script>
|
||||
(function(){
|
||||
<% if @survey.need_assign_color %>
|
||||
<% data = survey_answers_sep.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 max_time = <%= data.map{|k,d| d[-1][0] rescue 0}.max %>;
|
||||
<% all_data = data.values.flatten(1) %>
|
||||
<% y_data = all_data.map{|v| v[1]} %>
|
||||
var min_y = <%= y_data.min.to_i %>;
|
||||
var max_y = <%= y_data.max.to_i %>;
|
||||
<% else %>
|
||||
<% data = survey_answers_sep.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 max_time = <%= data[-1][0] rescue 0 %>;
|
||||
var min_y = <%= data.map{|a| a[1]}.min.to_i %>;
|
||||
var max_y = <%= data.map{|a| a[1]}.max.to_i %>;
|
||||
<% end %>
|
||||
var xaxes = [{
|
||||
mode: "time",
|
||||
axisLabelUseCanvas: false,
|
||||
timeformat: "%Y/%m/%d",
|
||||
timezone: "browser",
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
points: {
|
||||
radius: 5,
|
||||
show: true,
|
||||
fillColor: '#ffffff'
|
||||
// min: min_time,
|
||||
// max: max_time,
|
||||
axisLabel: "<%=t("survey.taken_date")%>",
|
||||
position: "bottom",
|
||||
}];
|
||||
var yaxes = [{
|
||||
use_min_force: false, //modify at jquery_flot_3.0.js
|
||||
axisLabelUseCanvas: false,
|
||||
showTickLabels: 'all',
|
||||
font: {
|
||||
size: '16',
|
||||
color: 'black'
|
||||
},
|
||||
downsample: {
|
||||
threshold: 0
|
||||
// min: min_y,
|
||||
// max: max_y,
|
||||
axisLabel: "<%=t("survey.result_score")%>",
|
||||
position: "left",
|
||||
axisLabelFontSizePixels: 12,
|
||||
axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
|
||||
axisLabelPadding: 5
|
||||
}];
|
||||
var options = {
|
||||
series: {
|
||||
lines: {
|
||||
show: true,
|
||||
lineWidth: 2,
|
||||
steps: false , //畫斜線
|
||||
is_sort: true
|
||||
},
|
||||
points: {
|
||||
radius: 5,
|
||||
show: true,
|
||||
fillColor: '#ffffff'
|
||||
},
|
||||
downsample: {
|
||||
threshold: 0
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
hoverable: true,
|
||||
clickable: true,
|
||||
show: true
|
||||
},
|
||||
xaxes: xaxes,
|
||||
yaxes: yaxes,
|
||||
zoom: {
|
||||
interactive: true
|
||||
},
|
||||
pan: {
|
||||
interactive: true,
|
||||
enableTouch: true
|
||||
},
|
||||
colors: ["#708fff"], //["#708fff","#ffc107","#96478c","#1e7e34"],
|
||||
polycolors: ["#3f66f4"],//["#3f66f4","#ffc107","#dc3545","#1e7e34"],
|
||||
// legend: {
|
||||
// show: true,
|
||||
// noColumns: 1
|
||||
// },
|
||||
bar: {
|
||||
zero: false
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
hoverable: true,
|
||||
clickable: true,
|
||||
show: true
|
||||
},
|
||||
xaxes: xaxes,
|
||||
yaxes: yaxes,
|
||||
zoom: {
|
||||
interactive: true
|
||||
},
|
||||
pan: {
|
||||
interactive: true,
|
||||
enableTouch: true
|
||||
},
|
||||
colors: ["#708fff"], //["#708fff","#ffc107","#96478c","#1e7e34"],
|
||||
polycolors: ["#3f66f4"],//["#3f66f4","#ffc107","#dc3545","#1e7e34"],
|
||||
// legend: {
|
||||
// show: true,
|
||||
// noColumns: 1
|
||||
// },
|
||||
bar: {
|
||||
zero: false
|
||||
}
|
||||
};
|
||||
<% all_colors = @survey.result_criteria.map{|c| c["color"]}.select{|c| c.present?}.uniq %>
|
||||
var points_fillColor = "#ffffff";
|
||||
var need_split_data = false;
|
||||
<% if all_colors.count == 1 %>
|
||||
points_fillColor = "<%=all_colors[0]%>";
|
||||
<% end %>
|
||||
// options['legend']['container'] = $('.legend-container')[0];
|
||||
<% if @survey.need_assign_color %>
|
||||
options["series"]["lines"]["show"] = false;
|
||||
<% label_name = @user.member_name rescue "NA" %>
|
||||
var chart_data = <%= ([{"label"=> label_name, "data"=> all_data,
|
||||
"color"=> "#708fff",
|
||||
"lines"=> {
|
||||
"show"=> true,
|
||||
"lineWidth"=> 2,
|
||||
"steps"=> false ,
|
||||
"is_sort"=> true
|
||||
}}] + data.map{|color,d| tmp_color=(color.blank? ? "#ffffff" : color);{"label"=>label_name, "data"=>d, "color"=> (tmp_color == "#ffffff" ? "#708fff" : tmp_color), "points"=>{
|
||||
"show"=> true,
|
||||
"fillColor"=> tmp_color
|
||||
}}}).to_json.html_safe %>;
|
||||
<% else %>
|
||||
var chart_data = [{"label": "<%=@user.member_name rescue "NA" %>", "data": <%= data.to_json.html_safe %>,"points": {
|
||||
show: true,
|
||||
fillColor: points_fillColor
|
||||
}}];
|
||||
<% end %>
|
||||
};
|
||||
<% all_colors = @survey.result_criteria.map{|c| c["color"]}.select{|c| c.present?}.uniq %>
|
||||
var points_fillColor = "#ffffff";
|
||||
var need_split_data = false;
|
||||
<% if all_colors.count == 1 %>
|
||||
points_fillColor = "<%=all_colors[0]%>";
|
||||
<% end %>
|
||||
// options['legend']['container'] = $('.legend-container')[0];
|
||||
<% if @survey.need_assign_color %>
|
||||
options["series"]["lines"]["show"] = false;
|
||||
<% label_name = @user.member_name rescue "NA" %>
|
||||
var chart_data = <%= ([{"label"=> label_name, "data"=> all_data,
|
||||
"color"=> "#708fff",
|
||||
"lines"=> {
|
||||
"show"=> true,
|
||||
"lineWidth"=> 2,
|
||||
"steps"=> false ,
|
||||
"is_sort"=> true
|
||||
}}] + data.map{|color,d| tmp_color=(color.blank? ? "#ffffff" : color);{"label"=>label_name, "data"=>d, "color"=> (tmp_color == "#ffffff" ? "#708fff" : tmp_color), "points"=>{
|
||||
"show"=> true,
|
||||
"fillColor"=> tmp_color
|
||||
}}}).to_json.html_safe %>;
|
||||
<% else %>
|
||||
var chart_data = [{"label": "<%=@user.member_name rescue "NA" %>", "data": <%= data.to_json.html_safe %>,"points": {
|
||||
show: true,
|
||||
fillColor: points_fillColor
|
||||
}}];
|
||||
<% end %>
|
||||
$(document).ready(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#<%=year%>_block .flot-placeholder").height(chart_height).plot(chart_data,options);
|
||||
})
|
||||
$(window).resize(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#<%=year%>_block .flot-placeholder").height(chart_height).plot(chart_data,options);
|
||||
})
|
||||
})();
|
||||
</script>
|
||||
<% end %>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#resultchart-container").height(chart_height).plot(chart_data,options);
|
||||
$(".flot-placeholder").bind("plothover", function (event, pos, item) {
|
||||
if (!pos.x || !pos.y) {
|
||||
return;
|
||||
}
|
||||
if (!item) {
|
||||
$("#tooltip").hide();
|
||||
$(this).siblings(".tooltip").hide();
|
||||
}
|
||||
});
|
||||
$(".flot-placeholder").bind("plotclick", function (event, pos, item) {
|
||||
if (!pos.x || !pos.y) {
|
||||
if (!pos.x || !pos.y || item == null) {
|
||||
return;
|
||||
}
|
||||
var tooltip = $(this).siblings(".tooltip");
|
||||
console.log(tooltip)
|
||||
var x = item.datapoint[0].toFixed(2),
|
||||
y = item.datapoint[1].toFixed(0);
|
||||
var date = new moment(Math.round(x));
|
||||
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 content_width = tp.length*8.2
|
||||
if (content_width+item.pageX+5>$(window).width()){
|
||||
|
@ -217,15 +243,10 @@
|
|||
left = item.pageX - content_width / 2;
|
||||
}
|
||||
var offset = $(this).parents(".flot_wrapper").eq(0).offset();
|
||||
|
||||
$("#tooltip").css({top: item.pageY+5-offset.top, left: left-offset.left})
|
||||
tooltip.css({top: item.pageY+5-offset.top, left: left-offset.left})
|
||||
.fadeIn(200);
|
||||
});
|
||||
})
|
||||
$(window).resize(function(){
|
||||
var chart_height = $(window).outerWidth(true)*0.2;
|
||||
$("#resultchart-container").height(chart_height).plot(chart_data,options);
|
||||
})
|
||||
</script>
|
||||
<% else %>
|
||||
<table class="table main-list">
|
||||
|
@ -237,6 +258,8 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @is_answer_list = true if !@answer_repeat%>
|
||||
<% answers_nil = @survey_answers.nil? %>
|
||||
<% (@survey_answer_groups || @survey_answers).each do |sa| %>
|
||||
<tr>
|
||||
<% user = sa.user.nil? ? nil : (User.find(sa.user) rescue nil) %>
|
||||
|
@ -251,6 +274,7 @@
|
|||
<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>
|
||||
<button class="btn btn-primary export-xls" data-href="/admin/surveys/<%= sa.id.to_s %>/export_answers" title="<%= t("survey.export") %>"><%= t("survey.export") %></button>
|
||||
<% else %>
|
||||
<% sa = sa.survey_answers.last if answers_nil %>
|
||||
<% if @survey.result_type == QuestionnaireSurvey::ResultCriteria %>
|
||||
<% tmp_msgs = []
|
||||
answer_model_attrs = sa.attributes
|
||||
|
|
|
@ -92,9 +92,10 @@
|
|||
</div>
|
||||
<ol class="o-question-list">
|
||||
<% if @survey.enable_consent_feature %>
|
||||
<div class="survey_consent_contents o-question-title">
|
||||
<label for="survey_consent_used"><%= f.check_box :consent_used , {:id=>"survey_consent_used", :title=>t('survey.agree')} %><span style="margin-left: 0.2em;"><%= @survey.consent_contents.to_s.html_safe %></span></label>
|
||||
</div>
|
||||
<li class="survey_consent_contents question-item ">
|
||||
<span class="required-star">(*)</span>
|
||||
<label for="survey_consent_used" class="o-question-title"><%= f.check_box :consent_used , {:id=>"survey_consent_used", :title=>t('survey.agree'), :required=>"required"} %><span style="margin-left: 0.2em;"><%= @survey.consent_contents.to_s.html_safe %></span></label>
|
||||
</li>
|
||||
<% end %>
|
||||
<% @questions.each_with_index do |question, i| %>
|
||||
<% header_count = i + 1 %>
|
||||
|
|
|
@ -2,6 +2,7 @@ en:
|
|||
module_name:
|
||||
survey: Survey
|
||||
survey:
|
||||
recover_to_default: Recover to default
|
||||
'true': 'Yes'
|
||||
'false': 'No'
|
||||
consent_to_be_used_for_research: "Consent answer to be used for research"
|
||||
|
|
|
@ -4,6 +4,7 @@ zh_tw:
|
|||
survey: 問卷調查
|
||||
|
||||
survey:
|
||||
recover_to_default: 恢復成預設
|
||||
'true': 已勾選
|
||||
'false': 未勾選
|
||||
consent_to_be_used_for_research: "同意填答結果被用於研究"
|
||||
|
|
Loading…
Reference in New Issue