infold 0.2.0 → 0.2.1

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: 34854ed0db701ed065426e414a75459e5b65b9925da9ebb3ac61ba9cd39ad5f5
4
- data.tar.gz: 5bb21994d45263520774efb5a991613dffddf17f17020a7456917eb6e3f36b7a
3
+ metadata.gz: a965cd1508d39abde6e77ad66a19dec7a088159b3562d795576dc70a3a36332a
4
+ data.tar.gz: 40163f510b91241b30fe97c56dfe9114e679f5de014c2f451b3a00de0e42650b
5
5
  SHA512:
6
- metadata.gz: a65c780a5bd993bc9dd2a081854f514d0c98d902fb0796dbb9d469317ce1f46989f16a8bd6afc3750cacf5ca0de076bdfc1ee6e02469ae18b681d6d251d64b3c
7
- data.tar.gz: df9d3d3ff2cc9ab70a783ddac5312ed14475ca9110aa7329a6237775c29bd32986b4ab022fd655e0d0e8a540fa965ec1a9c612ac030c92c52b10106935b94ae8
6
+ metadata.gz: 8c24112c452a48c2fcb3ca34b6cf8ea6a49edf18ecfe61ffd8ca35a972f484449af54cac939c2adfb1cfdd27cb635cbd5f59a4bced5e6a4248a0b647e5c5c4a7
7
+ data.tar.gz: 6bce2862588f717f633d09f1af464d9668f2a10a7de36f8c72610ab0141e76ec90d57e35b877b4b4ebe9c2789ad389d4efe1340fd523fe19f1e1fc311bb50140
data/README.md CHANGED
@@ -1,18 +1,22 @@
1
1
  # Infold
2
2
  Infold provides Scaffolding functionality specifically for Internal tools.
3
- CRUD (Create,Read,Update,Delete) applications with an easy-to-use UI can be built instantly.
3
+ CRUD (Create, Read, Update, Delete) applications with an easy-to-use UI can be built instantly.
4
4
  The generated code is highly readable and customizable, allowing for easy additional customization.
5
5
  Supports Rails >= 7.0 and Hotwire.
6
6
 
7
- ## Purpose
7
+ ## Goals
8
8
  - Quickly and easily build Internal tools with all the functionality you need
9
9
  - No need for a designer, just a developer to create a usable UI/UX
10
10
  - Easy customization with YAML and Scaffold instead of DSL development
11
11
 
