activeadmin_addons 0.2.7 → 0.2.8

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: 1110538781573fbe7162c64b28bfcb58018505c4
4
- data.tar.gz: 51fad730b2eb10c3c0c1dc810813556abe53d52f
3
+ metadata.gz: 86137e56876a2c8cd92c7a5426a2d30d68e52106
4
+ data.tar.gz: 27ec4aae8a07fcebab1cf94ea4f08400e20ba2ef
5
5
  SHA512:
6
- metadata.gz: 0024e1722cb4a43d3a918e34dc22e8f12a3576ed5db1f626b9972ebb8a5cf67175a5e3ac4541096efb8af558df689b787aabe257fe92057a252b66e3f8d2900d
7
- data.tar.gz: d0de9005c672a8a642830b91a389163231e3c3f1c2d529e4f00e955e23c12d7bbb54c87fa87ccf46a3f06ab2bc422295b24bde870f1ebab8c40f1cafaac0f33f
6
+ metadata.gz: 5fc25ec8546c1c0176a2eaadb5646b0d0f0d62a6324816aa354c3c117a9ec9b1d51145a4df991171349b8005965a0e16783ec3a03d00674492f98b39f9770f1b
7
+ data.tar.gz: d17dfcde0451c88c888cd4fb24c39f944f28ba3e93275c2b0d76a35297d1f909bee9f241cf9f90f9721aedd77f0945edb28f1490db518777eec27e2ed7e257af
@@ -31,6 +31,7 @@ $(function() {
31
31
  var url = $(el).data('url');
32
32
  var fields = $(el).data('fields');
33
33
  var displayName = $(el).data('display_name');
34
+ var minimumInputLength = $(el).data('minimum_input_length');
34
35
  var order = fields[0] + "_desc";
35
36
 
36
37
  $(el).select2({
@@ -70,7 +71,7 @@ $(function() {
70
71
  },
71
72
  cache: true
72
73
  },
73
- minimumInputLength: 1
74
+ minimumInputLength: minimumInputLength
74
75
  });
75
76
  });
76
77
  }
@@ -1 +1,13 @@
1
1
  @import "select2";
2
+
3
+ .filter_range_select {
4
+ input[type=number] {
5
+ padding-right: 0px;
6
+ width: 96px;
7
+ }
8
+ .separator {
9
+ display: inline-block;
10
+ text-align: center;
11
+ width: 12px;
12
+ }
13
+ }
@@ -0,0 +1,35 @@
1
+ class RangeSelectInput < Formtastic::Inputs::StringInput
2
+ include ActiveAdmin::Inputs::Filters::Base
3
+
4
+ def to_html
5
+ input_wrapping do
6
+ [
7
+ label_html,
8
+ builder.text_field(gt_input_name, input_html_options(gt_input_name)),
9
+ template.content_tag(:span, "-", class: "separator"),
10
+ builder.text_field(lt_input_name, input_html_options(lt_input_name)),
11
+ ].join("\n").html_safe
12
+ end
13
+ end
14
+
15
+ def gt_input_name
16
+ "#{method}_gteq"
17
+ end
18
+
19
+ alias :input_name :gt_input_name
20
+
21
+ def lt_input_name
22
+ "#{method}_lteq"
23
+ end
24
+
25
+ def input_html_options(input_name = gt_input_name)
26
+ is_gt = (input_name == gt_input_name)
27
+
28
+ {
29
+ type: "number",
30
+ step: "any",
31
+ value: @object.public_send(input_name),
32
+ placeholder: is_gt ? "min" : "max"
33
+ }
34
+ end
35
+ end
@@ -6,6 +6,7 @@ class SearchSelectInput < Formtastic::Inputs::StringInput
6
6
  opts["data-fields"] = (@options[:fields] || []).to_json
7
7
  opts["data-url"] = @options[:url] || ""
8
8
  opts["data-display_name"] = @options[:display_name] || "name"
9
+ opts["data-minimum_input_length"] = @options[:minimum_input_length] || 1
9
10
  opts["data-selected"] = relation.try(opts["data-display_name"].to_sym)
10
11
  super.merge opts
11
12
  end
@@ -16,10 +16,18 @@ module ActiveAdminAddons
16
16
  def i18n_lookup(key, last_default)
17
17
  model_name = model.class.model_name.i18n_key
18
18
 
