bug fix and add feature
This commit is contained in:
parent
515185d87c
commit
b659c7021d
|
@ -114,11 +114,6 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
|||
end
|
||||
end
|
||||
|
||||
def chart
|
||||
@survey = ::Survey.find(params[:id])
|
||||
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
|
||||
end
|
||||
|
||||
def set_answers
|
||||
@survey = ::Survey.find(params[:id])
|
||||
end
|
||||
|
|
|
@ -85,6 +85,7 @@ class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController
|
|||
def result
|
||||
redirect_standalone result_panel_survey_front_end_survey_path(params[:id], :standalone => 'true') do
|
||||
@survey = ::Survey.find params[:id]
|
||||
@survey.result_type = ::Survey::ResultChart if params[:force_chart]
|
||||
case @survey.result_type
|
||||
when ::Survey::ResultChart
|
||||
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
|
||||
|
|
|
@ -75,6 +75,17 @@ class Survey
|
|||
end
|
||||
end
|
||||
end
|
||||
when ::SurveyQuestion::Radiogroup
|
||||
chart_data[qid] = {}
|
||||
answers = survey_answers.each do |answer|
|
||||
if answer[qid]
|
||||
answer[qid].each do |option, group|
|
||||
chart_data[qid][option] ||= {}
|
||||
chart_data[qid][option][group] ||= 0
|
||||
chart_data[qid][option][group] += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<li><%= link_to t('survey.set_answers'), set_answers_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
|
||||
<li><%= link_to t('survey.answers_list'), panel_survey_back_end_survey_answers_path(survey, :page => params[:page]) %></li>
|
||||
<li><%= link_to t('survey.export_csv'), export_panel_survey_back_end_survey_path(survey, :format => :csv), :target => '_blank' %></li>
|
||||
<li><%= link_to t('survey.chart'), chart_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
|
||||
<li><%= link_to t('survey.chart'), result_panel_survey_front_end_survey_path(survey, :force_chart => true, :standalone => true), :target => '_blank' %></li>
|
||||
<li><%= link_to t(:delete_), panel_survey_back_end_survey_path(survey), :confirm => t('sure?'), :method => :delete, :remote => true %></li>
|
||||
<% end -%>
|
||||
</ul>
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<h1><%= @survey.title %> <%= t('survey.chart') %></h1>
|
||||
|
||||
<% @survey_questions.each do |question| %>
|
||||
|
||||
<h3><%= question.title %></h3>
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Radio, ::SurveyQuestion::Check, ::SurveyQuestion::Select %>
|
||||
<div id="question_chart_<%= question.id.to_s %>" style="width: 600px; height: 300px;"></div>
|
||||
<% else %>
|
||||
<p><%= t('survey_question.have_not_chart') %></p>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
<div class="form-actions form-fixed">
|
||||
<%= link_to t('back'), get_go_back, :class=>"btn" %>
|
||||
</div>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
<script type="text/javascript">
|
||||
google.load("visualization", "1", {packages:["corechart"]});
|
||||
google.setOnLoadCallback(function(){
|
||||
<% @survey_questions.each do |question| %>
|
||||
<% qid = question.id.to_s %>
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Radio, ::SurveyQuestion::Check, ::SurveyQuestion::Select %>
|
||||
var data_<%= qid %> = google.visualization.arrayToDataTable([
|
||||
['<%= t("survey_question.option") %>', ''],
|
||||
<% @chart_data[qid].each do |option, count| %>
|
||||
['<%= option %>', <%= count %>],
|
||||
<% end %>
|
||||
]);
|
||||
var chart_<%= qid %> = new google.visualization.PieChart(document.getElementById('question_chart_<%= qid %>'));
|
||||
chart_<%= qid %>.draw(data_<%= qid %>, {title: '<%= question.title %>'});
|
||||
<% end %>
|
||||
<% end %>
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
|
@ -7,9 +7,10 @@
|
|||
<% qid = question.id %>
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Check %>
|
||||
<%= answer[qid].join(', ') %>
|
||||
<%= ( answer[qid] || [] ).join(', ') %>
|
||||
<% when ::SurveyQuestion::Radiogroup %>
|
||||
<%= answer[qid].map{|key, value| key + ': ' + value}.join('; ') unless answer[qid].blank? %>
|
||||
<% options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, o.name ] }] %>
|
||||
<%= ( answer[qid] || {} ).map{|key, value| ( options[key] || key ) + ': ' + value}.join('; ') unless answer[qid].blank? %>
|
||||
<% else %>
|
||||
<%= answer[qid] %>
|
||||
<% end %>
|
||||
|
|
|
@ -2,16 +2,32 @@
|
|||
<% when ::Survey::ResultChart %>
|
||||
|
||||
<h1><%= @survey.title %> <%= t('survey.chart') %></h1>
|
||||
<div>
|
||||
<section>
|
||||
<div class="o-question">
|
||||
<div class="o-question-description">
|
||||
<%= t 'survey.results_count' %>: <%= @survey_questions.count %>
|
||||
</div>
|
||||
<ol class="o-question-list">
|
||||
<% @survey_questions.each do |question| %>
|
||||
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Radio, ::SurveyQuestion::Check, ::SurveyQuestion::Select %>
|
||||
<li>
|
||||
<div id="question_chart_<%= question.id.to_s %>" style="width: 600px; height: 300px;"></div>
|
||||
</li>
|
||||
<% when ::SurveyQuestion::Radiogroup %>
|
||||
<% question.survey_question_options.each do |option| %>
|
||||
<li>
|
||||
<div id="question_chart_<%= question.id.to_s %>_<%= option.id.to_s %>" style="width: 600px; height: 300px;"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</ol>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
<script type="text/javascript">
|
||||
|
@ -30,6 +46,18 @@
|
|||
]);
|
||||
var chart_<%= qid %> = new google.visualization.PieChart(document.getElementById('question_chart_<%= qid %>'));
|
||||
chart_<%= qid %>.draw(data_<%= qid %>, {title: '<%= question.title %>'});
|
||||
<% when ::SurveyQuestion::Radiogroup %>
|
||||
<% options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, o.name ] }] %>
|
||||
<% @chart_data[qid].each do |option, groups| %>
|
||||
var data_<%= qid %>_<%= option %> = google.visualization.arrayToDataTable([
|
||||
['<%= t("survey_question.option") %>', ''],
|
||||
<% groups.each do |group, count| %>
|
||||
['<%= group %>', <%= count %>],
|
||||
<% end %>
|
||||
]);
|
||||
var chart_<%= qid %>_<%= option %> = new google.visualization.PieChart(document.getElementById('question_chart_<%= qid %>_<%= option %>'));
|
||||
chart_<%= qid %>_<%= option %>.draw(data_<%= qid %>_<%= option %>, {title: '<%= question.title %> - <%= options[option] %>'});
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ zh_tw:
|
|||
start_deadline: 開始/結束時間
|
||||
no_postdate: 沒有開始時間
|
||||
no_deadline: 沒有結束時間
|
||||
results_count: 回覆數
|
||||
results_count: 填寫人數
|
||||
update_user: 最後更新者
|
||||
question: 問題
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ Rails.application.routes.draw do
|
|||
end
|
||||
member do
|
||||
get 'export'
|
||||
get 'chart'
|
||||
get 'set_answers'
|
||||
get 'jump'
|
||||
get 'duplicate_it'
|
||||
|
|
Loading…
Reference in New Issue