2023-04-17 21:30:21 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Site
|
|
|
|
# Obtiene un listado de layouts (schemas)
|
|
|
|
module LayoutOrdering
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
|
|
|
|
# Obtiene o genera un listado de layouts (schemas) con sus
|
|
|
|
# dependencias, para poder generar un árbol.
|
|
|
|
#
|
|
|
|
# Por defecto, si el sitio no lo soporta, se obtienen los layouts
|
|
|
|
# ordenados alfabéticamente por traducción.
|
|
|
|
#
|
2024-09-06 19:01:52 +00:00
|
|
|
# @param [Usuarie,nil]
|
2023-04-17 21:30:21 +00:00
|
|
|
# @return [Hash]
|
2024-09-06 19:01:52 +00:00
|
|
|
def schema_organization(usuarie = nil)
|
2023-04-17 21:30:21 +00:00
|
|
|
@schema_organization ||=
|
|
|
|
begin
|
2024-09-06 19:01:52 +00:00
|
|
|
# XXX: retrocompatibilidad
|
|
|
|
key = (usuarie.blank? || usuarie?(usuarie)) ? 'organization' : 'organization_guest'
|
|
|
|
schema_organization = data.dig('schema', key)
|
|
|
|
schema_organization ||= data.dig('schema', 'organization')
|
2023-04-17 21:30:21 +00:00
|
|
|
schema_organization&.symbolize_keys!
|
|
|
|
schema_organization&.transform_values! do |ary|
|
|
|
|
ary.map(&:to_sym)
|
|
|
|
end
|
|
|
|
|
|
|
|
schema_organization ||
|
|
|
|
begin
|
|
|
|
layouts = self.layouts.sort_by(&:humanized_name).map(&:name)
|
|
|
|
Hash[layouts.zip([].fill([], 0, layouts.size))]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: Deprecar cuando renombremos layouts a schemas
|
|
|
|
alias layout_organization schema_organization
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|