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/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/tags_controller.rb b/app/controllers/tags_controller.rb index 0216d529..ba01aa99 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -64,15 +64,18 @@ class TagsController < ApplicationController @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, - @forums_results, - @attachments_results, - @contests_tags, - @open_source_projects_results = refresh_results(@obj_id,@obj_flag,@selected_tags) + @forums_results, + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @@ -97,14 +100,18 @@ class TagsController < ApplicationController $related_tags.delete(@tag) # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, - @forums_results, - @attachments_results, - @contests_results = refresh_results(@obj_id,@show_flag) + @forums_results, + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) end # 删除已选tag @@ -116,14 +123,18 @@ class TagsController < ApplicationController $selected_tags.delete(@tag) # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, @forums_results, - @attachments_results, - @contests_results = refresh_results(@obj_id,@show_flag) + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) end def show_all diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 6105b22b..7c60e2dc 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -30,6 +30,11 @@ class WelcomeController < ApplicationController end def course + if params[:school_id] + @school_id = params[:school_id] + elsif User.current.logged? && User.current.user_extensions.school + @school_id = User.current.user_extensions.school.id + end @logoLink ||= logolink() end @@ -75,8 +80,7 @@ class WelcomeController < ApplicationController redirect_to projects_search_path(:name => search_condition, :project_type => Project::ProjectType_project) when :courses - redirect_to projects_search_path(:name => search_condition, - :project_type => Project::ProjectType_course) + redirect_to courses_search_path(:name => search_condition) when :users redirect_to users_search_path(:name => search_condition) when :users_teacher diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7660c050..c9dc4fa2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -473,7 +473,11 @@ module ApplicationHelper def principals_check_box_tags_ex(name, principals) s = '' principals.each do |principal| - s << "\n" + if principal.has_attribute?(:userInfo) + s << "\n" + else + s << "\n" + end end s.html_safe end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b1ec023c..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 @@ -370,4 +383,9 @@ module CoursesHelper end return homework_users end + + def get_courses_by_tag(tag_name) + Course.tagged_with(tag_name).order('updated_at desc') + end + end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 00867d9f..ea72e818 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -67,6 +67,30 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :class => css end + + # add by nwb + # 关注课程 + def new_course_watcher_link(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + watched = objects.any? {|object| object.watched_by?(user)} + @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Contest))) + css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : + ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + text = @watch_flag ? + (watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch)) + + url = watch_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = watched ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css + end + # added by fq, modify nyan # Somebody may use option params def join_in_course(course, user, options=[]) diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 048933e4..1004a49a 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -83,7 +83,8 @@ module WelcomeHelper # # => 前7个项目为新课程,后面三个是参与人数最多的 # # Returns project&courses array - def find_miracle_course(sum=10, max_rate=7, school_id) + # 原来的取课程逻辑 + def find_miracle_course_base(sum=10, max_rate=7, school_id) if User.current.user_extensions.school.nil? and school_id.nil? Project.active.visible.course_entities. @@ -133,6 +134,52 @@ module WelcomeHelper # (c1.take(max)+c2).take(sum) end + #获取课程列表 + # add by nwb + def find_miracle_course(sum=10, max_rate=7, school_id) + if User.current.user_extensions.school.nil? and school_id.nil? + Course.active.visible. + joins(:memberships). + group('members.course_id'). + reorder("courses.time DESC, COUNT(members.course_id) DESC").take sum + + else + if school_id.nil? + Course.active.visible. + joins(:memberships). + where("#{Course.table_name}.school_id = ?", User.current.user_extensions.school.id). + group('members.course_id'). + reorder("courses.time DESC, COUNT(members.course_id) DESC").take sum + else + if school_id == "0" + Course.active.visible. + joins(:memberships). + group('members.course_id'). + reorder("courses.time DESC, COUNT(members.course_id) DESC").take sum + else + Course.active.visible. + joins(:memberships). + where("#{Course.table_name}.school_id = ?", school_id). + group('members.course_id'). + reorder("courses.time DESC, COUNT(members.course_id) DESC").take sum + end + end + end +# else +# Project.active.visible.course_entities. +# joins(:course_extra). +# joins(:memberships). +# where("#{Course.table_name}.school_id = ?", school_id). +# group('members.project_id'). +# reorder("courses.time DESC, COUNT(members.project_id) DESC").take sum +# end +# max = sum*(max_rate.to_f/10) +# c1 = find_new_course(sum).to_a.dup +# c2 = find_all_hot_course(sum).to_a.dup +# c2 = c2 - c1 +# (c1.take(max)+c2).take(sum) + end + #查找所有学校按每个学校开设课程数量降序排序 #page 分页查询开始条数的编号,从0开始 #limit 分页查询的数量 @@ -182,11 +229,18 @@ module WelcomeHelper sort_course_by_hot limit end + # modif by nwb 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"); - Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ? and #{Project.table_name}.created_on like '%#{time_now}%' and #{Project.table_name}.identifier not in - (select extra from courses where school_id = ?)", 1,school_id).order("course_ac_para DESC").limit(limit).all + 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 def find_all_hot_bid diff --git a/app/models/course.rb b/app/models/course.rb index 51b11867..ff5e4fbd 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -27,6 +27,7 @@ class Course < ActiveRecord::Base has_many :boards, :dependent => :destroy, :order => "position ASC" #has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy has_many :news, :dependent => :destroy, :include => :author + has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy 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/repository.rb b/app/models/repository.rb index bcd3366c..ce7ac9d0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -38,7 +38,7 @@ class Repository < ActiveRecord::Base validates_length_of :password, :maximum => 255, :allow_nil => true validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true - validates_presence_of :identifier, :unless => Proc.new { |r| r.is_default? || r.set_as_default? } + validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? } validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph) # donwcase letters, digits, dashes, underscores but not digits only 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/courses/show.html.erb b/app/views/courses/show.html.erb index 5a440aff..59d6720c 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -11,7 +11,7 @@
    - + +
    <%= image_tag(url_to_avatar(e.event_author), :class => "avatar")%><%= image_tag(url_to_avatar(e.event_author), :class => "avatar") %> @@ -19,7 +19,9 @@ <%= h(e.event_title) if @course.nil? || (e.course != nil && @course.id != e.course.id) %> <% if @canShowRealName %> - <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %>(<%= link_to_user(e.event_author,@canShowRealName) if e.respond_to?(:event_author) %>) + <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %> + (<%= link_to_user(e.event_author, @canShowRealName) if e.respond_to?(:event_author) %> + ) <% else %> <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %> <% end %> @@ -31,18 +33,23 @@ - - + <% if e.event_type == "issue" %> - + <% end %> -
    +

    - <%= h(truncate(strip_tags(e.event_description).gsub(/ /,' '), length: 30, omission:'...')) %> + <%= h(truncate(strip_tags(e.event_description).gsub(/ /, ' '), length: 30, omission: '...')) %>

    <%= l :label_activity_time %>:  <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %> <%= l :label_activity_time %> + :  <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %> + <%= link_to l(:label_find_all_comments), issue_path(e) %> <%= l(:label_comments_count, :count => e.journals.count)%> + <%= link_to l(:label_find_all_comments), issue_path(e) %> <%= l(:label_comments_count, :count => e.journals.count) %> +
    +
    @@ -50,60 +57,47 @@ <% end %> - - <% if format_date(day) == format_date(@date_to - @days) %> -

    Test

    -
    - - - - - -
    <%= image_tag(url_to_avatar(@user), :class => "avatar") %> - - - - - -
    <%= link_to (h @user.try(:name)), user_path(@user) if @user %> <%= l(:label_user_create_project) %> <%= link_to @course.name %> !
    <%= l :label_update_time %>: <%= format_time(@course.created_on) %> -
    -
    - <% end %> <% end -%> - -<% else %> -
    - - - - - -
    <%= image_tag(url_to_avatar(@user), :class => "avatar") %> - - - - - -
    - <% - #判断是否显示真名 - if @canShowRealName - %> - <%= link_to (h @user.try(:name)), user_path(@user) if @user %>(<%= link_to (h @user.try(:realname)), user_path(@user) if @user %>) - <% else %> - <%= link_to (h @user.try(:name)), user_path(@user) if @user %> - <% end %> - <%= l(:label_user_create_project) %> <%= link_to @course.name %> !
    <%= l :label_update_time %>: <%= format_time(@course.created_at) %> -
    -
    <% end %> +
    + + + + + +
    <%= image_tag(url_to_avatar(@user), :class => "avatar") %> + + + + + +
    + <% + #判断是否显示真名 + if @canShowRealName + %> + <%= link_to (h @user.try(:name)), user_path(@user) if @user %> + (<%= link_to (h @user.try(:realname)), user_path(@user) if @user %>) + <% else %> + <%= link_to (h @user.try(:name)), user_path(@user) if @user %> + <% end %> + <%= l(:label_user_create_project) %> <%= link_to @course.name %> + !
    <%= l :label_update_time %> + : <%= format_time(@course.created_at) %> +
    +
    +
    + + + + 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/projects/show.html.erb b/app/views/projects/show.html.erb index 6be2a4d7..b4f767a5 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -48,37 +48,14 @@ <% end %> + + <% end -%> - - <% if format_date(day) == format_date(@date_to - @days) %> -

    Test

    -
    - - - - - -
    <%= image_tag(url_to_avatar(@user), :class => "avatar") %> - - - - - -
    <%= link_to (h @user.try(:name)), user_path(@user) if @user %> <%= l(:label_user_create_project) %> <%= link_to @project.name %> !
    <%= l :label_update_time %>: <%= format_time(@project.created_on) %> -
    -
    - <% end %> - <% end -%> - - - + -<% else %> + <%end%> +
    @@ -103,6 +80,13 @@
    -<% end %> + + + + 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 @@