cm-admin 0.8.7 → 0.8.9

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: 7c6cf3d2c260e9964ab1aa9865d14af11fe287e49b6216ae260ae575567c0e89
4
- data.tar.gz: 495df145a9060198ca69bfd1eaeea836b6bba24287a804e69d100fab5d36cbd1
3
+ metadata.gz: 51174128fc2fd12fde48837a9271d8e51bb84d847379c6052080cf3de2c8745f
4
+ data.tar.gz: 9b2381f05a97106e9b3a1d8e117d71721a8d55ff080dcee96a38d77d819f0bf4
5
5
  SHA512:
6
- metadata.gz: 03b3e0f445067d05f32313a7c4e519545ee6396eca549e75719de294380df8be3be2d5e95c6dfcf262d563eb5db4cd8e3ebabcae753075a4b61f69a6957c5c1d
7
- data.tar.gz: 498e3dfb9d3580fa69bfaf959df282567590cbdee12d2ad3bc65fcbb7f7101c70fd9d7d5aba2e78ea6a09547afe0fc4161dd478495110bcfe8efe3887e0d7040
6
+ metadata.gz: 4ecc29569a31a996554a0360d3bbc52942f30b90692c5de67afdb7f1e6c79ebfab25736892a0093e9ef209821ee3950fad8df69934b36626151ca4af6d7dde10
7
+ data.tar.gz: 28018ef669025bb8b62d5127036efca2bfb32e944761089f74b17c9eccbed9f5f3db932ac9fe94fb50b120b2b5c8c3829e78b2b1cecf1478809577d8651c3dc8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (0.8.7)
4
+ cm-admin (0.8.9)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -38,7 +38,7 @@ GEM
38
38
  ice_nine (~> 0.11.0)
39
39
  thread_safe (~> 0.3, >= 0.3.1)
40
40
  builder (3.2.4)
41
- caxlsx (3.2.0)
41
+ caxlsx (3.3.0)
42
42
  htmlentities (~> 4.3, >= 4.3.4)
43
43
  marcel (~> 1.0)
44
44
  nokogiri (~> 1.10, >= 1.10.4)
@@ -67,10 +67,8 @@ GEM
67
67
  nokogiri (>= 1.5.9)
68
68
  marcel (1.0.2)
69
69
  method_source (1.0.0)
70
- mini_portile2 (2.8.0)
71
70
  minitest (5.16.2)
72
- nokogiri (1.13.8)
73
- mini_portile2 (~> 2.8.0)
71
+ nokogiri (1.13.9-arm64-darwin)
74
72
  racc (~> 1.4)
75
73
  pagy (4.11.0)
76
74
  parallel (1.22.1)
@@ -146,7 +144,7 @@ GEM
146
144
  rack-proxy (>= 0.6.1)
147
145
  railties (>= 5.2)
148
146
  semantic_range (>= 2.3.0)
149
- zeitwerk (2.6.1)
147
+ zeitwerk (2.6.4)
150
148
 
151
149
  PLATFORMS
152
150
  ruby
@@ -72,7 +72,7 @@ a {
72
72
  position: sticky;
73
73
  top: 0;
74
74
  background-color: #fff;
75
- z-index: 1;
75
+ z-index: 4;
76
76
  }
77
77
 