19
- model_i18n = "activeadmin.addons.boolean.models.#{model_name}.#{key}"
20
- default_i18n = "activeadmin.addons.boolean.default.#{key}"
19
+ scope = "activeadmin.addons.boolean"
20
+ value = I18n.t("models.#{model_name}.#{attribute}.#{key}", default: '', scope: scope)
21
+ value = I18n.t("models.#{model_name}.#{key}", default: '', scope: scope) if value.empty?
22
+ value = I18n.t("default.#{key}", default: last_default, scope: scope) if value.empty?
21
23
 
22
- I18n.t(model_i18n, default: I18n.t(default_i18n, default: last_default)).html_safe
24
+ value.html_safe
25
+
26
+ #
27
+ # model_i18n = "activeadmin.addons.boolean.models.#{model_name}.#{key}"
28
+ # default_i18n = "activeadmin.addons.boolean.default.#{key}"
29
+ #
30
+ # I18n.t(model_i18n, default: I18n.t(default_i18n, default: last_default)).html_safe
23
31
  end
24
32
  end
25
33
 
@@ -1,10 +1,20 @@
1
1
  module ActiveAdminAddons
2
2
  class EnumBuilder < CustomBuilder
3
+
3
4
  def render
4
- raise 'you need to install enumerize gem first' unless defined? Enumerize::Value
5
- raise 'you need to pass an enumerize attribute' unless data.is_a?('Enumerize::Value'.constantize)
6
- context.status_tag(data.text, data)
5
+ @is_enum = false
6
+ @is_enum = :enumerize if data.is_a?('Enumerize::Value'.constantize)
7
+ if defined? Rails && Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 1
8
+ @is_enum = :enum if model.defined_enums[attribute.to_s]
9
+ end
10
+ raise 'you need to pass an enumerize or enum attribute' unless @is_enum
11
+ context.status_tag(display_data, data)
7
12
  end
13
+
14
+ def display_data
15
+ @is_enum == :enumerize ? data.text : data
16
+ end
17
+
8
18
  end
9
19
 
10
20
  module ::ActiveAdmin
@@ -13,7 +13,7 @@ module ActiveAdminAddons
13
13
  def render
14
14
  options[:as] = options.fetch(:as, :delimiter)
15
15
  if !NUMBER_TYPES.keys.include?(options[:as])
16
- raise "Invalid number type. Options are: #{NUMBER_TYPES.keys.to_s}"
16
+ raise "Invalid number type. Options are: #{NUMBER_TYPES.keys}"
17
17
  end
18
18
  context.send(NUMBER_TYPES[options[:as]], data, options)
19
19
  end
@@ -1,40 +1,44 @@
1
1
  module ActiveAdminAddons
2
2
  class PaperclipAttachmentBuilder < CustomBuilder
3
3
  KNOWN_EXTENSIONS = %w{
4
- 3gp 7z ace ai aif aiff amr asf asx bat bin bmp bup cab cbr cda cdl cdr chm
5
- dat divx dll dmg doc docx dss dvf dwg eml eps exe fla flv gif gz hqx htm html
6
- ifo indd iso jar jpeg jpg lnk log m4a m4b m4p m4v mcd mdb mid mov mp2 mp4
7
- mpeg mpg msi mswmm ogg pdf png pps ppt pptx ps psd pst ptb pub qbb qbw qxd ram
8
- rar rm rmvb rtf sea ses sit sitx ss swf tgz thm tif tmp torrent ttf txt
9
- vcd vob wav wma wmv wps xls xlsx xpi zip
4
+ 3gp 7z ace ai aif aiff amr asf asx bat bin bmp bup cab cbr cda cdl cdr chm
5
+ dat divx dll dmg doc docx dss dvf dwg eml eps exe fla flv gif gz hqx htm html
6
+ ifo indd iso jar jpeg jpg lnk log m4a m4b m4p m4v mcd mdb mid mov mp2 mp4
7
+ mpeg mpg msi mswmm ogg pdf png pps ppt pptx ps psd pst ptb pub qbb qbw qxd ram
8
+ rar rm rmvb rtf sea ses sit sitx ss swf tgz thm tif tmp torrent ttf txt
9
+ vcd vob wav wma wmv wps xls xlsx xpi zip
10
10
  }
11
11
 
12
- def icon_for_filename filename
12
+ def icon_for_filename(filename)
13
13
  for_ext File.extname(filename.to_s)
