diff --git a/.gitignore b/.gitignore index fdb7a3c6b..22d9e17e6 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ vendor/cache /public/images/avatars /public/files /tags +/config/initializers/gitlab_config.rb diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 42f1e2f20..ce0d7481a 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -56,12 +56,20 @@ class BlogCommentsController < ApplicationController end def destroy @article = BlogComment.find(params[:id]) - if @article.parent_id.nil? #如果是文章被删,那么跳转到用户博客界面 - @article.children.delete - @article.delete - redirect_to user_blogs_path(:user_id=>User.current) + if @article.parent_id.nil? #如果是文章被删,那么跳转到用户博客界面,如果带了course_id过来,那么就要跳转到课程首页 + if params[:course_id] #如果带了课程id过来,说明这是课程大纲,不要删除,只需取消课程大纲就ok了 + @course = Course.find(params[:course_id]) + @course.outline = 0 + @course.save + redirect_to course_path(:id=>params[:course_id]) + else + @article.children.delete + @article.delete + redirect_to user_blogs_path(:user_id=>User.current) + end + else#如果是回复被删, - if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 + if params[:course_id] #如果带了course_id过来了,那么这是要跳到课程大纲去的 @article.delete redirect_to show_course_outline_course_path(:id=>params[:course_id]) else diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3c211b361..c9d632fec 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -715,6 +715,7 @@ class CoursesController < ApplicationController def course_outline @teacher = User.find(@course.tea_id) @blog_articles = @teacher.blog.articles + @is_in_show_outline_page = params[:is_in_show_outline_page] respond_to do |format| format.js end @@ -732,6 +733,7 @@ class CoursesController < ApplicationController def set_course_outline @course.outline = params[:outline_id] @course.save + @is_in_show_outline_page = params[:is_in_show_outline_page] respond_to do |format| format.js end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 55807886b..3db7ada2b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -47,10 +47,18 @@ class HomeworkCommonController < ApplicationController if params[:homework_common] @homework.name = params[:homework_common][:name] @homework.description = params[:homework_common][:description] + if params[:homework_common][:publish_time] == "" + @homework.publish_time = Date.today + else + @homework.publish_time = params[:homework_common][:publish_time] + end @homework.end_time = params[:homework_common][:end_time] || Time.now @homework.course_id = params[:course_id] homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 + homework_detail_manual.comment_status = 1 + end homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start] homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f41dbe6c7..06c1a67e4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -263,7 +263,7 @@ update @course_tag = params[:course] project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT ip = RepositoriesHelper::REPO_IP_ADDRESS - gitlab_address = RepositoriesHelper::REPO_GITLAB_ADDRESS + gitlab_address = Redmine::Configuration['gitlab_address'] if @repository.type.to_s=="Repository::Gitlab" @repos_url = "http://"+gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git" else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7c41dd038..d79083919 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -243,7 +243,7 @@ class UsersController < ApplicationController #status 1 同意 2 拒绝 def dealwith_apply_request @msg = CourseMessage.find(params[:msg_id]) - + #CourseMessage content存的是role 7教辅 9 教师 case params[:agree] when 'Y' apply_user = User.find(@msg.course_message_id) @@ -368,8 +368,12 @@ class UsersController < ApplicationController if User.current == @user @page = params[:page] ? params[:page].to_i + 1 : 0 user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) + if @is_teacher + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) + else + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + end @is_in_course = params[:is_in_course].to_i || 0 respond_to do |format| format.js @@ -493,8 +497,12 @@ class UsersController < ApplicationController homework = HomeworkCommon.new homework.name = params[:homework_common][:name] homework.description = params[:homework_common][:description] - homework.end_time = params[:homework_common][:end_time] || Time.now - homework.publish_time = Time.now + homework.end_time = params[:homework_common][:end_time] || Date.today + if params[:homework_common][:publish_time] == "" + homework.publish_time = Date.today + else + homework.publish_time = params[:homework_common][:publish_time] + end homework.homework_type = params[:homework_type].to_i || 1 homework.late_penalty = 10 homework.teacher_priority = 1 @@ -506,7 +514,11 @@ class UsersController < ApplicationController homework_detail_manual = HomeworkDetailManual.new homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3 - homework_detail_manual.comment_status = 1 + if homework.publish_time > Date.today + homework_detail_manual.comment_status = 0 + else + homework_detail_manual.comment_status = 1 + end homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? homework.end_time + 7 : params[:evaluation_start] homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ba99fe454..f32bef51b 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -45,6 +45,11 @@ module RepositoriesHelper end end + def user_commit_rep(mail) + user = User.find_by_mail(mail) + user.nil? ? User.find(2) : User.find_by_mail(mail) + end + def render_properties(properties) unless properties.nil? || properties.empty? content = '' diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 03a7644a2..8d421a98f 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -23,7 +23,8 @@ class HomeworkCommon < ActiveRecord::Base :description => :description, :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} - after_create :act_as_activity, :send_mail, :act_as_course_activity, :act_as_course_message + after_create :act_as_activity, :send_mail, :act_as_course_message + after_save :act_as_course_activity after_destroy :delete_kindeditor_assets def act_as_activity @@ -33,17 +34,27 @@ class HomeworkCommon < ActiveRecord::Base #课程动态公共表记录 def act_as_course_activity if self.course - self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.course_id) + if self.homework_detail_manual.comment_status == 0 + self.course_acts.destroy_all + else + if self.course_acts.size == 0 + self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.course_id) + end + end end end #课程作业消息记录 def act_as_course_message if self.course - self.course.members.each do |m| - # if m.user_id != self.user_id + if self.homework_detail_manual.comment_status == 0 + self.course_messages.destroy_all + else + self.course.members.each do |m| + # if m.user_id != self.user_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - # end + # end + end end end end @@ -54,7 +65,9 @@ class HomeworkCommon < ActiveRecord::Base end def send_mail - Mailer.run.homework_added(self) + if self.homework_detail_manual.comment_status != 0 + Mailer.run.homework_added(self) + end end def is_program_homework? diff --git a/app/models/user.rb b/app/models/user.rb index b75b67a1a..e68fc7d8e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -260,7 +260,7 @@ class User < Principal @blog = Blog.where("author_id = #{self.id}").all[0] if @blog.nil? #如果某个user的blog不存在,那么就创建一条,并且跳转 - @blog = Blog.create(:name=>(User.find(self.id).realname), + @blog = Blog.create(:name=>(User.find(self.id).realname.blank? ? User.find(self.id).login : User.find(self.id).realname ), :description=>'', :author_id=>self.id) @blog.save diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 8092bee88..74580632f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -301,26 +301,46 @@ class CoursesService #@state == 5 您还未登录 #@state == 6 申请成功,请等待审核完毕 #@state == 7 您已经发送过申请了,请耐心等待 + #@state == 8 您已经是该课程的教师了 + #@state == 9 您已经是该课程的教辅了 #@state 其他 未知错误,请稍后再试 def join_course params,current_user course = Course.find_by_id params[:object_id] + @state = 10 if course if course_endTime_timeout? course @state = 2 else if current_user.member_of_course?(course) #如果已经是成员 + member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0] + roleName = member.roles[0].name if member if params[:course_password] == course.password - #如果加入角色为学生 - if params[:role] == "10" + #如果加入角色为学生 并且当前是学生 + if params[:role] == "10" && roleName == "Student" @state = 3 - elsif current_user.allowed_to?(:as_teacher,course) - @state = 3 - else - Mailer.run.join_course_request(course, User.current, params[:role]) - #如果加入角色为教师或者教辅 - CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) - @state = 6 + #如果加入的角色为老师,并且当前已经是老师 + elsif params[:role] == "9" && roleName == "Teacher" + @state = 8 + #如果加入的角色教辅并且当前为教辅 + elsif params[:role] == "7" && roleName == "TeachingAsistant" + @state = 9 + #如果加入角色为教师或者教辅,并且当前是学生,或者是要成为教辅,当前不是教辅,或者要成为教师,当前不是教师。那么要发送请求 + elsif (params[:role] != "10" && roleName == "Student") || (params[:role] == "7" && roleName != "TeachingAsistant" ) || (params[:role] == "9" && roleName != "Teacher" ) + #如果已经发送过消息了,那么就要给个提示 + if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = #{params[:role]} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0 ").count != 0 + @state = 7 + else + Mailer.run.join_course_request(course, User.current, params[:role]) + CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) + @state = 6 + end + #如果加入角色是学生,但是是当前课程的教师或者教辅 + elsif params[:role] == "10" && roleName != "Student" + member.role_ids = [params[:role]] + member.save + StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) + @state = 0 end else @state = 1 diff --git a/app/views/blog_comments/_simple_ke_reply_form.html.erb b/app/views/blog_comments/_simple_ke_reply_form.html.erb index d65dd3faa..61669058b 100644 --- a/app/views/blog_comments/_simple_ke_reply_form.html.erb +++ b/app/views/blog_comments/_simple_ke_reply_form.html.erb @@ -23,7 +23,7 @@
- +

