tybo 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d93a3e02b0858c49f45215e8457294b3dbe7a70e66c9cdce463324a86cc65414
4
- data.tar.gz: '09ca1b2fadff5a2bc2d8c0c32192bd506618916c9cb734341831b2e3478b1d37'
3
+ metadata.gz: daa02ecc2547566ac774ab1e182054ff7a9cfbaa7c45561338e2b706536eafe8
4
+ data.tar.gz: 8f506d40fe83c7856efceb1f1b5eb55ebdee15a5769ae4e59332850f2d18bfc7
5
5
  SHA512:
6
- metadata.gz: 74f8a9aaafeeea63b8a26d8336a9d77d7d945e04c106b3e2703c1d4900e1d0a0f7a11398aa87b2ee0e948c86cd8c24959737d3263eff66360baca567a61a9ce0
7
- data.tar.gz: 237dc58da09eee1ce80bd2295778acd88cc715089726e067755b9b6340530f58dda6c84b707fc7115b450a8f5a4e81733e22da099492470f4975b18b548c240f
6
+ metadata.gz: 0dfda4edfd7ed96a710117404e4247ab4a99b65af0da16b9ed71416e142c1c3ce01adff087dd463c474751d6d2aa07be437d02267ab2abc7d3af03df2ebbdb15
7
+ data.tar.gz: 5fef87ba89d3bb1deb46b6848239e4acfa717b60cbde1b714c75112cdb84546dd35913be7c349257e3c637a86bba5e86fe434b0a6c0fe25b134d147f32198dda
@@ -0,0 +1,5 @@
1
+ <!-- has_many Associations -->
2
+ <div class="my-5 select">
3
+ <label class="block text-sm font-medium text-gray-700 string optional text-sm font-medium text-gray-600" for="office_user_ids"><%= @title %></label>
4
+ <%= content %>
5
+ </div>
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Forms
3
+ class HasManyFormComponent < ViewComponent::Base
4
+ def initialize(title:)
5
+ @title = title
6
+ end
7
+ end
8
+ end
@@ -6,6 +6,7 @@ class BoGenerator < Rails::Generators::NamedBase
6
6
 
7
7
  check_class_collision suffix: 'bo'
8
8
  class_option :namespace, type: :string, default: 'administrators'
9
+
9
10
  def create_bo_file
10
11
  # Template method
11
12
  # First argument is the name of the template
@@ -21,12 +22,11 @@ class BoGenerator < Rails::Generators::NamedBase
21
22
  create_translations
22
23
  end
23
24
 
24
- def bo_model
25
- class_name.constantize
26
- end
27
25
 
28
- def plural_name
29
- file_name.pluralize
26
+ def add_link_to_side_bar
27
+ 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
28
+ " <%= sidebar.with_item(path: #{options[:namespace]}_#{plural_name}_path, icon: Icons::UsersComponent, label: I18n.t('bo.#{file_name}.others').capitalize) %>\n"
29
+ end
30
30
  end
31
31
 
32
32
  def create_routes
@@ -35,10 +35,24 @@ class BoGenerator < Rails::Generators::NamedBase
35
35
  end
36
36
  end
37
37
 
38
+ private
39
+
40
+ def bo_model
41
+ class_name.constantize
42
+ end
43
+
44
+ def plural_name
45
+ file_name.pluralize
46
+ end
47
+
38
48
  def model_columns
39
49
  bo_model.column_names.map(&:to_sym)
40
50
  end
41
51
 
52
+ def simple_form_conflict_keywords
53
+ %w[country country_code]
54
+ end
55
+
42
56
  def bo_model_title(model=nil)
43
57
  return unless model
44
58
 
@@ -61,6 +75,10 @@ class BoGenerator < Rails::Generators::NamedBase
61
75
  has_many_assoc&.map do |association|
62
76
  params["#{association.name.to_s.singularize}_ids".to_sym] = []
63
77
  end
78
+ has_one_assoc&.map do |association|
79
+ attributes = association.klass.column_names.map(&:to_sym).delete_if {|attr| excluded_columns.include?(attr)}
80
+ params["#{association.name.to_s.singularize}_attributes".to_sym] = attributes
81
+ end
64
82
  params
65
83
  end
66
84
 
@@ -80,9 +98,4 @@ class BoGenerator < Rails::Generators::NamedBase
80
98
  model_columns - excluded_columns
81
99
  end
82
100
 
83
- def add_link_to_side_bar
84
- 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
85
- " <%= sidebar.with_item(path: #{options[:namespace]}_#{plural_name}_path, icon: Icons::UsersComponent, label: I18n.t('bo.#{file_name}.others').capitalize) %>\n"
86
- end
87
- end
88
101
  end
@@ -17,24 +17,24 @@
17
17
  <%%= f.simple_fields_for :<%= association.name.to_s %> do |<%= association.name.to_s %>_form| %>
18
18
  <%- association.klass.column_names.each do |column| -%>
19
19
  <%- next if excluded_columns.include?(column.to_sym) || bo_model.reflect_on_all_associations.map(&:foreign_key).include?(column) -%>
20
- <%- simple_form_alias = %w[country country_code].include?(column) ? ',as: :string' : nil -%>
20
+ <%- simple_form_alias = simple_form_conflict_keywords.include?(column) ? ',as: :string' : nil -%>
21
21
  <%%= <%= association.name.to_s %>_form.input :<%= column %> <%= simple_form_alias %> %>
