csv stats & required start

This commit is contained in:
iCross 2013-05-22 18:03:46 +08:00
parent 7ba0977e16
commit 443d1c4fbe
3 changed files with 37 additions and 3 deletions

View File

@ -27,6 +27,12 @@
margin: 0 0 0 40px;
padding: 16px 0;
border-top: solid 1px #eee;
position: relative;
}
.o-question-list > li .required-star {
position: absolute;
left: -42px;
padding-top: 4px;
}
.o-question-list > li:first-child {
border: 0;

View File

@ -87,14 +87,40 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
def export
@survey = ::Survey.find(params[:id])
@survey_questions = @survey.survey_questions.all
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
respond_to do |format|
format.csv do
csv = CSV.generate do |csv|
csv << @survey_questions.map(&:title)
@survey.survey_answers.each do |answer|
csv_stats = []
csv_stats = @survey_questions.map do |question|
case question.type
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select, ::SurveyQuestion::Check
question.survey_question_options.map do |option|
"#{option.name} : #{(@chart_data[question.id.to_s][option.name] || 0 rescue 0)}"
end
when ::SurveyQuestion::Radiogroup
question.survey_question_options.map do |option|
question.survey_question_radiogroups.map do |group|
"#{option.name} - #{group.name} : #{(@chart_data[question.id.to_s][option.name][group.name] || 0 rescue 0)}"
end
end.flatten
else
' '
end
end
max_length = csv_stats.map(&:length).max
csv_stats.map do |l|
while l.length < max_length
l.push ' '
end
l
end.transpose.each do |l|
csv << l
end
@survey_answers.each do |answer|
row = []
@survey_questions.each do |question|
if question.type == ::SurveyQuestion::Radiogroup

View File

@ -9,7 +9,9 @@
<% @questions.each_with_index do |question, i| %>
<li class="question-item question-<%= question.id.to_s %> hide" data-index="<%= i %>" data-type="<%= question.type%>" data-custom="<%= question.custom_option.to_s %>">
<% label = question.title %>
<% label += ' (*)' if question.is_required %>
<% if question.is_required %>
<span class="required-star">(*)</span>
<% end %>
<%= f.label question.id, label, :class => "o-question-title" %>
<div class="o-question-description">
<%= question.description %>