diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index a45b64c8c..a8a351eb1 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -200,7 +200,7 @@ class BidsController < ApplicationController flash[:notice] = l(:label_bid_succeed) end end - redirect_to respond_path(@homework) + redirect_to course_for_bid_path(@homework) else @bid.safe_attributes = params[:bid] @courses = [] @@ -454,6 +454,7 @@ class BidsController < ApplicationController # 显示作业课程 # add by nwb def show_courseEx + if (User.current.logged? && (User.current.member_of_course?(@bid.courses.first) || User.current.admin?)) # flash[:notice] = "" @membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current)) @@ -489,26 +490,38 @@ class BidsController < ApplicationController if @bid.homework_type @homework = HomeworkAttach.new - if @bid.proportion - teacher_proportion = @bid.proportion * 1.0 / 100 - else - teacher_proportion = 1.0 + @is_teacher = is_course_teacher(User.current,@bid.courses.first) + teachers = "(" + teacher_members = searchTeacherAndAssistant(@bid.courses.first) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + if @is_teacher + all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score + FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1 + WHERE table1.t_score IS NULL") + @cur_type = 1 + else + all_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 IN #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + FROM homework_attaches + INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id + WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY s_score DESC") + @is_student_batch_homework = true + @cur_type = 4 end - #@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") - all_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.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 * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC") - - limit = 10 - feedback_count = all_homework_list.count - @feedback_pages = Paginator.new feedback_count, limit, params['page'] - offset ||= @feedback_pages.offset - @homework_list = all_homework_list[offset, limit] + @cur_page = params[:page] || 1 + @homework_list = paginateHelper all_homework_list,10 + @jours_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count if params[:student_id].present? @temp = [] @homework_list.each do |pro| @@ -635,13 +648,8 @@ class BidsController < ApplicationController end @user = @bid.author @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] + @jour = paginateHelper @jours,10 @bid.set_commit(@feedback_count) - respond_to do |format| format.js #format.api { render_api_ok } @@ -797,6 +805,7 @@ class BidsController < ApplicationController @bid.description = params[:bid][:description] @bid.is_evaluation = params[:bid][:is_evaluation] @bid.proportion = params[:bid][:proportion] + @bid.evaluation_num = params[:bid][:evaluation_num] @bid.reward_type = 3 # @bid.budget = params[:bid][:budget] @bid.deadline = params[:bid][:deadline] @@ -813,7 +822,7 @@ class BidsController < ApplicationController flash[:notice] = l(:label_bid_succeed) end end - redirect_to respond_url(@bid) + redirect_to course_homework_url(params[:course_id]) else @bid.safe_attributes = params[:bid] @homework = @bid @@ -852,6 +861,7 @@ class BidsController < ApplicationController @bid.description = params[:bid][:description] @bid.is_evaluation = params[:bid][:is_evaluation] @bid.proportion = params[:bid][:proportion] + @bid.evaluation_num = params[:bid][:evaluation_num] @bid.reward_type = 3 @bid.deadline = params[:bid][:deadline] @bid.budget = 0 @@ -991,8 +1001,81 @@ class BidsController < ApplicationController def manage end + + # 启动匿评 + def start_anonymous_comment + @bid = Bid.find(params[:id]) + @course = @bid.courses.first + if(@bid.comment_status == 0) + homeworks = @bid.homeworks + if(homeworks && homeworks.size >= 2) + homeworks.each_with_index do |homework, index| + user = homework.user + n = @bid.evaluation_num + n = n < homeworks.size ? n : homeworks.size - 1 + assigned_homeworks = get_assigned_homeworks(homeworks, n, index) + assigned_homeworks.each do |h| + @homework_evaluation = HomeworkEvaluation.new(user_id: user.id, homework_attach_id: h.id) + @homework_evaluation.save + end + end + @bid.update_column('comment_status', 1) + @statue = 1 + else + @statue = 2 + end + else + @statue = 3 + end + + respond_to do |format| + format.js + end + end + + def stop_anonymous_comment + @bid = Bid.find(params[:id]) + + @bid.update_column('comment_status', 2) + + respond_to do |format| + format.js + end + end + + def alert_anonymous_comment + @bid = Bid.find params[:id] + @course = @bid.courses.first + if @bid.comment_status == 0 + @totle_size = searchStudent(@course).size + @cur_size = @bid.homeworks.size + elsif @bid.comment_status == 1 + @totle_size = 0 + @bid.homeworks.map { |homework| @totle_size += homework.homework_evaluations.count} + teachers = "(" + teacher_members = searchTeacherAndAssistant(@course) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + @cur_size = 0 + @bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.rater_id not in #{teachers}").count} + end + @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) + respond_to do |format| + format.js + end + end private + + def get_assigned_homeworks(homeworks, n, index) + homeworks += homeworks + homeworks[index + 1 .. index + n] + end def find_bid if params[:id] @@ -1026,6 +1109,5 @@ class BidsController < ApplicationController render_404 end end - end diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index d7a79457a..833711e3e 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -124,11 +124,12 @@ class ContestsController < ApplicationController def show_contest @user = @contest.author @jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] + #@limit = 10 + #@feedback_count = @jours.count + #@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + #@offset ||= @feedback_pages.offset + #@jour = @jours[@offset, @limit] + @jour = paginateHelper @jours,10 @state = false respond_to do |format| diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 8a5bfd9fb..ee1ca0230 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -410,6 +410,7 @@ class CoursesController < ApplicationController @course = Course.new @course.safe_attributes = params[:course] + month = Time.now.month render :layout => 'base' end @@ -672,10 +673,10 @@ class CoursesController < ApplicationController page = 1 + offset / @limit end - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, page - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] + #@feedback_count = @jours.count + #@feedback_pages = Paginator.new @feedback_count, @limit, page + #@offset ||= @feedback_pages.offset + @jour = paginateHelper @jours,10 @state = false respond_to do |format| format.html{render :layout => 'base_courses'} diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 041c63a8e..2cf2e7895 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -1,24 +1,170 @@ class HomeworkAttachController < ApplicationController layout "course_base" include CoursesHelper + include HomeworkAttachHelper + helper :words ############################### before_filter :can_show_course,except: [] #判断当前角色权限时需先找到当前操作的project before_filter :find_course_by_bid_id, :only => [:new] - before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users] + before_filter :find_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours, :get_student_batch_homework, :get_my_homework] + before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users, :praise_homework] #判断当前角色是否有操作权限 #勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy] - def find_course_by_bid_id - @bid = Bid.find(params[:id]) - @course = @bid.courses[0] - rescue ActiveRecord::RecordNotFound - render_404 + #@cur_type: + #1.未批作业列表 + #2.已批作业列表 + #3.全部作业列表 + #4.匿评作业列表 + #根据此字段判断关闭homework_attach的show界面后是否要调用js刷新页面 + + #获取未批作业列表 + def get_not_batch_homework + sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" + if sort == 't_socre' + order_by = "t_score #{direction}" + elsif sort == 's_socre' + order_by = "s_score #{direction}" + elsif sort == 'time' + order_by = "created_at #{direction}" + end + teachers = find_course_teachers @course + all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY #{order_by}) AS table1 + WHERE table1.t_score IS NULL") + @cur_page = params[:page] || 1 + @cur_type = 1 + @homework_list = paginateHelper all_homework_list,10 + @direction = direction == 'asc'? 'desc' : 'asc' + respond_to do |format| + format.js + end end - def find_course_by_hoemwork_id - @homework = HomeworkAttach.find(params[:id]) - @course = @homework.bid.courses[0] + #获取已评作业列表 + def get_batch_homeworks + sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" + if sort == 't_socre' + order_by = "t_score #{direction}" + elsif sort == 's_socre' + order_by = "s_score #{direction}" + elsif sort == 'time' + order_by = "created_at #{direction}" + end + teachers = find_course_teachers @course + all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers} and stars IS NOT NULL) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY #{order_by}) AS table1 + WHERE table1.t_score IS NOT NULL") + @cur_page = params[:page] || 1 + @cur_type = 2 + @homework_list = paginateHelper all_homework_list,10 + @direction = direction == 'asc'? 'desc' : 'asc' + respond_to do |format| + format.js + end + end + + #获取所有作业列表 + def get_homeworks + sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" + if sort == 't_socre' + order_by = "t_score #{direction}" + elsif sort == 's_socre' + order_by = "s_score #{direction}" + elsif sort == 'time' + order_by = "created_at #{direction}" + end + teachers = find_course_teachers @course + all_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 in #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY #{order_by}") + @cur_page = params[:page] || 1 + @cur_type = 3 + @homework_list = paginateHelper all_homework_list,10 + @direction = direction == 'asc'? 'desc' : 'asc' + respond_to do |format| + format.js + end + end + + #获取学生匿评列表 + def get_student_batch_homework + @is_student_batch_homework = true + teachers = find_course_teachers @course + all_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 IN #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + FROM homework_attaches + INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id + WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY s_score DESC") + @cur_page = params[:page] || 1 + @cur_type = 4 + @homework_list = paginateHelper all_homework_list,10 + respond_to do |format| + format.js + end + end + + #获取我的作业 + def get_my_homework + @is_my_homework = true + teachers = find_course_teachers @course + all_homework_list = HomeworkAttach.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 IN #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score + FROM homework_attaches + WHERE homework_attaches.bid_id = #{@bid.id} AND homework_attaches.user_id = #{User.current.id}") + #如果我没有创建过作业,就检索我是否参与了某个作业 + if all_homework_list.empty? + all_homework_list = HomeworkAttach.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 IN #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score + FROM homework_attaches + INNER JOIN homework_users ON homework_users.homework_attach_id = homework_attaches.id + WHERE homework_attaches.bid_id = #{@bid.id} AND homework_users.user_id = #{User.current.id}") + end + @cur_page = params[:page] || 1 + @homework_list = paginateHelper all_homework_list,10 + respond_to do |format| + format.js + end + end + + #获取作业的留言列表 + def get_homework_jours + @user = @bid.author + @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + @jour = paginateHelper @jours,10 + @state = false + respond_to do |format| + format.js + end + end + + #为作业点赞 + def praise_homework + pt = PraiseTread.new + pt.user_id = User.current.id + pt.praise_tread_object_id = @homework.id + pt.praise_tread_object_type = "HomeworkAttach" + pt.praise_or_tread = 1 + if pt.save + respond_to do |format| + format.js + end + else + render_404 + end end #获取作业的成员 @@ -66,6 +212,9 @@ class HomeworkAttachController < ApplicationController homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first homework_user.destroy get_homework_member @homework + + @homework_list = [] + @is_my_homework = true respond_to do |format| format.js end @@ -77,7 +226,7 @@ class HomeworkAttachController < ApplicationController def create bid = Bid.find params[:bid_id] if User.current.admin? || User.current.member_of_course?(bid.courses.first) # modify by nwb - if bid.homeworks.where("user_id = ?",User.current).count == 0 + if bid.homeworks.where("user_id = ?",User.current).empty? user_id = params[:user_id] bid_id = params[:bid_id] if params[:homework_attach] @@ -90,8 +239,8 @@ class HomeworkAttachController < ApplicationController project_id = 0 end sta = 0 - name = params[:new_form][:name] - description = params[:new_form][:description] + name = params[:homework_attach][:name] + description = params[:homework_attach][:description] options = { :user_id => user_id, :state => sta, @@ -212,9 +361,14 @@ class HomeworkAttachController < ApplicationController def destroy if User.current.admin? || User.current == @homework.user if @homework.destroy + #respond_to do |format| + # format.html { redirect_to course_for_bid_url @homework.bid } + # format.json { head :no_content } + #end + @homework_list = [] + @is_my_homework = true respond_to do |format| - format.html { redirect_to course_for_bid_url @homework.bid } - format.json { head :no_content } + format.js end else end @@ -227,32 +381,71 @@ class HomeworkAttachController < ApplicationController def show if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first) # 打分统计 - stars_reates = @homework. - rates(:quality) - stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count - stars_status = stars_reates.select("stars, count(*) as scount"). - group("stars") - @stars_status_map = Hash.new(0.0) - stars_status.each do |star_status| - percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f - percent_m = format("%.2f", percent) - @stars_status_map["star#{star_status.stars.to_i}".to_sym] = - percent_m.to_s + "%" - end + stars_reates = @homework. rates(:quality) + #stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + #stars_status = stars_reates.select("stars, count(*) as scount").group("stars") + #@stars_status_map = Hash.new(0.0) + #stars_status.each do |star_status| + # percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f + # percent_m = format("%.2f", percent) + # @stars_status_map["star#{star_status.stars.to_i}".to_sym] = + # percent_m.to_s + "%" + #end #是否已经进行过评价 + temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{@homework.id} AND rater_id = #{User.current.id}").first + @m_score = temp.nil? ? 0:temp.stars @has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0 #是否开启互评功能 - @is_evaluation = @homework.bid.is_evaluation == 1 || @homework.bid.is_evaluation == nil - @limit = 10 - @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") - + #@is_evaluation = @homework.bid.is_evaluation == 1 || @homework.bid.is_evaluation == nil + #@limit = 10 + #@jours留言 is null条件用以兼容历史数据 + @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") + @cur_page = params[:cur_page] || 1 + @cur_type = params[:cur_type] || 5 + @jour = paginateHelper @jours,5 + #@feedback_count = @jours.count + #@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + #@offset ||= @feedback_pages.offset + #@jour = @jours[@offset, @limit] + #@comprehensive_evaluation教师评论 + #@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1").order("created_on DESC") + teachers = searchTeacherAndAssistant @course + @comprehensive_evaluation = [] + teachers.each do|teacher| + temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first + @comprehensive_evaluation << temp if temp + end + #@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id in #{convert_array(teachers)}").order("created_on DESC") + #@anonymous_comments 匿评 + #@anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2").order("created_on DESC") + annymous_users = @homework.homework_evaluations.map(&:user) + unless annymous_users.nil? || annymous_users.count == 0 + @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in #{convert_array(annymous_users)}").order("created_on DESC") + end @totle_score = score_for_homework @homework @teaher_score = teacher_score_for_homework @homework + + is_student = is_cur_course_student @homework.bid.courses.first + is_teacher = is_course_teacher User.current,@homework.bid.courses.first + @is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评 + if !User.current.member_of_course?(@homework.bid.courses.first) + @is_comprehensive_evaluation = 3 #留言 + elsif is_student && @is_anonymous_comments && !@has_evaluation#是学生且开启了匿评且未进行评分 + @is_comprehensive_evaluation = 2 #匿评 + elsif is_student && @is_anonymous_comments && @has_evaluation #是学生且开启了匿评,但已评分 + @is_comprehensive_evaluation = 2 #匿评 + elsif is_student && !@is_anonymous_comments #是学生未开启匿评 + @is_comprehensive_evaluation = 3 #留言 + elsif is_teacher + @is_comprehensive_evaluation = 1 #教师评论 + else + @is_comprehensive_evaluation = 3 + end + + respond_to do |format| + format.html + format.js + end else render_403 :message => :notice_not_authorized end @@ -260,7 +453,30 @@ class HomeworkAttachController < ApplicationController #删除留言 def destroy_jour - @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) + + @homework = HomeworkAttach.find(params[:jour_id]) + @journal_destroyed = JournalsForMessage.find(params[:object_id]) + @is_comprehensive_evaluation = @journal_destroyed.is_comprehensive_evaluation + @journal_destroyed.destroy + if @is_comprehensive_evaluation == 3 + @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") + @jour = paginateHelper @jours,5 + elsif @is_comprehensive_evaluation == 2 + annymous_users = @homework.homework_evaluations.map(&:user) + unless annymous_users.nil? || annymous_users.count == 0 + @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in #{convert_array(annymous_users)}").order("created_on DESC") + end + elsif @is_comprehensive_evaluation == 1 + teachers = searchTeacherAndAssistant @course + @comprehensive_evaluation = [] + teachers.each do|teacher| + temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first + @comprehensive_evaluation << temp if temp + end + end + + + respond_to do |format| format.js end @@ -270,16 +486,53 @@ class HomeworkAttachController < ApplicationController def addjours @homework = HomeworkAttach.find(params[:jour_id]) @add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation] - @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") + if @add_jour.is_comprehensive_evaluation == 3 + @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") + @jour = paginateHelper @jours,5 + elsif @add_jour.is_comprehensive_evaluation == 2 + annymous_users = @homework.homework_evaluations.map(&:user) + unless annymous_users.nil? || annymous_users.count == 0 + @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in #{convert_array(annymous_users)}").order("created_on DESC") + end + elsif @add_jour.is_comprehensive_evaluation == 1 + teachers = searchTeacherAndAssistant @homework.bid.courses.first + @comprehensive_evaluation = [] + teachers.each do|teacher| + temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first + @comprehensive_evaluation << temp if temp + end + end + + + #@limit = 10 + #@feedback_count = @jours.count + #@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + #@offset ||= @feedback_pages.offset + #@jour = @jours[@offset, @limit] + #@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") @totle_score = score_for_homework @homework @teaher_score = teacher_score_for_homework @homework + stars_reates = @homework. rates(:quality) + is_student = is_cur_course_student @homework.bid.courses.first + is_teacher = is_course_teacher User.current,@homework.bid.courses.first + @has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0 + @is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评 + if !User.current.member_of_course?(@homework.bid.courses.first) + @is_comprehensive_evaluation = 3 #留言 + elsif is_student && @is_anonymous_comments && !@has_evaluation#是学生且开启了匿评且未进行评分 + @is_comprehensive_evaluation = 2 #匿评 + elsif is_student && @is_anonymous_comments && @has_evaluation #是学生且开启了匿评,但已评分 + @is_comprehensive_evaluation = 3 #留言 + elsif is_student && !@is_anonymous_comments #是学生未开启匿评 + @is_comprehensive_evaluation = 3 #留言 + elsif is_teacher + @is_comprehensive_evaluation = 1 #教师评论 + else + @is_comprehensive_evaluation = 3 + end + + respond_to do |format| format.js end @@ -321,6 +574,7 @@ class HomeworkAttachController < ApplicationController end end + private #验证是否显示课程 def can_show_course @first_page = FirstPage.find_by_page_type('project') @@ -328,5 +582,51 @@ class HomeworkAttachController < ApplicationController render_404 end end + + def find_bid_and_course + @bid = Bid.find(params[:bid_id]) + @course = @bid.courses.first + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_course_by_bid_id + @bid = Bid.find(params[:id]) + @course = @bid.courses.first + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_course_by_hoemwork_id + @homework = HomeworkAttach.find(params[:id]) + @bid = @homework.bid + @course = @bid.courses.first + rescue ActiveRecord::RecordNotFound + render_404 + end + + #获取课程的老师列表 + def find_course_teachers course + teachers = "(" + teacher_members = searchTeacherAndAssistant(course) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + teachers + end + + #获取作业教师评分所占比例 + def get_teacher_proportion bid + if bid.proportion + teacher_proportion = bid.proportion * 1.0 / 100 + else + teacher_proportion = 1.0 + end + teacher_proportion + end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bf0717aae..47c8107ce 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -424,10 +424,10 @@ class ProjectsController < ApplicationController end - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, @page - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] + #@feedback_count = @jours.count + #@feedback_pages = Paginator.new @feedback_count, @limit, @page + #@offset ||= @feedback_pages.offset + @jour = paginateHelper @jours,10 @state = false @base_courses_tag = @project.project_type diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7e6e3d04a..9b2e5990a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -280,11 +280,11 @@ class UsersController < ApplicationController fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false) end - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] + #@limit = 10 + #@feedback_count = @jours.count + #@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + #@offset ||= @feedback_pages.offset + @jour = paginateHelper @jours,10 @state = false end # end diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index c6a5d2819..89fa0e1dc 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -27,11 +27,7 @@ class WordsController < ApplicationController end end @jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] + @jour = paginateHelper @jours,10 respond_to do |format| # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} @@ -56,6 +52,7 @@ class WordsController < ApplicationController reply_user_id = params[:reference_user_id] reply_id = params[:reference_message_id] # 暂时不实现 content = params[:user_notes] + @show_name = params[:show_name] == "true" options = {:user_id => author_id, :status => true, :m_parent_id => parent_id, @@ -82,7 +79,12 @@ class WordsController < ApplicationController def destroy @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) - + if @journal_destroyed.jour_type == "Bid" + @bid = Bid.find(@journal_destroyed.jour_id) + end + if @bid + @jours_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count + end respond_to do |format| format.js #format.api { render_api_ok } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 799316c47..8544b2cf3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -127,7 +127,8 @@ module ApplicationHelper # * :text - Link text (default to attachment filename) # * :download - Force download (default: false) def link_to_short_attachment(attachment, options={}) - text = h(truncate(options.delete(:text) || attachment.filename, length: 23, omission: '...')) + length = options[:length] ? options[:length]:23 + text = h(truncate(options.delete(:text) || attachment.filename, length: length, omission: '...')) route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path html_options = options.slice!(:only_path) url = send(route_method, attachment, attachment.filename, options) @@ -1892,5 +1893,64 @@ module ApplicationHelper content_tag(:ul, logos.join("").html_safe, :class => ul_class.to_s).html_safe end + def sort_homework_path(bid, sort, direction) + case self.action_name + when 'show_courseEx' + get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: 'asc') + when 'get_not_batch_homework' + get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) + when 'get_batch_homeworks' + get_batch_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) + when 'get_homeworks' + get_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) + else + '#' + end + end + def anonymous_comment_link(bid, course) + link = case bid.comment_status + when 0 + confirm_info = "开启匿评后学生将不能对作业进行提交、修改、删除等操作\n" + confirm_info += anonymous_comment_notice(bid,course) + confirm_info += '是否确定开启匿评?' + link_to '启动匿评', start_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, :confirm => confirm_info, disable_with: '加载中...' + when 1 + confirm_info = "关闭匿评后所有同学将不能继续进行匿评,且将公开已提交作业列表\n" + confirm_info += anonymous_comment_notice(bid,course) + confirm_info += '是否确定关闭匿评?' + link_to '关闭匿评', stop_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true, :confirm => confirm_info + when 2 + '匿评结束' + end + content_tag('span', link, id: "#{bid.id}_anonymous_comment") + end + + def anonymous_comment_notice(bid, course) + case bid.comment_status + when 0 + @student_size ||= searchStudent(course).size + @homework_size = bid.homeworks.size + percent = @homework_size.to_f / (@student_size == 0 ? 1 : @student_size) + confirm_info = "目前#{@student_size}个学生,总共提交了#{@homework_size}份作业,占#{number_to_percentage(percent * 100, precision: 1)}\n" + when 1 + @homework_evaluations = 0 + bid.homeworks.map { |homework| @homework_evaluations += homework.homework_evaluations.count} + teachers = "(" + teacher_members = searchTeacherAndAssistant(course) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + @has_evaluations = 0 + bid.homeworks.map { |homework| @has_evaluations += homework.rates(:quality).where("seems_rateable_rates.rater_id not in #{teachers}").count} + + percent = @has_evaluations.to_f / (@homework_evaluations == 0 ? 1 : @homework_evaluations) + confirm_info = "目前总共分配了#{@homework_evaluations}份匿评作业,已评价#{@has_evaluations}份作业,占#{number_to_percentage(percent * 100, precision: 1)}\n" + end + confirm_info + end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 1afb94220..ac22ed412 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -343,8 +343,7 @@ module CoursesHelper end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid - cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,bid.id) - cur_user_homework + bid.homeworks.where("user_id = ?",User.current) end #判断当前用户对指定作业是否已经评价过 @@ -394,10 +393,7 @@ module CoursesHelper #获取作业的教师评分 #多个教师只获取一份教师评分 def teacher_score_for_homework homework - members = searchTeacherAndAssistant(homework.bid.courses.first)#searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first - #if member.nil? - # return "0.00" - #end + members = searchTeacherAndAssistant(homework.bid.courses.first) teacher_ids = [] members.each do |user| teacher_ids << user.user_id @@ -407,7 +403,7 @@ module CoursesHelper teacher_stars.each do |star| teacher_stars_count = teacher_stars_count + star.stars end - return format("%.2f",teacher_stars_count) + return format("%.2f",teacher_stars.count > 0 ? teacher_stars_count/teacher_stars.count : 0) end #获取指定项目的得分 @@ -479,6 +475,17 @@ module CoursesHelper type << option2 type end + + def cur_course_term + month = Time.now.month + if month >= 9 || month < 3 + term = "秋季学期" + else + term = "春季学期" + end + term + end + #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb index 3510dc783..750a71f6a 100644 --- a/app/helpers/homework_attach_helper.rb +++ b/app/helpers/homework_attach_helper.rb @@ -74,4 +74,44 @@ module HomeworkAttachHelper end type end + + #判断指定用户是不是已经赞过该作业 + def is_praise_homework user_id, obj_id + PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'HomeworkAttach'").empty? + end + + #获取赞的总数 + def praise_homework_count obj_id + PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'HomeworkAttach'").count + end + + #获取用户对作业的评分 + def get_homework_score user, homework + seems_rateable_rate = HomeworkAttach.find_by_sql("SELECT * FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{homework.id} AND rater_id = #{user.id}") + seems_rateable_rate.nil? || seems_rateable_rate.count == 0 ? 0:seems_rateable_rate[0].stars + end + + def convert_array array + ary = "(" + if array.nil? || array.count == 0 + return "()" + end + array.length.times do |i| + if i == array.length - 1 + ary += array[i].id.to_s + ")" + else + if !(array[i].nil? || array[i].id.nil? || array[i].id.to_s == "") + ary += array[i].id.to_s + "," + end + end + end + #array.each do |member| + # if member == array.last + # ary += member.id.to_s + ")" + # else + # ary += member.id.to_s + "," + # end + #end + ary + end end \ No newline at end of file diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb index 5a161dc85..e987367ad 100644 --- a/app/helpers/stores_helper.rb +++ b/app/helpers/stores_helper.rb @@ -138,7 +138,7 @@ module StoresHelper return [link_to('unkown', '#')] end bid_list = link_to l(:label_homework), homework_course_path(bid.courses.first) - bid_item = link_to bid.name, respond_path(bid) + bid_item = link_to bid.name, course_for_bid_path(bid) return project_link(bid.courses.first).push(bid_list, bid_item) else xxx diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 166dfd0ec..298331c69 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -99,7 +99,7 @@ module WatchersHelper # 主讲教师不允许退出课程 return '' if user.id == course.tea_id || course.is_public == 0 joined = user.member_of_course?(course) - text = joined ? l(:label_exit_course) : l(:label_join_course) + text = joined ? l(:label_exit_course) : l(:label_new_join) url_t = join_path(:object_id => course.id) url_f = try_join_path(:object_id => course.id) method = joined ? 'delete' : 'post' diff --git a/app/models/bid.rb b/app/models/bid.rb index bc00a8460..88014477b 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -28,6 +28,7 @@ class Bid < ActiveRecord::Base has_many :homework_for_courses, :dependent => :destroy has_many :courses, :through => :homework_for_courses, :source => :course has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy + has_many :homework_evaluations, :through => :homeworks has_many :join_in_contests, :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy # has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}" diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index 99d540bd1..e18e254cb 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -10,6 +10,7 @@ class HomeworkAttach < ActiveRecord::Base has_many :users, :through => :homework_users seems_rateable :allow_update => true, :dimensions => :quality belongs_to :project + has_many :homework_evaluations, :dependent => :destroy safe_attributes "bid_id", "user_id" diff --git a/app/models/homework_evaluation.rb b/app/models/homework_evaluation.rb new file mode 100644 index 000000000..044d0155c --- /dev/null +++ b/app/models/homework_evaluation.rb @@ -0,0 +1,9 @@ +class HomeworkEvaluation < ActiveRecord::Base + attr_accessible :homework_attach_id, :user_id + + belongs_to :homework_attach + belongs_to :user + + validate :user, presence: true + validate :homework_attach, presence: true +end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 20e0c15f4..4819cd253 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -14,6 +14,7 @@ class JournalsForMessage < ActiveRecord::Base "is_readed", # 留言是否已读 "m_reply_count", # 留言的回复数量 "m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) + "is_comprehensive_evaluation" # 1 教师评论、2 匿评、3 留言 acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC" belongs_to :project, diff --git a/app/models/mailer.rb b/app/models/mailer.rb index f6c5e1a9e..a7f850766 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -42,7 +42,7 @@ class Mailer < ActionMailer::Base @url = case journals_for_message.jour.class.to_s.to_sym # 判断留言的对象所属类型 when :Bid - respond_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}") + course_for_bid_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}") when :Project return -1 if journals_for_message.jour.project_type == Project::ProjectType_project project_feedback_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}") diff --git a/app/models/user.rb b/app/models/user.rb index 0bb359812..bbee7f763 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -75,6 +75,7 @@ class User < Principal has_many :homework_users has_many :homework_attaches, :through => :homework_users + has_many :homework_evaluations has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index 52050ee06..c97da6d66 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -27,25 +27,28 @@ // file.click(); // } - -<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> - -<%= button_tag "浏览", :type=>"button", :onclick=>"_file.click()",:onmouseover => 'this.focus()' %> -<%= file_field_tag 'attachments[dummy][file]', - :id => '_file', - :class => 'file_selector', - :multiple => true, - :onchange => 'addInputFiles(this);', - :style => 'display:none', - :data => { - :max_file_size => Setting.attachment_max_size.to_i.kilobytes, - :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), - :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, - :upload_path => uploads_path(:format => 'js'), - :description_placeholder => l(:label_optional_description) - } %> -<%= l(:label_no_file_uploaded)%> -(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) + + <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> + + <%= button_tag "浏览", :type=>"button", :onclick=>"_file.click()",:onmouseover => 'this.focus()' %> + <%= file_field_tag 'attachments[dummy][file]', + :id => '_file', + :class => 'file_selector', + :multiple => true, + :onchange => 'addInputFiles(this);', + :style => 'display:none', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => uploads_path(:format => 'js'), + :description_placeholder => l(:label_optional_description) + } %> + + <%= l(:label_no_file_uploaded)%> + + (<%= l(:label_max_size) %>: + <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) <% content_for :header_tags do %> diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index d5359185e..2954adbcb 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -1,8 +1,13 @@ -
+
<% for attachment in attachments %>

