module Motor::Configs::BuildUiAppTag

Constants

CACHE_STORE

Public Instance Methods

alerts_data_hash(cache_key = nil, current_ability = nil) click to toggle source
# File lib/motor/configs/build_ui_app_tag.rb, line 84
def alerts_data_hash(cache_key = nil, current_ability = nil)
  Motor::Configs::LoadFromCache.load_alerts(cache_key: cache_key, current_ability: current_ability)
                               .as_json(only: %i[id name is_enabled updated_at],
                                        include: { tags: { only: %i[id name] } })
end
build_cache_key(cache_keys, key, current_user, current_ability) click to toggle source

@return [String]

# File lib/motor/configs/build_ui_app_tag.rb, line 56
def build_cache_key(cache_keys, key, current_user, current_ability)
  "#{cache_keys[key].hash}#{current_user&.id}#{current_ability&.rules_hash}"
end
build_data(cache_keys = {}, current_user = nil, current_ability = nil) click to toggle source

rubocop:disable Metrics/AbcSize @return [Hash]

# File lib/motor/configs/build_ui_app_tag.rb, line 26
def build_data(cache_keys = {}, current_user = nil, current_ability = nil)
  configs_cache_key = cache_keys[:configs]

  {
    version: Motor::VERSION,
    current_user: current_user&.as_json(only: %i[id email]),
    current_rules: current_ability.serialized_rules,
    audits_count: Motor::Audit.count,
    i18n: i18n_data,
    base_path: Motor::Admin.routes.url_helpers.motor_path,
    admin_settings_path: Rails.application.routes.url_helpers.try(:admin_settings_general_path),
    schema: Motor::BuildSchema.call(cache_keys, current_ability),
    header_links: header_links_data_hash(configs_cache_key),
    homepage_layout: homepage_layout_data_hash(configs_cache_key),
    queries: queries_data_hash(build_cache_key(cache_keys, :queries, current_user, current_ability),
                               current_ability),
    dashboards: dashboards_data_hash(build_cache_key(cache_keys, :dashboards, current_user, current_ability),
                                     current_ability),
    alerts: alerts_data_hash(build_cache_key(cache_keys, :alerts, current_user, current_ability),
                             current_ability),
    forms: forms_data_hash(build_cache_key(cache_keys, :forms, current_user, current_ability), current_ability)
  }
end
call(current_user = nil, current_ability = nil, cache_keys: LoadFromCache.load_cache_keys) click to toggle source
# File lib/motor/configs/build_ui_app_tag.rb, line 15
def call(current_user = nil, current_ability = nil, cache_keys: LoadFromCache.load_cache_keys)
  CACHE_STORE.fetch("#{I18n.locale}#{cache_keys.hash}#{current_user&.id}") do
    CACHE_STORE.clear

    data = build_data(cache_keys, current_user, current_ability)
    Motor::ApplicationController.helpers.tag.div('', id: 'app', data: data)
  end
end
dashboards_data_hash(cache_key = nil, current_ability = nil) click to toggle source
# File lib/motor/configs/build_ui_app_tag.rb, line 78
def dashboards_data_hash(cache_key = nil, current_ability = nil)
  Motor::Configs::LoadFromCache.load_dashboards(cache_key: cache_key, current_ability: current_ability)
                               .as_json(only: %i[id title updated_at],
                                        include: { tags: { only: %i[id name] } })
end
forms_data_hash(cache_key = nil, current_ability = nil) click to toggle source
# File lib/motor/configs/build_ui_app_tag.rb, line 90
def forms_data_hash(cache_key = nil, current_ability = nil)
  Motor::Configs::LoadFromCache.load_forms(cache_key: cache_key, current_ability: current_ability)
                               .as_json(only: %i[id name updated_at],
                                        include: { tags: { only: %i[id name] } })
end
homepage_layout_data_hash(cache_key = nil) click to toggle source
# File lib/motor/configs/build_ui_app_tag.rb, line 66
def homepage_layout_data_hash(cache_key = nil)
  configs = Motor::Configs::LoadFromCache.load_configs(cache_key: cache_key)

  configs.find { |c| c.key == 'homepage.layout' }&.value || []
end
i18n_data() click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/motor/configs/build_ui_app_tag.rb, line 51
def i18n_data
  I18n.t('motor', default: I18n.t('motor', locale: :en))
end
queries_data_hash(cache_key = nil, current_ability = nil) click to toggle source
# File lib/motor/configs/build_ui_app_tag.rb, line 72
def queries_data_hash(cache_key = nil, current_ability = nil)
  Motor::Configs::LoadFromCache.load_queries(cache_key: cache_key, current_ability: current_ability)
                               .as_json(only: %i[id name updated_at],
                                        include: { tags: { only: %i[id name] } })
end