redmineup 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/Gemfile +4 -0
  4. data/README.md +204 -0
  5. data/Rakefile +11 -0
  6. data/app/controllers/redmineup_controller.rb +26 -0
  7. data/app/views/redmine_crm/redmineup_calendar/_calendar.html.erb +34 -0
  8. data/app/views/redmineup/_money.html.erb +44 -0
  9. data/app/views/redmineup/settings.html.erb +10 -0
  10. data/bitbucket-pipelines.yml +50 -0
  11. data/config/currency_iso.json +2544 -0
  12. data/config/locales/cs.yml +13 -0
  13. data/config/locales/de.yml +13 -0
  14. data/config/locales/en.yml +13 -0
  15. data/config/locales/es.yml +13 -0
  16. data/config/locales/ru.yml +13 -0
  17. data/config/routes.rb +5 -0
  18. data/doc/CHANGELOG +14 -0
  19. data/doc/LICENSE.txt +339 -0
  20. data/lib/redmineup/acts_as_draftable/draft.rb +40 -0
  21. data/lib/redmineup/acts_as_draftable/up_acts_as_draftable.rb +172 -0
  22. data/lib/redmineup/acts_as_list/list.rb +282 -0
  23. data/lib/redmineup/acts_as_priceable/up_acts_as_priceable.rb +33 -0
  24. data/lib/redmineup/acts_as_taggable/tag.rb +81 -0
  25. data/lib/redmineup/acts_as_taggable/tag_list.rb +111 -0
  26. data/lib/redmineup/acts_as_taggable/tagging.rb +16 -0
  27. data/lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb +357 -0
  28. data/lib/redmineup/acts_as_viewed/up_acts_as_viewed.rb +274 -0
  29. data/lib/redmineup/acts_as_votable/up_acts_as_votable.rb +80 -0
  30. data/lib/redmineup/acts_as_votable/up_acts_as_voter.rb +20 -0
  31. data/lib/redmineup/acts_as_votable/votable.rb +323 -0
  32. data/lib/redmineup/acts_as_votable/vote.rb +28 -0
  33. data/lib/redmineup/acts_as_votable/voter.rb +131 -0
  34. data/lib/redmineup/assets_manager.rb +43 -0
  35. data/lib/redmineup/colors_helper.rb +192 -0
  36. data/lib/redmineup/compatibility/application_controller_patch.rb +33 -0
  37. data/lib/redmineup/compatibility/routing_mapper_patch.rb +25 -0
  38. data/lib/redmineup/currency/formatting.rb +224 -0
  39. data/lib/redmineup/currency/heuristics.rb +151 -0
  40. data/lib/redmineup/currency/loader.rb +23 -0
  41. data/lib/redmineup/currency.rb +450 -0
  42. data/lib/redmineup/engine.rb +4 -0
  43. data/lib/redmineup/helpers/external_assets_helper.rb +20 -0
  44. data/lib/redmineup/helpers/form_tag_helper.rb +88 -0
  45. data/lib/redmineup/helpers/rup_calendar_helper.rb +146 -0
  46. data/lib/redmineup/helpers/tags_helper.rb +13 -0
  47. data/lib/redmineup/helpers/vote_helper.rb +35 -0
  48. data/lib/redmineup/hooks/views_layouts_hook.rb +11 -0
  49. data/lib/redmineup/liquid/drops/attachment_drop.rb +47 -0
  50. data/lib/redmineup/liquid/drops/issue_relations_drop.rb +41 -0
  51. data/lib/redmineup/liquid/drops/issues_drop.rb +217 -0
  52. data/lib/redmineup/liquid/drops/news_drop.rb +54 -0
  53. data/lib/redmineup/liquid/drops/projects_drop.rb +86 -0
  54. data/lib/redmineup/liquid/drops/time_entries_drop.rb +65 -0
  55. data/lib/redmineup/liquid/drops/users_drop.rb +68 -0
  56. data/lib/redmineup/liquid/filters/arrays.rb +254 -0
  57. data/lib/redmineup/liquid/filters/base.rb +249 -0
  58. data/lib/redmineup/liquid/filters/colors.rb +31 -0
  59. data/lib/redmineup/money_helper.rb +66 -0
  60. data/lib/redmineup/patches/liquid_patch.rb +33 -0
  61. data/lib/redmineup/settings/money.rb +46 -0
  62. data/lib/redmineup/settings.rb +53 -0
  63. data/lib/redmineup/version.rb +3 -0
  64. data/lib/redmineup.rb +108 -0
  65. data/redmineup.gemspec +29 -0
  66. data/test/acts_as_draftable/draft_test.rb +29 -0
  67. data/test/acts_as_draftable/rup_acts_as_draftable_test.rb +178 -0
  68. data/test/acts_as_taggable/rup_acts_as_taggable_test.rb +350 -0
  69. data/test/acts_as_taggable/tag_list_test.rb +34 -0
  70. data/test/acts_as_taggable/tag_test.rb +72 -0
  71. data/test/acts_as_taggable/tagging_test.rb +15 -0
  72. data/test/acts_as_viewed/rup_acts_as_viewed_test.rb +47 -0
  73. data/test/acts_as_votable/rup_acts_as_votable_test.rb +19 -0
  74. data/test/acts_as_votable/rup_acts_as_voter_test.rb +14 -0
  75. data/test/acts_as_votable/votable_test.rb +507 -0
  76. data/test/acts_as_votable/voter_test.rb +296 -0
  77. data/test/currency_test.rb +292 -0
  78. data/test/database.yml +17 -0
  79. data/test/fixtures/attachments.yml +14 -0
  80. data/test/fixtures/issues.yml +24 -0
  81. data/test/fixtures/news.yml +8 -0
  82. data/test/fixtures/projects.yml +10 -0
  83. data/test/fixtures/taggings.yml +32 -0
  84. data/test/fixtures/tags.yml +11 -0
  85. data/test/fixtures/users.yml +9 -0
  86. data/test/fixtures/votable_caches.yml +2 -0
  87. data/test/fixtures/votables.yml +4 -0
  88. data/test/fixtures/voters.yml +6 -0
  89. data/test/liquid/drops/attachment_drop_test.rb +15 -0
  90. data/test/liquid/drops/issue_relations_drop_test.rb +24 -0
  91. data/test/liquid/drops/issues_drop_test.rb +38 -0
  92. data/test/liquid/drops/news_drop_test.rb +38 -0
  93. data/test/liquid/drops/projects_drop_test.rb +44 -0
  94. data/test/liquid/drops/uses_drop_test.rb +36 -0
  95. data/test/liquid/filters/arrays_filter_test.rb +31 -0
  96. data/test/liquid/filters/base_filter_test.rb +67 -0
  97. data/test/liquid/filters/colors_filter_test.rb +33 -0
  98. data/test/liquid/liquid_helper.rb +34 -0
  99. data/test/models/attachment.rb +3 -0
  100. data/test/models/issue.rb +21 -0
  101. data/test/models/issue_relation.rb +10 -0
  102. data/test/models/news.rb +3 -0
  103. data/test/models/project.rb +8 -0
  104. data/test/models/user.rb +11 -0
  105. data/test/models/vote_classes.rb +33 -0
  106. data/test/money_helper_test.rb +12 -0
  107. data/test/schema.rb +144 -0
  108. data/test/tags_helper_test.rb +29 -0
  109. data/test/test_helper.rb +66 -0
  110. data/test/vote_helper_test.rb +28 -0
  111. data/vendor/assets/images/money.png +0 -0
  112. data/vendor/assets/images/vcard.png +0 -0
  113. data/vendor/assets/javascripts/Chart.bundle.min.js +16 -0
  114. data/vendor/assets/javascripts/select2.js +2 -0
  115. data/vendor/assets/javascripts/select2_helpers.js +192 -0
  116. data/vendor/assets/stylesheets/money.css +96 -0
  117. data/vendor/assets/stylesheets/select2.css +424 -0
  118. metadata +295 -0
@@ -0,0 +1,450 @@
1
+ require "json"
2
+ require "redmineup/currency/loader"
3
+ require "redmineup/currency/heuristics"
4
+ require "redmineup/currency/formatting"
5
+
6
+ module Redmineup
7
+ # Represents a specific currency unit.
8
+ #
9
+ # @see http://en.wikipedia.org/wiki/Currency
10
+ # @see http://iso4217.net/
11
+ class Currency
12
+ include Comparable
13
+ extend Enumerable
14
+ extend Redmineup::Currency::Loader
15
+ extend Redmineup::Currency::Heuristics
16
+ extend Redmineup::Currency::Formatting
17
+
18
+
19
+
20
+ # Thrown when a Currency has been registered without all the attributes
21
+ # which are required for the current action.
22
+ class MissingAttributeError < StandardError
23
+ def initialize(method, currency, attribute)
24
+ super(
25
+ "Can't call Currency.#{method} - currency '#{currency}' is missing "\
26
+ "the attribute '#{attribute}'"
27
+ )
28
+ end
29
+ end
30
+
31
+ # Thrown when an unknown currency is requested.
32
+ class UnknownCurrency < ArgumentError; end
33
+
34
+ class << self
35
+
36
+ def add_admin_money_menu
37
+ return if Redmine::MenuManager.map(:admin_menu).exists?(:redmineup_money)
38
+
39
+ require 'redmineup/hooks/views_layouts_hook'
40
+ Redmine::MenuManager.map(:admin_menu).push(:redmineup_money,
41
+ { controller: 'redmineup', action: 'settings', id: 'money' },
42
+ caption: :label_redmineup_money,
43
+ html: { class: 'icon icon-redminecrm-money' })
44
+
45
+ end
46
+
47
+ # Lookup a currency with given +id+ an returns a +Currency+ instance on
48
+ # success, +nil+ otherwise.
49
+ #
50
+ # @param [String, Symbol, #to_s] id Used to look into +table+ and
51
+ # retrieve the applicable attributes.
52
+ #
53
+ # @return [Money::Currency]
54
+ #
55
+ # @example
56
+ # Money::Currency.find(:eur) #=> #<Money::Currency id: eur ...>
57
+ # Money::Currency.find(:foo) #=> nil
58
+ def find(id)
59
+ return nil if id == ""
60
+ id = id.to_s.downcase.to_sym
61
+ new(id)
62
+ rescue UnknownCurrency
63
+ nil
64
+ end
65
+
66
+ # Lookup a currency with given +num+ as an ISO 4217 numeric and returns an
67
+ # +Currency+ instance on success, +nil+ otherwise.
68
+ #
69
+ # @param [#to_s] num used to look into +table+ in +iso_numeric+ and find
70
+ # the right currency id.
71
+ #
72
+ # @return [Money::Currency]
73
+ #
74
+ # @example
75
+ # Money::Currency.find_by_iso_numeric(978) #=> #<Money::Currency id: eur ...>
76
+ # Money::Currency.find_by_iso_numeric('001') #=> nil
77
+ def find_by_iso_numeric(num)
78
+ num = num.to_s
79
+ id, _ = self.table.find{|key, currency| currency[:iso_numeric] == num}
80
+ new(id)
81
+ rescue UnknownCurrency
82
+ nil
83
+ end
84
+
85
+ # Wraps the object in a +Currency+ unless it's already a +Currency+
86
+ # object.
87
+ #
88
+ # @param [Object] object The object to attempt and wrap as a +Currency+
89
+ # object.
90
+ #
91
+ # @return [Money::Currency]
92
+ #
93
+ # @example
94
+ # c1 = Money::Currency.new(:usd)
95
+ # Money::Currency.wrap(nil) #=> nil
96
+ # Money::Currency.wrap(c1) #=> #<Money::Currency id: usd ...>
97
+ # Money::Currency.wrap("usd") #=> #<Money::Currency id: usd ...>
98
+ def wrap(object)
99
+ if object.nil?
100
+ nil
101
+ elsif object.is_a?(Currency)
102
+ object
103
+ else
104
+ Currency.new(object)
105
+ end
106
+ end
107
+
108
+ # List of known currencies.
109
+ #
110
+ # == monetary unit
111
+ # The standard unit of value of a currency, as the dollar in the United States or the peso in Mexico.
112
+ # http://www.answers.com/topic/monetary-unit
113
+ # == fractional monetary unit, subunit
114
+ # A monetary unit that is valued at a fraction (usually one hundredth) of the basic monetary unit
115
+ # http://www.answers.com/topic/fractional-monetary-unit-subunit
116
+ #
117
+ # See http://en.wikipedia.org/wiki/List_of_circulating_currencies and
118
+ # http://search.cpan.org/~tnguyen/Locale-Currency-Format-1.28/Format.pm
119
+ def table
120
+ @table ||= load_currencies
121
+ end
122
+
123
+ # List the currencies imported and registered
124
+ # @return [Array]
125
+ #
126
+ # @example
127
+ # Money::Currency.iso_codes()
128
+ # [#<Currency ..USD>, 'CAD', 'EUR']...
129
+ def all
130
+ table.keys.map do |curr|
131
+ c = Currency.new(curr)
132
+ if c.priority.nil?
133
+ raise MissingAttributeError.new(:all, c.id, :priority)
134
+ end
135
+ c
136
+ end.sort_by(&:priority)
137
+ end
138
+
139
+ # We need a string-based validator before creating an unbounded number of
140
+ # symbols.
141
+ # http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol#11
142
+ # https://github.com/RubyMoney/money/issues/132
143
+ #
144
+ # @return [Set]
145
+ def stringified_keys
146
+ @stringified_keys ||= stringify_keys
147
+ end
148
+
149
+ # Register a new currency
150
+ #
151
+ # @param curr [Hash] information about the currency
152
+ # @option priority [Numeric] a numerical value you can use to sort/group
153
+ # the currency list
154
+ # @option iso_code [String] the international 3-letter code as defined
155
+ # by the ISO 4217 standard
156
+ # @option iso_numeric [Integer] the international 3-digit code as
157
+ # defined by the ISO 4217 standard
158
+ # @option name [String] the currency name
159
+ # @option symbol [String] the currency symbol (UTF-8 encoded)
160
+ # @option subunit [String] the name of the fractional monetary unit
161
+ # @option subunit_to_unit [Numeric] the proportion between the unit and
162
+ # the subunit
163
+ # @option separator [String] character between the whole and fraction
164
+ # amounts
165
+ # @option delimiter [String] character between each thousands place
166
+ def register(curr)
167
+ key = curr.fetch(:iso_code).downcase.to_sym
168
+ table if !@table
169
+ @table[key] = curr
170
+ @stringified_keys = stringify_keys
171
+ end
172
+
173
+
174
+ # Unregister a currency.
175
+ #
176
+ # @param [Object] curr A Hash with the key `:iso_code`, or the ISO code
177
+ # as a String or Symbol.
178
+ #
179
+ # @return [Boolean] true if the currency previously existed, false
180
+ # if it didn't.
181
+ def unregister(curr)
182
+ if curr.is_a?(Hash)
183
+ key = curr.fetch(:iso_code).to_s.downcase.to_sym
184
+ else
185
+ key = curr.to_s.downcase.to_sym
186
+ end
187
+ existed = @table.delete(key)
188
+ @stringified_keys = stringify_keys
189
+ existed ? true : false
190
+ end
191
+
192
+
193
+ def each
194
+ all.each { |c| yield(c) }
195
+ end
196
+
197
+ private
198
+
199
+ def stringify_keys
200
+ table.keys.each_with_object(Set.new) { |k, set| set.add(k.to_s.downcase) }
201
+ end
202
+ end
203
+
204
+ # @!attribute [r] id
205
+ # @return [Symbol] The symbol used to identify the currency, usually THE
206
+ # lowercase +iso_code+ attribute.
207
+ # @!attribute [r] priority
208
+ # @return [Integer] A numerical value you can use to sort/group the
209
+ # currency list.
210
+ # @!attribute [r] iso_code
211
+ # @return [String] The international 3-letter code as defined by the ISO
212
+ # 4217 standard.
213
+ # @!attribute [r] iso_numeric
214
+ # @return [String] The international 3-numeric code as defined by the ISO
215
+ # 4217 standard.
216
+ # @!attribute [r] name
217
+ # @return [String] The currency name.
218
+ # @!attribute [r] symbol
219
+ # @return [String] The currency symbol (UTF-8 encoded).
220
+ # @!attribute [r] disambiguate_symbol
221
+ # @return [String] Alternative currency used if symbol is ambiguous
222
+ # @!attribute [r] html_entity
223
+ # @return [String] The html entity for the currency symbol
224
+ # @!attribute [r] subunit
225
+ # @return [String] The name of the fractional monetary unit.
226
+ # @!attribute [r] subunit_to_unit
227
+ # @return [Integer] The proportion between the unit and the subunit
228
+ # @!attribute [r] decimal_mark
229
+ # @return [String] The decimal mark, or character used to separate the
230
+ # whole unit from the subunit.
231
+ # @!attribute [r] The
232
+ # @return [String] character used to separate thousands grouping of the
233
+ # whole unit.
234
+ # @!attribute [r] symbol_first
235
+ # @return [Boolean] Should the currency symbol precede the amount, or
236
+ # should it come after?
237
+ # @!attribute [r] smallest_denomination
238
+ # @return [Integer] Smallest amount of cash possible (in the subunit of
239
+ # this currency)
240
+
241
+ attr_reader :id, :priority, :iso_code, :iso_numeric, :name, :symbol,
242
+ :disambiguate_symbol, :html_entity, :subunit, :subunit_to_unit, :decimal_mark,
243
+ :thousands_separator, :symbol_first, :smallest_denomination
244
+
245
+ alias_method :separator, :decimal_mark
246
+ alias_method :delimiter, :thousands_separator
247
+ alias_method :eql?, :==
248
+
249
+ # Create a new +Currency+ object.
250
+ #
251
+ # @param [String, Symbol, #to_s] id Used to look into +table+ and retrieve
252
+ # the applicable attributes.
253
+ #
254
+ # @return [Money::Currency]
255
+ #
256
+ # @example
257
+ # Money::Currency.new(:usd) #=> #<Money::Currency id: usd ...>
258
+ def initialize(id)
259
+ id = id.to_s.downcase
260
+ unless self.class.stringified_keys.include?(id)
261
+ raise UnknownCurrency, "Unknown currency '#{id}'"
262
+ end
263
+ @id = id.to_sym
264
+ initialize_data!
265
+ end
266
+
267
+ # Compares +self+ with +other_currency+ against the value of +priority+
268
+ # attribute.
269
+ #
270
+ # @param [Money::Currency] other_currency The currency to compare to.
271
+ #
272
+ # @return [-1,0,1] -1 if less than, 0 is equal to, 1 if greater than
273
+ #
274
+ # @example
275
+ # c1 = Money::Currency.new(:usd)
276
+ # c2 = Money::Currency.new(:jpy)
277
+ # c1 <=> c2 #=> 1
278
+ # c2 <=> c1 #=> -1
279
+ # c1 <=> c1 #=> 0
280
+ def <=>(other_currency)
281
+ # <=> returns nil when one of the values is nil
282
+ comparison = (self.priority <=> other_currency.priority || 0) rescue 0
283
+
284
+ if comparison == 0
285
+ self.id.to_s <=> other_currency.id.to_s
286
+ else
287
+ comparison
288
+ end
289
+ end
290
+
291
+ # Compares +self+ with +other_currency+ and returns +true+ if the are the
292
+ # same or if their +id+ attributes match.
293
+ #
294
+ # @param [Money::Currency] other_currency The currency to compare to.
295
+ #
296
+ # @return [Boolean]
297
+ #
298
+ # @example
299
+ # c1 = Money::Currency.new(:usd)
300
+ # c2 = Money::Currency.new(:jpy)
301
+ # c1 == c1 #=> true
302
+ # c1 == c2 #=> false
303
+ def ==(other_currency)
304
+ self.equal?(other_currency) || compare_ids(other_currency)
305
+ end
306
+
307
+ def compare_ids(other_currency)
308
+ other_currency_id = if other_currency.is_a?(Currency)
309
+ other_currency.id.to_s.downcase
310
+ else
311
+ other_currency.to_s.downcase
312
+ end
313
+ self.id.to_s.downcase == other_currency_id
314
+ end
315
+
316
+ private :compare_ids
317
+
318
+ # Returns a Fixnum hash value based on the +id+ attribute in order to use
319
+ # functions like & (intersection), group_by, etc.
320
+ #
321
+ # @return [Fixnum]
322
+ #
323
+ # @example
324
+ # Money::Currency.new(:usd).hash #=> 428936
325
+ def hash
326
+ id.hash
327
+ end
328
+
329
+ # Returns a human readable representation.
330
+ #
331
+ # @return [String]
332
+ #
333
+ # @example
334
+ # Money::Currency.new(:usd) #=> #<Currency id: usd ...>
335
+ def inspect
336
+ "#<#{self.class.name} id: #{id}, priority: #{priority}, symbol_first: #{symbol_first}, thousands_separator: #{thousands_separator}, html_entity: #{html_entity}, decimal_mark: #{decimal_mark}, name: #{name}, symbol: #{symbol}, subunit_to_unit: #{subunit_to_unit}, exponent: #{exponent}, iso_code: #{iso_code}, iso_numeric: #{iso_numeric}, subunit: #{subunit}, smallest_denomination: #{smallest_denomination}>"
337
+ end
338
+
339
+ # Returns a string representation corresponding to the upcase +id+
340
+ # attribute.
341
+ #
342
+ # --
343
+ # DEV: id.to_s.upcase corresponds to iso_code but don't use ISO_CODE for consistency.
344
+ #
345
+ # @return [String]
346
+ #
347
+ # @example
348
+ # Money::Currency.new(:usd).to_s #=> "USD"
349
+ # Money::Currency.new(:eur).to_s #=> "EUR"
350
+ def to_s
351
+ id.to_s.upcase
352
+ end
353
+
354
+ # Returns a string representation corresponding to the upcase +id+
355
+ # attribute. Useful in cases where only implicit conversions are made.
356
+ #
357
+ # @return [String]
358
+ #
359
+ # @example
360
+ # Money::Currency.new(:usd).to_str #=> "USD"
361
+ # Money::Currency.new(:eur).to_str #=> "EUR"
362
+ def to_str
363
+ id.to_s.upcase
364
+ end
365
+
366
+ # Returns a symbol representation corresponding to the upcase +id+
367
+ # attribute.
368
+ #
369
+ # @return [Symbol]
370
+ #
371
+ # @example
372
+ # Money::Currency.new(:usd).to_sym #=> :USD
373
+ # Money::Currency.new(:eur).to_sym #=> :EUR
374
+ def to_sym
375
+ id.to_s.upcase.to_sym
376
+ end
377
+
378
+ # Conversation to +self+.
379
+ #
380
+ # @return [self]
381
+ def to_currency
382
+ self
383
+ end
384
+
385
+ # Returns currency symbol or iso code for currencies with no symbol.
386
+ #
387
+ # @return [String]
388
+ def code
389
+ symbol || iso_code
390
+ end
391
+
392
+ def symbol_first?
393
+ !!@symbol_first
394
+ end
395
+
396
+ # Returns the number of digits after the decimal separator.
397
+ #
398
+ # @return [Float]
399
+ def exponent
400
+ Math.log10(@subunit_to_unit) if @subunit_to_unit
401
+ end
402
+
403
+ # Cache decimal places for subunit_to_unit values. Common ones pre-cached.
404
+ def self.decimal_places_cache
405
+ @decimal_places_cache ||= {1 => 0, 10 => 1, 100 => 2, 1000 => 3}
406
+ end
407
+
408
+ # The number of decimal places needed.
409
+ #
410
+ # @return [Integer]
411
+ def decimal_places
412
+ cache[subunit_to_unit] ||= calculate_decimal_places(subunit_to_unit)
413
+ end
414
+
415
+ private
416
+
417
+ def cache
418
+ self.class.decimal_places_cache
419
+ end
420
+
421
+ # If we need to figure out how many decimal places we need we
422
+ # use repeated integer division.
423
+ def calculate_decimal_places(num)
424
+ i = 1
425
+ while num >= 10
426
+ num /= 10
427
+ i += 1 if num >= 10
428
+ end
429
+ i
430
+ end
431
+
432
+ def initialize_data!
433
+ data = self.class.table[@id]
434
+ @alternate_symbols = data[:alternate_symbols]
435
+ @decimal_mark = data[:decimal_mark]
436
+ @disambiguate_symbol = data[:disambiguate_symbol]
437
+ @html_entity = data[:html_entity]
438
+ @iso_code = data[:iso_code]
439
+ @iso_numeric = data[:iso_numeric]
440
+ @name = data[:name]
441
+ @priority = data[:priority]
442
+ @smallest_denomination = data[:smallest_denomination]
443
+ @subunit = data[:subunit]
444
+ @subunit_to_unit = data[:subunit_to_unit]
445
+ @symbol = data[:symbol]
446
+ @symbol_first = data[:symbol_first]
447
+ @thousands_separator = data[:thousands_separator]
448
+ end
449
+ end
450
+ end
@@ -0,0 +1,4 @@
1
+ module Redmineup
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module Redmineup
2
+ module ExternalAssetsHelper
3
+ include ActionView::Helpers::JavaScriptHelper
4
+
5
+ def select2_assets
6
+ return if @select2_tag_included
7
+ @select2_tag_included = true
8
+ javascript_include_tag('select2', plugin: GEM_NAME) +
9
+ stylesheet_link_tag('select2', plugin: GEM_NAME) +
10
+ javascript_include_tag('select2_helpers', plugin: GEM_NAME)
11
+ end
12
+
13
+ def chartjs_assets
14
+ return if @chartjs_tag_included
15
+ @chartjs_tag_included = true
16
+ javascript_include_tag('Chart.bundle.min', plugin: GEM_NAME)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,88 @@
1
+ module Redmineup
2
+ module FormTagHelper
3
+ # Allows include select2 into your views.
4
+ #
5
+ # ==== Examples
6
+ # select2_tag 'city_id', '<option value="1">Lisbon</option>...'
7
+ # select2_tag 'city_id', options_for_select(...)
8
+ # select2_tag 'tag_list', nil, :multiple => true, :data => [{ id: 0, text: 'deal' }, ...], :tags => true, :include_hidden => false %>
9
+ # select2_tag 'tag_list', options_for_select(...), :multiple => true, :style => 'width: 100%;', :url => '/tags', :placeholder => '+ add tag', :tags => true %>
10
+ #
11
+ # You may use select_tag options and additional options.
12
+ #
13
+ # ==== Additional options
14
+ # * <tt>:url</tt> Allows searches for remote data using the ajax.
15
+ # * <tt>:data</tt> Load dropdown options from a local array if +url+ option not set.
16
+ # * <tt>:placeholder</tt> Supports displaying a placeholder value.
17
+ # * <tt>:include_hidden</tt> Adds hidden field after select when +multiple+ option true. Default value true.
18
+ # * <tt>:allow_clear</tt> Provides support for clearable selections. Default value false.
19
+ # * <tt>:min_input_length</tt> Minimum number of characters required to start a search. Default value 0.
20
+ # * <tt>:format_state</tt> Defines template of search results in the drop-down.
21
+ # * <tt>:tags</tt> Used to enable tagging feature.
22
+ #
23
+ # <b>Note:</b> The HTML specification says when +multiple+ parameter passed to select and all options got deselected
24
+ # web browsers do not send any value to server.
25
+ #
26
+ # In case if you don't want the helper to generate this hidden field you can specify
27
+ # <tt>include_hidden: false</tt> option.
28
+ #
29
+ # <b>Note:</b> Select2 assets must be available on a page.
30
+ # To include select2 assets to a page, you need to use the helper select2_assets.
31
+ # For example:
32
+ # <% content_for :header_tags do %>
33
+ # <%= select2_assets %>
34
+ # <% end %>
35
+ #
36
+ # Also aliased as: select2
37
+ #
38
+ # select2 'city_id', options_for_select(...)
39
+ #
40
+ def select2_tag(name, option_tags = nil, options = {})
41
+ s = select_tag(name, option_tags, options)
42
+
43
+ if options[:multiple] && options.fetch(:include_hidden, true)
44
+ s << hidden_field_tag("#{name}[]", '')
45
+ end
46
+
47
+ s + javascript_tag("select2Tag('#{sanitize_to_id(name)}', #{options.to_json});")
48
+ end
49
+
50
+ alias select2 select2_tag
51
+
52
+ # Transforms select filters of +type+ fields into select2
53
+ #
54
+ # ==== Examples
55
+ # transform_to_select2 'tags', url: auto_complete_tags_url
56
+ # transform_to_select2 'people', format_state: 'formatStateWithAvatar', min_input_length: 1, url: '/managers'
57
+ #
58
+ # ==== Options
59
+ # * <tt>:url</tt> Defines URL to search remote data using the ajax.
60
+ # * <tt>:format_state</tt> Defines template of search results in the drop-down.
61
+ # * <tt>:min_input_length</tt> Minimum number of characters required to start a search. Default value 0.
62
+ # * <tt>:width</tt> Sets the width of the control. Default value '60%'.
63
+ # * <tt>:multiple</tt> Supports multi-value select box. If set to false the selection will not allow multiple choices. Default value true.
64
+ #
65
+ # <b>Note:</b> Select2 assets must be available on a page.
66
+ # To include select2 assets to a page, you need to use the helper select2_assets.
67
+ # For example:
68
+ # <% content_for :header_tags do %>
69
+ # <%= select2_assets %>
70
+ # <% end %>
71
+ #
72
+ def transform_to_select2(type, options = {})
73
+ javascript_tag("setSelect2Filter('#{type}', #{options.to_json});") unless type.empty?
74
+ end
75
+
76
+ def format_datetime(time)
77
+ formated_time = format_time(time, false)
78
+ formated_date = ::I18n.l(time.to_date, format: '%Y-%m-%d')
79
+ "#{formated_date} #{formated_time}"
80
+ end
81
+
82
+ def format_datetime_date(time)
83
+ formated_date = ::I18n.l(time.to_date, format: '%Y-%m-%d')
84
+ "#{formated_date}"
85
+ end
86
+
87
+ end
88
+ end