diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 35d6f2b85..9d5768948 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -137,6 +137,7 @@ class HomeworkCommonController < ApplicationController def edit @user = User.current + @is_in_course = params[:is_in_course] respond_to do |format| format.html{render :layout => 'new_base_user'} end @@ -173,7 +174,11 @@ class HomeworkCommonController < ApplicationController if @homework.save @homework_detail_manual.save if @homework_detail_manual @homework_detail_programing.save if @homework_detail_programing - redirect_to user_homeworks_user_path(User.current.id) + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + else + redirect_to user_homeworks_user_path(User.current.id) + end end end end @@ -181,7 +186,13 @@ class HomeworkCommonController < ApplicationController def destroy if @homework.destroy respond_to do |format| - format.html {redirect_to user_homeworks_user_path(User.current.id)} + format.html { + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + else + redirect_to user_homeworks_user_path(User.current.id) + end + } end end end @@ -206,7 +217,9 @@ class HomeworkCommonController < ApplicationController end @homework_detail_manual.update_column('comment_status', 2) @statue = 1 - # send_message_homework(@homework) + # 匿评开启消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 2) + Mailer.send_mail_anonymous_comment_open(@homework).deliver else @statue = 2 end @@ -225,21 +238,22 @@ class HomeworkCommonController < ApplicationController student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 student_work.save end - # send_message_homework(@homework) + # 匿评关闭消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 3) + Mailer.send_mail_anonymous_comment_close(@homework).deliver respond_to do |format| format.js end end # 开启/关闭匿评消息通知 - # def send_message_homework(homework) - # # status 标记匿评状态 1为关闭 0为开启 - # course = @homework.course - # course.student.each do |st| - # @homework.course_messages << CourseMessage.new(:user_id => st.user_id, :course_id => course.id, :viewed => false, :status => false) - # end - # end - + def send_message_anonymous_comment(homework, m_status ) + # status 标记匿评状态 1为关闭 0为开启 + course = @homework.course + course.student.each do |st| + @homework.course_messages << CourseMessage.new(:user_id => st.student_id, :course_id => course.id, :viewed => false, :status => m_status) + end + end #提示 def alert_anonymous_comment @cur_size = 0 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 6da45c10b..71b852e01 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -464,6 +464,10 @@ class ProjectsController < ApplicationController # by young # include CoursesHelper def member + # 消息"同意加入项目" + if params[:message_id] + message_invite(params[:message_id], params[:key]) + end # params[:login]为邮箱邀请用户加入,主要功能: # 1、自动注册 # 2、加入项目、创建角色 @@ -519,6 +523,14 @@ class ProjectsController < ApplicationController @members = paginateHelper @members end + def message_invite(message_id, key) + forge_message = ForgeMessage.find(message_id) + if key == forge_message.secret_key + Member.create(:role_ids => [4], :user_id => forge_message.user_id, :project_id => forge_message.project_id) + UserGrade.create(:user_id => forge_message.user_id, :project_id => forge_message.project_id) + end + end + #判断指定用户是否为课程教师 def isCourseTeacher(id) result = false diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b6ac28258..d3921d44a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -198,7 +198,7 @@ class UsersController < ApplicationController # 系统消息 def user_system_messages @sytem_messages = SystemMessage.order("created_at desc").all - @sytem_messages = paginateHelper @sytem_messages,25 + @sytem_messages = paginateHelper @sytem_messages, 10 respond_to do |format| format.html{render :layout=>'new_base_user'} end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1982542a9..d7fac9a7d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2368,7 +2368,7 @@ module ApplicationHelper end def student_anonymous_comment homework - if homework.homework_type == 1 && homework.homework_detail_manual + if homework.homework_detail_manual case homework.homework_detail_manual.comment_status when 1 "未开启匿评".html_safe @@ -2377,10 +2377,6 @@ module ApplicationHelper when 3 "匿评已结束".html_safe end - elsif homework.homework_type == 0 - "未启用匿评".html_safe - elsif homework.homework_type == 2 - " 编程作业 ".html_safe end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 7b4b9d2e4..6a865b203 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -83,7 +83,7 @@ module ProjectsHelper elsif ivite_list.user.active? value = "邀请已发送,等待用户加入!" else - value = "账号尚未激活,等待用户应答!" + value = "邀请已发送,等待用户激活账号!" end end diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb index 0c8b3384f..0dce57598 100644 --- a/app/models/forge_message.rb +++ b/app/models/forge_message.rb @@ -8,7 +8,7 @@ class ForgeMessage < ActiveRecord::Base TYPE_OF_WIKI_ACT = "Wiki" TYPE_OF_NEWS_ACT = "News" - attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed + attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed, :secret_key belongs_to :forge_message ,:polymorphic => true belongs_to :project diff --git a/app/models/homework_detail_programing.rb b/app/models/homework_detail_programing.rb index f6286a45e..2877ed6c1 100644 --- a/app/models/homework_detail_programing.rb +++ b/app/models/homework_detail_programing.rb @@ -4,6 +4,6 @@ class HomeworkDetailPrograming < ActiveRecord::Base belongs_to :homework_common def language_name - %W(C C++).at(self.language.to_i - 1) + %W(C C++ Python).at(self.language.to_i - 1) end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index c9ab6e58e..07b2a345c 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -47,6 +47,42 @@ class Mailer < ActionMailer::Base MailerProxy.new(self) end + # 作业匿评开启 + def send_mail_anonymous_comment_open(homework_common) + course = homework_common.course + recipients ||= [] + course.student.each do |student| + user = User.find(student.student_id) + @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" + @token = Token.get_token_from_user(user, 'autologin') + @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @anonymous_comment_close_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipients << user.mail + end + mail :to => recipients, + :subject => @subject + end + + # 作业匿评关闭 + def send_mail_anonymous_comment_close(homework_common) + course = homework_common.course + recipients ||= [] + course.student.each do |student| + user = User.find(student.student_id) + @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" + @token = Token.get_token_from_user(user, 'autologin') + @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @anonymous_comment_close_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipients << user.mail + end + mail :to => recipients, + :subject => @subject + end + # author: alan # 邀请未注册用户加入项目 # 功能: 在加入项目的同时自动注册用户 @@ -82,14 +118,15 @@ class Mailer < ActionMailer::Base @token = Token.get_token_from_user(user, 'autologin') @project_url = url_for(:controller => 'projects', :action => 'member', :id => project.id, :user_id => user.id, :mail => true, :token => @token.value) # 发送消息邀请 - send_message(user,project) + send_message_request_member(user,project) # end mail :to => email, :subject => @subject end # 邀请信息消息 注:forge_message_id 为邀请人ID(特殊情况) - def send_message(user, project) - ForgeMessage.create(:user_id => user.id, :project_id => project.id, :forge_message_type => "Project_Invite",:forge_message_id => User.current.id, :viewed => false) + def send_message_request_member(user, project) + key = newpass(6).to_s + ForgeMessage.create(:user_id => user.id, :project_id => project.id, :forge_message_type => "ProjectInvite",:forge_message_id => User.current.id, :viewed => false, :secret_key =>key) end # author: alan diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 51cb4458e..7892ed773 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,3 +1,3 @@ $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id,:first_user_activity =>@first_user_activity,:page => @page}) %>"); -init_activity_KindEditor_data('<%= @user_activity_id%>',"","85%"); +init_activity_KindEditor_data('<%= @user_activity_id%>',"","87%"); diff --git a/app/views/homework_common/edit.html.erb b/app/views/homework_common/edit.html.erb index d6815a00a..5fc11728b 100644 --- a/app/views/homework_common/edit.html.erb +++ b/app/views/homework_common/edit.html.erb @@ -16,6 +16,7 @@
<%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @anonymous_comment_close_name, @anonymous_comment_close_url%> 已经关闭了匿评!
+ +<%=link_to @author, user_url(@author) %> 发布的作业:<%=link_to @anonymous_comment_close_name, @anonymous_comment_close_url%> 已经开启匿评了!
+ +标题:<%= usm.subject %>
<% end %> - <% if usm.description.nil? && usm.content.nil? %> - - <% else %> -diff --git a/config/configuration.yml b/config/configuration.yml index 5c58c705a..87a54a976 100644 --- a/config/configuration.yml +++ b/config/configuration.yml @@ -103,7 +103,7 @@ default: # autologin_cookie_name: the name of the cookie (default: autologin) # autologin_cookie_path: the cookie path (default: /) # autologin_cookie_secure: true sets the cookie secure flag (default: false) - autologin_cookie_name: "autologin_trustie" + autologin_cookie_name: autologin_cookie_path: autologin_cookie_secure: @@ -197,16 +197,10 @@ default: #max_concurrent_ajax_uploads: 2 #pic_types: "bmp,jpeg,jpg,png,gif" - repository_root_path: '/tmp/htdocs' - - judge_server: 'http://judge.trustie.net/' - # specific configuration options for production environment # that overrides the default ones production: - judge_server: 'http://192.168.80.21:8080/' - repository_root_path: '/home/pdl/redmine-2.3.2-0/apache2/htdocs' - cookie_domain: ".trustie.net" + # CJK support rmagick_font_path: /usr/share/fonts/ipa-mincho/ipam.ttf email_delivery: delivery_method: :smtp @@ -224,9 +218,9 @@ development: email_delivery: delivery_method: :smtp smtp_settings: - address: smtp.163.com + address: mail.trustie.net port: 25 - domain: smtp.163.com + domain: mail.trustie.net authentication: :login - user_name: "huang.jingquan@163.com" - password: "xinhu1ji2qu366" + user_name: "mail@trustie.net" + password: "loong2010" diff --git a/config/locales/mailers/zh.yml b/config/locales/mailers/zh.yml index fea392421..c2dd5c7e0 100644 --- a/config/locales/mailers/zh.yml +++ b/config/locales/mailers/zh.yml @@ -25,4 +25,6 @@ zh: mail_course_homework_active: "中发布了作业" mail_attention: "请您关注!" mail_homework_endtime: "作业截止时间快到了!" - mail_homework: "作业:" \ No newline at end of file + mail_homework: "作业:" + mail_anonymous_comment_close: "作业匿评已经关闭!" + mail_anonymous_comment_open: "作业匿评已经开启!" \ No newline at end of file diff --git a/db/migrate/20150918134804_add_secret_key_to_forge_message.rb b/db/migrate/20150918134804_add_secret_key_to_forge_message.rb new file mode 100644 index 000000000..1de5a8ae9 --- /dev/null +++ b/db/migrate/20150918134804_add_secret_key_to_forge_message.rb @@ -0,0 +1,5 @@ +class AddSecretKeyToForgeMessage < ActiveRecord::Migration + def change + add_column :forge_messages, :secret_key, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index d0c60e724..43357f44f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150917081214) do +ActiveRecord::Schema.define(:version => 20150918005722) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -497,26 +497,23 @@ ActiveRecord::Schema.define(:version => 20150917081214) do add_index "documents", ["created_on"], :name => "index_documents_on_created_on" add_index "documents", ["project_id"], :name => "documents_project_id" - create_table "dts", :primary_key => "Num", :force => true do |t| - t.string "Defect", :limit => 50 - t.string "Category", :limit => 50 - t.string "File" - t.string "Method" - t.string "Module", :limit => 20 - t.string "Variable", :limit => 50 - t.integer "StartLine" - t.integer "IPLine" - t.string "IPLineCode", :limit => 200 - t.string "Judge", :limit => 15 - t.integer "Review", :limit => 1 + create_table "dts", :force => true do |t| + t.string "IPLineCode" t.string "Description" - t.text "PreConditions", :limit => 2147483647 - t.text "TraceInfo", :limit => 2147483647 - t.text "Code", :limit => 2147483647 + t.string "Num" + t.string "Variable" + t.string "TraceInfo" + t.string "Method" + t.string "File" + t.string "IPLine" + t.string "Review" + t.string "Category" + t.string "Defect" + t.string "PreConditions" + t.string "StartLine" t.integer "project_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "id", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "enabled_modules", :force => true do |t| @@ -686,7 +683,6 @@ ActiveRecord::Schema.define(:version => 20150917081214) do t.integer "user_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false - t.string "mail" end create_table "issue_categories", :force => true do |t| @@ -1308,9 +1304,9 @@ ActiveRecord::Schema.define(:version => 20150917081214) do create_table "student_work_tests", :force => true do |t| t.integer "student_work_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "status", :default => 9 + t.integer "status" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.text "results" t.text "src" end @@ -1329,7 +1325,7 @@ ActiveRecord::Schema.define(:version => 20150917081214) do t.datetime "updated_at", :null => false t.integer "late_penalty", :default => 0 t.integer "absence_penalty", :default => 0 - t.integer "system_score" + t.float "system_score", :default => 0.0 t.boolean "is_test", :default => false end @@ -1363,10 +1359,8 @@ ActiveRecord::Schema.define(:version => 20150917081214) do create_table "system_messages", :force => true do |t| t.integer "user_id" t.string "content" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.text "description" - t.string "subject" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "taggings", :force => true do |t| @@ -1558,6 +1552,7 @@ ActiveRecord::Schema.define(:version => 20150917081214) do t.string "identity_url" t.string "mail_notification", :default => "", :null => false t.string "salt", :limit => 64 + t.integer "gid" end add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id" diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js index 0499ac5fb..3589a0728 100644 --- a/public/javascripts/homework.js +++ b/public/javascripts/homework.js @@ -124,7 +124,7 @@ $(function(){ $('#textarea_input_test').focus(); }); - $("#BluePopupBox a.BlueCirBtn").live('click', function(){ + var saveProgramAnswers = function() { var test_numbers = 0; var valid = true; var input = null; @@ -159,6 +159,12 @@ $(function(){ $('.program-input').remove(); var html=bt('t:program-input-list',data); $("input[name=homework_type]").after(html); + } + return valid; + } + + $("#BluePopupBox a.BlueCirBtn").live('click', function(){ + if(saveProgramAnswers()){ if($( "#BluePopupBox" ).dialog( "isOpen" )){ $("#BluePopupBox").dialog( "close" ); } @@ -180,4 +186,4 @@ $(function(){ $("#BluePopupBox").on('click', 'a.icon_remove', function(){ $(this).parent('.mt10').remove(); }); -}); \ No newline at end of file +}); diff --git a/public/javascripts/init_activity_KindEditor.js b/public/javascripts/init_activity_KindEditor.js index b73ff10d3..866d0ea41 100644 --- a/public/javascripts/init_activity_KindEditor.js +++ b/public/javascripts/init_activity_KindEditor.js @@ -1,10 +1,7 @@ -/** - * Created by Alan on 2015/9/18. - */ function init_editor(params){ // var minHeight; //最小高度 - var id = arguments[1] ? arguments[1] : undefined; var paramsHeight = params.height; //设定的高度 + var id = arguments[1] ? arguments[1] : undefined; var paramsWidth = params.width == undefined ? "100%" : params.width; var editor = params.kindutil.create(params.textarea, { @@ -13,19 +10,42 @@ function init_editor(params){ minHeight:"30px",// == undefined ? "30px":paramsHeight+"px", items:['emoticons'], afterChange:function(){//按键事件 - nh_check_field({content:this,contentmsg:params.contentmsg,textarea:params.textarea}); + var edit = this.edit; var body = edit.doc.body; edit.iframe.height(paramsHeight); this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) + (paramsHeight == undefined ? 30:paramsHeight), paramsHeight)); }, + afterBlur:function(){ + nh_check_field({content:this,contentmsg:params.contentmsg,textarea:params.textarea}); + if(this.edit.html()=="") { + this.edit.html('我要回复'); + } + //params.toolbar_container.hide(); + $('#reply_image_' + id).addClass('imageFuzzy'); + //this.resize("95%", null); + //params.submit_btn.css("display","none"); + }, + afterFocus: function(){ + var edit = this.edit; + var body = edit.doc.body; + if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\#\d*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(edit.html())){ + edit.html(''); + } + params.contentmsg.hide(); + // params.toolbar_container.show(); + $('#reply_image_' + id).removeClass('imageFuzzy'); + //edit.iframe.width(paramsWidth); + this.resize(paramsWidth, null); + params.submit_btn.show(); + }, + afterCreate:function(){ params.submit_btn.css("display","none"); var toolbar = $("div[class='ke-toolbar']",params.div_form); toolbar.css('width',24); $(".ke-outline>.ke-toolbar-icon",toolbar).append('表情'); params.toolbar_container.append(toolbar); - params.toolbar_container.style.display = 'none'; //init var edit = this.edit; var body = edit.doc.body; @@ -36,20 +56,10 @@ function init_editor(params){ var body = edit.doc.body; paramsHeight = paramsHeight == undefined ? params.kindutil.removeUnit(this.height) : paramsHeight; edit.iframe.height(paramsHeight); + edit.html('我要回复'); this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight)+ (paramsHeight == undefined ? 30:paramsHeight) , paramsHeight)); + // params.toolbar_container.hide(); - }, - afterFocus:function(){ - $('#reply_image_' + id).removeClass('imageFuzzy'); - //edit.iframe.width(paramsWidth); - this.resize(paramsWidth, null); - params.submit_btn.css('display','inline-block'); - }, - - afterBlur:function(){ - $('#reply_image_' + id).addClass('imageFuzzy'); - this.resize("95%", null); - params.submit_btn.css("display","none"); } }).loadPlugin('paste'); return editor; @@ -64,7 +74,7 @@ function nh_check_field(params){ if(params.content.html()!=params.textarea.html() || params.issubmit==true){ params.textarea.html(params.content.html()); params.content.sync(); - if(params.content.isEmpty()){ + if(params.content.isEmpty() || /^\&\w*\;\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\#\d*\;\"\&\w*\;[\u4e00-\u9fa5]*\&\w*\;\/\w*\&\w*\;$/.test(params.textarea.html())){ params.contentmsg.html('内容不能为空'); params.contentmsg.css({color:'#ff0000'}); }else{ @@ -128,7 +138,7 @@ function init_activity_KindEditor_data(id){ params.height = height; params.width = width; if (params.textarea.data('init') == undefined) { - params.editor = init_editor(params, id); + params.editor = init_editor(params,id); init_form(params); params.cancel_btn.click(function () { nh_reset_form(params); @@ -141,4 +151,4 @@ function init_activity_KindEditor_data(id){ } }); }); -} +} \ No newline at end of file diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index eaff43533..144589d5b 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -568,6 +568,7 @@ a.postTypeGrey:hover {color:#269ac9;} .homepagePostReply {width:710px; margin:0px auto; background-color:#f1f1f1; margin-top:10px;} .homepagePostReplyBanner {width:708px; height:33px; border:1px solid #e4e4e4; line-height:33px; vertical-align:middle; font-size:12px; color:#888888;} .borderBottomNone {border-bottom:none !important;} +div.minHeight48{min-height: 48px;} .homepagePostReplyBannerCount{width:255px; display:inline-block; margin-left:20px;} .homepagePostReplyBannerTime{width:85px; display:inline-block;} .homepagePostReplyBannerMore{width:330px; display:inline-block; text-align:right;} @@ -583,7 +584,7 @@ a.postReplyCancel {color:#888888; display:block;} a.postReplyCancel:hover {color:#ffffff;} .homepagePostReplyInputContainer2 {width:595px; margin:0px auto;} .homepagePostReplyInput2 {width:588px; height:45px; max-width:588px; max-height:45px; border:1px solid #d9d9d9; outline:none; margin:0px auto 10px auto;} -.homepagePostReplyContainer {border-bottom:1px solid #e3e3e3; width:680px; margin:0px auto; margin-top:18px; min-height:48px;} +.homepagePostReplyContainer {border-bottom:1px solid #e3e3e3; width:680px; margin:0px auto; margin-top:15px; min-height:60px;} .homepagePostSetting {position:absolute; width:20px; height:20px; right:0px; top:0px;} .homepagePostSetting ul li:hover ul {display:block;} .homepagePostSettingIcon {background:url(../images/homepage_icon.png) -93px -5px no-repeat; width:20px; height:20px;}