diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0bb027153..e3d7c9d06 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -561,6 +561,7 @@ class CoursesController < ApplicationController def delete_member member = @course.members.find params[:member_id] student_role = member.member_roles.where("role_id = 10").first + teacher_role = member.member_roles.where("role_id = 7 || role_id = 9").first if member && member.deletable? && student_role user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, @course.id) if user_admin.size > 0 @@ -569,8 +570,9 @@ class CoursesController < ApplicationController joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id) joined.destroy_all - if member.member_roles.count > 1 + if member.member_roles.count > 1&& student_role && teacher_role student_role.destroy + teacher_role.update_attribute("is_current", 1) member.update_attribute("course_group_id", 0) else member.destroy diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c87cd3d42..3690df1f3 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -15,7 +15,7 @@ class HomeworkCommon < ActiveRecord::Base has_one :homework_detail_group, :dependent => :destroy has_many :student_work_projects, :dependent => :destroy has_many :homework_tests, :dependent => :destroy - has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" + has_many :student_works, :dependent => :destroy, :conditions => "is_test=0 and is_delete != 1" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :apply_homeworks, :dependent => :destroy diff --git a/app/models/students_for_course.rb b/app/models/students_for_course.rb index 767d65b10..d9bf96770 100644 --- a/app/models/students_for_course.rb +++ b/app/models/students_for_course.rb @@ -9,11 +9,21 @@ class StudentsForCourse < ActiveRecord::Base validates_uniqueness_of :student_id, :scope => :course_id after_destroy :delete_student_works + after_create :recovery_student_works + #退出班级或删除学生时隐藏学生的作品 def delete_student_works course = self.course homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}") - student_works.destroy_all + student_works.update_all(:is_delete => 1) + end + + #加入班级时还原作品 + def recovery_student_works + course = self.course + homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" + student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}") + student_works.update_all(:is_delete => 0) end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f72623d84..43bdf9e09 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -452,12 +452,20 @@ class CoursesService @state = 2 return @state end - @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id) - if @member.nil? || @member.count == 0 + @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id).first + if @member.nil? @state = 1 return @state end - @member.first.destroy + student_role = @member.member_roles.where("role_id = 10").first + teacher_role = @member.member_roles.where("role_id = 7 || role_id = 9").first + if @member.member_roles.count > 1 && student_role && teacher_role + student_role.destroy + teacher_role.update_attribute("is_current", 1) + @member.update_attribute("course_group_id", 0) + else + @member.destroy + end joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id]) joined.each do |join| join.destroy diff --git a/app/views/courses/_set_join.js.erb b/app/views/courses/_set_join.js.erb index 822757dfe..7c395e54e 100644 --- a/app/views/courses/_set_join.js.erb +++ b/app/views/courses/_set_join.js.erb @@ -1,3 +1,4 @@ +hideModal(); <% if object_id && @state != 6%> $("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(course, user)) %>"); <% end %> diff --git a/app/views/layouts/_course_base_info.html.erb b/app/views/layouts/_course_base_info.html.erb index e3041f92c..3b1c70fe8 100644 --- a/app/views/layouts/_course_base_info.html.erb +++ b/app/views/layouts/_course_base_info.html.erb @@ -26,6 +26,18 @@ +<% elsif User.current.logged? && User.current.member_of_course?(@course) %> +
+ +
<% end %>
@@ -84,7 +96,7 @@ <% elsif is_teacher && is_ST %> <%= link_to '学生身份', switch_role_course_path(@course, :user_id => User.current.id, :curr_role => (is_TA ? 7 : 9), :tar_role => 10), :class => "sy_btn_orange mr10 fl", :title => "由教师身份切换至学生身份" %> <% end %> - <% unless (is_teacher || is_TA || is_TE) %> + <% unless (is_teacher || is_TA || is_TE || is_ST) %>
<%= join_in_course_header(@course, User.current) %>
<% end %> diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 19f7694b3..957f720be 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -276,6 +276,13 @@ $("#expand_tools_expand a").addClass('active'); $("#navContentCourse").toggle(); }); + + function delete_confirm(){ + var htmlvalue = '

提示

'+ + '

您确认要退出该班级吗?

确  定'+ + '取  消
'; + pop_box_new(htmlvalue, 300, 140); + } \ No newline at end of file diff --git a/db/migrate/20161117015856_add_is_delete_to_student_works.rb b/db/migrate/20161117015856_add_is_delete_to_student_works.rb new file mode 100644 index 000000000..f6b3abdd6 --- /dev/null +++ b/db/migrate/20161117015856_add_is_delete_to_student_works.rb @@ -0,0 +1,5 @@ +class AddIsDeleteToStudentWorks < ActiveRecord::Migration + def change + add_column :student_works, :is_delete, :integer, :default => 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index fd75bb020..b95fd7a56 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 => 20161114092115) do +ActiveRecord::Schema.define(:version => 20161117015856) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1910,6 +1910,7 @@ ActiveRecord::Schema.define(:version => 20161114092115) do t.float "work_score" t.integer "work_status", :default => 0 t.datetime "commit_time" + t.integer "is_delete", :default => 0 end add_index "student_works", ["homework_common_id", "user_id"], :name => "index_student_works_on_homework_common_id_and_user_id" diff --git a/public/stylesheets/css/common.css b/public/stylesheets/css/common.css index afe6192fb..08d12745d 100644 --- a/public/stylesheets/css/common.css +++ b/public/stylesheets/css/common.css @@ -169,6 +169,7 @@ h4{ font-size:14px;}/*color:#3b3b3b;*/ .mr70{margin-right: 70px;} .mr75{margin-right: 75px;} .mr80{margin-right: 80px;} +.mr85{margin-right: 85px;} .mr95 {margin-right:95px !important;} .mr100 {margin-right:100px !important;} .mr118 {margin-right:118px !important;}