egov_utils 0.3.3 → 0.3.4

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: a0e499d916b193c97d48999f4862bddf853c70c7e2458f718641ecbec895cded
4
- data.tar.gz: a502e385e0afb8be990fdc438cd94433afc6984853b1aec8fa1dfbefa0d398dc
3
+ metadata.gz: 674e8db7ce7f9de0944efee865134ecde920a578b259c23ce74370ba4ba35ada
4
+ data.tar.gz: cfd4672a9a481389924b9dc69f485bcedbcd824ca4ed5969d6825a2d09b3e5ea
5
5
  SHA512:
6
- metadata.gz: 002bd6cc5358ac39753abb16e3e276e0a965addbab6b3c191dd53579d8eb94ffa2badf155d20f4690e114f33c5059360c6f697e53fc13fe959690337198869f4
7
- data.tar.gz: 6b77faa9d8755c12e75ae565242eb65bc20c29448ee90eaa1c01ea5bef3bee9d41a90b8e425d66d6ea24bd24ab31c8e3337a632df1f8d432344de2e365edefb7
6
+ metadata.gz: 6cd772c57e1c3e27f6f3281238e2e317c01fae05fc6027398a828b6a5281b0c99edb0a7269c4fd0cb8862b090275057ff9041aa4b58b7fd6980150bb524df024
7
+ data.tar.gz: 5ead03e0f48e6da8aa5293786f3019e4668b6b30f2a81e03a58647506a03717b79c75318d63e9c0d89baa33d8a27c07fc00b60c72f65d8a4a73ff18c275438e0
@@ -5,6 +5,7 @@ module EgovUtils
5
5
  s = ''
6
6
  s << "window.I18n.defaultLocale = '#{I18n.default_locale}';"
7
7
  s << "window.I18n.locale = '#{I18n.locale}';"
8
+ s << "window.currency_symbols = #{Money::Currency.table.each_with_object({}){|(k,v),o|o[k]=v[:symbol]}.to_json};"
8
9
  s
9
10
  javascript_tag s
10
11
  end
@@ -3,7 +3,7 @@ module EgovUtils
3
3
 
4
4
  def type_for_grid(type)
5
5
  case type
6
- when 'integer', 'float', 'decimal'
6
+ when 'integer', 'float', 'decimal', 'currency'
7
7
  'Number'
8
8
  when 'string', 'text', 'list', 'love'
9
9
  'String'
@@ -57,10 +57,10 @@ module EgovUtils
57
57
 
58
58
  if attribute.type == 'list'
59
59
  s << ", format: ( (value) -> I18n.t('#{attribute.attribute_name.i18n_scoped_list_prefix}'+'.'+value, {defaults: $.map( #{attribute.attribute_name.i18n_list_fallback_prefixes.to_json}, (pref, i)-> {scope: (pref + '.' + value)} )}) ) "
60
- elsif attribute.type == 'date'
60
+ elsif %w(date datetime).include?(attribute.type)
61
61
  s << ", format: ( (value)-> I18n.l('date.formats.default', value) )"
62
- elsif attribute.type == 'datetime'
63
- s << ", format: ( (value)-> I18n.l('time.formats.default', value) )"
62
+ elsif attribute.type == 'currency'
63
+ s << ", columnTemplate: ( (cell, item, index)-> $('<div></div>').appendTo(cell).html( I18n.toCurrency(item['#{attribute.name}'], { unit: window.currency_symbols[item['#{attribute.try(:currency_code_col)}']]}) ) )"
64
64
  end
65
65
  s << "}"
66
66
  end
@@ -0,0 +1,10 @@
1
+ require 'money'
2
+
3
+ require 'azahara_schema_currency/currency_format'
4
+ require 'azahara_schema_currency/currency_attribute'
5
+
6
+ require 'azahara_schema_currency/attribute_formatter_patch'
7
+ AzaharaSchema::AttributeFormatter.__send__('prepend', AzaharaSchemaCurrency::AttributeFormatterPatch)
8
+
9
+ require 'azahara_schema_currency/association_attribute_patch'
10
+ AzaharaSchema::AssociationAttribute.__send__('prepend', AzaharaSchemaCurrency::AssociationAttributePatch)
@@ -0,0 +1,9 @@
1
+ module AzaharaSchemaCurrency
2
+ module AssociationAttributePatch
3
+
4
+ def currency_code_col
5
+ association.name.to_s+'-'+attribute.try(:currency_code_col).to_s
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module AzaharaSchemaCurrency
2
+ module AttributeFormatterPatch
3
+
4
+ def format_value_html(attribute, unformated_value, **options)
5
+ case attribute.type
6
+ when 'currency'
7
+ Money.new(unformated_value, options[:currency_code].to_s.upercase.presence).format
8
+ else
9
+ super
10
+ end
11
+ end
12
+
13
+
14
+ def formatting_options(attribute, entity)
15
+ case attribute.type
16
+ when 'currency'
17
+ {currency_code: attribute.currency_code(entity).to_s}
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # Author:: Ondřej Ezr (mailto:oezr@msp.justice.cz)
2
+ # Copyright:: Copyright (c) 2018 Ministry of Justice
3
+ # License:: Distributes under license Open Source Licence pro Veřejnou Správu a Neziskový Sektor v.1
4
+
5
+ module AzaharaSchemaCurrency
6
+ class CurrencyAttribute < AzaharaSchema::Attribute
7
+
8
+ def initialize(model, name, type='currency', **options)
9
+ super(model, name, type)
10
+ @options = options
11
+ end
12
+
13
+ def currency_code_col
14
+ @options[:currency_code_method] || 'currency_code'
15
+ end
16
+
17
+ def currency_code(entity)
18
+ entity.try(currency_code_col)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module AzaharaSchemaCurrency
2
+ class CurrencyFormat < AzaharaSchema::FieldFormat::DecimalFormat
3
+ add 'currency'
4
+ end
5
+ end
@@ -6,6 +6,7 @@ require 'cancancan'
6
6
  require 'audited'
7
7
  require 'paranoia'
8
8
  require 'azahara_schema'
9
+ require 'azahara_schema_currency'
9
10
 
10
11
  require 'font-awesome-sass'
11
12
  require 'modernizr-rails'
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
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-04-17 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '2.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: money
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '6.11'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '6.11'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: request_store_rails
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +226,14 @@ dependencies:
212
226
  requirements:
213
227
  - - "~>"
214
228
  - !ruby/object:Gem::Version
215
- version: 4.0.0.beta
229
+ version: 4.0.0
216
230
  type: :runtime
217
231
  prerelease: false
218
232
  version_requirements: !ruby/object:Gem::Requirement
219
233
  requirements:
220
234
  - - "~>"
221
235
  - !ruby/object:Gem::Version
222
- version: 4.0.0.beta
236
+ version: 4.0.0
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: sass-rails
225
239
  requirement: !ruby/object:Gem::Requirement
@@ -494,6 +508,11 @@ files:
494
508
  - db/migrate/20180403133155_create_egov_utils_people_base.rb
495
509
  - db/migrate/20180403141531_join_people_tables.rb
496
510
  - db/migrate/20180403150556_create_egov_utils_legal_people.rb
511
+ - lib/azahara_schema_currency.rb
512
+ - lib/azahara_schema_currency/association_attribute_patch.rb
513
+ - lib/azahara_schema_currency/attribute_formatter_patch.rb
514
+ - lib/azahara_schema_currency/currency_attribute.rb
515
+ - lib/azahara_schema_currency/currency_format.rb
497
516
  - lib/bootstrap_form/check_box_patch.rb
498
517
  - lib/bootstrap_form/custom_file_field.rb
499
518
  - lib/bootstrap_form/datetimepicker.rb