diff --git a/.gitignore b/.gitignore index 2b9fa95fe..73b76dc34 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ public/api_doc/ /.metadata vendor/cache +/files +/public/images/avatars +/public/files diff --git a/Gemfile b/Gemfile index 48c5adc0e..976184793 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,11 @@ source 'http://ruby.taobao.org' unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' - gem 'rubyzip' - gem 'zip-zip' end +gem 'rubyzip' +gem 'delayed_job_active_record'#, :group => :production +gem 'daemons' gem 'grape', '~> 0.9.0' gem 'grape-entity' gem 'seems_rateable', '~> 1.0.13' @@ -23,7 +24,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 +33,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' @@ -58,8 +59,6 @@ group :test do #end end - # gem 'rspec-rails' , '2.13.1' - # gem 'guard-rspec','2.5.0' # Gems used only for assets and not required # in production environments by default. group :assets do diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index 8f7f0342f..4724b0bc0 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -41,7 +41,7 @@ module Mobile mount Apis::Comments #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) - #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? + #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? end end diff --git a/app/api/mobile/apis/auth.rb b/app/api/mobile/apis/auth.rb index fbec9a3b0..9e4cb1bc6 100644 --- a/app/api/mobile/apis/auth.rb +++ b/app/api/mobile/apis/auth.rb @@ -26,7 +26,7 @@ module Mobile present :data, {token: key.access_token, user: api_user}, using: Entities::Auth present :status, 0 else - raise 'Unauthorized.' + raise "无效的用户名或密码" end end diff --git a/app/api/mobile/apis/comments.rb b/app/api/mobile/apis/comments.rb index 2e84fe5a9..edc7bcf54 100644 --- a/app/api/mobile/apis/comments.rb +++ b/app/api/mobile/apis/comments.rb @@ -80,7 +80,7 @@ module Mobile end post do cs_params = { - memo: {:subject => params[:subject],:content => '该贴来自手机App意见反馈'}, + memo: {:subject => '该贴来自手机App意见反馈' ,:content => params[:subject]}, } cs = CommentService.new memo,message = cs.create_feedback cs_params, current_user diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 6d68d549a..08c7adf10 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -80,6 +80,10 @@ module Mobile class_period: params[:class_period] } course = ::Course.find(params[:course_id]) + # 如果没有传密码过来,那就把原来的密码给上,不然会不更新 + if params[:password].nil? || params[:password].blank? + cs_params[:course][:password] = course[:password] + end cs.edit_course_authorize(current_user,course) course = cs.edit_course(cs_params, course,current_user) present :data, course, with: Mobile::Entities::Course diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index b6d1db25c..063cfafae 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -14,7 +14,7 @@ module Mobile us = UsersService.new user = us.register params.merge(:password_confirmation => params[:password], :should_confirmation_password => true) - raise "register failed #{user.errors.full_messages}" if user.new_record? + raise "该邮箱已经被注册过了" if user.new_record? present :data, user, with: Mobile::Entities::User present :status, 0 diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 4c91738c1..520f73384 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -58,6 +58,7 @@ module Mobile end course_expose :current_user_is_member course_expose :current_user_is_teacher + course_expose :work_unit end end end diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index 1f52ae841..9112e7ec5 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -15,13 +15,13 @@ module Mobile when :img_url url_to_avatar(u) when :gender - u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender + u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender when :work_unit get_user_work_unit u when :location get_user_location u when :brief_introduction - u.user_extensions.brief_introduction + u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction end end end diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 2cf404ffb..f8d0f5dd1 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -88,9 +88,7 @@ class AccountController < ApplicationController # create a new token for password recovery token = Token.new(:user => user, :action => "recovery") if token.save - Thread.new do - Mailer.lost_password(token).deliver - end + Mailer.run.lost_password(token) flash[:notice] = l(:notice_account_lost_email_sent) redirect_to signin_url return @@ -228,7 +226,7 @@ class AccountController < ApplicationController user = User.find(params[:user]) if params[:user] token = Token.new(:user => user, :action => "register") if token.save - Mailer.register(token).deliver + Mailer.run.register(token) else yield if block_given? @@ -366,7 +364,7 @@ class AccountController < ApplicationController token = Token.new(:user => user, :action => "register") if user.save and token.save UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) - Mailer.register(token).deliver + Mailer.run.register(token) flash[:notice] = l(:notice_account_register_done) @@ -401,7 +399,7 @@ class AccountController < ApplicationController if user.save UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0) # Sends an email to the administrators - Mailer.account_activation_request(user).deliver + Mailer.run.account_activation_request(user) account_pending else yield if block_given? diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index f2c0eb056..8e70ed32c 100644 --- a/app/controllers/applied_project_controller.rb +++ b/app/controllers/applied_project_controller.rb @@ -13,7 +13,7 @@ class AppliedProjectController < ApplicationController @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id]) if @applieds.count == 0 appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) - Mailer.applied_project(appliedproject).deliver + Mailer.run.applied_project(appliedproject) @status = 2 else @status = 1 @@ -31,7 +31,7 @@ class AppliedProjectController < ApplicationController @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id]) if @applieds.count == 0 appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) - Mailer.applied_project(appliedproject).deliver + Mailer.run.applied_project(appliedproject) end #redirect_to project_path(params[:project_id]) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 23b080d94..d880ebe35 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -27,7 +27,7 @@ class AttachmentsController < ApplicationController accept_api_auth :show, :download, :upload require 'iconv' include AttachmentsHelper - + include ApplicationHelper def show respond_to do |format| @@ -65,36 +65,7 @@ class AttachmentsController < ApplicationController def download # modify by nwb # 下载添加权限设置 - candown = false - if @attachment.container.class.to_s != "HomeworkAttach" && (@attachment.container.has_attribute?(:project) || @attachment.container.has_attribute?(:project_id)) && @attachment.container.project - project = @attachment.container.project - candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1) - elsif @attachment.container.is_a?(Project) - project = @attachment.container - candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1) - elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board && - @attachment.container.board.project - project = @attachment.container.board.project - candown = User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1) - elsif (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) && @attachment.container.course - course = @attachment.container.course - candown = User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) - elsif @attachment.container.is_a?(Course) - course = @attachment.container - candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) - elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board && - @attachment.container.board.course - course = @attachment.container.board.course - candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) - elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3 - candown = true - elsif @attachment.container_type == "Bid" && @attachment.container && @attachment.container.courses.first - course = @attachment.container.courses.first - candown = User.current.member_of_course?(course) || (course.is_public == 1 && @attachment.is_public == 1) - else - - candown = @attachment.is_public == 1 - end + candown = attachment_candown @attachment if candown || User.current.admin? || User.current.id == @attachment.author_id @attachment.increment_download if stale?(:etag => @attachment.digest) @@ -108,7 +79,7 @@ class AttachmentsController < ApplicationController end rescue => e - redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" + redirect_to "http: //" + (Setting.host_name.to_s) +"/file_not_found.html" end #更新资源文件类型 @@ -349,6 +320,46 @@ class AttachmentsController < ApplicationController end end + def add_exist_file_to_projects + file = Attachment.find(params[:file_id]) + projects = params[:projects][:project] + @message = "" + projects.each do |project| + c = Project.find(project); + if project_contains_attachment?(c,file) + if @message && @message == "" + @message += l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + else + @message += "
" + l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + end + end + attach_copied_obj = file.copy + attach_copied_obj.tag_list.add(file.tag_list) # tag关联 + attach_copied_obj.container = c + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + @obj = c + @save_flag = attach_copied_obj.save + @save_message = attach_copied_obj.errors.full_messages + update_quotes attach_copied_obj + end + respond_to do |format| + format.js + end + rescue NoMethodError + @save_flag = false + @save_message = [] << l(:label_course_empty_select) + respond_to do |format| + format.js + end + end + def add_exist_file_to_courses file = Attachment.find(params[:file_id]) courses = params[:courses][:course] diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index a22012390..d38846ea0 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 @@ -499,7 +490,7 @@ class BidsController < ApplicationController (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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") + WHERE table1.t_score IS NULL OR table1.t_score = 0") @not_batch_homework = true @cur_type = 1 else @@ -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,16 +1030,17 @@ class BidsController < ApplicationController respond_to do |format| format.js end - end + end def alert_anonymous_comment @bid = Bid.find params[:id] @course = @bid.courses.first + @cur_size = 0 + @totle_size = 0 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} @cur_size = 0 @bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.is_teacher_score = 0").count} @@ -1060,7 +1052,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/comments_controller.rb b/app/controllers/comments_controller.rb index 9f61306ab..d226000c0 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -17,6 +17,7 @@ class CommentsController < ApplicationController default_search_scope :news + include ApplicationHelper model_object News before_filter :find_model_object before_filter :find_project_from_association @@ -26,9 +27,13 @@ class CommentsController < ApplicationController raise Unauthorized unless @news.commentable? @comment = Comment.new - @comment.safe_attributes = params[:comment] + @project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment] @comment.author = User.current if @news.comments << @comment + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@comment.id,OwnerTypeHelper::COMMENT + end flash[:notice] = l(:label_comment_added) end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f9ad609cc..8710b624e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,6 +1,7 @@ class CoursesController < ApplicationController - layout 'base_courses' + # layout 'base_courses' include CoursesHelper + include ActivitiesHelper helper :activities helper :members helper :words @@ -30,66 +31,33 @@ class CoursesController < ApplicationController def join if User.current.logged? cs = CoursesService.new - join = cs.join_course params,User.current + user = User.current + join = cs.join_course params,user @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 respond_to do |format| - format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => course, :object_id => params[:object_id]} } + format.js { render :partial => 'set_join', :locals => {:user => user, :course => course, :object_id => params[:object_id]} } end rescue Exception => e @state = 4 #已经加入了课程 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 => nil, :object_id => nil} } end end 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| @@ -105,6 +73,7 @@ class CoursesController < ApplicationController if @course.errors.full_messages.count <= 0 respond_to do |format| format.html { + # render :layout => 'base_courses' flash[:notice] = l(:notice_successful_update) redirect_to settings_course_url(@course) } @@ -114,41 +83,11 @@ class CoursesController < ApplicationController respond_to do |format| format.html { settings - render :action => 'settings' + redirect_to settings_course_url(@course) } 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 +99,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 +180,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 +204,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 +238,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 +285,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,25 +320,20 @@ 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.html {render :layout => 'base_courses'} format.js else format.html {render :layout => 'base_courses'} end end - - # render :layout => 'base_courses' else render_403 end - end def export_course_member_excel @@ -415,20 +347,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 +357,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 +370,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 +377,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 @@ -493,6 +405,13 @@ class CoursesController < ApplicationController @issue_category ||= IssueCategory.new @member ||= @course.members.new @trackers = Tracker.sorted.all + + @roles = Role.givable.all[3..5] + @members = @course.member_principals.includes(:roles, :principal).all.sort + respond_to do |format| + format.html { render :layout => 'base_courses' } + format.api { render_validation_errors(@course) } + end else render_403 end @@ -510,6 +429,7 @@ class CoursesController < ApplicationController else respond_to do |format| format.html { + # render :layout => 'base_courses' flash[:notice] = l(:notice_successful_create) if params[:continue] redirect_to new_course_url(attrs, :course => '0') @@ -522,57 +442,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 +459,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 +488,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 +496,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 +504,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 +590,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 +606,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,52 +670,65 @@ 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, "show_course_messages" => true, + #"show_course_journals_for_messages" => true, "show_bids" => true, - "show_course_journals_for_messages" => true, - "show_homeworks" => true + "show_homeworks" => true, + #"show_polls" => 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 - # 决定显示所用用户或单个用户活动 - @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, - :with_subprojects => false, - :author => @author) - @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) + if @author.nil? + # 显示老师和助教的活动 + # @authors = searchTeacherAndAssistant(@course) + @authors = course_all_member(@course) + events = [] + @authors.each do |author| + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subprojects => false, + :author => author.user) + + @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 + + end else - events = @activity.events(@days, @course.created_at, :is_public => 1) + # @author = @course.teacher + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subprojects => false, + :author => @author) + + @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 end # 无新动态时,显示老动态 @@ -904,23 +739,17 @@ 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_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 + + sorted_events = sort_activity_events_course(events) + events = paginateHelper sorted_events,10 + @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} + # documents + + respond_to do |format| format.html{render :layout => 'base_courses'} format.api @@ -947,10 +776,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 +815,6 @@ class CoursesController < ApplicationController end private - def allow_join course if course_endTime_timeout? course respond_to do |format| @@ -1021,38 +845,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 +892,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/documents_controller.rb b/app/controllers/documents_controller.rb index 9bf2ee846..570726320 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -110,7 +110,7 @@ class DocumentsController < ApplicationController render_attachment_warning_if_needed(@document) if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') - Mailer.attachments_added(attachments[:files]).deliver + Mailer.run.attachments_added(attachments[:files]) end redirect_to document_url(@document) end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 28156ac0c..1ca3e2fcf 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,13 +23,14 @@ class FilesController < ApplicationController before_filter :auth_login1, :only => [:index] before_filter :logged_user_by_apptoken,:only => [:index] before_filter :find_project_by_project_id#, :except => [:getattachtype] - before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project] helper :sort include SortHelper include FilesHelper helper :project_score include CoursesHelper + include ApplicationHelper def show_attachments obj @attachments = [] @@ -41,8 +42,8 @@ class FilesController < ApplicationController @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @offset ||= @feedback_pages.offset - @curse_attachments_all = @all_attachments[@offset, @limit] - @curse_attachments = paginateHelper @all_attachments,10 + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 end def search @@ -78,6 +79,39 @@ class FilesController < ApplicationController end end + def search_project + sort = "" + @sort = "" + @order = "" + @is_remote = true + if params[:sort] + order_by = params[:sort].split(":") + @sort = order_by[0] + if order_by.count > 1 + @order = order_by[1] + end + sort = "#{@sort} #{@order}" + end + + begin + q = "%#{params[:name].strip}%" + #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? + if params[:insite] + @result = find_public_attache q,sort + @result = visable_attachemnts_insite @result,@project + @searched_attach = paginateHelper @result,10 + else + @result = find_project_attache q,@project,sort + @result = visable_attachemnts @result + @searched_attach = paginateHelper @result,10 + end + + #rescue Exception => e + # #render 'stores' + # redirect_to search_course_files_url + end + end + def find_course_attache keywords,course,sort = "" if sort == "" sort = "created_on DESC" @@ -87,6 +121,26 @@ class FilesController < ApplicationController #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") end + def find_project_attache keywords,project,sort = "" + if sort == "" + sort = "created_on DESC" + end + ids = "" + len = 0 + count = project.versions.count + project.versions.each do |version| + len = len + 1 + if len != count + ids += version.id.to_s + ',' + else + ids += version.id.to_s + end + end + resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%"). + reorder(sort) + #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") + end + def find_public_attache keywords,sort = "" # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map # 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。 @@ -132,17 +186,27 @@ class FilesController < ApplicationController attribute = "downloads" when "created_on" attribute = "created_on" + when "quotes" + attribute = "quotes" + else + attribute = "created_on" end - - if order_by.count == 1 - sort += "#{Attachment.table_name}.#{attribute} asc " if attribute - elsif order_by.count == 2 - sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " if attribute && order_by[1] - end - if sort_type != params[:sort].split(",").last - sort += "," + @sort = order_by[0] + @order = order_by[1] + if order_by.count == 1 && attribute + sort += "#{Attachment.table_name}.#{attribute} asc " + if sort_type != params[:sort].split(",").last + sort += "," + end + elsif order_by.count == 2 && order_by[1] + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + if sort_type != params[:sort].split(",").last + sort += "," + end end end + else + sort = "#{Attachment.table_name}.created_on desc" end @containers = [ Project.includes(:attachments).find(@project.id)] @@ -184,6 +248,8 @@ class FilesController < ApplicationController attribute = "created_on" when "quotes" attribute = "quotes" + else + attribute = "created_on" end @sort = order_by[0] @order = order_by[1] @@ -199,6 +265,8 @@ class FilesController < ApplicationController end end end + else + sort = "#{Attachment.table_name}.created_on desc" end @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] @@ -215,6 +283,11 @@ class FilesController < ApplicationController @can_quote = attachment_candown @file end + def quote_resource_show_project + @file = Attachment.find(params[:id]) + @can_quote = attachment_candown @file + end + def new @versions = @project.versions.sort @course_tag = @project.project_type @@ -241,7 +314,7 @@ class FilesController < ApplicationController render_attachment_warning_if_needed(container) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - Mailer.attachments_added(attachments[:files]).deliver + Mailer.run.attachments_added(attachments[:files]) end # TODO: 临时用 nyan @@ -270,7 +343,7 @@ class FilesController < ApplicationController attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type]) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - Mailer.attachments_added(attachments[:files]).deliver + Mailer.run.attachments_added(attachments[:files]) end # TODO: 临时用 nyan diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 64157ea42..253e1d28d 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,11 @@ class ForumsController < ApplicationController respond_to do |format| if @memo.save + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@memo.id,OwnerTypeHelper::MEMO + end + #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 +168,15 @@ 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 + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM + end + #end respond_to do |format| format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index ba7e92467..c90d078e2 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -22,6 +22,7 @@ class HomeworkAttachController < ApplicationController #获取未批作业列表 def get_not_batch_homework @not_batch_homework = true + @search_name = params[:name] sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" get_not_batch_homework_list sort,direction, @bid.id @cur_page = params[:page] || 1 @@ -39,6 +40,7 @@ class HomeworkAttachController < ApplicationController #获取已评作业列表 def get_batch_homeworks + @search_name = params[:name] sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" @is_batch_homeworks = true if sort == 't_socre' @@ -49,11 +51,12 @@ class HomeworkAttachController < ApplicationController order_by = "created_at #{direction}" end all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL AND stars > 0 ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}) AS table1 WHERE table1.t_score IS NOT NULL") + all_homework_list = search_homework_member(all_homework_list,@search_name.to_s.downcase) if @search_name @cur_page = params[:page] || 1 @cur_type = 2 @homework_list = paginateHelper all_homework_list,10 @@ -72,6 +75,7 @@ class HomeworkAttachController < ApplicationController #获取所有作业列表 def get_homeworks @is_all_homeworks = true + @search_name = params[:name] sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" if sort == 't_socre' order_by = "t_score #{direction}" @@ -85,6 +89,8 @@ class HomeworkAttachController < ApplicationController (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}") + + all_homework_list = search_homework_member(all_homework_list,@search_name.to_s.downcase) if @search_name @cur_page = params[:page] || 1 @cur_type = 3 @homework_list = paginateHelper all_homework_list,10 @@ -477,7 +483,7 @@ class HomeworkAttachController < ApplicationController get_not_batch_homework_list params[:cur_sort] || "s_socre",params[:cur_direction] || "desc",@homework.bid_id elsif @cur_type == "2" #老师已批列表 @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL AND stars > 0 ORDER BY updated_at DESC limit 0,1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE id = #{@homework.id}").first elsif @cur_type == "3" #全部作业列表 @@ -538,6 +544,14 @@ class HomeworkAttachController < ApplicationController end private + #根据条件过滤作业结果 + def search_homework_member homeworks,name + select_homework = homeworks.select{ |homework| + homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name) + } + select_homework + end + #验证是否显示课程 def can_show_course @first_page = FirstPage.find_by_page_type('project') @@ -596,7 +610,8 @@ class HomeworkAttachController < ApplicationController (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{bid_id} ORDER BY #{order_by}) AS table1 - WHERE table1.t_score IS NULL") + WHERE table1.t_score IS NULL OR table1.t_score = 0 ") + @all_homework_list = search_homework_member(@all_homework_list,@search_name.to_s.downcase) if @search_name @homework_list = paginateHelper @all_homework_list,10 end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index aaaa4484d..fc243741a 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -133,6 +133,9 @@ class MembersController < ApplicationController elsif @course course_info = [] if params[:membership] + @create_member_error_messages = "角色不能留空" unless params[:membership][:role_ids] + @create_member_error_messages = "用户不能留空" unless params[:membership][:user_ids] + if params[:membership][:user_ids] attrs = params[:membership].dup user_ids = attrs.delete(:user_ids) @@ -140,7 +143,7 @@ class MembersController < ApplicationController member = Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) role = Role.find_by_id(params[:membership][:role_ids]) # 这里的判断只能通过角色名,可以弄成常量 - if role.name == "学生" || role.name == "Student" + if role && (role.name == "学生" || role.name == "Student") StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id) end members << member @@ -159,6 +162,11 @@ class MembersController < ApplicationController end @course.members << members @course.course_infos << course_info + + @roles = Role.givable.all[3..5] + members = @course.member_principals.includes(:roles, :principal).all.sort + else + @create_member_error_messages = l(:label_user_role_null) end respond_to do |format| format.html { redirect_to_settings_in_courses } @@ -242,6 +250,9 @@ class MembersController < ApplicationController end end end + @roles = Role.givable.all[3..5] + @members = @course.member_principals.includes(:roles, :principal).all.sort + @member = @course.members.new end saved = @member.save @@ -304,7 +315,8 @@ class MembersController < ApplicationController joined.each do |join| join.delete end - + @roles = Role.givable.all[3..5] + @members = @course.member_principals.includes(:roles, :principal).all.sort end respond_to do |format| format.html { redirect_to_settings_in_courses } 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..436418430 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 @@ -69,6 +86,11 @@ class MessagesController < ApplicationController if request.post? @message.save_attachments(params[:attachments]) if @message.save + # 更新kindeditor上传的图片资源所有者 + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE + end call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) render_attachment_warning_if_needed(@message) redirect_to board_message_url(@board, @message) @@ -76,6 +98,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 @@ -93,6 +122,10 @@ class MessagesController < ApplicationController @topic.children << @reply #@topic.update_attribute(:updated_on, Time.now) if !@reply.new_record? + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@reply.id,OwnerTypeHelper::MESSAGE + end call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) attachments = Attachment.attach_files(@reply, params[:attachments]) render_attachment_warning_if_needed(@reply) @@ -159,16 +192,7 @@ class MessagesController < ApplicationController @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> " @temp = Message.new - #@temp.content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}> " - @content << @message.content.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" - @content_html = textilizable(@content) - @temp.content = @content_html - #@content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}
  " - #@content << @message.content.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n") + "\n\n
