268 lines
8.8 KiB
Plaintext
268 lines
8.8 KiB
Plaintext
<%
|
|
data = action_data
|
|
@survey = data["survey"]
|
|
@user = data["user"]
|
|
@survey_answers = data["survey_answers"]
|
|
@table_fields = data["table_fields"]
|
|
@is_answer_list = data["is_answer_list"]
|
|
%>
|
|
<% if @user.nil? %>
|
|
<h3><a id="display_login_button" href="#" title="<%=t("survey.please_login_first")%>"><%=t("survey.please_login_first")%></a></h3>
|
|
<script>
|
|
$("#display_login_button").click(function(){
|
|
$('#loginbutton').click();
|
|
})
|
|
</script>
|
|
<% else %>
|
|
<style type="text/css">
|
|
#survey_answer_search label{
|
|
float: left;
|
|
margin-right: 0.5em;
|
|
line-height: 2;
|
|
}
|
|
#survey_answer_search input{
|
|
float: left;
|
|
line-height: 2;
|
|
}
|
|
</style>
|
|
<h3><%= @survey.title %></h3>
|
|
<div>
|
|
<h4><%=t('survey.taken_by')%>: <%=@user.member_name%></h4>
|
|
</div>
|
|
<% if @is_answer_list %>
|
|
<% type = 'result_chart' if params[:type] == 'result_chart' %>
|
|
<div class="pull-right">
|
|
<a href="?method=my_record&type=" class="btn <%= 'active' if type != 'result_chart' %>"><%=t("survey.table")%></a>
|
|
<a href="?method=my_record&type=result_chart" class="btn <%= 'active' if type == 'result_chart' %>"><%=t("survey.result_chart")%></a>
|
|
</div>
|
|
<% end %>
|
|
<% if type == "result_chart" %>
|
|
<div style="clear: both;"></div>
|
|
<style type="text/css">
|
|
#tooltip{
|
|
position: absolute;
|
|
background: #ffffff;
|
|
z-index: 1;
|
|
border-radius: 10px;
|
|
padding: 2px;
|
|
display: none;
|
|
font-weight: bold;
|
|
}
|
|
</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" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.time.min.js" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.uiConstants.js" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.saturated.js" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.browser.js" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.drawSeries.js" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.axislabels.js" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.hover.js" %>
|
|
<%= javascript_include_tag "survey/jquery.flot.animator.min.js" %>
|
|
<!-- <%= javascript_include_tag "survey/jquery.flot.legend.js" %> -->
|
|
<%= javascript_include_tag "survey/moment.min.js" %>
|
|
<style type="text/css">
|
|
.axisLabels {
|
|
font-weight: bold;
|
|
}
|
|
.flot_wrapper{
|
|
position: relative;
|
|
}
|
|
</style>
|
|
<script>
|
|
<% data = @survey_answers.order_by(:updated_at=>1).map{|sa| [sa.updated_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 %>;
|
|
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
|
|
},
|
|
points: {
|
|
radius: 3,
|
|
show: false
|
|
},
|
|
downsample: {
|
|
threshold: 0
|
|
}
|
|
},
|
|
grid: {
|
|
hoverable: true,
|
|
clickable: true,
|
|
show: true
|
|
},
|
|
xaxes: xaxes,
|
|
yaxes: yaxes,
|
|
zoom: {
|
|
interactive: true
|
|
},
|
|
pan: {
|
|
interactive: true,
|
|
enableTouch: true
|
|
},
|
|
colors: ["#708fff","#ffc107","#96478c","#1e7e34"],
|
|
polycolors: ["#3f66f4","#ffc107","#dc3545","#1e7e34"],
|
|
// legend: {
|
|
// show: true,
|
|
// noColumns: 1
|
|
// },
|
|
bar: {
|
|
zero: false
|
|
}
|
|
};
|
|
// options['legend']['container'] = $('.legend-container')[0];
|
|
var chart_data = [{"label": "<%=@user.member_name rescue "NA" %>", "data": <%= data.to_json.html_safe %>}];
|
|
$(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();
|
|
}
|
|
});
|
|
$(".flot-placeholder").bind("plotclick", function (event, pos, item) {
|
|
if (!pos.x || !pos.y) {
|
|
return;
|
|
}
|
|
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);
|
|
var left = 0;
|
|
var content_width = tp.length*8.2
|
|
if (content_width+item.pageX+5>$(window).width()){
|
|
left = $(window).width()-content_width;
|
|
}else{
|
|
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})
|
|
.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">
|
|
<thead>
|
|
<tr class="sort-header">
|
|
<% @table_fields.each do |f| %>
|
|
<%= thead(f) %>
|
|
<% end %>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<% (@survey_answer_groups || @survey_answers).each do |sa| %>
|
|
<tr>
|
|
<% user = sa.user.nil? ? nil : (User.find(sa.user) rescue nil) %>
|
|
<% if !user.nil? %>
|
|
<td><%= user.member_name rescue user.name %></td>
|
|
<% else %>
|
|
<td>NA</td>
|
|
<% end %>
|
|
<td><%= (@is_answer_list ? sa.updated_at : sa.last_modified).strftime("%h %d, %Y - %H:%M") rescue nil %></td>
|
|
<td>
|
|
<% 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>
|
|
<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 %>
|
|
<% if @survey.result_type == QuestionnaireSurvey::ResultCriteria %>
|
|
<% tmp_msgs = []
|
|
answer_model_attrs = sa.attributes
|
|
weight_relations = @survey.survey_questions.map{|q| [q.id.to_s,(q.weight.nil? ? 1 : q.weight)]}.to_h
|
|
types = [] %>
|
|
<% @survey.result_criteria.each do |criteria| %>
|
|
<%
|
|
total_criteria_score = 0
|
|
total_weight = 0
|
|
((criteria["questions"][0].to_i - 1)..(criteria["questions"][1].to_i - 1)).each do |x|
|
|
total_criteria_score = (total_criteria_score + sa.individual_total[x].to_i) rescue 0
|
|
k = weight_relations.keys[x]
|
|
if k && answer_model_attrs.has_key?(k)
|
|
total_weight += weight_relations[k]
|
|
end
|
|
end
|
|
type = criteria["type"].to_i
|
|
%>
|
|
<% if type == 0 %>
|
|
<% if (criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(total_criteria_score) %>
|
|
<% tmp_msgs << criteria["msg"] %>
|
|
<% types << type %>
|
|
<% end %>
|
|
<% else %>
|
|
<% if (criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(total_criteria_score / total_weight) %>
|
|
<% tmp_msgs << criteria["msg"] %>
|
|
<% types << type %>
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
<% if types.include?(0) %>
|
|
<h4>Your total score is <%= sa.scored_points %> </h4>
|
|
<% end %>
|
|
<% if types.include?(1) %>
|
|
<h4>Your average score is <%= sa.get_avg_points %> </h4>
|
|
<% end %>
|
|
<% tmp_msgs.each do |msg| %>
|
|
<div><%=msg.html_safe%></div>
|
|
<% end %>
|
|
<% else %>
|
|
<a class="btn btn-primary" href="/admin/surveys/<%= @is_answer_list ? sa.id : sa.survey_answer_ids.last.to_s %>/answer_set" title="<%= t("survey.view_answers") %>"><%= t("survey.view_answers") %></a>
|
|
<% end %>
|
|
<% end %>
|
|
</td>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
<%= create_pagination((@survey_answer_groups || @survey_answers).total_pages).html_safe %>
|
|
<% end %>
|
|
<% end %> |