Class: Decidim::Accountability::Result
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Accountability::Result
- Includes:
- Comments::CommentableWithComponent, DownloadYourData, FilterableResource, HasAttachmentCollections, HasAttachments, HasCategory, HasComponent, HasReference, Loggable, Randomable, Resourceable, ScopableResource, Searchable, SoftDeletable, Taxonomizable, Traceable, TranslatableResource
- Defined in:
- decidim-accountability/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
- .log_presenter_class_for(_log) ⇒ Object
- .ransackable_associations(auth_object = nil) ⇒ Object
- .ransackable_attributes(auth_object = nil) ⇒ Object
- .ransackable_scopes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
-
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the
allow_resource_permissions?Resourceable 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. - #presenter ⇒ Object
- #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 weight and them summed - not using weights, and using the average of progress of each children.
Methods included from Searchable
searchable_resources, searchable_resources_by_type, searchable_resources_of_type_comment, searchable_resources_of_type_component, searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space
Methods included from HasAttachments
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
52 53 54 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 52 def self.log_presenter_class_for(_log) Decidim::Accountability::AdminLog::ResultPresenter end |
.ransackable_associations(auth_object = nil) ⇒ Object
113 114 115 116 117 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 113 def self.ransackable_associations(auth_object = nil) return [] unless auth_object&.admin? %w(taxonomies status) end |
.ransackable_attributes(auth_object = nil) ⇒ Object
105 106 107 108 109 110 111 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 105 def self.ransackable_attributes(auth_object = nil) base = %w(search_text title description) return base unless auth_object&.admin? base + %w(id_string created_at id progress) end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
93 94 95 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 93 def self.ransackable_scopes(_auth_object = nil) [:with_any_taxonomies] end |
Instance Method Details
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the allow_resource_permissions? Resourceable concern method.
89 90 91 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 89 def true end |
#comments_have_alignment? ⇒ Boolean
Public: Overrides the comments_have_alignment? Commentable concern method.
79 80 81 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 79 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
Public: Overrides the comments_have_votes? Commentable concern method.
84 85 86 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 84 def comments_have_votes? true end |
#presenter ⇒ Object
56 57 58 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 56 def presenter Decidim::Accountability::ResultPresenter.new(self) end |
#update_parent_progress ⇒ Object
60 61 62 63 64 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 60 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 weight and them summed
- not using weights, and using the average of progress of each children
69 70 71 72 73 74 75 76 |
# File 'decidim-accountability/app/models/decidim/accountability/result.rb', line 69 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 |