madmin 0.1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +50 -63
- data/Rakefile +5 -6
- data/app/assets/config/manifest.js +2 -0
- data/app/assets/stylesheets/actiontext.scss +36 -0
- data/app/assets/stylesheets/{madmin/application.css → application.css} +2 -9
- data/app/controllers/madmin/base_controller.rb +5 -9
- data/app/controllers/madmin/dashboard_controller.rb +1 -3
- data/app/controllers/madmin/resource_controller.rb +81 -0
- data/app/helpers/madmin/application_helper.rb +10 -8
- data/app/views/layouts/madmin/application.html.erb +23 -25
- data/app/views/madmin/application/_form.html.erb +25 -0
- data/app/views/madmin/application/_javascript.html.erb +24 -0
- data/app/views/madmin/application/_navigation.html.erb +6 -0
- data/app/views/madmin/application/edit.html.erb +3 -0
- data/app/views/madmin/application/index.html.erb +47 -0
- data/app/views/madmin/application/new.html.erb +3 -0
- data/app/views/madmin/application/show.html.erb +24 -0
- data/app/views/madmin/dashboard/show.html.erb +1 -0
- data/app/views/madmin/fields/attachment/_form.html.erb +2 -0
- data/app/views/madmin/fields/attachment/_index.html.erb +3 -0
- data/app/views/madmin/fields/attachment/_show.html.erb +3 -0
- data/app/views/madmin/fields/attachments/_form.html.erb +2 -0
- data/app/views/madmin/fields/attachments/_index.html.erb +1 -0
- data/app/views/madmin/fields/attachments/_show.html.erb +7 -0
- data/app/views/madmin/fields/belongs_to/_form.html.erb +2 -14
- data/app/views/madmin/fields/belongs_to/_index.html.erb +3 -7
- data/app/views/madmin/fields/belongs_to/_show.html.erb +3 -8
- data/app/views/madmin/fields/boolean/_form.html.erb +2 -0
- data/app/views/madmin/fields/boolean/_index.html.erb +1 -0
- data/app/views/madmin/fields/boolean/_show.html.erb +1 -0
- data/app/views/madmin/fields/date/_form.html.erb +2 -0
- data/app/views/madmin/fields/date/_index.html.erb +1 -0
- data/app/views/madmin/fields/date/_show.html.erb +1 -0
- data/app/views/madmin/fields/date_time/_form.html.erb +2 -0
- data/app/views/madmin/fields/date_time/_index.html.erb +1 -0
- data/app/views/madmin/fields/date_time/_show.html.erb +1 -0
- data/app/views/madmin/fields/decimal/_form.html.erb +2 -0
- data/app/views/madmin/fields/decimal/_index.html.erb +1 -0
- data/app/views/madmin/fields/decimal/_show.html.erb +1 -0
- data/app/views/madmin/fields/enum/_form.html.erb +2 -0
- data/app/views/madmin/fields/enum/_index.html.erb +1 -0
- data/app/views/madmin/fields/enum/_show.html.erb +1 -0
- data/app/views/madmin/fields/float/_form.html.erb +2 -0
- data/app/views/madmin/fields/float/_index.html.erb +1 -0
- data/app/views/madmin/fields/float/_show.html.erb +1 -0
- data/app/views/madmin/fields/has_many/_form.html.erb +2 -0
- data/app/views/madmin/fields/has_many/_index.html.erb +1 -0
- data/app/views/madmin/fields/has_many/_show.html.erb +4 -14
- data/app/views/madmin/fields/has_one/_form.html.erb +3 -0
- data/app/views/madmin/fields/has_one/_index.html.erb +3 -0
- data/app/views/madmin/fields/has_one/_show.html.erb +3 -12
- data/app/views/madmin/fields/integer/_form.html.erb +2 -0
- data/app/views/madmin/fields/integer/_index.html.erb +1 -0
- data/app/views/madmin/fields/integer/_show.html.erb +1 -0
- data/app/views/madmin/fields/json/_form.html.erb +2 -0
- data/app/views/madmin/fields/json/_index.html.erb +1 -0
- data/app/views/madmin/fields/json/_show.html.erb +1 -0
- data/app/views/madmin/fields/polymorphic/_form.html.erb +5 -32
- data/app/views/madmin/fields/polymorphic/_index.html.erb +3 -1
- data/app/views/madmin/fields/polymorphic/_show.html.erb +3 -14
- data/app/views/madmin/fields/rich_text/_form.html.erb +4 -0
- data/app/views/madmin/fields/rich_text/_index.html.erb +1 -0
- data/app/views/madmin/fields/rich_text/_show.html.erb +3 -0
- data/app/views/madmin/fields/string/_form.html.erb +2 -0
- data/app/views/madmin/fields/string/_index.html.erb +1 -0
- data/app/views/madmin/fields/string/_show.html.erb +1 -0
- data/app/views/madmin/fields/text/_form.html.erb +2 -4
- data/app/views/madmin/fields/text/_index.html.erb +1 -1
- data/app/views/madmin/fields/text/_show.html.erb +1 -8
- data/app/views/madmin/fields/time/_form.html.erb +2 -0
- data/app/views/madmin/fields/time/_index.html.erb +1 -0
- data/app/views/madmin/fields/time/_show.html.erb +1 -0
- data/lib/generators/madmin/install/install_generator.rb +31 -12
- data/lib/generators/madmin/install/templates/controller.rb.tt +22 -0
- data/lib/generators/madmin/resource/resource_generator.rb +83 -47
- data/lib/generators/madmin/resource/templates/controller.rb.tt +4 -0
- data/lib/generators/madmin/resource/templates/resource.rb.tt +11 -0
- data/lib/generators/madmin/views/edit_generator.rb +16 -0
- data/lib/generators/madmin/views/form_generator.rb +15 -0
- data/lib/generators/madmin/views/index_generator.rb +15 -0
- data/lib/generators/madmin/views/layout_generator.rb +21 -0
- data/lib/generators/madmin/views/navigation_generator.rb +15 -0
- data/lib/generators/madmin/views/new_generator.rb +16 -0
- data/lib/generators/madmin/views/show_generator.rb +15 -0
- data/lib/generators/madmin/views/views_generator.rb +8 -8
- data/lib/madmin.rb +34 -23
- data/lib/madmin/engine.rb +5 -2
- data/lib/madmin/field.rb +22 -46
- data/lib/madmin/fields/attachment.rb +6 -0
- data/lib/madmin/fields/attachments.rb +9 -0
- data/lib/madmin/fields/belongs_to.rb +18 -0
- data/lib/madmin/fields/boolean.rb +6 -0
- data/lib/madmin/fields/date.rb +6 -0
- data/lib/madmin/fields/date_time.rb +6 -0
- data/lib/madmin/fields/decimal.rb +6 -0
- data/lib/madmin/fields/enum.rb +9 -0
- data/lib/madmin/fields/float.rb +6 -0
- data/lib/madmin/fields/has_many.rb +18 -0
- data/lib/madmin/fields/has_one.rb +6 -0
- data/lib/madmin/fields/integer.rb +6 -0
- data/lib/madmin/fields/json.rb +6 -0
- data/lib/madmin/fields/polymorphic.rb +17 -0
- data/lib/madmin/fields/rich_text.rb +6 -0
- data/lib/madmin/fields/string.rb +6 -0
- data/lib/madmin/fields/text.rb +6 -0
- data/lib/madmin/fields/time.rb +6 -0
- data/lib/madmin/generator_helpers.rb +24 -0
- data/lib/madmin/namespace.rb +35 -0
- data/lib/madmin/resource.rb +176 -0
- data/lib/madmin/version.rb +1 -1
- data/lib/madmin/view_generator.rb +42 -0
- data/lib/tasks/madmin_tasks.rake +7 -0
- metadata +106 -111
- data/app/assets/config/madmin_manifest.js +0 -2
- data/app/assets/javascripts/madmin/application.js +0 -15
- data/app/assets/javascripts/madmin/dashboard.js +0 -2
- data/app/assets/javascripts/madmin/resources.js +0 -36
- data/app/assets/stylesheets/madmin/dashboard.css +0 -4
- data/app/assets/stylesheets/madmin/resources.css +0 -4
- data/app/controllers/madmin/application_controller.rb +0 -16
- data/app/controllers/madmin/resources_controller.rb +0 -97
- data/app/decorators/madmin/resource_decorator.rb +0 -16
- data/app/helpers/madmin/fields/polymorphic_helper.rb +0 -25
- data/app/jobs/madmin/application_job.rb +0 -4
- data/app/mailers/madmin/application_mailer.rb +0 -6
- data/app/models/madmin/application_record.rb +0 -5
- data/app/views/application/_navigation.html.erb +0 -17
- data/app/views/madmin/dashboard/index.html.erb +0 -6
- data/app/views/madmin/fields/check_box/_form.html.erb +0 -4
- data/app/views/madmin/fields/check_box/_index.html.erb +0 -1
- data/app/views/madmin/fields/check_box/_show.html.erb +0 -8
- data/app/views/madmin/fields/email/_form.html.erb +0 -4
- data/app/views/madmin/fields/email/_index.html.erb +0 -1
- data/app/views/madmin/fields/email/_show.html.erb +0 -8
- data/app/views/madmin/fields/number/_form.html.erb +0 -4
- data/app/views/madmin/fields/number/_index.html.erb +0 -1
- data/app/views/madmin/fields/number/_show.html.erb +0 -8
- data/app/views/madmin/fields/password/_form.html.erb +0 -4
- data/app/views/madmin/fields/password/_index.html.erb +0 -1
- data/app/views/madmin/fields/password/_show.html.erb +0 -8
- data/app/views/madmin/fields/select/_form.html.erb +0 -4
- data/app/views/madmin/fields/select/_index.html.erb +0 -1
- data/app/views/madmin/fields/select/_show.html.erb +0 -8
- data/app/views/madmin/fields/text_area/_form.html.erb +0 -4
- data/app/views/madmin/fields/text_area/_index.html.erb +0 -1
- data/app/views/madmin/fields/text_area/_show.html.erb +0 -8
- data/app/views/madmin/resources/_form.html.erb +0 -15
- data/app/views/madmin/resources/_scopes.html.erb +0 -10
- data/app/views/madmin/resources/edit.html.erb +0 -2
- data/app/views/madmin/resources/index.html.erb +0 -13
- data/app/views/madmin/resources/index/_content.html.erb +0 -33
- data/app/views/madmin/resources/new.html.erb +0 -2
- data/app/views/madmin/resources/show.html.erb +0 -10
- data/config/routes.rb +0 -11
- data/lib/generators/madmin/controller/USAGE +0 -8
- data/lib/generators/madmin/controller/controller_generator.rb +0 -10
- data/lib/generators/madmin/page/USAGE +0 -8
- data/lib/generators/madmin/page/page_generator.rb +0 -20
- data/lib/generators/madmin/page/templates/template.html.erb +0 -2
- data/lib/generators/madmin/page/templates/template.rb.erb +0 -10
- data/lib/generators/madmin/resource/templates/resource.rb.erb +0 -11
- data/lib/madmin/field/associatable.rb +0 -58
- data/lib/madmin/field/belongs_to.rb +0 -9
- data/lib/madmin/field/check_box.rb +0 -8
- data/lib/madmin/field/date_time.rb +0 -8
- data/lib/madmin/field/email.rb +0 -8
- data/lib/madmin/field/has_many.rb +0 -9
- data/lib/madmin/field/has_one.rb +0 -9
- data/lib/madmin/field/number.rb +0 -8
- data/lib/madmin/field/password.rb +0 -8
- data/lib/madmin/field/polymorphic.rb +0 -57
- data/lib/madmin/field/select.rb +0 -13
- data/lib/madmin/field/text.rb +0 -8
- data/lib/madmin/field/text_area.rb +0 -8
- data/lib/madmin/resourceable.rb +0 -72
- data/lib/madmin/resourceable/class_methods.rb +0 -152
- data/lib/madmin/resources.rb +0 -13
@@ -1,97 +0,0 @@
|
|
1
|
-
require_dependency "madmin/application_controller"
|
2
|
-
|
3
|
-
module Madmin
|
4
|
-
class ResourcesController < ApplicationController
|
5
|
-
include ActiveSupport::Inflector
|
6
|
-
|
7
|
-
before_action :find_resource, only: [:show, :edit, :update, :destroy]
|
8
|
-
|
9
|
-
helper_method :madmin_resource
|
10
|
-
|
11
|
-
def index
|
12
|
-
@scopes = madmin_resource.scopes
|
13
|
-
@headers = madmin_resource.index_headers
|
14
|
-
|
15
|
-
if params[:scope]&.to_sym&.in?(@scopes)
|
16
|
-
begin
|
17
|
-
@collection = resource.send(params[:scope])
|
18
|
-
rescue ArgumentError
|
19
|
-
raise ScopeWithArgumentsError, "The scope #{params[:scope.to_sym]} on #{resource.name} takes arguments, which are currently unsupported."
|
20
|
-
end
|
21
|
-
else
|
22
|
-
@collection = resource.all
|
23
|
-
end
|
24
|
-
|
25
|
-
respond_to do |format|
|
26
|
-
format.html
|
27
|
-
format.json { render json: @collection.map { |c| {id: c.id, display_value: c.title} } }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def show
|
32
|
-
end
|
33
|
-
|
34
|
-
def new
|
35
|
-
@resource = ResourceDecorator.new(resource.new(resource_params))
|
36
|
-
end
|
37
|
-
|
38
|
-
def create
|
39
|
-
@resource = ResourceDecorator.new(resource.new(resource_params))
|
40
|
-
|
41
|
-
if @resource.save
|
42
|
-
redirect_to resource_path(id: @resource.id)
|
43
|
-
else
|
44
|
-
render :new
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def edit
|
49
|
-
end
|
50
|
-
|
51
|
-
def update
|
52
|
-
if @resource.update(resource_params)
|
53
|
-
redirect_to resource_path(id: @resource.id)
|
54
|
-
else
|
55
|
-
render :edit
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def destroy
|
60
|
-
if @resource.destroy
|
61
|
-
redirect_to resources_path(params[:resource])
|
62
|
-
else
|
63
|
-
flash[:error] = "There was an issue deleting the record."
|
64
|
-
redirect_to :back
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def find_resource
|
71
|
-
@resource ||= Madmin::ResourceDecorator.new(resource.find(params[:id]))
|
72
|
-
end
|
73
|
-
|
74
|
-
def form_keys
|
75
|
-
madmin_resource.form_fields.map { |field| field.strong_params_keys }.flatten
|
76
|
-
end
|
77
|
-
|
78
|
-
def madmin_resource
|
79
|
-
Object.const_get("::Madmin::Resources::#{resource_name}").new
|
80
|
-
end
|
81
|
-
|
82
|
-
def resource
|
83
|
-
Object.const_get(resource_name)
|
84
|
-
end
|
85
|
-
|
86
|
-
def resource_name
|
87
|
-
camelize(params[:resource].singularize)
|
88
|
-
end
|
89
|
-
|
90
|
-
def resource_params
|
91
|
-
param_key = resource_name.downcase.to_sym
|
92
|
-
return unless params.dig(param_key)
|
93
|
-
|
94
|
-
params.require(param_key).permit(form_keys)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Madmin
|
2
|
-
module Fields
|
3
|
-
module PolymorphicHelper
|
4
|
-
def polymorphic_models(type)
|
5
|
-
all_resources = Madmin::Resources.all.map { |r| Madmin::ResourceDecorator.new(r) }
|
6
|
-
|
7
|
-
polymorphic_resources = all_resources.select { |resource|
|
8
|
-
associations = resource.model.reflect_on_all_associations
|
9
|
-
associations.select { |a| a.options.dig(:as) === type }.any?
|
10
|
-
}
|
11
|
-
|
12
|
-
polymorphic_resources.map(&:model)
|
13
|
-
end
|
14
|
-
|
15
|
-
def polymorphic_options_for_selected_type(form:, field:)
|
16
|
-
options_from_collection_for_select(
|
17
|
-
form.object.send(field.polymorphic_type_param).constantize.send(field.polymorphic_scope),
|
18
|
-
:id,
|
19
|
-
field.polymorphic_display_value,
|
20
|
-
form.object.send(field.polymorphic_id_param)
|
21
|
-
)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<nav class="nav bg-dark col-md-2 sidebar px-4 py-3 d-flex flex-column">
|
2
|
-
<h3><%= link_to 'Madmin', root_path %></h3>
|
3
|
-
|
4
|
-
<ul class="list-unstyled mt-3">
|
5
|
-
<% available_resources.each do |resource| %>
|
6
|
-
<% next unless resource.show_in_menu? %>
|
7
|
-
<li class="mb-1">
|
8
|
-
<%= link_to resource.friendly_name.pluralize, resources_path(resource.slug), class: "text-white" %>
|
9
|
-
</li>
|
10
|
-
<% end %>
|
11
|
-
<% pages.each do |page| %>
|
12
|
-
<li class="mb-1">
|
13
|
-
<%= link_to page, "#", class: "text-white"%>
|
14
|
-
</li>
|
15
|
-
<% end %>
|
16
|
-
</ul>
|
17
|
-
</nav>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= field.value_for(resource) %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= field.value_for(resource) %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= link_to field.value_for(resource), resource_path(madmin_resource.slug, id: resource.id) %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= 'Password Encrypted' if field.value %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= field.value %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= field.value %>
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<%= form_for resource, url: url do |form| %>
|
2
|
-
<% if resource.errors.any? %>
|
3
|
-
<% resource.errors.full_messages.each do |message| %>
|
4
|
-
<li><%= message %></li>
|
5
|
-
<% end %>
|
6
|
-
<% end %>
|
7
|
-
|
8
|
-
<% madmin_resource.form_fields.each do |field| %>
|
9
|
-
<%= render "#{field.to_partial_path}/form", field: field, form: form, resource: resource %>
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
<div class="mt-4">
|
13
|
-
<%= form.submit class: "btn btn-primary" %>
|
14
|
-
</div>
|
15
|
-
<% end %>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<div class="list-group">
|
2
|
-
<%= link_to resources_path(madmin_resource.slug), class: "list-group-item py-2 list-group-item-action #{'active' if params[:scope].blank?}" do %>
|
3
|
-
All
|
4
|
-
<% end %>
|
5
|
-
<% scopes.each do |scope| %>
|
6
|
-
<%= link_to resources_path(madmin_resource.slug, scope: scope.to_s), class: "list-group-item py-2 list-group-item-action #{'active' if params[:scope] == scope.to_s}" do %>
|
7
|
-
<%= scope.to_s.titleize %>
|
8
|
-
<% end %>
|
9
|
-
<% end %>
|
10
|
-
</div>
|
@@ -1,13 +0,0 @@
|
|
1
|
-
<div class="row">
|
2
|
-
<div class="col">
|
3
|
-
<h1><%= madmin_resource.friendly_name.pluralize %></h1>
|
4
|
-
</div>
|
5
|
-
</div>
|
6
|
-
<div class="row">
|
7
|
-
<%= content_tag :div, class: @scopes.any? ? 'col-3' : 'd-none' do %>
|
8
|
-
<%= render 'scopes', scopes: @scopes %>
|
9
|
-
<% end %>
|
10
|
-
<%= content_tag :div, class: @scopes.any? ? 'col-9' : 'col-12' do %>
|
11
|
-
<%= render 'madmin/resources/index/content', headers: @headers, collection: @collection, show_new_button: true %>
|
12
|
-
<% end %>
|
13
|
-
</div>
|
@@ -1,33 +0,0 @@
|
|
1
|
-
<table class="table">
|
2
|
-
<thead>
|
3
|
-
<% headers.each do |header| %>
|
4
|
-
<th><%= header %></th>
|
5
|
-
<% end %>
|
6
|
-
</thead>
|
7
|
-
<% if collection.any? %>
|
8
|
-
<% collection.each do |resource| %>
|
9
|
-
<tr>
|
10
|
-
<% madmin_resource.index_fields.each do |field| %>
|
11
|
-
<td>
|
12
|
-
<%=
|
13
|
-
render "#{field.to_partial_path}/index",
|
14
|
-
field: field,
|
15
|
-
madmin_resource: madmin_resource,
|
16
|
-
resource: resource
|
17
|
-
%>
|
18
|
-
</td>
|
19
|
-
<% end %>
|
20
|
-
</tr>
|
21
|
-
<% end %>
|
22
|
-
<% else %>
|
23
|
-
<tr>
|
24
|
-
<td>No records found</td>
|
25
|
-
</tr>
|
26
|
-
<% end %>
|
27
|
-
</table>
|
28
|
-
|
29
|
-
<% if show_new_button %>
|
30
|
-
<div class="mt-4">
|
31
|
-
<%= link_to 'New', new_resource_path, class: "btn btn-primary" %>
|
32
|
-
</div>
|
33
|
-
<% end %>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<h1><%= @resource.name %> <%= @resource.id %></h1>
|
2
|
-
|
3
|
-
<% madmin_resource.show_fields.each do |field| %>
|
4
|
-
<%= render "#{field.to_partial_path}/show", field: field, resource: @resource %>
|
5
|
-
<% end %>
|
6
|
-
|
7
|
-
<div class="mt-4">
|
8
|
-
<%= link_to 'Edit', edit_resource_path(id: @resource.id), class: "btn btn-primary" %>
|
9
|
-
<%= link_to 'Delete', resource_path(id: @resource.id), method: :delete, class: "btn btn-danger" %>
|
10
|
-
</div>
|
data/config/routes.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
Madmin::Engine.routes.draw do
|
2
|
-
root to: "dashboard#index"
|
3
|
-
|
4
|
-
get "/:resource", to: "resources#index", as: :resources
|
5
|
-
get "/:resource/new", to: "resources#new", as: :new_resource
|
6
|
-
post "/:resource", to: "resources#create"
|
7
|
-
get "/:resource/:id", to: "resources#show", as: :resource
|
8
|
-
get "/:resource/:id/edit", to: "resources#edit", as: :edit_resource
|
9
|
-
patch "/:resource/:id", to: "resources#update"
|
10
|
-
delete "/:resource/:id", to: "resources#destroy"
|
11
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class Madmin::ControllerGenerator < Rails::Generators::NamedBase
|
2
|
-
source_root File.expand_path("../../../../../", __FILE__)
|
3
|
-
|
4
|
-
def copy_controller
|
5
|
-
copy_file(
|
6
|
-
"app/controllers/madmin/#{file_name}_controller.rb",
|
7
|
-
"app/controllers/madmin/#{file_name}_controller.rb"
|
8
|
-
)
|
9
|
-
end
|
10
|
-
end
|