captive-admin 0.2.9 → 0.2.11

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: 28efe38700cab350ab210400adcfbc3f8351e30e56498f435fa67b8292443876
4
- data.tar.gz: 676f77870aa5e60da1d22c812c2ebfe7a6228e5cdcd1b830c91c86990a58d528
3
+ metadata.gz: ffe7ba5722703ad09819644a416e1214d51019fe252f237cbeebb3a1740735ca
4
+ data.tar.gz: d045ce6ffee5981ab1d22e6242bef2a1e4d735ad11ab6061c2777431ee44f4c6
5
5
  SHA512:
6
- metadata.gz: 723339b8fcded2c955c817b326c4bc2d596412223b3cc53146d69c4689d45cf0f2f7a3860f2fa183f2753863753813491c1b015b55658a3e3639540b8a4d9456
7
- data.tar.gz: 3cb7549acf12e634360e6f78b2ad43aab247397841044cd17fabc30b7f76d879e0dce3fbef4fdd022ed1778371b98e6add24864362ec214ec43ad8c3d2f683f3
6
+ metadata.gz: 8e6ea5c022f2886c471acc43a4a1515e5be93ac2cd21554509999fde84cb6c316aa74982cb886340454a7567ddb714ddc72786f3132e1e8ee240751cb629df35
7
+ data.tar.gz: 2d0c024d00719e35e229f1f84238ffa55d71693bb7656483c2d54a70a0b5ef041048b5b2653f80486c2d5c12fb4954560f5b19cae79628bf2683f0d88e99643d
data/README.md CHANGED
@@ -29,6 +29,14 @@ gem 'captive-admin'
29
29
  @import "captive-admin/base";
