Module: Motor::Configs::BuildUiAppTag
- Defined in:
- lib/motor/configs/build_ui_app_tag.rb
Constant Summary collapse
- CACHE_STORE =
if Motor.development? ActiveSupport::Cache::NullStore.new else ActiveSupport::Cache::MemoryStore.new(size: 5.megabytes) end
Class Method Summary collapse
- .alerts_data_hash(cache_key = nil, current_ability = nil) ⇒ Object
- .build_cache_key(cache_keys, key, current_user, current_ability) ⇒ String
-
.build_data(cache_keys = {}, current_user = nil, current_ability = nil) ⇒ Hash
rubocop:disable Metrics/AbcSize.
- .call(current_user = nil, current_ability = nil, cache_keys: LoadFromCache.load_cache_keys) ⇒ Object
- .dashboards_data_hash(cache_key = nil, current_ability = nil) ⇒ Object
- .forms_data_hash(cache_key = nil, current_ability = nil) ⇒ Object
- .header_links_data_hash(cache_key = nil) ⇒ Object
- .homepage_layout_data_hash(cache_key = nil) ⇒ Object
-
.i18n_data ⇒ Object
rubocop:enable Metrics/AbcSize.
- .queries_data_hash(cache_key = nil, current_ability = nil) ⇒ Object
Class Method Details
.alerts_data_hash(cache_key = nil, current_ability = nil) ⇒ Object
84 85 86 87 88 |
# 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) ⇒ String
56 57 58 |
# 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) ⇒ Hash
rubocop:disable Metrics/AbcSize
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 |
# 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}#{current_ability&.rules_hash}") 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) ⇒ Object
78 79 80 81 82 |
# 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) ⇒ Object
90 91 92 93 94 |
# 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 |
.header_links_data_hash(cache_key = nil) ⇒ Object
60 61 62 63 64 |
# File 'lib/motor/configs/build_ui_app_tag.rb', line 60 def header_links_data_hash(cache_key = nil) configs = Motor::Configs::LoadFromCache.load_configs(cache_key: cache_key) configs.find { |c| c.key == 'header.links' }&.value || [] end |
.homepage_layout_data_hash(cache_key = nil) ⇒ Object
66 67 68 69 70 |
# 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 ⇒ Object
rubocop:enable Metrics/AbcSize
51 52 53 |
# 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) ⇒ Object
72 73 74 75 76 |
# 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 |