lib/ecoportal/api/v2/page/sections.rb in ecoportal-api-v2-0.8.13 vs lib/ecoportal/api/v2/page/sections.rb in ecoportal-api-v2-0.8.14

- old
+ new

@@ -5,10 +5,14 @@ class Sections < Common::Content::CollectionModel class_resolver :section_class, "Ecoportal::API::V2::Page::Section" self.klass = :section_class + def ooze + self._parent.ooze + end + # Creates a new `section` # @note # - It won't fix weights unless all the sections of the ooze are present # - This means that it doesn't fix section weights on stages, # as shared sections could change order in other stages @@ -22,24 +26,34 @@ fix_weights! yield(section) if block_given? end end + # @return [Ecoportal::API::V2::Page::Section] + def get_by_id(id) + self.find do |sec| + sec.id == id + end + end + + # @return [Array<Ecoportal::API::V2::Page::Section>] def get_by_type(type) ordered.select do |sec| sec.type == type end end + # @return [Array<Ecoportal::API::V2::Page::Section>] def get_by_heading(heading) ordered.select do |sec| value = heading == :unnamed ? nil : heading same_string?(sec.heading, value) end end # Gets all the sections between `sec1` and `sec2` + # @return [Array<Ecoportal::API::V2::Page::Section>] def between(sec1, sec2, included: false) sorted_secs = ordered pos1 = (sec1 = to_section(sec1)) && sorted_secs.index(sec1) pos2 = (sec2 = to_section(sec2)) && sorted_secs.index(sec2) if included @@ -51,16 +65,22 @@ end sorted_secs[pos1..pos2] end # Gets the sections ordered by `weight` (as they appear in the page) + # @return [Array<Ecoportal::API::V2::Page::Section>] section sorted by `weight` def ordered self.sort_by.with_index do |section, index| [section.weight, index] end end + # @return [Array<Ecoportal::API::V2::Page::Section>] sections not attached to any stage + def unattached + select {|sec| !sec.attached?} + end + private def scope_weight(section, pos: NOT_USED, before: NOT_USED, after: NOT_USED) case when used_param?(pos) @@ -106,10 +126,9 @@ secs = ordered pos = secs.index(value) - 1 return if pos < 0 secs[pos] end - end end end end end