cm-admin 2.2.0 → 2.3.0

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: ab22f4bef2b77930d17a0910dbc5ee20f0773f9f025d7e7ba7fde8a55be7e5f8
4
- data.tar.gz: ba334104c29113fbec5440dbe31b13b8fb8513efd6a8be7308928815141256a0
3
+ metadata.gz: f02c4921628126ddc305b8f76fefe27c325d11a90b6649166f30376af4983b9d
4
+ data.tar.gz: a0f263e975a1b4e7505bb6174a4cfe9942c55103259fda85d33e2cbf1b29af4b
5
5
  SHA512:
6
- metadata.gz: 67c7bf36f684d04d976fbad85a58f5910a84762f2e750918b3ab2eef6b7c9b4471bb9ff6f8b1594bb8dc7f3bf9910cf6b4560d9e80ad8ae24d6a8b56321901ae
7
- data.tar.gz: 47b9d696e72e73ef748ffc51301891dc2fa3667f3f201ec61643167d13b286d0dc289ec7ddd4a867700c93a1b23bdbb5395b747d82e7fc71e00c39fc42e77e44
6
+ metadata.gz: '0286312409deddb904e8f85ec754fc07c62b91db53f8d46171bfcb65e94bf3418578eca0ea9d329cf6b11a1c7447941508da91152b132d74e2e207bc93c3818e'
7
+ data.tar.gz: 66ca0d6ccacf4440b180a7e5b1b37e723e5f1363a96b3fa0e30d88d365476a94d5ff6a67590fdca34af18ebf08c026b6eecd6fae0739286512e9a858644d68e5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (2.2.0)
4
+ cm-admin (2.3.0)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -1,7 +1,7 @@
1
1
  // Card view right now is application specific, so card partial will be overwritten in the application
2
2
 
3
3
  .table-top
4
- p.table-top__total-count = "#{humanized_ar_collection_count(@ar_object.pagy.count, @model.table_name)}"
4
+ p.table-top__total-count = "#{humanized_ar_collection_count(@ar_object.pagy.count, @model.formatted_name)}"
5
5
  .table-top__column-action
6
6
  .btn-group[role="group" aria-label="Basic example"]
7
7
  a.btn.btn-ghost href="#{cm_admin.send("#{@model.name.underscore}_index_path")}?page=#{params[:page] || 1}"
@@ -68,4 +68,4 @@
68
68
  p.count-text.m-0 Showing #{@ar_object.pagy.from} to #{@ar_object.pagy.to} out of #{@ar_object.pagy.count}
69
69
  == render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @ar_object.pagy }
70
70
 
71
- / = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @model, ar_collection: @ar_object }
71
+ / = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @model, ar_collection: @ar_object }
@@ -4,6 +4,8 @@
4
4
  p.section-heading = section.section_name
5
5
  .card
6
6
  .card-body
7
+ - if section.partial.present?
8
+ = render partial: section.partial, locals: { ar_object: @ar_object }
7
9
  - if !section.section_fields.empty?
8
10
  - section.section_fields.each do |field|
9
11
  = show_field(@ar_object, field)
@@ -1,5 +1,5 @@
1
1
  .table-top
2
- p.table-top__total-count = "#{humanized_ar_collection_count(@ar_object.pagy.count, @model.table_name)}"
2
+ p.table-top__total-count = "#{humanized_ar_collection_count(@ar_object.pagy.count, @model.formatted_name)}"
3
3
  .table-top__column-action
4
4
  - if @current_action.view_type == :card_view
5
5
  .btn-group[role="group" aria-label="Card Toggle"]
@@ -55,4 +55,4 @@
55
55
  p.count-text.m-0 Showing #{@ar_object.pagy.from} to #{@ar_object.pagy.to} out of #{@ar_object.pagy.count}
56
56
  == render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @ar_object.pagy }
57
57
 
58
- / = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @model, ar_collection: @ar_object }
58
+ / = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @model, ar_collection: @ar_object }
@@ -3,5 +3,7 @@
3
3
  p.section-heading = section.section_name
4
4
  .card
5
5
  .card-body
