Class: Thredded::MessageboardGroupView
- Inherits:
-
Object
- Object
- Thredded::MessageboardGroupView
- Defined in:
- app/view_models/thredded/messageboard_group_view.rb
Overview
A view model for a page of MessageboardGroupViews.
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#messageboards ⇒ Object
readonly
Returns the value of attribute messageboards.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(group, messageboards) ⇒ MessageboardGroupView
constructor
A new instance of MessageboardGroupView.
Constructor Details
#initialize(group, messageboards) ⇒ MessageboardGroupView
Returns a new instance of MessageboardGroupView.
46 47 48 49 |
# File 'app/view_models/thredded/messageboard_group_view.rb', line 46 def initialize(group, ) @group = group @messageboards = end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
7 8 9 |
# File 'app/view_models/thredded/messageboard_group_view.rb', line 7 def group @group end |
#messageboards ⇒ Object (readonly)
Returns the value of attribute messageboards.
7 8 9 |
# File 'app/view_models/thredded/messageboard_group_view.rb', line 7 def @messageboards end |
Class Method Details
.grouped(messageboards_scope, user: Thredded::NullUser.new, with_unread_topics_counts: !user.thredded_anonymous?) ⇒ Array<MessageboardGroupView>
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/view_models/thredded/messageboard_group_view.rb', line 13 def self.grouped( # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity , user: Thredded::NullUser.new, with_unread_topics_counts: !user.thredded_anonymous? ) scope = .preload(last_topic: [:last_user]) .eager_load(:group) .order(Arel.sql('COALESCE(thredded_messageboard_groups.position, 0) ASC, thredded_messageboard_groups.id ASC')) .ordered topics_scope = Thredded::TopicPolicy::Scope.new(user, Thredded::Topic.all).resolve if with_unread_topics_counts unread_topics_counts = .unread_topics_counts(user: user, topics_scope: topics_scope) unread_followed_topics_counts = .unread_topics_counts( user: user, topics_scope: topics_scope.followed_by(user) ) end topic_counts = topics_scope.group(:messageboard_id).count posts_scope = Thredded::PostPolicy::Scope.new(user, Thredded::Post.all).resolve post_counts = posts_scope.group(:messageboard_id).count scope.group_by(&:group).map do |(group, )| MessageboardGroupView.new(group, .map do || MessageboardView.new( , topics_count: topic_counts[.id] || 0, posts_count: post_counts[.id] || 0, unread_topics_count: with_unread_topics_counts && unread_topics_counts[.id] || 0, unread_followed_topics_count: with_unread_topics_counts && unread_followed_topics_counts[.id] || 0 ) end) end end |