Class: Decidim::ParticipatoryDocuments::Document
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::ParticipatoryDocuments::Document
- Includes:
- Authorable, HasComponent, HasUploadValidations, Loggable, Decidim::Publicable, Traceable, TranslatableResource
- Defined in:
- app/models/decidim/participatory_documents/document.rb
Instance Attribute Summary collapse
-
#organization ⇒ Object
override the delegate from HasComponent for the dynamic upload validator.
-
#remove_file ⇒ Object
Returns the value of attribute remove_file.
Class Method Summary collapse
Instance Method Summary collapse
- #has_suggestions? ⇒ Boolean
-
#update_positions! ⇒ Object
rubocop:disable Rails/SkipsModelValidations.
Instance Attribute Details
#organization ⇒ Object
override the delegate from HasComponent for the dynamic upload validator
34 35 36 |
# File 'app/models/decidim/participatory_documents/document.rb', line 34 def organization component&.organization || @organization end |
#remove_file ⇒ Object
Returns the value of attribute remove_file.
27 28 29 |
# File 'app/models/decidim/participatory_documents/document.rb', line 27 def remove_file @remove_file end |
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
38 39 40 |
# File 'app/models/decidim/participatory_documents/document.rb', line 38 def self.log_presenter_class_for(_log) Decidim::ParticipatoryDocuments::AdminLog::DocumentPresenter end |
Instance Method Details
#has_suggestions? ⇒ Boolean
42 43 44 |
# File 'app/models/decidim/participatory_documents/document.rb', line 42 def has_suggestions? suggestions.any? || annotations.any? { |annotation| annotation.suggestions.any? } end |
#update_positions! ⇒ Object
rubocop:disable Rails/SkipsModelValidations
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/decidim/participatory_documents/document.rb', line 47 def update_positions! transaction do boxes = annotations.reload.sort do |a, b| if a.page_number == b.page_number if a.rect["top"].to_i == b.rect["top"].to_i a.rect["left"].to_i <=> b.rect["left"].to_i else a.rect["top"].to_i <=> b.rect["top"].to_i end else a.page_number <=> b.page_number end end section_number = 0 all_sections = {} boxes.each_with_index do |box, index| box.update_column(:position, index + 1) if all_sections[box.section_id] box.section.update_column(:position, all_sections[box.section_id]) else section_number += 1 box.section.update_column(:position, section_number) end all_sections[box.section_id] = section_number end end end |