6
+ - if section.partial.present?
7
+ = render partial: section.partial, locals: { ar_object: @associated_ar_object }
6
8
  - section.section_fields.each do |field|
7
9
  = show_field(@associated_ar_object, field)
@@ -5,12 +5,31 @@
5
5
  .show-page__inner
6
6
  .card.col-7
7
7
  .card-body
8
- ul.history-items-list
9
- - @ar_object.action_trails.each do |at|
8
+ ul.history-items-list
9
+ - @ar_object.versions.each do |version|
10
10
  li.history-item
11
11
  .d-inline-flex.mb-2
12
- span.fw-bold.me-1 = at.actor.first_name
13
- span.me-1 = at.trail_type.titleize
12
+ span.fw-bold.me-1 = User.find_by(id: version.whodunnit).present? ? User.find_by(id: version.whodunnit).full_name : "Anonymous"
13
+ span.me-1 = version.event
14
14
  span.me-1 the
15
- span.fw-bold.me-1 = at.entity_type
16
- span.text-body-tertiary.me-1 = at.created_at.strftime("%B")
15
+ span.fw-bold.me-1 = version.item_type
16
+ span.text-body-tertiary.me-1 = version.created_at.strftime("%B %d, %Y, %H:%M %p")
17
+ - if version.event == 'update' && version.changeset.present?
18
+ .history-details
19
+ table.table.table-bordered.table-light style="width: 600px;"
20
+ thead
21
+ tr
22
+ th
23
+ | Updated Column
24
+ th
25
+ | Previous Value
26
+ th
27
+ | Updated Value
28
+ tbody
29
+ - version.changeset.each do |key, value|
30
+ tr
31
+ td = key
32
+ td = value[0] || '-'
33
+ td = value[1].instance_of?(ActiveSupport::TimeWithZone) ? value[1].strftime("%B %d, %Y, %H:%M %p") : value[1]
34
+
35
+
@@ -121,8 +121,8 @@ module CmAdmin
121
121
  @additional_permitted_fields = fields
122
122
  end
123
123
 
124
- def table_name
125
- @display_name.present? ? @display_name : @ar_model.table_name
124
+ def formatted_name
125
+ @display_name != @name ? @display_name : @ar_model.table_name
126
126
  end
127
127
 
128
128
  def alert_box(options = {})
@@ -175,14 +175,14 @@ module CmAdmin
175
175
  # cm_section('Basic Information', display_if: ->(current_object) { current_object.name == 'John' }, col_size: 6, html_attrs: { class: 'section-class' }) do
176
176
  # field :title, input_type: :string
177
177
  # end
178
- def cm_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
178
+ def cm_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, partial: nil, &block)
179
179
  @available_fields[@current_action.name.to_sym] ||= []
180
- @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, &block)
180
+ @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, partial, &block)
181
181
  end
182
182
 
183
183
  # @deprecated Use {#cm_section} instead of this method
184
- def cm_show_section(section_name, display_if: nil, html_attrs: nil, &block)
185
- cm_section(section_name, display_if:, html_attrs:, &block)
184
+ def cm_show_section(section_name, display_if: nil, html_attrs: nil, partial: nil, &block)
185
+ cm_section(section_name, display_if:, html_attrs:, partial:, &block)
186
186
  end
187
187
 
188
188
  # Create a new column on index layout.
@@ -378,12 +378,15 @@ module CmAdmin
378
378
  end
379
379
 
380
380
  # Configure sortable columns for model
381
+ # @note default sort direction will be ascending
381
382
  # @param columns [Array] the array of hash for column and display name
382
383
  # @example Sortable Columns
383
- # sortable_columns([{column: 'id', display_name: 'ID'}, {column: 'updated_at', display_name: 'Last Updated At'}])
384
+ # sortable_columns([{column: 'id', display_name: 'ID'},
385
+ # {column: 'updated_at', display_name: 'Last Updated At'}])
384
386
  #
385
387
  # @example Sortable Columns with default column and direction
