Class: Ecoportal::API::GraphQL::Builder::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/ecoportal/api/graphql/builder/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Template

Returns a new instance of Template.



8
9
10
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 8

def initialize(client)
  @client = client
end

Instance Attribute Details

#client ⇒ Object (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 6

def client
  @client
end

Instance Method Details

#change_log(detail: false, **kargs, &block) ⇒ Object

TEMPLATE CHANGE LOG — who changed this template, what, and when. Newest first (server-side _id: :desc), paginated.

api.template.change_log(id: template_page_id, first: 50)   # => Connection
api.template.change_log.each(id: template_page_id) { |e| ... }  # auto-paginates

★ Two caveats, both silent — read Base::Template::ChangeLogEntry before relying on this: the connection is nil (not empty) unless the caller satisfies Pages::TemplatePolicy#update_information?, and only TEMPLATE_BUILDER-sourced commands appear (workflow-builder ones are on Query::PagesWorkflowCommands).

Called with no arguments it returns the query object itself, so #each /#map and the rest of Enumerable are available — same idiom as the QueryIntegration queries on Model::Organization.

Parameters:

  • detail (Boolean) (defaults to: false) —

    when true, also select FIELD-LEVEL detail (what changed). Ignored when an explicit block is given -- the block wins, since it is the more specific instruction. Off by default so the common who/when read stays cheap.



83
84
85
86
87
88
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 83

def change_log(detail: false, **kargs, &block)
  selection = block || (detail ? Query::TemplateChangeLog.detail_block : nil)
  return changeLogQuery if kargs.empty? && !selection

  changeLogQuery.query(**kargs, &selection)
end

#create(commands:, register_id: nil, &block) ⇒ Object

Parameters:

  • register_id (String, nil) (defaults to: nil) —

    bind the new template to this register. Optional in the schema, but in practice REQUIRED for the create to be authorized at all — see the WHY in Mutation::Template::Create. Omitted when nil.



15
16
17
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 15

def create(commands:, register_id: nil, &block)
  createMutation.query(commands: commands, register_id: register_id, &block)
end


37
38
39
40
41
42
43
44
45
46
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 37

def create_related_page(template_id:, title:, register_id:, patch_ver:, filters: nil, &block)
  createRelatedPageMutation.query(
    template_id: template_id,
    title:       title,
    register_id: register_id,
    patch_ver:   patch_ver,
    filters:     filters,
    &block
  )
end


62
63
64
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 62

def destroy_related_page(template_id:, id:, patch_ver:, &block)
  destroyRelatedPageMutation.query(template_id: template_id, id: id, patch_ver: patch_ver, &block)
end

#publish(id:, &block) ⇒ Object



25
26
27
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 25

def publish(id:, &block)
  publishMutation.query(id: id, &block)
end

#unpublish(id:, &block) ⇒ Object



29
30
31
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 29

def unpublish(id:, &block)
  unpublishMutation.query(id: id, &block)
end

#update(model, commands:, patch_ver: model.patchVer, client_mutation_id: nil, &block) ⇒ Object



19
20
21
22
23
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 19

def update(model, commands:, patch_ver: model.patchVer, client_mutation_id: nil, &block)
  kwargs = { id: model.id, patch_ver: patch_ver, commands: commands }
  kwargs[:client_mutation_id] = client_mutation_id unless client_mutation_id.nil?
  updateMutation.query(**kwargs, &block)
end

#update_information(id:, **kargs, &block) ⇒ Object



33
34
35
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 33

def update_information(id:, **kargs, &block)
  updateInformationMutation.query(id: id, **kargs, &block)
end

Edits an existing related-pages entry. Only the keys you pass are sent — absent keys are left alone server-side, so this is a partial update, not a replace.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ecoportal/api/graphql/builder/template.rb', line 50

def update_related_page(template_id:, id:, patch_ver:, title: nil, register_id: nil, filters: nil, &block)
  updateRelatedPageMutation.query(
    template_id: template_id,
    id:          id,
    patch_ver:   patch_ver,
    title:       title,
    register_id: register_id,
    filters:     filters,
    &block
  )
end