14
14
  end
15
15
 
16
- def for_ext file_extension
16
+ def for_ext(file_extension)
17
17
  ext = file_extension.start_with?('.') ? file_extension[1..-1] : file_extension
18
18
  ext.downcase!
19
19
  ext = "unknown" unless KNOWN_EXTENSIONS.include?(ext)
20
20
  "fileicons/file_extension_#{ext}.png"
21
21
  end
22
22
 
23
- def render
24
- raise 'you need to pass a paperclip attribute' unless data.respond_to?(:url)
25
- options[:truncate] = options.fetch(:truncate, true)
26
- return nil unless data.exists?
27
-
23
+ def build_label
28
24
  icon = icon_for_filename(data.original_filename)
29
- icon_img = context.image_tag(icon, width: "20", height: "20", style: "margin-right: 5px; vertical-align: middle;")
30
- file_name = (options[:truncate] == true) ? context.truncate(data.original_filename) : data.original_filename
25
+ style = { width: "20", height: "20", style: "margin-right: 5px; vertical-align: middle;" }
26
+ icon_img = context.image_tag(icon, style)
27
+ file_name = data.original_filename
28
+ file_name = context.truncate(data.original_filename) if options[:truncate] == true
31
29
  label_text = options.fetch(:label, file_name)
32
- label = context.content_tag(:span) do
30
+
31
+ context.content_tag(:span) do
33
32
  context.concat(icon_img)
34
33
  context.safe_concat(label_text)
35
34
  end
35
+ end
36
36
 
37
- context.link_to(label, data.url, { target: "_blank" })
37
+ def render
38
+ raise 'you need to pass a paperclip attribute' unless data.respond_to?(:url)
39
+ options[:truncate] = options.fetch(:truncate, true)
40
+ return nil unless data.exists?
41
+ context.link_to(build_label, data.url, target: "_blank", class: "attachment-link")
38
42
  end
39
43
  end
40
44
 
@@ -0,0 +1,48 @@
1
+ module ActiveAdminAddons
2
+ class StateBuilder < CustomBuilder
3
+ DEFAULT_CLASS_BINDINGS = {
4
+ accepted: "ok",
5
+ confirmed: "ok",
6
+ ready: "ok",
7
+ rejected: "error",
8
+ canceled: "error"
9
+ }
10
+
11
+ def render
12
+ raise 'you need to install AASM gem first' unless defined? AASM
13
+ raise "the #{attribute} is not an AASM state" unless state_attribute?
14
+ context.status_tag(model.aasm.human_state, status_class_for_model)
15
+ end
16
+
17
+ private
18
+
19
+ def state_attribute?
20
+ model.class.respond_to?(:aasm) &&
21
+ attribute.present? &&
22
+ model.class.aasm.attribute_name == attribute.to_sym
23
+ end
24
+
25
+ def status_class_for_model
26
+ class_bindings[data.to_sym] || data
27
+ end
28
+
29
+ def class_bindings
30
+ @class_bindings ||= DEFAULT_CLASS_BINDINGS.merge(options[:states] || {})
31
+ end
32
+ end
33
+
34
+ module ::ActiveAdmin
35
+ module Views
36
+ class TableFor
37
+ def state_column(*args, &block)
38
+ column(*args) { |model| StateBuilder.render(self, model, *args, &block) }
39
+ end
40
+ end
41
+ class AttributesTable
42
+ def state_row(*args, &block)
43
+ row(*args) { |model| StateBuilder.render(self, model, *args, &block) }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,6 +8,7 @@ module ActiveAdminAddons
8
8
  require_relative './addons/paperclip_image'
9
9
  require_relative './addons/paperclip_attachment'
10
10
  require_relative './addons/enum_tag'
11
+ require_relative './addons/state_values'
11
12
  require_relative './addons/number'
12
13
  require_relative './addons/list'
13
14
  require_relative './support/enumerize_formtastic_support'
@@ -43,6 +43,5 @@ module ActiveAdminAddons
43
43
  def has_opts?
44
44
  @has_opts ||= args.last.is_a?(Hash)
45
45
  end
46
-
47
46
  end
48
47
  end
@@ -1,15 +1,13 @@
1
1
  module ::Formtastic
2
2
  module Helpers
3
3
  module InputHelper
4
+ alias_method :original_default_input_type, :default_input_type
4
5
 
5
- alias_method :original_default_input_type, :default_input_type
6
-
7
- def default_input_type(method, options = {})
8
- input_type = original_default_input_type(method, options)
9
- input_type = :datepicker if input_type == :date_select
10
- input_type
11
- end
12
-
6
+ def default_input_type(method, options = {})
7
+ input_type = original_default_input_type(method, options)
8
+ input_type = :datepicker if input_type == :date_select
9
+ input_type
10
+ end
13
11
  end
14
12
  end
15
13
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveadminAddons
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
metadata CHANGED
@@ -1,97 +1,237 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_addons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Platanus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: select2-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 3.5.9
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.5.9
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec-rails
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '>='
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl_rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 4.4.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 4.4.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: shoulda-matchers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.6.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.6.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.7.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.7.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: capybara
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
60
158
  - !ruby/object:Gem::Version
61
159
  version: '0'
62
160
  type: :development
63
161
  prerelease: false
64
162
  version_requirements: !ruby/object:Gem::Requirement
65
163
  requirements:
66
- - - '>='
164
+ - - ">="
67
165
  - !ruby/object:Gem::Version
68
166
  version: '0'
69
167
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
168
+ name: enumerize
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: paperclip
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: selenium-webdriver
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: poltergeist
71
211
  requirement: !ruby/object:Gem::Requirement
72
212
  requirements:
73
- - - '>='
213
+ - - ">="
74
214
  - !ruby/object:Gem::Version
75
215
  version: '0'
76
216
  type: :development
77
217
  prerelease: false
78
218
  version_requirements: !ruby/object:Gem::Requirement
79
219
  requirements:
80
- - - '>='
220
+ - - ">="
81
221
  - !ruby/object:Gem::Version
82
222
  version: '0'
83
223
  - !ruby/object:Gem::Dependency
84
- name: pry
224
+ name: database_cleaner
85
225
  requirement: !ruby/object:Gem::Requirement
86
226
  requirements:
87
- - - '>='
227
+ - - ">="
88
228
  - !ruby/object:Gem::Version
89
229
  version: '0'
90
230
  type: :development
91
231
  prerelease: false
92
232
  version_requirements: !ruby/object:Gem::Requirement
93
233
  requirements:
94
- - - '>='
234
+ - - ">="
95
235
  - !ruby/object:Gem::Version
96
236
  version: '0'
97
237
  description: Set of addons to help with the activeadmin ui
@@ -209,6 +349,7 @@ files:
209
349
  - app/assets/javascripts/activeadmin_addons/all.js.coffee
210
350
  - app/assets/javascripts/activeadmin_addons/select2.js
211
351
  - app/assets/stylesheets/activeadmin_addons/all.css.scss
352
+ - app/inputs/range_select_input.rb
212
353
  - app/inputs/search_select_input.rb
213
354
  - app/inputs/tags_input.rb
214
355
  - lib/activeadmin_addons.rb
@@ -218,6 +359,7 @@ files:
218
359
  - lib/activeadmin_addons/addons/number.rb
219
360
  - lib/activeadmin_addons/addons/paperclip_attachment.rb
220
361
  - lib/activeadmin_addons/addons/paperclip_image.rb
362
+ - lib/activeadmin_addons/addons/state_values.rb
221
363
  - lib/activeadmin_addons/engine.rb
222
364
  - lib/activeadmin_addons/support/custom_builder.rb
223
365
  - lib/activeadmin_addons/support/enumerize_formtastic_support.rb
@@ -234,17 +376,17 @@ require_paths:
234
376
  - lib
235
377
  required_ruby_version: !ruby/object:Gem::Requirement
236
378
  requirements:
237
- - - '>='
379
+ - - ">="
238
380
  - !ruby/object:Gem::Version
239
381
  version: '0'
240
382
  required_rubygems_version: !ruby/object:Gem::Requirement
241
383
  requirements:
242
- - - '>='
384
+ - - ">="
243
385
  - !ruby/object:Gem::Version
244
386
  version: '0'
245
387
  requirements: []
246
388
  rubyforge_project:
247
- rubygems_version: 2.4.8
389
+ rubygems_version: 2.4.5
248
390
  signing_key:
249
391
  specification_version: 4
250
392
  summary: Set of addons to help with the activeadmin ui