From 78612488e591f5b2b9b4a7ece0754801e1a46ae6 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 17 Jun 2014 11:32:41 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E6=96=B0=E5=BB=BA=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=8F=8A=E8=A7=86=E5=9B=BE=202.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E4=BD=9C=E4=B8=9A=E5=8F=8A=E8=A7=86=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 133 ++++++-- app/helpers/avatar_helper.rb | 2 +- app/helpers/courses_helper.rb | 13 + app/models/bid.rb | 6 +- app/models/homework_for_course.rb | 4 +- app/views/bids/_bid_homework_show.html.erb | 10 +- app/views/courses/_homework_form.html.erb | 1 - app/views/layouts/base_homework.html.erb | 376 +++++++++++---------- config/routes.rb | 2 + db/schema.rb | 20 ++ 10 files changed, 346 insertions(+), 221 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index a0c85689..d7c54db3 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -375,7 +375,7 @@ class BidsController < ApplicationController unless(membership.project.project_type==1) membership.member_roles.each{|role| if(role.role_id == 3) - @option << membership.project + @option << membership.project end } end @@ -397,18 +397,18 @@ class BidsController < ApplicationController end @bidding_project = @temp else - #added by nie - @temp = [] - @bidding_project.each do |pro| - if pro.project && pro.project.project_status - @temp << pro + #added by nie + @temp = [] + @bidding_project.each do |pro| + if pro.project && pro.project.project_status + @temp << pro + end + @temp end - @temp - end - if @temp.size > 0 + if @temp.size > 0 @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} - end - #ended + end + #ended end if @bid.homework_type == 1 @@ -419,9 +419,9 @@ class BidsController < ApplicationController if params[:student_id].present? @temp = [] @homework_list.each do |pro| - if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id - @temp << pro - end + if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id + @temp << pro + end @temp end @homework_list = @temp @@ -430,17 +430,94 @@ class BidsController < ApplicationController respond_to do |format| if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } + format.html { + render :layout => 'base_homework' + } elsif @bid.reward_type == 1 format.html { - render :layout => 'base_bids' - } + render :layout => 'base_bids' + } else - format.html { - render :layout => 'base_contest' - } + format.html { + render :layout => 'base_contest' + } + end + format.api + end + end + + # 显示作业课程 + # add by nwb + def show_course + # flash[:notice] = "" + @membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current)) + @option = [] + @membership.each do |membership| + membership.member_roles.each{|role| + if(role.role_id == 3) + @option << membership.course + end + } + end + + @user = @bid.author + @bidding_project = @bid.biding_projects.all + if params[:student_id].present? + @temp = [] + @bidding_project.each do |pro| + if pro.project && pro.project.project_status + if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id + @temp << pro + end + end + @temp + end + @bidding_project = @temp + else + #added by nie + @temp = [] + @bidding_project.each do |pro| + if pro.project && pro.project.project_status + @temp << pro + end + @temp + end + if @temp.size > 0 + @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} + end + #ended + end + + if @bid.homework_type == 1 + @homework = HomeworkAttach.new + #@homework_list = @bid.homeworks + #增加作业按评分排序, + @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC") + if params[:student_id].present? + @temp = [] + @homework_list.each do |pro| + if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id + @temp << pro + end + @temp + end + @homework_list = @temp + end + end + + respond_to do |format| + if @bid.reward_type == 3 + format.html { + render :layout => 'base_homework' + } + elsif @bid.reward_type == 1 + format.html { + render :layout => 'base_bids' + } + else + format.html { + render :layout => 'base_contest' + } end format.api end @@ -724,14 +801,16 @@ class BidsController < ApplicationController render file: 'courses/new_homework', layout: 'base_courses' end end - + + # modify by nwb\ + # 编辑作业 def edit @bid = Bid.find(params[:bid_id]) if (User.current.admin?||User.current.id==@bid.author_id) - @project_id = params[:project_id] + @course_id = params[:course_id] respond_to do |format| format.html { - @project = Project.find(params[:project_id]) + @course = Course.find(params[:course_id]) @user= User.find(User.current.id) render :layout => 'base_courses' } @@ -743,11 +822,11 @@ class BidsController < ApplicationController def update @bid = Bid.find(params[:id]) - @project = @bid.courses.first#Project.find(params[:course_id]) + @course = @bid.courses.first#Project.find(params[:course_id]) @bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) if @bid.update_attributes(params[:bid]) && @bid.save flash[:notice] = l(:label_update_homework_succeed) - redirect_to project_homework_path(@project) + redirect_to course_homework_path(@course) else @bid.safe_attributes = params[:bid] render :action => 'edit', :layout =>'base_courses' diff --git a/app/helpers/avatar_helper.rb b/app/helpers/avatar_helper.rb index abaa7950..2ebdae0c 100644 --- a/app/helpers/avatar_helper.rb +++ b/app/helpers/avatar_helper.rb @@ -42,7 +42,7 @@ module AvatarHelper end def get_avatar?(source) - if File.exist?(disk_filename(source.class,source.id)) + if source && File.exist?(disk_filename(source.class,source.id)) return true else return false diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 2475121e..f3eab89e 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -51,6 +51,19 @@ module CoursesHelper end + #是否启动互评下拉框 + def is_evaluation_option + type = [] + option1 = [] + option2 = [] + option1 << l(:lable_start_mutual_evaluation) + option1 << 1 + option2 << l(:lable_close_mutual_evaluation) + option2 << 2 + type << option1 + type << option2 + end + # garble count 混淆数量 # alias projectCountOrigin projectCount # def projectCount project diff --git a/app/models/bid.rb b/app/models/bid.rb index e58e640a..b36efe6f 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -21,12 +21,12 @@ class Bid < ActiveRecord::Base belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :course has_many :biding_projects, :dependent => :destroy - has_many :projects, :through => :biding_projects - has_many :projects_member, :class_name => 'User', :through => :projects + has_many :courses, :through => :biding_courses + has_many :courses_member, :class_name => 'User', :through => :courses has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy - has_many :courses, :through => :homework_for_courses, :source => :project + has_many :courses, :through => :homework_for_courses, :source => :course has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy has_many :join_in_contests, :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy diff --git a/app/models/homework_for_course.rb b/app/models/homework_for_course.rb index 7a440449..59fd7ba1 100644 --- a/app/models/homework_for_course.rb +++ b/app/models/homework_for_course.rb @@ -1,8 +1,8 @@ class HomeworkForCourse < ActiveRecord::Base - attr_accessible :bid_id, :project_id + attr_accessible :bid_id, :course_id belongs_to :bid - belongs_to :project + belongs_to :course end diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index c4eb875a..179e2d58 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -13,9 +13,9 @@ <%= l(:label_user_create_project_homework) %> <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %> - <% if(User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)) %> + <% if(User.current.logged? && (!Member.where('user_id = ? and course_id = ?', User.current.id, bid.courses.first.id).first.nil? && (Member.where('user_id = ? and course_id = ?', User.current.id, bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)) %> <%# 提交作业按钮 %> - + <% cur_user_homework = cur_user_homework_for_bid(bid) %> <% if cur_user_homework!= nil && cur_user_homework.count == 0 %> <%= link_to l(:label_commit_homework),new_homework_attach_path(bid) %> @@ -26,7 +26,7 @@ <% if (User.current.admin?||User.current.id==bid.author_id) %> <%= link_to( l(:button_edit), - {:action => 'edit', :controller=>'bids', :project_id =>@project.id, :bid_id => bid.id}, + {:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id}, :class => 'icon icon-edit' ) %> <%= link_to( @@ -51,9 +51,9 @@ end %> <% if bid.homework_type == 1%> - <%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<%= link_to bid.homeworks.count, project_for_bid_path(bid.id) %>) + <%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<%= link_to bid.homeworks.count, course_for_bid_path(bid.id) %>) <% else %> - <%= l(:label_x_homework_project, :count => @temp.count) %>(<%= link_to @temp.count, project_for_bid_path(bid.id) %>) + <%= l(:label_x_homework_project, :count => @temp.count) %>(<%= link_to @temp.count, course_for_bid_path(bid.id) %>) <% end %> <%= l(:label_x_responses, :count => bid.commit) %>(<%= link_to bid.commit, respond_path(bid) %>) diff --git a/app/views/courses/_homework_form.html.erb b/app/views/courses/_homework_form.html.erb index 442ebbeb..b30785e1 100644 --- a/app/views/courses/_homework_form.html.erb +++ b/app/views/courses/_homework_form.html.erb @@ -21,7 +21,6 @@ <%= error_messages_for 'bid' %> -