" - #@content = "
" << @content - #@temp = Message.new - #@temp.content = @content - + @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @message.author)}
#{@message.content.html_safe}
".html_safe end def preview diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index b44e8a348..d41491349 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -17,6 +17,7 @@ class NewsController < ApplicationController layout 'base_projects'# by young + include ApplicationHelper before_filter :authorize1, :only => [:show] default_search_scope :news model_object News @@ -70,13 +71,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 @@ -136,6 +137,10 @@ class NewsController < ApplicationController @news.safe_attributes = params[:news] @news.save_attachments(params[:attachments]) if @news.save + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS + end render_attachment_warning_if_needed(@news) flash[:notice] = l(:notice_successful_create) redirect_to course_news_index_url(@course) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e9a27cf44..8ed9fcfef 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -336,11 +336,11 @@ class ProjectsController < ApplicationController def send_mail_to_member if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil? email = params[:mail] - Mailer.send_invite_in_project(email, @project, User.current).deliver + Mailer.run.send_invite_in_project(email, @project, User.current) @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/repositories_controller.rb b/app/controllers/repositories_controller.rb index 6c115fc11..01e470c91 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -131,7 +131,7 @@ update @project_path=@root_path+"htdocs/"+@repository_name @repository_tag=params[:repository][:upassword] || params[:repository][:password] @repo_name=User.current.login.to_s+"_"+params[:repository][:identifier] - logger.info "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+": "+@repository_tag + logger.info "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+": "+@repository_tag logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name attrs = pickup_extra_info if((@repository_tag!="")&¶ms[:repository_scm]=="Git") @@ -147,9 +147,9 @@ update @repository.project = @project if request.post? && @repository.save if(params[:repository_scm]=="Git") - system "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+" "+@repository_tag + system "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+" "+@repository_tag system "echo -e '"+@repo_name+"-write:"+ - " "+@repo_name+"' >> "+@root_path+"group.passwd" + " "+@repo_name+"' >> "+@root_path+"htdocs/group.passwd" system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s system "git init --bare "+@project_path system "mv "+@project_path+"/hooks/post-update{.sample,}" @@ -243,8 +243,8 @@ update if(@repository.type=="Repository::Git") logger.info "destory the repository value"+"root path"+@root_path+"repo_name"+@repo_name+ "repository_name"+@repository_name+"user group"+@middle - system "sed -i /"+@repo_name+"/{d} "+@root_path+"user.passwd" - system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" + system "sed -i /"+@repo_name+"/{d} "+@root_path+"htdocs/user.passwd" + system "sed -i /"+@middle+"/{d} "+@root_path+"htdocs/group.passwd" system "rm -r "+@root_path+"htdocs/"+@repository_name # if(@sed_user&&@sed_group&&@remove) # else diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index c60d1bd8f..93e0e9c4b 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -29,6 +29,9 @@ class SettingsController < ApplicationController end def edit + hidden_non_project = Setting.find_by_name("hidden_non_project") + @text = (hidden_non_project && hidden_non_project.value == "0") ? l(:label_show_non_project) : l(:label_hidden_non_project) + @notifiables = Redmine::Notifiable.all if request.post? && params[:settings] && params[:settings].is_a?(Hash) settings = (params[:settings] || {}).dup.symbolize_keys @@ -70,4 +73,20 @@ class SettingsController < ApplicationController rescue Redmine::PluginNotFound render_404 end + + #隐藏/显示非项目信息 + def hidden_non_project + @notifiable = Setting.find_by_name("hidden_non_project") + if @notifiable + @notifiable.value == "1" ? @notifiable.value = 0 : @notifiable.value = 1 + @notifiable.save + else + @notifiable = Setting.new() + @notifiable.name = "hidden_non_project" + @notifiable.value = 0 + @notifiable.save + end + + redirect_to settings_url + end end 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/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4db471ab4..2a10af260 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -438,13 +438,84 @@ class UsersController < ApplicationController # Description 所有动态 where_condition = nil; # where_condition = "act_type <> 'JournalsForMessage'" + user_ids = [] if @user == User.current watcher = User.watched_by(@user) watcher.push(User.current) - activity = Activity.where(where_condition).where('user_id in (?)', watcher).order('id desc') + user_ids = watcher.map{|x| x.id} else - activity = Activity.where(where_condition).where('user_id = ?', @user.id).order('id desc') + user_ids << @user.id end + activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc') + + permission = !User.current.admin? + if permission + #Issue + act_ids = activity.where(act_type: 'Issue').select('act_id').map{|x| x.act_id} + project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids = [] + ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id} + + #Bid + act_ids = activity.where(act_type: 'Bid').select('act_id').map{|x| x.act_id} + course_ids = HomeworkForCourse.where(bid_id: act_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: course_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << HomeworkForCourse.where(bid_id: act_ids, course_id: c_ids).map{|x| x.id} + + #Journal + act_ids = activity.where(act_type: 'Journal').select('act_id').map{|x| x.act_id} + project_ids = Journal.where(id:act_ids, journalized_type: 'Project').select('distinct journalized_id').map{|x| x.journalized_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id} + + #News + act_ids = activity.where(act_type: 'News').select('act_id').map{|x| x.act_id} + project_ids = News.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id} + + project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: project_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id} + + #Message + act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id} + board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id} + project_ids = Board.where(id: board_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id} + + project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: project_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id} + + logger.debug "filter ids #{ids}" + + activity = activity.where('act_id not in (?)', ids.flatten ).order('id desc') unless ids.flatten.empty? + end + # activity = activity.reject { |e| # e.act.nil? || # (!User.current.admin? && !e.act.nil? @@ -454,14 +525,11 @@ class UsersController < ApplicationController # (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) || # (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course)))))) # } + # + @activity_count = activity.count @activity_pages = Paginator.new @activity_count, pre_count, params['page'] @activity = activity.slice(@activity_pages.offset,@activity_pages.per_page) - # @activity = @activity.reject { |e| - # ((e.act_type=="Issue") && ( !e.act.visible?(User.current))) || - # ((e.act_type == "Journal") && (!e.act.project.visible?(User.current))) || - # ((e.act_type == "Bid") && ((!User.current.member_of_course?(e.act.courses.first) || !User.current.admin?))) - # } @state = 0 end @@ -553,7 +621,7 @@ class UsersController < ApplicationController @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information] + Mailer.run.account_information(@user, params[:user][:password]) if params[:send_information] respond_to do |format| format.html { @@ -620,9 +688,9 @@ class UsersController < ApplicationController @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) if was_activated - Mailer.account_activated(@user).deliver + Mailer.run.account_activated(@user) elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? - Mailer.account_information(@user, params[:user][:password]).deliver + Mailer.run.account_information(@user, params[:user][:password]) end respond_to do |format| diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 2fc4fef9a..680a13963 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -1,7 +1,7 @@ # encoding: utf-8 #####leave message fq class WordsController < ApplicationController - + include ApplicationHelper before_filter :find_user, :only => [:new, :create, :destroy, :more, :back] def create if params[:new_form][:user_message].size>0 @@ -209,6 +209,10 @@ class WordsController < ApplicationController message = params[:new_form][:course_message] feedback = Course.add_new_jour(user, message, params[:id]) if(feedback.errors.empty?) + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE + end redirect_to course_feedback_url(params[:id]), notice: l(:label_feedback_success) else flash[:error] = feedback.errors.full_messages[0] diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 6c5385115..df354f107 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -5,24 +5,48 @@ class ZipdownController < ApplicationController #检查权限 #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" - OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" + OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" + #统一下载功能 + def download + begin + send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => params[:filename], :type => detect_content_type(params[:file]) + rescue => e + render file: 'public/no_file_found.html' + end + end + #一个作业下所有文件打包下载,只有admin和课程老师有权限 def assort if params[:obj_class] == "Bid" bid = Bid.find params[:obj_id] + render_403 if User.current.allowed_to?(:as_teacher,bid.courses.first) file_count = 0 bid.homeworks.map { |homework| file_count += homework.attachments.count} if file_count > 0 zipfile = zip_bid bid else render file: 'public/no_file_found.html' + return end else logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!" end - send_file zipfile, :filename => bid.name + ".zip", :type => detect_content_type(zipfile) if zipfile + # if zipfile + # if zipfile.length > 1 + # @mut_down_files = zipfile #zipfile.each{|x| File.basename(x)} + # else + # send_file zipfile.first[:real_file], :filename => bid.name + ".zip", :type => detect_content_type(zipfile.first[:real_file]) + # return + # end + # end + + respond_to do |format| + format.json { + render json: zipfile.to_json + } + end #rescue Exception => e # render file: 'public/no_file_found.html' end @@ -34,9 +58,9 @@ class ZipdownController < ApplicationController if homework != nil unless homework.attachments.empty? zipfile = zip_homework_by_user homework - send_file zipfile, :filename => ((homework.user.user_extensions.nil? || homework.user.user_extensions.student_id.nil?) ? "" : homework.user.user_extensions.student_id) + + send_file zipfile.file_path, :filename => ((homework.user.user_extensions.nil? || homework.user.user_extensions.student_id.nil?) ? "" : homework.user.user_extensions.student_id) + "_" + (homework.user.lastname.nil? ? "" : homework.user.lastname) + (homework.user.firstname.nil? ? "" : homework.user.firstname) + - "_" + homework.name + ".zip", :type => detect_content_type(zipfile) if(zipfile) + "_" + homework.name + ".zip", :type => detect_content_type(zipfile.file_path) if(zipfile) else render file: 'public/no_file_found.html' end @@ -66,68 +90,145 @@ class ZipdownController < ApplicationController def zip_bid(bid) # Todo: User Access Controll bid_homework_path = [] + digests = [] bid.homeworks.each do |homeattach| unless homeattach.attachments.empty? - bid_homework_path << zip_homework_by_user(homeattach) + out_file = zip_homework_by_user(homeattach) + bid_homework_path << out_file.file_path + digests << out_file.file_digest end end - zipping "#{Time.now.to_i}_#{bid.name}.zip", bid_homework_path, OUTPUT_FOLDER + + homework_id = bid.id + user_id = bid.author_id + + + out_file = find_or_pack(homework_id, user_id, digests.sort){ + zipping("#{Time.now.to_i}_#{bid.name}.zip", + bid_homework_path, OUTPUT_FOLDER) + } + + + # zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024) + # x = 0 + # + # + # zips.each { |o| + # x += 1 + # file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER + # o[:real_file] = file + # o[:file] = File.basename(file) + # o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2) + # } + + [{files:[out_file.file_path], count: 1, index: 1, + real_file: out_file.file_path, file: File.basename(out_file.file_path), + size:(out_file.pack_size / 1024.0 / 1024.0).round(2) + }] end - def zip_homework_by_user(homeattach) + def zip_homework_by_user(homework_attach) homeworks_attach_path = [] not_exist_file = [] # 需要将所有homework.attachments遍历加入zip - # 并且返回zip路径 - homeattach.attachments.each do |attach| + + + digests = [] + homework_attach.attachments.each do |attach| if File.exist?(attach.diskfile) homeworks_attach_path << attach.diskfile + digests << attach.digest else not_exist_file << attach.filename + digests << 'not_exist_file' end end - zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) + + out_file = find_or_pack(homework_attach.bid_id, homework_attach.user_id, digests.sort){ + zipping("#{homework_attach.user.lastname}#{homework_attach.user.firstname}_#{((homework_attach.user.user_extensions.nil? || homework_attach.user.user_extensions.student_id.nil?) ? "" : homework_attach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", + homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) + } + end - def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) - # 输入待打包的文件列表,已经打包文件定位到ouput_path - ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE') - input_filename = files_paths + def find_or_pack(homework_id, user_id, digests) + raise "please given a pack block" unless block_given? + out_file = ZipPack.packed?(homework_id, user_id, digests.sort) + + unless out_file && out_file.file_valid? + file = yield + + ZipPack.where(homework_id: homework_id, + user_id: user_id).delete_all + + out_file = ZipPack.create(homework_id: homework_id, + user_id: user_id, + file_digest: Trustie::Utils.digest(file), + file_path: file, + pack_size: File.size(file), + file_digests: digests.join(',') + ) + else + out_file.pack_times = out_file.pack_times + 1 + out_file.save + end + + out_file + end + + + def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" zipfile_name = "#{output_path}/#{rename_zipfile}" Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) - Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| - input_filename.each do |filename| - flag = true - index = 1 - rename_file = ic.iconv( (File.basename(filename)) ).to_s - rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment - + files_paths.each do |filename| + rename_file = File.basename(filename) + rename_file = filename_to_real( File.basename(filename)) if is_attachment begin zipfile.add(rename_file, filename) - flag = false rescue Exception => e - zipfile.get_output_stream('FILE_NOTICE.txt') do |os| - os.write l(:label_file_exist) - end + zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)} next end end unless not_exist_file.empty? - zipfile.get_output_stream('FILE_LOST.txt') do |os| - os.write l(:label_file_lost) + not_exist_file.join(',').to_s - end + zipfile.get_output_stream('FILE_LOST.txt'){|os| os.write l(:label_file_lost) + not_exist_file.join(',').to_s} end end zipfile_name - #rescue Errno => e - # logger.error "[zipdown#zipping] ===> #{e}" - # @error = e end + + # 合理分配文件打包 + # 如果小于 pack_attachment_max_size, 则返回单个文件 + # 反之则切分为多个文件组返回 + def split_pack_files(files, pack_attachment_max_size) + max_size = 0 + last_files = [] + ret_files = [] + files.each_with_index do |f,i| + if (max_size += File.size(f)) > pack_attachment_max_size + max_size = 0 + if last_files.empty? #如果单个文件超过大小,也将此文件作为一组 + ret_files << {files: [f], count: 1, index: ret_files.count+1} + last_files.clear + else + ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} + last_files.clear + redo + end + else + last_files << f + end + end + + ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} unless last_files.empty? + ret_files + end + def detect_content_type(name) content_type = Redmine::MimeType.of(name) content_type.to_s diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb index 8ef2d6095..445a1670e 100644 --- a/app/helpers/account_helper.rb +++ b/app/helpers/account_helper.rb @@ -23,7 +23,7 @@ module AccountHelper token = Token.new(:user => user, :action => "register") if user.save and token.save UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) - Mailer.register(token).deliver + Mailer.run.register(token) #flash[:notice] = l(:notice_account_register_done) #render action: 'email_valid', locals: {:mail => user.mail} else @@ -51,7 +51,7 @@ module AccountHelper if user.save UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0) # Sends an email to the administrators - Mailer.account_activation_request(user).deliver + Mailer.run.account_activation_request(user) #account_pending else yield if block_given? diff --git a/app/helpers/activities_helper.rb b/app/helpers/activities_helper.rb index c15d89e0c..2f48ba87f 100644 --- a/app/helpers/activities_helper.rb +++ b/app/helpers/activities_helper.rb @@ -30,4 +30,16 @@ module ActivitiesHelper end sorted_events end + def sort_activity_events_course(events) + events_by_group = events.group_by(&:event_group) + sorted_events = [] + events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event| + if group_events = events_by_group.delete(event.event_group) + group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i| + sorted_events << e unless e.event_description.nil? + end + end + end + sorted_events + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b4f54f075..095d0ada5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,39 @@ 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 + # owner_type = 2 对应的是forum + # owner_type = 3 对应的是message + # owner_type = 4 对应的是news + # owner_type = 5 对应的是comment + 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 +128,21 @@ module ApplicationHelper end end + #重载上面方法,增加样式显示 + def link_to_user_header user,canShowRealName=false,options={} + if user.is_a?(User) + if canShowRealName + name = user.show_name + name = user.login if name == "" + else + name = user.login + 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 +304,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, "javascript:void(0)", :onclick => onclick,:class => options[:class]) end def image_to_function(name, function, html_options = {}) @@ -1622,6 +1670,53 @@ 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 + + + def attachment_candown attachment + candown = false + if attachment.container + if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project + project = attachment.container.project + candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif attachment.container.is_a?(Project) + project = attachment.container + candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && + attachment.container.board.project + project = attachment.container.board.project + candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course + course = attachment.container.course + candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif attachment.container.is_a?(Course) + course = attachment.container + candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && + attachment.container.board.course + course = attachment.container.board.course + candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3 + candown = true + elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses + course = attachment.container.courses.first + candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1) + else + candown = (attachment.is_public == 1 || attachment.is_public == true) + end + end + candown + end + private def wiki_helper @@ -1847,12 +1942,14 @@ module ApplicationHelper def render_dynamic_nav home_link = link_to l(:field_homepage), {:controller => 'welcome', :action => 'index'} - home_link = "
  • " << home_link << "
  • " + home_link = "
  • " << home_link << "
  • " # bootstrap_render_dynamic_nav content_tag :ul, (home_link.html_safe+bootstrap_render_dynamic_nav) end def bootstrap_render_dynamic_nav + hidden_non_project = Setting.find_by_name("hidden_non_project") + visiable = !(hidden_non_project && hidden_non_project.value == "0") main_course_link = link_to l(:label_course_practice), {:controller => 'welcome', :action => 'index', :host => Setting.course_domain} main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain} @@ -1870,25 +1967,25 @@ module ApplicationHelper #@nav_dispaly_project_label nav_list = Array.new - nav_list.push(school_all_school_link) if @nav_dispaly_course_all_label && @show_course == 1 + nav_list.push(school_all_school_link) if @nav_dispaly_course_all_label && @show_course == 1 && visiable # nav_list.push(course_all_course_link) if @nav_dispaly_course_all_label && @show_course == 1 - nav_list.push(course_teacher_all_link) if @nav_dispaly_teacher_all_label && @show_course == 1 + nav_list.push(course_teacher_all_link) if @nav_dispaly_teacher_all_label && @show_course == 1 && visiable nav_list.push(main_project_link) if @nav_dispaly_main_project_label - nav_list.push(main_course_link) if @nav_dispaly_main_course_label && @show_course == 1 - nav_list.push(main_contest_link) if @nav_dispaly_main_contest_label && @show_contest == 1 + nav_list.push(main_course_link) if @nav_dispaly_main_course_label && @show_course == 1 && visiable + nav_list.push(main_contest_link) if @nav_dispaly_main_contest_label && @show_contest == 1 && visiable - nav_list.push(courses_link) if @nav_dispaly_course_label && @show_course == 1 + nav_list.push(courses_link) if @nav_dispaly_course_label && @show_course == 1 && visiable # nav_list.push(projects_link) if @nav_dispaly_project_label #nav_list.push(users_link) if @nav_dispaly_user_label # nav_list.push(contest_link) if @nav_dispaly_contest_label && @show_contest == 1 - nav_list.push(bids_link) if @nav_dispaly_bid_label - nav_list.push(forum_link) if @nav_dispaly_forum_label - nav_list.push(stores_link) if @nav_dispaly_store_all_label + nav_list.push(bids_link) if @nav_dispaly_bid_label && visiable + nav_list.push(forum_link) if @nav_dispaly_forum_label && visiable + nav_list.push(stores_link) if @nav_dispaly_store_all_label && visiable content_li = '' nav_list.collect do |nav_item| - content_li << content_tag(:li, nav_item) + content_li << content_tag(:li, nav_item, :class => 'topnav_a fl') end content_li.html_safe end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 50dd79a08..8843b1a76 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -34,6 +34,16 @@ module AttachmentsHelper :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)} end end + + def link_to_attachments_course(container, options = {}) + options.assert_valid_keys(:author, :thumbnails) + + if container.attachments.any? + options = {:deletable => container.attachments_deletable?, :author => true}.merge(options) + render :partial => 'attachments/course_file_links', + :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)} + end + end def attach_delete(project) if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 3, 7)).size >0) || project.user_id == User.current.id) @@ -67,6 +77,7 @@ module AttachmentsHelper end end + #判断课程course中是否包含课件attachment,course中引用了attachment也算作包含 def course_contains_attachment? course,attachment course.attachments.each do |att| if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from @@ -75,6 +86,15 @@ module AttachmentsHelper end false end + #判断项目project中是否包含课件attachment,project中引用了attachment也算作包含 + def project_contains_attachment? project,attachment + project.attachments.each do |att| + if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from + return true + end + end + false + end def get_qute_number attachment if attachment.copy_from diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index bd017757a..5b311acd7 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -20,11 +20,45 @@ module CoursesHelper # 返回教师数量,即roles表中定义的Manager def teacherCount project - project.members.count - studentCount(project).to_i + project ? project.members.count - studentCount(project).to_i : 0 # or # searchTeacherAndAssistant(project).count end + #课程模块需要展示的模块 + def course_model + @nav_dispaly_course_all_label = 1 + @nav_dispaly_forum_label = 1 + @nav_dispaly_course_label = nil + @nav_dispaly_store_all_label = 1 + end + + #生成课程老师成员链接 + def course_teacher_link teacher_num + if User.current.member_of_course?(@course) + link_to "#{teacher_num}", course_member_path(@course, :role => 1), :class => 'info_foot_num c_blue' + else + content_tag 'span',teacher_num, :class => 'info_foot_num c_blue' + end + end + + #生成课程学生列表连接 + def course_student_link student_num + if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) + link_to "#{student_num}", course_member_path(@course, :role => 2), :class => 'info_foot_num c_blue' + else + content_tag 'span',student_num, :class => 'info_foot_num c_blue' + end + end + + def course_poll_count + Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status in (2,3)").count + end + + def course_feedback_count + @course.journals_for_messages.where('m_parent_id IS NULL').count + end + # 返回学生数量,即roles表中定义的Reporter #def studentCount project # searchStudent(project).count @@ -118,7 +152,7 @@ module CoursesHelper # 学生人数计算 # add by nwb def studentCount course - course.student.count.to_s#course.student.count + course ? course.student.count.to_s : 0#course.student.count end #课程成员数计算 @@ -199,10 +233,10 @@ module CoursesHelper #searchPeopleByRoles(project, StudentRoles) mems = [] if name != "" + name = name.to_s.downcase members.each do |m| - - username = m.user[:lastname].to_s + m.user[:firstname].to_s - if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) mems << m end end @@ -598,30 +632,163 @@ module CoursesHelper #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() - days = Setting.activity_days_default.to_i - date_to ||= Date.today + 1 - date_from = date_to - days-1.years + #原来课程动态计算当期时间前(一年+一月)的动态 + # date_to ||= Date.today + 1 + # #date_from = date_to - days-1.years + date_from = @course.created_at.to_date-days #file_count Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment| + if attachment.is_public? || User.current.member_of_course?(@course) || User.current.admin? activities[attachment.container_id]+=1 + else + activities[attachment.container_id] + end end + #message_count + #Board.where(course_id: @course_ids).each do |board| + # activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count + #end + #message_count Board.where(course_id: @course_ids).each do |board| -# activities[board.course_id]+=1 - activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count + countmessage = 0 + # 课程人员退出课程后,之前在讨论区回帖不计入课程动态统计 + board.messages.where("updated_on>?", date_from).each do |message| + if message.author.member_of_course?(@course) + countmessage+=1 + end + end + activities[board.course_id]+=countmessage end #news News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news| + if news.author.member_of_course?(@course) activities[news.course_id]+=1 + end end + #feedback_count 留言目前有问题留待下一步处理 + #JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| + # activities[jourformess.jour_id]+=1 + #end + + #homework_count + HomeworkForCourse.where(course_id: @course_ids).each do |homework| + countbid=0 + # @bid_ids<?",date_from).each do |bid| + countbid+=1 + end + activities[homework.course_id]+=countbid + end + + #@bid_ids.each do |bid_id| + # activities[] +=Bid.where(id: bid_id ).where("created_on>?",date_from).count + #end + + #poll_count + #Poll.where(polls_group_id: @course_ids, polls_type: Course, polls_status: 2||3).where("published_at>?",date_from).each do |poll| + # activities[poll.polls_group_id]+=1 + #end + #end + + # 动态数 + 1 ( 某某创建了该课程 ) activities.each_pair { |key, value| activities[key] = value + 1 } return activities end + #获取某个课程的动态数 + def course_activity_count course + course_activity_count=Hash.new + course_activity_count[course.id]=0 + count = get_course_activity([course],course_activity_count)[course.id] + count.nil? ? 0 : count + end + + #重启、关闭课程按钮 + def set_course_time course + id = "finish_course_#{course.id}" + linkPath = course_endTime_timeout?(course) ? restartcourse_course_path(course) : finishcourse_course_path(course, format: :js) + desc = course_endTime_timeout?(course) ? l(:label_course_reload) : l(:label_course_closed) + link_to "#{desc}".html_safe, linkPath, :remote => true, :method => :post, :id => id, :confirm => l(:label_course_closed_tips, :desc => desc), :class => "pr_join_a" + end + + #加入课程、退出课程按钮 + def join_in_course_header(course, user, options=[]) + if user.logged? + joined = course.members.map{|member| member.user_id}.include? user.id + text = joined ? ("".html_safe + l(:label_course_exit_student)) : ("".html_safe + l(:label_course_join_student)) + url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id) + method = joined ? 'delete' : 'post' + if joined + link = "#{l(:label_course_join_student)}" + link_to(text, url, :remote => true, :method => method, :class => "pr_join_a", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out)) + else + link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "pr_join_a") + "#{l(:label_course_exit_student)}".html_safe + end + else + link = "#{l(:label_course_join_student)}" + + "#{l(:label_course_exit_student)}" + end + link.html_safe + end + + def bid_anonymous_comment bid + 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 + "未开启匿评".html_safe + when 1 + "正在匿评中".html_safe + when 2 + "匿评已结束".html_safe + end + else + "未启用匿评".html_safe + end + end + + def visable_attachemnts_incourse course + return[] unless course + result = [] + course.attachments.each do |attachment| + if attachment.is_public? || User.current.member_of_course?(course) || User.current.admin? + result << attachment + end + end + result + end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 9eff409ff..3c8ed63d4 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -45,6 +45,7 @@ module FilesHelper File.new(zipfile_name,'w+') end + #带勾选框的课程列表 def courses_check_box_tags(name,courses,current_course,attachment) s = '' courses.each do |course| @@ -55,6 +56,17 @@ module FilesHelper s.html_safe end + #带勾选框的项目列表 + def projects_check_box_tags(name,projects,current_project,attachment) + s = '' + projects.each do |project| + if !project_contains_attachment?(project,attachment) && User.current.allowed_to?(:manage_files, project) + s << "" + end + end + s.html_safe + end + #判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 def has_course? user,file result = false @@ -66,6 +78,17 @@ module FilesHelper result end + #判断用户是否拥有不包含当前资源的项目,需用户在该项目中有资源管理相关资源 + def has_project? user,file + result = false + user.projects.each do |project| + if !project_contains_attachment?(project,file) && User.current.allowed_to?(:manage_files, project) + return true + end + end + result + end + # 判断指定的资源时候符合类型 def isTypeOk(attachment, type, contentType) result = false @@ -87,66 +110,33 @@ module FilesHelper def visable_attachemnts attachments result = [] attachments.each do |attachment| - if attachment.is_public? || (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + if attachment.is_public? || + (attachment.container_type == "Project" && User.current.member_of?(attachment.project)) || + (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| + attachment.author_id == User.current.id result << attachment end end result end - def visable_attachemnts_incourse attachments + def visable_attachemnts_insite attachments,obj result = [] - attachments.each do |attachment| - if attachment.is_public? || (attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id - result << attachment - end - end - result - end - - def visable_attachemnts_insite attachments,course - result = [] - attachments.each do |attachment| - if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == course.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id - result << attachment + if obj.is_a?(Course) + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == obj.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end end + else if obj.is_a?(Project) + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "Project" && attachment.container_id == obj.id && User.current.member_of_course?(Project.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end + end end - result end - - def attachment_candown attachment - candown = false - if attachment.container - if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project - project = attachment.container.project - candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif attachment.container.is_a?(Project) - project = attachment.container - candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && - attachment.container.board.project - project = attachment.container.board.project - candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course - course = attachment.container.course - candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif attachment.container.is_a?(Course) - course = attachment.container - candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && - attachment.container.board.course - course = attachment.container.board.course - candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3 - candown = true - elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses - course = attachment.container.courses.first - candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1) - else - candown = (attachment.is_public == 1 || attachment.is_public == true) - end - end - candown + result end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index ed18b7ae4..c8e8bd87b 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -44,18 +44,19 @@ module MembersHelper # add by nwb # 课程可添加的成员列表 def render_principals_for_new_course_members(course) - scope = Principal.active.sorted.not_member_of_course(course).like(params[:q]) - principal_count = scope.count - principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] - principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all - - s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals') + if params[:q] && params[:q] != "" + scope = Principal.active.sorted.not_member_of_course(course).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') - links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options| + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true) {|text, parameters, options| link_to text, autocomplete_course_memberships_path(course, parameters.merge(:q => params[:q], :format => 'js')), :remote => true } - s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') + s + content_tag('ul', links,:class => 'wlist',:id => "course_member_pagination_links") end diff --git a/app/helpers/owner_type_helper.rb b/app/helpers/owner_type_helper.rb new file mode 100644 index 000000000..98f273bee --- /dev/null +++ b/app/helpers/owner_type_helper.rb @@ -0,0 +1,9 @@ +module OwnerTypeHelper + MEMO = 1 + FORUM = 2 + MESSAGE = 3 + NEWS = 4 + COMMENT = 5 + BID = 6 + JOURNALSFORMESSAGE = 7 +end \ No newline at end of file diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 17b68c3f6..284ee8c43 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -20,6 +20,8 @@ module TagsHelper @obj= Contest.find_by_id(obj_id) when '9' @obj= Course.find_by_id(obj_id) + when '10' + @obj = Attachment.find_by_id(obj_id) else raise Exception, '[TagsHelper] ===> tag type unknow.' end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 58935dd11..af2d5abc4 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -278,4 +278,29 @@ module UsersHelper end } end + + #获取用户留言相关的连接 + def user_jour_feed_back_url active + if active.act_type == "JournalsForMessage" + jour = JournalsForMessage.find active.act_id + if jour + case jour.jour_type + when "Principal" + link_to(l(:label_goto), user_newfeedback_user_path(jour.jour_id)) + when "Project" + link_to(l(:label_goto), project_feedback_path(jour.jour_id)) + when "Bid" + link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) + when "Course" + link_to(l(:label_goto), course_feedback_path(jour.jour_id)) + when "Contest" + link_to(l(:label_goto), show_contest_contest_path(jour.jour_id)) + when "Softapplication" + link_to(l(:label_goto), softapplication_path(jour.jour_id)) + when "HomeworkAttach" + link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) + end + end + end + end end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 294d895a5..7995d7e68 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -45,6 +45,26 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :class => css end + + def watcher_link_with_id(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + watched = objects.any? {|object| object.watched_by?(user)} + @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or objects.first.instance_of?(Contest) or (objects.first.instance_of?(Bid))) + css = options[:class] + + text = @watch_flag ? + (watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch)) + + url = watch_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = watched ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css,:id=>options[:id] + end ############## added by linchun def new_watcher_link(objects, user, options=[]) @@ -135,7 +155,7 @@ module WatchersHelper else text = l(:label_new_join_group) form_tag({:controller => "courses", :action => "join_group", :object_id => "#{group.id}"}, :remote => true, :method => 'post') do - submit_tag text, class: "group_in", style: "width: 43px;height: 21px;" + submit_tag text, class: "group_in", style: "width: 90px;height: 21px;" end end end diff --git a/app/models/bid.rb b/app/models/bid.rb index 10476b4d3..ccd6198bb 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -17,7 +17,8 @@ class Bid < ActiveRecord::Base HomeworkProject = 2 attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password include Redmine::SafeAttributes - + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :course has_many :biding_projects, :dependent => :destroy @@ -47,7 +48,7 @@ class Bid < ActiveRecord::Base validate :validate_user validate :validate_reward_type after_create :act_as_activity - + after_destroy :delete_kindeditor_assets scope :visible, lambda {|*args| nil } @@ -157,5 +158,10 @@ class Bid < ActiveRecord::Base end end - + # Time 2015-04-01 14:19:06 + # Author lizanle + # Description 删除对应课程通知的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::BID + end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 539c62e85..bdb642d3c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -17,8 +17,25 @@ class Comment < ActiveRecord::Base include Redmine::SafeAttributes + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :commented, :polymorphic => true, :counter_cache => true belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :commented, :author, :comments safe_attributes 'comments' + after_create :send_mail + + def send_mail + if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') + Mailer.run.news_comment_added(self) + end + end + after_destroy :delete_kindeditor_assets + + # Time 2015-03-31 09:15:06 + # Author lizanle + # Description 删除对应评论的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::COMMENT + end end diff --git a/app/models/comment_observer.rb b/app/models/comment_observer.rb deleted file mode 100644 index a46e53ab9..000000000 --- a/app/models/comment_observer.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class CommentObserver < ActiveRecord::Observer - def after_create(comment) - if comment.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') - ##by senluo - thread3=Thread.new do - Mailer.news_comment_added(comment).deliver - end - end - end -end diff --git a/app/models/discuss_demo.rb b/app/models/discuss_demo.rb deleted file mode 100644 index 6ed8d15b6..000000000 --- a/app/models/discuss_demo.rb +++ /dev/null @@ -1,4 +0,0 @@ -class DiscussDemo < ActiveRecord::Base - attr_accessible :title, :body - has_many_kindeditor_assets :assets, :dependent => :destroy -end diff --git a/app/models/document.rb b/app/models/document.rb index 33ffdaa2f..c8e5f8a24 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -24,6 +24,7 @@ class Document < ActiveRecord::Base after_save :be_user_score # user_score after_destroy :down_user_score acts_as_attachable :delete_permission => :delete_documents + after_create :send_mail # 被ForgeActivity虚拟关联 has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # end @@ -87,4 +88,8 @@ class Document < ActiveRecord::Base :project_id => self.project_id) end + def send_mail + Mailer.run.document_added(self) if Setting.notified_events.include?('document_added') + end + end diff --git a/app/models/document_observer.rb b/app/models/document_observer.rb deleted file mode 100644 index 447952c70..000000000 --- a/app/models/document_observer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class DocumentObserver < ActiveRecord::Observer - def after_create(document) - ##by senluo - thread2=Thread.new do - Mailer.document_added(document).deliver if Setting.notified_events.include?('document_added') - end - end -end diff --git a/app/models/forum.rb b/app/models/forum.rb index 878937ea7..6db069a09 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,5 +1,7 @@ class Forum < ActiveRecord::Base include Redmine::SafeAttributes + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL" belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' @@ -15,10 +17,10 @@ class Forum < ActiveRecord::Base validates_length_of :name, maximum: 50 #validates_length_of :description, maximum: 255 validates :name, :uniqueness => true - + after_destroy :delete_kindeditor_assets acts_as_taggable scope :by_join_date, order("created_at DESC") - #after_create :send_email + after_create :send_mail def reset_counters! self.class.reset_counters!(id) end @@ -33,10 +35,9 @@ class Forum < ActiveRecord::Base self.creator == user || user.admin? end - def send_email - Thread.start do - Mailer.forum_add(self).deliver if Setting.notified_events.include?('forum_add') - end + def send_mail + logger.debug "send mail for forum add." + Mailer.run.forum_add(self) if Setting.notified_events.include?('forum_add') end # Updates topic_count, memo_count and last_memo_id attributes for +board_id+ def self.reset_counters!(forum_id) @@ -47,5 +48,11 @@ class Forum < ActiveRecord::Base ["id = ?", forum_id]) end + # Time 2015-03-26 15:50:54 + # Author lizanle + # Description 删除论坛后删除对应的资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::FORUM + end end diff --git a/app/models/forum_observer.rb b/app/models/forum_observer.rb deleted file mode 100644 index 6afcac824..000000000 --- a/app/models/forum_observer.rb +++ /dev/null @@ -1,8 +0,0 @@ -class ForumObserver < ActiveRecord::Observer - # def after_create(forum) - # Thread.start do - # Mailer.forum_add(forum).deliver if Setting.notified_events.include?('forum_add') - # end - # - # end -end diff --git a/app/models/issue_observer.rb b/app/models/issue_observer.rb index e404a4a1c..51f64c783 100644 --- a/app/models/issue_observer.rb +++ b/app/models/issue_observer.rb @@ -18,13 +18,11 @@ class IssueObserver < ActiveRecord::Observer def after_create(issue) - Thread.start do # 将跟踪者与本项目的其他成员都设为收件方,并去重,不在进行抄送, recipients = issue.recipients - issue.watcher_recipients + issue.watcher_recipients recipients.each do |rec| - Mailer.issue_add(issue,rec).deliver if Setting.notified_events.include?('issue_added') + Mailer.run.issue_add(issue,rec) if Setting.notified_events.include?('issue_added') end - end end end diff --git a/app/models/journal_observer.rb b/app/models/journal_observer.rb index b58464a9b..1fca58f37 100644 --- a/app/models/journal_observer.rb +++ b/app/models/journal_observer.rb @@ -23,14 +23,12 @@ class JournalObserver < ActiveRecord::Observer (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) || (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?) ) - Thread.start do # 将跟踪者与本项目的其他成员都设为收件方,并去重,不在进行抄送, recipients = journal.recipients - journal.watcher_recipients + journal.watcher_recipients recipients.each do |rec| - Mailer.issue_edit(journal,rec).deliver + Mailer.run.issue_edit(journal,rec) end - end end end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 23d9c7753..dda45965e 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -4,6 +4,8 @@ class JournalsForMessage < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy safe_attributes "jour_type", # 留言所属类型 "jour_id", # 留言所属类型的id "notes", # 留言内容 @@ -16,7 +18,7 @@ class JournalsForMessage < ActiveRecord::Base "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" - + after_destroy :delete_kindeditor_assets belongs_to :project, :foreign_key => 'jour_id', :conditions => "#{self.table_name}.jour_type = 'Project' " @@ -47,6 +49,7 @@ class JournalsForMessage < ActiveRecord::Base acts_as_activity_provider :type => 'course_journals_for_messages', :author_key => :user_id, + :permission => :view_course_journals_for_messages, :timestamp => "#{self.table_name}.updated_on", :find_options => {:include => :course } @@ -163,5 +166,10 @@ class JournalsForMessage < ActiveRecord::Base end end - + # Time 2015-04-01 14:15:06 + # Author lizanle + # Description 删除对应课程留言的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,7 + end end diff --git a/app/models/journals_for_message_observer.rb b/app/models/journals_for_message_observer.rb index 0e5f29d03..ee8e28b86 100644 --- a/app/models/journals_for_message_observer.rb +++ b/app/models/journals_for_message_observer.rb @@ -1,9 +1,7 @@ # Added by young class JournalsForMessageObserver < ActiveRecord::Observer def after_create(journals_for_message) - thread1 = Thread.start do - Mailer.journals_for_message_add(User.current, journals_for_message).deliver - end + Mailer.run.journals_for_message_add(User.current, journals_for_message) end end diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 8421fb67d..da1af66a8 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -101,7 +101,7 @@ class MailHandler < ActionMailer::Base end add_user_to_group(@@handler_options[:default_group]) unless @@handler_options[:no_account_notice] - Mailer.account_information(@user, @user.password).deliver + Mailer.run.account_information(@user, @user.password) end else if logger && logger.error diff --git a/app/models/mailer.rb b/app/models/mailer.rb index b404ea531..a6acb1635 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -27,6 +27,24 @@ class Mailer < ActionMailer::Base { :host => Setting.host_name, :protocol => Setting.protocol } end + + class MailerProxy + def initialize(cls) + @target = cls + end + def method_missing(name, *args, &block) + if Setting.delayjob_enabled && Object.const_defined?('Delayed') + @target.delay.send(name, *args, &block) + else + @target.send(name, *args, &block).deliver + end + end + end + + def self.run + MailerProxy.new(self) + end + # author: alan # 发送邀请未注册用户加入项目邮件 # 功能: 在加入项目的同时自动注册用户 @@ -45,6 +63,12 @@ class Mailer < ActionMailer::Base def send_for_user_activities(user, date_to, days) date_from = date_to - days.days + subject = "[ #{user.show_name} : #{l(:label_day_mail)}]" + @subject = " #{user.show_name} : #{date_to} #{l(:label_day_mail)}" + + date_from = "#{date_from} 17:59:59" + date_to = "#{date_to} 17:59:59" + # 生成token用于直接点击登录 @user = user token = Token.new(:user =>user , :action => 'autologin') @@ -59,10 +83,11 @@ class Mailer < ActionMailer::Base course_ids = courses.map {|course| course.id}.join(",") # 查询user的缺陷,包括发布的,跟踪的以及被指派的缺陷 - @issues = Issue.find_by_sql("select DISTINCT i.* from issues i, watchers w + sql = "select DISTINCT i.* from issues i, watchers w where (i.assigned_to_id = #{user.id} or i.author_id = #{user.id} or (w.watchable_type = 'Issue' and w.watchable_id = i.id and w.user_id = #{user.id})) - and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc") + and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc" + @issues = Issue.find_by_sql(sql) # @bids 查询课程作业,包括老师发布的作业,以及user提交作业 # @attachments查询课程课件更新 @@ -97,11 +122,11 @@ class Mailer < ActionMailer::Base end end # 查询user在课程中发布的通知,项目中发的新闻 - @course_news = News.find_by_sql("select DISTINCT n.* from news n + @course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.course_id in (#{course_ids}) - and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") - @project_news = News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids}) - and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] + @project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids}) + and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : [] # 查询user在课程及个人中留言 @course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT * from journals_for_messages where @@ -114,18 +139,18 @@ class Mailer < ActionMailer::Base @forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc") @memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id})) and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc") - if days == 1 - subject = "[ #{user.show_name} : #{l(:label_day_mail)}]" - @subject = " #{user.show_name} : #{date_to - 1.days} #{l(:label_day_mail)}" - else - subject = "[ #{user.show_name} : #{l(:label_week_mail)}]" - @subject = "#{user.show_name} : #{l(:label_week_mail)}" - end - mail :to => user.mail,:subject => subject - end + has_content = [@issues,@homeworks,@course_messages,@project_messages,@course_news,@project_news, + @course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o| + !o.empty? + } + binding.pry if Rails.env.development? + #有内容才发,没有不发 + mail :to => user.mail,:subject => subject if has_content + end + # 公共讨论区发帖、回帖添加邮件发送信息 def forum_message_added(memo) @memo = memo redmine_headers 'Memo' => memo.id @@ -134,16 +159,16 @@ class Mailer < ActionMailer::Base @forum_url = url_for(:controller => 'forums', :action => 'show', :id => @forum.id) @issue_author_url = url_for(user_activities_url(@author)) recipients ||= [] - if @forum.author.mail_notification != 'day' && @forum.author.mail_notification != 'week' - recipients << @forum.creator.mail - end - if @author.mail_notification != 'day' && @author.mail_notification != 'week' - recipients << @author.mail - end + #将帖子创建者邮箱地址加入数组 + recipients << @forum.creator.mail + #回复人邮箱地址加入数组 + recipients << @author.mail # cc = wiki_content.page.wiki.watcher_recipients - recipients @memo_url = url_for(forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))) - mail :to => recipients,:subject => "[ #{l(:label_message_plural)} : #{memo.subject} #{l(:label_memo_create_succ)}]" + mail :to => recipients, + :subject => "[ #{l(:label_message_plural)} : #{memo.subject} #{l(:label_memo_create_succ)}]", + :filter => true end # Builds a Mail::Message object used to email recipients of the added journals for message. @@ -178,12 +203,8 @@ class Mailer < ActionMailer::Base # 验证用户的收取邮件的方式 recipients ||= [] recipients1 ||= [] - if @mail.mail_notification != 'week' && @mail.mail_notification != 'day' - recipients1 = @mail.mail - end - if journals_for_message.jour.author.mail_notification != 'week' && journals_for_message.jour.author.mail_notification != 'day' - recipients = journals_for_message.jour.author.mail - end + recipients1 = @mail.mail + recipients = journals_for_message.jour.author.mail # modify by nwb #如果是直接留言并且留言对象是课程 @@ -195,25 +216,24 @@ class Mailer < ActionMailer::Base #收件人邮箱 @recipients ||= [] @members.each do |teacher| - if teacher.user.mail_notification != 'week' && teacher.user.mail_notification != 'day' - @recipients << teacher.user.mail - end + @recipients << teacher.user.mail end mail :to => @recipients, - :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} " + :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} ", + :filter => true elsif journals_for_message.jour.class.to_s.to_sym == :Bid if !journals_for_message.jour.author.notify_about? journals_for_message return -1 end - mail :to => recipients, :subject => @title + mail :to => recipients, :subject => @title,:filter => true elsif journals_for_message.jour.class.to_s.to_sym == :Contest if !journals_for_message.jour.author.notify_about? journals_for_message return -1 end - mail :to => recipients, :subject => @title + mail :to => recipients, :subject => @title,:filter => true else - mail :to => recipients1, :subject => @title + mail :to => recipients1, :subject => @title,:filter => true end @@ -248,9 +268,9 @@ class Mailer < ActionMailer::Base subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}" - mail(:to => recipients, - - :subject => subject) + mail :to => recipients, + :subject => subject, + :filter => true end # issue.attachments.each do |attach| # attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}") @@ -296,9 +316,9 @@ class Mailer < ActionMailer::Base @issue = issue @journal = journal # @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") - mail(:to => recipients, - - :subject => s) + mail :to => recipients, + :subject => s, + :filter => true end def self.deliver_mailer(to,cc, subject) @@ -384,7 +404,8 @@ class Mailer < ActionMailer::Base @issue_author_url = url_for(user_activities_url(@author)) @document_url = url_for(:controller => 'documents', :action => 'show', :id => document) mail :to => document.recipients, - :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" + :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}", + :filter => true end # Builds a Mail::Message object used to email recipients of a project when an attachements are added. @@ -422,21 +443,24 @@ class Mailer < ActionMailer::Base @added_to = added_to @added_to_url = added_to_url mail :to => recipients, - :subject => "[#{container.name}] #{l(:label_attachment_new)}" + :subject => "[#{container.name}] #{l(:label_attachment_new)}", + :filter => true elsif container.class.name == 'Project' redmine_headers 'Project' => container.id @attachments = attachments @added_to = added_to @added_to_url = added_to_url mail :to => recipients, - :subject => "[#{container.name}] #{l(:label_attachment_new)}" + :subject => "[#{container.name}] #{l(:label_attachment_new)}", + :filter => true else redmine_headers 'Project' => container.project.identifier @attachments = attachments @added_to = added_to @added_to_url = added_to_url mail :to => recipients, - :subject => "[#{container.project.name}] #{l(:label_attachment_new)}" + :subject => "[#{container.project.name}] #{l(:label_attachment_new)}", + :filter => true end end @@ -455,7 +479,8 @@ class Mailer < ActionMailer::Base @news = news @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => news.recipients, - :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}" + :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}", + :filter => true elsif news.course redmine_headers 'Course' => news.course.id @author = news.author @@ -465,7 +490,8 @@ class Mailer < ActionMailer::Base recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail } @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => recipients, - :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}" + :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}", + :filter => true end end @@ -486,7 +512,8 @@ class Mailer < ActionMailer::Base @news_url = url_for(:controller => 'news', :action => 'show', :id => news) mail :to => news.recipients, :cc => news.watcher_recipients, - :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}" + :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}", + :filter => true elsif news.course redmine_headers 'Course' => news.course.id @author = comment.author @@ -498,7 +525,8 @@ class Mailer < ActionMailer::Base recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail } mail :to => recipients, - :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}" + :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}", + :filter => true end end @@ -521,7 +549,8 @@ class Mailer < ActionMailer::Base @message_url = url_for(message.event_url) mail :to => recipients, :cc => cc, - :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" + :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}", + :filter => true elsif message.course redmine_headers 'Course' => message.course.id, 'Topic-Id' => (message.parent_id || message.id) @@ -535,7 +564,8 @@ class Mailer < ActionMailer::Base @message_url = url_for(message.event_url) mail :to => recipients, :cc => cc, - :subject => "[#{message.board.course.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" + :subject => "[#{message.board.course.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}", + :filter => true end end @@ -557,7 +587,8 @@ class Mailer < ActionMailer::Base :id => wiki_content.page.title) mail :to => recipients, :cc => cc, - :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}" + :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}", + :filter => true end # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated. @@ -581,7 +612,8 @@ class Mailer < ActionMailer::Base :version => wiki_content.version) mail :to => recipients, :cc => cc, - :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}" + :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}", + :filter => true end # Builds a Mail::Message object used to email the specified user their account information. @@ -732,6 +764,25 @@ class Mailer < ActionMailer::Base ActionMailer::Base.delivery_method = saved_method end + #过滤掉不是不合规则的收件人 + def filter(reps) + r_reps = [] + if reps.is_a? Array + reps.each do |r| + u = User.find_by_mail(r) + if u && u.mail_notification == 'all' + r_reps << r + end + end + elsif reps.is_a? String + u = User.find_by_mail(reps) + if u && u.mail_notification == 'all' + r_reps << reps + end + end + r_reps + end + def mail(headers={}) headers.merge! 'X-Mailer' => 'Redmine', 'X-Redmine-Host' => Setting.host_name, @@ -748,6 +799,11 @@ class Mailer < ActionMailer::Base headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array) end + if headers[:filter] + headers[:to] = filter(headers[:to]) + headers[:cc] = filter(headers[:cc]) + end + if @author && @author.logged? redmine_headers 'Sender' => @author.login end diff --git a/app/models/memo.rb b/app/models/memo.rb index 052ca03db..191d4f978 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,7 +1,9 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper belongs_to :forum + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :author, :class_name => "User", :foreign_key => 'author_id' validates_presence_of :author_id, :forum_id, :subject,:content # 若是主题帖,则内容可以是空 @@ -42,9 +44,9 @@ class Memo < ActiveRecord::Base "parent_id", "replies_count" - after_create :add_author_as_watcher, :reset_counters! #, :sendmail#,:be_user_score -- 公共区发帖暂不计入得分 + after_create :add_author_as_watcher, :reset_counters!, :send_mail # after_update :update_memos_forum - after_destroy :reset_counters!#,:down_user_score -- 公共区发帖暂不计入得分 + after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分 # after_create :send_notification # after_save :plusParentAndForum # after_destroy :minusParentAndForum @@ -53,10 +55,8 @@ class Memo < ActiveRecord::Base # includes(:forum => ).where() # } - def sendmail - thread1=Thread.new do - Mailer.forum_message_added(self).deliver if Setting.notified_events.include?('forum_message_added') - end + def send_mail + Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added') end def cannot_reply_to_locked_topic @@ -113,7 +113,7 @@ class Memo < ActiveRecord::Base def send_notification if Setting.notified_events.include?('message_posted') - Mailer.message_posted(self).deliver + Mailer.run.message_posted(self) end end @@ -170,4 +170,10 @@ class Memo < ActiveRecord::Base update_replay_for_memo(User.current,1) end + # Time 2015-03-26 15:20:24 + # Author lizanle + # Description 从硬盘上删除资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MEMO + end end diff --git a/app/models/memo_observer.rb b/app/models/memo_observer.rb deleted file mode 100644 index 66cabe923..000000000 --- a/app/models/memo_observer.rb +++ /dev/null @@ -1,8 +0,0 @@ -class MemoObserver < ActiveRecord::Observer - def after_create(memo) - - thread1=Thread.new do - Mailer.forum_message_added(memo).deliver if Setting.notified_events.include?('forum_message_added') - end - end -end diff --git a/app/models/message.rb b/app/models/message.rb index 85a87132d..669495b45 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,6 +18,8 @@ class Message < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy belongs_to :board belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :praise_tread, as: :praise_tread_object, dependent: :destroy @@ -62,12 +64,10 @@ class Message < ActiveRecord::Base after_create :add_author_as_watcher, :reset_counters! after_update :update_messages_board - after_destroy :reset_counters!,:down_user_score + after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets - # fq - after_create :act_as_activity,:be_user_score,:act_as_forge_activity + after_create :act_as_activity,:be_user_score,:act_as_forge_activity, :send_mail #before_save :be_user_score - # end scope :visible, lambda {|*args| includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) @@ -208,5 +208,14 @@ class Message < ActiveRecord::Base end end + def send_mail + Mailer.run.message_posted(self) if Setting.notified_events.include?('message_posted') + end + # Time 2015-03-31 09:15:06 + # Author lizanle + # Description 删除对应消息的图片资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE + end end diff --git a/app/models/message_observer.rb b/app/models/message_observer.rb deleted file mode 100644 index 383301664..000000000 --- a/app/models/message_observer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class MessageObserver < ActiveRecord::Observer - def after_create(message) - ##by senluo - thread5=Thread.new do - Mailer.message_posted(message).deliver if Setting.notified_events.include?('message_posted') - end - end -end diff --git a/app/models/news.rb b/app/models/news.rb index d2547fc02..de3ad35b0 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -18,6 +18,8 @@ class News < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project + include ApplicationHelper + has_many_kindeditor_assets :assets, :dependent => :destroy #added by nwb belongs_to :course belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' @@ -45,11 +47,10 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :add_author_as_watcher - # fq - after_create :act_as_activity,:act_as_forge_activity - # end - + after_create :act_as_activity,:act_as_forge_activity,:add_author_as_watcher, :send_mail + + after_destroy :delete_kindeditor_assets + scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) } @@ -105,4 +106,15 @@ class News < ActiveRecord::Base end end + # Time 2015-03-31 13:50:54 + # Author lizanle + # Description 删除news后删除对应的资源 + def delete_kindeditor_assets + delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::NEWS + end + + def send_mail + Mailer.run.news_added(self) if Setting.notified_events.include?('news_added') + end + end diff --git a/app/models/news_observer.rb b/app/models/news_observer.rb deleted file mode 100644 index 8b9bc7b4b..000000000 --- a/app/models/news_observer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class NewsObserver < ActiveRecord::Observer - def after_create(news) - ##by senluo - thread6=Thread.new do - Mailer.news_added(news).deliver if Setting.notified_events.include?('news_added') - end - end -end diff --git a/app/models/poll.rb b/app/models/poll.rb index 06f1369c1..943c08b51 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -6,4 +6,23 @@ class Poll < ActiveRecord::Base has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number" has_many :poll_users, :dependent => :destroy has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 + # 添加课程的poll动态 +# has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy +# after_create :act_as_activity + +# acts_as_event :title => Proc.new {|o| "#{l(:label_my_message)} ##{o.id}: #{o.name}" }, +# :description => :description, +# :author => :author, +# :url => Proc.new {|o| {:controller => 'poll', :action => 'show', :id => o.id}} + +# acts_as_activity_provider :type => 'polls', +# :permission => :view_course_polls, + #:find_options => {:include => [:course, :author]}, + #:timestamp => "#{self.table_name}.published_at", +# :author_key => :author_id + +# def act_as_activity +# self.acts << Activity.new(:user_id => self.user_id) +# end + end diff --git a/app/models/principal.rb b/app/models/principal.rb index 5aa21768f..dfec5b911 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -42,7 +42,8 @@ class Principal < ActiveRecord::Base where({}) else pattern = "%#{q}%" - sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ") + # sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ") + sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) or LOWER(login) LIKE LOWER(:p) or LOWER(mail) LIKE LOWER(:p)" params = {:p => pattern} if q =~ /^(.+)\s+(.+)$/ a, b = "#{$1}%", "#{$2}%" diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb index f087fce2b..181aa89f6 100644 --- a/app/models/relative_memo.rb +++ b/app/models/relative_memo.rb @@ -159,7 +159,7 @@ class RelativeMemo < ActiveRecord::Base def send_notification if Setting.notified_events.include?('message_posted') - Mailer.message_posted(self).deliver + Mailer.run.message_posted(self) end end diff --git a/app/models/user.rb b/app/models/user.rb index 87dc88976..7b232bf13 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,9 +64,10 @@ class User < Principal }, } + #每日一报、一事一报、不报 MAIL_NOTIFICATION_OPTIONS = [ ['all', :label_user_mail_option_all], - ['week', :label_user_mail_option_week], + #['week', :label_user_mail_option_week], ['day', :label_user_mail_option_day], ['none', :label_user_mail_option_none] ] @@ -765,7 +766,7 @@ class User < Principal # * nil with options[:global] set : check if user has at least one role allowed for this action, # or falls back to Non Member / Anonymous permissions depending if the user is logged def allowed_to?(action, context, options={}, &block) - if context && context.is_a?(Project) + if Project === context return false unless context.allows_to?(action) # Admin users are authorized for anything else return true if admin? @@ -778,7 +779,7 @@ class User < Principal (block_given? ? yield(role, self) : true) } #添加课程相关的权限判断 - elsif context && context.is_a?(Course) + elsif Course === context return false unless context.allows_to?(action) # Admin users are authorized for anything else return true if admin? diff --git a/app/models/wiki_content_observer.rb b/app/models/wiki_content_observer.rb index 187c02288..6e13d1a8a 100644 --- a/app/models/wiki_content_observer.rb +++ b/app/models/wiki_content_observer.rb @@ -17,18 +17,12 @@ class WikiContentObserver < ActiveRecord::Observer def after_create(wiki_content) - ##by senluo - thread7=Thread.new do - Mailer.wiki_content_added(wiki_content).deliver if Setting.notified_events.include?('wiki_content_added') - end + Mailer.run.wiki_content_added(wiki_content) if Setting.notified_events.include?('wiki_content_added') end def after_update(wiki_content) if wiki_content.text_changed? - ##by senluo - thread8=Thread.new do - Mailer.wiki_content_updated(wiki_content).deliver if Setting.notified_events.include?('wiki_content_updated') - end + Mailer.run.wiki_content_updated(wiki_content) if Setting.notified_events.include?('wiki_content_updated') end end end diff --git a/app/models/zip_pack.rb b/app/models/zip_pack.rb new file mode 100644 index 000000000..e2d03f363 --- /dev/null +++ b/app/models/zip_pack.rb @@ -0,0 +1,18 @@ +class ZipPack < ActiveRecord::Base + # attr_accessible :title, :body + + def self.packed?(bid_id, user_id, digests) + zip_pack = ZipPack.where(homework_id: bid_id, user_id: user_id).first + return false unless zip_pack && zip_pack.digests == digests + zip_pack + end + + def file_valid? + return false unless File.exist?(self.file_path) + Trustie::Utils.digest(self.file_path) == self.file_digest + end + + def digests + self.file_digests.split(',').sort + end +end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index c689d699d..aa216d755 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -161,10 +161,15 @@ class CoursesService #显示课程 def show_course(params,current_user) course = Course.find(params[:id]) + if course.school + work_unit = course.school.name + else + work_unit = get_user_work_unit course.teacher + end unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?) raise '403' end - {:course => course,:img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)} + {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)} end #创建课程 @@ -194,6 +199,8 @@ class CoursesService @course.setup_time = params[:setup_time] @course.endup_time = params[:endup_time] @course.class_period = params[:class_period] + params[:course][:is_public] ? @course.is_public = 1 : @course.is_public = 0 + params[:course][:open_student] ? @course.open_student = 1 : @course.open_student = 0 end @issue_custom_fields = IssueCustomField.sorted.all @@ -239,6 +246,8 @@ class CoursesService course.time = params[:time] course.term = params[:term] course.class_period = params[:class_period] + params[:course][:is_public] ? course.is_public = 1 : course.is_public = 0 + params[:course][:open_student] ? course.open_student = 1 : course.open_student = 0 if course.save if params[:course][:is_public] == '0' course_status = CourseStatus.find_by_course_id(course.id) @@ -336,7 +345,7 @@ class CoursesService def course_dynamic(params,current_user) @user = User.find(params[:id]) - if !current_user.admin? && !@user.active? + if current_user.nil? && !current_user.admin? && !@user.active? raise '404' return end @@ -369,6 +378,16 @@ class CoursesService unless latest_bid.nil? latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => get_user_language(current_user))} end + + # Time 2015-04-07 14:58:30 + # Author lizanle + # Description 添加课程创建动态 + if(User.find_by_id(CourseInfos.find_by_course_id(course.id).try(:user_id))) + create_user_name = User.find_by_id(CourseInfos.find_by_course_id(course.id).user_id).realname + latest_course_dynamics << {:type => 5,:time => course.created_at,:message =>l(:label_recently,:locale => get_user_language(current_user)) << create_user_name << l(:label_creat,:locale => get_user_language(current_user))} + end + + #每个作业中的最新留言 messages = [] course.homeworks.each do |bid| @@ -415,7 +434,7 @@ class CoursesService many_times = course.homeworks.index(bid) + 1 name = bid.name homework_count = bid.homeworks.count #已提交的作业数量 - student_questions_count = bid.commit.nil? ? 0 : bid.commit + student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count description = bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = bid.comment_status @@ -435,7 +454,7 @@ class CoursesService many_times = course.homeworks.index(bid) + 1 name = bid.name homework_count = bid.homeworks.count #已提交的作业数量 - student_questions_count = bid.commit.nil? ? 0 : bid.commit + student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count description = bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = bid.comment_status diff --git a/app/services/homework_service.rb b/app/services/homework_service.rb index f9be6f79d..d22c62a5a 100644 --- a/app/services/homework_service.rb +++ b/app/services/homework_service.rb @@ -20,7 +20,7 @@ class HomeworkService many_times = course.homeworks.index(@bid) + 1 name = @bid.name homework_count = @bid.homeworks.count #已提交的作业数量 - student_questions_count = @bid.commit.nil? ? 0 : @bid.commit + student_questions_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count description = @bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = @bid.comment_status @@ -282,7 +282,7 @@ class HomeworkService many_times = course.homeworks.index(@bid) + 1 name = @bid.name homework_count = @bid.homeworks.count #已提交的作业数量 - student_questions_count = @bid.commit.nil? ? 0 : @bid.commit + student_questions_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count description = @bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 state = @bid.comment_status diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 39ca37d26..63dd725cd 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -95,9 +95,7 @@ class UsersService # create a new token for password recovery token = Token.new(:user => user, :action => "recovery") if token.save - Thread.new do - Mailer.lost_password(token).deliver - end + Mailer.run.lost_password(token) return l(:notice_account_lost_email_sent,:locale => user.language) end end @@ -194,20 +192,22 @@ class UsersService #raise @current_user.errors.full_message #return @current_user else - raise 'wrong password' + raise l(:notice_account_wrong_password,:locale => 'zh') end @current_user end #搜索用户 def search_user params - @status = params[:status] || 1 + status = params[:status] || 1 has = { "show_changesets" => true } - scope = User.logged.status(@status) - @search_by = params[:search_by] ? params[:search_by] : "0" - scope = scope.like(params[:name],@search_by) if params[:name].present? + scope = User.logged.status(status) + watcher = User.watched_by(params[:user_id]) + watcher.push(params[:user_id]) + search_by = params[:search_by] ? params[:search_by] : "0" + scope = scope.where("id not in (?)",watcher).like(params[:name],search_by) if params[:name].present? scope end diff --git a/app/views/applied_project/applied_join_project.js.erb b/app/views/applied_project/applied_join_project.js.erb index 3f4f6aff7..ab5cdd484 100644 --- a/app/views/applied_project/applied_join_project.js.erb +++ b/app/views/applied_project/applied_join_project.js.erb @@ -1,11 +1,11 @@ <% if @status == 0%> - alert("您申请的项目不存在"); + alert("<%= l('project.join.tips.notexist') %>"); <% elsif @status == 1%> - alert("请勿重复申请加入该项目"); + alert("<%= l('project.join.tips.repeat') %>"); <% elsif @status == 2%> - alert("申请成功"); + alert("<%= l('project.join.tips.success') %>"); <% elsif @status == 3%> - alert("您已加入该项目"); + alert("<%= l('project.join.tips.has') %>"); <%else%> - alert("申请失败"); + alert("<%= l('project.join.tips.fail') %>"); <%end%> \ No newline at end of file diff --git a/app/views/attachments/_course_file_links.html.erb b/app/views/attachments/_course_file_links.html.erb new file mode 100644 index 000000000..d32025787 --- /dev/null +++ b/app/views/attachments/_course_file_links.html.erb @@ -0,0 +1,72 @@ +
    + <% is_float ||= false %> + <% for attachment in attachments %> +

    + <%if is_float%> +

    + <% end%> + + <% if options[:length] %> + <%= link_to_short_attachment attachment, :class => ' link_file_board', :download => true,:length => options[:length] -%> + <% else %> + <%= link_to_short_attachment attachment, :class => ' link_file_board', :download => true -%> + <% end %> + + <%if is_float%> +
    + <% end%> + + <% if attachment.is_text? %> + <%= link_to image_tag('magnifier.png'), + :controller => 'attachments', + :action => 'show', + :id => attachment, + :filename => attachment.filename%> + <% end %> + + <%= 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}, + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :class => 'delete delete-homework-icon', + :remote => true, + :title => l(:button_delete) %> + <% else %> + <%= link_to image_tag('delete.png'), attachment_path(attachment), + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :class => 'delete', + #:remote => true, + #:id => "attachments_" + attachment.id.to_s, + :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) %>, + <%= format_time(attachment.created_on) %> + + <% end %> +

    + <% end %> + <% if defined?(thumbnails) && thumbnails %> + <% images = attachments.select(&:thumbnailable?) %> + <% if images.any? %> +
    + <% images.each do |attachment| %> +
    <%= thumbnail_tag(attachment) %>
    + <% end %> +
    + <% end %> + <% end %> +
    diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index b026fead2..18586e809 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -17,23 +17,7 @@ <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <% end %> - <% container.saved_attachments.each_with_index do |attachment, i| %> - - <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> - <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> - <%= l(:field_is_public)%>: - <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => 'is_public')%> - <%= if attachment.id.nil? - #待补充代码 - else - link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') - end - %> - <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> - <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> - - <% end %> <% end %> diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 6572ee2c9..577cd280f 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -22,8 +22,8 @@ <%= link_to "留言", get_homework_jours_homework_attach_index_path(:bid_id => @bid.id), {:remote => true}%> (<%= @jours_count %>) -
  • - <%= link_to "作品打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), class: "tb_all" unless @bid.homeworks.empty? %> +
  • <%= link_to "作品打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid, format: :json), + remote: true, class: "tb_all" unless @bid.homeworks.empty? %>
  • <% else %> @@ -63,6 +63,19 @@ + +
    + + +
    +

    下载文件包太大,分成多个下载包

    + +
    +
    +
    +
    diff --git a/app/views/bids/_new.html.erb b/app/views/bids/_new.html.erb index a305ccfec..733961a17 100644 --- a/app/views/bids/_new.html.erb +++ b/app/views/bids/_new.html.erb @@ -41,7 +41,7 @@ <%= f.text_field :reference_user_id, :style=>"display:none"%> <%= l(:button_clear_meassge) %> - <%= l(:label_responses) %> + <%= l(:label_responses) %> diff --git a/app/views/bids/_new_homework_form.html.erb b/app/views/bids/_new_homework_form.html.erb new file mode 100644 index 000000000..129bcec5e --- /dev/null +++ b/app/views/bids/_new_homework_form.html.erb @@ -0,0 +1,53 @@ +<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', :media => 'all' %> +<%= error_messages_for 'bid' %> +<%= hidden_field_tag 'course_id', @course.id %> +
    +

    <%= l(:label_course_homework_new)%>

    +
    +
    +
      +
    • + + +

      +
    • +
    • + + + <% if edit_mode %> + <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:owner_id => bid.id,:owner_type =>OwnerTypeHelper::BID %> + <% else %> + <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> + <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor' %> + <% end %> +
    • +
      +
    • + + + <%= calendar_for('bid_deadline')%> +
    • +
    • + + > +
      +
    • +
    • + + + <%= l(:label_evaluation_description)%> +

      +
    • +
    • + + <%= render :partial => 'attachments/new_form', :locals => {:container => bid} %> +
      +
    • +
    • + <%= l(:button_create)%> + <%= link_to l(:button_cancel), homework_course_path(@course), :class => "blue_btn grey_btn fl c_white"%> +
      +
    • +
    +
    +
    diff --git a/app/views/bids/alert_anonymous_comment.js.erb b/app/views/bids/alert_anonymous_comment.js.erb index 2ec98fcc2..5cb4018a6 100644 --- a/app/views/bids/alert_anonymous_comment.js.erb +++ b/app/views/bids/alert_anonymous_comment.js.erb @@ -3,6 +3,6 @@ showModal('ajax-modal', '500px'); $('#ajax-modal').css('height','180px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before("" + - ""); + ""); $('#ajax-modal').parent().css("top","").css("left",""); $('#ajax-modal').parent().addClass("anonymos"); \ No newline at end of file diff --git a/app/views/bids/edit.html.erb b/app/views/bids/edit.html.erb index ee2142dd5..37121d720 100644 --- a/app/views/bids/edit.html.erb +++ b/app/views/bids/edit.html.erb @@ -1,129 +1,4 @@ - - -

    <%= l(:label_edit_homework) %>

    - -<%= labelled_form_for @bid do |f| %> -
    - <%#= render :partial => 'homework_form', :locals => { :f => f } %> - <%= render :partial => 'homework_form', :locals => { :f => f } %> - - - <%= l(:button_create)%> - - <% end %> -
    \ No newline at end of file +<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= labelled_form_for @bid,:html => { :multipart => true } do |f| %> + <%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}",:f=>f,:edit_mode => true} %> +<% end %> \ No newline at end of file diff --git a/app/views/bids/start_anonymous_comment.js.erb b/app/views/bids/start_anonymous_comment.js.erb index 5b13b2f77..431393a0e 100644 --- a/app/views/bids/start_anonymous_comment.js.erb +++ b/app/views/bids/start_anonymous_comment.js.erb @@ -1,9 +1,8 @@ <% if @statue == 1%> alert('启动成功'); - $("#<%= @bid.id %>_start_anonymous_comment").remove(); - $("#<%= @bid.id %>_anonymous_comment").append('<%= link_to "关闭匿评", alert_anonymous_comment_bid_path(@bid), remote: true, id:"#{@bid.id}_stop_anonymous_comment" %>'); + $("#<%= @bid.id %>_start_anonymous_comment").replaceWith('<%= escape_javascript(link_to "关闭匿评", alert_anonymous_comment_bid_path(@bid), remote: true, id:"#{@bid.id}_stop_anonymous_comment",:class => "fr mr10 work_edit")%>'); <% elsif @statue == 2 %> alert('启动失败\n作业总数大于等于2份时才能启动匿评'); <% elsif @statue == 3%> alert("已开启匿评,请务重复开启"); -<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/bids/stop_anonymous_comment.js.erb b/app/views/bids/stop_anonymous_comment.js.erb index 82847a8f5..cf22d0623 100644 --- a/app/views/bids/stop_anonymous_comment.js.erb +++ b/app/views/bids/stop_anonymous_comment.js.erb @@ -1,2 +1,2 @@ alert('关闭成功'); -$("#<%= @bid.id %>_anonymous_comment").html('匿评结束'); +$("#<%= @bid.id %>_stop_anonymous_comment").replaceWith('匿评结束'); diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index eac85e2d7..ed2c20448 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -1,24 +1,17 @@ - -
    - <%=h @board.name %> +
    +

    <%= l(:label_board_plural) %>

    + <% if !User.current.logged?%>
    <%= l(:label_user_login_course_board) %> @@ -37,74 +31,45 @@
    <% end %> - -
    - - 共有 - <%=link_to @topic_count,:controller => 'boards',:action => 'index' %> - 个贴子 - - - <%= link_to l(:label_message_new), - new_board_message_path(@board), - :class => 'icon icon-add', - :onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %> - +
    +

    + <%= l(:label_totle) %> + <%= @topic_count %> + <%= l(:label_course_momes_count) %> +

    + <%= link_to l(:label_message_new), + new_board_message_path(@board), + :class => 'problem_new_btn fl c_dorange' if User.current.logged? %> +
    -
    <% if @topics.any? %> <% @topics.each do |topic| %> - - - - - -
    <%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) %> - - - - - - - - -
    - <%= link_to h(topic.subject.truncate(40,ommision:'...')), board_message_path(@board, topic),title: topic.subject.to_s %> - - - - - - - - -
    - <%=link_to (topic.replies_count), board_message_path(@board, topic) %> -
    - 回答 -
    -
    - - <%= authoring topic.created_on, topic.author %> -
    -
    -
    -
    +
    + <%= link_to image_tag(url_to_avatar(topic.author), :width=>"32",:height=>"32"), user_path(topic.author),:class => 'problem_pic talk_pic fl' %> +
    + <%= link_to h(topic.subject.truncate(40,ommision:'...')), board_message_path(@board, topic),title: topic.subject.to_s,:class => "problem_tit fl fb c_dblue" %> + <% if topic.sticky? %> + 置顶 + <% end %> +
    +

    由<%= link_to topic.author,user_path(topic.author),:class => "problem_name" %>添加于<%= format_time(topic.created_on) %>

    +
    + <%=link_to (l(:label_reply) + topic.replies_count.to_s), board_message_path(@board, topic),:class => "talk_btn fr c_white" %> + +
    +
    <% end %> - <% else %>

    <%= l(:label_no_data) %>

    <% end %> -
    - -<% other_formats_links do |f| %> - <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> -<% end %> +
      + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> +
    +<%# other_formats_links do |f| %> + <%#= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> +<%# end %> <% html_title @board.name %> diff --git a/app/views/boards/_project_show.html.erb b/app/views/boards/_project_show.html.erb index 7ddd37ad6..765cb2a65 100644 --- a/app/views/boards/_project_show.html.erb +++ b/app/views/boards/_project_show.html.erb @@ -10,7 +10,7 @@
    <% if User.current.logged? %>
    -

    <%= l(:label_message_new) %>

    +

    <%= l(:project_module_boards_post) %>

    <%= form_for @message, :url => new_board_message_path(@board), :html => {:multipart => true, :id => 'message-form'} do |f| %> <%= render :partial => 'messages/form', :locals => {:f => f} %> @@ -39,12 +39,18 @@
    -

    <%= h @board.name %>

    +

    + <% if User.current.language == "zh"%> + <%= h @board.name %> + <% else %> + <%= l(:project_module_boards) %> + <% end %> +

    -
    项目讨论区共有<%= @topic_count %>个帖子
    +
    <%= l(:label_project_board_count , :count => @topic_count)%>
    <% if @project.enabled_modules.where("name = 'boards'").count > 0 && User.current.member_of?(@project) %> - <%= link_to l(:label_message_new), new_board_message_path(@board), + <%= link_to l(:project_module_boards_post), new_board_message_path(@board), :class => 'problem_new_btn fl', :onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %> <% end %> @@ -61,15 +67,15 @@
    <%= link_to h(topic.subject), board_message_path(@board, topic), title:topic.subject.to_s, :class =>"problem_tit fl" %> <% if topic.sticky? %> - 置顶 + <%= l(:label_board_sticky)%> <% end %>
    - 由<%= link_to topic.author, user_path(topic.author), :class =>"problem_name" %> - 添加于<%= format_time topic.created_on %> + <%= l(:label_post_by)%><%= link_to topic.author, user_path(topic.author), :class =>"problem_name" %> +  <%= l(:label_post_by_time)%><%= format_time topic.created_on %>
    - 回复<%= link_to (topic.replies_count), board_message_path(@board, topic), :style =>"color:#fff;" %> + <%= link_to (l(:label_short_reply) + " "+topic.replies_count.to_s), board_message_path(@board, topic), :style =>"color:#fff;line-height: 18px;" %>
    <% end %> diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb index 6e5888363..81d1288fd 100644 --- a/app/views/boards/show.html.erb +++ b/app/views/boards/show.html.erb @@ -1,3 +1,4 @@ + <% if @project %> <%= render :partial => 'project_show', locals: {project: @project} %> <% elsif @course %> diff --git a/app/views/courses/_course_members.html.erb b/app/views/courses/_course_members.html.erb new file mode 100644 index 000000000..38ef7e9db --- /dev/null +++ b/app/views/courses/_course_members.html.erb @@ -0,0 +1,49 @@ +
    +
      +
    • + + 用户 + + + 角色 + + +
    • + +
      + <%= render :partial => "courses/member" %> +
      +
    +
    +
    +

    添加成员

    + <%= form_for(@member, {:as => :membership, :url => course_memberships_path(@course), :remote => true, :method => :post}) do |f| %> + + <% end%> +
    \ No newline at end of file diff --git a/app/views/courses/_course_student.html.erb b/app/views/courses/_course_student.html.erb new file mode 100644 index 000000000..8da3987a8 --- /dev/null +++ b/app/views/courses/_course_student.html.erb @@ -0,0 +1,16 @@ +
    + +
    + +
    + <%= render :partial => 'new_groups_name', :locals => {:course_groups => @course_groups} %> +
    +
    + +
    + <%= render :partial => 'new_member_list', :locals => {:members => members} %> +
    +
    +
    \ No newline at end of file diff --git a/app/views/courses/_course_teacher.html.erb b/app/views/courses/_course_teacher.html.erb new file mode 100644 index 000000000..89a3eea7e --- /dev/null +++ b/app/views/courses/_course_teacher.html.erb @@ -0,0 +1,23 @@ +
    +
    + 加入时间 +
    + + <% members.each do |member| %> +
    + + <%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :width => 32, :height => 32)) %> + + <%= l(:label_username)%> + <%= link_to(member.user.name, user_path(member.user),:class => "ml10 c_blue02") %> + <%= format_date(member.created_on)%> +
    +
    + <% end%> + +
      + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/courses/_courses_jours.html.erb b/app/views/courses/_courses_jours.html.erb index 23c74ed4b..ef1d25bd4 100644 --- a/app/views/courses/_courses_jours.html.erb +++ b/app/views/courses/_courses_jours.html.erb @@ -1,10 +1,7 @@ -
    +<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
    <%# reply_allow = JournalsForMessage.create_by_user? User.current %> - -

    - <%= l(:label_user_response) %> -

    +

    <%= l(:label_leave_message) %>

    <% if !User.current.logged?%>
    @@ -13,20 +10,17 @@
    <% else %> -
    <%= form_for('new_form', :method => :post, - :url => {:controller => 'words', :action => 'leave_course_message'}) do |f|%> - <%= f.text_area 'course_message',:id => "leave_meassge", :rows => 3, :cols => 65, - :placeholder => "#{l(:label_welcome_my_respond)}", - :style => "resize: none; width: 98%", - :class => 'noline',:maxlength => 250%> - - <%= l(:button_leave_meassge)%> + :url => {:controller => 'words', :action => 'leave_course_message'},:html => {:id=>'leave_message_form'}) do |f|%> + <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> + <%= f.kindeditor 'course_message',:height => '140px;',:editor_id => 'leave_message_editor',:input_html=>{:id => "leave_meassge",:style => "resize: none;", + :placeholder => "#{l(:label_welcome_my_respond)}",:maxlength => 250}%> + 取  消 + + <%= l(:button_leave_meassge)%> <% end %> -
    <% end %> -
    @@ -34,5 +28,4 @@
      <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> -
    -
    \ No newline at end of file + \ No newline at end of file diff --git a/app/views/courses/_history.html.erb b/app/views/courses/_history.html.erb index 555e94f6d..e7c5a7c5e 100644 --- a/app/views/courses/_history.html.erb +++ b/app/views/courses/_history.html.erb @@ -1,32 +1,27 @@ <% reply_allow = JournalsForMessage.create_by_user? User.current %> - -
    -
    <% if journals.size > 0 %> <% for journal in journals %>
    - - <%= image_tag(url_to_avatar(journal.user)) %> - + <%= link_to image_tag(url_to_avatar(journal.user),:width => '46',:height => '46'), user_path(journal.user) %>
    -
    +
    - <%= link_to journal.user, user_path(journal.user),:style => " font-weight:bold; color:#15bccf; margin-right:30px; background:none;", :target => "_blank"%> + <%= link_to journal.user, user_path(journal.user),:class => 'c_blue fb fl mb10', :target => "_blank"%> - + <%= format_time(journal.created_on) %>

    - <%= textilizable journal.notes%> + <%= journal.notes.html_safe %>

    <% ids = 'project_respond_form_'+ journal.id.to_s%> - + <% if journal.user == User.current|| User.current.admin? || (@course && User.current.allowed_to?(:as_teacher,@course)) %> <%= link_to(l(:label_bid_respond_delete), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => @user}, @@ -38,31 +33,23 @@ {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea')); $('##{ids} textarea') ;return false;"} %> <% end %> - - - <%= l(:label_bids_published) %>  - <%= time_tag(journal.created_on).html_safe %>  - <%= l(:label_bids_published_ago) %> -
    -
    +
    <% ids = 'project_respond_form_'+ journal.id.to_s%> <% if reply_allow %>
    - <%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal,:show_name => true} %> + <%= render :partial => 'words/new_respond_course', :locals => {:journal => journal, :m_reply_id => journal,:show_name => true} %>
    <% end %> -
    -
    - <%= render :partial => "words/journal_reply", :locals => {:journal => journal, :show_name => true, :allow_delete => @course && User.current.allowed_to?(:as_teacher,@course)} %> -
    +
    + + <%= render :partial => "words/journal_reply", :locals => {:journal => journal, :show_name => true, :allow_delete => @course && User.current.allowed_to?(:as_teacher,@course)} %> +
    <% end %> <% end %> -
    -
    diff --git a/app/views/courses/_join_private_course.html.erb b/app/views/courses/_join_private_course.html.erb index 343e7252a..788f47d2d 100644 --- a/app/views/courses/_join_private_course.html.erb +++ b/app/views/courses/_join_private_course.html.erb @@ -68,10 +68,10 @@
  • - + <%= l(:label_new_join) %> - + <%= l(:button_cancel)%>
  • diff --git a/app/views/courses/_member.html.erb b/app/views/courses/_member.html.erb new file mode 100644 index 000000000..a4b5bae6e --- /dev/null +++ b/app/views/courses/_member.html.erb @@ -0,0 +1,37 @@ +<% @members.each do |member| %> +
  • + <%= link_to_user_header member.principal,true,:class => "w150 c_orange fl" %> + + <%= h member.roles.sort.collect(&:to_s).join(', ') %> + <%= form_for(member, {:as => :membership, :remote => true, :url => membership_path(member), + :method => :put, + :html => {:id => "member-#{member.id}-roles-form", :class => 'hol'}} + ) do |f| %> + <% @roles.each do |role| %> +
      + <%= radio_button_tag 'membership[role_ids][]', role.id, member.roles.include?(role), + :disabled => member.member_roles.detect { |mr| mr.role_id == role.id && !mr.inherited_from.nil? } %> + +
    + + <% end %> + <%= hidden_field_tag 'membership[role_ids][]', '' %> + + <% end %> +
    + <% unless member.roles.first.to_s == "Manager"%> + 编辑 + <%= delete_link membership_path(member), + :remote => true, + :class => "c_dblue w40 fl", + :data => (!User.current.admin? && member.include?(User.current) ? {:confirm => l(:text_own_membership_delete_confirmation)} : {confirm: l(:label_delete_confirm)}) if member.deletable? %> + <% end%> +
  • +<% end%> \ No newline at end of file diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb index 11bfd9f81..60c10dff6 100644 --- a/app/views/courses/_member_list.html.erb +++ b/app/views/courses/_member_list.html.erb @@ -1,9 +1,7 @@ -
    +
    <% if User.current.logged? && User.current.member_of_course?(@course) && @group %> - <% if !@canShowCode %> - <%= join_in_course_group(@course.course_groups,@group, User.current) %> - <% end %> + <%= join_in_course_group(@course.course_groups,@group, User.current) unless @canShowCode %> <%= l(:label_current_group)%>:  <%= @group.name %> @@ -25,7 +23,8 @@
      <% if @subPage_title == l(:label_student_list) %> -
    • <%= link_to '作业积分', member_score_sort_course_path(:sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? @group.id : 0),:search_name => (@search_name ? @search_name : nil)) ,:result => members,method: 'get', remote: true%> +
    • + <%= link_to '作业积分', member_score_sort_course_path(:sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? @group.id : 0),:search_name => (@search_name ? @search_name : nil)) ,:result => members,method: 'get', remote: true%> <% if @score_sort_by == 'desc' %> <% else %> @@ -33,7 +32,7 @@ <% end %>
    • - 加入时间 + 加入时间
    • <% else %>
    • @@ -41,7 +40,7 @@
    • - 加入时间 + 加入时间
    • <% end %> @@ -51,7 +50,7 @@
      - + <%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :width => 40, :height => 40)) %>
        diff --git a/app/views/courses/_new_groups_name.html.erb b/app/views/courses/_new_groups_name.html.erb new file mode 100644 index 000000000..da599ef5a --- /dev/null +++ b/app/views/courses/_new_groups_name.html.erb @@ -0,0 +1,56 @@ +
          +
        • 分班:
        • +
        • + <%= link_to l(:label_all), searchgroupmembers_course_path(@course,:group_id => 0), :onclick => "checkclass('course_group_0')", method: 'get', remote: true%> +
        • + + <% unless course_groups.nil? %> + <% course_groups.each do |group| %> + <% group_name = " #{ group.name}( #{group.members.count.to_s}人)".html_safe %> +
        • + <%= link_to group_name, searchgroupmembers_course_path(@course,:group_id => group.id), method: 'get', remote: true,:onclick => "checkclass('group_name_#{group.id}')"%> + <% if @canShowCode%> + <% if group.members.empty?%> + <%= link_to '', deletegroup_course_path(:group_id => group.id), :method => 'delete', :remote => true, + :data => {confirm: l(:label_delete_group)}, + :class => 'f_1', + :style => "width: 11px;height: 16px;margin-top:3px;margin-left:5px;background: url(/images/pic_del.gif) no-repeat 0 0;" + %> + <% else%> + + 删除班级 + + <% end%> + + 编辑班级 + + <% end %> +
        • + +
        • + <% if @canShowCode%> + <%= form_tag(updategroupname_course_path(@course,:group_id => group.id), method: 'get', remote:true, :id => 'update_group_'+group.id.to_s) do %> + + <% end %> + <% end %> +
        • + <% end %> + <% end %> + + <% if @canShowCode %> +
        • + +添加分班 +
        • +
        • + +
        • + <% end %> +
        \ No newline at end of file diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb new file mode 100644 index 000000000..e7d282256 --- /dev/null +++ b/app/views/courses/_new_member_list.html.erb @@ -0,0 +1,81 @@ + +
        + <% if User.current.logged? && User.current.member_of_course?(@course) && @group %> + <%= join_in_course_group(@course.course_groups,@group, User.current) unless @canShowCode %> + + <%= l(:label_current_group)%>:  + <%= @group.name %> + + <% end %> +
        +
        + +<% if members.any? %> + <% if @result_count %> +

        + <%= l(:label_search_member_count) %> + <%= @result_count %> + <%= l(:label_member_people) %> +

        +
        + <% end %> + +
        +
          +
        • 姓名
        • +
        • 学号
        • +
        • + <%= link_to '作业积分', member_score_sort_course_path(:sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? @group.id : 0),:search_name => (@search_name ? @search_name : nil)) ,:result => members,method: 'get', remote: true%> + <% if @score_sort_by == 'desc' %> + + <% else %> + + <% end %> +
        • +
        • 加入时间
        • +
        +
        + + <% members.each do |member| %> +
        + + <%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :width => 32, :height => 32)) %> + +
          + <% if @canShowCode %> +
        • + <% if member.user.show_name == ''%> + <%= link_to("#{l(:label_bidding_user_studentname)}:#{member.user.name}".html_safe,user_path(member.user)) %> + <% else%> + <%= link_to("#{l(:label_bidding_user_studentname)}:#{member.user.show_name}".html_safe,user_path(member.user)) %> + <%end%> +
        • + <% else %> +
        • <%= link_to("#{l(:label_bidding_user_studentname)}:#{member.user.name}".html_safe, user_path(member.user)) %>
        • + <% end %> +
          + <% unless member.user.user_extensions.student_id == ''%> +
        • <%= link_to("#{l(:label_bidding_user_studentcode)}:#{member.user.user_extensions.student_id}".html_safe,user_path(member.user)) %>
        • + <% end%> +
        + <%= link_to format("%0.2f",member.score.nil? ? 0 : member.score.to_s), { + :action => 'show_member_score', + :member_id => member.id, + :remote => true}, + :class => 'ml258 c_red' %> + <%= format_date(member.created_on)%> + <%= call_hook(:view_projects_settings_members_table_row, { :course => @course, :member => member}) %> +
        +
        + <% end; reset_cycle %> +
        + +
          + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => @is_remote, :flag => true%> +
        +<% else%> +

        + <%= l(:label_no_data) %> +

        +<% end%> + diff --git a/app/views/courses/_searchmembers.html.erb b/app/views/courses/_searchmembers.html.erb index 71bacd02e..c6b577c8d 100644 --- a/app/views/courses/_searchmembers.html.erb +++ b/app/views/courses/_searchmembers.html.erb @@ -1,12 +1,11 @@ -<% if @subPage_title && @subPage_title == l(:label_student_list)%> - <%= form_tag( searchmembers_course_path(@course), method: 'get',:class => "f_l",:style => "margin-left: 5px; ",:remote=>true) do %> - <%= text_field_tag 'name', params[:name], name: "name", :class => 'f_1', :style => "height:15px; float: left;"%> - <% if @group %> - <%= hidden_field "search_group_id", params[:search_group_id],:value => "#{@group.id}", name: 'search_group_id' %> - <%= submit_tag l(:label_search_member), :name => "ingroup",:class => "f_2", :style => "float: left "%> - <% else %> - <%= submit_tag l(:label_search_member),:style => "float: left", :name => 'incourse',:onclick => "checkclass('group_name_0')",:class => "f_2"%> - <% end %> +<%= form_tag( searchmembers_course_path(@course), method: 'get',:class => "f_l",:remote=>true,:id => "search_student") do %> + <%= text_field_tag 'name', params[:name], name: "name", :class => 'st_search_input', :placeholder => '输入学生姓名、学号进行搜索'%> + <% if @group %> + <%= hidden_field "search_group_id", params[:search_group_id],:value => "#{@group.id}", name: 'search_group_id' %> + + <% else %> + <% end %> - <%= link_to l(:label_export_excel), export_course_member_excel_course_path(@course,:format => 'xls'),:class=>'xls'%> -<% end %> \ No newline at end of file +<% end %> +搜索 +<%= link_to l(:label_export_excel), export_course_member_excel_course_path(@course,:format => 'xls'),:class=>'xls'%> \ No newline at end of file diff --git a/app/views/courses/_set_join.js.erb b/app/views/courses/_set_join.js.erb index f65d6e98b..0ccefdba1 100644 --- a/app/views/courses/_set_join.js.erb +++ b/app/views/courses/_set_join.js.erb @@ -1,9 +1,10 @@ <% if object_id%> - $("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course(course, user) %>'); + $("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(course, user)) %>"); <% end %> <% if @state %> <% if @state == 0 %> alert("加入成功"); + hideModal("#popbox02"); <% elsif @state == 1 %> alert("密码错误"); <% elsif @state == 2 %> diff --git a/app/views/courses/addgroups.js.erb b/app/views/courses/addgroups.js.erb index a6f6933b9..cb7e1fbb1 100644 --- a/app/views/courses/addgroups.js.erb +++ b/app/views/courses/addgroups.js.erb @@ -1 +1 @@ -$("#st_groups").html("<%= escape_javascript( render :partial => 'groups_name', locals: {:course_groups => @course_groups})%>"); \ No newline at end of file +$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>"); \ No newline at end of file diff --git a/app/views/courses/deletegroup.js.erb b/app/views/courses/deletegroup.js.erb index a6f6933b9..cb7e1fbb1 100644 --- a/app/views/courses/deletegroup.js.erb +++ b/app/views/courses/deletegroup.js.erb @@ -1 +1 @@ -$("#st_groups").html("<%= escape_javascript( render :partial => 'groups_name', locals: {:course_groups => @course_groups})%>"); \ No newline at end of file +$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>"); \ No newline at end of file diff --git a/app/views/courses/feedback.html.erb b/app/views/courses/feedback.html.erb index ccd171679..c45259efd 100644 --- a/app/views/courses/feedback.html.erb +++ b/app/views/courses/feedback.html.erb @@ -1,46 +1,12 @@ <% reply_allow = JournalsForMessage.create_by_user? User.current %> -<%= stylesheet_link_tag 'css', :media => 'all' %> + +
        +

        <%= l(:label_contest_userresponse) %>

        +
        + <%= render :partial => 'courses_jours', :locals => { :contest => @contest, :journals => @jour, :state => false} %> -<% html_title(l(:label_user_response)) -%> - <% html_title(l(:label_course_feedback)) -%> \ No newline at end of file diff --git a/app/views/courses/finishcourse.js.erb b/app/views/courses/finishcourse.js.erb index 46bc57e32..2399062fd 100644 --- a/app/views/courses/finishcourse.js.erb +++ b/app/views/courses/finishcourse.js.erb @@ -1,10 +1,6 @@ <% if @save_flag %> - <% if Rails.env.development? %> - console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@course.extra).try(:endup_time)%>'); - <% end %> - $('#content-title-top-div').html("<%= j(render partial: 'users/my_course_ex', :locals => {:memberships => @memberships,:user=>@user, - :memberships_doing=>@memberships_doing,:memberships_done=>@memberships_done} )%>"); - $('#finish_course_<%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>"); + $('#finish_course_<%=@course.id%>').replaceWith("<%= escape_javascript(set_course_time(@course_prefs))%>"); +// alert("关闭成功"); <% else %> alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。'); <% end %> diff --git a/app/views/courses/homework.html.erb b/app/views/courses/homework.html.erb index 81201bef5..f7cf2a360 100644 --- a/app/views/courses/homework.html.erb +++ b/app/views/courses/homework.html.erb @@ -1,63 +1,62 @@ - -<%= javascript_include_tag 'attachments' %> - -
        - <% if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.nil? && (Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.roles&Role.where(id: [3, 4, 7, 9] )).size >0))%> - <%= link_to(l(:label_course_homework_new), {:controller => 'courses', :action => 'new_homework'}, :class => 'icon icon-add') %> - <% else %> - - <%= l(:label_coursejoin_tip) %> - - <% end %> +
        +

        + <%= l(:label_homework)%> +

        -
        - <%= render :partial => 'bids/bid_homework_show', :locals => {:bids => @bids, :bid_pages => @bid_pages} %> +
        +

        + <%= 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 %> +
        - -
        -
        -
        -

        课程: <%= @course.name%>

        -

        上传作业

        - +<% @bids.each do |bid|%> +
        + <%= link_to(image_tag(url_to_avatar(bid.author), :width => "42", :height => "42"), user_path(bid.author), :class => "problem_pic fl") %> +
        + <%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author),:class => 'problem_name fl') %> + <%= l(:label_user_create_project_homework) %>: + <%= link_to(bid.name, course_for_bid_path(bid), :class => 'problem_tit fl fb c_dblue') %> +
        +

        <%= 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 %> +
        + +
        +
        + <%= bid.description.html_safe %> +
        -
        - + + <%= l(:label_end_time)%>:<%= bid.deadline%> + <% if betweentime(bid.deadline) < 0 %> + + <%= l(:label_commit_limit)%> + + <% else %> + +
        +
        + <% end %> +
        +
        -
        - +<% end%> -<% html_title(l(:label_homework)) -%> \ No newline at end of file +
          + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> +
        +
        \ No newline at end of file diff --git a/app/views/courses/join_group.js.erb b/app/views/courses/join_group.js.erb index 7bdefdb9f..e0db2b440 100644 --- a/app/views/courses/join_group.js.erb +++ b/app/views/courses/join_group.js.erb @@ -1,2 +1,2 @@ -$("#st_groups").html("<%= escape_javascript( render :partial => 'groups_name', locals: {:course_groups => @course_groups})%>"); +$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>"); $("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>"); \ No newline at end of file diff --git a/app/views/courses/join_private_courses.js.erb b/app/views/courses/join_private_courses.js.erb index 254311ce7..23dc551f7 100644 --- a/app/views/courses/join_private_courses.js.erb +++ b/app/views/courses/join_private_courses.js.erb @@ -3,7 +3,7 @@ showModal('ajax-modal', '510px'); $('#ajax-modal').css('height','330px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before("" + - ""); + ""); $('#ajax-modal').parent().removeClass("alert_praise"); $('#ajax-modal').parent().css("top","").css("left",""); $('#ajax-modal').parent().addClass("alert_box"); diff --git a/app/views/courses/member.html.erb b/app/views/courses/member.html.erb index e2c1fb418..ce336373b 100644 --- a/app/views/courses/member.html.erb +++ b/app/views/courses/member.html.erb @@ -1,81 +1,9 @@ - - -<%= stylesheet_link_tag 'course_group', :media => 'all' %> - -
        - -
        - <% if @subPage_title == l(:label_student_list) %> -
        - <%= render :partial => 'groups_name', :locals => {:course_groups => @course_groups} %> -
        - <% end %> - -
        - -
        - <%= error_messages_for 'member' %> - <%= render :partial => @render_file, :locals => {:members => @members} %> -
        +
        +

        <%= @subPage_title%>

        +<% if @subPage_title == l(:label_student_list)%> + <%= render :partial => 'course_student', :locals => {:members => @members} %> +<% else%> + <%= render :partial => 'course_teacher', :locals => {:members => @members} %> +<% end%> diff --git a/app/views/courses/member_score_sort.js.erb b/app/views/courses/member_score_sort.js.erb index c6ff97164..926836356 100644 --- a/app/views/courses/member_score_sort.js.erb +++ b/app/views/courses/member_score_sort.js.erb @@ -1,4 +1,4 @@ /** * Created by Administrator on 2014/12/3. */ -$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>"); \ No newline at end of file +$("#member_content").html("<%= escape_javascript( render :partial => "new_member_list", :locals => {:members => @results})%>"); \ No newline at end of file diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index b9422ba64..0ea51d5f4 100644 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -1,16 +1,58 @@ -<% @nav_dispaly_course_all_label = 1 - @nav_dispaly_forum_label = 1 - @nav_dispaly_course_label = nil - @nav_dispaly_store_all_label = 1 %> -

        <%=l(:label_course_new)%>

        -<%= labelled_form_for @course do |f| %> -
        - <%= render :partial => 'course_form', :locals => { :f => f } %> - - <%= submit_tag l(:button_create), :class => "enterprise"%> - - - <%= javascript_tag "$('#course_name').focus();" %> -
        -<% end %> -<% html_title(l(:label_course_new)) -%> \ No newline at end of file +
        +

        <%= l(:permission_new_course)%>

        +
        +
        +
          + <%= labelled_form_for @course do |f| %> +
        • + + + +
        • +
          +
        • + + + +
        • +
          +
        • + + <%= select_tag :time,options_for_select(course_time_option(@course.time),@course.time), {} %> + <%= select_tag :term,options_for_select(course_term_option,@course.term || cur_course_term),{} %> +
        • +
          +
        • + + + + 显示明码 +
          + 学生或其他成员申请加入课程时候需要使用该口令,该口令可以由老师在课堂上公布。 +
        • +
        • + + +
          +
        • +
        • + + + (打钩为公开,不打钩则不公开,若不公开,仅课程成员可见该课程。) +
          +
        • +
        • + + + (打钩为"学生列表公开",不打钩为不公开,若不公开,则课程外部人员看不到学生列表) +
          +
        • +
        • + 提交 + 取消 +
          +
        • + <% end%> +
        +
        +
        \ No newline at end of file diff --git a/app/views/courses/new_homework.html.erb b/app/views/courses/new_homework.html.erb index 2e0b35c6d..ac26c2f29 100644 --- a/app/views/courses/new_homework.html.erb +++ b/app/views/courses/new_homework.html.erb @@ -1,115 +1,4 @@ - - -

        <%=l(:label_course_new_homework)%>

        - -<%= labelled_form_for @homework, :url => {:controller => 'bids', :action => 'create_homework',:course_id => "#{params[:id] || params[:course_id]}"} do |f| %> -
        - <%= render :partial => 'homework_form', :locals => { :f => f } %> - - <%= l(:button_create)%> - <%= javascript_tag "$('#bid_name').focus();" %> - <% end %> -
        \ No newline at end of file +<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= labelled_form_for @homework, :html => { :multipart => true }, :url => {:controller => 'bids', :action => 'create_homework',:course_id => "#{params[:id] || params[:course_id]}"} do |f| %> + <%= render :partial => 'bids/new_homework_form', :locals => { :bid => @homework,:bid_id => "new_bid",:f => f,:edit_mode => false } %> +<% end %> \ No newline at end of file diff --git a/app/views/courses/new_join.js.erb b/app/views/courses/new_join.js.erb index c0a6f4a50..00245f8cb 100644 --- a/app/views/courses/new_join.js.erb +++ b/app/views/courses/new_join.js.erb @@ -1,3 +1,8 @@ -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'projects/new_join', :locals => {:course => @course}) %>'); -showModal('ajax-modal', '400px'); -$('#ajax-modal').addClass('new-watcher'); +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'projects/new_join', locals: { :course => @course}) %>'); +showModal('ajax-modal', '500px'); +$('#ajax-modal').css('height','100px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + +""); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("anonymos"); diff --git a/app/views/courses/searchmembers.js.erb b/app/views/courses/searchmembers.js.erb index efe47a9c0..1d3c0ad21 100644 --- a/app/views/courses/searchmembers.js.erb +++ b/app/views/courses/searchmembers.js.erb @@ -1,4 +1,4 @@ /** * Created by Administrator on 2014/12/2. */ -$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>"); \ No newline at end of file +$("#member_content").html("<%= escape_javascript( render :partial => 'new_member_list', :locals => {:members => @results})%>"); \ No newline at end of file diff --git a/app/views/courses/settings.html.erb b/app/views/courses/settings.html.erb index c2030ffec..acc6c12a5 100644 --- a/app/views/courses/settings.html.erb +++ b/app/views/courses/settings.html.erb @@ -1,3 +1,77 @@ -

        <%=l(:label_settings)%>

        -<%= render_tabs course_settings_tabs %> -<% html_title(l(:label_settings)) -%> +
        +

        <%= l(:label_course_modify_settings)%>

        +
        +
        +
        +
          +
        • + 基本信息 +
        • +
        • + 成员 +
        • +
        +
        +
        +
          + <%= labelled_form_for @course do |f| %> +
        • + <%= render :partial => "avatar/new_avatar_form", :locals => {source: @course} %> +
          +
        • +
        • + + + +
        • +
          +
        • + + + +
        • +
          +
        • + + <%= select_tag :time,options_for_select(course_time_option(@course.time),@course.time), {} %> + <%= select_tag :term,options_for_select(course_term_option,@course.term || cur_course_term),{} %> +
        • +
          +
        • + + + 显示明码 +
          + 学生或其他成员申请加入课程时候需要使用该口令,该口令可以由老师在课堂上公布。 +
        • +
        • + + +
          +
        • +
        • + + id="course_is_public" name="course[is_public]" type="checkbox"> + (打钩为公开,不打钩则不公开,若不公开,仅课程成员可见该课程。) +
          +
        • +
        • + + id="course_open_student" name="course[open_student]" type="checkbox" style="margin-left: 1px;"/> + (打钩为"学生列表公开",不打钩为不公开,若不公开,则课程外部人员看不到学生列表) +
          +
        • +
        • + 提交 + <%= link_to l(:button_cancel), course_path(@course), :class => "blue_btn grey_btn fl c_white" %> +
          +
        • + <% end %> +
        +
        + +
        + <%= render :partial => "course_members" %> +
        +
        +
        \ No newline at end of file diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 9c91908d2..1cc117dd6 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -1,143 +1,52 @@ - -<% if @events_by_day != nil && @events_by_day.size >0 %> -
        -

        -

        - - <% @events_by_day.keys.sort.reverse.each do |day| %> -
        - <% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%> -
        - - - - - -
        - <%= image_tag(url_to_avatar(e.event_author), :class => "avatar") %> - - - - - - - - - - - <% if e.event_type == "issue" %> - - <% end %> - -
        - - <%= h(e.event_title) if @course.nil? || (e.course != nil && @course.id != e.course.id) %> - - - <% if @canShowRealName %> - <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %> - (<%= link_to_user(e.event_author, @canShowRealName) if e.respond_to?(:event_author) %>) - <% else %> - <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %> - <% end %> - <%= l(:label_new_activity) %> - - <%= link_to "#{eventToLanguageCourse(e.event_type, @course)}: "<< format_activity_title(e.event_title), (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) : e.event_url%> -
        -

        - <%= e.event_description %> -

        -
        - - <%= l :label_activity_time %> - :  - <%= format_activity_day(day) %> - <%= format_time(e.event_datetime, false) %> - - - - <%= link_to l(:label_find_all_comments), issue_path(e.id) %> - - - <%= l(:label_comments_count, :count => e.journals.count) %> - -
        -
        -
        - <% end %> -
        - <% end -%> - <% if (@events_pages.page == @events_pages.last_page) %> -
        - - - - - -
        - <%= image_tag(url_to_avatar(@user), :class => "avatar") %> - - - - - - -
        - <% if @canShowRealName %> - (<%= link_to_user(@user, @canShowRealName) %>) - <% else %> - <%= link_to_user(@user)%> - <% end %> - - <%= l(:label_user_create_project) %> - <%= link_to @course.name %> - ! -
        - <%= l :label_create_time %>: - <%= format_time(@course.created_at) %> -
        -
        -
        - <% end %> -
        - <%else%> -
        - - - - - -
        - <%= image_tag(url_to_avatar(@user), :class => "avatar") %> - - - - - - -
        - <% if @canShowRealName %> - (<%= link_to_user(@user, @canShowRealName) %>) - <% else %> - <%= link_to_user(@user)%> - <% end %> - <%= l(:label_user_create_project) %> - <%= link_to @course.name %> - ! -
        - <%= l :label_create_time %>: - <%= format_time(@course.created_at) %> -
        -
        -
        -<% end %> - - - - + <%= file_field_tag 'attachments[dummy][file]', :id => '_file', - :class => 'file_selector', + :class => ie8? ? '':'file_selector', :multiple => true, :onchange => 'addInputFiles(this);', :style => ie8? ? '': 'display:none', @@ -41,10 +41,9 @@ :delete_all_files => l(:text_are_you_sure_all) } %> - \ No newline at end of file diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 030b6cb24..44dd50c5e 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -1,8 +1,3 @@ -<% attachmenttypes = @course.attachmenttypes %> -<% sufixtypes = @course.contenttypes %> - - -<%= stylesheet_link_tag 'resource', :media => 'all' %> + +
        +
        +
        + <%= form_tag( search_project_project_files_path(@project), method: 'get',:class => "re_search f_l",:remote=>true) do %> + <%= text_field_tag 'name', params[:name], name: "name", :class => 're_schbox',:style=>"padding: 0px"%> + <%= submit_tag "课内搜索", :class => "re_schbtn b_lblue",:name => "incourse",:id => "incourse", :onmouseover => "presscss('incourse')",:onmouseout =>"buttoncss()" %> + <%= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> + <% end %> + <% manage_allowed = User.current.allowed_to?(:manage_files, @project) %> + <% if manage_allowed %> + 上传资源 + <% end %> +
        +
        + +
        + <%= render :partial => 'project_file_list',:locals => {project: @project,all_attachments: @all_attachments,sort:@sort,order:@order,project_attachments:@obj_attachments,:manage_allowed => manage_allowed} %> +
        + +
        +
        +<% html_title(l(:label_attachment_plural)) -%> \ No newline at end of file diff --git a/app/views/files/_show_all_attachment.html.erb b/app/views/files/_show_all_attachment.html.erb index 6935c186f..729f0a483 100644 --- a/app/views/files/_show_all_attachment.html.erb +++ b/app/views/files/_show_all_attachment.html.erb @@ -24,8 +24,8 @@ - <% if @curse_attachments != nil %> - <% @curse_attachments.each do |file| %> + <% if @obj_attachments != nil %> + <% @obj_attachments.each do |file| %> <%if file.is_public == 0 && !User.current.member_of?(@project)%> <%next%> <%end%> diff --git a/app/views/files/_show_quote_resource.html.erb b/app/views/files/_show_quote_resource.html.erb index eb1ed446e..02009e462 100644 --- a/app/views/files/_show_quote_resource.html.erb +++ b/app/views/files/_show_quote_resource.html.erb @@ -14,7 +14,7 @@ id: "relation_file_form" do %> <%= hidden_field_tag(:file_id, file.id) %> <%= content_tag('div', courses_check_box_tags('courses[course][]', User.current.courses,course,file), :id => 'courses')%> - 引  用取  消 + 引  用取  消 <% end -%>
        <% end %> diff --git a/app/views/files/_show_quote_resource_project.html.erb b/app/views/files/_show_quote_resource_project.html.erb new file mode 100644 index 000000000..7df1dc2f3 --- /dev/null +++ b/app/views/files/_show_quote_resource_project.html.erb @@ -0,0 +1,31 @@ +
        +
        +

        将此课件引入我的资源库

        + <% if error == '403' %> +
        +
        您没有权限引用此资源
        +
        + <% else %> +
        +
        + <%= form_tag attach_relations_path, + method: :post, + remote: true, + id: "relation_file_form" do %> + <%= hidden_field_tag(:file_id, file.id) %> + <%= content_tag('div', projects_check_box_tags('projects[project][]', User.current.projects,project,file), :id => 'projects')%> + 引  用取  消 + <% end -%> +
        + <% end %> + + +
        +
        + + \ No newline at end of file diff --git a/app/views/files/_upload_show.html.erb b/app/views/files/_upload_show.html.erb index 70465c21e..959fcb7bf 100644 --- a/app/views/files/_upload_show.html.erb +++ b/app/views/files/_upload_show.html.erb @@ -1,4 +1,5 @@ -
        + +

        <%= l(:label_upload_files)%>

        @@ -9,8 +10,8 @@ <%= render :partial => 'attachement_list',:locals => {:course => course} %>
        - <%= l(:button_confirm)%> - <%= l(:button_cancel)%> + <%= l(:button_cancel)%> + <%= l(:button_confirm)%> <% end %>
        diff --git a/app/views/files/_upload_show_project.html.erb b/app/views/files/_upload_show_project.html.erb new file mode 100644 index 000000000..25a03b347 --- /dev/null +++ b/app/views/files/_upload_show_project.html.erb @@ -0,0 +1,29 @@ + +
        +
        +

        <%= l(:label_upload_files)%>

        +
        + <%= error_messages_for 'attachment' %> + + + <%= form_tag(project_files_path(project), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> + + <%= render :partial => 'attachement_list',:locals => {:project => project} %> +
        + <%= l(:button_cancel)%> + <%= l(:button_confirm)%> + <% end %> +
        + +
        + <% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> + <% end %> +
        + + \ No newline at end of file diff --git a/app/views/files/create.js.erb b/app/views/files/create.js.erb index 69ea896c9..b00ae3612 100644 --- a/app/views/files/create.js.erb +++ b/app/views/files/create.js.erb @@ -1,35 +1,33 @@ -<%if @addTag%> -<% if @obj_flag == '3'%> - -$('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name', +<% if @addTag%> + <% if @obj_flag == '3'%> + $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); -//$('#put-tag-form-issue').hide(); -$('#name-issue').val(""); -<% elsif @obj_flag == '6'%> -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name', + //$('#put-tag-form-issue').hide(); + $('#name-issue').val(""); + <% elsif @obj_flag == '6'%> + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); -$("#put-tag-form- <%=@obj.class%>- <%=@obj.id%>").hide(); -$("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val(""); -<% else %> - -$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', + $("#put-tag-form- <%=@obj.class%>- <%=@obj.id%>").hide(); + $("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val(""); + <% else %> + $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); -$('#tags_show').html('<%=render_attachments_tag_save(@project, nil)%>'); -$('#put-tag-form #name').val(""); -//$('#put-tag-form').hide(); -<% end %> -<%else%> + $('#tags_show').html('<%=render_attachments_tag_save(@project, nil)%>'); + $('#put-tag-form #name').val(""); + //$('#put-tag-form').hide(); + <% end %> +<% else %> $("#attachments_fields").children().remove(); $("#upload_file_count").text("未上传文件"); $('#upload_file_div').slideToggle('slow'); -<%if @project%> -$("#all_browse_div").html('<%= j(render partial: "show_all_attachment")%>'); -<%elsif @course%> -$("#all_browse_div").html('<%= j(render partial: "course_show_all_attachment")%>'); -closeModal(); -$("#resource_list").html('<%= j(render partial: "course_file" ,locals: {course: @course}) %>'); -<%end%> + <% if @project%> + closeModal(); + $("#resource_list").html('<%= j(render partial: "project_file_new" ,locals: {project: @project}) %>'); + <%elsif @course%> + closeModal(); + $("#resource_list").html('<%= j(render partial: "course_file" ,locals: {course: @course}) %>'); + <% end %> <% end %> $(document).ready(img_thumbnails); diff --git a/app/views/files/quote_resource_show.js.erb b/app/views/files/quote_resource_show.js.erb index 1d82479c5..fa1f8f4ca 100644 --- a/app/views/files/quote_resource_show.js.erb +++ b/app/views/files/quote_resource_show.js.erb @@ -7,4 +7,5 @@ showModal('ajax-modal', '513px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(""); -$('#ajax-modal').parent().css("top","5").css("left","511"); \ No newline at end of file +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("popbox_polls"); \ No newline at end of file diff --git a/app/views/files/quote_resource_show_project.js.erb b/app/views/files/quote_resource_show_project.js.erb new file mode 100644 index 000000000..440004357 --- /dev/null +++ b/app/views/files/quote_resource_show_project.js.erb @@ -0,0 +1,11 @@ +<% if @can_quote %> + $('#ajax-modal').html('<%= escape_javascript(render :partial => 'show_quote_resource_project',:locals => {:project => @project,:file => @file,:error => ''}) %>'); +<% else %> + $('#ajax-modal').html('<%= escape_javascript(render :partial => 'show_quote_resource_project',:locals => {:project => @project,:file => @file,:error => '403'}) %>'); +<% end %> + +showModal('ajax-modal', '513px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("popbox_polls"); \ No newline at end of file diff --git a/app/views/files/search_project.js.erb b/app/views/files/search_project.js.erb new file mode 100644 index 000000000..f64b8beeb --- /dev/null +++ b/app/views/files/search_project.js.erb @@ -0,0 +1 @@ +$("#course_list").html("<%= escape_javascript(render :partial => 'project_file_list',:locals => {project: @project,all_attachments: @result,sort:@sort,order:@order,project_attachments:@searched_attach,:manage_allowed => User.current.allowed_to?(:manage_files, @project)})%>"); \ No newline at end of file diff --git a/app/views/forums/_form.html.erb b/app/views/forums/_form_create_mode.html.erb similarity index 81% rename from app/views/forums/_form.html.erb rename to app/views/forums/_form_create_mode.html.erb index ac9c298ff..63162c7a0 100644 --- a/app/views/forums/_form.html.erb +++ b/app/views/forums/_form_create_mode.html.erb @@ -1,49 +1,51 @@ - - -
        - <%= labelled_form_for(@forum) do |f| %> - <% if @forum.errors.any? %> - - <% end %> -
        -
        - <%= f.text_field :name, :required => true, :style => 'width: 100%;', :class => 'create-share', :maxlength => 50%> -
        -
        - <% if User.current.logged? && User.current.admin? %> - <% if @forum.safe_attribute? 'sticky' %> - <%= f.check_box :sticky %> - <%= label_tag 'message_sticky', l(:label_board_sticky) %> - <% end %> - <% if @forum.safe_attribute? 'locked' %> - <%= f.check_box :locked %> - <%= label_tag 'message_locked', l(:label_board_locked) %> - <% end %> - <% end %> -
        -
        - -

        - <%= f.text_area :description, :required => true, :id => 'editor01' %> -

        - - -

        - (<%= l(:label_forums_max_length) %>) -

        -
        -
        - <%= submit_tag l(:button_submit) %> - <%= link_to l(:button_back), forums_path ,:style => 'font-size: 14px; padding: 0px 3px;' %> -
        -
        - <% end %> -
        + + + +
        + <%= labelled_form_for(@forum) do |f| %> + <% if @forum.errors.any? %> + + <% end %> +
        +
        + <%= f.text_field :name, :required => true, :style => 'width: 100%;', :class => 'create-share', :maxlength => 50%> +
        +
        + <% if User.current.logged? && User.current.admin? %> + <% if @forum.safe_attribute? 'sticky' %> + <%= f.check_box :sticky %> + <%= label_tag 'message_sticky', l(:label_board_sticky) %> + <% end %> + <% if @forum.safe_attribute? 'locked' %> + <%= f.check_box :locked %> + <%= label_tag 'message_locked', l(:label_board_locked) %> + <% end %> + <% end %> +
        +
        + + <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> +

        + <%= f.kindeditor :description, :required => true %> +

        + + +

        + (<%= l(:label_forums_max_length) %>) +

        +
        +
        + <%= submit_tag l(:button_submit) %> + <%= link_to l(:button_back), forums_path ,:style => 'font-size: 14px; padding: 0px 3px;' %> +
        +
        + <% end %> +
        diff --git a/app/views/forums/_form_edit_mode.html.erb b/app/views/forums/_form_edit_mode.html.erb new file mode 100644 index 000000000..a9bb05f79 --- /dev/null +++ b/app/views/forums/_form_edit_mode.html.erb @@ -0,0 +1,49 @@ + + + +
        + <%= labelled_form_for(@forum) do |f| %> + <% if @forum.errors.any? %> + + <% end %> +
        +
        + <%= f.text_field :name, :required => true, :style => 'width: 100%;', :class => 'create-share', :maxlength => 50%> +
        +
        + <% if User.current.logged? && User.current.admin? %> + <% if @forum.safe_attribute? 'sticky' %> + <%= f.check_box :sticky %> + <%= label_tag 'message_sticky', l(:label_board_sticky) %> + <% end %> + <% if @forum.safe_attribute? 'locked' %> + <%= f.check_box :locked %> + <%= label_tag 'message_locked', l(:label_board_locked) %> + <% end %> + <% end %> +
        +
        +

        + <%= f.kindeditor :description, :required => true,:owner_id => @forum.id,:owner_type => 2 %> +

        + + +

        + (<%= l(:label_forums_max_length) %>) +

        +
        +
        + <%= submit_tag l(:button_submit) %> + <%= link_to l(:button_back), forums_path ,:style => 'font-size: 14px; padding: 0px 3px;' %> +
        +
        + <% end %> +
        diff --git a/app/views/forums/_forum_list.html.erb b/app/views/forums/_forum_list.html.erb index fe2f757c3..59ed1092e 100644 --- a/app/views/forums/_forum_list.html.erb +++ b/app/views/forums/_forum_list.html.erb @@ -16,7 +16,7 @@ - +

        <%= textAreailizable forum.description%>

        diff --git a/app/views/forums/_show_topics.html.erb b/app/views/forums/_show_topics.html.erb index 7a9eb4316..e61995ecc 100644 --- a/app/views/forums/_show_topics.html.erb +++ b/app/views/forums/_show_topics.html.erb @@ -26,7 +26,10 @@ <%= authoring topic.created_at, topic.author %> - 最后回复:<%=link_to_user topic.last_reply.try(:author) %> + <% author = topic.last_reply.try(:author)%> + <% if author%> + 最后回复:<%=link_to_user author %> + <% end%>
        diff --git a/app/views/forums/edit.html.erb b/app/views/forums/edit.html.erb index 4aafbac7f..9fe72fdb7 100644 --- a/app/views/forums/edit.html.erb +++ b/app/views/forums/edit.html.erb @@ -1,4 +1,4 @@

        编辑讨论区

        - -<%= render 'form' %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= render 'form_edit_mode' %> diff --git a/app/views/forums/new.html.erb b/app/views/forums/new.html.erb index 0d51db57a..35814d843 100644 --- a/app/views/forums/new.html.erb +++ b/app/views/forums/new.html.erb @@ -5,7 +5,7 @@ <% @nav_dispaly_forum_label = 1%>

        <%= l :label_forum_new %>

        - -<%= render 'form' %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= render 'form_create_mode' %> <%#= link_to l(:button_back), forums_path %> diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 85fa8093a..2f4ec56a0 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -6,13 +6,14 @@ <% if User.current.logged? %> <%= labelled_form_for(@memo, :url => create_memo_forum_path(@forum), :html => {:multipart => true} ) do |f| %>
        + <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>

        <%= 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_member.html.erb b/app/views/homework_attach/_homework_member.html.erb index 82e4a3b36..0064d45be 100644 --- a/app/views/homework_attach/_homework_member.html.erb +++ b/app/views/homework_attach/_homework_member.html.erb @@ -61,7 +61,7 @@ <%= render_new_members_for_homework(members) %>

        - + <%= l(:button_add) %>

        diff --git a/app/views/homework_attach/_homeworks_list.html.erb b/app/views/homework_attach/_homeworks_list.html.erb index 9c960d8b8..d2121c85f 100644 --- a/app/views/homework_attach/_homeworks_list.html.erb +++ b/app/views/homework_attach/_homeworks_list.html.erb @@ -11,9 +11,17 @@ ( <%= homework_count%> ) + <% + url= get_batch_homeworks_homework_attach_index_path(:bid_id => @bid.id) if is_batch_homeworks + url= get_not_batch_homework_homework_attach_index_path(:bid_id => @bid.id) if not_batch_homework + url= get_homeworks_homework_attach_index_path(:bid_id => @bid.id) if is_all_homeworks + %> + <%= link_to l(:label_export_excel), get_batch_homeworks_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if is_batch_homeworks%> <%= link_to l(:label_export_excel), get_not_batch_homework_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if not_batch_homework%> <%= link_to l(:label_export_excel), get_homeworks_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if is_all_homeworks%> + + 搜索 按  diff --git a/app/views/homework_attach/_praise_alert.html.erb b/app/views/homework_attach/_praise_alert.html.erb index d7f5dd446..3d9d05d79 100644 --- a/app/views/homework_attach/_praise_alert.html.erb +++ b/app/views/homework_attach/_praise_alert.html.erb @@ -11,8 +11,8 @@

        匿名评价

            据说雷锋做完好事是从来不留名的呢,我们这次评分也不留名!!!但是,但是,您给的分数一定要公正哦,老天爷看不到,我们的系统可是清楚得很!

            别怪我没告诉你,系统分配给你的作品不评价可是要扣分的哈!

        - 匿名评分 - 冒着扣分的危险残忍拒绝 + 匿名评分 + 冒着扣分的危险残忍拒绝
        diff --git a/app/views/homework_attach/_show_star.html.erb b/app/views/homework_attach/_show_star.html.erb index 33279c360..80f9d7f54 100644 --- a/app/views/homework_attach/_show_star.html.erb +++ b/app/views/homework_attach/_show_star.html.erb @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/app/views/homework_attach/_show_static_star.html.erb b/app/views/homework_attach/_show_static_star.html.erb index 7fe3edf22..b0f525680 100644 --- a/app/views/homework_attach/_show_static_star.html.erb +++ b/app/views/homework_attach/_show_static_star.html.erb @@ -1,5 +1,5 @@ - - - - - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb index 26d2a02a0..19c0d9344 100644 --- a/app/views/homework_attach/edit.html.erb +++ b/app/views/homework_attach/edit.html.erb @@ -28,7 +28,7 @@ } else { - $("#homework_attach_name_span").text("填写正确"); + $("#homework_attach_name_span").text("<%= l(:label_field_correct)%>"); $("#homework_attach_name_span").css('color','#008000'); return true; } @@ -107,7 +107,7 @@                        - + <%= l(:label_button_ok) %> 取  消 diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb index e9d32afd4..8697ff7ab 100644 --- a/app/views/homework_attach/new.html.erb +++ b/app/views/homework_attach/new.html.erb @@ -56,6 +56,7 @@
        <%= form_for(HomeworkAttach.new, :method => :post, :name => 'new_form', + :html => { :multipart => true }, :url => {:controller => 'homework_attach', :action => 'create', :user_id => User.current.id, @@ -103,7 +104,7 @@                        - + <%= l(:label_button_ok) %> 取  消 diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb index 58960df4c..4519b6047 100644 --- a/app/views/issues/_list.html.erb +++ b/app/views/issues/_list.html.erb @@ -55,9 +55,9 @@ <%= l(:label_updated_time_on, format_date(issue.updated_on)).html_safe %>
        - <%= link_to l(:label_find_all_comments), issue_path(issue.id) %> + <%= link_to l(:label_find_all_comments), issue_path(issue.id) if issue.journals.all.count!= 0 %> - <%= l(:label_comments_count, :count => issue.journals.all.count) %> + <%= l(:label_comments_count, :count => issue.journals.all.count) %>
      <% end -%> diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 946fd9715..b75a90c55 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -12,7 +12,7 @@ :onclick => '$("#custom_query").slideToggle(400); ' if true || User.current.logged? %> <% end %> - <%= l(:label_issues_sum) %>:<%= @project.issues.count %> <%= l(:lable_issues_undo) %> <%= @project.issues.where('status_id in (1,2,4,6)').count %> + <%= l(:label_issues_sum) %>:<%= @project.issues.count %> <%= l(:lable_issues_undo) %>:<%= @project.issues.where('status_id in (1,2,4,6)').count %>
      <% if !@query.new_record? && @query.editable_by?(User.current) %> diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 51ebd139e..0ac338321 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -1,5 +1,5 @@
      -

      问题跟踪

      +

      <%= l(:label_issue_new) %>

      <%= call_hook(:view_issues_new_top, {:issue => @issue}) %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 38afc672d..1f782341d 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -1,5 +1,5 @@
      -

      <%= l(:label_issue_plural) %>

      +

      <%= l(:label_issue_edit) %>

      <%# html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> <% html_title "#{@issue.tracker.name} #{@issue.source_from}'#'#{@issue.project_index}: #{@issue.subject}" %> diff --git a/app/views/layouts/_base_feedback.html.erb b/app/views/layouts/_base_feedback.html.erb index bbf26dd8b..0f901ea65 100644 --- a/app/views/layouts/_base_feedback.html.erb +++ b/app/views/layouts/_base_feedback.html.erb @@ -85,13 +85,13 @@ show_btn.css('width', 25); } - //close??? + //close closeBtn.bind("click",function(){ sideContent.animate({width: '0px'},"fast"); show_btn.stop(true, true).delay(300).animate({ width: '25px'},"fast"); cookiesave('minStatue','true','','',''); }); - //show??? + //show show_btn.bind("click",function() { $(this).animate({width: '0px'},"fast"); sideContent.stop(true, true).delay(200).animate({ width: '154px'},"fast"); @@ -110,7 +110,7 @@ $(function(){ myTips("<%= l(:label_feedback_success) %>","success"); }); -}) +}); function f_submit() { @@ -121,15 +121,15 @@ function cookiesave(n, v, mins, dn, path) { if(n) { - + if(!mins) mins = 365 * 24 * 60; if(!path) path = "/"; var date = new Date(); - + date.setTime(date.getTime() + (mins * 60 * 1000)); - + var expires = "; expires=" + date.toGMTString(); - + if(dn) dn = "domain=" + dn + "; "; document.cookie = n + "=" + v + expires + "; " + dn + "path=" + path; @@ -167,13 +167,12 @@ function cookieget(n) <% get_memo %> <%= form_for(@new_memo, :url => create_feedback_forum_path(@public_forum)) do |f| %> <%= f.text_area :subject, :class => "opnionText", :placeholder => l(:label_feedback_tips) %> - <%= f.hidden_field :content, :required => true , :value => l(:label_feedback_value) %> + <%= f.hidden_field :content,:id => 'hidden', :required => true , :value => l(:label_feedback_value) %> <%#= f.submit :value => l(:label_memo_create), :class => "opnionButton", :id => "button1" %> <%= l(:label_submit)%> - <% end %> -
      + <% end %> +
    diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index 0c7cca7d5..322fae0e3 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -22,14 +22,26 @@

    diff --git a/app/views/layouts/_base_header.html.erb b/app/views/layouts/_base_header.html.erb index 445a5abf4..9eaf7f6ed 100644 --- a/app/views/layouts/_base_header.html.erb +++ b/app/views/layouts/_base_header.html.erb @@ -1,32 +1,3 @@ -<% - request.headers['REQUEST_URI'] = "" if request.headers['REQUEST_URI'].nil? - realUrl = request.original_url - if (realUrl.match(/.*forge\.trustie\.net\/*/)) - #@nav_dispaly_project_label = 1 - #@nav_dispaly_forum_label = 1 - elsif (realUrl.match(/.*course\.trustie\.net\/*/)) - #@nav_dispaly_course_all_label = 1 - #@nav_dispaly_forum_label = 1 - #@nav_dispaly_course_label = nil - #@nav_dispaly_store_all_label = 1 - elsif (realUrl.match(/.*user\.trustie\.net\/*/)) - #@nav_dispaly_home_path_label = 1 - #@nav_dispaly_main_course_label = 1 - #@nav_dispaly_main_project_label = 1 - #@nav_dispaly_main_contest_label = 1 - elsif (realUrl.match(/.*contest\.trustie\.net\/*/)) - #@nav_dispaly_contest_label = 1 - #@nav_dispaly_store_all_label = 1 - else - #@nav_dispaly_project_all_label = 1 - #@nav_dispaly_course_all_label = 1 - #@nav_dispaly_forum_label = 1 - #@nav_dispaly_bid_label = 1 - #@nav_dispaly_contest_label = 1 - #@nav_dispaly_store_all_label = 1 - #@nav_dispaly_user_label = 1 - end -%> <%= render :partial => "layouts/base_feedback" %>
    <% end -%> - <%#= render_menu :top_menu if User.current.logged? || !Setting.login_required? -%> <%= render_dynamic_nav if User.current.logged? || !Setting.login_required? -%> - <%# 自建导航条在base页面中以 (@nav_dispaly......) 开头变量设定, 全局搜索即可发现 %>
    -
    -
    + + + + + + +
    + + \ No newline at end of file diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index bcc7a1c90..439c5f7b2 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -3,6 +3,7 @@ <%=h html_title %> + <%= render :partial => "layouts/point_browser" %> <%= csrf_meta_tag %> diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 814478174..f277cbaa6 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -1,9 +1,8 @@ -<% @nav_dispaly_course_all_label = 1 - @nav_dispaly_forum_label = 1 - @nav_dispaly_course_label = nil - @nav_dispaly_store_all_label = 1 %> +<% course_model %> <% teacher_num = teacherCount(@course) %> <% student_num = studentCount(@course) %> +<% course_file_num = visable_attachemnts_incourse(@course).count%> +<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> @@ -15,353 +14,181 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %> - <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> - <%= javascript_include_tag "jquery.leanModal.min" %> <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> + <%= stylesheet_link_tag 'public', 'leftside', 'courses'%> + <%= javascript_include_tag "course","header" %> <%= yield :header_tags -%> - -
    -
    -
    -<%= render :partial => 'layouts/base_header' %> -
    - -
    - - - - - - - - - - -
    - + + - - <%= l(:label_user_location) %> : - - - -
    -

    - <%= link_to l(:field_homepage), home_path %> - > - - <%=l(:label_courses_management_platform)%> + +

    + <%= l(:label_user_location) %> : + <%= link_to l(:field_homepage), home_path %> + > + + <%=l(:label_courses_management_platform)%> + + > + <%= link_to @course.name, course_path(@course) %> +

    + +
    -
    - - - - -<%= render :partial => 'layouts/base_footer' %> -
    + <%= render :partial => 'layouts/new_footer' %> +
    +
    +<%= render :partial => 'layouts/new_feedback' %> -
    -
    <%= call_hook :view_layouts_base_body_bottom %> -
    \ No newline at end of file diff --git a/app/views/layouts/base_forums.html.erb b/app/views/layouts/base_forums.html.erb index cc9cdd071..4d79f50f9 100644 --- a/app/views/layouts/base_forums.html.erb +++ b/app/views/layouts/base_forums.html.erb @@ -12,11 +12,12 @@ <%= csrf_meta_tag %> <%= favicon %> + <%= javascript_include_tag "/assets/kindeditor/kindeditor" %> <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> <%= heads_for_theme %> - <%= javascript_include_tag "ckeditor/ckeditor.js" %> + <%= call_hook :view_layouts_base_html_head %> <%= yield :header_tags -%> @@ -52,7 +53,7 @@