Sha256: 1ed1175856b2f6ddb839db1370b37a731a0f70f83ec6d4d967abbe75d18af01d

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 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] unique id
          def uid
            if counter = mould_counter
              counter.render
            end
          end
          
          # @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

1 entries across 1 versions & 1 rubygems

Version Path
ecoportal-api-v2-0.8.29 lib/ecoportal/api/v2/pages/page_stage.rb