78
78
  .scrollable {
@@ -6,7 +6,6 @@
6
6
  overflow: auto;
7
7
 
8
8
  .sticky-container {
9
- z-index: 4;
10
9
  .cm-filters-v2 {
11
10
  padding: 16px 24px 36px 24px;
12
11
  }
@@ -153,22 +153,25 @@ module CmAdmin
153
153
  end
154
154
 
155
155
  def custom_controller_action(action_name, params)
156
- current_action = CmAdmin::Models::Action.find_by(@model, name: action_name.to_s)
157
- if current_action
158
- @current_action = current_action
159
- @ar_object = @model.ar_model.name.classify.constantize.find(params[:id])
160
- if @current_action.child_records
161
- child_records = @ar_object.send(@current_action.child_records)
162
- @associated_model = CmAdmin::Model.find_by(name: @model.ar_model.reflect_on_association(@current_action.child_records).klass.name)
163
- if child_records.is_a? ActiveRecord::Relation
164
- @associated_ar_object = filter_by(params, child_records, @associated_model.filter_params(params))
165
- else
166
- @associated_ar_object = child_records
167
- end
168
- return @ar_object, @associated_model, @associated_ar_object
169
- end
170
- return @ar_object
171
- end
156
+ @current_action = CmAdmin::Models::Action.find_by(@model, name: action_name.to_s)
157
+ return unless @current_action
158
+
159
+ @ar_object = @model.ar_model.name.classify.constantize.find(params[:id])
160
+ return @ar_object unless @current_action.child_records
161
+
162
+ child_records = @ar_object.send(@current_action.child_records)
163
+ @reflection = @model.ar_model.reflect_on_association(@current_action.child_records)
164
+ @associated_model = if @reflection.klass.column_names.include?('type')
165
+ CmAdmin::Model.find_by(name: @reflection.plural_name.classify)
166
+ else
167
+ CmAdmin::Model.find_by(name: @reflection.klass.name)
168
+ end
169
+ @associated_ar_object = if child_records.is_a? ActiveRecord::Relation
170
+ filter_by(params, child_records, @associated_model.filter_params(params))
171
+ else
172
+ child_records
173
+ end
174
+ return @ar_object, @associated_model, @associated_ar_object
172
175
  end
173
176
 
174
177
  def filter_by(params, records, filter_params={}, sort_params={})
@@ -176,7 +179,7 @@ module CmAdmin
176
179
  sort_column = "created_at"
177
180
  sort_direction = %w[asc desc].include?(sort_params[:sort_direction]) ? sort_params[:sort_direction] : "asc"
178
181
  sort_params = {sort_column: sort_column, sort_direction: sort_direction}
179
-
182
+
180
183
  records = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve if records.nil?
181
184
  records = records.order("#{@current_action.sort_column} #{@current_action.sort_direction}")
182
185
  final_data = CmAdmin::Models::Filter.filtered_data(filter_params, records, @associated_model ? @associated_model.filters : @model.filters)
@@ -65,5 +65,11 @@ module CmAdmin
65
65
  end
66
66
  end
67
67
  end
68
+
69
+ def is_show_action_available(model)
70
+ model &&
71
+ model.available_actions.map(&:name).include?('show') &&
72
+ has_valid_policy(model.name, 'show')
73
+ end
68
74
  end
69
75
  end
@@ -9,23 +9,29 @@ module CmAdmin::FileImport
9
9
  page_title 'File Import'
10
10
  page_description 'Manage all file import progress here'
11
11
 
12
+ filter [:id, :associated_model_name], :search, placeholder: 'ID, Table Name'
13
+ filter :status, :single_select,
14
+ collection: %w[in_progress success failed],
15
+ placeholder: 'Status'
16
+ filter :created_at, :date, placeholder: 'Created At'
17
+
12
18
  column :id
13
19
  column :imported_file_name, header: 'File'
14
- column :created_at, header: 'Started At', field_type: :datetime, format: '%B %d, %Y, %H:%M %p'
15
- column :completed_at, header: 'Completed At', field_type: :datetime, format: '%B %d, %Y, %H:%M %p'
16
- column :associated_model_name, header: 'Model name'
17
- column :added_by_name, header: 'Uploaded By'
20
+ column :created_at, header: 'Created At', field_type: :datetime, format: '%B %d, %Y, %H:%M %p'
18
21
  column :status, field_type: :tag, tag_class: STATUS_TAG_COLOR
22
+ column :associated_model_name, header: 'Table name'
23
+ column :added_by_name, header: 'Uploaded By'
24
+
19
25
  end
20
26
 
21
27
  cm_show page_title: :id do
22
28
  tab :profile, '' do
23
29
  cm_show_section 'Import details' do
24
30
  field :id, label: 'Import ID'
25
- field :imported_file_name, label: 'File'
26
- field :created_at, header: 'Started At', field_type: :datetime, format: '%B %d, %Y, %H:%M %p'
31
+ field :import_file, label: 'File', field_type: :attachment
32
+ field :created_at, header: 'Created At', field_type: :datetime, format: '%B %d, %Y, %H:%M %p'
27
33
  field :completed_at, header: 'Completed At', field_type: :datetime, format: '%B %d, %Y, %H:%M %p'
28
- field :associated_model_name, header: 'Model name'
34
+ field :associated_model_name, header: 'Table name'
29
35
  field :added_by_name, header: 'Uploaded By'
30
36
  field :status, field_type: :tag, tag_class: STATUS_TAG_COLOR
31
37
  end
@@ -35,11 +35,14 @@
35
35
  / input.cm-checkbox type="checkbox"
36
36
  - @model.available_fields[@action.name.to_sym].each_with_index do |column, index|
37
37
  td class="text-ellipsis"
38
- span class="#{column.cm_css_class}"
39
- - if index == 0 && @associated_model && @associated_model.available_actions.map(&:name).include?('show')
38
+ span class="#{column.field_type.to_s} #{column.cm_css_class} "
39
+ - if index == 0 && is_show_action_available(@associated_model)
40
40
  a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/#{ar_object.id}" = show_field_value(ar_object, column)
41
41
  - else
42
42
  = show_field_value(ar_object, column)
43
+ - if column.field_type == :drawer
44
+ = render partial: column.drawer_partial, locals: { ar_object: ar_object }
45
+
43
46
  - if @associated_model
44
47
  == render partial: 'cm_admin/main/actions_dropdown', locals: { cm_model: @associated_model, ar_object: ar_object }
45
48
 
@@ -28,7 +28,7 @@
28
28
  - if column.display_if.call(Current.user)
29
29
  td.text-ellipsis
30
30
  span class="#{column.field_type.to_s} #{column.cm_css_class} "
31
- - if index == 0 && !([:link, :custom, :attachment, :drawer, :image].include?(column.field_type))
31
+ - if index == 0 && is_show_action_available(@model) && !([:link, :custom, :attachment, :drawer, :image].include?(column.field_type))
32
32
  = link_to ar_object.send(column.field_name), cm_admin.send("#{ar_object.model_name.singular}_show_path", ar_object.id)
33
33
  - else
34
34
  = show_field_value(ar_object, column)
data/lib/cm-admin.rb ADDED
@@ -0,0 +1 @@
1
+ require 'cm_admin'
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = "0.8.7"
2
+ VERSION = '0.8.9'
3
3
  end
@@ -35,6 +35,9 @@ module CmAdmin
35
35
  when :datetime
36
36
  self.extend LocalTimeHelper
37
37
  local_time(ar_object.send(field.field_name).strftime(field.format || "%d/%m/%Y").to_s) if ar_object.send(field.field_name)
38
+ when :date
39
+ self.extend LocalTimeHelper
40
+ local_date(ar_object.send(field.field_name), (field.format || '%B %e, %Y'))
38
41
  when :text
39
42
  ar_object.send(field.field_name)
40
43
  when :custom
@@ -88,6 +91,7 @@ module CmAdmin
88
91
  end
89
92
  end
90
93
  end
94
+
91
95
  end
92
96
  end
93
97
  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: 0.8.7
4
+ version: 0.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - sajinmp
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-10-22 00:00:00.000000000 Z
13
+ date: 2022-11-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: caxlsx_rails
@@ -231,6 +231,7 @@ files:
231
231
  - config/webpack/test.js
232
232
  - config/webpacker.yml
233
233
  - lib/.DS_Store
234
+ - lib/cm-admin.rb
234
235
  - lib/cm_admin.rb
235
236
  - lib/cm_admin/configuration.rb
236
237
  - lib/cm_admin/constants.rb