madmin 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dabaf5123e6b2ffca6ad53b150aa7fd682f3867123229ab194e79379e63ab3d
4
- data.tar.gz: 1cc11dbbb97bfdc38c6db838bd3077f3391202afc0e86899e8db41a1f501978a
3
+ metadata.gz: ea857d0e707bca79172d1bcbecb72cfb939724279ab3f2c08546ff279fd38d03
4
+ data.tar.gz: c886c8ad0c5d0a11c81f1aecf45463e29205e9bf29dfe00fae4fc94466988ee0
5
5
  SHA512:
6
- metadata.gz: 91819f3b6fa6913e61cbb47260022b4673e3566c84156bf3c45f43ddc924279346e21c690f6ab7e12ec99593d68a2ffa7142c0ef9c747e47284bcf3033b75304
7
- data.tar.gz: d6b666670851c5b2c69d9df5ec07abd4b21e67808d9ede0f85d8e20613b89f84ec538c9ab7ff19edbc80132d50c0b1d1e80c4909175f70c7b6d9328efc829134
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"><%= link_to "View", resource.show_path(record), class: "text-indigo-500" %></td>
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,4 @@
1
+ <div class="block md:inline-block md:w-32 flex-shrink-0 text-gray-700">
2
+ <%= render "madmin/shared/label", form: form, field: field %>
3
+ </div>
4
+ <%= form.file_field field.attribute_name, class: "form-input" %>
@@ -0,0 +1 @@
1
+ <%= field.value(record) %>
@@ -0,0 +1,6 @@
1
+ <% value = field.value(record) %>
2
+ <% if value.respond_to?(:url) %>
3
+ <%= link_to value.url, value.url, target: :_blank, class: "text-indigo-500 underline" %>
4
+ <% else %>
5
+ <%= value %>
6
+ <% end %>
@@ -1 +1,5 @@
1
- <%= field.value(record) %>
1
+ <% if field.attribute_name == :id %>
2
+ <%= link_to field.value(record), resource.show_path(record), class: "text-indigo-500 underline" %>
3
+ <% else %>
4
+ <%= field.value(record) %>
5
+ <% end %>
@@ -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
 
@@ -0,0 +1,9 @@
1
+ module Madmin
2
+ module Fields
3
+ class File < Field
4
+ def searchable?
5
+ false
6
+ end
7
+ end
8
+ end
9
+ end
@@ -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
- def index_path(options = {})
62
- route_name = "madmin_#{model.model_name.plural}_path"
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
- url_helpers.send(route_name, options)
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
- route_name = "new_madmin_#{model.model_name.singular}_path"
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
- route_name = "madmin_#{model.model_name.singular}_path"
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
- route_name = "edit_madmin_#{model.model_name.singular}_path"
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,
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
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
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-24 00:00:00.000000000 Z
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