diff --git a/.gitignore b/.gitignore index bc936c34c..a6ee997aa 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ public/api_doc/ /.metadata vendor/cache +/files +/public/images/avatars +/public/files 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/bids_controller.rb b/app/controllers/bids_controller.rb index be97fdb6e..d38846ea0 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -490,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 @@ -1035,11 +1035,12 @@ class BidsController < ApplicationController 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} diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 57ad9d4ce..d226000c0 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -27,7 +27,7 @@ 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] diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a243018ba..8710b624e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,5 +1,5 @@ class CoursesController < ApplicationController - layout 'base_courses' + # layout 'base_courses' include CoursesHelper include ActivitiesHelper helper :activities @@ -73,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) } @@ -82,7 +83,7 @@ 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 @@ -407,6 +408,10 @@ class CoursesController < ApplicationController @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 @@ -424,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') @@ -681,9 +687,10 @@ class CoursesController < ApplicationController "show_course_files" => true, "show_course_news" => true, "show_course_messages" => true, - "show_course_journals_for_messages" => true, + #"show_course_journals_for_messages" => true, "show_bids" => 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 @@ -737,7 +744,7 @@ class CoursesController < ApplicationController @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) end - sorted_events = sort_activity_events_course(events); + 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 diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 1ca3e2fcf..12d1f6856 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,7 +23,7 @@ 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,:search_project,:quote_resource_show_project] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project,:search_tag_attachment] helper :sort include SortHelper @@ -51,6 +51,7 @@ class FilesController < ApplicationController @sort = "" @order = "" @is_remote = true + @q = params[:name].strip if params[:sort] order_by = params[:sort].split(":") @sort = order_by[0] @@ -60,19 +61,26 @@ class FilesController < ApplicationController sort = "#{@sort} #{@order}" end + # show_attachments [@course] + 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,@course - @searched_attach = paginateHelper @result,10 + if q == "%%" + @result = [] + @searched_attach = paginateHelper @result,10 + else + @result = find_public_attache q,sort + @result = visable_attachemnts_insite @result,@course + @searched_attach = paginateHelper @result,10 + end else @result = find_course_attache q,@course,sort @result = visable_attachemnts @result @searched_attach = paginateHelper @result,10 + @tag_list = attachment_tag_list @result end - #rescue Exception => e # #render 'stores' # redirect_to search_course_files_url @@ -273,6 +281,8 @@ class FilesController < ApplicationController show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + render :layout => 'base_courses' end @@ -346,6 +356,27 @@ class FilesController < ApplicationController Mailer.run.attachments_added(attachments[:files]) end + if params[:course_attachment_type] && params[:course_attachment_type] != "5" + case params[:course_attachment_type] + when "1" + tag_name = l(:label_courseware) + when "2" + tag_name = l(:label_software) + when "3" + tag_name = l(:label_media) + when "4" + tag_name = l(:label_code) + else + tag_name = "" + end + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + # TODO: 临时用 nyan sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -489,8 +520,31 @@ class FilesController < ApplicationController format.html end end + end + #查找指定TAG的按条件过滤的资源列表,只有课程内搜索有此功能 + def search_tag_attachment + @q,@tag_name,@order = params[:q],params[:tag_name] + @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 + q = "%#{@q.strip}%" + @result = find_course_attache q,@course,sort + @result = visable_attachemnts @result + @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} + @searched_attach = paginateHelper @result,10 + @tag_list = attachment_tag_list @result + respond_to do |format| + format.js + # format.html + end end end 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/messages_controller.rb b/app/controllers/messages_controller.rb index c58ebf851..436418430 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -192,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)}
((.|\s)*?)}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n") + "\n\n
" << @content - #@temp = Message.new - #@temp.content = @content - + @temp.content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}".html_safe end def preview diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8e9802280..c846de965 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -323,6 +323,7 @@ class ProjectsController < ApplicationController @member ||= @project.members.new @trackers = Tracker.sorted.all @wiki ||= @project.wiki + @select_tab = params[:tab] end def send_mail_to_member 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/users_controller.rb b/app/controllers/users_controller.rb index a230688dc..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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ab5f0a308..dc52de3e3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -81,7 +81,7 @@ module ApplicationHelper def authorize_for(controller, action) User.current.allowed_to?({:controller => controller, :action => action}, @project) end - + # add by nwb def authorize_for_course(controller, action) User.current.allowed_to?({:controller => controller, :action => action}, @course) @@ -128,6 +128,15 @@ module ApplicationHelper end end + def link_to_isuue_user(user, options={}) + if user.is_a?(User) + name = h(user.name(options[:format])) + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => "pro_info_p" + else + h(user.to_s) + end + end + def link_to_settings_user(user, options={}) if user.is_a?(User) name = h(user.name(options[:format])) @@ -141,9 +150,10 @@ module ApplicationHelper def link_to_user_header user,canShowRealName=false,options={} if user.is_a?(User) if canShowRealName - name = h(user.realname(options[:format])) + name = user.show_name + name = user.login if name == "" else - name = h(user.name(options[:format])) + name = user.login end link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => options[:class] else @@ -178,6 +188,28 @@ module ApplicationHelper s end + def link_to_issue_version(issue, options={}) + title = nil + subject = nil + text = options[:tracker] == false ? "##{issue.id}" : "#{issue.tracker} ##{issue.id}" + if options[:subject] == false + title = truncate(issue.subject, :length => 60) + else + subject = issue.subject + if options[:truncate] + subject = truncate(subject, :length => 60) + end + end + if issue.status_id == 5 + s = link_to text, issue_path(issue), :class => "text_line_s", :title => title + else + s = link_to text, issue_path(issue), :class => "c_blue", :title => title + end + s << h(": #{subject}") if subject + s = h("#{issue.project} - ") + s if options[:project] + s + end + # Generates a link to an attachment. # Options: # * :text - Link text (default to attachment filename) @@ -201,7 +233,7 @@ module ApplicationHelper route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path html_options = options.slice!(:only_path) url = send(route_method, attachment, attachment.filename, options) - url << "?token=#{token}" unless token.nil? + url << "?token=#{token}" unless token.nil? link_to text, url, html_options end @@ -226,18 +258,18 @@ module ApplicationHelper h(text), {:controller => 'repositories', :action => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev}, :title => l(:label_revision_id, format_revision(revision)) - ) + ) end # Generates a link to a message def link_to_message(message, options={}, html_options = nil) link_to( - truncate(message.subject, :length => 60), - board_message_path(message.board_id, message.parent_id || message.id, { - :r => (message.parent_id && message.id), - :anchor => (message.parent_id ? "message-#{message.id}" : nil) - }.merge(options)), - html_options + truncate(message.subject, :length => 60), + board_message_path(message.board_id, message.parent_id || message.id, { + :r => (message.parent_id && message.id), + :anchor => (message.parent_id ? "message-#{message.id}" : nil) + }.merge(options)), + html_options ) end @@ -289,8 +321,8 @@ module ApplicationHelper def thumbnail_tag(attachment) link_to image_tag(thumbnail_path(attachment)), - named_attachment_path(attachment, attachment.filename), - :title => attachment.filename + named_attachment_path(attachment, attachment.filename), + :title => attachment.filename end # 图片缩略图链接 @@ -312,15 +344,15 @@ module ApplicationHelper onclick = "$('##{id}').slideToggle(); " onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ") onclick << "return false;" - link_to(name, "#", :onclick => onclick,:class => options[:class]) + link_to(name, "javascript:void(0)", :onclick => onclick,:class => options[:class]) end def image_to_function(name, function, html_options = {}) html_options.symbolize_keys! tag(:input, html_options.merge({ - :type => "image", :src => image_path(name), - :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" - })) + :type => "image", :src => image_path(name), + :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" + })) end def format_activity_title(text) @@ -354,7 +386,7 @@ module ApplicationHelper # The given collection may be a subset of the whole project tree # (eg. some intermediate nodes are private and can not be seen) #Modified by nie. - def render_project_nested_lists(projects) + def render_project_nested_lists(projects) s = '' if projects.any? ancestors = [] @@ -383,9 +415,9 @@ module ApplicationHelper if project.try(:project_type) == Project::ProjectType_project unless User.current.member_of?(@project) - s << "" - s << watcher_link(@project, User.current)#, ['whiteButton']) - s << "" + s << "" + s << watcher_link(@project, User.current)#, ['whiteButton']) + s << "" end s << (render :partial => 'projects/project', :locals => {:project => project}).to_s else @@ -398,7 +430,7 @@ module ApplicationHelper @project = original_project end s.html_safe - end + end def render_course_nested_lists(courses) s = '' @@ -433,7 +465,7 @@ module ApplicationHelper end - #added by young + #added by young def render_project_nested_lists_new(projects) s = '' if projects.any? @@ -462,7 +494,7 @@ module ApplicationHelper end s.html_safe end - #end + #end def render_page_hierarchy(pages, node=nil, options={}) content = '' if pages[node] @@ -511,8 +543,8 @@ module ApplicationHelper projects = User.current.memberships.collect(&:project).compact.select(&:active?).uniq if projects.any? options = - ("" + - '').html_safe + ("" + + '').html_safe options << project_tree_options_for_select(projects, :selected => @project) do |p| { :value => project_path(:id => p, :jump => current_menu_item) } @@ -702,24 +734,24 @@ module ApplicationHelper link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => method, :title => l(:label_sort_highest)) + - link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), - url.merge({"#{name}[move_to]" => 'higher'}), - :method => method, :title => l(:label_sort_higher)) + - link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), - url.merge({"#{name}[move_to]" => 'lower'}), - :method => method, :title => l(:label_sort_lower)) + - link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), - url.merge({"#{name}[move_to]" => 'lowest'}), - :method => method, :title => l(:label_sort_lowest)) + link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), + url.merge({"#{name}[move_to]" => 'higher'}), + :method => method, :title => l(:label_sort_higher)) + + link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), + url.merge({"#{name}[move_to]" => 'lower'}), + :method => method, :title => l(:label_sort_lower)) + + link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), + url.merge({"#{name}[move_to]" => 'lowest'}), + :method => method, :title => l(:label_sort_lowest)) end def breadcrumb(*args) elements = args.flatten - elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil + elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'wiki_con_tit"') : nil end def other_formats_links(&block) - concat('
#{@message.content.html_safe}'.html_safe + l(:label_export_to)) + concat('
'.html_safe + l(:label_export_to)) yield Redmine::Views::OtherFormatsBuilder.new(self) concat('
'.html_safe) end @@ -794,15 +826,15 @@ module ApplicationHelper def textilizable(*args) options = args.last.is_a?(Hash) ? args.pop : {} case args.size - when 1 - obj = options[:object] - text = args.shift - when 2 - obj = args.shift - attr = args.shift - text = obj.send(attr).to_s - else - raise ArgumentError, 'invalid arguments to textilizable' + when 1 + obj = options[:object] + text = args.shift + when 2 + obj = args.shift + attr = args.shift + text = obj.send(attr).to_s + else + raise ArgumentError, 'invalid arguments to textilizable' end return '' if text.blank? project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) @@ -958,18 +990,18 @@ module ApplicationHelper # check if page exists wiki_page = link_project.wiki.find_page(page) url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page - "##{anchor}" - else - case options[:wiki_links] - when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '') - when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export - else - wiki_page_id = page.present? ? Wiki.titleize(page) : nil - parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil - url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, - :id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent) - end - end + "##{anchor}" + else + case options[:wiki_links] + when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '') + when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export + else + wiki_page_id = page.present? ? Wiki.titleize(page) : nil + parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil + url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, + :id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent) + end + end link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new'))) else # project or wiki doesn't exist @@ -1044,110 +1076,110 @@ module ApplicationHelper # project.changesets.visible raises an SQL error because of a double join on repositories if repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(repository.id, identifier)) link = link_to(h("#{project_prefix}#{repo_prefix}r#{identifier}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.revision}, - :class => 'changeset', - :title => truncate_single_line(changeset.comments, :length => 100)) + :class => 'changeset', + :title => truncate_single_line(changeset.comments, :length => 100)) end end elsif sep == '#' oid = identifier.to_i case prefix - when nil - if oid.to_s == identifier && issue = Issue.visible.find_by_id(oid, :include => :status) - anchor = comment_id ? "note-#{comment_id}" : nil - link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => anchor}, - :class => issue.css_classes, - :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})") - end - when 'document' - if document = Document.visible.find_by_id(oid) - link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, - :class => 'document' - end - when 'version' - if version = Version.visible.find_by_id(oid) - link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, - :class => 'version' - end - when 'message' - if message = Message.visible.find_by_id(oid, :include => :parent) - link = link_to_message(message, {:only_path => only_path}, :class => 'message') - end - when 'forum' - if board = Board.visible.find_by_id(oid) - link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project}, - :class => 'board' - end - when 'news' - if news = News.visible.find_by_id(oid) - link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news}, - :class => 'news' - end - when 'project' - if p = Project.visible.find_by_id(oid) - link = link_to_project(p, {:only_path => only_path}, :class => 'project') - end + when nil + if oid.to_s == identifier && issue = Issue.visible.find_by_id(oid, :include => :status) + anchor = comment_id ? "note-#{comment_id}" : nil + link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => anchor}, + :class => issue.css_classes, + :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})") + end + when 'document' + if document = Document.visible.find_by_id(oid) + link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, + :class => 'document' + end + when 'version' + if version = Version.visible.find_by_id(oid) + link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, + :class => 'version' + end + when 'message' + if message = Message.visible.find_by_id(oid, :include => :parent) + link = link_to_message(message, {:only_path => only_path}, :class => 'message') + end + when 'forum' + if board = Board.visible.find_by_id(oid) + link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project}, + :class => 'board' + end + when 'news' + if news = News.visible.find_by_id(oid) + link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news}, + :class => 'news' + end + when 'project' + if p = Project.visible.find_by_id(oid) + link = link_to_project(p, {:only_path => only_path}, :class => 'project') + end end elsif sep == ':' # removes the double quotes if any name = identifier.gsub(%r{^"(.*)"$}, "\\1") case prefix - when 'document' - if project && document = project.documents.visible.find_by_title(name) - link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, - :class => 'document' - end - when 'version' - if project && version = project.versions.visible.find_by_name(name) - link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, - :class => 'version' - end - when 'forum' - if project && board = project.boards.visible.find_by_name(name) - link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project}, - :class => 'board' - end - when 'news' - if project && news = project.news.visible.find_by_title(name) - link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news}, - :class => 'news' - end - when 'commit', 'source', 'export' - if project - repository = nil - if name =~ %r{^(([a-z0-9\-_]+)\|)(.+)$} - repo_prefix, repo_identifier, name = $1, $2, $3 - repository = project.repositories.detect {|repo| repo.identifier == repo_identifier} - else - repository = project.repository + when 'document' + if project && document = project.documents.visible.find_by_title(name) + link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, + :class => 'document' + end + when 'version' + if project && version = project.versions.visible.find_by_name(name) + link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, + :class => 'version' + end + when 'forum' + if project && board = project.boards.visible.find_by_name(name) + link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project}, + :class => 'board' + end + when 'news' + if project && news = project.news.visible.find_by_title(name) + link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news}, + :class => 'news' end - if prefix == 'commit' - if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first) - link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier}, - :class => 'changeset', - :title => truncate_single_line(changeset.comments, :length => 100) + when 'commit', 'source', 'export' + if project + repository = nil + if name =~ %r{^(([a-z0-9\-_]+)\|)(.+)$} + repo_prefix, repo_identifier, name = $1, $2, $3 + repository = project.repositories.detect {|repo| repo.identifier == repo_identifier} + else + repository = project.repository end - else - if repository && User.current.allowed_to?(:browse_repository, project) - name =~ %r{^[/\\]*(.*?)(@([^/\\@]+?))?(#(L\d+))?$} - path, rev, anchor = $1, $3, $5 - link = link_to h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"), {:controller => 'repositories', :action => (prefix == 'export' ? 'raw' : 'entry'), :id => project, :repository_id => repository.identifier_param, - :path => to_path_param(path), - :rev => rev, - :anchor => anchor}, - :class => (prefix == 'export' ? 'source download' : 'source') + if prefix == 'commit' + if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first) + link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier}, + :class => 'changeset', + :title => truncate_single_line(changeset.comments, :length => 100) + end + else + if repository && User.current.allowed_to?(:browse_repository, project) + name =~ %r{^[/\\]*(.*?)(@([^/\\@]+?))?(#(L\d+))?$} + path, rev, anchor = $1, $3, $5 + link = link_to h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"), {:controller => 'repositories', :action => (prefix == 'export' ? 'raw' : 'entry'), :id => project, :repository_id => repository.identifier_param, + :path => to_path_param(path), + :rev => rev, + :anchor => anchor}, + :class => (prefix == 'export' ? 'source download' : 'source') + end end + repo_prefix = nil + end + when 'attachment' + attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) + if attachments && attachment = Attachment.latest_attach(attachments, name) + link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment') + end + when 'project' + if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first + link = link_to_project(p, {:only_path => only_path}, :class => 'project') end - repo_prefix = nil - end - when 'attachment' - attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) - if attachments && attachment = Attachment.latest_attach(attachments, name) - link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment') - end - when 'project' - if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first - link = link_to_project(p, {:only_path => only_path}, :class => 'project') - end end end end @@ -1164,9 +1196,9 @@ module ApplicationHelper @current_section += 1 if @current_section > 1 content_tag('div', - link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)), - :class => 'contextual', - :title => l(:button_edit_section)) + heading.html_safe + link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)), + :class => 'contextual', + :title => l(:button_edit_section)) + heading.html_safe else heading end @@ -1285,10 +1317,10 @@ module ApplicationHelper # Same as Rails' simple_format helper without using paragraphs def simple_format_without_paragraph(text) text.to_s. - gsub(/\r\n?/, "\n"). # \r\n and \r -> \n - gsub(/\n\n+/, "
"). # 2+ newline -> 2 br - gsub(/([^\n]\n)(?=[^\n])/, '\1
'). # 1 newline -> br - html_safe + gsub(/\r\n?/, "\n"). # \r\n and \r -> \n + gsub(/\n\n+/, "
"). # 2+ newline -> 2 br + gsub(/([^\n]\n)(?=[^\n])/, '\1
'). # 1 newline -> br + html_safe end def wiki_simple_format_without_paragraph(text) @@ -1303,7 +1335,7 @@ module ApplicationHelper end def lang_options_for_select(blank=true) - { 'Chinese简体中文 '=> 'zh', :English => :en} + { 'Chinese简体中文 '=> 'zh', :English => :en} end def label_tag_for(name, option_tags = nil, options = {}) @@ -1378,6 +1410,16 @@ module ApplicationHelper link_to l(:button_delete), url, options end + def delete_link_version(url, options={}) + options = { + :method => :delete, + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'c_purple' + }.merge(options) + + link_to l(:button_delete), url, options + end + def delete_new_link(url, options={}) @@ -1395,7 +1437,7 @@ module ApplicationHelper :href => "#", :onclick => %|submitPreview("#{escape_javascript url_for(url)}", "#{escape_javascript form}", "#{escape_javascript target}"); return false;|, :accesskey => accesskey(:preview) - }.merge(options) + }.merge(options) end def link_to_function(name, function, html_options={}) @@ -1422,7 +1464,7 @@ module ApplicationHelper def check_all_links(form_name) link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + " ".html_safe + " | "+ " ".html_safe + - link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") + link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") end def progress_bar(pcts, options={}) @@ -1433,12 +1475,12 @@ module ApplicationHelper width = options[:width] || '100px;' legend = options[:legend] || '' content_tag('table', - content_tag('tr', - (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : ''.html_safe) + - (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : ''.html_safe) + - (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : ''.html_safe) - ), :class => 'progress', :style => "width: #{width};").html_safe + - content_tag('p', legend, :class => 'percent').html_safe + content_tag('tr', + (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : ''.html_safe) + + (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : ''.html_safe) + + (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : ''.html_safe) + ), :class => 'progress', :style => "width: #{width};").html_safe + + content_tag('p', legend, :class => 'percent').html_safe end def checked_image(checked=true) @@ -1451,7 +1493,7 @@ module ApplicationHelper unless @context_menu_included content_for :header_tags do javascript_include_tag('context_menu') + - stylesheet_link_tag('context_menu') + stylesheet_link_tag('context_menu') end if l(:direction) == 'rtl' content_for :header_tags do @@ -1482,7 +1524,7 @@ module ApplicationHelper tags = javascript_tag( "var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " + "showOn: 'button', buttonImageOnly: true, buttonImage: '" + - path_to_image('/images/calendar.png') + + path_to_image('/images/public_icon.png') + "', showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true};") jquery_locale = l('jquery.locale', :default => current_language.to_s) unless jquery_locale == 'en' @@ -1504,7 +1546,7 @@ module ApplicationHelper tags = javascript_tag( "var datepickerOptions={dateFormat: 'yy-mm-dd',minDate: new Date(), firstDay: #{start_of_week}, " + "showOn: 'button', buttonImageOnly: true, buttonImage: '" + - path_to_image('/images/calendar.png') + + path_to_image('/images/public_icon.png') + "', showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true, onClose: function(dateText, inst) {TimeClose(dateText,inst);}, beforeShow : function(input){TimeBeforeShow(input);} };") jquery_locale = l('jquery.locale', :default => current_language.to_s) unless jquery_locale == 'en' @@ -1710,7 +1752,7 @@ module ApplicationHelper end s end - + def get_memo @new_memo = Memo.new #@new_memo.subject = "有什么想说的,尽管来咆哮吧~~" @@ -1797,11 +1839,11 @@ module ApplicationHelper html << (content_tag "span", l(:label_no_current_watchers)) end for user in User.watched_by(obj.id) - html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => "#{user.name}") - count = count + 1 - if count >= 12 - break - end + html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => "#{user.name}") + count = count + 1 + if count >= 12 + break + end end html.html_safe end @@ -1827,13 +1869,13 @@ module ApplicationHelper html.html_safe end - def show_bid_fans_picture(obj) + def show_bid_fans_picture(obj) html = '' if obj.watcher_users.count == 0 html << (content_tag "span", l(:label_project_no_follow)) else obj.watcher_users.take(12).each do |user| - html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name) + html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name) end end html.html_safe @@ -1868,7 +1910,7 @@ module ApplicationHelper html.html_safe end - def show_contest_project(contest) + def show_contest_project(contest) html = '' if contest.projects.where('is_public = 1').count == 0 html << (content_tag "p", l(:label_no_bid_project), :class => "font_lighter") @@ -1880,7 +1922,7 @@ module ApplicationHelper html.html_safe end - def show_contest_softapplication(contest) + def show_contest_softapplication(contest) html = '' if contest.softapplications.where('is_public = 1').count == 0 html << (content_tag "p", l(:label_no_contest_softapplication), :class => "font_lighter") @@ -1892,17 +1934,17 @@ module ApplicationHelper html.html_safe end - def show_contest_fans_picture(obj) + def show_contest_fans_picture(obj) html = '' if obj.watcher_users.count == 0 html << (content_tag "span", l(:label_project_no_follow)) else obj.watcher_users.take(12).each do |user| - html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name) + html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name) end end html.html_safe - end + end #display fans picture def show_more_fans?(obj) @@ -1919,13 +1961,13 @@ module ApplicationHelper html << (content_tag "span", l(:label_no_current_fans)) else obj.watcher_users.take(12).each do |user| - html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name) + html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name) end end html.html_safe end - # added by bai + # added by bai def show_more_participate?(obj) if obj.join_in_contests.count > 12 return true @@ -1934,18 +1976,18 @@ module ApplicationHelper end end - def show_participate_picture(obj) + def show_participate_picture(obj) html = '' count = 0 if obj.join_in_contests.count == 0 html << (content_tag "span", l(:label_no_current_participate)) end for temp in obj.join_in_contests - html << (link_to image_tag(url_to_avatar(temp.user), :class => "avatar"), user_path(temp.user), :class => "avatar", :title => "#{temp.user.name}") - count = count + 1 - if count >= 12 - break - end + html << (link_to image_tag(url_to_avatar(temp.user), :class => "avatar"), user_path(temp.user), :class => "avatar", :title => "#{temp.user.name}") + count = count + 1 + if count >= 12 + break + end end html.html_safe end @@ -1954,14 +1996,14 @@ module ApplicationHelper # add by huang def show_watcher_list(user) - html = '' - count = 0 + html = '' + count = 0 for user in User.watched_by(user.id) - html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => "#{user.name}") - count = count + 1 - if count >= 12 - break - end + html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => "#{user.name}") + count = count + 1 + if count >= 12 + break + end end html.html_safe end @@ -1979,14 +2021,14 @@ module ApplicationHelper return true if bid.nil? case bid.homework_type - when Bid::HomeworkFile - attaches = HomeworkAttach.where(bid_id: curb) - attaches.map(&:user_id).include? cur - when Bid::HomeworkProject - attaches = BidingProject.where(user_id: User.current, bid_id: bid) - attaches.count > 0 # > 0 则有提交记录 - else - true + when Bid::HomeworkFile + attaches = HomeworkAttach.where(bid_id: curb) + attaches.map(&:user_id).include? cur + when Bid::HomeworkProject + attaches = BidingProject.where(user_id: User.current, bid_id: bid) + attaches.count > 0 # > 0 则有提交记录 + else + true end end @@ -1999,6 +2041,8 @@ module ApplicationHelper 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} @@ -2018,23 +2062,23 @@ 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(project_new_link) if @nav_dispaly_project_label # nav_list.push(project_mine_link) if @nav_dispaly_main_project_label # 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| @@ -2048,12 +2092,12 @@ module ApplicationHelper end # def hadcommittedforcontest(curu) - # message = JournalsForMessage.find_by_sql("select * from journals_for_messages where jour_type = 'Softapplication' ") - # message.each do |createmessage| - # if createmessage.user_id == curu - # return true - # end - # end + # message = JournalsForMessage.find_by_sql("select * from journals_for_messages where jour_type = 'Softapplication' ") + # message.each do |createmessage| + # if createmessage.user_id == curu + # return true + # end + # end # end def footer_logo(ul_class=nil, li_class=nil) @@ -2073,63 +2117,63 @@ module ApplicationHelper def sort_homework_path(bid, sort, direction) case self.action_name - when 'show_courseEx' - get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: 'asc') - when 'get_not_batch_homework' - get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) - when 'get_batch_homeworks' - get_batch_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) - when 'get_homeworks' - get_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) - else - '#' + when 'show_courseEx' + get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: 'asc') + when 'get_not_batch_homework' + get_not_batch_homework_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) + when 'get_batch_homeworks' + get_batch_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) + when 'get_homeworks' + get_homeworks_homework_attach_index_path(bid_id: bid.id, sort: sort, direction: direction) + else + '#' end end def anonymous_comment_link(bid, course) link = case bid.comment_status - when 0 - confirm_info = "开启匿评后学生将不能对作业进行提交、修改、删除等操作\n" - confirm_info += anonymous_comment_notice(bid,course) - confirm_info += '是否确定开启匿评?' - link_to '启动匿评', start_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, :confirm => confirm_info, disable_with: '加载中...' - when 1 - confirm_info = "关闭匿评后所有同学将不能继续进行匿评,且将公开已提交作业列表\n" - confirm_info += anonymous_comment_notice(bid,course) - confirm_info += '是否确定关闭匿评?' - link_to '关闭匿评', stop_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true, :confirm => confirm_info - when 2 - '匿评结束' - end + when 0 + confirm_info = "开启匿评后学生将不能对作业进行提交、修改、删除等操作\n" + confirm_info += anonymous_comment_notice(bid,course) + confirm_info += '是否确定开启匿评?' + link_to '启动匿评', start_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, :confirm => confirm_info, disable_with: '加载中...' + when 1 + confirm_info = "关闭匿评后所有同学将不能继续进行匿评,且将公开已提交作业列表\n" + confirm_info += anonymous_comment_notice(bid,course) + confirm_info += '是否确定关闭匿评?' + link_to '关闭匿评', stop_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true, :confirm => confirm_info + when 2 + '匿评结束' + end content_tag('span', link, id: "#{bid.id}_anonymous_comment") end def anonymous_comment_notice(bid, course) - case bid.comment_status - when 0 - @student_size ||= searchStudent(course).size - @homework_size = bid.homeworks.size - percent = @homework_size.to_f / (@student_size == 0 ? 1 : @student_size) - confirm_info = "目前#{@student_size}个学生,总共提交了#{@homework_size}份作业,占#{number_to_percentage(percent * 100, precision: 1)}\n" - when 1 - @homework_evaluations = 0 - bid.homeworks.map { |homework| @homework_evaluations += homework.homework_evaluations.count} - teachers = "(" - teacher_members = searchTeacherAndAssistant(course) - teacher_members.each do |member| - if member == teacher_members.last - teachers += member.user_id.to_s + ")" - else - teachers += member.user_id.to_s + "," - end - end - @has_evaluations = 0 - bid.homeworks.map { |homework| @has_evaluations += homework.rates(:quality).where("seems_rateable_rates.rater_id not in #{teachers}").count} - - percent = @has_evaluations.to_f / (@homework_evaluations == 0 ? 1 : @homework_evaluations) - confirm_info = "目前总共分配了#{@homework_evaluations}份匿评作业,已评价#{@has_evaluations}份作业,占#{number_to_percentage(percent * 100, precision: 1)}\n" - end - confirm_info + case bid.comment_status + when 0 + @student_size ||= searchStudent(course).size + @homework_size = bid.homeworks.size + percent = @homework_size.to_f / (@student_size == 0 ? 1 : @student_size) + confirm_info = "目前#{@student_size}个学生,总共提交了#{@homework_size}份作业,占#{number_to_percentage(percent * 100, precision: 1)}\n" + when 1 + @homework_evaluations = 0 + bid.homeworks.map { |homework| @homework_evaluations += homework.homework_evaluations.count} + teachers = "(" + teacher_members = searchTeacherAndAssistant(course) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + @has_evaluations = 0 + bid.homeworks.map { |homework| @has_evaluations += homework.rates(:quality).where("seems_rateable_rates.rater_id not in #{teachers}").count} + + percent = @has_evaluations.to_f / (@homework_evaluations == 0 ? 1 : @homework_evaluations) + confirm_info = "目前总共分配了#{@homework_evaluations}份匿评作业,已评价#{@has_evaluations}份作业,占#{number_to_percentage(percent * 100, precision: 1)}\n" + end + confirm_info end def get_technical_title user diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 3adcdb09e..5b311acd7 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -20,7 +20,7 @@ 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 @@ -52,7 +52,7 @@ module CoursesHelper end def course_poll_count - Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}").count + Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status in (2,3)").count end def course_feedback_count @@ -152,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 #课程成员数计算 @@ -233,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 @@ -632,48 +632,73 @@ module CoursesHelper #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() - @bid_ids = [] 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 - #feedbackc_count - JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| - activities[jourformess.jour_id]+=1 - 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| - # @bid_ids<?",date_from).count - - #end + 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 } + activities.each_pair { |key, value| activities[key] = value + 1 } return activities end @@ -757,9 +782,10 @@ module CoursesHelper 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) + if attachment.is_public? || User.current.member_of_course?(course) || User.current.admin? result << attachment end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 29a2e57cb..d57cd68eb 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -120,6 +120,20 @@ module FilesHelper result end + def attachment_tag_list attachments + tag_list = Hash.new + attachments.each do |attachment| + attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1} + end + tag_list.sort {|a,b| b[1]<=>a[1]} + end + + def get_attachments_by_tag attachments,tag + attachments.each do |attachment| + attachment.tag_list.include?(tag) + end + end + def visable_attachemnts_insite attachments,obj result = [] if obj.is_a?(Course) diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index cfebb4d30..6e3155f48 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -73,6 +73,35 @@ module JournalsHelper content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes ,:style => "width:580px") end + # 缺陷回复内容、引用内容 + # Redo:后面需要统一扩展 + def render_notes_issue (issue, journal, options={}) + content = '' + editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project))) + destroyable = User.current.logged? && ((journal.user == User.current) || (issue.author_id == User.current.id) || (User.current.admin == 1)) + links = [] + if !journal.notes.blank? + links << link_to(l(:button_quote), + {:controller => 'journals', :action => 'new', :id => issue.id, :journal_id => journal}, + :remote => true, + :method => 'post', + :title => l(:button_quote)) if options[:reply_links] + links << link_to_in_place_notes_editor(l(:button_edit), "journal-#{journal.id}-notes", + { :controller => 'journals', :action => 'edit', :id => journal, :format => 'js' }, + :title => l(:button_edit)) if editable + #Added by young + if destroyable + links << link_to(l(:button_delete), { :controller => 'journals', :action => 'destroy', :id => journal, :format => 'js' }, + :title => l(:button_delete)) + end + end + #content << content_tag('div', links.join(' ').html_safe, :class => 'contextual', :style => 'margin-top:-25px;') unless links.empty? + content << textilizable(journal, :notes) + css_classes = "wiki" + css_classes << " editable" if editable + content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes ,:style => "width:510px") + end + def link_to_in_place_notes_editor(text, field_id, url, options={}) onclick = "$.ajax({url: '#{url_for(url)}', type: 'get'}); return false;" link_to text, '#', options.merge(:onclick => onclick) diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index d1cd3ccd0..7c0cc45d1 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -44,7 +44,11 @@ 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]) + 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') diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 1d47e8bcc..d8078aeb7 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -24,6 +24,11 @@ module ProjectsHelper link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, :class => "c_blue02" end + def link_to_version_show(version, options = {}) + return '' unless version && version.is_a?(Version) + link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, :class => " f16 fb c_dblue " + end + def project_settings_tabs tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural}, {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, 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 6edb171c8..d3b2a49b1 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -42,7 +42,28 @@ module WatchersHelper :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) ) method = watched ? 'delete' : 'post' - + + link_to text, url, :remote => true, :method => method, :class => css + end + + def watcher_link_issue(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 = @watch_flag ? ([watcher_css(objects), watched ? 'talk_edit ' : 'talk_edit '].join(' ') << options[0].to_s) : + ([watcher_css(objects), watched ? 'talk_edit fr ' : 'talk_edit fr '].join(' ') << options[0].to_s) + + text = @watch_flag ? + (watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch)) + + url = watch_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = watched ? 'delete' : 'post' + link_to text, url, :remote => true, :method => method, :class => css end @@ -267,11 +288,23 @@ module WatchersHelper - +# 缺陷跟踪者列表复选框生成 def watchers_checkboxes(object, users, checked=nil) if users.nil? else + # tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil + # content_tag 'label', "#{tag} #{h(user)}".html_safe, + # :id => "issue_watcher_user_ids_#{user.id}", + # :class => "floating" + users.map do |user| + c = checked.nil? ? object.watched_by?(user) : checked + s = content_tag(:ul, + content_tag(:li, "#{check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil } #{h link_to user.userInfo, user_path( user.id)}".html_safe, + :id=>"issue_watcher_user_ids_#{user.id}",:style=>"float: left;width: 175px;margin: 0px 20px 10px 0px; overflow: hidden; line-height:1.6em;" ), + :class => "mb10 ml80") + end.join.html_safe + # scope = users.sort # watchers = paginateHelper scope,10 # s = content_tag('ul', issue_watcher_check_box_tags_ex('issue[watcher_user_ids][]', watchers), :class => 'mb10 ml80') @@ -279,10 +312,6 @@ module WatchersHelper # link_to text, watchers_autocomplete_for_user_path(@users, parameters.merge(:q => params[:q],:format => 'js',:flag => 'ture')), :remote => true # } # s + content_tag('ul', links,:class => 'wlist', :style =>"float:left;margin-top:0px;") - users.map do |user| - c = checked.nil? ? object.watched_by?(user) : checked - end.join.html_safe - s = content_tag('ul', issue_watcher_check_box_tags_ex('issue[watcher_user_ids][]', users), :class => 'mb10 ml80') end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index e96bd93cd..396501862 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -49,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 } diff --git a/app/models/mailer.rb b/app/models/mailer.rb index fd22c645c..ce3924119 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -66,8 +66,8 @@ class Mailer < ActionMailer::Base subject = "[ #{user.show_name} : #{l(:label_day_mail)}]" @subject = " #{user.show_name} : #{date_to} #{l(:label_day_mail)}" - date_from = "#{date_from} 23:59:59" - date_to = "#{date_to} 23:59:59" + date_from = "#{date_from} 17:59:59" + date_to = "#{date_to} 17:59:59" # 生成token用于直接点击登录 @user = user @@ -122,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 @@ -775,9 +775,9 @@ class Mailer < ActionMailer::Base end end elsif reps.is_a? String - u = User.find_by_mail(r) + u = User.find_by_mail(reps) if u && u.mail_notification == 'all' - r_reps << r + r_reps << reps end end r_reps 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/user.rb b/app/models/user.rb index a17652afa..7b232bf13 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -766,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? @@ -779,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/services/courses_service.rb b/app/services/courses_service.rb index 73cf4452d..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 #创建课程 @@ -340,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 @@ -429,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 @@ -449,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/users_service.rb b/app/services/users_service.rb index 80aa34d45..63dd725cd 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -192,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/_form.html.erb b/app/views/attachments/_form.html.erb index ce78274a3..d3ce35caf 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -1,11 +1,12 @@ + <% if defined?(container) && container && container.saved_attachments %> <% container.attachments.each_with_index do |attachment, i| %> - -<% project = project %> - <% end %> - <% container.saved_attachments.each_with_index do |attachment, i| %> + <% container.saved_attachments.each_with_index do |attachment, i| %> - <% end %> <% end %>diff --git a/app/views/attachments/_form_course.html.erb b/app/views/attachments/_form_course.html.erb index 39c760690..1e81aaf65 100644 --- a/app/views/attachments/_form_course.html.erb +++ b/app/views/attachments/_form_course.html.erb @@ -38,7 +38,7 @@ <% project = project %>