diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index a22012390..5ee3d4823 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -15,7 +15,7 @@ class BidsController < ApplicationController before_filter :can_show_contest,only: [] #Ended by young before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork, - :show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings] + :show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings] # added by fq before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest] # end @@ -48,7 +48,7 @@ class BidsController < ApplicationController format.js end end - + def index @project_type = params[:project_type] @@ -57,8 +57,8 @@ class BidsController < ApplicationController @offset, @limit = api_offset_and_limit({:limit => 10}) if @project_type == '1' @bids = Bid.visible.where('reward_type = ?', 3) - # elsif - # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4) + # elsif + # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4) else @bids = Bid.visible.where('reward_type = ?', 1) end @@ -71,33 +71,33 @@ class BidsController < ApplicationController #added by nie if params[:bid_sort_type].present? case params[:bid_sort_type] - when '0' - unless @offset == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.offset(@offset).limit(limit).all.reverse - end - @s_state = 0 - when '1' - unless @offset == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse - end - @s_state = 1 - when '2' - unless @offset == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - end - @s_state = 0 + when '0' + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.offset(@offset).limit(limit).all.reverse + end + @s_state = 0 + when '1' + unless @offset == 0 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse + end + @s_state = 1 + when '2' + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + end + @s_state = 0 end else unless @offset == 0 @@ -109,7 +109,7 @@ class BidsController < ApplicationController end @s_state = 1 end - #end + #end end #huang def contest @@ -130,33 +130,33 @@ class BidsController < ApplicationController #added by nie if params[:contest_sort_type].present? case params[:contest_sort_type] - when '0' - unless @offset == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.offset(@offset).limit(limit).all.reverse - end - @s_state = 0 - when '1' - unless @offset == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse - end - @s_state = 1 - when '2' - unless @offset == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - end - @s_state = 0 + when '0' + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.offset(@offset).limit(limit).all.reverse + end + @s_state = 0 + when '1' + unless @offset == 0 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse + end + @s_state = 1 + when '2' + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + end + @s_state = 0 end else unless @offset == 0 @@ -168,7 +168,7 @@ class BidsController < ApplicationController end @s_state = 1 end - #end + #end end def fork @@ -176,7 +176,7 @@ class BidsController < ApplicationController @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) @membership.each do |membership| if membership.project.project_type == 1 - @courses << membership.project + @courses << membership.project end end end @@ -229,12 +229,12 @@ class BidsController < ApplicationController layout_file = '' case @bid.reward_type when 3 - html_title(l(:label_question_student)) - layout_file = 'base_homework' - when 1 - layout_file = 'base_bids' - else - layout_file = 'base_contest' + html_title(l(:label_question_student)) + layout_file = 'base_homework' + when 1 + layout_file = 'base_bids' + else + layout_file = 'base_contest' end format.html { render :layout => layout_file @@ -242,7 +242,7 @@ class BidsController < ApplicationController format.api end end - + def join_in_contest if @bid.reward_type == 2 && params[:course_password] == @bid.password JoinInContest.create(:user_id => User.current.id, :bid_id => @bid.id) @@ -250,49 +250,49 @@ class BidsController < ApplicationController else @state = 1 end - + respond_to do |format| # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} # TO_DO format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} } end end - + def unjoin_in_contest - + joined = JoinInContest.where('bid_id = ? and user_id = ?', @bid.id, User.current.id) - + joined.each do |join| join.delete end - + respond_to do |format| # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} } end end - + def new_join # added by fq end - + # added by bai 增加了参与者和竞赛设置 def show_participator render :layout => 'base_contest' - + end - + def settings - if @bid.author.id == User.current.id - if @bid.reward_type == 2 - @contest = Bid.find_by_reward_type(@bid.reward_type) - render :layout => 'base_contest' - end - else - render_403 :message => :notice_not_contest_setting_authorized - end + if @bid.author.id == User.current.id + if @bid.reward_type == 2 + @contest = Bid.find_by_reward_type(@bid.reward_type) + render :layout => 'base_contest' + end + else + render_403 :message => :notice_not_contest_setting_authorized + end end #end @@ -311,12 +311,12 @@ class BidsController < ApplicationController } 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 @@ -337,12 +337,12 @@ class BidsController < ApplicationController } 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 @@ -365,12 +365,12 @@ class BidsController < ApplicationController } 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 @@ -569,12 +569,12 @@ class BidsController < ApplicationController } 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 @@ -586,19 +586,19 @@ class BidsController < ApplicationController bid_message = params[:bid_for_save][:bid_message] if BidingProject.where("project_id = ? and bid_id = ?", project.id, @bid.id).size == 0 if BidingProject.cerate_bidding(@bid.id, project.id, bid_message) - + # added by bai type ==1 需求,type==2 竞赛, type==3 作业 if @bid.reward_type == 1 flash.now[:notice] = l(:label_bidding_succeed) - + elsif @bid.reward_type == 2 flash.now[:notice] = l(:label_bidding_contest_succeed) - + else @bid.reward_type == 3 - flash.now[:notice] = l(:label_bidding_homework_succeed) + flash.now[:notice] = l(:label_bidding_homework_succeed) end # end - + end else if @bid.reward_type == 3 @@ -609,11 +609,11 @@ class BidsController < ApplicationController end @bidding_project = @bid.biding_projects respond_to do |format| - # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} - # format.html + # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} + # format.html format.html { redirect_to :back } format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -647,7 +647,7 @@ class BidsController < ApplicationController @bid.set_commit(@feedback_count) respond_to do |format| format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -674,9 +674,9 @@ class BidsController < ApplicationController # @message_count = a_message.count respond_to do |format| - # format.html + # format.html format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -689,7 +689,7 @@ class BidsController < ApplicationController respond_to do |format| format.html { redirect_to :back } format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -698,11 +698,11 @@ class BidsController < ApplicationController def new @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id] if @jour - user = @jour.user - text = @jour.notes + user = @jour.user + text = @jour.notes else - user = @bid.author - text = @bid.description + user = @bid.author + text = @bid.description end # Replaces pre blocks with [...] text = text.to_s.strip.gsub(%r{
((.|\s)*?)}m, '[...]') @@ -711,7 +711,7 @@ class BidsController < ApplicationController @id = user.id rescue ActiveRecord::RecordNotFound render_404 - end + end ##新建需求 def new_bid @@ -743,15 +743,15 @@ class BidsController < ApplicationController end end -# added by bai - def update_contest + # added by bai + def update_contest @bid = Bid.find(params[:id]) @bid.name = params[:bid][:name] @bid.description = params[:bid][:description] @bid.reward_type = 2 @bid.budget = params[:bid][:budget] @bid.deadline = params[:bid][:deadline] - @bid.password = params[:bid][:password] + @bid.password = params[:bid][:password] @bid.author_id = User.current.id @bid.commit = 0 if @bid.save @@ -825,31 +825,31 @@ class BidsController < ApplicationController @course = Course.find_by_id(params[:course_id]) @course_id = @course.id #respond_to do |format| - # format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'} - # format.api { render_validation_errors(@bid) } - #end + # format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'} + # format.api { render_validation_errors(@bid) } + #end 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.allowed_to?(:as_teacher,@bid.courses.first)) - @course_id = params[:course_id] - respond_to do |format| - format.html { - @course = Course.find(params[:course_id]) - @user= User.find(User.current.id) - render :layout => 'base_courses' - } - end + def edit + @bid = Bid.find(params[:bid_id]) + if (User.current.admin?||User.current.allowed_to?(:as_teacher,@bid.courses.first)) + @course_id = params[:course_id] + respond_to do |format| + format.html { + @course = Course.find(params[:course_id]) + @user= User.find(User.current.id) + render :layout => 'base_courses' + } + end else render_403 end end - + def update @bid = Bid.find(params[:id]) @course = @bid.courses.first#Project.find(params[:course_id]) @@ -881,38 +881,38 @@ class BidsController < ApplicationController find_bid render :layout => 'base_homework' end - + def add_homework 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) # homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id) # homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) - - if hadcommittedhomework(User.current.id, @bid.id) == true - @homework_flag = l(:label_bidding_homework_committed) - else - @homework = HomeworkAttach.new - @homework.safe_attributes = params[:homeworkattach] - @homework.bid_id = @bid.id - @homework.user_id = User.current.id - @homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@homework) - - @homework_flag = if @homework.save - l(:label_bidding_homework_succeed) - else - l(:label_bidding_homework_failed) - end - - if @homework.attachments.empty? - @homework.delete - #flash[:error] = l(:no_attachmens_allowed) - @homework_flag = l(:no_attachmens_allowed) - # else - end - end + if hadcommittedhomework(User.current.id, @bid.id) == true + @homework_flag = l(:label_bidding_homework_committed) + else + @homework = HomeworkAttach.new + @homework.safe_attributes = params[:homeworkattach] + @homework.bid_id = @bid.id + @homework.user_id = User.current.id + @homework.save_attachments(params[:attachments]) + + render_attachment_warning_if_needed(@homework) + + @homework_flag = if @homework.save + l(:label_bidding_homework_succeed) + else + l(:label_bidding_homework_failed) + end + + if @homework.attachments.empty? + @homework.delete + #flash[:error] = l(:no_attachmens_allowed) + @homework_flag = l(:no_attachmens_allowed) + # else + end + end end - + @homework_list = @bid.homeworks respond_to do |format| format.html{ @@ -931,7 +931,7 @@ class BidsController < ApplicationController @member = [] @course.memberships.each do |member| unless (member.roles && Role.where('id = ? ', 3)).empty? - @member.push member + @member.push member end end if @bid.homework_type = 1 @@ -958,7 +958,7 @@ class BidsController < ApplicationController respond_to do |format| format.html { redirect_to :back } format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -970,7 +970,7 @@ class BidsController < ApplicationController respond_to do |format| format.html { redirect_to :back } format.js - #format.api { render_api_ok } + #format.api { render_api_ok } end end @@ -999,7 +999,7 @@ class BidsController < ApplicationController def manage end - + # 启动匿评 def start_anonymous_comment @bid = Bid.find(params[:id]) @@ -1031,7 +1031,7 @@ class BidsController < ApplicationController end end - def stop_anonymous_comment + def stop_anonymous_comment @bid = Bid.find(params[:id]) @bid.update_column('comment_status', 2) @@ -1039,7 +1039,7 @@ class BidsController < ApplicationController respond_to do |format| format.js end - end + end def alert_anonymous_comment @bid = Bid.find params[:id] @@ -1060,7 +1060,7 @@ class BidsController < ApplicationController end private - + def get_assigned_homeworks(homeworks, n, index) homeworks += homeworks homeworks[index + 1 .. index + n] diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ff211cde9..c4f083bee 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -33,28 +33,6 @@ class CoursesController < ApplicationController join = cs.join_course params,User.current @state = join[:state] course = join[:course] - #course = Course.find_by_id params[:object_id] - #if course - # if course_endTime_timeout? course - # @state = 2 - # else - # if User.current.member_of_course?(course) - # @state = 3 - # else - # if params[:course_password] == course.password - # members = [] - # members << Member.new(:role_ids => [10], :user_id => User.current.id) - # course.members << members - # StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) - # @state = 0 - # else - # @state = 1 - # end - # end - # end - #else - # @state = 4 - #end else @state = 5 #未登录 end @@ -71,25 +49,14 @@ class CoursesController < ApplicationController def unjoin if User.current.logged? - # - # @member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id) - # @member.first.destroy - # - # joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id]) - # joined.each do |join| - # join.delete - # end cs = CoursesService.new cs.exit_course params,User.current end - respond_to do |format| - # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} } end end - def join_private_courses respond_to do |format| @@ -119,36 +86,6 @@ class CoursesController < ApplicationController format.api { render_validation_errors(@course) } end end - #@course.safe_attributes = params[:course] - #@course.time = params[:time] - #@course.term = params[:term] - #@course.class_period = params[:class_period] - #if @course.save - # if params[:course][:is_public] == '0' - # course_status = CourseStatus.find_by_course_id(@course.id) - # course_status.destroy if course_status - # elsif params[:course][:is_public] == '1' - # course_status = CourseStatus.find_by_course_id(@course.id) - # course_status.destroy if course_status - # course_status = CourseStatus.create(:course_id => @course.id, :grade => 0) - # end - # - # respond_to do |format| - # format.html { - # flash[:notice] = l(:notice_successful_update) - # redirect_to settings_course_url(@course) - # } - # format.api { render_api_ok } - # end - #else - # respond_to do |format| - # format.html { - # settings - # render :action => 'settings' - # } - # format.api { render_validation_errors(@course) } - # end - #end end def new_join @@ -160,7 +97,6 @@ class CoursesController < ApplicationController def search courses_all = Course.all_course name = params[:name] - #(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank? if name.blank? @courses = [] @courses_all = [] @@ -347,22 +283,15 @@ class CoursesController < ApplicationController @score_sort_by = "desc" if params[:group_id] && params[:group_id] != "0" @group = CourseGroup.find(params[:group_id]) - @results = student_homework_score(@group.id,0, 0,"desc") @results = paginateHelper @results, 10 - - else page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) @results = student_homework_score(0,page_from, 10,"desc") @results = paginateHelper_for_members @results, 10 end - - - end - def member ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) @@ -383,12 +312,8 @@ class CoursesController < ApplicationController @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) @all_members = student_homework_score(0,page, 10,"desc") - @members = paginateHelper_for_members @all_members, 10 - - end - respond_to do |format| if params[:page] format.js @@ -396,12 +321,9 @@ class CoursesController < ApplicationController format.html {render :layout => 'base_courses'} end end - - # render :layout => 'base_courses' else render_403 end - end def export_course_member_excel @@ -415,20 +337,9 @@ class CoursesController < ApplicationController end def member_score_sort - - # @teachers= searchTeacherAndAssistant(@course) @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' - # @role = params[:role] - # @course_groups = @course.course_groups if @course.course_groups - # @show_serch = params[:role] == '2' @subPage_title = l :label_student_list - @render_file = 'member_list' - # @results = params[:result] if params[:result] - # unless @result.nil? - # @results = @result.reverse - # - # end - # @results = paginateHelper @results@score_sort_by = "desc" + @render_file = 'member_list' @is_remote = true @score_sort_by = params[:sort_by] if params[:sort_by] @search_name = params[:search_name] if params[:search_name] @@ -436,7 +347,6 @@ class CoursesController < ApplicationController if !@search_name.nil? if group_id == '0' page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by), @search_name) @result_count = @results.count @results = paginateHelper @results, 10 @@ -450,7 +360,6 @@ class CoursesController < ApplicationController if group_id == '0' page = params[:page].nil? ? 0 : (params['page'].to_i - 1) @results = student_homework_score(0,page, 10,@score_sort_by) - @results = paginateHelper_for_members @results, 10 else @group = CourseGroup.find(group_id) @@ -458,32 +367,25 @@ class CoursesController < ApplicationController @results = paginateHelper @results, 10 end end - end # 显示每个学生的作业评分详情 def show_member_score - @member_score = Member.find(params[:member_id]) if params[:member_id] respond_to do |format| format.html {render :layout => 'course_base'} format.js - end - end def handle_course courses, activities course_activity_count_array=activities.values() - course_array=[] i=0; courses.each do |course| course_array[i]=course i=i+1 end - courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array) - return courses end @@ -522,57 +424,6 @@ class CoursesController < ApplicationController format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } end end - #if User.current.user_extensions.identity - # @course = Course.new - # @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s - # @course.safe_attributes = params[:course] - # @course.tea_id = User.current.id - # # added by bai - # @course.term = params[:term] - # @course.time = params[:time] - # #@course.school_id = params[:occupation] - # @course.school_id = User.current.user_extensions.school_id - # @course.setup_time = params[:setup_time] - # @course.endup_time = params[:endup_time] - # @course.class_period = params[:class_period] - #end - # - #@issue_custom_fields = IssueCustomField.sorted.all - #@trackers = Tracker.sorted.all - # - #if @course.save - # #unless User.current.admin? - # r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first - # m = Member.new(:user => User.current, :roles => [r]) - # m.project_id = -1 - # course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id) - # #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) - # if params[:course][:is_public] == '1' - # course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) - # end - # @course.members << m - # @course.course_infos << course - # #end - # respond_to do |format| - # format.html { - # flash[:notice] = l(:notice_successful_create) - # if params[:continue] - # redirect_to new_course_url(attrs, :course => '0') - # elsif params[:course_continue] - # redirect_to new_course_url(:course => '1') - # else - # redirect_to settings_course_url(@course, :course_type => 1) - # end - # } - # format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } - # end - # else - # #@course.destroy - # respond_to do |format| - # format.html { render :action => 'new', :layout => 'base' } #Added by young - # format.api { render_validation_errors(@course) } - # end - # end end def course @@ -590,54 +441,28 @@ class CoursesController < ApplicationController @course_count = @courses_all.count @course_pages = Paginator.new @course_count, per_page_option, params['page'] - - #gcm activity count - @course_activity_count=Hash.new - #count initialize @courses_all.each do |course| @course_activity_count[course.id]=0 end - - #@course_activity_count=get_course_activity @courses_all,@course_activity_count - #gcm end - - case params[:course_sort_type] when '0' @courses = @courses_all.order("created_on desc") @s_type = 0 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - when '1' @courses = @courses_all.order("course_ac_para desc") @s_type = 1 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - when '2' @courses = @courses_all.order("watchers_count desc") @s_type = 2 @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - - #gcm when '3' - - #gcm @course_activity_count=get_course_activity @courses_all,@course_activity_count - #gcmend - @courses=handle_course @courses_all,@course_activity_count @s_type = 3 @courses = @courses[@course_pages.offset, @course_pages.per_page] @@ -645,11 +470,7 @@ class CoursesController < ApplicationController @s_type = 0 @courses = @courses_all.order("created_on desc") @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - end respond_to do |format| @@ -657,9 +478,6 @@ class CoursesController < ApplicationController render :layout => 'base' } format.api { - # @offset, @limit = api_offset_and_limit - # @course_count = Course.visible.count - # @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all } format.atom { courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all @@ -668,20 +486,16 @@ class CoursesController < ApplicationController end end - def new @course_type = params[:course_type] ||= params[:course] @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all - @course = Course.new @course.safe_attributes = params[:course] month = Time.now.month - render :layout => 'base' end - def desc_sort_course_by_avtivity(activity_count, courses) return courses if activity_count.size<2 (activity_count.size-2).downto(0) do |i| @@ -762,22 +576,7 @@ class CoursesController < ApplicationController bids = bids.like(params[:name]) if params[:name].present? @bids = paginateHelper bids,10 @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) - # - # @offset, @limit = api_offset_and_limit({:limit => 10}) - # - # @bid_count = @bids.count - # @bid_pages = Paginator.new @bid_count, @limit, params['page'] - # - # @offset ||= @bid_pages.reverse_offset - # unless @offset == 0 - # @bids = @bids.offset(@offset).limit(@limit).all.reverse - # else - # limit = @bid_count % @limit - # if limit == 0 - # limit = 10 - # end - # @bids = @bids.offset(@offset).limit(limit).all.reverse - # end + @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) render :layout => 'base_courses' else render_403 @@ -853,26 +652,19 @@ class CoursesController < ApplicationController end def show - - # try to redirect to the requested menu item if params[:jump] && redirect_to_course_menu_item(@course, params[:jump]) return end - @users_by_role = @course.users_by_role if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) end - - @key = User.current.rss_key #新增内容 @days = Setting.activity_days_default.to_i - if params[:from] begin; @date_to = params[:from].to_date + 1; rescue; end end - has = { "show_course_files" => true, "show_course_news" => true, @@ -881,9 +673,7 @@ class CoursesController < ApplicationController "show_course_journals_for_messages" => true } @date_to ||= Date.today + 1 - # @date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date - #@date_from = @date_to - @days-1.years @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) # 决定显示所用用户或单个用户活动 @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, @@ -892,13 +682,11 @@ class CoursesController < ApplicationController @activity.scope_select {|t| has["show_#{t}"]} # modify by nwb # 添加私密性判断 - if User.current.member_of_course?(@course)|| User.current.admin? events = @activity.events(@days, @course.created_at) else events = @activity.events(@days, @course.created_at, :is_public => 1) end - # 无新动态时,显示老动态 if events.count == 0 if User.current.member_of_course?(@course)|| User.current.admin? @@ -907,21 +695,10 @@ class CoursesController < ApplicationController events = @activity.events(:is_public => 1) end end - - # @offset, @limit = api_offset_and_limit({:limit => 10}) - # @events_count = events.count - # @events_pages = Paginator.new @events_count, @limit, params['page'] - # @offset ||= @events_pages.offset - # events = events.slice(@offset,@limit) events = paginateHelper events,10 - @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} # documents @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' - # 这写变量发现没有用而且拖慢速度 - #@teachers= searchTeacherAndAssistant(@course) - #@canShowRealName = isCourseTeacher(User.current.id,@course) - if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) end @@ -951,10 +728,6 @@ class CoursesController < ApplicationController offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) page = 1 + offset / @limit end - - #@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| @@ -994,7 +767,6 @@ class CoursesController < ApplicationController end private - def allow_join course if course_endTime_timeout? course respond_to do |format| diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 62879f010..49d2ff9b5 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -694,16 +694,46 @@ module CoursesHelper end def bid_anonymous_comment bid - if bid.open_anonymous_evaluation == 1 && bid.homeworks.count >= 2 + if bid.open_anonymous_evaluation == 1 + if bid.homeworks.count >= 2 + case bid.comment_status + when 0 + link = link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit' + when 1 + link = link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit' + when 2 + link = "匿评结束".html_safe + end + else + link = "启动匿评".html_safe + end + else + link = "启动匿评".html_safe + end + link + end + + def student_new_homework bid + user_homework = cur_user_homework_for_bid bid + if user_homework && user_homework.empty? + link_to l(:label_commit_homework), new_exercise_book_path(bid),:class => 'fr mr10 work_edit' + else + "作业已交".html_safe + end + end + + def student_anonymous_comment bid + if bid.open_anonymous_evaluation == 1 case bid.comment_status when 0 - # 关闭匿评 - link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit' + "未开启匿评".html_safe when 1 - link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit' + "正在匿评中".html_safe when 2 - "匿评结束".html_safe + "匿评已结束".html_safe end + else + "未启用匿评".html_safe end end end diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index 034cbdf1a..8b22ea417 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -31,7 +31,7 @@