Class: Decidim::Accountability::Result

Inherits:
ApplicationRecord show all
Includes:
Comments::CommentableWithComponent, DownloadYourData, FilterableResource, HasAttachmentCollections, HasAttachments, HasCategory, HasComponent, HasReference, Loggable, Randomable, Resourceable, ScopableResource, Searchable, SoftDeletable, Taxonomizable, Traceable, TranslatableResource
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

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



54
55
56
# File 'app/models/decidim/accountability/result.rb', line 54

def self.log_presenter_class_for(_log)
  Decidim::Accountability::AdminLog::ResultPresenter
end

.ransackable_associations(_auth_object = nil) ⇒ Object



115
116
117
# File 'app/models/decidim/accountability/result.rb', line 115

def self.ransackable_associations(_auth_object = nil)
  %w(taxonomies status)
end

.ransackable_attributes(auth_object = nil) ⇒ Object



107
108
109
110
111
112
113
# File 'app/models/decidim/accountability/result.rb', line 107

def self.ransackable_attributes(auth_object = nil)
  base = %w(id_string id search_text title description)

  return base unless auth_object&.admin?

  base + %w(created_at progress)
end

.ransackable_scopes(_auth_object = nil) ⇒ Object



95
96
97
# File 'app/models/decidim/accountability/result.rb', line 95

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.

Returns:

  • (Boolean)


91
92
93
# File 'app/models/decidim/accountability/result.rb', line 91

def allow_resource_permissions?
  true
end

#comments_have_alignment?Boolean

Public: Overrides the ‘comments_have_alignment?` Commentable concern method.

Returns:

  • (Boolean)


81
82
83
# File 'app/models/decidim/accountability/result.rb', line 81

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

Public: Overrides the ‘comments_have_votes?` Commentable concern method.

Returns:

  • (Boolean)


86
87
88
# File 'app/models/decidim/accountability/result.rb', line 86

def comments_have_votes?
  true
end

#presenterObject



58
59
60
# File 'app/models/decidim/accountability/result.rb', line 58

def presenter
  Decidim::Accountability::ResultPresenter.new(self)
end

#update_parent_progressObject



62
63
64
65
66
# File 'app/models/decidim/accountability/result.rb', line 62

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


71
72
73
74
75
76
77
78
# File 'app/models/decidim/accountability/result.rb', line 71

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