Class: Ecoportal::API::GraphQL::Model::Page::Phased

Inherits:
Base::Page::Phased show all
Defined in:
lib/ecoportal/api/graphql/model/page/phased.rb,
lib/ecoportal/api/graphql/model/page/phased/stage.rb

Defined Under Namespace

Classes: Stage

Constant Summary

Constants included from Common::GraphQL::Model::Diffable

Common::GraphQL::Model::Diffable::DIFF_CLASS

Instance Attribute Summary collapse

Attributes inherited from Interface::BasePage

#_compat_source_template_id

Instance Method Summary collapse

Methods inherited from Interface::BasePage

#forces, #location_ids, #location_ids=, #workflow

Methods included from Concerns::DataFieldAccess

#components, #data_fields_additions, #data_fields_deletions, #data_fields_dirty?, #data_fields_updates, #field_collection, #section_collection, #sections

Methods included from Concerns::PageCompat

#components, #consolidate!, #dirty?, #external_id, #stages?, #template_id, #validate

Methods included from Concerns::SnakeCamelAccess

#method_missing, #respond_to_missing?

Methods included from Common::GraphQL::Model::AsInput

#as_input

Methods included from Common::GraphQL::Model::Diffable

#as_update, #dirty?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ecoportal::API::GraphQL::Concerns::SnakeCamelAccess

Instance Attribute Details

#_compat_active_stage_idObject

The stage the client is currently working on, set when a stage view is taken over this page (Compat::StageView / pages.get(stage_id:) / OozeRedirect#stage). It is the AUTHORITATIVE target for a subsequent submit!/sign_off!: stage tasks (and the people-field permissions scoped to them) apply to a SPECIFIC stage, so the submit must name the stage the work was done on — not a guessed "active" stage. current_stage_id (server-state inference) is only a last-resort fallback. Explicit accessor so it wins over the doc-backed method_missing; nil until a view is taken. See Compat::Pages#compat_stage_id for the resolution order.



19
20
21
# File 'lib/ecoportal/api/graphql/model/page/phased.rb', line 19

def _compat_active_stage_id
  @_compat_active_stage_id
end

Instance Method Details

#current_stage_idObject

v2 compatible: ID of the stage with state == 'inprogress', or nil



35
36
37
38
39
40
41
# File 'lib/ecoportal/api/graphql/model/page/phased.rb', line 35

def current_stage_id
  raw = doc['stagesIndex'] || doc['stages']
  return nil unless raw.is_a?(Array)

  active = raw.find { |s| s['state'] == 'inprogress' || s['active'] == true }
  active&.fetch('id', nil)
end

#stagesObject

Override passarray :stages to return a StageCollection wrapper, enabling v2-compatible access: stages[id_name], stages.get_by_name, stages.ordered



23
24
25
26
27
28
29
30
31
32
# File 'lib/ecoportal/api/graphql/model/page/phased.rb', line 23

def stages
  embedded = super
  # Share the page's canonical field objects with each stage, so mutations made
  # via stage.components reach the page's data_fields_updates (phased write-path).
  fc = field_collection
  Array(embedded).each do |st|
    st.page_field_collection = fc if st.respond_to?(:page_field_collection=)
  end
  Compat::StageCollection.new(embedded)
end