simpleadmin 1.2.4 → 1.2.5

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
  SHA1:
3
- metadata.gz: e99cdb380006f15b9fd1984bcd3ef515dbc7a938
4
- data.tar.gz: 5648457d8aa33e7e25160290609762c4d26ca2e6
3
+ metadata.gz: 82784c29c8c79b091658249fa53e8503d615edaf
4
+ data.tar.gz: b625444669f13b75da2d9a504be1ed348ed45e96
5
5
  SHA512:
6
- metadata.gz: 1e76548b4c9b3a71daf4dd91101cd4b095356f53406f61730e727eb38c20b981f5faf5299e82ad4644677974910440edba8122186b8709122464a70646dec42e
7
- data.tar.gz: bca47c1d1a2937231754d1e17996de32202569d1654907a1643dba3bcba9db2bb45fe30e32f64bc248b62e8b670e9e4089411aa5e404fba43158e19c71494317
6
+ metadata.gz: 920362a8d4c2cc4da2780f8dd59cb1da2483d1e928bccd72371fb627207db522a62f52f5a6878f2dc43ef150551a1c55c488209097490e0a8220dbeda4bc8073
7
+ data.tar.gz: fa6f5b7dcb16de7e10bebd14da74086be4cb81d7b85c78e9c5de75fead0c9f01dae8fa9079a52ad8bbe1fdecdb7765d31c9e219bb5c5c423005bbbe480d4d29b
@@ -2,7 +2,9 @@ module SimpleAdmin
2
2
  class ResourcesController < BaseController
3
3
  def index
4
4
  resource_service = ResourcesService.new(params[:model_klass_name], params[:model_fields])
5
- .index_action(params[:per_page], params[:page], params[:sort], params[:query], params[:model_attributes])
5
+ .index_action(params[:per_page], params[:page], params[:sort],
6
+ params[:query], params[:model_attributes], params[:reflection_tables],
7
+ params[:reflection_columns])
6
8
 
7
9
  render json: {
8
10
  resources: resource_service.resources,
@@ -21,7 +23,7 @@ module SimpleAdmin
21
23
  def show_by
22
24
  model_fields = params[:model_fields].map { |model_field| model_field['field_name'] }
23
25
 
24
- resource = model_klass.find_by(params[:column_name] => params[:column_value] ).attributes.slice(*model_fields)
26
+ resource = model_klass.find_by(params[:column_name] => params[:column_value]).attributes.slice(*model_fields)
25
27
 
26
28
  render json: resource
27
29
  end
@@ -6,7 +6,7 @@ class ResourcesService
6
6
  @model_fields = model_fields.map { |field_attributes| field_attributes[:field_name] }
7
7
  end
8
8
 
9
- def index_action(per_page, page, sort, query, model_attributes)
9
+ def index_action(per_page, page, sort, query, model_attributes, reflection_tables, reflection_columns)
10
10
  per_page = per_page.to_i
11
11
  page = page.to_i if page.present?
12
12
 
@@ -14,6 +14,11 @@ class ResourcesService
14
14
 
15
15
  resources = model_klass.limit(per_page)
16
16
 
17
+ if reflection_tables.present?
18
+ resources = resources.includes(reflection_tables)
19
+ model_fields.push(*reflection_columns)
20
+ end
21
+
17
22
  if query.present?
18
23
  search_result = search(query, model_klass, model_attributes)
19
24
 
@@ -29,20 +34,8 @@ class ResourcesService
29
34
  resources.order(id: :asc)
30
35
  end
31
36
 
32
- resources = resources.map do |resource|
33
- _resource = {}
34
-
35
- resource.attributes.each do |attribute_name, attribute_value|
36
- next unless model_fields.include?(attribute_name)
37
-
38
- _resource[attribute_name] = attribute_value
39
- end
40
-
41
- _resource
42
- end
43
-
44
37
  OpenStruct.new(
45
- resources: resources,
38
+ resources: resources.pluck(*model_fields).map { |resource| model_fields.zip(resource).to_h },
46
39
  total: total
47
40
  )
48
41
  end
@@ -1,3 +1,3 @@
1
1
  module Simpleadmin
2
- VERSION = '1.2.4'.freeze
2
+ VERSION = '1.2.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpleadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Strukov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-08 00:00:00.000000000 Z
11
+ date: 2019-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler