quick_admin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +46 -0
- data/MIT-LICENSE +20 -0
- data/README.md +270 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/quick_admin/application.js +245 -0
- data/app/assets/javascripts/quick_admin/controllers/alert_controller.js +28 -0
- data/app/assets/javascripts/quick_admin/controllers/bulk_actions_controller.js +49 -0
- data/app/assets/javascripts/quick_admin/controllers/modal_controller.js +35 -0
- data/app/assets/javascripts/quick_admin/controllers/search_controller.js +26 -0
- data/app/assets/javascripts/quick_admin/controllers/text_expander_controller.js +22 -0
- data/app/assets/stylesheets/quick_admin/application.css +617 -0
- data/app/controllers/quick_admin/application_controller.rb +34 -0
- data/app/controllers/quick_admin/dashboard_controller.rb +20 -0
- data/app/controllers/quick_admin/resources_controller.rb +229 -0
- data/app/helpers/quick_admin/application_helper.rb +141 -0
- data/app/views/layouts/quick_admin/application.html.erb +41 -0
- data/app/views/quick_admin/dashboard/index.html.erb +36 -0
- data/app/views/quick_admin/resources/_form.html.erb +39 -0
- data/app/views/quick_admin/resources/_pagination.html.erb +29 -0
- data/app/views/quick_admin/resources/_resource_row.html.erb +32 -0
- data/app/views/quick_admin/resources/_resources_list.html.erb +58 -0
- data/app/views/quick_admin/resources/attachment.html.erb +21 -0
- data/app/views/quick_admin/resources/bulk_destroy.turbo_stream.erb +4 -0
- data/app/views/quick_admin/resources/create.turbo_stream.erb +9 -0
- data/app/views/quick_admin/resources/destroy.turbo_stream.erb +4 -0
- data/app/views/quick_admin/resources/edit.html.erb +14 -0
- data/app/views/quick_admin/resources/index.html.erb +38 -0
- data/app/views/quick_admin/resources/index.turbo_stream.erb +3 -0
- data/app/views/quick_admin/resources/new.html.erb +14 -0
- data/app/views/quick_admin/resources/show.html.erb +38 -0
- data/app/views/quick_admin/resources/update.turbo_stream.erb +9 -0
- data/config/routes.rb +14 -0
- data/lib/generators/quick_admin/install_generator.rb +37 -0
- data/lib/generators/quick_admin/templates/quick_admin.rb +43 -0
- data/lib/quick_admin/configuration.rb +59 -0
- data/lib/quick_admin/engine.rb +20 -0
- data/lib/quick_admin/resource.rb +102 -0
- data/lib/quick_admin/version.rb +3 -0
- data/lib/quick_admin.rb +70 -0
- metadata +146 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<turbo-frame id="modal">
|
|
2
|
+
<div class="modal-overlay" onclick="document.getElementById('modal').innerHTML = ''; document.body.style.overflow = '';">
|
|
3
|
+
<div class="modal-content" onclick="event.stopPropagation()">
|
|
4
|
+
<div class="modal-header">
|
|
5
|
+
<h2>Edit <%= @resource_config.model_name.singularize.humanize %></h2>
|
|
6
|
+
<button type="button" class="modal-close" onclick="document.getElementById('modal').innerHTML = ''; document.body.style.overflow = '';">×</button>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<div class="modal-body">
|
|
10
|
+
<%= render "form", resource: @resource %>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</turbo-frame>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<div class="resources-index">
|
|
2
|
+
<div class="page-header">
|
|
3
|
+
<h1><%= @resource_config.display_name %></h1>
|
|
4
|
+
<%= link_to "Add New #{@resource_config.model_name.singularize.humanize}",
|
|
5
|
+
quick_admin.new_resource_path(resource_name),
|
|
6
|
+
class: "btn btn-primary",
|
|
7
|
+
data: { turbo_frame: "modal" } %>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div class="filters-section">
|
|
11
|
+
<%= form_with url: quick_admin.resources_path(resource_name), method: :get,
|
|
12
|
+
local: false, data: { turbo_frame: "resources_list" },
|
|
13
|
+
class: "search-form" do |f| %>
|
|
14
|
+
<% if @resource_config.searchable_fields.any? %>
|
|
15
|
+
<%= f.text_field :search,
|
|
16
|
+
placeholder: "Search #{@resource_config.searchable_fields.join(', ')}",
|
|
17
|
+
value: params[:search],
|
|
18
|
+
data: { search: "input" },
|
|
19
|
+
class: "search-input" %>
|
|
20
|
+
<% end %>
|
|
21
|
+
|
|
22
|
+
<% @resource_config.filterable_fields.each do |field| %>
|
|
23
|
+
<%= f.select "filter[#{field}]",
|
|
24
|
+
options_for_select(filter_options_for_field(@resource_config.model_class, field), params.dig(:filter, field)),
|
|
25
|
+
{ include_blank: "All #{field.humanize}" },
|
|
26
|
+
{ data: { filter: "select" }, class: "filter-select" } %>
|
|
27
|
+
<% end %>
|
|
28
|
+
<% end %>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<turbo-frame id="resources_list">
|
|
32
|
+
<%= render "resources_list", resources: @resources, pagy: @pagy %>
|
|
33
|
+
</turbo-frame>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<turbo-frame id="modal">
|
|
37
|
+
<!-- Modal content will be loaded here -->
|
|
38
|
+
</turbo-frame>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<turbo-frame id="modal">
|
|
2
|
+
<div class="modal-overlay" onclick="document.getElementById('modal').innerHTML = ''; document.body.style.overflow = '';">
|
|
3
|
+
<div class="modal-content" onclick="event.stopPropagation()">
|
|
4
|
+
<div class="modal-header">
|
|
5
|
+
<h2>New <%= @resource_config.model_name.singularize.humanize %></h2>
|
|
6
|
+
<button type="button" class="modal-close" onclick="document.getElementById('modal').innerHTML = ''; document.body.style.overflow = '';">×</button>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<div class="modal-body">
|
|
10
|
+
<%= render "form", resource: @resource %>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</turbo-frame>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<turbo-frame id="modal">
|
|
2
|
+
<div class="modal-overlay" onclick="document.getElementById('modal').innerHTML = ''; document.body.style.overflow = '';">
|
|
3
|
+
<div class="modal-content" onclick="event.stopPropagation()">
|
|
4
|
+
<div class="modal-header">
|
|
5
|
+
<h2><%= @resource_config.model_name.singularize.humanize %> Details</h2>
|
|
6
|
+
<button type="button" class="modal-close" onclick="document.getElementById('modal').innerHTML = ''; document.body.style.overflow = '';">×</button>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<div class="modal-body">
|
|
10
|
+
<div class="resource-details">
|
|
11
|
+
<% @resource_config.fields.each do |field| %>
|
|
12
|
+
<div class="detail-row">
|
|
13
|
+
<label class="detail-label"><%= field.humanize %>:</label>
|
|
14
|
+
<div class="detail-value">
|
|
15
|
+
<%= display_field_value(@resource, field) %>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
<% end %>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="detail-actions">
|
|
22
|
+
<%= link_to "Edit", quick_admin.edit_resource_path(resource_name, @resource),
|
|
23
|
+
class: "btn btn-warning",
|
|
24
|
+
data: { turbo_frame: "modal" } %>
|
|
25
|
+
<%= button_to "Delete", quick_admin.resource_path(resource_name, @resource),
|
|
26
|
+
method: :delete,
|
|
27
|
+
class: "btn btn-danger",
|
|
28
|
+
form_class: "inline-form",
|
|
29
|
+
local: false,
|
|
30
|
+
data: {
|
|
31
|
+
turbo_confirm: "Are you sure?"
|
|
32
|
+
} %>
|
|
33
|
+
<button type="button" class="btn btn-secondary" onclick="document.getElementById('modal').innerHTML = ''; document.body.style.overflow = '';">Close</button>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
</turbo-frame>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%= turbo_stream.update "modal", "" %>
|
|
2
|
+
<%= turbo_stream.update "resources_list" do %>
|
|
3
|
+
<%= render "resources_list", resources: @resources, pagy: @pagy %>
|
|
4
|
+
<% end %>
|
|
5
|
+
<%= turbo_stream.append "body" do %>
|
|
6
|
+
<div class="flash-message alert alert-success" style="position: fixed; top: 20px; right: 20px; z-index: 9999;" data-auto-dismiss="true">
|
|
7
|
+
Record updated successfully!
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
QuickAdmin::Engine.routes.draw do
|
|
2
|
+
root 'dashboard#index'
|
|
3
|
+
|
|
4
|
+
get ':resource_name', to: 'resources#index', as: :resources
|
|
5
|
+
get ':resource_name/new', to: 'resources#new', as: :new_resource
|
|
6
|
+
post ':resource_name', to: 'resources#create'
|
|
7
|
+
get ':resource_name/:id', to: 'resources#show', as: :resource
|
|
8
|
+
get ':resource_name/:id/edit', to: 'resources#edit', as: :edit_resource
|
|
9
|
+
patch ':resource_name/:id', to: 'resources#update'
|
|
10
|
+
put ':resource_name/:id', to: 'resources#update'
|
|
11
|
+
delete ':resource_name/:id', to: 'resources#destroy'
|
|
12
|
+
delete ':resource_name', to: 'resources#bulk_destroy', as: :bulk_destroy_resources
|
|
13
|
+
get ':resource_name/:id/attachment/:field(/:signed_id)', to: 'resources#attachment', as: :resource_attachment
|
|
14
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
|
|
3
|
+
module QuickAdmin
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
|
7
|
+
|
|
8
|
+
desc 'Install QuickAdmin configuration and mount the engine'
|
|
9
|
+
|
|
10
|
+
def create_initializer
|
|
11
|
+
template 'quick_admin.rb', 'config/initializers/quick_admin.rb'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_route
|
|
15
|
+
route 'mount QuickAdmin::Engine, at: "/admin"'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def show_usage
|
|
19
|
+
say "\n"
|
|
20
|
+
say "QuickAdmin has been installed!", :green
|
|
21
|
+
say "\n"
|
|
22
|
+
say "Next steps:", :yellow
|
|
23
|
+
say "1. Configure your resources in config/initializers/quick_admin.rb"
|
|
24
|
+
say "2. Visit http://localhost:3000/admin to access your admin panel"
|
|
25
|
+
say "\n"
|
|
26
|
+
say "Example resource configuration:", :cyan
|
|
27
|
+
say <<-EXAMPLE
|
|
28
|
+
QuickAdmin.resource :user do |r|
|
|
29
|
+
r.fields :name, :email, :created_at
|
|
30
|
+
r.searchable :name, :email
|
|
31
|
+
r.editable :name, :email
|
|
32
|
+
end
|
|
33
|
+
EXAMPLE
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# QuickAdmin Configuration
|
|
2
|
+
QuickAdmin.configure do |config|
|
|
3
|
+
# Authentication settings
|
|
4
|
+
# config.authentication = :devise # Use Devise authentication
|
|
5
|
+
# config.authentication = :custom # Use custom authentication (override admin_authenticated? method)
|
|
6
|
+
config.authentication = nil # No authentication (default)
|
|
7
|
+
|
|
8
|
+
# CSS Framework
|
|
9
|
+
# config.css_framework = :tailwind # Use Tailwind CSS
|
|
10
|
+
# config.css_framework = :bootstrap # Use Bootstrap
|
|
11
|
+
config.css_framework = :none # Use built-in styles (default)
|
|
12
|
+
|
|
13
|
+
# Text Editor
|
|
14
|
+
# config.text_editor = :trix # Use Trix editor (requires Action Text)
|
|
15
|
+
# config.text_editor = :lexical # Use Lexical editor
|
|
16
|
+
config.text_editor = :textarea # Use simple textarea (default)
|
|
17
|
+
|
|
18
|
+
# Turbo/Hotwire settings
|
|
19
|
+
config.turbo_enabled = true # Enable Turbo (default: true)
|
|
20
|
+
config.stimulus_enabled = true # Enable Stimulus (default: true)
|
|
21
|
+
|
|
22
|
+
# General settings
|
|
23
|
+
config.per_page = 25 # Records per page
|
|
24
|
+
config.mount_path = '/admin' # Mount path for admin interface
|
|
25
|
+
config.app_name = 'QuickAdmin' # App name shown in navigation
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Configure your resources here
|
|
29
|
+
# Example:
|
|
30
|
+
# QuickAdmin.resource :user do |r|
|
|
31
|
+
# r.fields :name, :email, :created_at, :updated_at
|
|
32
|
+
# r.searchable :name, :email
|
|
33
|
+
# r.filterable :created_at
|
|
34
|
+
# r.editable :name, :email
|
|
35
|
+
# r.name 'Users'
|
|
36
|
+
# end
|
|
37
|
+
|
|
38
|
+
# QuickAdmin.resource :post do |r|
|
|
39
|
+
# r.fields :title, :content, :published, :created_at
|
|
40
|
+
# r.searchable :title, :content
|
|
41
|
+
# r.filterable :published, :created_at
|
|
42
|
+
# r.editable :title, :content, :published
|
|
43
|
+
# end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module QuickAdmin
|
|
2
|
+
# Configuration class for QuickAdmin.
|
|
3
|
+
# Holds all configuration options for the admin interface.
|
|
4
|
+
#
|
|
5
|
+
# @attr authentication [Symbol, nil] authentication method (:devise, :custom, or nil)
|
|
6
|
+
# @attr css_framework [Symbol] CSS framework to use (:tailwind, :bootstrap, or :none)
|
|
7
|
+
# @attr text_editor [Symbol] text editor for rich text fields (:trix, :lexical, or :textarea)
|
|
8
|
+
# @attr turbo_enabled [Boolean] whether to enable Turbo (default: true)
|
|
9
|
+
# @attr stimulus_enabled [Boolean] whether to enable Stimulus (default: true)
|
|
10
|
+
# @attr per_page [Integer] number of records per page (default: 25)
|
|
11
|
+
# @attr mount_path [String] URL path where admin is mounted (default: '/admin')
|
|
12
|
+
# @attr app_name [String] application name shown in UI (default: 'QuickAdmin')
|
|
13
|
+
class Configuration
|
|
14
|
+
attr_accessor :authentication, :css_framework, :text_editor, :turbo_enabled,
|
|
15
|
+
:stimulus_enabled, :per_page, :mount_path, :app_name
|
|
16
|
+
|
|
17
|
+
# Initializes a new Configuration with default values.
|
|
18
|
+
def initialize
|
|
19
|
+
@authentication = nil # No authentication by default
|
|
20
|
+
@css_framework = :none # Use built-in styles
|
|
21
|
+
@text_editor = :textarea # Simple textarea editor
|
|
22
|
+
@turbo_enabled = true # Turbo enabled for modern UX
|
|
23
|
+
@stimulus_enabled = true # Stimulus enabled for controllers
|
|
24
|
+
@per_page = 25 # Reasonable default pagination
|
|
25
|
+
@mount_path = '/admin' # Standard admin path
|
|
26
|
+
@app_name = 'QuickAdmin' # Default app name
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Checks if Devise authentication is enabled and available.
|
|
30
|
+
# @return [Boolean] true if devise is configured and gem is loaded
|
|
31
|
+
def devise_enabled?
|
|
32
|
+
authentication == :devise && defined?(Devise)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Checks if Tailwind CSS framework is enabled.
|
|
36
|
+
# @return [Boolean] true if tailwind is configured
|
|
37
|
+
def tailwind_enabled?
|
|
38
|
+
css_framework == :tailwind
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Checks if Bootstrap CSS framework is enabled.
|
|
42
|
+
# @return [Boolean] true if bootstrap is configured
|
|
43
|
+
def bootstrap_enabled?
|
|
44
|
+
css_framework == :bootstrap
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Checks if Trix editor is enabled and available.
|
|
48
|
+
# @return [Boolean] true if trix is configured and gem is loaded
|
|
49
|
+
def trix_enabled?
|
|
50
|
+
text_editor == :trix && defined?(Trix)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Checks if Lexical editor is enabled.
|
|
54
|
+
# @return [Boolean] true if lexical is configured
|
|
55
|
+
def lexical_enabled?
|
|
56
|
+
text_editor == :lexical
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module QuickAdmin
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace QuickAdmin
|
|
4
|
+
|
|
5
|
+
config.generators do |g|
|
|
6
|
+
g.test_framework :rspec
|
|
7
|
+
g.fixture_replacement :factory_bot
|
|
8
|
+
g.assets false
|
|
9
|
+
g.helper false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
initializer "quick_admin.assets.precompile" do |app|
|
|
13
|
+
if app.config.respond_to?(:assets) && app.config.assets.respond_to?(:precompile)
|
|
14
|
+
app.config.assets.precompile += %w( quick_admin/application.css quick_admin/application.js )
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Engine configuration - no auto-mounting to avoid conflicts
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module QuickAdmin
|
|
2
|
+
# Resource represents a model configuration for the admin interface.
|
|
3
|
+
# It defines which fields to display, search, filter, and edit.
|
|
4
|
+
#
|
|
5
|
+
# @attr model_name [String] the name of the model
|
|
6
|
+
# @attr searchable_fields [Array<String>] fields that can be searched
|
|
7
|
+
# @attr filterable_fields [Array<String>] fields that can be filtered
|
|
8
|
+
# @attr editable_fields [Array<String>] fields that can be edited
|
|
9
|
+
# @attr display_name [String] human-friendly name for the resource
|
|
10
|
+
class Resource
|
|
11
|
+
attr_accessor :model_name, :searchable_fields,
|
|
12
|
+
:filterable_fields, :editable_fields, :display_name
|
|
13
|
+
|
|
14
|
+
# Initializes a new Resource.
|
|
15
|
+
#
|
|
16
|
+
# @param model_name [Symbol, String] the name of the model
|
|
17
|
+
def initialize(model_name)
|
|
18
|
+
@model_name = model_name.to_s
|
|
19
|
+
@fields = []
|
|
20
|
+
@searchable_fields = []
|
|
21
|
+
@filterable_fields = []
|
|
22
|
+
@editable_fields = []
|
|
23
|
+
@display_name = model_name.to_s.humanize.pluralize
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the actual model class for this resource.
|
|
27
|
+
# Attempts to constantize the model name.
|
|
28
|
+
#
|
|
29
|
+
# @return [Class, nil] the model class or nil if not found
|
|
30
|
+
def model_class
|
|
31
|
+
@model_class ||= model_name.classify.constantize
|
|
32
|
+
rescue NameError => e
|
|
33
|
+
Rails.logger.warn "QuickAdmin: Could not load model class for #{model_name}: #{e.message}"
|
|
34
|
+
nil
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Gets or sets the fields to display in the index view.
|
|
38
|
+
#
|
|
39
|
+
# @param field_names [Array<Symbol>] optional field names to set
|
|
40
|
+
# @return [Array<String>] the list of field names
|
|
41
|
+
#
|
|
42
|
+
# @example
|
|
43
|
+
# r.fields :name, :email, :created_at # setter
|
|
44
|
+
# r.fields # getter
|
|
45
|
+
def fields(*field_names)
|
|
46
|
+
if field_names.any?
|
|
47
|
+
@fields = field_names.map(&:to_s)
|
|
48
|
+
else
|
|
49
|
+
@fields.empty? ? default_fields : @fields
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Gets or sets the searchable fields.
|
|
54
|
+
#
|
|
55
|
+
# @param field_names [Array<Symbol>] optional field names to set
|
|
56
|
+
# @return [Array<String>] the list of searchable field names
|
|
57
|
+
def searchable(*field_names)
|
|
58
|
+
@searchable_fields = field_names.map(&:to_s) if field_names.any?
|
|
59
|
+
@searchable_fields
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Gets or sets the filterable fields.
|
|
63
|
+
#
|
|
64
|
+
# @param field_names [Array<Symbol>] optional field names to set
|
|
65
|
+
# @return [Array<String>] the list of filterable field names
|
|
66
|
+
def filterable(*field_names)
|
|
67
|
+
@filterable_fields = field_names.map(&:to_s) if field_names.any?
|
|
68
|
+
@filterable_fields
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Gets or sets the editable fields.
|
|
72
|
+
#
|
|
73
|
+
# @param field_names [Array<Symbol>] optional field names to set
|
|
74
|
+
# @return [Array<String>] the list of editable field names
|
|
75
|
+
def editable(*field_names)
|
|
76
|
+
@editable_fields = field_names.map(&:to_s) if field_names.any?
|
|
77
|
+
@editable_fields
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Gets or sets the display name for this resource.
|
|
81
|
+
#
|
|
82
|
+
# @param display_name [String, nil] optional display name to set
|
|
83
|
+
# @return [String] the display name
|
|
84
|
+
def name(display_name = nil)
|
|
85
|
+
@display_name = display_name if display_name
|
|
86
|
+
@display_name
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
# Returns default fields from the model if no fields are explicitly set.
|
|
92
|
+
# Excludes id, created_at, and updated_at by default.
|
|
93
|
+
#
|
|
94
|
+
# @return [Array<String>] list of column names
|
|
95
|
+
def default_fields
|
|
96
|
+
return [] unless model_class&.respond_to?(:column_names)
|
|
97
|
+
|
|
98
|
+
excluded_fields = %w[id created_at updated_at]
|
|
99
|
+
model_class.column_names.reject { |field| excluded_fields.include?(field) }
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
data/lib/quick_admin.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require "turbo-rails"
|
|
2
|
+
require "quick_admin/version"
|
|
3
|
+
require "quick_admin/engine"
|
|
4
|
+
require "quick_admin/configuration"
|
|
5
|
+
require "quick_admin/resource"
|
|
6
|
+
|
|
7
|
+
# QuickAdmin is a lightweight Rails admin interface gem.
|
|
8
|
+
# It provides CRUD operations, search, filtering, and modern Turbo/Hotwire integration
|
|
9
|
+
# with minimal configuration.
|
|
10
|
+
#
|
|
11
|
+
# @example Basic configuration
|
|
12
|
+
# QuickAdmin.configure do |config|
|
|
13
|
+
# config.authentication = :devise
|
|
14
|
+
# config.per_page = 25
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# @example Defining a resource
|
|
18
|
+
# QuickAdmin.resource :user do |r|
|
|
19
|
+
# r.fields :name, :email, :created_at
|
|
20
|
+
# r.searchable :name, :email
|
|
21
|
+
# r.editable :name, :email
|
|
22
|
+
# end
|
|
23
|
+
module QuickAdmin
|
|
24
|
+
class << self
|
|
25
|
+
attr_accessor :configuration
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Configures QuickAdmin with the given block.
|
|
29
|
+
# Creates a new configuration if one doesn't exist.
|
|
30
|
+
#
|
|
31
|
+
# @yield [Configuration] the configuration object
|
|
32
|
+
# @return [Configuration] the configuration object
|
|
33
|
+
def self.configure
|
|
34
|
+
self.configuration ||= Configuration.new
|
|
35
|
+
yield(configuration)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Returns the current configuration or creates a new one.
|
|
39
|
+
#
|
|
40
|
+
# @return [Configuration] the configuration object
|
|
41
|
+
def self.config
|
|
42
|
+
self.configuration ||= Configuration.new
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Returns a hash of all registered resources.
|
|
46
|
+
#
|
|
47
|
+
# @return [Hash<String, Resource>] hash of resource name to Resource objects
|
|
48
|
+
def self.resources
|
|
49
|
+
@resources ||= {}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Registers a new resource with QuickAdmin.
|
|
53
|
+
#
|
|
54
|
+
# @param model_name [Symbol, String] the name of the model (e.g., :user, :post)
|
|
55
|
+
# @yield [Resource] the resource configuration object
|
|
56
|
+
# @return [Resource] the configured resource
|
|
57
|
+
#
|
|
58
|
+
# @example
|
|
59
|
+
# QuickAdmin.resource :post do |r|
|
|
60
|
+
# r.fields :title, :content, :published
|
|
61
|
+
# r.searchable :title, :content
|
|
62
|
+
# r.filterable :published
|
|
63
|
+
# r.editable :title, :content, :published
|
|
64
|
+
# end
|
|
65
|
+
def self.resource(model_name, &block)
|
|
66
|
+
resource = Resource.new(model_name)
|
|
67
|
+
yield(resource) if block_given?
|
|
68
|
+
resources[model_name.to_s] = resource
|
|
69
|
+
end
|
|
70
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: quick_admin
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nezir Zahirovic
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 7.0.0
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '9.0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: 7.0.0
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '9.0'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: turbo-rails
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - "~>"
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '2.0'
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - "~>"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '2.0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: sqlite3
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '1.4'
|
|
53
|
+
type: :development
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '1.4'
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: rspec-rails
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '6.0'
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '6.0'
|
|
74
|
+
description: A lightweight Rails admin gem with minimal dependencies, featuring CRUD
|
|
75
|
+
operations, search, filtering, and modern Turbo/Hotwire integration
|
|
76
|
+
email:
|
|
77
|
+
- nezir.zahirovic@gmail.com
|
|
78
|
+
executables: []
|
|
79
|
+
extensions: []
|
|
80
|
+
extra_rdoc_files: []
|
|
81
|
+
files:
|
|
82
|
+
- CHANGELOG.md
|
|
83
|
+
- MIT-LICENSE
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- app/assets/javascripts/quick_admin/application.js
|
|
87
|
+
- app/assets/javascripts/quick_admin/controllers/alert_controller.js
|
|
88
|
+
- app/assets/javascripts/quick_admin/controllers/bulk_actions_controller.js
|
|
89
|
+
- app/assets/javascripts/quick_admin/controllers/modal_controller.js
|
|
90
|
+
- app/assets/javascripts/quick_admin/controllers/search_controller.js
|
|
91
|
+
- app/assets/javascripts/quick_admin/controllers/text_expander_controller.js
|
|
92
|
+
- app/assets/stylesheets/quick_admin/application.css
|
|
93
|
+
- app/controllers/quick_admin/application_controller.rb
|
|
94
|
+
- app/controllers/quick_admin/dashboard_controller.rb
|
|
95
|
+
- app/controllers/quick_admin/resources_controller.rb
|
|
96
|
+
- app/helpers/quick_admin/application_helper.rb
|
|
97
|
+
- app/views/layouts/quick_admin/application.html.erb
|
|
98
|
+
- app/views/quick_admin/dashboard/index.html.erb
|
|
99
|
+
- app/views/quick_admin/resources/_form.html.erb
|
|
100
|
+
- app/views/quick_admin/resources/_pagination.html.erb
|
|
101
|
+
- app/views/quick_admin/resources/_resource_row.html.erb
|
|
102
|
+
- app/views/quick_admin/resources/_resources_list.html.erb
|
|
103
|
+
- app/views/quick_admin/resources/attachment.html.erb
|
|
104
|
+
- app/views/quick_admin/resources/bulk_destroy.turbo_stream.erb
|
|
105
|
+
- app/views/quick_admin/resources/create.turbo_stream.erb
|
|
106
|
+
- app/views/quick_admin/resources/destroy.turbo_stream.erb
|
|
107
|
+
- app/views/quick_admin/resources/edit.html.erb
|
|
108
|
+
- app/views/quick_admin/resources/index.html.erb
|
|
109
|
+
- app/views/quick_admin/resources/index.turbo_stream.erb
|
|
110
|
+
- app/views/quick_admin/resources/new.html.erb
|
|
111
|
+
- app/views/quick_admin/resources/show.html.erb
|
|
112
|
+
- app/views/quick_admin/resources/update.turbo_stream.erb
|
|
113
|
+
- config/routes.rb
|
|
114
|
+
- lib/generators/quick_admin/install_generator.rb
|
|
115
|
+
- lib/generators/quick_admin/templates/quick_admin.rb
|
|
116
|
+
- lib/quick_admin.rb
|
|
117
|
+
- lib/quick_admin/configuration.rb
|
|
118
|
+
- lib/quick_admin/engine.rb
|
|
119
|
+
- lib/quick_admin/resource.rb
|
|
120
|
+
- lib/quick_admin/version.rb
|
|
121
|
+
homepage: https://github.com/nezirz/quick_admin
|
|
122
|
+
licenses:
|
|
123
|
+
- MIT
|
|
124
|
+
metadata:
|
|
125
|
+
homepage_uri: https://github.com/nezirz/quick_admin
|
|
126
|
+
source_code_uri: https://github.com/nezirz/quick_admin
|
|
127
|
+
changelog_uri: https://github.com/nezirz/quick_admin/blob/main/CHANGELOG.md
|
|
128
|
+
bug_tracker_uri: https://github.com/nezirz/quick_admin/issues
|
|
129
|
+
rdoc_options: []
|
|
130
|
+
require_paths:
|
|
131
|
+
- lib
|
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: 3.0.0
|
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: 2.0.0
|
|
142
|
+
requirements: []
|
|
143
|
+
rubygems_version: 3.7.2
|
|
144
|
+
specification_version: 4
|
|
145
|
+
summary: Simple, minimal Rails admin interface
|
|
146
|
+
test_files: []
|