From 60b07432926d330981a15a041fbc959807bf032d Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 14 Jan 2015 09:48:19 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E8=B0=83=E6=9F=A5?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=9C=A8=E7=81=AB=E7=8B=90=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/poll/show.html.erb | 4 ++++ db/schema.rb | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/views/poll/show.html.erb b/app/views/poll/show.html.erb index 66fcd3bcd..a0c111a79 100644 --- a/app/views/poll/show.html.erb +++ b/app/views/poll/show.html.erb @@ -25,6 +25,7 @@
第1题: 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 *
+
@@ -52,6 +53,7 @@
第2题: 多选题 *
+
@@ -80,6 +82,7 @@
第3题: 单行主观
+
@@ -90,6 +93,7 @@
第4题: 多行主观
+
diff --git a/db/schema.rb b/db/schema.rb index 9c6f4eac3..a58602e37 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150112024820) do +ActiveRecord::Schema.define(:version => 20150112080435) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -23,6 +23,18 @@ ActiveRecord::Schema.define(:version => 20150112024820) 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 From e4edc5d1db85c13906772869e6ef34e07832c962 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 14 Jan 2015 10:05:05 +0800 Subject: [PATCH 2/7] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD=202.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BC=96=E8=BE=91=E5=AE=8C=E6=88=90=E5=90=8E?= =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=A4=B4=E9=A1=B5=E9=9D=A2=203.=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=97=AE=E5=8D=B7=E6=8C=89=E9=92=AE=E7=9A=84css?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/poll/_poll_form.html.erb | 59 +++++++++++++++++++++++++++++ app/views/poll/_show_head.html.erb | 8 ++++ app/views/poll/edit.html.erb | 13 +------ app/views/poll/index.html.erb | 5 +++ app/views/poll/new.html.erb | 60 +----------------------------- public/stylesheets/polls.css | 5 +++ 6 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 app/views/poll/_poll_form.html.erb create mode 100644 app/views/poll/_show_head.html.erb diff --git a/app/views/poll/_poll_form.html.erb b/app/views/poll/_poll_form.html.erb new file mode 100644 index 000000000..0387bb9c6 --- /dev/null +++ b/app/views/poll/_poll_form.html.erb @@ -0,0 +1,59 @@ + + + + + 问卷调查_问卷编辑 + <%= stylesheet_link_tag 'polls', :media => 'all' %> + + + + + + + + diff --git a/app/views/poll/_show_head.html.erb b/app/views/poll/_show_head.html.erb new file mode 100644 index 000000000..f8a2d58f0 --- /dev/null +++ b/app/views/poll/_show_head.html.erb @@ -0,0 +1,8 @@ +
+

标题标题标题标题标题标题标题

+

描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述 + 描述描述描述描述描述描述描述描述描述描述描述描述 +

+ +
+
\ No newline at end of file diff --git a/app/views/poll/edit.html.erb b/app/views/poll/edit.html.erb index a35b1d2e7..d346d0699 100644 --- a/app/views/poll/edit.html.erb +++ b/app/views/poll/edit.html.erb @@ -1,13 +1,2 @@ - -<%= form_for(@poll) do |f|%> - <%= f.text_field :polls_name, :required => true, :name => "polls_name"%> - - <%= l(:label_button_ok) %> - -<% end%> +<%= render :partial => 'poll_form'%> diff --git a/app/views/poll/index.html.erb b/app/views/poll/index.html.erb index 150c13382..9d0bd5549 100644 --- a/app/views/poll/index.html.erb +++ b/app/views/poll/index.html.erb @@ -26,6 +26,11 @@ method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml20 mr10") %> <% end%> +
  • + <% if @is_teacher%> + <%= link_to l(:button_edit), edit_poll_path(poll.id), :class => "polls_de fr ml20"%> + <% end%> +
  • <%= format_time poll.created_at%>
  • diff --git a/app/views/poll/new.html.erb b/app/views/poll/new.html.erb index 06ef2fae8..eddb3a590 100644 --- a/app/views/poll/new.html.erb +++ b/app/views/poll/new.html.erb @@ -1,59 +1 @@ - - - - - 问卷调查_问卷编辑 - <%= stylesheet_link_tag 'polls', :media => 'all' %> - - - - - - - - +<%= render :partial => 'poll_form'%> \ No newline at end of file diff --git a/public/stylesheets/polls.css b/public/stylesheets/polls.css index 428ade808..b13cb1da2 100644 --- a/public/stylesheets/polls.css +++ b/public/stylesheets/polls.css @@ -13,6 +13,11 @@ div,html,img,ul,li,p,body,h1,h2,h3,h4,p,a,table,tr,td,fieldset,input,span{ margi #polls .fl{ float: left;} #polls .fr{ float:right;} +/*问卷按钮*/ +.polls_btn{ height:33px;border-top:1px solid #15bed1; border-bottom:1px solid #15bed1;border-right:1px solid #cee6e6; width:225px; padding:7px 0 0 15px; } +.polls_btn a{font-size:14px; color:#444444;font-weight:bold;} +.polls_btn span{ color:#15bed1; font-size:12px; font-weight:normal;} + /*问卷列表*/ .polls_content{ width:615px;} .polls_head{ width:677px; height:48px; background:#eaeaea;} From b6826a74d34cde40c248aa409ea8c6ca6db7ade9 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 14 Jan 2015 11:50:59 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 4 +- app/models/poll.rb | 2 +- app/models/poll_question.rb | 2 +- app/views/poll/show.html.erb | 181 ++++++++++-------- ...0_add_question_number_to_poll_questions.rb | 9 + db/schema.rb | 7 +- 6 files changed, 115 insertions(+), 90 deletions(-) create mode 100644 db/migrate/20150114022710_add_question_number_to_poll_questions.rb diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 9177e044b..88bbfff46 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -19,8 +19,8 @@ class PollController < ApplicationController def show @poll = Poll.find params[:id] - @poll_questions = @poll.poll_questions - + poll_questions = @poll.poll_questions + @poll_questions = paginateHelper poll_questions,3 #分页 respond_to do |format| format.html {render :layout => 'base_courses'} end diff --git a/app/models/poll.rb b/app/models/poll.rb index 803ee6ac6..06f1369c1 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -3,7 +3,7 @@ class Poll < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :user - has_many :poll_questions, :dependent => :destroy + has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number" has_many :poll_users, :dependent => :destroy has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 end diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 66dcea67e..2d9912fc2 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -3,6 +3,6 @@ class PollQuestion < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :poll - has_many :poll_answers, :dependent => :destroy + has_many :poll_answers, :order => "#{PollAnswer.table_name}.answer_position",:dependent => :destroy has_many :poll_votes, :dependent => :destroy end diff --git a/app/views/poll/show.html.erb b/app/views/poll/show.html.erb index a0c111a79..26daa8fc5 100644 --- a/app/views/poll/show.html.erb +++ b/app/views/poll/show.html.erb @@ -20,90 +20,105 @@
      - -
    1. -
      - 第1题: 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 * -
      -
      -
      -
    - - - - - - - - - - - -
    - -
    - -
    - -
    -
    - - -
  • -
    - 第2题: 多选题 * -
    -
    -
    - - - - - - - - - - - - -
    - -
    - -
    - -
    -
    -
  • - - -
  • -
    - 第3题: 单行主观 -
    -
    -
    - -
    -
  • - -
  • -
    -
    - 第4题: 多行主观 -
    -
    -
    - -
    -
    -
  • - + <% @poll_questions.each do |pq| %> + <% if pq.question_type == 1 %> + +
  • +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + + + <% pq.poll_answers.each do |pa| %> + + + + <% end %> + +
    + +
    +
    +
  • + <% elsif pq.question_type == 2 %> + +
  • +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + + + <% pq.poll_answers.each do |pa| %> + + + + <% end %> + +
    + +
    +
    +
  • + <% elsif pq.question_type == 3 %> + +
  • +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + +
    +
  • + <% elsif pq.question_type == 4 %> + +
  • +
    +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + +
    +
    +
  • + <% else %> + + <% end %> + <% end %> - -
    - 下一页 + +
    +
    diff --git a/db/migrate/20150114022710_add_question_number_to_poll_questions.rb b/db/migrate/20150114022710_add_question_number_to_poll_questions.rb new file mode 100644 index 000000000..71f0328be --- /dev/null +++ b/db/migrate/20150114022710_add_question_number_to_poll_questions.rb @@ -0,0 +1,9 @@ +class AddQuestionNumberToPollQuestions < ActiveRecord::Migration + def self.up + add_column :poll_questions, :question_number, :integer + end + + def self.down + remove_column :poll_questions, :question_number + end +end diff --git a/db/schema.rb b/db/schema.rb index a58602e37..53d57d748 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150112080435) do +ActiveRecord::Schema.define(:version => 20150114022710) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -815,8 +815,9 @@ ActiveRecord::Schema.define(:version => 20150112080435) do t.integer "question_type" t.integer "is_necessary" t.integer "poll_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "question_number" end create_table "poll_users", :force => true do |t| From eb2498c62c6af8f3af92641d6bd5796964ec56cf Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 14 Jan 2015 14:23:41 +0800 Subject: [PATCH 4/7] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8D=95=E9=80=89=E9=A2=98=E3=80=81=E6=96=B0=E5=A2=9E=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E3=80=81=E5=88=A0=E9=99=A4=E9=80=89=E9=A1=B9=E7=AD=89?= =?UTF-8?q?js=202.=E4=BF=AE=E6=94=B9=E9=97=AE=E5=8D=B7layout=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=203.=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=A2=9E=E5=8D=95?= =?UTF-8?q?=E9=80=89=E9=A2=98=E7=A1=AE=E5=AE=9A=E6=8C=89=E9=92=AE=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=BB=A5=E5=8F=8A=E7=9B=B8=E5=85=B3action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 8 ++-- app/views/poll/_edit_MC.html.erb | 55 +++++++++++------------- app/views/poll/_poll_form.html.erb | 17 ++++++++ app/views/poll/_question_answer.html.erb | 11 +++++ config/routes.rb | 2 +- 5 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 app/views/poll/_question_answer.html.erb diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 9177e044b..e1439b7f9 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -54,7 +54,9 @@ class PollController < ApplicationController end def edit - + respond_to do |format| + format.html{render :layout => 'base_courses'} + end end def update @@ -82,8 +84,8 @@ class PollController < ApplicationController end #添加单选题 - def add_mc - + def create_poll_question + a = 1 end private diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb index 73d967ca9..492126827 100644 --- a/app/views/poll/_edit_MC.html.erb +++ b/app/views/poll/_edit_MC.html.erb @@ -1,33 +1,26 @@ -
    -
    -
    - - - - -
    -
    -
      -
    • - - - - -
    • -
      -
    • - - - - -
    • +<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> +
      + +
      +
      + + + + +
      +
      +
        + <%= render :partial => 'question_answer'%> + <%= render :partial => 'question_answer'%> + <%= render :partial => 'question_answer'%> +
      +
      +
      -
    -
    - +
    -
    -
    -
    \ No newline at end of file +<% 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 0387bb9c6..a8ad46694 100644 --- a/app/views/poll/_poll_form.html.erb +++ b/app/views/poll/_poll_form.html.erb @@ -10,6 +10,22 @@ function add_MCQ(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_MCQ') %>");} function add_single(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_single') %>");} function add_mulit(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_mulit') %>");} + //单选题 + function add_single_answer(doc) + { + doc.parent().after("<%= escape_javascript(render :partial => 'question_answer') %>"); + } + function remove_single_answer(doc) + { + if(doc.parent().siblings("li").length == 0) + { + doc.parent().parent().parent().parent().parent().parent().remove(); + } + else + { + doc.parent().remove(); + } + } @@ -45,6 +61,7 @@ <%= render :partial => 'edit_head'%>
    + <%#= render :partial => 'edit_MC'%>
    diff --git a/app/views/poll/_question_answer.html.erb b/app/views/poll/_question_answer.html.erb new file mode 100644 index 000000000..765d71787 --- /dev/null +++ b/app/views/poll/_question_answer.html.erb @@ -0,0 +1,11 @@ +
  • + + + + +
  • +
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index af0b75ae7..d2d0c73a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,7 +61,7 @@ RedmineApp::Application.routes.draw do resources :poll do member do get 'statistics_result' - get 'add_mc' + post 'create_poll_question' end end From 0433f7c87f551b4544e267b335c571a36bde130a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 14 Jan 2015 15:35:04 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E5=8D=95=E9=80=89=E9=A2=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 25 +++++++++++++++++++++++-- app/views/poll/_edit_MC.html.erb | 11 ++++++++--- app/views/poll/_poll_form.html.erb | 4 +++- config/locales/zh.yml | 2 ++ db/schema.rb | 12 ------------ 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index b3fdf5087..99287e2cd 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -1,5 +1,5 @@ class PollController < ApplicationController - before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result] + before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question] before_filter :find_container, :only => [:new,:create, :index] before_filter :is_member_of_course, :only => [:index,:show] before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy] @@ -85,7 +85,28 @@ class PollController < ApplicationController #添加单选题 def create_poll_question - a = 1 + question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] + option = { + :is_necessary => params[:is_necessary] || true, + :question_title => question_title, + :question_type => params[:question_type] || 1 + } + @poll_questions = @poll.poll_questions.new option + if params[:question_answer] + for i in 1..params[:question_answer].count + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + question_option = { + :answer_position => i, + :answer_text => params[:question_answer].values[i-1] + } + @poll_questions.poll_answers.new question_option + end + end + if @poll_questions.save + respond_to do |format| + format.js + end + end end private diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb index 492126827..bf120a20a 100644 --- a/app/views/poll/_edit_MC.html.erb +++ b/app/views/poll/_edit_MC.html.erb @@ -4,15 +4,20 @@
    +
      - <%= render :partial => 'question_answer'%> - <%= render :partial => 'question_answer'%> - <%= render :partial => 'question_answer'%> +
    • + + + + +
    • +