22
22
  <%- end -%>
23
- <%% end %>
23
+ <%% end %>
24
24
  <%% end %>
25
+
25
26
  <%- end -%>
26
27
  <%- end -%>
27
-
28
28
  <!-- has_many Associations -->
29
29
  <%- has_many_assoc.each do |association| -%>
30
- <div class="my-5 select">
31
- <label class="block text-sm font-medium text-gray-700 string optional text-sm font-medium text-gray-600" for="<%= "#{class_name.underscore}_#{association.name.to_s.singularize}_ids" %>"><%= association.name.to_s.singularize%></label>
30
+ <%%= render(Forms::HasManyFormComponent.new(title: I18n.t('bo.<%= association.name.to_s.singularize%>.others') )) do %>
32
31
  <%%= f.select :<%= "#{association.name.to_s.singularize}_ids" %>,
33
- <%= association.klass.name %>.all.map { |item| [item.<%=bo_model_title(association.klass.name.constantize)%>, item.id] },
34
- { include_blank: true },
35
- multiple: true,
36
- data: { controller: 'ts--select' } %>
37
- </div>
32
+ <%= association.klass.name %>.all.map { |item| [item.<%=bo_model_title(association.klass.name.constantize)%>, item.id] },
33
+ { include_blank: true },
34
+ multiple: true,
35
+ data: { controller: 'ts--select' } %>
36
+ <%% end %>
37
+
38
38
  <%- end -%>
39
39
  <%%= render(Forms::SubmitButtonComponent.new) %>
40
40
  <%% end %>
@@ -1,4 +1,4 @@
1
- <div class="relative inline-block text-left" data-controller="dropdown">
1
+ <div class="relative mt-3 inline-block text-left" data-controller="dropdown">
2
2
  <div>
3
3
  <button data-action="click->dropdown#toggle click@window->dropdown#hide" type="button" class="inline-flex w-full justify-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none " id="menu-button" aria-expanded="true" aria-haspopup="true">
4
4
  <%%= I18n.t('bo.filters') %>
@@ -9,26 +9,34 @@ module <%= options[:namespace].camelize %>
9
9
  @pagy, @<%= class_name.pluralize.underscore %> = pagy(@q.result(distinct: true))
10
10
  end
11
11
 
12
- def show; end
12
+ def show
13
+ <%- has_one_assoc.each do |association| -%>
14
+ <%- next if association.options[:class_name] == "ActionText::RichText" -%>
15
+ @<%= class_name.underscore %>.build_<%= association.name %> if @<%= class_name.underscore %>.<%= association.name %>.nil?
16
+ <%- end -%>
17
+ end
13
18
 
14
19
  def new
15
20
  @<%= class_name.underscore %> = <%= class_name %>.new
21
+ <%- has_one_assoc.each do |association| -%>
22
+ <%- next if association.options[:class_name] == "ActionText::RichText" -%>
23
+ @<%= class_name.underscore %>.build_<%= association.name %>
24
+ <%- end -%>
16
25
  end
17
26
 
27
+ def edit; end
28
+
18
29
  def create
19
30
  @<%= class_name.underscore %> = <%= class_name %>.new(<%= class_name.underscore %>_params)
20
31
 
21
32
  if @<%= class_name.underscore %>.save
22
33
  flash[:success] = t('bo.record.created')
23
34
  redirect_to <%="#{options[:namespace]}_#{class_name.underscore.pluralize}_path"%>
24
-
25
35
  else
26
36
  render :new, status: :unprocessable_entity
27
37
  end
28
38
  end
29
39
 
30
- def edit; end
31
-
32
40
  def update
33
41
  if @<%= class_name.underscore %>.update(<%= class_name.underscore %>_params)
34
42
  flash[:success] = t('bo.record.updated')
@@ -44,7 +52,7 @@ module <%= options[:namespace].camelize %>
44
52
 
45
53
  redirect_to <%="#{options[:namespace]}_#{class_name.underscore.pluralize}_path"%>, status: :see_other
46
54
  end
47
-
55
+
48
56
  private
49
57
 
50
58
  def set_<%= class_name.underscore %>
@@ -57,7 +65,7 @@ module <%= options[:namespace].camelize %>
57
65
  <%- if value.nil? -%>
58
66
  :<%= key %><%=permited_params.count == (index +1) ? '' : ',' %>
59
67
  <%- else -%>
60
- <%= "#{key}: []" %><%=permited_params.count == (index +1) ? '' : ',' %>
68
+ <%= "#{key}: %i[#{value.join(" ")}]" %><%=permited_params.count == (index +1) ? '' : ',' %>
61
69
  <%- end -%>
62
70
  <%- end -%>
63
71
  )
data/lib/tybo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tybo
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Delpierre
@@ -141,6 +141,8 @@ files:
141
141
  - app/components/forms/delete_button_component.rb
142
142
  - app/components/forms/divider_component.html.erb
143
143
  - app/components/forms/divider_component.rb
144
+ - app/components/forms/has_many_form_component.html.erb
145
+ - app/components/forms/has_many_form_component.rb
144
146
  - app/components/forms/has_one_form_component.html.erb
145
147
  - app/components/forms/has_one_form_component.rb
146
148
  - app/components/forms/submit_button_component.html.erb