<% end%> diff --git a/app/views/courses/_course_outlines_list.html.erb b/app/views/courses/_course_outlines_list.html.erb index b8a8bfd2a..6710c22ba 100644 --- a/app/views/courses/_course_outlines_list.html.erb +++ b/app/views/courses/_course_outlines_list.html.erb @@ -10,6 +10,7 @@ <%= form_tag(url_for(:controller=>'courses',:action=>'set_course_outline',:id=>course.id),:method=>'post',:remote=>'true') do %> +
<% unless articles.blank? %> <% articles.each do |article|%> @@ -24,7 +25,7 @@ <% end %>
-
确定
+
确定
取消
diff --git a/app/views/courses/course_outline.js.erb b/app/views/courses/course_outline.js.erb index f747661b8..490361a24 100644 --- a/app/views/courses/course_outline.js.erb +++ b/app/views/courses/course_outline.js.erb @@ -1,4 +1,4 @@ -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'course_outlines_list',:locals => {:articles=>@blog_articles,:course=>@course}) %>'); +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'course_outlines_list',:locals => {:articles=>@blog_articles,:course=>@course,:show_page=>@is_in_show_outline_page}) %>'); showModal('ajax-modal', '300px'); //$('#ajax-modal').css('height','250px'); $('#ajax-modal').css('padding-top','0px'); @@ -6,4 +6,4 @@ $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(' '); $('#ajax-modal').parent().css("top","30%").css("left","50%"); $('#ajax-modal').parent().addClass("courseOutlinePopup"); -$('#ajax-modal').css("padding-left","16px")//.css("padding-bottom","16px"); \ No newline at end of file +$('#ajax-modal').css("padding-left","16px")//.css("padding-bottom","16px"); diff --git a/app/views/courses/join.js.erb b/app/views/courses/join.js.erb index 721367549..2b4927f48 100644 --- a/app/views/courses/join.js.erb +++ b/app/views/courses/join.js.erb @@ -24,6 +24,14 @@ hidden_join_course_form(); <% elsif @state == 7%> alert("您已经发送过申请了,请耐心等待"); hidden_join_course_form(); +<% elsif @state == 8%> +alert("您已经是该课程的教师了"); +hidden_join_course_form(); +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" +<% elsif @state == 9%> +alert("您已经是该课程的教辅了"); +hidden_join_course_form(); +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% else %> alert("未知错误,请稍后再试"); <% end %> diff --git a/app/views/courses/set_course_outline.js.erb b/app/views/courses/set_course_outline.js.erb index febcb0b1f..af075d2b8 100644 --- a/app/views/courses/set_course_outline.js.erb +++ b/app/views/courses/set_course_outline.js.erb @@ -3,3 +3,6 @@ hideModal(); <% else %> $("#course_outline_bar").html(' ') <%end %> +<%if @is_in_show_outline_page && @is_in_show_outline_page == 'Y'%> + window.location.href='<%=show_course_outline_course_path(@course) %>'; +<% end %> diff --git a/app/views/courses/show_course_outline.html.erb b/app/views/courses/show_course_outline.html.erb index ff503d983..18f5817b0 100644 --- a/app/views/courses/show_course_outline.html.erb +++ b/app/views/courses/show_course_outline.html.erb @@ -1,5 +1,16 @@ <%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg',"init_activity_KindEditor",'blog' %> - + -
+
<%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %>
- <% if @article.author.id == User.current.id%> + <% if User.current && @article.author.id == User.current.id%> +
+
    +
  • +
      +
    • + 重设大纲 +
    • +
    • + <%= link_to( + '取消大纲', + {:controller => 'blog_comments',:action => 'destroy',:user_id=>BlogComment.find(@course.outline).author_id,:blog_id=>BlogComment.find(@course.outline).blog_id, :id => @course.outline,:course_id=>@course.id}, + :method => :delete, + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'postOptionLink' + ) if User.current && User.current.id == @article.author.id %> +
    • +
    +
  • +
