diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 221c482c7..1e33e16ba 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -85,10 +85,22 @@ class PollController < ApplicationController end def statistics_result + @poll = Poll.find(params[:id]) + poll_questions = @poll.poll_questions + @poll_questions = paginateHelper poll_questions, 5 respond_to do |format| format.html{render :layout => 'base_courses'} end end + + def get_poll_totalcount poll_question + @total_questions_count = poll_question.poll_votes.count + end + + def get_poll_everycount poll_answer + @every_answer_count = poll_answer.poll_votes.count + end + #添加单选题 def create_poll_question @@ -120,8 +132,7 @@ class PollController < ApplicationController #修改单选题 def update_poll_question @poll_question = PollQuestion.find params[:poll_question] - @poll = @poll_question.poll - + #@poll = @poll_question.poll @poll_question.is_necessary = params[:is_necessary]=="true" ? 1 : 0 @poll_question.question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] ################处理选项 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5d43a4e20..5ff9a3f17 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -116,8 +116,8 @@ class ProjectsController < ApplicationController joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id").joins("LEFT JOIN #{ProjectScore.table_name} ON #{Project.table_name}.id = #{ProjectScore.table_name}.project_id"). where("#{Project.table_name}.project_type = ? ", Project::ProjectType_project) - @project_count = @projects_all.count - @project_pages = Paginator.new @project_count, per_page_option, params['page'] + @poll_questions_count = @projects_all.count + @poll_questions_pages = Paginator.new @project_count, per_page_option, params['page'] #gcm activity count diff --git a/app/helpers/poll_helper.rb b/app/helpers/poll_helper.rb index 7816d8e37..1a8fabae3 100644 --- a/app/helpers/poll_helper.rb +++ b/app/helpers/poll_helper.rb @@ -27,7 +27,7 @@ module PollHelper false end end - + #获取文本题答案 def get_anwser_vote_text(question_id,user_id) pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id) @@ -47,4 +47,20 @@ module PollHelper true end end + + #统计答题百分比 + def statistics_result_percentage(e, t) + return e*100/t + end + + def options_show p + case p + when 1 + "单选题" + when 2 + "多选题" + else + "问答题" + end + end end \ No newline at end of file diff --git a/app/views/poll/_choice_show.html.erb b/app/views/poll/_choice_show.html.erb new file mode 100644 index 000000000..16971d5ad --- /dev/null +++ b/app/views/poll/_choice_show.html.erb @@ -0,0 +1,28 @@ +
+ + + + + + + + <% poll_question.poll_answers.each do |poll_answer| %> + + + + + + <% end %> + + + + + + +
<%= l(:label_poll_options) %> <%= l(:label_poll_subtotal) %> <%= l(:label_poll_proportion) %>
<%= poll_answer.answer_text %> <%= poll_answer.poll_votes.count %> +
+ +
+ <%= statistics_result_percentage(poll_answer.poll_votes.count, @poll.users.count) %>%
<%= l(:label_poll_valid_commit) %> <%= poll_question.poll_votes.count %> 
+
+ diff --git a/app/views/poll/_edit_MCQ.html.erb b/app/views/poll/_edit_MCQ.html.erb index cf64e7f3e..f34319569 100644 --- a/app/views/poll/_edit_MCQ.html.erb +++ b/app/views/poll/_edit_MCQ.html.erb @@ -1,33 +1,28 @@ -
+<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
- - - - + + + /> +
    -
  • - - - - -
  • -
    -
  • - - - - -
  • -
    + <% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %> +
  • + + + + +
  • +
    + <% end%>
