simpleadmin 1.0.0 → 1.0.1

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
- SHA256:
3
- metadata.gz: 89bce08902d50cacab299ba5e5fa55b847de9be550caa8b4bad1d8ac58520f2d
4
- data.tar.gz: '0671935bb1f9973b7dc908e400392a65f99701c1c4f52108c125295c5f8cdec8'
2
+ SHA1:
3
+ metadata.gz: e16106fffda69e8ce0a3647d28e1c761f2d0a1d5
4
+ data.tar.gz: d76c5254c70f3ecd386d0f3c82ddf393b1260d2b
5
5
  SHA512:
6
- metadata.gz: ec2bb8cb67ca622ffe019bbc580018b7c8785884fec132e27f32948bb83eb6d38a00b6c4c000bd45fcab3cc45da0a118dd5efc49471d41553bf31f38a900f22d
7
- data.tar.gz: ba41bf51917aef04c818f53ff37d1009a33126863bc471482c752c5262de9a9f83380e062bd000319b3d7cef6f37f8757174bb189018147fc72fb49552b7702c
6
+ metadata.gz: 62def8a8e18efdfc72fde4d5e0d376226051adc7d50f51f58f37746f6b6ac4692e5a41807c83901216fb11d12bf82d91ab11a2d0c5cb62b1bb483a34445836b4
7
+ data.tar.gz: 1b0f40e9c6d143f4241958feb785108e66d1d48cf633f75dc31c0a95caa1bbf0106821ef34b79d3b35843b3d0c346b9f8ec7e251b14e19f8f555afe7577be30f
@@ -1,100 +1,98 @@
1
- module Api::V1
2
- module SimpleAdmin
3
- class ResourcesController < BaseController
4
- def index
5
- model_klass = params[:model_klass_name].constantize
6
- model_fields = params[:model_fields]
1
+ module SimpleAdmin
2
+ class ResourcesController < BaseController
3
+ def index
4
+ model_klass = params[:model_klass_name].constantize
5
+ model_fields = params[:model_fields]
7
6
 
8
- per_page = params[:per_page].to_i
9
- page = params[:page].to_i if params[:page].present?
10
- total = model_klass.count
7
+ per_page = params[:per_page].to_i
8
+ page = params[:page].to_i if params[:page].present?
9
+ total = model_klass.count
11
10
 
12
- resources = model_klass.limit(per_page)
11
+ resources = model_klass.limit(per_page)
13
12
 
14
- if params[:query].present?
15
- search_result = search(params[:query], model_klass, params[:model_attributes])
13
+ if params[:query].present?
14
+ search_result = search(params[:query], model_klass, params[:model_attributes])
16
15
 
17
- resources = search_result[:resources]
18
- total = search_result[:total]
19
- end
20
-
21
- resources = resources.offset((per_page * page) - per_page) if page.present?
22
- resources = resources.order(params[:sort][:column_name] => params[:sort][:order]) if params[:sort].present?
16
+ resources = search_result[:resources]
17
+ total = search_result[:total]
18
+ end
23
19
 
24
- resources = resources.map do |resource|
25
- _resource = {}
20
+ resources = resources.offset((per_page * page) - per_page) if page.present?
21
+ resources = resources.order(params[:sort][:column_name] => params[:sort][:order]) if params[:sort].present?
26
22
 
27
- resource.attributes.each do |attribute_name, attribute_value|
28
- next unless model_fields.include?(attribute_name)
23
+ resources = resources.map do |resource|
24
+ _resource = {}
29
25
 
30
- _resource[attribute_name] = attribute_value
31
- end
26
+ resource.attributes.each do |attribute_name, attribute_value|
27
+ next unless model_fields.include?(attribute_name)
32
28
 
33
- _resource
29
+ _resource[attribute_name] = attribute_value
34
30
  end
35
31
 
36
- render json: {
37
- resources: resources,
38
- total: total
39
- }
32
+ _resource
40
33
  end
41
34
 
42
- def show
43
- model_klass = params[:model_klass_name].constantize
44
- model_fields = params[:model_fields]
35
+ render json: {
36
+ resources: resources,
37
+ total: total
38
+ }
39
+ end
45
40
 
46
- resource = model_klass.find(params[:id]).attributes.slice(*model_fields)
41
+ def show
42
+ model_klass = params[:model_klass_name].constantize
43
+ model_fields = params[:model_fields]
47
44
 
48
- render json: resource
49
- end
45
+ resource = model_klass.find(params[:id]).attributes.slice(*model_fields)
50
46
 
51
- def create
52
- model_klass = params[:model_klass_name].constantize
47
+ render json: resource
48
+ end
53
49
 
54
- resource = model_klass.new(resource_params)
50
+ def create
51
+ model_klass = params[:model_klass_name].constantize
55
52
 
56
- if resource.save
57
- render json: resource
58
- else
59
- render json: resource.errors
60
- end
53
+ resource = model_klass.new(resource_params)
54
+
55
+ if resource.save
56
+ render json: resource
57
+ else
58
+ render json: resource.errors
61
59
  end
60
+ end
62
61
 
63
- def update
64
- model_klass = params[:model_klass_name].constantize
65
- resource = model_klass.find(params[:id])
62
+ def update
63
+ model_klass = params[:model_klass_name].constantize
64
+ resource = model_klass.find(params[:id])
66
65
 
67
- if resource.update(resource_params)
68
- render json: resource
69
- else
70
- render json: resource.errors
71
- end
66
+ if resource.update(resource_params)
67
+ render json: resource
68
+ else
69
+ render json: resource.errors
72
70
  end
71
+ end
73
72
 
74
- def destroy
75
- model_klass = params[:model_klass_name].constantize
76
- resource = model_klass.find(params[:id])
73
+ def destroy
74
+ model_klass = params[:model_klass_name].constantize
75
+ resource = model_klass.find(params[:id])
77
76
 
78
- resource.destroy
79
- end
77
+ resource.destroy
78
+ end
80
79
 
81
- private
80
+ private
82
81
 
83
- def search(search_query, model_klass, model_attributes)
84
- return [] if model_attributes.empty?
82
+ def search(search_query, model_klass, model_attributes)
83
+ return [] if model_attributes.empty?
85
84
 
86
- query = model_attributes.map { |model_attribute| "#{model_attribute} LIKE ?" }.join(' OR ')
87
- query_arguments = model_attributes.map { "%#{search_query}%" }
85
+ query = model_attributes.map { |model_attribute| "#{model_attribute} LIKE ?" }.join(' OR ')
86
+ query_arguments = model_attributes.map { "%#{search_query}%" }
88
87
 
89
- {
90
- resources: model_klass.where(query, *query_arguments),
91
- total: model_klass.where(query, *query_arguments).count
92
- }
93
- end
88
+ {
89
+ resources: model_klass.where(query, *query_arguments),
90
+ total: model_klass.where(query, *query_arguments).count
91
+ }
92
+ end
94
93
 
95
- def resource_params
96
- params.require(:resource).permit!
97
- end
98
- end
94
+ def resource_params
95
+ params.require(:resource).permit!
96
+ end
99
97
  end
100
98
  end
@@ -1,3 +1,3 @@
1
1
  module Simpleadmin
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpleadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Strukov
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubyforge_project:
140
- rubygems_version: 2.7.6
140
+ rubygems_version: 2.6.11
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: simple-admin