Class: Indicator
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Progress
#dirty_parent_by_submission!, #guide_indicator?, #has_duplicates_in?, #parent, #transfer_to!
active_between, aggregate_of, all_except, defaults, #delete, #destroy!, enum_prefixed_translations_for, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes, with_pg_retry, with_temporary_token
Methods included from WithPgLock
#with_pg_lock
Class Method Details
.delete_all_for!(content, organization) ⇒ Object
65
66
67
|
# File 'app/models/indicator.rb', line 65
def self.delete_all_for!(content, organization)
where(content: content, organization: organization).delete_all
end
|
.dirty_by_content_change!(content) ⇒ Object
14
15
16
|
# File 'app/models/indicator.rb', line 14
def self.dirty_by_content_change!(content)
where(content: content).update_all dirty_by_content_change: true
end
|
Instance Method Details
#_copy_to!(organization) ⇒ Object
74
75
76
77
78
|
# File 'app/models/indicator.rb', line 74
def _copy_to!(organization)
progress_item = super
children.each { |it| it._copy_to! organization }
progress_item
end
|
#_move_to!(organization) ⇒ Object
69
70
71
72
|
# File 'app/models/indicator.rb', line 69
def _move_to!(organization)
move_children_to!(organization)
super
end
|
#cascade_delete_children! ⇒ Object
86
87
88
89
|
# File 'app/models/indicator.rb', line 86
def cascade_delete_children!
indicators.each(&:cascade_delete_children!)
children.delete_all(:delete_all)
end
|
#clean! ⇒ Object
37
38
39
40
41
|
# File 'app/models/indicator.rb', line 37
def clean!
self.dirty_by_submission = false
self.dirty_by_content_change = false
self.once_completed ||= all_children_passed?
end
|
#completed? ⇒ Boolean
56
57
58
59
|
# File 'app/models/indicator.rb', line 56
def completed?
rebuild!
all_children_passed?
end
|
#completion_percentage ⇒ Object
51
52
53
54
|
# File 'app/models/indicator.rb', line 51
def completion_percentage
rebuild!
children_passed_count.fdiv children_count
end
|
#content_available_in?(organization) ⇒ Boolean
91
92
93
|
# File 'app/models/indicator.rb', line 91
def content_available_in?(organization)
content.usage_in_organization(organization).present?
end
|
#delete_duplicates_in!(organization) ⇒ Object
95
96
97
98
|
# File 'app/models/indicator.rb', line 95
def delete_duplicates_in!(organization)
duplicates_in(organization).each(&:cascade_delete_children!)
super
end
|
#dirty_by_submission! ⇒ Object
18
19
20
|
# File 'app/models/indicator.rb', line 18
def dirty_by_submission!
propagate_up! { update! dirty_by_submission: true }
end
|
#move_children_to!(organization) ⇒ Object
80
81
82
83
84
|
# File 'app/models/indicator.rb', line 80
def move_children_to!(organization)
children.update_all(organization_id: organization.id)
indicators.each { |it| it.move_children_to!(organization) }
end
|
#once_completed? ⇒ Boolean
61
62
63
|
# File 'app/models/indicator.rb', line 61
def once_completed?
self.once_completed || completed?
end
|
#propagate_up!(&block) ⇒ Object
9
10
11
12
|
# File 'app/models/indicator.rb', line 9
def propagate_up!(&block)
instance_eval &block
parent&.instance_eval { propagate_up! &block }
end
|
#rebuild! ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/models/indicator.rb', line 22
def rebuild!
if dirty_by_content_change?
propagate_up! do
refresh_children_count!
refresh_children_passed_count!
clean!
save!
end
elsif dirty_by_submission?
refresh_children_passed_count!
clean!
save!
end
end
|
#refresh_children_count! ⇒ Object
43
44
45
|
# File 'app/models/indicator.rb', line 43
def refresh_children_count!
self.children_count = content.structural_children.count
end
|
#refresh_children_passed_count! ⇒ Object
47
48
49
|
# File 'app/models/indicator.rb', line 47
def refresh_children_passed_count!
self.children_passed_count = children.count(&:completed?)
end
|