30
30
  ```
31
31
 
32
+ ## Usage
33
+
34
+ You can use the admin generator. [See the usage doc to read more information](./lib/generators/admin/USAGE) :
35
+
36
+ ```console
37
+ bin/rails generate admin Thing
38
+ ```
39
+
32
40
  ## Contributing
33
41
 
34
42
  Bug reports and pull requests are welcome on GitHub at https://github.com/Captive-Studio/captive-sdk.
data/lib/captive/admin.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "captive/admin/engine"
4
+ require "captive/theme"
4
5
 
5
6
  module Captive
6
7
  module Admin
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Créé une resource ActiveAdmin au standard
3
+
4
+ Example:
5
+ bin/rails generate admin Thing
6
+
7
+ This will create:
8
+ app/admin/things.rb
9
+ app/views/admin/things/_form.html.arb
10
+ app/views/admin/things/_show.html.arb
@@ -0,0 +1,130 @@
1
+ class AdminGenerator < Rails::Generators::NamedBase
2
+ desc "Créé une resource ActiveAdmin au standard"
3
+ def create_resource_file
4
+ say "Voir le Standard : https://captive.notion.site/ActiveAdmin-Personnaliser-l-index-e7869c1bd6064e94a623eb7950d1ca8c?pvs=4",
5
+ :blue
6
+ create_resource
7
+ create_show
8
+ create_form
9
+ end
10
+
11
+ private
12
+
13
+ def create_resource
14
+ create_file "app/admin/#{plural_name}.rb", <<~RUBY
15
+ # frozen_string_literal: true
16
+
17
+ ActiveAdmin.register #{class_name} do
18
+ config.sort_order = "created_at_desc"
19
+
20
+ permit_params #{permit_params.map { |p| ":#{p}" }.join(", ")}
21
+ #{includes}
22
+ index do
23
+ #{index_columns.map { |attr| "column :#{attr}" }.join("\n ")}
24
+ actions dropdown: true
25
+ end
26
+
27
+ show do
28
+ render partial: "admin/#{plural_name}/show", locals: { resource: resource }
29
+ end
30
+
31
+ form partial: "admin/#{plural_name}/form"
32
+ end
33
+ RUBY
34
+ end
35
+
36
+ def create_show
37
+ create_file "app/views/admin/#{plural_name}/_show.html.arb", <<~RUBY
38
+ # frozen_string_literal: true
39
+
40
+ panel "Détails #{plural_name}" do
41
+ attributes_table_for resource do
42
+ #{show_rows.map { |attr| "row :#{attr}" }.join("\n ")}
43
+ end
44
+ end
45
+ RUBY
46
+ end
47
+
48
+ def create_form
49
+ create_file "app/views/admin/#{plural_name}/_form.html.arb", <<~RUBY
50
+ # frozen_string_literal: true
51
+
52
+ active_admin_form_for [:admin, resource] do |f|
53
+ f.semantic_errors
54
+ f.inputs do
55
+ #{form_inputs.map { |p| "f.input :#{p}" }.join("\n ")}
56
+ end
57
+ f.actions
58
+ end
59
+ RUBY
60
+ end
61
+
62
+ def columns
63
+ @columns ||=
64
+ class_name.constantize
65
+ .columns
66
+ .map(&:name)
67
+ end
68
+
69
+ def columns_with_associations
70
+ @columns_with_associations ||=
71
+ columns.map do |c|
72
+ association =
73
+ class_name.constantize.reflect_on_all_associations.find do |a|
74
+ a.association_foreign_key == c
75
+ end
76
+
77
+ next c if association.blank?
78
+
79
+ association.name.to_s
80
+ end
81
+ end
82
+
83
+ def associations
84
+ @associations ||=
85
+ columns.map do |c|
86
+ class_name.constantize.reflect_on_all_associations.find do |a|
87
+ a.association_foreign_key == c
88
+ end&.name
89
+ end.compact
90
+ end
91
+
92
+ def includes
93
+ return if associations.blank?
94
+
95
+ "\n includes :#{associations.join(", ")}\n"
96
+ end
97
+
98
+ PERMIT_PARAMS_EXCLUDED = [
99
+ "id",
100
+ "created_at",
101
+ "updated_at",
102
+ "encrypted_password",
103
+ "reset_password_token",
104
+ "reset_password_sent_at",
105
+ "remember_created_at",
106
+ ].freeze
107
+ def permit_params
108
+ permit_params = columns.excluding(PERMIT_PARAMS_EXCLUDED)
109
+ if columns.include?("encrypted_password")
110
+ permit_params << "password"
111
+ permit_params << "password_confirmation"
112
+ end
113
+ permit_params
114
+ end
115
+
116
+ INDEX_EXCLUDED = PERMIT_PARAMS_EXCLUDED
117
+ def index_columns
118
+ columns_with_associations.excluding(INDEX_EXCLUDED)
119
+ end
120
+
121
+ SHOW_EXCLUDED = ["encrypted_password"].freeze
122
+ def show_rows
123
+ columns_with_associations.excluding(SHOW_EXCLUDED)
124
+ end
125
+
126
+ INPUT_EXCLUDED = INDEX_EXCLUDED
127
+ def form_inputs
128
+ columns_with_associations.excluding(INPUT_EXCLUDED)
129
+ end
130
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: captive-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captive
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-11-06 00:00:00.000000000 Z
12
+ date: 2023-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 0.2.9
34
+ version: 0.2.11
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: 0.2.9
41
+ version: 0.2.11
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec-rails
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -91,13 +91,15 @@ files:
91
91
  - app/assets/stylesheets/captive-admin/structure/_title_bar.scss
92
92
  - lib/captive/admin.rb
93
93
  - lib/captive/admin/engine.rb
94
+ - lib/generators/admin/USAGE
95
+ - lib/generators/admin/admin_generator.rb
94
96
  - lib/tasks/captive/admin_tasks.rake
95
97
  homepage: https://captive.fr/
96
98
  licenses:
97
99
  - MIT
98
100
  metadata:
99
101
  homepage_uri: https://captive.fr/
100
- source_code_uri: https://github.com/Captive-Studio/captive-sdk/tree/v0.2.9/captive-admin
102
+ source_code_uri: https://github.com/Captive-Studio/captive-sdk/tree/v0.2.11/captive-admin
101
103
  post_install_message:
102
104
  rdoc_options: []
103
105
  require_paths: