module Ecoportal module API class V2 class Page class Component class ReferenceField < Page::Component passthrough :register_id passarray :references passboolean :hide_create, :hide_attach passboolean :hide_metadata, :hide_dashboards passboolean :display_fields, :display_fields_in_lookup def reference_ids references.map do |ref| ref["id"] end end def to_s(delimiter: "\n") reference_ids.to_a.join(delimiter) end # Quick config helper # @param conf [Symbol, Array] # - `:show_fields` specify if the public register fields should be shown (requires `register_id`) # - `:create` specify if the `NEW` button should appear # - `:attach` specify if the `ATTACH` button should appear # - `:metadata` specify if `metadata` should be shown (i.e. status) def configure(*conf) conf.each_with_object([]) do |cnf, unused| case cnf when :show_fields self.display_fields = true self.display_fields_in_lookup = true when Hash supported = [:create, :attach, :metadata] unless (rest = hash_except(cnf.dup, *supported)).empty? unused.push(rest) end if cnf.key?(:create) then self.hide_create = !cnf[:create] end if cnf.key?(:attach) then self.hide_attach = !cnf[:attach] end if cnf.key?(:metadata) then self.hide_metadata = !cnf[:metadata] end else unused.push(cnf) end end.yield_self do |unused| super(*unused) end end end end end end end end