Class: Decidim::Accountability::Result
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Accountability::Result
- Includes:
- Comments::Commentable, DataPortability, HasCategory, HasComponent, HasReference, Loggable, Randomable, Resourceable, ScopableComponent, Traceable
- Defined in:
- app/models/decidim/accountability/result.rb
Overview
The data store for a Result in the Decidim::Accountability component. It stores a title, description and any other useful information to render a custom result.
Class Method Summary collapse
Instance Method Summary collapse
-
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
-
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
-
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
-
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
- #update_parent_progress ⇒ Object
-
#update_progress! ⇒ Object
Public: There are two ways to update parent’s progress: - using weights, in which case each progress is multiplied by the weigth and them summed - not using weights, and using the average of progress of each children.
-
#user_allowed_to_comment?(user) ⇒ Boolean
Public: Whether the object can have new comments or not.
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
31 32 33 |
# File 'app/models/decidim/accountability/result.rb', line 31 def self.log_presenter_class_for(_log) Decidim::Accountability::AdminLog::ResultPresenter end |
Instance Method Details
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
59 60 61 |
# File 'app/models/decidim/accountability/result.rb', line 59 def accepts_new_comments? commentable? && !component.current_settings.comments_blocked end |
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
54 55 56 |
# File 'app/models/decidim/accountability/result.rb', line 54 def commentable? component.settings.comments_enabled? end |
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
64 65 66 |
# File 'app/models/decidim/accountability/result.rb', line 64 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
69 70 71 |
# File 'app/models/decidim/accountability/result.rb', line 69 def comments_have_votes? true end |
#update_parent_progress ⇒ Object
35 36 37 38 39 |
# File 'app/models/decidim/accountability/result.rb', line 35 def update_parent_progress return if parent.blank? parent.update_progress! end |
#update_progress! ⇒ Object
Public: There are two ways to update parent’s progress:
- using weights, in which case each progress is multiplied by the weigth and them summed
- not using weights, and using the average of progress of each children
44 45 46 47 48 49 50 51 |
# File 'app/models/decidim/accountability/result.rb', line 44 def update_progress! self.progress = if children_use_weighted_progress? children.sum { |result| (result.progress.presence || 0) * (result.weight.presence || 1) } else children.average(:progress) end save! end |
#user_allowed_to_comment?(user) ⇒ Boolean
Public: Whether the object can have new comments or not.
74 75 76 |
# File 'app/models/decidim/accountability/result.rb', line 74 def user_allowed_to_comment?(user) can_participate_in_space?(user) end |