podemos-info/census

View on GitHub
app/views/people/_show.arb

Summary

Maintainability
Test Coverage
# frozen_string_literal: true

context.instance_eval do
  panel title do
    changes_table_for(resource, changes: local_assigns[:changes], mode: local_assigns[:mode]) do
      chrow :membership_level, machine: :membership_level
      chrow :state, machine: :state
      chrow :verification, machine: :verification
      chrow :phone_verification, machine: :phone_verification
      chrow :id
      chrow :first_name
      chrow :last_name1
      chrow :last_name2
      chrow :document_type, &:document_type_name
      chrow :document_id
      chrow :document_scope do
        resource.full_document_scope
      end
      chrow :born_at
      chrow :gender, &:gender_name
      chrow :address
      chrow :address_scope, change_field: :address_scope_id do
        resource.full_address_scope
      end
      chrow :postal_code
      chrow :email do
        resource.email_link
      end
      chrow :phone
      chrow :scope, change_field: :scope_id do
        resource.full_scope
      end
      chrow :created_at
      chrow :updated_at
    end

    show_additional_information = resource.additional_information.any?
    show_external_ids = resource.external_ids.present?
    if local_assigns[:mode] == :changes
      show_additional_information &= local_assigns[:changes][:additional_information]
      show_external_ids &= local_assigns[:changes][:external_ids]
    end

    if show_additional_information
      show_table(context: self, resource: resource, title: t("census.people.information"),
                 table: resource.additional_information)
    end

    if show_external_ids
      show_table(context: self, resource: resource, title: t("census.people.external_ids"),
                 table: resource.external_ids)
    end
  end
end