This commit is contained in:
BoHung Chiu 2023-08-22 23:07:05 +08:00
parent 23677b4798
commit 23f0cc92c2
4 changed files with 27 additions and 10 deletions

View File

@ -47,7 +47,7 @@ class Admin::RulingTimersController < OrbitMemberController
end
def timer_management
@timer_temps = RulingTimerTemp.all.page(params[:page]).per(15)
@active_users = @timer_temps.map{|t| t.user}
@active_users = @timer_temps.map{|t| t.user}.compact
end
def task_management
@tasks = RulingTimerTask.all.desc(:created_at).page(params[:page]).per(10)

View File

@ -69,20 +69,18 @@ class RulingTimerTask
end
after_save do
if self.ruling_timer_project_id_change && !@already_save
if self.ruling_timer_project_id_change[0]
old_project = RulingTimerProject.find(self.ruling_timer_project_id_change[0]) rescue nil
if old_project
old_project.task_count -= 1
@already_save = true
old_project.save(:validate=>false)
end
if self.ruling_timer_project_id_was
RulingTimerProject.where(:id=>self.ruling_timer_project_id_was).update_all({"$inc"=>{"task_count"=>-1}})
old_project = RulingTimerProject.where(:id=>self.ruling_timer_project_id_was).first
old_project.all_user_ids = old_project.ruling_timer_tasks.pluck(:user_ids).uniq
old_project.save
end
new_project = self.ruling_timer_project
new_project.task_count += 1
new_project.all_user_ids += self.get_all_user_ids
new_project.all_user_ids.uniq
@already_save = true
new_project.save(:validate=>false)
RulingTimerProject.where(:id=>self.ruling_timer_project_id).update_all({"$inc"=>{"task_count"=>1}})
end
if self.ruling_timer_section_id_change && !@already_save
need_create_notify = true

View File

@ -27,7 +27,7 @@
<% user_ids = task.user_ids
user_bson_ids = user_ids.map{|id| BSON::ObjectId(id)}
%>
<% users = User.find(user_ids).index_by(&:id).slice(*user_bson_ids).values %>
<% users = User.where(:id.in=>user_ids).index_by(&:id).slice(*user_bson_ids).values %>
<% users.each do |user| %>
<% sub_task = task.ruling_timer_sub_tasks.where(:user=>user).first %>
<% next if sub_task.nil? %>

View File

@ -51,6 +51,25 @@ Rails.application.routes.draw do
category.title_translations = I18n.available_locales.map{|l| [l.to_s,I18n.with_locale(l){I18n.t("ruling_timer.personal_project")}]}.to_h
category.save
end
RulingTimerTemp.all.to_a.each do |t|
if t.user.nil? # user has been removed
user_id = t.user_id.to_s
RulingTimerTask.where(:user_ids=>user_id).to_a.each do |task|
task.ruling_timer_sub_tasks.where(:user_id=>user_id).destroy
if task.owner_id.to_s == user_id
task.owner_id = nil
end
task.helper_ids.delete(user_id)
task.user_ids.delete(user_id)
task.save
end
RulingTimerProject.where(:all_user_ids=>user_id).each do |proj|
proj.all_user_ids.delete(user_id)
proj.save
end
t.destroy
end
end
rescue => e
puts e.to_s
end