-
-
\ No newline at end of file + +<% end%> \ No newline at end of file diff --git a/app/views/poll/_edit_mulit.html.erb b/app/views/poll/_edit_mulit.html.erb index c4a9e0e0f..684a285e3 100644 --- a/app/views/poll/_edit_mulit.html.erb +++ b/app/views/poll/_edit_mulit.html.erb @@ -1,18 +1,21 @@ +<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
- - + + + />
- - , - + + +
-
\ No newline at end of file + +<% end%> \ No newline at end of file diff --git a/app/views/poll/_edit_single.html.erb b/app/views/poll/_edit_single.html.erb index 4e98babe4..b8157ee6c 100644 --- a/app/views/poll/_edit_single.html.erb +++ b/app/views/poll/_edit_single.html.erb @@ -1,13 +1,17 @@ +<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
- - + + + />
-
\ No newline at end of file + +<% end%> \ No newline at end of file diff --git a/app/views/poll/_new_MC.html.erb b/app/views/poll/_new_MC.html.erb index 013bf0ed0..5ff70e9eb 100644 --- a/app/views/poll/_new_MC.html.erb +++ b/app/views/poll/_new_MC.html.erb @@ -1,6 +1,5 @@ <%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> -
- +
@@ -35,11 +34,10 @@
-
<% end%> \ No newline at end of file diff --git a/app/views/poll/_new_MCQ.html.erb b/app/views/poll/_new_MCQ.html.erb index 6739c233e..d94964bbf 100644 --- a/app/views/poll/_new_MCQ.html.erb +++ b/app/views/poll/_new_MCQ.html.erb @@ -1,33 +1,41 @@ -
+<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>
- + + - - + +
    -
  • - - - - +
  • + + + +
  • -
    -
  • - - - - +
    +
  • + + + +
  • -
    +
    +
  • + + + + +
  • +
-
\ No newline at end of file +<% end%> \ No newline at end of file diff --git a/app/views/poll/_new_mulit.html.erb b/app/views/poll/_new_mulit.html.erb index 6c3528473..e034e54af 100644 --- a/app/views/poll/_new_mulit.html.erb +++ b/app/views/poll/_new_mulit.html.erb @@ -1,18 +1,21 @@ +<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>
- - - + + + +
- - , - + + +
-
\ No newline at end of file + +<% end%> \ No newline at end of file diff --git a/app/views/poll/_new_single.html.erb b/app/views/poll/_new_single.html.erb index b7d5a9725..ec06933a8 100644 --- a/app/views/poll/_new_single.html.erb +++ b/app/views/poll/_new_single.html.erb @@ -1,13 +1,16 @@ -
-
- - - - -
- -
-
\ No newline at end of file +<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> +
+
+ + + + + +
+ +
+
+<% end%> \ No newline at end of file diff --git a/app/views/poll/_poll_content.html.erb b/app/views/poll/_poll_content.html.erb index 6c2e61215..40c9a6181 100644 --- a/app/views/poll/_poll_content.html.erb +++ b/app/views/poll/_poll_content.html.erb @@ -1,10 +1,26 @@ <% poll.poll_questions.each do |poll_question|%>
- <%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %> + <% if poll_question.question_type == 1%> + <%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %> + <% elsif poll_question.question_type == 2%> + <%= render :partial => 'show_MCQ', :locals => {:poll_question => poll_question} %> + <% elsif poll_question.question_type == 3%> + <%= render :partial => 'show_single', :locals => {:poll_question => poll_question} %> + <% elsif poll_question.question_type == 4%> + <%= render :partial => 'show_mulit', :locals => {:poll_question => poll_question} %> + <% end%>
<% end %> \ No newline at end of file diff --git a/app/views/poll/_poll_form.html.erb b/app/views/poll/_poll_form.html.erb index 598ef1207..1b30c973d 100644 --- a/app/views/poll/_poll_form.html.erb +++ b/app/views/poll/_poll_form.html.erb @@ -60,6 +60,19 @@
+ + +
+ <%= render :partial => 'edit_head', :locals => {:poll => @poll}%> +
+ + +
+ <%= render :partial => 'poll_content', :locals => {:poll => @poll}%> +
+
- -
- <%= render :partial => 'show_head', :locals => {:poll => @poll}%> -
- - - -
- <%= render :partial => 'poll_content', :locals => {:poll => @poll}%> -
-
diff --git a/app/views/poll/_show_MC.html.erb b/app/views/poll/_show_MC.html.erb index f3fc9c8b5..594baea9d 100644 --- a/app/views/poll/_show_MC.html.erb +++ b/app/views/poll/_show_MC.html.erb @@ -7,7 +7,7 @@ <%if poll_question.is_necessary == 1%> * <%end%> - + (单选题)
<%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> diff --git a/app/views/poll/_show_MCQ.html.erb b/app/views/poll/_show_MCQ.html.erb index e56de53b9..64e39523a 100644 --- a/app/views/poll/_show_MCQ.html.erb +++ b/app/views/poll/_show_MCQ.html.erb @@ -1,28 +1,31 @@
- 第2题: 多选题 * + + 第<%= poll_question.question_number%>题: + + <%= poll_question.question_title %> + <%if poll_question.is_necessary == 1%> + * + <%end%> + (多选题)
- - + <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), + method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> +
- - - - - - - - - + <% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %> + + + + <% end %>
- -
- -
- -
+ +
diff --git a/app/views/poll/_show_mulit.html.erb b/app/views/poll/_show_mulit.html.erb index 35e37ef06..23bdbe6eb 100644 --- a/app/views/poll/_show_mulit.html.erb +++ b/app/views/poll/_show_mulit.html.erb @@ -1,10 +1,18 @@
- 第4题: 多行主观 + + 第<%= poll_question.question_number%>题: + + <%= poll_question.question_title %> + <%if poll_question.is_necessary == 1%> + * + <%end%> + (多行主观)
- - + <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), + method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> +
diff --git a/app/views/poll/_show_single.html.erb b/app/views/poll/_show_single.html.erb index 437e38044..d9ef2abc7 100644 --- a/app/views/poll/_show_single.html.erb +++ b/app/views/poll/_show_single.html.erb @@ -1,9 +1,17 @@
- 第3题: 单行文字 + + 第<%= poll_question.question_number%>题: + + <%= poll_question.question_title %> + <%if poll_question.is_necessary == 1%> + * + <%end%> + (单行文字)
- - + <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), + method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> +
diff --git a/app/views/poll/create_poll_question.js.erb b/app/views/poll/create_poll_question.js.erb index 18f999157..ac44ebb4c 100644 --- a/app/views/poll/create_poll_question.js.erb +++ b/app/views/poll/create_poll_question.js.erb @@ -1,10 +1,26 @@ $("#new_poll_question").html(""); $("#poll_content").append("
" + "
" + + "<% if @poll_questions.question_type == 1%>" + "<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_questions}) %>" + + "<% elsif @poll_questions.question_type == 2%>" + + "<%= escape_javascript(render :partial => 'show_MCQ', :locals => {:poll_question => @poll_questions}) %>" + + "<% elsif @poll_questions.question_type == 3%>" + + "<%= escape_javascript(render :partial => 'show_single', :locals => {:poll_question => @poll_questions}) %>" + + "<% elsif @poll_questions.question_type == 4%>" + + "<%= escape_javascript(render :partial => 'show_mulit', :locals => {:poll_question => @poll_questions}) %>" + + "<% end%>" + "
" + "" + "
"); diff --git a/app/views/poll/statistics_result.html.erb b/app/views/poll/statistics_result.html.erb index 164020cde..dea18f8d8 100644 --- a/app/views/poll/statistics_result.html.erb +++ b/app/views/poll/statistics_result.html.erb @@ -2,211 +2,37 @@ - 问卷调查_问卷结果 + <%= l(:label_poll_result) %> <%= stylesheet_link_tag 'polls', :media => 'all' %>
-

某问卷统计

+

<%= @poll.polls_name %> <%= l(:label_poll) %>

- +<% @poll_questions.each do |poll_question| %>
  1. - 第1题:问题描述问题描述 [单选题] + 第<%= poll_question.question_number %>题:<%= poll_question.question_title %> + [<%= options_show(poll_question.question_type) %>]
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  2. -
  3. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  4. -
  5. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  6. -
  7. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  8. -
  9. -
    - 第1题:问题描述问题描述 [单选题] -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    选项 小计 比例
    第一选项 24
    75%
    第二选项 1
    3.13%
    第三选项 1
    3.13%
    本题有效填写人次 26 
    -
    -
  10. + <%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %> +