- - <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + + <% if options[:length] %> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true,:length => options[:length] -%> + <% else %> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <% end %> + <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), @@ -12,9 +17,10 @@ :filename => attachment.filename%> <% end %> - <%= h(truncate(" - #{attachment.description}", length: 15, omission: '...')) unless attachment.description.blank? %> + <%= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>) + <% if options[:deletable] %> <% if attachment.container_type == 'HomeworkAttach' %> <%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id}, @@ -32,6 +38,10 @@ :title => l(:button_delete) %> <% end %> <% end %> + <% if options[:wrap] %> +
+   + <% end %> <% if options[:author] %> <%= link_to h(truncate(attachment.author.name, length: 10, omission: '...')),user_path(attachment.author) %>, diff --git a/app/views/bids/_alert_anonyoms.html.erb b/app/views/bids/_alert_anonyoms.html.erb new file mode 100644 index 000000000..e533048f5 --- /dev/null +++ b/app/views/bids/_alert_anonyoms.html.erb @@ -0,0 +1,90 @@ + + + + 开启匿评功能 + + + + + + +

+
+ <% if @bid.comment_status == 0%> +

开启匿评功能

+

+ 开启匿评后学生将不能对作业进行 + 提交、修改、删除 + 等操作,目前有 + <%= totle_size%>个 + 学生,共提交了 + <%= cur_size %> + 份作业,占 + <%= percent %>%, + 是否确定开启匿评? +

+ <% elsif @bid.comment_status == 1 %> +

关闭匿评功能

+

+ 关闭匿评后学生将不能对作业进行 + 匿评 + ,且作业列表将会 + 公开, + 目前分配了 + <%= totle_size%>份 + 匿评作业,已评了 + <%= cur_size %> + 份作业,占 + <%= percent %>%, + 是否确定关闭匿评? +

+ <% end %> + +
+
+ + + diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index d452b6d53..73a9bc6bd 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -5,94 +5,157 @@ <% else %> <% bids.each do |bid|%> - -
<%= link_to(image_tag(url_to_avatar(bid.author), :class => 'avatar'), user_path(bid.author), :class => "avatar") %> - - - + + +
<%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author)) %> - <%= 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 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) %> - <% else %> - <%= l(:lable_has_commit_homework)%> +
+ <%= link_to(image_tag(url_to_avatar(bid.author), :class => 'avatar'), user_path(bid.author), :class => "avatar") %> + + + + - - - - - - - - - - - + + <%= link_to( + l(:button_edit), + {:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id}, + :class => 'icon icon-edit' + ) %> + <%#= link_to( + l(:button_delete), + {:action => 'homework_destroy', :controller=>'bids', :course_id => bid.id}, + :method => :post, + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'icon icon-del' + ) %> + <% end %> + + + + + + + + + + + + + + <%= l(:label_create_time) %> + :  + <%=format_time bid.created_on %> + + + <%= l(:field_deadline) %> + :  + <%=bid.deadline %> + + -
+ + <%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author)) %> + + + <%= l(:label_user_create_project_homework) %> + + + <%= link_to(bid.name, course_for_bid_path(bid), :class => 'bid_path') %> + + + <% if User.current.logged? && is_cur_course_student(@course) %> + <% cur_user_homework = cur_user_homework_for_bid(bid) %> + <% if cur_user_homework!= nil && cur_user_homework.empty? %> + <%= link_to l(:label_commit_homework),new_exercise_book_path(bid) %> + <% else %> + + <%= l(:lable_has_commit_homework)%> + + <% end %> + <% end %> + <% if (User.current.admin?||User.current.id==bid.author_id) %> + + <% case bid.comment_status %> + <% when 0 %> + <%= link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...' %> + <% when 1 %> + <%= link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true %> + <% when 2 %> + 匿评结束 <% end %> - <% end %> - <% if (User.current.admin?||User.current.id==bid.author_id) %> - <%= link_to( - l(:button_edit), - {:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id}, - :class => 'icon icon-edit' - ) %> - <%= link_to( - l(:button_delete), - {:action => 'homework_destroy', :controller=>'bids', :course_id => bid.id}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'icon icon-del' - ) %> - <% end %> -
- <% bidding_project = bid.biding_projects.all - temp = [] - bidding_project.each do |pro| - if pro.project && pro.project.project_status - temp << pro - end - temp - end - %> - <% if bid.homework_type == 1%> - <%= 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, course_for_bid_path(bid.id) %>) - <% end %> - <%= l(:label_x_responses, :count => bid.commit) %>(<%= link_to bid.commit, respond_path(bid) %>) - - <% if betweentime(bid.deadline) < 0 %> - <%= l(:label_commit_limit)%> - <% else %> - <% if betweentime(bid.deadline) < 3 %> - <%= l(:label_commit_ar) %> - <% else %> - <% end %> - - - <% end %> -
<% if bid.reward_type.nil? or bid.reward_type == 1 %> <%= l(:label_bids_reward_method) %><%= l(:label_call_bonus) %> <%= l(:label_RMB_sign) %> - <%= bid.budget%> <% elsif bid.reward_type == 2 %> <%= l(:label_bids_reward_method) %><%= bid.budget%> - <% else %> - - <% end %>
- <%#= bid.description %> - <%= textilizable bid, :description %> -
+ + <% bidding_project = bid.biding_projects.all + temp = [] + bidding_project.each do |pro| + if pro.project && pro.project.project_status + temp << pro + end + temp + end + %> + <% if bid.homework_type == 1%> + <%= 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, course_for_bid_path(bid.id) %> + ) + <% end %> + + + <%= l(:label_students_responses) %> + ( + + <%= bid.commit.nil? ? 0 : bid.commit %> + + ) + + + <% if betweentime(bid.deadline) < 0 %> + + <%= l(:label_commit_limit)%> + + <% else %> + <% if betweentime(bid.deadline) < 3 %> + + <%= l(:label_commit_ar) %> + + <% end %> + <% end %> + +
+ <% if bid.reward_type.nil? or bid.reward_type == 1 %> + + <%= l(:label_bids_reward_method) %> + + <%= l(:label_call_bonus) %> +   + <%= l(:label_RMB_sign) %> + <%= bid.budget%> + + + <% elsif bid.reward_type == 2 %> + + <%= l(:label_bids_reward_method) %> + + <%= bid.budget%> + + + <% end %> +
+ + <%= textilizable bid, :description %> + +
- <%= l(:label_create_time) %> :  <%=format_time bid.created_on %> <%= l(:field_deadline) %> :  <%=bid.deadline %> -
- <% end %> <% end %>