diff --git a/Gemfile b/Gemfile index c739e1085..2b12860f0 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'daemons' gem 'grape', '~> 0.9.0' gem 'grape-entity' gem 'seems_rateable', '~> 1.0.13' -gem "rails", "3.2.13" +gem "rails", "~> 3.2.13" gem "jquery-rails", "~> 2.0.2" gem "i18n", "~> 0.6.0" gem 'coderay', '~> 1.1.0' diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 456306c64..fe16385f4 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -8,6 +8,15 @@ class AtController < ApplicationController users = find_at_users(params[:type], params[:id]) @users = users @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users + + #加上all + if @users.size > 0 + allUser = Struct.new(:id, :name).new + allUser.id = @users.map{|u| u.id}.join(",") + allUser.name = "all" + @users.insert(0, allUser) + end + @users end private diff --git a/app/models/issue.rb b/app/models/issue.rb index c82f6f0be..0d72407ba 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -84,7 +84,9 @@ class Issue < ActiveRecord::Base attr_reader :current_journal # fq - after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message, :add_issues_count + after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, + act_as_at_message(:description, :author_id), :add_issues_count + after_update :be_user_score,:update_activity after_destroy :down_user_score, :decrease_issues_count # after_create :be_user_score @@ -165,12 +167,12 @@ class Issue < ActiveRecord::Base end # at 功能添加消息提醒 - def act_as_at_message - users = self.description.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) - end - end + # def act_as_at_message + # users = self.description.scan //m + # users && users.flatten.uniq.each do |uid| + # self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) + # end + # end # 创建issue的时候,issues_count加1 def add_issues_count diff --git a/app/models/journal.rb b/app/models/journal.rb index c37b8d2c5..fd67e8a62 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -51,7 +51,7 @@ class Journal < ActiveRecord::Base before_create :split_private_notes, :add_journals_count # fq - after_save :act_as_activity,:be_user_score, :act_as_forge_message, :act_as_at_message + after_save :act_as_activity,:be_user_score, :act_as_forge_message, act_as_at_message(:notes, :user_id) after_create :update_issue_time # end #after_destroy :down_user_score @@ -186,13 +186,6 @@ class Journal < ActiveRecord::Base end end - def act_as_at_message - users = self.notes.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id) - end - end - # 更新用户分数 -by zjc def be_user_score #新建了缺陷留言且留言不为空,不为空白 diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index dae779b65..fa5beb813 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -68,7 +68,9 @@ class JournalsForMessage < ActiveRecord::Base has_many :at_messages, as: :at_message, dependent: :destroy validates :notes, presence: true, if: :is_homework_jour? - after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_at_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score + after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, + act_as_at_message(:notes, :user_id), :act_as_user_feedback_message, + :act_as_principal_activity, :act_as_student_score after_create :reset_counters! #after_update :update_activity after_destroy :reset_counters! @@ -253,12 +255,7 @@ class JournalsForMessage < ActiveRecord::Base end end - def act_as_at_message - users = self.notes.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id) - end - end + # 用户留言消息通知 def act_as_user_feedback_message # 主留言 diff --git a/app/models/message.rb b/app/models/message.rb index 0ddc6f8e0..d697db236 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -81,7 +81,8 @@ class Message < ActiveRecord::Base after_update :update_messages_board, :update_activity after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score - after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, :act_as_at_message + after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, + :act_as_system_message, :send_mail, :act_as_student_score, act_as_at_message(:content, :author_id) #before_save :be_user_score scope :visible, lambda {|*args| @@ -287,13 +288,6 @@ class Message < ActiveRecord::Base end end - def act_as_at_message - users = self.content.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) - end - end - #更新用户分数 -by zjc def be_user_score #新建message且无parent的为发帖 diff --git a/app/views/at/show.json.erb b/app/views/at/show.json.erb index 5341f251e..6e2a244e4 100644 --- a/app/views/at/show.json.erb +++ b/app/views/at/show.json.erb @@ -1,6 +1,11 @@ [ <% @users && @users.each_with_index do |person,index| %> + <% if index == 0 %> + {"id":<%=index%>, "userid": "<%=person.id%>", "name": "所有人", "login": "<%=person.name%>", "searchKey": "<%=person.name%>"} + <%= index != @users.size-1 ? ',' : '' %> + <% else %> {"id":<%=index%>, "userid": <%=person.id%>, "name": "<%=person.show_name%>", "login": "<%=person.login%>", "searchKey": "<%=person.get_at_show_name%>"} <%= index != @users.size-1 ? ',' : '' %> <% end %> + <% end %> ] diff --git a/config/initializers/30-redmine.rb b/config/initializers/30-redmine.rb index 5a5f7c55a..28167c014 100644 --- a/config/initializers/30-redmine.rb +++ b/config/initializers/30-redmine.rb @@ -1,8 +1,8 @@ I18n.default_locale = 'en' I18n.backend = Redmine::I18n::Backend.new -require 'redmine' require 'trustie' +require 'redmine' # Load the secret token from the Redmine configuration file secret = Redmine::Configuration['secret_token'] diff --git a/lib/trustie.rb b/lib/trustie.rb index 2010e2d43..b7bd97de9 100644 --- a/lib/trustie.rb +++ b/lib/trustie.rb @@ -2,3 +2,4 @@ require 'trustie/utils' require 'trustie/utils/image' require 'trustie/gitlab/api' require 'trustie/grack/grack' +require 'trustie/at/at' diff --git a/lib/trustie/at/at.rb b/lib/trustie/at/at.rb new file mode 100644 index 000000000..e010d4a4d --- /dev/null +++ b/lib/trustie/at/at.rb @@ -0,0 +1,23 @@ +#coding=utf-8 + +module Trustie + module At + extend ActiveSupport::Concern + + module ClassMethods + def act_as_at_message(content, send_id) + self.send :define_method, :act_as_at_message_func do + users = self[content].scan //m + users && users.flatten.uniq.each do |uids| + uids.split(",").each do |uid| + self.at_messages << AtMessage.new(user_id: uid, sender_id: self[send_id]) + end + end + end + end + + end + end +end + +ActiveRecord::Base.send(:include, Trustie::At) \ No newline at end of file diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js index 7dd416dec..b478e2d9b 100644 --- a/public/javascripts/homework.js +++ b/public/javascripts/homework.js @@ -32,30 +32,34 @@ $(function(){ return; } - $.post( - '/student_work/program_test', - {homework: homework_id, student_work_id: student_work_id, src: src, title: title, is_test: is_test}, - function(data,status){ - tested = true; - console.log(data); - if(data.index <=0){ - data.index = $('.ProResultTop').length+1; - } + $.ajax({ + url: '/student_work/program_test', + type: 'POST', + timeout: 60*1000, + data: {homework: homework_id, student_work_id: student_work_id, src: src, title: title, is_test: is_test} + }).done(function(data){ + tested = true; + console.log(data); + if(data.index <=0){ + data.index = $('.ProResultTop').length+1; + } + if (typeof cb == 'function') {cb(data); return;} + var html=bt('t:result-list',data); + $('.ProResult').prepend(html); - if (typeof cb == 'function') {cb(data); return;} - - - var html=bt('t:result-list',data); - $('.ProResult').prepend(html); - - if (data.status==0 && is_test != 'true') { - var r=confirm("答题正确,是否立刻提交?"); - if (r) { - $(".HomeWorkCon form").submit(); - } + if (data.status==0 && is_test != 'true') { + var r=confirm("答题正确,是否立刻提交?"); + if (r) { + $(".HomeWorkCon form").submit(); } } - ); + }).fail(function(xhr, status){ + if(status == 'timeout'){ + alert("您的答案超时了, 请检查代码是否存在死循环的错误."); + } else { + alert("测试失败,服务器出错.") + } + }); }; $('#test-program-btn').on('click', test_program);