Skip to content

Commit 7283dd7

Browse files
committed
[E] Add by_subject scope to journal
* Also allow filtering subjects to used by journals
1 parent cb24e00 commit 7283dd7

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api/app/controllers/concerns/validation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def annotation_filter_params
607607
end
608608

609609
def subject_filter_params
610-
params.permit(filter: [:featured, :keyword, :typeahead, :used])[:filter] || {}
610+
params.permit(filter: [:featured, :keyword, :typeahead, :used, :used_journal])[:filter] || {}
611611
end
612612

613613
def collaborator_filter_params
@@ -635,7 +635,7 @@ def journal_issue_filter_params
635635

636636
def journal_filter_params
637637
params.permit(
638-
filter: [:draft, :keyword, :order, :typeahead, :show_on_homepage, :with_update_ability, :with_update_or_issue_update_ability]
638+
filter: [:draft, :keyword, :order, :typeahead, :show_on_homepage, :with_update_ability, :with_update_or_issue_update_ability, :subject]
639639
)[:filter]
640640
end
641641

api/app/models/journal.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ class Journal < ApplicationRecord
8787
scope :with_update_ability, ->(user = nil) { build_update_ability_scope_for user }
8888
scope :with_update_or_issue_update_ability, ->(user = nil) { build_update_or_issue_update_ability_for user }
8989

90+
scope :by_subject, ->(subject = nil) {
91+
next all unless subject.present?
92+
93+
where(id: unscoped.joins(:journal_subjects)
94+
.merge(JournalSubject.by_subject(subject)).select(:journal_id))
95+
}
96+
9097
multisearches! :description_plaintext
9198

9299
has_keyword_search!(

api/app/models/subject.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class Subject < ApplicationRecord
3333
joins(:project_subjects).where.not(project_subjects: { id: nil }).group(:id)
3434
}
3535

36+
scope :by_used_journal, ->(used = nil) {
37+
return all unless used.present?
38+
39+
joins(:journal_subjects).where.not(journal_subjects: { id: nil }).group(:id)
40+
}
41+
3642
validates :name, presence: true, uniqueness: true
3743

3844
alias_attribute :title, :name

0 commit comments

Comments
 (0)