Class: Decidim::ParticipatoryDocuments::Document

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Authorable, HasComponent, HasUploadValidations, Loggable, Decidim::Publicable, Traceable, TranslatableResource
Defined in:
app/models/decidim/participatory_documents/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#remove_fileObject

Returns the value of attribute remove_file.



25
26
27
# File 'app/models/decidim/participatory_documents/document.rb', line 25

def remove_file
  @remove_file
end

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



27
28
29
# File 'app/models/decidim/participatory_documents/document.rb', line 27

def self.log_presenter_class_for(_log)
  Decidim::ParticipatoryDocuments::AdminLog::DocumentPresenter
end

Instance Method Details

#has_suggestions?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/decidim/participatory_documents/document.rb', line 31

def has_suggestions?
  suggestions.any? || annotations.any? { |annotation| annotation.suggestions.any? }
end

#update_positions!Object

rubocop:disable Rails/SkipsModelValidations



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/decidim/participatory_documents/document.rb', line 36

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