+ <% end %> +
    + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> +
+
- -
-
答题已完成 0%
-
- -
diff --git a/app/views/poll/update_poll_question.js.erb b/app/views/poll/update_poll_question.js.erb index 39d0fcfd6..e0727df67 100644 --- a/app/views/poll/update_poll_question.js.erb +++ b/app/views/poll/update_poll_question.js.erb @@ -1,6 +1,22 @@ $("#poll_questions_<%= @poll_question.id%>").html("
" + - "<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_question}) %>" + + "<% if @poll_question.question_type == 1%>" + + "<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_question}) %>" + + "<% elsif @poll_question.question_type == 2%>" + + "<%= escape_javascript(render :partial => 'show_MCQ', :locals => {:poll_question => @poll_question}) %>" + + "<% elsif @poll_question.question_type == 3%>" + + "<%= escape_javascript(render :partial => 'show_single', :locals => {:poll_question => @poll_question}) %>" + + "<% elsif @poll_question.question_type == 4%>" + + "<%= escape_javascript(render :partial => 'show_mulit', :locals => {:poll_question => @poll_question}) %>" + + "<% end%>" + "
" + ""); diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 95ab07d5d..5c2925b90 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2253,5 +2253,10 @@ zh: label_new_answer: 新建选项 label_poll_title: 问卷标题 label_poll_description: 问卷描述 + label_poll_options: 选项 + label_poll_subtotal: 小计 + label_poll_proportion: 比例 + label_poll_valid_commit: 本题有效填写人次 + label_poll_result: 问卷调查_问卷统计 diff --git a/db/schema.rb b/db/schema.rb index 2120080a0..f9ea40ae9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -23,6 +23,18 @@ ActiveRecord::Schema.define(:version => 20150114022710) do add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type" add_index "activities", ["user_id"], :name => "index_activities_on_user_id" + create_table "api_keys", :force => true do |t| + t.string "access_token" + t.datetime "expires_at" + t.integer "user_id" + t.boolean "active", :default => true + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "api_keys", ["access_token"], :name => "index_api_keys_on_access_token" + add_index "api_keys", ["user_id"], :name => "index_api_keys_on_user_id" + create_table "applied_projects", :force => true do |t| t.integer "project_id", :null => false t.integer "user_id", :null => false @@ -1056,6 +1068,14 @@ ActiveRecord::Schema.define(:version => 20150114022710) do t.string "description" end + create_table "social_groups", :force => true do |t| + t.string "name" + t.text "description" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "softapplications", :force => true do |t| t.string "name" t.text "description" @@ -1271,6 +1291,36 @@ ActiveRecord::Schema.define(:version => 20150114022710) do add_index "versions", ["project_id"], :name => "versions_project_id" add_index "versions", ["sharing"], :name => "index_versions_on_sharing" + create_table "voting_choices", :force => true do |t| + t.integer "poll_id", :null => false + t.string "text", :null => false + t.datetime "created_on", :null => false + t.integer "position", :default => 1 + end + + add_index "voting_choices", ["poll_id"], :name => "choices_poll_id" + + create_table "voting_polls", :force => true do |t| + t.integer "project_id", :null => false + t.string "question", :null => false + t.datetime "created_on", :null => false + t.boolean "revote" + end + + add_index "voting_polls", ["project_id"], :name => "polls_project_id" + + create_table "voting_votes", :force => true do |t| + t.integer "user_id", :null => false + t.integer "poll_id", :null => false + t.integer "choice_id", :null => false + t.datetime "created_on", :null => false + end + + add_index "voting_votes", ["choice_id"], :name => "votes_choice_id" + add_index "voting_votes", ["poll_id"], :name => "votes_poll_id" + add_index "voting_votes", ["user_id", "poll_id"], :name => "votes_user_poll_unique", :unique => true + add_index "voting_votes", ["user_id"], :name => "votes_user_id" + create_table "watchers", :force => true do |t| t.string "watchable_type", :default => "", :null => false t.integer "watchable_id", :default => 0, :null => false