12
+ ## Getting started
13
+ - Try the [live demo](https://demo.infold.dev/admin).
14
+ - Check the [website](https://infold.dev).
15
+
12
16
  ## Installation
13
17
  Add this line to your application's Gemfile:
14
18
  ```ruby
15
- gem 'indold', require: false
19
+ gem 'infold', require: false
16
20
  ```
17
21
 
18
22
  In addition, infold uses the following Gem, add these lines to your Gemfile too.
@@ -55,33 +59,35 @@ The following is an example of a Product model.
55
59
  $ rails generate infold Product
56
60
  ```
57
61
 
58
- This will generate several files, including Controller and View.
62
+ The above commands will generate several files, including Controller and View.
59
63
  You can check it by starting rails from `bin/dev` and accessing `http://localhost:3000/admin`.
60
64
 
61
65
  ![basic](./readme/basic.png)
62
66
 
63
- By executing the above command, each directory such as controllers, models, and views automatically generates code to run the internal tools.
64
- This is a mechanism similar to that of Rails' Scaffold, and it is possible to implement additional necessary functions based on this.
67
+ By executing the above command, each directory, such as controllers, models, and views, automatically generates code to run the internal tools.
68
+ This mechanism is similar to Rails' Scaffold, and it is possible to implement additional necessary functions based on this.
65
69
 
66
- However, **this is not the only functionality that can be generated from Infold**.
70
+ However, **this is not the only functionality that can generate from Infold**.
67
71
  Let's customize YAML and automatically generate the necessary functions by referring to the following contents.
68
72
 
69
73
  ## More Customization
70
- infold can be customized more by configuring YAML. YAML is generated in the `config/infold` directory.
74
+ Infold can be customized more by configuring YAML. YAML is generated in the `config/infold` directory.
71
75
  After setting up YAML, the code is regenerated by executing the following command.
72
76
  ```shell
73
- $ rails generate infold:scaffold Product
77
+ $ rails generate infold:scaffold ResourceName (eg: Product)
74
78
  ```
75
79
 
80
+ ### YAML for demo apps
81
+ The YAML file for the [demo apps](https://demo.infold.dev/admin) can be referenced [here](https://github.com/yamataka22/infold/tree/main/test/dummy/config/infold). Please refer to it.
82
+
76
83
  ### Validation
77
84
  In `model`.`validate`, you can define validation for each field.
78
85
  #### Example
79
- The following example shows the `title` and `price` fields with required validation and the `price` field with numeric (and greater than or equal to 0) validation.
86
+ The following example shows the `title` and `price` fields with required validation and the `price` field with numeric and greater than or equal to 0 validation.
80
87
  ```yaml
81
88
  model:
82
89
  validate:
83
- title:
84
- - presence
90
+ title: presence
85
91
  price:
86
92
  - presence
87
93
  - numericality:
@@ -109,7 +115,8 @@ Then the screen displays the Name of the Enum.
109
115
  ![enum](./readme/enum.png)
110
116
 
111
117
  #### Colored Enum
112
- Enum also allows you to specify a color for each element. The available colors are `blue` `azure` `indigo` `purple` `pink` `red` `orange` `yellow` `lime` `green` `teal` `cyan`.
118
+ Enum also allows you to specify a color for each element.
119
+ The available colors are `blue`, `azure`, `indigo`, `purple`, `pink`, `red`, `orange`, `yellow`, `lime`, `green`, `teal` and `cyan`.
113
120
  #### Example
114
121
  ```yaml
115
122
  model:
@@ -133,7 +140,7 @@ It will then be displayed with a colored badge for easy identification.
133
140
  ### Decorator
134
141
  In `model`.`decorator`, you can define simple decorations such as comma-separated numbers and units.
135
142
  #### Example
136
- In the following example, the `price` field displays a comma-separated number and "$" as the unit of measure in the front, and the `weight` field displays "Kg" in the back.
143
+ In the following example, the `price` field indicates a comma-separated number and "$" as the unit of measure in the front, and the `weight` field indicates "Kg" in the back.
137
144
  ```yaml
138
145
  model:
139
146
  decorator:
@@ -144,16 +151,16 @@ model:
144
151
  append: Kg
145
152
  ```
146
153
 
147
- Price is displayed as comma-separated and with units.
154
+ Price indicated as comma-separated and with units.
148
155
 
149
156
  ![decorator](./readme/decorator.png)
150
157
 
151
158
  ### ActiveStorage
152
- Infold supports ActiveStorage. If you want to store files such as images or PDFs, define them in `model`. `active_storage`.
159
+ Infold supports ActiveStorage. If you want to store files such as images or PDFs, define them in the `model`. `active_storage`.
153
160
 
154
- **As a prerequisite, ActiveStorage must be installed in the project.**
161
+ **As a prerequisite, ActiveStorage must installed in the project.**
155
162
  #### Example
156
- In the following example, define the use of ActiveStorage with the name `photo` and specify "image" as kind (for PDF, etc., specify "file" as kind).
163
+ In the following example, define the use of ActiveStorage with the name `photo` and select "image" as kind (for PDF, etc., select "file" as kind).
157
164
  ```yaml
158
165
  model:
159
166
  active_storage:
@@ -166,7 +173,7 @@ Then images stored in ActiveStorage can be displayed.
166
173
  ![active_storage_image](./readme/active_storage_image.png)
167
174
 
168
175
  ### Association
169
- Infold supports association with other models such as `has_many` and `belongs_to`. By defining `model`.`association`, it is possible to bulk register and reference related models.
176
+ Infold supports an association with other models such as `has_many` and `belongs_to`. By defining `model`.`association`, it is possible to bulk register and reference, related models.
170
177
  ### belongs_to
171
178
  For example, the relation `purchase` belongs_to `customer` is defined as follows:
172
179
  ```yaml
@@ -176,7 +183,7 @@ model:
176
183
  kind: belongs_to
177
184
  ```
178
185
  #### Naming field
179
- In the case of `belongs_to`, The field representing the record name of the referenced parent model, if any, is defined in `name_filed`.
186
+ In the case of `belongs_to`, the field representing the record name of the referenced parent model, if any, is defined in `name_filed`.
180
187
  The `customer.name` associated with the `customer_id` is displayed. The `customer` is also displayed as a link, which can be clicked to view the details of the `customer`.
181
188
  ```yaml
182
189
  model:
@@ -204,11 +211,11 @@ The `app.show.fields` settings described below will enable batch registration an
204
211
  ![has_many_show](./readme/has_many_show.png)
205
212
 
206
213
  #### Advanced configuration of the referenced model in `has_many`.
207
- For example, in a `has_many` association such as `order` and `order details`, you may want to register multiple `order details` at once when registering `order`.
208
- In this case, by defining `model` in the association model, Validation, Enum, etc. can be defined in the same way as above.
214
+ For example, in a `has_many` association, such as `order` and `order details`, you may want to register multiple `order details` at once when registering `order`.
215
+ In this case, by defining the `model` in the association model, Validation, Enum, etc., can be defined in the same way as above.
209
216
  #### Example
210
217
  In the example below, there is a `has_many order_details` association.
211
- For this `order_details`, define a required validation for the `product_id` field, and a decorator for the `amount` field. It also defines an `association`.`belongs_to` for the `product` model that the `order_detail` is associated with.
218
+ For this `order_details`, define a required validation for the `product_id` field, and a decorator for the `amount` field. It also defines an `association`.`belongs_to` for the `product` with which the `order_detail` is associated with.
212
219
  ```yaml
213
220
  model:
214
221
  association:
@@ -216,8 +223,7 @@ model:
216
223
  kind: has_many
217
224
  model:
218
225
  validate:
219
- product_id:
220
- - presence
226
+ product: presence
221
227
  decorator:
222
228
  amount:
223
229
  digit: true
@@ -228,6 +234,9 @@ model:
228
234
  ```
229
235
 
230
236
  #### Bulk Registration Form
237
+ In the following example, multiple lines of OrderDetails can be registered at once.
238
+ You can add rows from the ADD button and delete records with the trash icon.
239
+
231
240
  ![has_many_form](./readme/has_many_form.png)
232
241
 
233
242
  ## View Customization
@@ -249,10 +258,10 @@ form_kind can be specified as follows:
249
258
  - number (input type="number")
250
259
  - select
251
260
  - switch (Used with the boolean type)
252
- - association_search (For association columns in belongs_to, `association_search` allows you to search and specify the related tables from the child screen)
261
+ - association_search (For association columns in belongs_to, `association_search` allows you to search and specify the related tables from the child screen.)
253
262
 
254
263
  #### Example
255
- For example, equal search for id, association search for customer_id, multiple checkboxes for status, is defined as follows:
264
+ For example, equal search for id, association search for customer_id, and multiple checkboxes for status are defined as follows:
256
265
  ```yaml
257
266
  app:
258
267
  index:
@@ -291,7 +300,7 @@ app:
291
300
  ![index_view](./readme/index_view.png)
292
301
 
293
302
  #### CSV output
294
- infold also allows CSV output of search results. Define the target columns in `app`.`index`.`csv`.`fields`. If empty, all fields will be output.
303
+ Infold also allows CSV output of search results. Define the target columns in `app`.`index`.`csv`.`fields`. If empty, all fields will be output.
295
304
 
296
305
  #### Example
297
306
  ```yaml
@@ -312,8 +321,8 @@ If you include has_many / has_one associations in the field, you can also specif
312
321
 
313
322
  #### Example
314
323
  - The following example shows fields such as `id` and `status` to be displayed.
315
- - It also displays the `customer.name_field` by including `customer` in the `belongs_to` association.
316
- - In addition, the has_many association `order_details` is included. The `product`, `amount`, `unit_price` of this `order_details` is specified as the display field.
324
+ - It also displays the `customer.name_field` by including the `customer` in the `belongs_to` association.
325
+ - In addition, the has_many association `order_details` is included. The `product`, `amount` and `unit_price` of this `order_details` are specified as the display field.
317
326
  ```yaml
318
327
  app:
319
328
  show:
@@ -344,17 +353,17 @@ Specify the form type from `kind`, `kind` can be specified as follows:
344
353
  - select
345
354
  - switch (boolean)
346
355
  - file (defined in ActiveStorage)
347
- - association_search (For association columns in belongs_to, `association_search` allows you to search and specify the related tables from the child screen)
356
+ - association_search (For association columns in belongs_to, `association_search` allows you to search and specify the related tables from the child screen.)
348
357
 
349
358
  If has_many/has_one of association is specified in the field, batch registration of related models is enabled.
350
359
 
351
360
  #### Example
352
361
  - Able to search and specify the related customer from a child screen (related to `order belongs_to customer`)
353
- - `status` allows radio button selection of Enum elements
354
- - Decorator's append($) set to `total_price` is displayed on the form
362
+ - The `status` allows radio button selection of Enum elements
363
+ - The decorator's append($) set to `total_price` is displayed on the form
355
364
  - Enable batch registration of related data, including `order_details`, which are related to has_many.
356
365
  - Display `product_id`, `amount`, `unit_price` from related `order_details` on the form
357
- - In relation to `order_detail belongs_to product`, and the related product can be searched from the child screen.
366
+ - In relation to `order_detail belongs_to product`, the related product can be searched from the child screen.
358
367
  - ADD button to add rows.
359
368
  ```yaml
360
369
  app:
@@ -378,9 +387,9 @@ app:
378
387
  ![form](./readme/form.png)
379
388
 
380
389
  ### Association search view
381
- Fields that are related to `belongs_to` can be searched and selected from the child screens for data in the related model.
390
+ Fields related to `belongs_to` can be searched and selected from the child screens for data in the related model.
382
391
 
383
- **Note: Child screen searches should be defined in the resource (YAML) of the caller. For example, in the case of `order belongs_to customer`, define the association_search in the YAML of the `customer`, not in the `order`.**
392
+ **Note: Child screen should be defined in the caller's resource (YAML). For example, in the case of `order belongs_to customer`, define the association_search in the YAML of the `customer`, not in the `order`.**
384
393
 
385
394
  The configuration is the same as for `app`.`index`. Define the necessary fields for `conditions` and `list`.
386
395
  #### Example
@@ -10,7 +10,8 @@ module Infold
10
10
 
11
11
  def setup
12
12
  resource_name = name.camelize.singularize
13
- db_schema = DbSchema.new(File.read(Rails.root.join('db/schema.rb')))
13
+ db_schema_file = Rails.root.join('db/schema.rb')
14
+ db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
14
15
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
15
16
  resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
16
17
  @writer = ControllerWriter.new(resource)
@@ -31,13 +32,8 @@ module Infold
31
32
  end
32
33
  end
33
34
 
34
- return if name.pluralize.underscore == 'admin_users'
35
- in_file = File.readlines(file).grep(/^\s+authenticated :admin_user do root/)
36
- if in_file.blank?
37
- inject_into_file file, after: "resources :admin_users" do
38
- "\n authenticated :admin_user do root :to => '#{name.pluralize.underscore}#index', as: :root end"
39
- end
40
- end
35
+ gsub_file file, "root :to => 'admin_users#index'",
36
+ "root :to => '#{name.pluralize.underscore}#index'"
41
37
  end
42
38
 
43
39
  def add_menu
@@ -10,7 +10,8 @@ module Infold
10
10
 
11
11
  def setup
12
12
  resource_name = name.camelize.singularize
13
- db_schema = DbSchema.new(File.read(Rails.root.join('db/schema.rb')))
13
+ db_schema_file = Rails.root.join('db/schema.rb')
14
+ db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
14
15
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
15
16
  @resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
16
17
  end
@@ -10,7 +10,8 @@ module Infold
10
10
 
11
11
  def setup
12
12
  resource_name = name.camelize.singularize
13
- db_schema = DbSchema.new(File.read(Rails.root.join('db/schema.rb')))
13
+ db_schema_file = Rails.root.join('db/schema.rb')
14
+ db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
14
15
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
15
16
  @resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
16
17
  end
@@ -21,10 +22,11 @@ module Infold
21
22
  end
22
23
 
23
24
  def create_association_model_file
24
- @resource.associations&.
25
- select { |as| !as.belongs_to? && as.field_group.has_association_model? }&.each do |association|
25
+ @resource.associations&.select(&:has_child?)&.each do |association|
26
+ # association_modelが未定義の場合、skip: trueで作成する
27
+ option = association.field_group.has_association_model? ? { force: true } : { skip: true }
26
28
  @writer = ModelWriter.new(association)
27
- template "model.rb", Rails.root.join("app/models/admin", "#{association.model_name(:snake)}.rb"), force: true
29
+ template "model.rb", Rails.root.join("app/models/admin", "#{association.model_name(:snake)}.rb"), **option
28
30
  end
29
31
  end
30
32
  end
@@ -10,7 +10,8 @@ module Infold
10
10
 
11
11
  def setup
12
12
  resource_name = name.camelize.singularize
13
- db_schema = DbSchema.new(File.read(Rails.root.join('db/schema.rb')))
13
+ db_schema_file = Rails.root.join('db/schema.rb')
14
+ db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
14
15
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
15
16
  resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
16
17
  @writer = SearchFormWriter.new(resource)
@@ -26,4 +26,4 @@ en:
26
26
  db_synced: DB sync is complete
27
27
  badge:
28
28
  required: Required
29
- no_data: There is no data
29
+ no_data: Not found
@@ -9,5 +9,6 @@ end
9
9
 
10
10
  namespace 'admin' do
11
11
  resources :admin_users
12
+ authenticated :admin_user do root :to => 'admin_users#index', as: :root end
12
13
  devise_scope :admin_user do root :to => 'admin_users/sessions#new', as: :unauthenticated_root end
13
14
  end
@@ -1,29 +1,94 @@
1
1
  <%# encoding: utf-8 -%>
2
2
  model:
3
- validate:
4
- decorator:
5
- association:
6
- enum:
7
- active_storage:
3
+ # # Define validation here
4
+ # validate:
5
+ # amount: presence
6
+ # price:
7
+ # - presence
8
+ # - numericality:
9
+ # greater_than_or_equal_to: 0
10
+ # # Define Enum here
11
+ # enum:
12
+ # status:
13
+ # ordered:
14
+ # value: 1
15
+ # color: blue
16
+ # charged:
17
+ # value: 2
18
+ # color: pink
19
+ # # Define decorator here
20
+ # decorator:
21
+ # price:
22
+ # prepend: $
23
+ # digit: true
24
+ # # Define association here
25
+ # association:
26
+ # customer:
27
+ # kind: belongs_to
28
+ # name_field: name
29
+ # order_details:
30
+ # kind: has_many
31
+ # dependent: destroy
32
+ # # If the child model on the has_many side also needs to be configured, define it here.
33
+ # model:
34
+ # validate:
35
+ # enum:
36
+ # decorator:
37
+ # association:
38
+ # # Define active_storage here
39
+ # active_storage:
40
+ # photo:
41
+ # kind: image
8
42
  app:
9
- title: <%= @name.pluralize.underscore.gsub('_', ' ').upcase %>
10
- index:
11
- conditions:
12
- - id:
13
- sign: eq
14
- list:
15
- fields:
16
- default_order:
17
- csv:
18
- fields:
19
- show:
20
- fields:
21
- form:
22
- fields:
23
- association_search:
24
- conditions:
25
- - id:
26
- sign: eq
27
- list:
28
- fields:
29
- default_order:
43
+ # title: <%= @name.pluralize.underscore.gsub('_', ' ').upcase %>
44
+ # # index view settings (search condition, list and csv)
45
+ # index:
46
+ # conditions:
47
+ # - id:
48
+ # sign: eq
49
+ # - status:
50
+ # sign: any
51
+ # form_kind: checkbox
52
+ # list:
53
+ # fields:
54
+ # - id
55
+ # - customer
56
+ # - status
57
+ # default_order:
58
+ # field: id
59
+ # kind: desc
60
+ # csv:
61
+ # # If fields is empty, all fields are covered. (The show view is the same)
62
+ # fields:
63
+ # # show view settings
64
+ # show:
65
+ # fields:
66
+ # - id
67
+ # - customer
68
+ # - order_details:
69
+ # fields:
70
+ # - product
71
+ # - amount
72
+ # # form view settings
73
+ # form:
74
+ # fields:
75
+ # - status:
76
+ # kind: radio
77
+ # - customer:
78
+ # kind: association_search
79
+ # #Bulk registration of has_many
80
+ # - order_details:
81
+ # kind: association
82
+ # fields:
83
+ # - product
84
+ # kind: association_search
85
+ # - amount
86
+ # # Child screen search for related models
87
+ # association_search:
88
+ # conditions:
89
+ # - id:
90
+ # sign: eq
91
+ # list:
92
+ # fields:
93
+ # - id
94
+ # - title
@@ -3,13 +3,13 @@
3
3
  <%- @writer.form_fields.each do |field| -%>
4
4
  <%- if field.form_element.kind_has_association? -%>
5
5
  .card.mb-3{ data: {controller: 'nested-form'} }
6
- .card-header.py-2
6
+ .card-header
7
7
  %div
8
- %h3.text-muted.mb-0= Admin::<%= field.association.model_name %>.human_attribute_name(:<%= field.name %>)
8
+ %h4.text-muted.mb-0= Admin::<%= field.association.model_name %>.model_name.human
9
9
  = render Admin::InvalidMessageComponent.new(form, :<%= field.name %>)
10
10
  %template{ data: { nested_form_target: 'template' } }
11
11
  = form.fields_for :<%= field.name %>, Admin::<%= field.association.model_name %>.new, child_index: 'NEW_RECORD' do |nested_form|
12
- = render 'form_<%= field.name(:single) %>', purchase: form.object, form: nested_form
12
+ = render 'form_<%= field.name(:single) %>', form: nested_form
13
13
  .table-responsive
14
14
  %table.table.nested_form_table.card-table
15
15
  %thead
@@ -3,8 +3,8 @@
3
3
  <%- @writer.show_fields.each do |field| -%>
4
4
  <%- if field.show_element.kind_association? && !field.association.belongs_to? -%>
5
5
  .card.mb-3
6
- .card-header.py-2
7
- %h3.text-muted.mb-0= <%= @writer.resource_name(:snake) %>.class.human_attribute_name(:<%= field.name %>)
6
+ .card-header
7
+ %h4.text-muted.mb-0= Admin::<%= field.association.model_name %>.model_name.human
8
8
  - if <%= @writer.resource_name(:snake) %>.<%= field.name %>.blank?
9
9
  .card-body
10
10
  .alert= t('infold.no_data')
@@ -11,7 +11,8 @@ module Infold
11
11
 
12
12
  def setup
13
13
  resource_name = name.camelize.singularize
14
- db_schema = DbSchema.new(File.read(Rails.root.join('db/schema.rb')))
14
+ db_schema_file = Rails.root.join('db/schema.rb')
15
+ db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
15
16
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
16
17
  resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
17
18
  @writer = FormWriter.new(resource)
@@ -39,7 +40,7 @@ module Infold
39
40
 
40
41
  def association_form_file
41
42
  @writer.form_fields.each do |field|
42
- if field.association&.has_many? || field.association&.has_one?
43
+ if field.association&.has_child?
43
44
  @association_field = field
44
45
  template "views/_form_association.haml",
45
46
  Rails.root.join("app/views/admin/#{name.underscore.pluralize}/_form_#{field.name(:single)}.html.haml"), force: true
@@ -11,7 +11,8 @@ module Infold
11
11
 
12
12
  def setup
13
13
  resource_name = name.camelize.singularize
14
- db_schema = DbSchema.new(File.read(Rails.root.join('db/schema.rb')))
14
+ db_schema_file = Rails.root.join('db/schema.rb')
15
+ db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
15
16
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
16
17
  resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
17
18
  @writer = IndexWriter.new(resource)
@@ -11,7 +11,8 @@ module Infold
11
11
 
12
12
  def setup
13
13
  resource_name = name.camelize.singularize
14
- db_schema = DbSchema.new(File.read(Rails.root.join('db/schema.rb')))
14
+ db_schema_file = Rails.root.join('db/schema.rb')
15
+ db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
15
16
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
16
17
  resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
17
18
  @writer = ShowWriter.new(resource)
@@ -5,7 +5,8 @@ module Infold
5
5
 
6
6
  def initialize(content=nil)
7
7
  @tables = []
8
- content&.split("\n").each.each do |row|
8
+ return unless content
9
+ content.split("\n").each.each do |row|
9
10
  row = row.strip
10
11
  if row.start_with?('create_table')
11
12
  table_name = row.split('"').second.strip
@@ -16,7 +16,7 @@ module Infold
16
16
  end
17
17
 
18
18
  def find_or_initialize_field(field_name)
19
- find { |field| field.name == field_name || field.association&.name == field_name } ||
19
+ find { |field| field.association&.name == field_name || field.name == field_name } ||
20
20
  (@fields << Field.new(field_name)).last
21
21
  end
22
22
 
@@ -56,14 +56,24 @@ module Infold
56
56
  end
57
57
 
58
58
  def condition_fields(kind=nil)
59
- case kind.to_s
60
- when 'index'
61
- select { |f| f.search_conditions.find(&:in_index?).present? }
62
- when 'association_search'
63
- select { |f| f.search_conditions.find(&:in_association_search?).present? }
64
- else
65
- select { |f| f.search_conditions.present? }
59
+ fields =
60
+ case kind.to_s
61
+ when 'index'
62
+ select { |f| f.search_conditions.find(&:in_index?).present? }
63
+ when 'association_search'
64
+ select { |f| f.search_conditions.find(&:in_association_search?).present? }
65
+ else
66
+ select { |f| f.search_conditions.present? }
67
+ end
68
+ if fields.blank?
69
+ # 条件が未設定の場合、idを対象とする
70
+ id_field = find_or_initialize_field(:id)
71
+ id_field.add_search_condition(kind || :index,
72
+ sign: 'eq',
73
+ form_kind: :text)
74
+ fields = [id_field]
66
75
  end
76
+ fields
67
77
  end
68
78
 
69
79
  def conditions(kind=nil)
@@ -53,6 +53,10 @@ module Infold
53
53
  kind.to_sym == :has_one
54
54
  end
55
55
 
56
+ def has_child?
57
+ !belongs_to?
58
+ end
59
+
56
60
  def model_name(*attr)
57
61
  name = class_name.presence || self.name.singularize.camelize
58
62
  name = name.underscore if attr.include?(:snake)
@@ -36,12 +36,18 @@ module Infold
36
36
  end
37
37
 
38
38
  def form_kind
39
- if @form_kind == 'association_search'
39
+ if @form_kind.to_s == 'association_search'
40
40
  if field.association&.belongs_to?
41
41
  :association_search
42
42
  else
43
43
  :text
44
44
  end
45
+ elsif @form_kind.to_s == 'select'
46
+ if field.association&.belongs_to? || field.enum.present?
47
+ :select
48
+ else
49
+ :text
50
+ end
45
51
  elsif kind_datetime?
46
52
  :datetime
47
53
  elsif kind_file?
@@ -1,3 +1,3 @@
1
1
  module Infold
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -10,7 +10,7 @@ module Infold
10
10
  @db_schema = db_schema
11
11
  field_group = FieldGroup.new(db_schema.table(resource_name))
12
12
  resource = Resource.new(resource_name)
13
- yaml = yaml.with_indifferent_access
13
+ yaml = (yaml || {}).with_indifferent_access
14
14
  model = yaml.dig('model') || {}
15
15
  app = yaml.dig('app') || {}
16
16
  assign_associations( field_group, model.dig(:association))
@@ -30,7 +30,8 @@ module Infold
30
30
  field = field_group.find_or_initialize_field(default_order.dig(:field))
31
31
  resource.default_order = DefaultOrder.new(self, field, default_order.dig(:kind))
32
32
  end
33
- resource.app_title = app.dig(:title)
33
+ resource.app_title = app.dig(:title).presence ||
34
+ resource_name.pluralize.underscore.gsub('_', ' ').upcase
34
35
  resource
35
36
  end
36
37
 
@@ -232,7 +233,7 @@ module Infold
232
233
  form_element.add_association_fields(
233
234
  association_field,
234
235
  seq: association_seq,
235
- form_kind: association_field_config.dig(association_field.name, :kind))
236
+ form_kind: association_field_config.dig(association_field_config.keys[0], :kind))
236
237
  end
237
238
  end
238
239
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yamataka22
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-01 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails