diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 5f20d2ce..76872d78 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -498,10 +498,10 @@ class BidsController < ApplicationController #增加作业按评分排序, #@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC") @homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{@bid.courses.first.teacher.id}) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id <> #{@bid.courses.first.teacher.id}) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{@bid.author_id}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id <> #{@bid.author_id}) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY - (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * 0.6 END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * 0.4 END) DESC,created_at ASC") + (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{@bid.proportion * 1.0 / 100} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - @bid.proportion * 1.0 / 100} END) DESC,created_at ASC") if params[:student_id].present? @temp = [] @homework_list.each do |pro| @@ -788,6 +788,7 @@ class BidsController < ApplicationController @bid.name = params[:bid][:name] @bid.description = params[:bid][:description] @bid.is_evaluation = params[:bid][:is_evaluation] + @bid.proportion = params[:bid][:proportion] @bid.reward_type = 3 # @bid.budget = params[:bid][:budget] @bid.deadline = params[:bid][:deadline] diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7cd46b65..20bda61e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -490,6 +490,7 @@ class CoursesController < ApplicationController # 新建作业 def new_homework @homework = Bid.new + @homework.proportion @homework.safe_attributes = params[:bid] if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] )) render :layout => 'base_courses' diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index b4de06fb..62f860a9 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -51,7 +51,10 @@ class MemosController < ApplicationController @memo_new = @memo.dup @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示 - @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1)) + unless @memo.new_record? + @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1)) + end + page = params[:page] if params[:r] && page.nil? @@ -68,10 +71,14 @@ class MemosController < ApplicationController limit(@reply_pages.per_page). offset(@reply_pages.offset). all + if @memo.new_record? + format.html { redirect_to back_url, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + else + format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + # format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end - format.html { render action: :show }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } - # format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } - format.json { render json: @memo.errors, status: :unprocessable_entity } end end end diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index ec14ba5c..c8b495fe 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -105,7 +105,7 @@ class SchoolController < ApplicationController end options = "" @school.each do |s| - options << "
  • #{s.name}
  • " + options << "
  • #{s.name}
  • " end render :text => options diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index f16dbd97..7c60e2dc 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -32,7 +32,7 @@ class WelcomeController < ApplicationController def course if params[:school_id] @school_id = params[:school_id] - else + elsif User.current.logged? && User.current.user_extensions.school @school_id = User.current.user_extensions.school.id end @logoLink ||= logolink() diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b0cc3ce6..88b55b2b 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -83,6 +83,19 @@ module CoursesHelper type << option2 end + def proportion_option + type = [] + i = 0 + while i <= 100 + option = [] + option << i.to_s + "%" + option << i + type << option + i = i + 10 + end + type + end + alias teacherCountOrigin teacherCount def teacherCount project @@ -308,7 +321,7 @@ module CoursesHelper #最终评分 = 学生评分的平均分 * 0.4 +教师评分 * 0.6 def score_for_homework homework if homework.bid.is_evaluation == 1 || homework.bid.is_evaluation == nil - return format("%.2f",(teacher_score_for_homework(homework).to_f * 0.6 + student_score_for_homework(homework).to_f * 0.4)) + return format("%.2f",(homework.bid.proportion * 1.0 / 100) * (teacher_score_for_homework(homework).to_f) + (1 - homework.bid.proportion * 1.0 / 100) * (student_score_for_homework(homework).to_f)) else return teacher_score_for_homework homework end @@ -332,7 +345,7 @@ module CoursesHelper return format("%.2f",teacher_stars == nil ? 0 : teacher_stars.stars) end - #获取指定作业的得分 + #获取指定项目的得分 def project_score project issue_count = project.issues.count issue_journal_count = project.issue_changes.count diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 0054b003..1004a49a 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -233,8 +233,13 @@ module WelcomeHelper def find_all_new_hot_course limit = 9 ,school_id = 0 #sort_project_by_hot_rails 1, 'course_ac_para DESC', limit time_now = Time.new.strftime("%Y"); + if school_id courses = Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <> ?", school_id).order("course_ac_para DESC").limit(limit).all + else + courses = Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id is not NULL + ").order("course_ac_para DESC").limit(limit).all + end courses end diff --git a/app/models/course.rb b/app/models/course.rb index ff5e4fbd..bf6190c8 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -38,6 +38,7 @@ class Course < ActiveRecord::Base validates_format_of :class_period, :with =>/^[1-9]\d*$/ validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/ + before_save :self_validate after_save :create_board_sync before_destroy :delete_all_members @@ -77,7 +78,7 @@ class Course < ActiveRecord::Base where(nil) else pattern = "%#{arg.to_s.strip.downcase}%" - where("LOWER(extra) LIKE :p OR LOWER(name) LIKE :p ", :p => pattern) + where(" LOWER(name) LIKE :p ", :p => pattern) end } @@ -166,10 +167,8 @@ class Course < ActiveRecord::Base end #自定义验证 - def validate - if !class_period.match([0-9]) - errors.add_to_base("class period can only digital") - end + def self_validate + end # 创建课程讨论区 diff --git a/app/models/memo.rb b/app/models/memo.rb index 1e857a22..feb10dec 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -3,9 +3,9 @@ class Memo < ActiveRecord::Base belongs_to :forum belongs_to :author, :class_name => "User", :foreign_key => 'author_id' - validates_presence_of :author_id, :forum_id, :subject + validates_presence_of :author_id, :forum_id, :subject,:content # 若是主题帖,则内容可以是空 - validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? } + #validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? } validates_length_of :subject, maximum: 50 validates_length_of :content, maximum: 3072 validate :cannot_reply_to_locked_topic, :on => :create diff --git a/app/models/project.rb b/app/models/project.rb index 492ca86b..f38ad0dd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -113,6 +113,7 @@ class Project < ActiveRecord::Base validates_presence_of :name, :identifier validates_uniqueness_of :identifier + validates_uniqueness_of :name validates_associated :repository, :wiki # validates_length_of :description, :maximum => 255 validates_length_of :name, :maximum => 255 diff --git a/app/models/user.rb b/app/models/user.rb index 6138f9b5..257681cb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -164,7 +164,7 @@ class User < Principal # Prevents unauthorized assignments attr_protected :login, :admin, :password, :password_confirmation, :hashed_password - LOGIN_LENGTH_LIMIT = 60 + LOGIN_LENGTH_LIMIT = 25 MAIL_LENGTH_LIMIT = 60 validates_presence_of :login, :firstname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } diff --git a/app/views/courses/_homework_form.html.erb b/app/views/courses/_homework_form.html.erb index 6e49fcde..41c05960 100644 --- a/app/views/courses/_homework_form.html.erb +++ b/app/views/courses/_homework_form.html.erb @@ -34,6 +34,8 @@

    <%= f.select :is_evaluation, is_evaluation_option %>

    +

    <%= f.select :proportion, proportion_option %> +

    <%= hidden_field_tag 'course_id', @course.id %>

    <%= l(:label_attachment_plural) %> diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb index 6324cec3..b3ffbe3e 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/messages/_form.html.erb @@ -4,7 +4,7 @@


    -<%= f.text_field :subject,:size => 60, :style => "width: 99%;", :id => "message_subject" %> +<%= f.text_field :subject,:size => 60, :style => "width: 99%;", :id => "message_subject",:readonly=>true %>

    <% unless replying %> @@ -30,9 +30,12 @@

    <%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %> <%= f.text_area :content, :cols => 80, :rows => 13, :class => 'wiki-edit', :id => 'message_content' %>

    -<%= wikitoolbar_for 'message_content' %> +

    <%= l(:label_attachment_plural) %>
    <%= render :partial => 'attachments/form', :locals => {:container => @message} %>

    + + +<%#= wikitoolbar_for 'message_content' %> \ No newline at end of file diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index fa2e8da1..ec0bf7fb 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -5,7 +5,9 @@ <% end %>

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

    -

    <%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %>

    +

    + <%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> +

    <%= f.text_field :identifier, :required => true, :size => 60, :style => "width:488px;", :disabled => @project.identifier_frozen?, :maxlength => Project::IDENTIFIER_MAX_LENGTH %> <% unless @project.identifier_frozen? %> <%= l(:text_length_between, :min => 1, :max => Project::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_project_identifier_info).html_safe %> @@ -24,44 +26,44 @@ <%= call_hook(:view_projects_form, :project => @project, :form => f) %> - +<%# end %> +<%# end %> --> <% unless @project.identifier_frozen? %> diff --git a/app/views/school/index.html.erb b/app/views/school/index.html.erb index 755bd315..6993ee7f 100644 --- a/app/views/school/index.html.erb +++ b/app/views/school/index.html.erb @@ -43,9 +43,9 @@