386
- # sortable_columns([{column: 'id', display_name: 'ID', default: true, default_direction: 'desc'}, {column: 'updated_at', display_name: 'Last Updated At'}])
388
+ # sortable_columns([{column: 'id', display_name: 'ID', default: true, default_direction: 'desc'},
389
+ # {column: 'updated_at', display_name: 'Last Updated At'}])
387
390
  def sortable_columns(columns)
388
391
  @sort_columns = columns
389
392
  default_column = columns.filter do |column|
@@ -35,17 +35,17 @@ module CmAdmin
35
35
  end
36
36
  end
37
37
 
38
- def cm_section(section_name, col_size: nil, display_if: nil, html_attrs: nil, &block)
39
- @sections << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, &block)
38
+ def cm_section(section_name, col_size: nil, display_if: nil, html_attrs: nil, partial: nil, &block)
39
+ @sections << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, partial, &block)
40
40
  end
41
41
 
42
42
  # This method is deprecated. Use cm_section instead.
43
- def cm_show_section(section_name, col_size: nil, display_if: nil, html_attrs: nil, &block)
44
- cm_section(section_name, col_size: col_size, display_if: display_if, html_attrs: html_attrs, &block)
43
+ def cm_show_section(section_name, col_size: nil, display_if: nil, html_attrs: nil, partial: nil, &block)
44
+ cm_section(section_name, col_size: col_size, display_if: display_if, html_attrs: html_attrs, partial: partial, &block)
45
45
  end
46
46
 
47
- def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
48
- nested_section = CmAdmin::Models::Section.new(section_name, @current_action, @cm_model, display_if, html_attrs, col_size, &block)
47
+ def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, partial: nil, &block)
48
+ nested_section = CmAdmin::Models::Section.new(section_name, @current_action, @cm_model, display_if, html_attrs, col_size, partial, &block)
49
49
  nested_section.parent_section = self
50
50
  @row_fields << nested_section
51
51
  end
@@ -7,9 +7,9 @@ module CmAdmin
7
7
  # It also contains rows, which contains sections and fields.
8
8
 
9
9
  attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :parent_section,
10
- :nested_table_fields, :rows, :col_size, :current_nested_field, :nested_sections, :html_attrs
10
+ :nested_table_fields, :rows, :col_size, :current_nested_field, :nested_sections, :html_attrs, :partial
11
11
 
12
- def initialize(section_name, current_action, cm_model, display_if, html_attrs, col_size, &block)
12
+ def initialize(section_name, current_action, cm_model, display_if, html_attrs, col_size, partial, &block)
13
13
  @section_fields = []
14
14
  @rows = []
15
15
  @nested_table_fields = []
@@ -22,6 +22,7 @@ module CmAdmin
22
22
  @current_nested_field = nil
23
23
  @nested_sections = []
24
24
  @parent_section = nil
25
+ @partial = partial || nil
25
26
  instance_eval(&block)
26
27
  end
27
28
 
@@ -63,8 +64,8 @@ module CmAdmin
63
64
  @rows << CmAdmin::Models::Row.new(@current_action, @model, display_if, html_attrs, &block)
64
65
  end
65
66
 
66
- def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
67
- nested_section = CmAdmin::Models::Section.new(section_name, @current_action, @cm_model, display_if, html_attrs, col_size, &block)
67
+ def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, partial: nil, &block)
68
+ nested_section = CmAdmin::Models::Section.new(section_name, @current_action, @cm_model, display_if, html_attrs, col_size, partial, &block)
68
69
  nested_section.parent_section = self
69
70
  @nested_sections ||= []
70
71
  @nested_sections << nested_section
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -65,6 +65,7 @@ module CmAdmin
65
65
 
66
66
  def create_sections(resource, form_obj, section)
67
67
  content_tag :div, class: 'col form-container' do
68
+ return render partial: section.partial, locals: { form_obj: } if section.partial
68
69
  concat content_tag(:p, section.section_name, class: 'form-title') unless section.parent_section.present?
69
70
  concat set_form_for_fields(resource, form_obj, section)
70
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: exe
16
16
  cert_chain: []
17
- date: 2024-10-01 00:00:00.000000000 Z
17
+ date: 2024-10-04 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: caxlsx_rails