madmin 1.2.4 → 1.2.5
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 +4 -4
- data/app/controllers/madmin/application_controller.rb +22 -0
- data/app/views/madmin/application/index.html.erb +5 -2
- data/app/views/madmin/application/show.html.erb +1 -1
- data/app/views/madmin/fields/file/_form.html.erb +4 -0
- data/app/views/madmin/fields/file/_index.html.erb +1 -0
- data/app/views/madmin/fields/file/_show.html.erb +6 -0
- data/app/views/madmin/fields/integer/_index.html.erb +5 -1
- data/app/views/madmin/fields/text/_index.html.erb +1 -1
- data/lib/madmin/field.rb +3 -2
- data/lib/madmin/fields/file.rb +9 -0
- data/lib/madmin/resource.rb +17 -14
- data/lib/madmin/version.rb +1 -1
- data/lib/madmin.rb +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea857d0e707bca79172d1bcbecb72cfb939724279ab3f2c08546ff279fd38d03
|
|
4
|
+
data.tar.gz: c886c8ad0c5d0a11c81f1aecf45463e29205e9bf29dfe00fae4fc94466988ee0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65e7522be423638030455299a70bfdd21cc706e75a5b6624f7a41f869250517474b00dd514551914e86bb3b7e7dac31aa812826461a634649caba8456b73f5c8
|
|
7
|
+
data.tar.gz: faea74829b0c7e307960dcbe006986f51c064e147c00b17f1234bfc6b72246511c1d206d4891fd773f3f97ea05b96a87dbcdd3e9b709aac1141407a580529b26
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Madmin
|
|
2
|
+
class ApplicationController < Madmin::BaseController
|
|
3
|
+
before_action :authenticate_admin_user
|
|
4
|
+
|
|
5
|
+
def authenticate_admin_user
|
|
6
|
+
# TODO: Add your authentication logic here
|
|
7
|
+
|
|
8
|
+
# For example, we could redirect if the user isn't an admin
|
|
9
|
+
# redirect_to "/", alert: "Not authorized." unless user_signed_in? && current_user.admin?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Authenticate with Clearance
|
|
13
|
+
# include Clearance::Controller
|
|
14
|
+
# before_action :require_login
|
|
15
|
+
|
|
16
|
+
# Authenticate with Devise
|
|
17
|
+
# before_action :authenticate_user!
|
|
18
|
+
|
|
19
|
+
# Authenticate with Basic Auth
|
|
20
|
+
# http_basic_authenticate_with(name: Rails.application.credentials.admin_username, password: Rails.application.credentials.admin_password)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -47,10 +47,13 @@
|
|
|
47
47
|
<% resource.attributes.values.each do |attribute| %>
|
|
48
48
|
<% next if attribute.field.nil? %>
|
|
49
49
|
<% next unless attribute.field.visible?(action_name) %>
|
|
50
|
-
<td class="px-4 py-2"><%= render partial: attribute.field.to_partial_path("index"), locals: { field: attribute.field, record: record } %></td>
|
|
50
|
+
<td class="px-4 py-2"><%= render partial: attribute.field.to_partial_path("index"), locals: { field: attribute.field, record: record, resource: resource } %></td>
|
|
51
51
|
<% end %>
|
|
52
52
|
|
|
53
|
-
<td class="px-4 py-2 text-center"
|
|
53
|
+
<td class="px-4 py-2 text-center">
|
|
54
|
+
<%= link_to "View", resource.show_path(record), class: "text-indigo-500" %>
|
|
55
|
+
<%= link_to "Edit", resource.edit_path(record), class: "text-indigo-500" %>
|
|
56
|
+
</td>
|
|
54
57
|
</tr>
|
|
55
58
|
<% end %>
|
|
56
59
|
</tbody>
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
</div>
|
|
25
25
|
|
|
26
26
|
<div class="md:col-span-3">
|
|
27
|
-
<%= render partial: attribute.field.to_partial_path("show"), locals: { field: attribute.field, record: @record } %>
|
|
27
|
+
<%= render partial: attribute.field.to_partial_path("show"), locals: { field: attribute.field, record: @record, resource: resource } %>
|
|
28
28
|
</div>
|
|
29
29
|
</div>
|
|
30
30
|
<% end %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= field.value(record) %>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%= field.value(record) %>
|
|
1
|
+
<%= truncate field.value(record) %>
|
data/lib/madmin/field.rb
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
module Madmin
|
|
2
2
|
class Field
|
|
3
|
-
attr_reader :attribute_name, :model, :options
|
|
3
|
+
attr_reader :attribute_name, :model, :options, :resource
|
|
4
4
|
|
|
5
5
|
def self.field_type
|
|
6
6
|
to_s.split("::").last.underscore
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def initialize(attribute_name:, model:, **options)
|
|
9
|
+
def initialize(attribute_name:, model:, resource:, **options)
|
|
10
10
|
@attribute_name = attribute_name
|
|
11
11
|
@model = model
|
|
12
|
+
@resource = resource
|
|
12
13
|
@options = options
|
|
13
14
|
end
|
|
14
15
|
|
data/lib/madmin/resource.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Madmin
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def model
|
|
14
|
-
model_name.constantize
|
|
14
|
+
@model ||= model_name.constantize
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def model_find(id)
|
|
@@ -37,7 +37,7 @@ module Madmin
|
|
|
37
37
|
attributes[name] = OpenStruct.new(
|
|
38
38
|
name: name,
|
|
39
39
|
type: type,
|
|
40
|
-
field: field.new(**options.merge(attribute_name: name, model: model))
|
|
40
|
+
field: field.new(**options.merge(attribute_name: name, model: model, resource: self))
|
|
41
41
|
)
|
|
42
42
|
rescue => e
|
|
43
43
|
builder = ResourceBuilder.new(model)
|
|
@@ -58,28 +58,30 @@ module Madmin
|
|
|
58
58
|
model_name.gsub("::", " / ")
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
# Support for isolated namespaces
|
|
62
|
+
# Finds parent module class to include in polymorphic urls
|
|
63
|
+
def route_namespace
|
|
64
|
+
return @route_namespace if instance_variable_defined?(:@route_namespace)
|
|
65
|
+
namespace = model.module_parents.detect do |n|
|
|
66
|
+
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
|
67
|
+
end
|
|
68
|
+
@route_namespace = (namespace ? namespace.name.singularize.underscore.to_sym : nil)
|
|
69
|
+
end
|
|
63
70
|
|
|
64
|
-
|
|
71
|
+
def index_path(options = {})
|
|
72
|
+
url_helpers.polymorphic_path([:madmin, route_namespace, model], options)
|
|
65
73
|
end
|
|
66
74
|
|
|
67
75
|
def new_path
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
url_helpers.send(route_name)
|
|
76
|
+
url_helpers.polymorphic_path([:madmin, route_namespace, model], action: :new)
|
|
71
77
|
end
|
|
72
78
|
|
|
73
79
|
def show_path(record)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
url_helpers.send(route_name, record.to_param)
|
|
80
|
+
url_helpers.polymorphic_path([:madmin, route_namespace, record])
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
def edit_path(record)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
url_helpers.send(route_name, record.to_param)
|
|
84
|
+
url_helpers.polymorphic_path([:madmin, route_namespace, record], action: :edit)
|
|
83
85
|
end
|
|
84
86
|
|
|
85
87
|
def param_key
|
|
@@ -128,6 +130,7 @@ module Madmin
|
|
|
128
130
|
time: Fields::Time,
|
|
129
131
|
timestamp: Fields::Time,
|
|
130
132
|
password: Fields::Password,
|
|
133
|
+
file: Fields::File,
|
|
131
134
|
|
|
132
135
|
# Postgres specific types
|
|
133
136
|
bit: Fields::String,
|
data/lib/madmin/version.rb
CHANGED
data/lib/madmin.rb
CHANGED
|
@@ -18,6 +18,7 @@ module Madmin
|
|
|
18
18
|
autoload :DateTime, "madmin/fields/date_time"
|
|
19
19
|
autoload :Decimal, "madmin/fields/decimal"
|
|
20
20
|
autoload :Enum, "madmin/fields/enum"
|
|
21
|
+
autoload :File, "madmin/fields/file"
|
|
21
22
|
autoload :Float, "madmin/fields/float"
|
|
22
23
|
autoload :HasMany, "madmin/fields/has_many"
|
|
23
24
|
autoload :HasOne, "madmin/fields/has_one"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: madmin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Oliver
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2021-09-
|
|
12
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
@@ -59,6 +59,7 @@ files:
|
|
|
59
59
|
- app/assets/config/manifest.js
|
|
60
60
|
- app/assets/stylesheets/actiontext.scss
|
|
61
61
|
- app/assets/stylesheets/application.css
|
|
62
|
+
- app/controllers/madmin/application_controller.rb
|
|
62
63
|
- app/controllers/madmin/base_controller.rb
|
|
63
64
|
- app/controllers/madmin/dashboard_controller.rb
|
|
64
65
|
- app/controllers/madmin/resource_controller.rb
|
|
@@ -98,6 +99,9 @@ files:
|
|
|
98
99
|
- app/views/madmin/fields/enum/_form.html.erb
|
|
99
100
|
- app/views/madmin/fields/enum/_index.html.erb
|
|
100
101
|
- app/views/madmin/fields/enum/_show.html.erb
|
|
102
|
+
- app/views/madmin/fields/file/_form.html.erb
|
|
103
|
+
- app/views/madmin/fields/file/_index.html.erb
|
|
104
|
+
- app/views/madmin/fields/file/_show.html.erb
|
|
101
105
|
- app/views/madmin/fields/float/_form.html.erb
|
|
102
106
|
- app/views/madmin/fields/float/_index.html.erb
|
|
103
107
|
- app/views/madmin/fields/float/_show.html.erb
|
|
@@ -167,6 +171,7 @@ files:
|
|
|
167
171
|
- lib/madmin/fields/date_time.rb
|
|
168
172
|
- lib/madmin/fields/decimal.rb
|
|
169
173
|
- lib/madmin/fields/enum.rb
|
|
174
|
+
- lib/madmin/fields/file.rb
|
|
170
175
|
- lib/madmin/fields/float.rb
|
|
171
176
|
- lib/madmin/fields/has_many.rb
|
|
172
177
|
- lib/madmin/fields/has_one.rb
|