mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-03 10:24:30 +08:00
Merge pull request #8465 from artoscinote/ma_SCI_11853
Add favorite join and update serializers [SCI-11853]
This commit is contained in:
commit
4c07653a75
5 changed files with 28 additions and 14 deletions
|
@ -7,6 +7,10 @@ module Favoritable
|
|||
has_many :favorites, as: :item, inverse_of: :item, dependent: :destroy
|
||||
|
||||
scope :favorite_for, ->(user) { joins(:favorites).where(favorites: { user: user }) }
|
||||
scope :with_favorites, lambda { |user|
|
||||
joins("LEFT JOIN favorites ON item_id = #{table_name}.id AND item_type = '#{name}' AND favorites.user_id = #{user.id}")
|
||||
.select("#{table_name}.*, favorites.id IS NOT NULL AS favorite")
|
||||
}
|
||||
end
|
||||
|
||||
def favorite!(user, favorite_team = nil)
|
||||
|
@ -16,4 +20,8 @@ module Favoritable
|
|||
def unfavorite!(user, favorite_team = nil)
|
||||
favorites.find_by(user: user, team: favorite_team || team).destroy!
|
||||
end
|
||||
|
||||
def favorite
|
||||
attributes['favorite']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,6 +104,10 @@ class ProjectFolder < ApplicationRecord
|
|||
parent_folder.present? && parent_folder.archived_branch?
|
||||
end
|
||||
|
||||
def favorite
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def inherit_team_from_parent_folder
|
||||
|
|
|
@ -6,19 +6,20 @@ module Lists
|
|||
|
||||
def fetch_records
|
||||
@records = @raw_data.joins(:project)
|
||||
.includes(my_modules: { my_module_status: :my_module_status_implications })
|
||||
.includes(workflowimg_attachment: :blob, user_assignments: %i(user_role user))
|
||||
.joins('LEFT OUTER JOIN my_modules AS active_tasks ON
|
||||
.includes(my_modules: { my_module_status: :my_module_status_implications })
|
||||
.includes(workflowimg_attachment: :blob, user_assignments: %i(user_role user))
|
||||
.joins('LEFT OUTER JOIN my_modules AS active_tasks ON
|
||||
active_tasks.experiment_id = experiments.id
|
||||
AND active_tasks.archived = FALSE')
|
||||
.joins('LEFT OUTER JOIN my_modules AS active_completed_tasks ON
|
||||
active_completed_tasks.experiment_id = experiments.id
|
||||
AND active_completed_tasks.archived = FALSE AND active_completed_tasks.state = 1')
|
||||
.readable_by_user(@user)
|
||||
.select('experiments.*')
|
||||
.select('COUNT(DISTINCT active_tasks.id) AS task_count')
|
||||
.select('COUNT(DISTINCT active_completed_tasks.id) AS completed_task_count')
|
||||
.group('experiments.id')
|
||||
.joins('LEFT OUTER JOIN my_modules AS active_completed_tasks ON
|
||||
active_completed_tasks.experiment_id = experiments.id
|
||||
AND active_completed_tasks.archived = FALSE AND active_completed_tasks.state = 1')
|
||||
.readable_by_user(@user)
|
||||
.with_favorites(@user)
|
||||
.select('experiments.*')
|
||||
.select('COUNT(DISTINCT active_tasks.id) AS task_count')
|
||||
.select('COUNT(DISTINCT active_completed_tasks.id) AS completed_task_count')
|
||||
.group('experiments.id, favorites.id')
|
||||
|
||||
view_mode = if @params[:project].archived?
|
||||
'archived'
|
||||
|
|
|
@ -16,8 +16,8 @@ module Lists
|
|||
|
||||
def fetch_records
|
||||
@records = @raw_data.includes(PRELOAD)
|
||||
.select('my_modules.*')
|
||||
.group('my_modules.id')
|
||||
.with_favorites(@user)
|
||||
.group('my_modules.id, favorites.id')
|
||||
|
||||
view_mode = if @params[:experiment].archived_branch?
|
||||
'archived'
|
||||
|
|
|
@ -35,11 +35,12 @@ module Lists
|
|||
def fetch_projects
|
||||
@team.projects
|
||||
.includes(:team, :project_comments, user_assignments: %i(user user_role))
|
||||
.with_favorites(@user)
|
||||
.visible_to(@user, @team)
|
||||
.left_outer_joins(:project_comments)
|
||||
.select('projects.*')
|
||||
.select('COUNT(DISTINCT comments.id) AS comment_count')
|
||||
.group('projects.id')
|
||||
.group('projects.id, favorites.id')
|
||||
end
|
||||
|
||||
def fetch_project_folders
|
||||
|
|
Loading…
Add table
Reference in a new issue