Sha256: f49191498d351ab3b8621e907768a619bd704274a98c98c5a439531a5327587c

Contents?: true

Size: 1.82 KB

Versions: 9

Compression:

Stored size: 1.82 KB

Contents

module Ecoportal
  module API
    class V2
      class Pages
        class PageStage < V2::Page
          passthrough :mould_counter, :archive
          passthrough :task_priority, :state, :status
          passthrough :votes_enabled, :upvotes, :downvotes

          #embeds_many :permits, klass: "Ecoportal::API::V2::Page::Permit"
          passarray   :force_errors, :subtags, order_matters: false

          # @return [String] `id` of the stage we got the data of.
          def current_stage_id
            doc.dig("active_stage", "id") || doc["current_stage_id"]
          end

          # @return [Ecoportal::API::V2::Page::Stage]
          def current_stage
            if stage_id = current_stage_id
              stages[stage_id]
            end
          end

          # @return [String] with feedback, if for this page instance, there are any of:
          #   1. orphaned components (fields not belonging to any section)
          #   2. orphaned sections (sections not belonging to any stage)
          def validate
            msg  = super
            msg  = "" unless msg.is_a?(String)

            orphans = components.unattached.select {|comp| comp.global_binding.to_s.strip.empty?}
            if orphans.length > 0
              msg += "There are fields not attached to any sections:\n  • "
              msg += orphans.map do |fld|
                fld.label
              end.join("\n  • ") + "\n"
            end

            if (orphans = sections.unattached).length > 0
              msg += "There are sections not attached to any stage:\n  • "
              msg += orphans.map do |sec|
                "'#{sec.heading}' (#{sec.id})"
              end.join("\n  • ") + "\n"
            end
            msg.empty?? true : msg
          end

        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ecoportal-api-v2-0.8.28 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.27 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.26 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.25 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.24 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.23 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.22 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.21 lib/ecoportal/api/v2/pages/page_stage.rb
ecoportal-api-v2-0.8.20 lib/ecoportal/api/v2/pages/page_stage.rb