Module: Tramway::Admin
- Extended by:
- AdditionalButtons, Forms, Navbar, Notifications, RecordsModels, SingletonModels, WelcomePageActions
- Defined in:
- lib/tramway/admin.rb,
lib/tramway/admin/engine.rb,
lib/tramway/admin/version.rb,
app/helpers/tramway/admin/cases_helper.rb,
app/jobs/tramway/admin/application_job.rb,
lib/tramway/admin/record_routes_helper.rb,
lib/tramway/admin/welcome_page_actions.rb,
app/helpers/tramway/admin/navbar_helper.rb,
app/helpers/tramway/admin/records_helper.rb,
app/helpers/tramway/admin/application_helper.rb,
app/mailers/tramway/admin/application_mailer.rb,
lib/tramway/admin/generators/model_generator.rb,
app/helpers/tramway/admin/russian_cases_helper.rb,
lib/tramway/admin/generators/install_generator.rb,
app/controllers/tramway/admin/singletons_controller.rb,
app/controllers/tramway/admin/application_controller.rb
Defined Under Namespace
Modules: ActionsHelper, AdditionalButtons, AdditionalButtonsBuilder, ApplicationHelper, CasesHelper, FocusGeneratorHelper, Forms, Generators, Navbar, NavbarHelper, Notifications, RecordRoutesHelper, RecordsHelper, RecordsModels, RussianCasesHelper, SingletonHelper, SingletonModels, TramwayModelHelper, WelcomePageActions Classes: ApplicationController, ApplicationJob, ApplicationMailer, Engine, HasAndBelongsToManyRecordsController, RecordsController, SessionsController, SingletonsController, WelcomeController
Constant Summary collapse
- VERSION =
'2.0'
Class Attribute Summary collapse
-
.customized_admin_navbar ⇒ Object
readonly
Returns the value of attribute customized_admin_navbar.
Attributes included from WelcomePageActions
Attributes included from Forms
Class Method Summary collapse
- .action_is_available?(record, project:, role:, model_name:, action:) ⇒ Boolean
- .engine_class(project) ⇒ Object
- .get_models_by_key(checked_models, project, role) ⇒ Object
- .models_array(models_type:, role:) ⇒ Object
- .project_is_engine?(project) ⇒ Boolean
- .select_actions(project:, role:, model_name:) ⇒ Object
- .stringify_keys(hash) ⇒ Object
Methods included from Navbar
navbar_items_for, navbar_structure
Methods included from Notifications
notificable_queries, set_notificable_queries
Methods included from AdditionalButtons
additional_buttons, set_additional_buttons
Methods included from SingletonModels
set_singleton_models, singleton_models, singleton_models_for
Methods included from RecordsModels
available_models, available_models_for, set_available_models
Class Attribute Details
.customized_admin_navbar ⇒ Object (readonly)
Returns the value of attribute customized_admin_navbar.
29 30 31 |
# File 'lib/tramway/admin.rb', line 29 def @customized_admin_navbar end |
Class Method Details
.action_is_available?(record, project:, role:, model_name:, action:) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tramway/admin.rb', line 58 def action_is_available?(record, project:, role:, model_name:, action:) project = project.underscore.to_sym unless project.is_a? Symbol actions = select_actions(project: project, role: role, model_name: model_name) availability = actions&.select do |a| if a.is_a? Symbol a == action.to_sym elsif a.is_a? Hash a.keys.first.to_sym == action.to_sym end end&.first return false unless availability.present? return true if availability.is_a? Symbol availability.values.first.call record end |
.engine_class(project) ⇒ Object
31 32 33 34 |
# File 'lib/tramway/admin.rb', line 31 def engine_class(project) class_name = "::Tramway::#{project.to_s.camelize}" class_name.classify.safe_constantize end |
.get_models_by_key(checked_models, project, role) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tramway/admin.rb', line 40 def get_models_by_key(checked_models, project, role) unless project.present? error = Tramway::Error.new( plugin: :admin, method: :get_models_by_key, message: "Looks like you have not create at least one instance of #{Tramway::Core.application.model_class} model OR Tramway Application Model is nil" ) raise error. end checked_models && checked_models[project]&.dig(role)&.keys || [] end |
.models_array(models_type:, role:) ⇒ Object
52 53 54 55 56 |
# File 'lib/tramway/admin.rb', line 52 def models_array(models_type:, role:) instance_variable_get("@#{models_type}_models")&.map do |projects| projects.last[role]&.keys end&.flatten || [] end |
.project_is_engine?(project) ⇒ Boolean
36 37 38 |
# File 'lib/tramway/admin.rb', line 36 def project_is_engine?(project) engine_class(project) end |
.select_actions(project:, role:, model_name:) ⇒ Object
75 76 77 |
# File 'lib/tramway/admin.rb', line 75 def select_actions(project:, role:, model_name:) stringify_keys(@singleton_models&.dig(project, role))&.dig(model_name) || stringify_keys(@available_models&.dig(project, role))&.dig(model_name) end |
.stringify_keys(hash) ⇒ Object
79 80 81 82 83 |
# File 'lib/tramway/admin.rb', line 79 def stringify_keys(hash) hash&.reduce({}) do |new_hash, pair| new_hash.merge! pair[0].to_s => pair[1] end end |