mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-08 04:47:22 +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
|
has_many :favorites, as: :item, inverse_of: :item, dependent: :destroy
|
||||||
|
|
||||||
scope :favorite_for, ->(user) { joins(:favorites).where(favorites: { user: user }) }
|
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
|
end
|
||||||
|
|
||||||
def favorite!(user, favorite_team = nil)
|
def favorite!(user, favorite_team = nil)
|
||||||
|
@ -16,4 +20,8 @@ module Favoritable
|
||||||
def unfavorite!(user, favorite_team = nil)
|
def unfavorite!(user, favorite_team = nil)
|
||||||
favorites.find_by(user: user, team: favorite_team || team).destroy!
|
favorites.find_by(user: user, team: favorite_team || team).destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def favorite
|
||||||
|
attributes['favorite']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -104,6 +104,10 @@ class ProjectFolder < ApplicationRecord
|
||||||
parent_folder.present? && parent_folder.archived_branch?
|
parent_folder.present? && parent_folder.archived_branch?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def favorite
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def inherit_team_from_parent_folder
|
def inherit_team_from_parent_folder
|
||||||
|
|
|
@ -6,19 +6,20 @@ module Lists
|
||||||
|
|
||||||
def fetch_records
|
def fetch_records
|
||||||
@records = @raw_data.joins(:project)
|
@records = @raw_data.joins(:project)
|
||||||
.includes(my_modules: { my_module_status: :my_module_status_implications })
|
.includes(my_modules: { my_module_status: :my_module_status_implications })
|
||||||
.includes(workflowimg_attachment: :blob, user_assignments: %i(user_role user))
|
.includes(workflowimg_attachment: :blob, user_assignments: %i(user_role user))
|
||||||
.joins('LEFT OUTER JOIN my_modules AS active_tasks ON
|
.joins('LEFT OUTER JOIN my_modules AS active_tasks ON
|
||||||
active_tasks.experiment_id = experiments.id
|
active_tasks.experiment_id = experiments.id
|
||||||
AND active_tasks.archived = FALSE')
|
AND active_tasks.archived = FALSE')
|
||||||
.joins('LEFT OUTER JOIN my_modules AS active_completed_tasks ON
|
.joins('LEFT OUTER JOIN my_modules AS active_completed_tasks ON
|
||||||
active_completed_tasks.experiment_id = experiments.id
|
active_completed_tasks.experiment_id = experiments.id
|
||||||
AND active_completed_tasks.archived = FALSE AND active_completed_tasks.state = 1')
|
AND active_completed_tasks.archived = FALSE AND active_completed_tasks.state = 1')
|
||||||
.readable_by_user(@user)
|
.readable_by_user(@user)
|
||||||
.select('experiments.*')
|
.with_favorites(@user)
|
||||||
.select('COUNT(DISTINCT active_tasks.id) AS task_count')
|
.select('experiments.*')
|
||||||
.select('COUNT(DISTINCT active_completed_tasks.id) AS completed_task_count')
|
.select('COUNT(DISTINCT active_tasks.id) AS task_count')
|
||||||
.group('experiments.id')
|
.select('COUNT(DISTINCT active_completed_tasks.id) AS completed_task_count')
|
||||||
|
.group('experiments.id, favorites.id')
|
||||||
|
|
||||||
view_mode = if @params[:project].archived?
|
view_mode = if @params[:project].archived?
|
||||||
'archived'
|
'archived'
|
||||||
|
|
|
@ -16,8 +16,8 @@ module Lists
|
||||||
|
|
||||||
def fetch_records
|
def fetch_records
|
||||||
@records = @raw_data.includes(PRELOAD)
|
@records = @raw_data.includes(PRELOAD)
|
||||||
.select('my_modules.*')
|
.with_favorites(@user)
|
||||||
.group('my_modules.id')
|
.group('my_modules.id, favorites.id')
|
||||||
|
|
||||||
view_mode = if @params[:experiment].archived_branch?
|
view_mode = if @params[:experiment].archived_branch?
|
||||||
'archived'
|
'archived'
|
||||||
|
|
|
@ -35,11 +35,12 @@ module Lists
|
||||||
def fetch_projects
|
def fetch_projects
|
||||||
@team.projects
|
@team.projects
|
||||||
.includes(:team, :project_comments, user_assignments: %i(user user_role))
|
.includes(:team, :project_comments, user_assignments: %i(user user_role))
|
||||||
|
.with_favorites(@user)
|
||||||
.visible_to(@user, @team)
|
.visible_to(@user, @team)
|
||||||
.left_outer_joins(:project_comments)
|
.left_outer_joins(:project_comments)
|
||||||
.select('projects.*')
|
.select('projects.*')
|
||||||
.select('COUNT(DISTINCT comments.id) AS comment_count')
|
.select('COUNT(DISTINCT comments.id) AS comment_count')
|
||||||
.group('projects.id')
|
.group('projects.id, favorites.id')
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_project_folders
|
def fetch_project_folders
|
||||||
|
|
Loading…
Add table
Reference in a new issue