azahara_schema 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/azahara_schema/application_helper.rb +10 -2
- data/app/views/azahara_schema/_schema.html.erb +5 -3
- data/lib/azahara_schema/attribute_name.rb +2 -0
- data/lib/azahara_schema/controller_additions.rb +23 -3
- data/lib/azahara_schema/model_schema.rb +3 -2
- data/lib/azahara_schema/schema.rb +35 -5
- data/lib/azahara_schema/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5524a5493e19e41523f7e1bc68d332d60f8632b135eb332f2d0c647e7b078123
|
4
|
+
data.tar.gz: f6b312c7ce2da1b2eb24d4d0fda8c1f197816862014444f97e6285936c546555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f2e34b86aa21762d72af69f1a214af3b8418aee16dfa224cbda52b3cb1b74d6b24f216286f1384769a1825e3e9904ccbe7662c92e23e9ed1824d01ec66630a
|
7
|
+
data.tar.gz: 2339248d1a7a6cfce3b92ca2e6ca8bfd214ae884a037cbb342b29135fb062b0cfdecd7a5d8b20c5d0317d5ba0b0cc263bbd27da57c1bfc5e462e1e578cac7e34
|
@@ -40,8 +40,12 @@ module AzaharaSchema
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
def azahara_export_path(schema, export_format)
|
44
|
+
polymorphic_path(schema.model, schema.to_param.merge(format: export_format))
|
45
|
+
rescue NoMethodError => err
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
45
49
|
def list_values_for_select(attribute)
|
46
50
|
if attribute.format.format_name == 'list'
|
47
51
|
attribute.available_values.collect do |l, val|
|
@@ -52,6 +56,10 @@ module AzaharaSchema
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
59
|
+
def azahara_attribute_for(model, name)
|
60
|
+
AzaharaSchema::Schema.schema_class_for(model).attribute(model, name)
|
61
|
+
end
|
62
|
+
|
55
63
|
def attribute_formatter_for(schema_or_model, **options)
|
56
64
|
AttributeFormatter.formatter_for(schema_or_model).new(schema_or_model, self, options)
|
57
65
|
end
|
@@ -5,8 +5,10 @@
|
|
5
5
|
<%= render output %>
|
6
6
|
<% end %>
|
7
7
|
<div class="exports text-right">
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
<% if (csv_path = azahara_export_path(schema, :csv)) %>
|
9
|
+
<%= link_to csv_path do %>
|
10
|
+
<i class="fa fa-file-o"></i>
|
11
|
+
<%= t('label_export_as', as: 'CSV') %>
|
12
|
+
<% end %>
|
11
13
|
<% end %>
|
12
14
|
</div>
|
@@ -11,6 +11,8 @@ module AzaharaSchema
|
|
11
11
|
I18n.t(i18n_scoped_key, options.merge(default: i18n_fallback_keys))
|
12
12
|
end
|
13
13
|
|
14
|
+
# translates values to list_values
|
15
|
+
# TODO: not needed to do it for every value - for example districts are not translatable
|
14
16
|
def human_list_value(value, **options)
|
15
17
|
return '' unless value.present?
|
16
18
|
I18n.t(i18n_scoped_list_key(value.to_s), options.merge(default: i18n_list_fallback_keys(value)+[value.to_s]))
|
@@ -2,9 +2,7 @@ module AzaharaSchema
|
|
2
2
|
module ControllerAdditions
|
3
3
|
|
4
4
|
def azahara_schema_index(**options, &block)
|
5
|
-
|
6
|
-
@resource_schema.from_params(params.reverse_merge(options[:defaults] || {}))
|
7
|
-
yield(@resource_schema) if block_given?
|
5
|
+
azahara_schema_for_index(options, &block)
|
8
6
|
respond_to do |format|
|
9
7
|
format.html
|
10
8
|
format.json {
|
@@ -29,5 +27,27 @@ module AzaharaSchema
|
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
30
|
+
def azahara_schema_api_index(**options, &block)
|
31
|
+
azahara_schema_for_index(options, &block)
|
32
|
+
respond_to do |format|
|
33
|
+
format.json {
|
34
|
+
json_result = {}
|
35
|
+
if params['_type'] == 'count'
|
36
|
+
json_result = {count: @resource_schema.entity_count}
|
37
|
+
else
|
38
|
+
json_result = {entities: @resource_schema, count: @resource_schema.entity_count}
|
39
|
+
end
|
40
|
+
render json: json_result
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def azahara_schema_for_index(**options, &block)
|
47
|
+
@resource_schema = self.class.cancan_resource_class.new(self).send(:collection_instance)
|
48
|
+
@resource_schema.from_params(params.reverse_merge(options[:defaults] || {}))
|
49
|
+
yield(@resource_schema) if block_given?
|
50
|
+
end
|
51
|
+
|
32
52
|
end
|
33
53
|
end
|
@@ -3,7 +3,21 @@ require 'active_support' #Hash.slice
|
|
3
3
|
module AzaharaSchema
|
4
4
|
class Schema
|
5
5
|
|
6
|
+
def self.schema_class_for(klass)
|
7
|
+
klasses = [klass]
|
8
|
+
while klass != klass.base_class
|
9
|
+
klass = klass.superclass
|
10
|
+
klasses << klass
|
11
|
+
end
|
12
|
+
klasses.each do |kls|
|
13
|
+
schema_klass = "#{kls.name}Schema".safe_constantize
|
14
|
+
return schema_klass if schema_klass
|
15
|
+
end
|
16
|
+
AzaharaSchema::Schema
|
17
|
+
end
|
18
|
+
|
6
19
|
def self.schema_for(klass, *attributes)
|
20
|
+
model = klass
|
7
21
|
klasses = [klass]
|
8
22
|
while klass != klass.base_class
|
9
23
|
klass = klass.superclass
|
@@ -11,9 +25,27 @@ module AzaharaSchema
|
|
11
25
|
end
|
12
26
|
klasses.each do |kls|
|
13
27
|
schema_klass = "#{kls.name}Schema".safe_constantize
|
14
|
-
|
28
|
+
if schema_klass
|
29
|
+
return kls.try(:abstract_class?) ? schema_klass.new(model, *attributes) : schema_klass.new(*attributes)
|
30
|
+
end
|
15
31
|
end
|
16
|
-
AzaharaSchema::Schema.new(
|
32
|
+
AzaharaSchema::Schema.new(model, *attributes)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.attribute_type(model, name)
|
36
|
+
col = model.columns_hash[name.to_s]
|
37
|
+
col && col.type
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.attribute(model, name, attr_type=nil)
|
41
|
+
attr_type ||= attribute_type(model, name)
|
42
|
+
Attribute.new(model, name, attr_type)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.attribute_for_column(model, col, attr_type=nil)
|
46
|
+
attr_type ||= ('list' if model.defined_enums[col.name])
|
47
|
+
attr_type ||= col.type
|
48
|
+
attribute(model, col.name, attr_type)
|
17
49
|
end
|
18
50
|
|
19
51
|
def self.enabled_filters(*filter_names)
|
@@ -179,9 +211,7 @@ module AzaharaSchema
|
|
179
211
|
end
|
180
212
|
|
181
213
|
def attribute_for_column(col)
|
182
|
-
|
183
|
-
t ||= col.type
|
184
|
-
Attribute.new(model, col.name, t)
|
214
|
+
self.class.attribute_for_column(model, col)
|
185
215
|
end
|
186
216
|
|
187
217
|
def initialize_available_attributes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azahara_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Ezr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.7.
|
106
|
+
rubygems_version: 2.7.6
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Gem to support developement of rails application with schema over an entity
|