diff --git a/Gemfile b/Gemfile index 362be8642..70281fedf 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ gem 'ruby-ole' #gem 'email_verifier', path: 'lib/email_verifier' gem 'rufus-scheduler' #gem 'dalli', path: 'lib/dalli-2.7.2' -gem 'rails_kindeditor' +gem 'rails_kindeditor',path:'lib/rails_kindeditor' group :development do gem 'grape-swagger' #gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git' @@ -32,7 +32,7 @@ group :development do if RUBY_VERSION >= '2.0.0' gem 'pry-byebug' else - gem 'pry-debugger' + # gem 'pry-debugger' end gem 'pry-stack_explorer' gem 'better_errors', '~> 1.1.0' diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index a22012390..be97fdb6e 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,11 +176,12 @@ 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 + #将某个企业外包需求选为作业,目前此功能已放弃 def create_fork @homework = Bid.new @homework.name = params[:bid][:name] @@ -215,6 +216,7 @@ class BidsController < ApplicationController end end + #有两个路由链接到此方法:/bids/:id /calls/:id但是貌似这两个路由都不能访问。。方法作用有待确认 def show @user = @bid.author @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @@ -229,12 +231,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 +244,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,53 +252,44 @@ 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 + def new_join 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 - # 显示课程 + # 显示课程作业,但是好像已经废弃 def show_course bids = Bid.where('parent_id = ?', @bid.id) @courses = [] @@ -311,12 +304,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 +330,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 +358,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 @@ -459,9 +452,7 @@ class BidsController < ApplicationController 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)) - @user = @bid.author @bidding_project = @bid.biding_projects.all @@ -569,12 +560,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 +577,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 +600,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 +638,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 +665,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 +680,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 +689,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 +702,7 @@ class BidsController < ApplicationController @id = user.id rescue ActiveRecord::RecordNotFound render_404 - end + end ##新建需求 def new_bid @@ -743,15 +734,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 +816,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]) @@ -858,7 +849,7 @@ class BidsController < ApplicationController @bid.is_evaluation = params[:bid][:is_evaluation] @bid.proportion = params[:bid][:proportion] @bid.evaluation_num = params[:bid][:evaluation_num] - @bid.open_anonymous_evaluation = params[:bid][:open_anonymous_evaluation] + params[:bid][:open_anonymous_evaluation] ? @bid.open_anonymous_evaluation = 1 : @bid.open_anonymous_evaluation = 0 @bid.reward_type = 3 @bid.deadline = params[:bid][:deadline] @bid.budget = 0 @@ -881,38 +872,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) + @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 + @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 +922,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 +949,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 +961,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 +990,7 @@ class BidsController < ApplicationController def manage end - + # 启动匿评 def start_anonymous_comment @bid = Bid.find(params[:id]) @@ -1031,7 +1022,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 +1030,7 @@ class BidsController < ApplicationController respond_to do |format| format.js end - end + end def alert_anonymous_comment @bid = Bid.find params[:id] @@ -1060,7 +1051,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/boards_controller.rb b/app/controllers/boards_controller.rb index f797c7a2f..bdbbb8e37 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -66,15 +66,28 @@ class BoardsController < ApplicationController 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" @topic_count = @board.topics.count - @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] - @topics = @board.topics. - reorder("#{Message.table_name}.sticky DESC"). - includes(:last_reply). - limit(@topic_pages.per_page). - offset(@topic_pages.offset). - order(sort_clause). - preload(:author, {:last_reply => :author}). - all + if @project + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @topics = @board.topics. + reorder("#{Message.table_name}.sticky DESC"). + includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + order(sort_clause). + preload(:author, {:last_reply => :author}). + all + elsif @course + board_topics = @board.topics. + reorder("#{Message.table_name}.sticky DESC"). + includes(:last_reply). + # limit(@topic_pages.per_page). + # offset(@topic_pages.offset). + order(sort_clause). + preload(:author, {:last_reply => :author}). + all + @topics = paginateHelper board_topics,10 + end + @message = Message.new(:board => @board) #modify by nwb if @project diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f9ad609cc..ebdb18c08 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 = [] @@ -242,22 +178,19 @@ class CoursesController < ApplicationController def searchmembers @subPage_title = l :label_student_list - @render_file = 'member_list' - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' - @is_remote = true + @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' + # @is_remote = true @score_sort_by = "desc" q = "#{params[:name].strip}" - #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:incourse] - @results = searchmember_by_name(student_homework_score(0,0,0,"desc"), q) - + results = searchmember_by_name(student_homework_score(0,0,0,"desc"), q) elsif params[:ingroup] @group = CourseGroup.find(params[:search_group_id]) - @results = searchmember_by_name(student_homework_score(@group.id,0,0,"desc"), q) + results = searchmember_by_name(student_homework_score(@group.id,0,0,"desc"), q) end @is_remote = true - @result_count = @results.count - @results = paginateHelper @results, 10 + @result_count = results.count + @results = paginateHelper results, 10 @search_name = q end @@ -269,7 +202,7 @@ class CoursesController < ApplicationController group.course_id = @course.id group.save end - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @is_remote = true @course_groups = @course.course_groups @@ -303,17 +236,26 @@ class CoursesController < ApplicationController valid_attr = params[:valid] valid_value = params[:value] - - faker = CourseGroup.new + group_id = params[:group_id] + # faker = CourseGroup.new if valid_attr.eql?('name') - faker.name = valid_value - faker.course_id = params[:course_id] - faker.valid? - req[:valid] = faker.errors[:name].blank? - req[:message] = faker.errors[:name] + course = Course.find params[:course_id] + group_names = course.course_groups.map{|group| group.name unless group.id.to_s == group_id}.select{|group| !group.nil?} + if group_names.include?(valid_value) + req[:valid] = false + req[:message] = l(:modal_valid_unpassing) + else + req[:valid] = true + req[:message] = l(:modal_valid_passing) + end + # faker.name = valid_value + # faker.course_id = params[:course_id] + # faker.valid? + # req[:valid] = faker.errors[:name].blank? + # req[:message] = faker.errors[:name] end - req[:message] = l(:modal_valid_passing) if req[:message].blank? + # req[:message] = l(:modal_valid_passing) if req[:message].blank? render :json => req end def join_group @@ -341,35 +283,28 @@ class CoursesController < ApplicationController end def searchgroupmembers @subPage_title = l :label_student_list - @render_file = 'member_list' + @render_file = 'new_member_list' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true @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))) - @render_file = 'member_list' + @render_file = 'new_member_list' @score_sort_by = "desc" - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @role = params[:role].nil? ? '2':params[:role] @is_remote = true @course_groups = @course.course_groups if @course.course_groups @@ -383,12 +318,9 @@ 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") - + # @all_members = @course.members @members = paginateHelper_for_members @all_members, 10 - - end - respond_to do |format| if params[:page] format.js @@ -396,12 +328,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 +344,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 = 'new_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 +354,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 +367,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 +374,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 +431,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 +448,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 +477,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 +485,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 +493,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' + render :layout => 'new_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| @@ -758,22 +579,11 @@ class CoursesController < ApplicationController def homework if @course.is_public != 0 || User.current.member_of_course?(@course) || User.current.admin? - @offset, @limit = api_offset_and_limit({:limit => 10}) - @bids = @course.homeworks.order('deadline ASC') - @bids = @bids.like(params[:name]) if params[:name].present? - @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 + bids = @course.homeworks.order('created_on DESC') + 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)) + @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) render :layout => 'base_courses' else render_403 @@ -785,6 +595,7 @@ class CoursesController < ApplicationController @homework = Bid.new @homework.safe_attributes = params[:bid] @homework.open_anonymous_evaluation = 1 + @homework.deadline = (Time.now + 3600 * 24).strftime('%Y-%m-%d') if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] )) render :layout => 'base_courses' else @@ -848,26 +659,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, @@ -877,9 +681,7 @@ class CoursesController < ApplicationController "show_homeworks" => 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])) @author ||= @course.teacher # 决定显示所用用户或单个用户活动 @@ -889,13 +691,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? @@ -904,20 +704,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 @@ -947,10 +737,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| @@ -990,7 +776,6 @@ class CoursesController < ApplicationController end private - def allow_join course if course_endTime_timeout? course respond_to do |format| @@ -1021,38 +806,38 @@ class CoursesController < ApplicationController if groupid == 0 if nums == 0 sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id -AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id -UNION all -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND -students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) -) -GROUP BY members.user_id ORDER BY score #{score_sort_by}" + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND + students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" else sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id -AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id -UNION all -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND -students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) -) -GROUP BY members.user_id ORDER BY score #{score_sort_by} limit #{start_from}, #{nums}" + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND + students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by} limit #{start_from}, #{nums}" end else sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id - and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) - GROUP BY members.user_id -UNION all -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} -and members.course_group_id = #{groupid} AND -students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) -) -GROUP BY members.user_id ORDER BY score #{score_sort_by}" + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id + and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) + GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} + and members.course_group_id = #{groupid} AND + students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" end sql = ActiveRecord::Base.connection() homework_scores = Member.find_by_sql(sql_select) @@ -1068,7 +853,7 @@ GROUP BY members.user_id ORDER BY score #{score_sort_by}" #当加入,退出分班时查询分班的学生 def search_group_members group @subPage_title = l :label_student_list - @render_file = 'member_list' + @render_file = 'new_member_list' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true @score_sort_by = "desc" diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 64157ea42..c347ba6b8 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -1,7 +1,7 @@ # added by fq class ForumsController < ApplicationController layout "users_base" - + include ApplicationHelper # GET /forums # GET /forums.json before_filter :find_forum_if_available @@ -63,6 +63,9 @@ class ForumsController < ApplicationController respond_to do |format| if @memo.save + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@memo.id,1 + #end format.html { redirect_to (forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))), notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else @@ -163,6 +166,13 @@ class ForumsController < ApplicationController @forum = Forum.new(params[:forum]) @forum.creator_id = User.current.id if @forum.save + # Time 2015-03-24 17:07:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 2 对应的是 forum + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@forum.id,2 + #end respond_to do |format| format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index aaa99e417..54bcc0496 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -59,6 +59,20 @@ class MemosController < ApplicationController @memo.content = @quote + @memo.content respond_to do |format| if @memo.save + # Time 2015-03-24 14:47:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 1 对应的是 memo + if !params[:asset_id].nil? + ids = params[:asset_id].split(',') + ids.each do |id| + asset = Kindeditor::Asset.find(id.to_i) + asset.owner_id = @memo.id + asset.owner_type = 1 + asset.save + end + end + #end format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } format.json { render json: @memo, status: :created, location: @memo } else diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index d2a253c2a..b50b2720f 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -44,18 +44,35 @@ class MessagesController < ApplicationController end @reply_count = @topic.children.count - @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page - @replies = @topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC"). - limit(@reply_pages.per_page). - offset(@reply_pages.offset). - all + # @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page + # @replies = @topic.children. + # includes(:author, :attachments, {:board => :project}). + # reorder("#{Message.table_name}.created_on DESC"). + # limit(@reply_pages.per_page). + # offset(@reply_pages.offset). + # all @reply = Message.new(:subject => "RE: #{@message.subject}") if @course + messages_replies = @topic.children. + includes(:author, :attachments, {:board => :project}). + reorder("#{Message.table_name}.created_on DESC"). + #limit(@reply_pages.per_page). + #offset(@reply_pages.offset). + all + @replies = paginateHelper messages_replies,10 + @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => "base_courses"#by young else + @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page + @replies = @topic.children. + includes(:author, :attachments, {:board => :project}). + reorder("#{Message.table_name}.created_on DESC"). + limit(@reply_pages.per_page). + offset(@reply_pages.offset). + all + + @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => "base_projects"#by young end end @@ -76,6 +93,13 @@ class MessagesController < ApplicationController layout_file = @project ? 'base_projects' : 'base_courses' render :action => 'new', :layout => layout_file end + else + respond_to do |format| + format.html { + layout_file = @project ? 'base_projects' : 'base_courses' + render :layout => layout_file + } + end end end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index b44e8a348..617e56575 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -70,13 +70,13 @@ class NewsController < ApplicationController scope = @course ? @course.news.course_visible : News.course_visible @news_count = scope.count - @news_pages = Paginator.new @news_count, @limit, params['page'] - @offset ||= @news_pages.offset - @newss = scope.all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC", - :offset => @offset, - :limit => @limit) - + #@news_pages = Paginator.new @news_count, @limit, params['page'] + #@offset ||= scope_page.offset + scope_order = scope.all(:include => [:author, :course], + :order => "#{News.table_name}.created_on DESC") + # :offset => @offset, + # :limit => @limit) + @newss = paginateHelper scope_order,10 respond_to do |format| format.html { @news = News.new diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e9a27cf44..41876e041 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -340,7 +340,7 @@ class ProjectsController < ApplicationController @is_zhuce =false flash[:notice] = l(:notice_email_sent, :value => email) else - flash[:error] = l(:notice_registed_success, :value => email) + flash[:error] = l(:notice_registed_error, :value => email) @is_zhuce = true end respond_to do |format| diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 5bd5fb0e3..e26901320 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -73,7 +73,7 @@ class TagsController < ApplicationController @issues_results, @bids_results, @forums_results, - @attachments_results, + @attachments_results, @contests_results, @courses_results, @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) @@ -109,7 +109,7 @@ class TagsController < ApplicationController @issues_results, @bids_results, @forums_results, - @attachments_results, + @attachments_results, @contests_results, @courses_results, @open_source_projects_results= refresh_results(@obj_id,@show_flag) @@ -248,6 +248,8 @@ class TagsController < ApplicationController @obj = OpenSourceProject.find_by_id(@obj_id) when '9' @obj = Course.find_by_id(@obj_id) + when '10' + @obj = Attachment.find_by_id(@obj_id) else @obj = nil end @@ -315,6 +317,14 @@ class TagsController < ApplicationController when '8' @obj = OpenSourceProject.find_by_id(obj_id) @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) + when '10' + @obj = Attachment.find_by_id(obj_id) + + # modifed by Long Jun + # this is used to find the attachments that came from the same project and tagged with the same tag. + #@result = get_attachments_by_project_tag(selected_tags, @obj) + @result = get_attachments_by_tag(selected_tags) + @obj_pages, @attachments_results, @results_count = for_pagination(@result) when '9' then @obj = Course.find_by_id(obj_id) @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) @@ -380,7 +390,9 @@ class TagsController < ApplicationController when '8' return 'OpenSourceProject' when '9' - return 'Course' + return 'Course' + when '10' + return 'Attachment' else render_error :message => e.message return diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b4f54f075..c8168455c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,35 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + # Time 2015-03-24 15:27:29 + # Author lizanle + # Description 从硬盘上删除对应的资源文件 + def delete_kindeditor_assets_from_disk owner_id,owner_type + assets = Kindeditor::Asset.where(["owner_id = ? and owner_type = ?",owner_id,owner_type]) + if !assets.nil? && !assets.blank? + assets.all.each do |asset| + next if asset.nil? + filepath = File.join(Rails.root,"public","files","uploads", + asset[:created_at].to_s.gsub("+0800","").to_datetime.strftime("%Y%m").to_s, + asset[:asset].to_s) + File.delete(filepath) if File.exist?filepath + end + end + end + + # Time 2015-03-24 16:38:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 1 对应的是 memo + def update_kindeditor_assets_owner ids,owner_id,owner_type + ids.each do |id| + asset = Kindeditor::Asset.find(id.to_i) + asset.owner_id = owner_id + asset.owner_type = owner_type + asset.save + end + end + # Added by young # Define the course menu's link class # 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表 @@ -95,6 +124,20 @@ module ApplicationHelper end end + #重载上面方法,增加样式显示 + def link_to_user_header user,canShowRealName=false,options={} + if user.is_a?(User) + if canShowRealName + name = h(user.realname(options[:format])) + else + name = h(user.name(options[:format])) + end + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => options[:class] + else + h(user.to_s) + end + end + # Displays a link to +issue+ with its subject. # Examples: # @@ -256,7 +299,7 @@ module ApplicationHelper onclick = "$('##{id}').slideToggle(); " onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ") onclick << "return false;" - link_to(name, "#", :onclick => onclick) + link_to(name, "#", :onclick => onclick,:class => options[:class]) end def image_to_function(name, function, html_options = {}) @@ -1622,6 +1665,17 @@ module ApplicationHelper @public_forum = Forum.find(1) end + #获取用户未过期的课程 + def get_user_course user + courses_doing = [] + user.courses.each do |course| + if !course_endTime_timeout?(course) + courses_doing.push course + end + end + courses_doing + end + private def wiki_helper @@ -1847,7 +1901,7 @@ module ApplicationHelper def render_dynamic_nav home_link = link_to l(:field_homepage), {:controller => 'welcome', :action => 'index'} - home_link = "
+ <%= l(:label_totle)%><%= @obj_count%><%= l(:label_homework_count)%> +
+ <%= link_to( l(:label_course_homework_new), new_homework_course_path(@course), :class => 'problem_new_btn fl c_dorange') if @is_teacher %> +上传作业
- +<% @bids.each do |bid|%> +<%= l(:lebel_homework_commit)%> ( <%= link_to bid.homeworks.count, course_for_bid_path(bid.id), :class => 'c_red'%> )
+ <% if @is_teacher%> + <%= bid_anonymous_comment(bid)%> + <%= link_to(l(:button_edit),edit_bid_path(:course_id =>@course.id, :bid_id => bid.id), :class => "fr mr10 work_edit") %> + <% elsif @is_student%> + <%= student_anonymous_comment bid %> + <%= student_new_homework bid %> + <% end %> + + +-
- - <% @events_by_day.keys.sort.reverse.each do |day| %> -- <%= image_tag(url_to_avatar(e.event_author), :class => "avatar") %> - | -
-
|
-
- <%= image_tag(url_to_avatar(@user), :class => "avatar") %> - | -
-
|
-
- <%= image_tag(url_to_avatar(@user), :class => "avatar") %> - | -
-
|
-
<%= e.event_description %>
+
+ <%= l :label_activity_time %> : <%= format_activity_day(day) %><%= format_time(e.event_datetime, false) %>
+
+
+ <%= l :label_create_time %>: : <%= format_time(@course.created_at) %>
+
- <%= f.text_area :description, :required => true, :id => 'editor01' %> -
- - -- (<%= l(:label_forums_max_length) %>) -
-<%= f.text_field :subject, :required => true, :maxlength => 50%>
- <%= f.text_area :content, :required => true, :id => 'editor02' %> + <%= f.kindeditor :content, :required => true %>
- +(<%= l(:label_memos_max_length) %>)
diff --git a/app/views/homework_attach/_addjour.html.erb b/app/views/homework_attach/_addjour.html.erb index 78514daca..861ad10d3 100644 --- a/app/views/homework_attach/_addjour.html.erb +++ b/app/views/homework_attach/_addjour.html.erb @@ -53,7 +53,7 @@ :maxlength => 250 %> <%= f.text_field :reference_user_id, :style=>"display:none"%> diff --git a/app/views/homework_attach/_homework.html.erb b/app/views/homework_attach/_homework.html.erb index fca25e8ee..2b5c48cd4 100644 --- a/app/views/homework_attach/_homework.html.erb +++ b/app/views/homework_attach/_homework.html.erb @@ -26,7 +26,7 @@据说雷锋做完好事是从来不留名的呢,我们这次评分也不留名!!!但是,但是,您给的分数一定要公正哦,老天爷看不到,我们的系统可是清楚得很!
别怪我没告诉你,系统分配给你的作品不评价可是要扣分的哈!
- 匿名评分 - 冒着扣分的危险残忍拒绝 + 匿名评分 + 冒着扣分的危险残忍拒绝