+
- [设置大纲] - + + <%end%>
主题: <%= @article.title%> @@ -142,18 +173,39 @@ <% end %>
<% if !@article.locked? && User.current.logged?%> -
- -
-
- <%= form_for :blog_comment, :url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id}, :html => {:multipart => true, :id => 'message_form'} do |f| %> - - <%= render :partial => 'blog_comments/reply_form', :locals => {:f => f,:user=>@user,:article=>@article} %> - <%= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'canel_message_replay();', :class => " grey_btn fr c_white mt10 mr5" %> - <%= link_to l(:button_submit), "javascript:void(0)", :onclick => 'submit_message_replay();', :class => "blue_btn fr c_white mt10", :style => "margin-right: 5px;" %> - <% end %> + + + + + + + + + + + + + +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@article.author_id), :alt => "用户头像" %>
+
+
+ <%= form_for 'blog_comment',:url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id},:method => "post",:html => {:multipart => true, :id => 'message_form'} do |f|%> + + + + + +
+ +
+

+ <% end%> +
+
<% end %>
diff --git a/app/views/homework_common/edit.html.erb b/app/views/homework_common/edit.html.erb index 5fc11728b..79692207f 100644 --- a/app/views/homework_common/edit.html.erb +++ b/app/views/homework_common/edit.html.erb @@ -1,6 +1,7 @@