tybo 0.0.32 → 0.0.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/forms/search_date_input_component.html.erb +16 -0
- data/app/components/forms/search_date_input_component.rb +19 -0
- data/app/components/forms/search_input_component.html.erb +1 -1
- data/app/components/index_header_component.html.erb +1 -1
- data/app/components/index_header_export_component.rb +0 -1
- data/app/components/tables/td_component.html.erb +1 -1
- data/app/views/layouts/devise_admin.html.erb +1 -1
- data/lib/generators/bo/bo_generator.rb +14 -5
- data/lib/generators/bo/templates/_form.html.erb +3 -4
- data/lib/generators/bo/templates/_search_bar.html.erb +7 -19
- data/lib/generators/bo/templates/_table.html.erb +2 -2
- data/lib/generators/bo/templates/index.html.erb +3 -3
- data/lib/generators/bo/templates/item.html.erb +2 -5
- data/lib/generators/bo/utils/files/fr.json +19 -17
- data/lib/generators/bo/utils/translations.rb +7 -5
- data/lib/tybo/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f1a040c49efef7ae924cde3a0bc4cd77622fc8920bd8d376d891c015859c4fa
|
4
|
+
data.tar.gz: 2236e0ffe3cf5ff30613aa801c00f341abd8786872ba92ed379c1f196d167869
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293a5d9bd5d672671cf4f8cee78a6c641df9bf105e7b262221bfcac4bec6c0961d7b3e982061bbef2e7d5373d69deb3ac10b2496ec43f2e2df6c80aee8df732f
|
7
|
+
data.tar.gz: a992ebe8fd5f0bc3bedb135402c126db152f33bcc21a26503398ba05f8320b9ca6748c442d40b7e514685213b75d82236d255c4d12181cf254e2fb9ff77a4ec8
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="sm:grid sm:grid-cols-12 sm:items-start sm:gap-4 pt-5">
|
2
|
+
<div class="mt-1 sm:col-span-4 sm:mt-">
|
3
|
+
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
|
4
|
+
<%= @label %>
|
5
|
+
</label>
|
6
|
+
</div>
|
7
|
+
<div class="mt-1 sm:col-span-3 sm:mt-0">
|
8
|
+
<%= @form.date_field @from_field, data: { action: "input->search-form#search" }, class: "rounded-md border-gray-300 shadow-sm focus:border-tybo-500 focus:ring-tybo-500 sm:text-sm" %>
|
9
|
+
</div>
|
10
|
+
<div class="mt-1 sm:col-span-2 text-center">
|
11
|
+
to
|
12
|
+
</div>
|
13
|
+
<div class="mt-1 sm:col-span-3 sm:mt-0">
|
14
|
+
<%= @form.date_field @to_field, data: { action: "input->search-form#search" }, class: "rounded-md border-gray-300 shadow-sm focus:border-tybo-500 focus:ring-tybo-500 sm:text-sm" %>
|
15
|
+
</div>
|
16
|
+
</div>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Forms::SearchDateInputComponent < ViewComponent::Base
|
4
|
+
def initialize(label:, form:, field:)
|
5
|
+
@label = label
|
6
|
+
@field = field
|
7
|
+
@form = form
|
8
|
+
@from_field = from_field
|
9
|
+
@to_field = to_field
|
10
|
+
end
|
11
|
+
|
12
|
+
def from_field
|
13
|
+
"#{@field}_from_date".to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_field
|
17
|
+
"#{@field}_to_date".to_sym
|
18
|
+
end
|
19
|
+
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
6
|
<%= csrf_meta_tags %>
|
7
7
|
<%= csp_meta_tag %>
|
8
|
-
<%= stylesheet_link_tag
|
8
|
+
<%= stylesheet_link_tag 'tailwind', 'inter-font', 'data-turbo-track': 'reload' %>
|
9
9
|
<%= javascript_importmap_tags %>
|
10
10
|
</head>
|
11
11
|
<body class="h-full">
|
@@ -8,6 +8,7 @@ class BoGenerator < Rails::Generators::NamedBase
|
|
8
8
|
class_option :namespace, type: :string, default: 'administrators'
|
9
9
|
|
10
10
|
def create_bo_file
|
11
|
+
check_model_existence
|
11
12
|
# Template method
|
12
13
|
# First argument is the name of the template
|
13
14
|
# Second argument is where to create the resulting file. In this case, app/bo/my_bo.rb
|
@@ -20,27 +21,35 @@ class BoGenerator < Rails::Generators::NamedBase
|
|
20
21
|
template 'show.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/show.html.erb")
|
21
22
|
template 'controller.rb', File.join("app/controllers/#{options[:namespace]}", "#{plural_name}_controller.rb")
|
22
23
|
template 'policy.rb', File.join("app/policies/bo/#{options[:namespace]}", "#{file_name.underscore}_policy.rb")
|
23
|
-
unless File.
|
24
|
+
unless File.exist?("app/policies/bo/#{options[:namespace]}_policy.rb")
|
24
25
|
template 'namespace_policy.rb', "app/policies/bo/#{options[:namespace]}_policy.rb"
|
25
26
|
end
|
26
27
|
create_translations
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
30
|
def add_link_to_side_bar
|
31
|
-
inject_into_file "app/views/#{options[:namespace]}/layouts/_side_bar.html.erb", before: " <%= sidebar.with_current_user_card(user: current_#{options[:namespace].singularize}) %>\n" do
|
31
|
+
inject_into_file "app/views/#{options[:namespace]}/layouts/_side_bar.html.erb", before: " <%= sidebar.with_current_user_card(user: current_#{options[:namespace].singularize}) %>\n" do
|
32
32
|
" <%= sidebar.with_item(path: #{options[:namespace]}_#{plural_name}_path, icon: Icons::UsersComponent, label: I18n.t('bo.#{file_name}.others').capitalize) %>\n"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
def create_routes
|
37
|
-
|
38
|
-
|
37
|
+
rails_routes = Rails.application.routes.named_routes.names.map(&:to_s)
|
38
|
+
return if rails_routes.any?("#{options[:namespace]}_#{plural_name}")
|
39
|
+
|
40
|
+
inject_into_file 'config/routes.rb', after: " namespace :#{options[:namespace]} do\n" do
|
41
|
+
" resources :#{plural_name}\n"
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
42
45
|
private
|
43
46
|
|
47
|
+
def check_model_existence
|
48
|
+
return if Object.const_defined?(class_name) && Object.const_get(class_name).ancestors.include?(ActiveRecord::Base)
|
49
|
+
|
50
|
+
raise ArgumentError, "The model #{class_name} does not exist or is not an ActiveRecord model. Ensure the model exists before running the generator."
|
51
|
+
end
|
52
|
+
|
44
53
|
def bo_model
|
45
54
|
class_name.constantize
|
46
55
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<%%= simple_form_for [:<%= options[:namespace] %>, <%= class_name.underscore %>], html: { class: "<%= class_name.underscore %> form" } do |f| %>
|
2
|
-
<!-- Model columns -->
|
2
|
+
<!-- Model columns -->
|
3
3
|
<%- bo_model.column_names.each do |column| -%>
|
4
4
|
<%- next if excluded_columns.include?(column.to_sym) || bo_model.reflect_on_all_associations.map(&:foreign_key).include?(column) -%>
|
5
|
-
<%%= f.input :<%= column %>,label: I18n.t('bo.<%= class_name.underscore %>.attributes.<%= column %>')
|
5
|
+
<%%= f.input :<%= column %>,label: I18n.t('bo.<%= class_name.underscore %>.attributes.<%= column %>') %>
|
6
6
|
<%- end -%>
|
7
7
|
<!-- belongs_to Associations -->
|
8
8
|
<%- belongs_to_assoc.each do |association| -%>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
<%%= I18n.t('bo.<%= class_name.underscore %>.attributes.<%=- association.name.to_s.singularize.to_s.remove('rich_text_') -%>') %>
|
15
15
|
</label>
|
16
16
|
<%%= f.rich_text_area :<%= association.name.to_s.singularize.to_s.remove('rich_text_')%> %>
|
17
|
-
|
17
|
+
<%- end -%>
|
18
18
|
<!-- File Associations -->
|
19
19
|
<%- storage_assoc.each do |association| -%>
|
20
20
|
<%%= render(Input::FileComponent.new(item: <%= class_name.underscore %>, field: '<%= association.name.to_s.singularize.to_s.remove('_attachment') %>', form: f)) %>
|
@@ -40,7 +40,6 @@
|
|
40
40
|
multiple: true,
|
41
41
|
data: { controller: 'ts--select' } %>
|
42
42
|
<%% end %>
|
43
|
-
|
44
43
|
<%- end -%>
|
45
44
|
<%%= render(Forms::SubmitButtonComponent.new) %>
|
46
45
|
<%% end %>
|
@@ -9,8 +9,8 @@
|
|
9
9
|
</div>
|
10
10
|
<div data-dropdown-target="menu" class="drop-shadow-md hidden absolute py-5 px-5 left-0 z-10 mt-2 w-[40rem] origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="menu-button" tabindex="-1">
|
11
11
|
<%%= search_form_for [:<%=options[:namespace].underscore %>, @q], method: :post, class: "", data: { controller: "search-form", search_form_target: "form", turbo_frame: '<%=class_name.underscore.pluralize%>' } do |f| %>
|
12
|
-
<%- bo_model.columns.group_by(&:type).each do |type| -%>
|
13
12
|
<!-- columns -->
|
13
|
+
<%- bo_model.columns.group_by(&:type).each do |type| -%>
|
14
14
|
<%- type.second.sort_by(&:type).each do |col| -%>
|
15
15
|
<%- next if bo_model.reflect_on_all_associations.map(&:foreign_key).include?(col.name) -%>
|
16
16
|
<%- if col.type == :string || col.type == :text -%>
|
@@ -50,22 +50,11 @@
|
|
50
50
|
</div>
|
51
51
|
</div>
|
52
52
|
<%- elsif col.type == :datetime || col.type == :date -%>
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
</div>
|
59
|
-
<div class="mt-1 sm:col-span-3 sm:mt-0">
|
60
|
-
<%%= f.date_field :<%= col.name %>_from_date, data: { action: "input->search-form#search" }, class: "rounded-md border-gray-300 shadow-sm focus:border-tybo-500 focus:ring-tybo-500 sm:text-sm" %>
|
61
|
-
</div>
|
62
|
-
<div class="mt-1 sm:col-span-2 text-center">
|
63
|
-
to
|
64
|
-
</div>
|
65
|
-
<div class="mt-1 sm:col-span-3 sm:mt-0">
|
66
|
-
<%%= f.date_field :<%= col.name %>_to_date, data: { action: "input->search-form#search" }, class: "rounded-md border-gray-300 shadow-sm focus:border-tybo-500 focus:ring-tybo-500 sm:text-sm" %>
|
67
|
-
</div>
|
68
|
-
</div>
|
53
|
+
<%%= render(Forms::SearchDateInputComponent.new(
|
54
|
+
label: I18n.t('bo.<%= class_name.underscore %>.attributes.<%= col.name %>'),
|
55
|
+
form: f,
|
56
|
+
field: '<%= col.name %>')
|
57
|
+
) %>
|
69
58
|
<%- end -%>
|
70
59
|
<%- end -%>
|
71
60
|
<%- end -%>
|
@@ -73,7 +62,7 @@
|
|
73
62
|
<%- belongs_to_assoc.each do |association| -%>
|
74
63
|
<div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 pt-5">
|
75
64
|
<label for="<%=association.name%>" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
|
76
|
-
<%%=I18n.t('bo.<%=association.klass.name.underscore%>.one')%>
|
65
|
+
<%%= I18n.t('bo.<%=association.klass.name.underscore%>.one') %>
|
77
66
|
</label>
|
78
67
|
<div class="mt-1 sm:col-span-2 sm:mt-0">
|
79
68
|
<%%= f.select :<%= association.foreign_key %>_eq, <%=association.klass.name.constantize%>.all.map { |value| [value.<%=bo_model_title(association.class_name.constantize)%>, value.id] }, { include_blank: true }, { class: "block w-full rounded-md border-gray-300 shadow-sm focus:border-tybo-500 focus:ring-tybo-500 sm:text-sm", data: { action: "input->search-form#search" } } %>
|
@@ -83,4 +72,3 @@
|
|
83
72
|
<%% end %>
|
84
73
|
</div>
|
85
74
|
</div>
|
86
|
-
|
@@ -13,13 +13,13 @@
|
|
13
13
|
<%- end -%>
|
14
14
|
<%%= tr.with_td do %>
|
15
15
|
<%%= link_to <%="#{options[:namespace]}_#{class_name.underscore}_path(#{class_name.underscore})"%>, class: "text-tybo-600 hover:text-tybo-900" do %>
|
16
|
-
|
16
|
+
<%%= I18n.t('bo.details') %>
|
17
17
|
<%% end %>
|
18
18
|
<%% end %>
|
19
19
|
<%%= tr.with_td do %>
|
20
20
|
<%%= link_to <%="#{options[:namespace]}_#{class_name.underscore}_path(#{class_name.underscore})"%>,
|
21
21
|
class: "text-tybo-600 hover:text-tybo-900",
|
22
|
-
data: {turbo_method: :delete, turbo_confirm:
|
22
|
+
data: { turbo_method: :delete, turbo_confirm: I18n.t('bo.confirm_delete') } do %>
|
23
23
|
<%%= render(Icons::TrashComponent.new) %>
|
24
24
|
<%% end %>
|
25
25
|
<%% end %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%%= render(IndexComponent.new) do |index| %>
|
2
|
-
<!-- Header -->
|
2
|
+
<!-- Header -->
|
3
3
|
<%%= index.with_header(
|
4
4
|
title: I18n.t('bo.<%= class_name.underscore %>.others').capitalize,
|
5
5
|
subtitle: I18n.t('bo.<%= class_name.underscore %>.subtitle').capitalize,
|
@@ -7,9 +7,9 @@
|
|
7
7
|
<%%= header.with_add_button(path: <%="new_#{options[:namespace]}_#{class_name.underscore}_path" %>) %>
|
8
8
|
<%% end %>
|
9
9
|
|
10
|
-
<!-- Search Bar -->
|
10
|
+
<!-- Search Bar -->
|
11
11
|
<%%= render('search_bar') %>
|
12
|
-
<!-- Table -->
|
12
|
+
<!-- Table -->
|
13
13
|
<%%= turbo_frame_tag "<%= class_name.underscore.pluralize %>", class: "shadow overflow-hidden rounded border-b border-gray-200" do %>
|
14
14
|
<%%= render('table') %>
|
15
15
|
<div class="py-2">
|
@@ -1,7 +1,5 @@
|
|
1
1
|
<%%= render(FormComponent.new(item: <%= class_name.underscore %>)) do |form| %>
|
2
|
-
<%%
|
3
|
-
current_page = if <%= class_name.underscore
|
4
|
-
%>.persisted?
|
2
|
+
<%% current_page = if <%= class_name.underscore %>.persisted?
|
5
3
|
{ label: I18n.t('bo.show'), path: <%= "#{options[:namespace]}_#{class_name.underscore}_path(#{class_name.underscore})"%> }
|
6
4
|
else
|
7
5
|
{ label: I18n.t('bo.<%= class_name.underscore %>.new').capitalize, path: <%= "new_#{options[:namespace]}_#{class_name.underscore}_path" %> }
|
@@ -10,8 +8,7 @@
|
|
10
8
|
form.with_breadcrumb([
|
11
9
|
{ label: I18n.t('bo.<%= class_name.underscore %>.others').capitalize, path: <%= "#{options[:namespace]}_#{class_name.pluralize.underscore}_path"%> },
|
12
10
|
current_page
|
13
|
-
])
|
14
|
-
%>
|
11
|
+
]) %>
|
15
12
|
<br>
|
16
13
|
<%%= render "form", <%= class_name.underscore %>: @<%= class_name.underscore %> %>
|
17
14
|
<%% end %>
|
@@ -1,19 +1,21 @@
|
|
1
1
|
{
|
2
|
-
"id": "
|
3
|
-
"email": "
|
4
|
-
"password": "
|
5
|
-
"created_at": "
|
6
|
-
"updated_at": "
|
7
|
-
"title": "
|
8
|
-
"content": "
|
9
|
-
"description": "
|
10
|
-
"name": "
|
11
|
-
"position": "
|
12
|
-
"first_name": "
|
13
|
-
"last_name": "
|
14
|
-
"full_name": "
|
15
|
-
"updated": "
|
16
|
-
"created": "
|
17
|
-
"destroyed": "
|
18
|
-
"filters": "
|
2
|
+
"id": "Identifiant",
|
3
|
+
"email": "Email",
|
4
|
+
"password": "Mot de passe",
|
5
|
+
"created_at": "Date de création",
|
6
|
+
"updated_at": "Date de modification",
|
7
|
+
"title": "Titre",
|
8
|
+
"content": "Contenu",
|
9
|
+
"description": "Description",
|
10
|
+
"name": "Nom",
|
11
|
+
"position": "Position",
|
12
|
+
"first_name": "Prénom",
|
13
|
+
"last_name": "Nom",
|
14
|
+
"full_name": "Nom complet",
|
15
|
+
"updated": "Modification effectuée",
|
16
|
+
"created": "Création effectuée",
|
17
|
+
"destroyed": "Suppression effectuée",
|
18
|
+
"filters": "Filtres",
|
19
|
+
"confirm_delete": "Êtes-vous sûr ?",
|
20
|
+
"details": "Détails"
|
19
21
|
}
|
@@ -8,6 +8,8 @@ def create_translations
|
|
8
8
|
local => {
|
9
9
|
'bo' => {
|
10
10
|
'filters' => find_existing_translation('filters', local),
|
11
|
+
'details' => find_existing_translation('details', local),
|
12
|
+
'confirm_delete' => find_existing_translation('confirm_delete', local),
|
11
13
|
'record' => {
|
12
14
|
'created' => find_existing_translation('created', local),
|
13
15
|
'updated' => find_existing_translation('updated', local),
|
@@ -20,21 +22,21 @@ def create_translations
|
|
20
22
|
|
21
23
|
yaml_string = File.open locale_file
|
22
24
|
data = YAML.load yaml_string
|
23
|
-
data[local]['bo'][file_name.underscore
|
25
|
+
data[local]['bo'][file_name.underscore] = {
|
24
26
|
'one' => find_existing_translation(bo_model.to_s.downcase, local),
|
25
27
|
'others' => find_existing_translation(bo_model.to_s.pluralize.downcase, local),
|
26
28
|
'subtitle' => find_existing_translation("list of #{bo_model.to_s.pluralize.downcase}", local),
|
27
|
-
'attributes' => model_attributes(local)
|
29
|
+
'attributes' => model_attributes(data, local)
|
28
30
|
}
|
29
31
|
output = YAML.dump data
|
30
32
|
File.write(locale_file, output)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
def model_attributes(local)
|
35
|
-
hash = {}
|
36
|
+
def model_attributes(data, local)
|
37
|
+
hash = data.dig(local, 'bo', file_name.underscore, 'attributes') || {}
|
36
38
|
model_columns.each do |col|
|
37
|
-
hash[col.to_s]
|
39
|
+
hash[col.to_s] ||= find_existing_translation(col, local)
|
38
40
|
end
|
39
41
|
hash
|
40
42
|
end
|
data/lib/tybo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tybo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Delpierre
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-03-
|
12
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -153,6 +153,8 @@ files:
|
|
153
153
|
- app/components/forms/has_many_form_component.rb
|
154
154
|
- app/components/forms/has_one_form_component.html.erb
|
155
155
|
- app/components/forms/has_one_form_component.rb
|
156
|
+
- app/components/forms/search_date_input_component.html.erb
|
157
|
+
- app/components/forms/search_date_input_component.rb
|
156
158
|
- app/components/forms/search_input_component.html.erb
|
157
159
|
- app/components/forms/search_input_component.rb
|
158
160
|
- app/components/forms/submit_button_component.html.erb
|