<%= l(:label_homeworks_form_new_description) %>

<%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT %>

diff --git a/app/views/layouts/base_homework.html.erb b/app/views/layouts/base_homework.html.erb index 34d3b7b5..6efb321c 100644 --- a/app/views/layouts/base_homework.html.erb +++ b/app/views/layouts/base_homework.html.erb @@ -18,214 +18,226 @@ <%= yield :header_tags -%> - <% project = @bid.courses.includes(:course_extra).first %> - <% course = project.course_extra %> -
-
-
- <%= render :partial => 'layouts/base_header'%> -
- -
- - - - + <% course = @bid.courses.first %> + <% if course %> +
+
+
+ <%= render :partial => 'layouts/base_header' %> +
+ +
+
高校课程实践社区<%= l(:label_user_location) %> :
+ + + - - - - - -
高校课程实践社区<%= l(:label_user_location) %> :
<%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%>

<%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> > - <%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%> > - <%=link_to(@bid.name, respond_path(@bid)) %>

-
- + + + + <%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index' %> +

<%= link_to "主页", home_path %> + > <%= link_to l(:label_course_practice), :controller => 'courses', :action => 'index' %> > + <%= link_to(@bid.courses.first.name.to_s, homework_course_path(@bid.courses.first)) if @bid.courses.first %> + > + <%= link_to(@bid.name, respond_path(@bid)) %>

+ + +
+ - - -
-
- -
-
    -
  • - <%= link_to l(:label_question_student), {:controller => 'bids', :action => 'show' },:class => link_class(:respond)%> -
  • - <% if User.current.member_of? @bid.courses.first%> -
  • - <% if User.current.logged? && @bid.courses.first && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) %> - <%= link_to l(:label_homework_commit), {:controller => 'bids', :action => 'show_project' },:class => link_class(:project)%> - <% else %> - <%= link_to l(:label_homework_info), {:controller => 'bids', :action => 'show_project' },:class => link_class(:project)%> - - <% end %> -
  • +
    +
    + <%= l(:label_commit_homework) %> +
    +
    + + +
    + <% if @bid.homework_type == 1 %> + <% if @bid.homeworks.size>0 %> + <% for homework in @bid.homeworks.eager_load(:user) %> + <%= link_to image_tag(url_to_avatar(homework.user), :class => "avatar", :title => homework.user.name), user_path(homework.user), :class => "avatar" %> + <% end %> + <% else %> +

    + <%= l(:label_no_course_project) %> +

    <% end %> - - + +
    + +
    +
      +
    • + <%= link_to l(:label_question_student), {:controller => 'bids', :action => 'show'}, :class => link_class(:respond) %> +
    • + <% if User.current.member_of? @bid.courses.first %> +
    • + <% if User.current.logged? && @bid.courses.first && (!Member.where('user_id = ? and course_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and course_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?', 5, 10, 7)).size >0) %> + <%= link_to l(:label_homework_commit), {:controller => 'bids', :action => 'show_course'}, :class => link_class(:course) %> + <% else %> + <%= link_to l(:label_homework_info), {:controller => 'bids', :action => 'show_course'}, :class => link_class(:course) %> + + <% end %> +
    • + <% end %> + +
    -
    +
    - <%= yield %> - <%= call_hook :view_layouts_base_content %> -
    - - <%= render :partial => 'layouts/base_footer'%> - - - + <%= yield %> + <%= call_hook :view_layouts_base_content %> +
    + + <%= render :partial => 'layouts/base_footer' %> + + + - - + + - - <%= call_hook :view_layouts_base_body_bottom %> + + <%= call_hook :view_layouts_base_body_bottom %> + <% end %> diff --git a/config/routes.rb b/config/routes.rb index 59c3eb35..3ee5d777 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -591,6 +591,7 @@ RedmineApp::Application.routes.draw do end resources :news, :except => [:show, :edit, :update, :destroy] resources :boards + match '/homework', :controller => 'courses', :action => 'homework', :as => 'homework', :via => :get end # end of resources :courses match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback' match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post] @@ -632,6 +633,7 @@ RedmineApp::Application.routes.draw do match 'calls/new_bid', :controller => 'bids', :action => 'new_bid' match 'contest/new_contest', :controller => 'bids', :action => 'new_contest' #huang match 'calls/:id/show_project', :controller => 'bids', :action => 'show_project', :as => 'project_for_bid' + match 'calls/:id/show_course', :controller => 'bids', :action => 'show_course', :as => 'course_for_bid' # nwb added match 'calls/:id/new_exercise_book', :controller => 'homework_attach', :action => 'new', :as => 'new_homework_attach' match 'calls/:id/add', :controller => 'bids', :action => 'add' match 'calls/:id/delete', :controller => 'bids', :action => 'delete' diff --git a/db/schema.rb b/db/schema.rb index 51a2f805..2af470d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -207,6 +207,17 @@ ActiveRecord::Schema.define(:version => 20140611161801) do t.string "reward" end + create_table "contestnotifications", :force => true do |t| + t.integer "contest_id" + t.string "title" + t.string "summary" + t.string "description" + t.integer "author_id" + t.integer "notificationcomments_count" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "contests", :force => true do |t| t.string "name" t.string "budget", :default => "" @@ -595,6 +606,15 @@ ActiveRecord::Schema.define(:version => 20140611161801) do t.datetime "updated_at", :null => false end + create_table "notificationcomments", :force => true do |t| + t.string "notificationcommented_type" + t.integer "notificationcommented_id" + t.integer "author_id" + t.text "notificationcomments" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "open_id_authentication_associations", :force => true do |t| t.integer "issued" t.integer "lifetime"