avo 2.5.2.pre.6 → 2.6.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +8 -1
  4. data/app/assets/builds/action_cable.js +2 -0
  5. data/app/assets/builds/action_cable.js.map +7 -0
  6. data/app/assets/builds/avo.css +725 -203
  7. data/app/assets/builds/avo.js +211 -122
  8. data/app/assets/builds/avo.js.map +3 -3
  9. data/app/assets/stylesheets/avo.css +2 -0
  10. data/app/assets/stylesheets/css/tags.css +16 -0
  11. data/app/components/avo/actions_component.html.erb +1 -1
  12. data/app/components/avo/button_component.rb +8 -14
  13. data/app/components/avo/card_component.rb +12 -0
  14. data/app/components/avo/fields/belongs_to_field/autocomplete_component.html.erb +2 -0
  15. data/app/components/avo/fields/concerns/item_labels.rb +40 -0
  16. data/app/components/avo/fields/tags_field/edit_component.html.erb +27 -0
  17. data/app/components/avo/fields/tags_field/edit_component.rb +4 -0
  18. data/app/components/avo/fields/tags_field/index_component.html.erb +10 -0
  19. data/app/components/avo/fields/tags_field/index_component.rb +9 -0
  20. data/app/components/avo/fields/tags_field/show_component.html.erb +7 -0
  21. data/app/components/avo/fields/tags_field/show_component.rb +7 -0
  22. data/app/components/avo/fields/tags_field/tag_component.html.erb +9 -0
  23. data/app/components/avo/fields/tags_field/tag_component.rb +11 -0
  24. data/app/components/avo/index/resource_table_component.html.erb +1 -1
  25. data/app/components/avo/paginator_component.html.erb +2 -2
  26. data/app/components/avo/sidebar_component.html.erb +1 -1
  27. data/app/components/avo/sidebar_profile_component.html.erb +1 -1
  28. data/app/controllers/avo/base_controller.rb +0 -19
  29. data/app/controllers/avo/search_controller.rb +11 -4
  30. data/app/javascript/js/application.js +1 -1
  31. data/app/javascript/js/controllers/base_controller.js +22 -0
  32. data/app/javascript/js/controllers/fields/tags_field_controller.js +86 -0
  33. data/app/javascript/js/controllers/fields/tags_field_helpers.js +47 -0
  34. data/app/javascript/js/controllers/search_controller.js +7 -1
  35. data/app/javascript/js/controllers.js +2 -0
  36. data/app/views/avo/dashboards/_chartkick_card.html.erb +1 -1
  37. data/app/views/avo/dashboards/_metric_card.html.erb +1 -1
  38. data/app/views/avo/partials/_global_search.html.erb +1 -1
  39. data/app/views/avo/partials/_navbar.html.erb +3 -3
  40. data/app/views/avo/partials/_resource_search.html.erb +1 -1
  41. data/db/factories.rb +2 -0
  42. data/lib/avo/base_resource.rb +6 -0
  43. data/lib/avo/concerns/handles_field_args.rb +36 -0
  44. data/lib/avo/fields/base_field.rb +2 -1
  45. data/lib/avo/fields/tags_field.rb +82 -0
  46. data/lib/avo/hosts/association_scope_host.rb +1 -0
  47. data/lib/avo/hosts/base_host.rb +2 -0
  48. data/lib/avo/hosts/record_host.rb +7 -0
  49. data/lib/avo/licensing/pro_license.rb +2 -1
  50. data/lib/avo/version.rb +1 -1
  51. data/lib/generators/avo/templates/cards/chartkick_card.tt +1 -1
  52. data/lib/generators/avo/templates/cards/chartkick_card_sample.tt +1 -1
  53. data/lib/generators/avo/templates/cards/metric_card.tt +1 -1
  54. data/lib/generators/avo/templates/cards/metric_card_sample.tt +1 -1
  55. data/lib/generators/avo/templates/locales/avo.en.yml +4 -0
  56. data/lib/tasks/avo_tasks.rake +7 -3
  57. data/public/avo-assets/avo.css +694 -78
  58. data/public/avo-assets/avo.js +211 -122
  59. data/public/avo-assets/avo.js.map +3 -3
  60. metadata +20 -2
@@ -0,0 +1,36 @@
1
+ module Avo
2
+ module Concerns
3
+ module HandlesFieldArgs
4
+ extend ActiveSupport::Concern
5
+
6
+ private
7
+
8
+ # Add an instance variable from args
9
+ # That may be a string, boolean, or array
10
+ # Each args should also have a default value
11
+ def add_prop_from_args(args = {}, name: nil, type: :string, default: nil)
12
+ value = default
13
+
14
+ if type == :boolean
15
+ value = args[name.to_sym] == true
16
+ else
17
+ value = args[name.to_sym] unless args.dig(name.to_sym).nil?
18
+ end
19
+
20
+ instance_variable_set(:"@#{name}", value)
21
+ end
22
+
23
+ def add_boolean_prop(args, name, default = false)
24
+ add_prop_from_args args, name: name, default: default, type: :boolean
25
+ end
26
+
27
+ def add_array_prop(args, name, default = [])
28
+ add_prop_from_args args, name: name, default: default, type: :array
29
+ end
30
+
31
+ def add_string_prop(args, name, default = [])
32
+ add_prop_from_args args, name: name, default: default, type: :string
33
+ end
34
+ end
35
+ end
36
+ end
@@ -4,8 +4,9 @@ module Avo
4
4
  extend ActiveSupport::DescendantsTracker
5
5
  extend Avo::Fields::FieldExtensions::HasFieldName
6
6
 
7
- include ActionView::Helpers::UrlHelper
8
7
  include Avo::Fields::FieldExtensions::VisibleInDifferentViews
8
+ include Avo::Concerns::HandlesFieldArgs
9
+ include ActionView::Helpers::UrlHelper
9
10
 
10
11
  delegate :view_context, to: "Avo::App"
11
12
  delegate :main_app, to: :view_context
@@ -0,0 +1,82 @@
1
+ module Avo
2
+ module Fields
3
+ class TagsField < BaseField
4
+ attr_reader :acts_as_taggable_on
5
+ attr_reader :close_on_select
6
+ attr_reader :delimiters
7
+ attr_reader :enforce_suggestions
8
+
9
+ def initialize(id, **args, &block)
10
+ super(id, **args, &block)
11
+
12
+ add_boolean_prop args, :close_on_select
13
+ add_boolean_prop args, :enforce_suggestions
14
+ add_string_prop args, :acts_as_taggable_on
15
+ add_array_prop args, :disallowed
16
+ add_array_prop args, :delimiters, [","]
17
+ add_array_prop args, :suggestions
18
+ end
19
+
20
+ def field_value
21
+ return json_value if acts_as_taggable_on.present?
22
+
23
+ value || []
24
+ end
25
+
26
+ def json_value
27
+ value.map do |item|
28
+ {
29
+ value: item.name
30
+ }
31
+ end.as_json
32
+ end
33
+
34
+ def fill_field(model, key, value, params)
35
+ if acts_as_taggable_on.present?
36
+ model.send(act_as_taggable_attribute(key), parsed_value(value))
37
+ else
38
+ model.send("#{key}=", parsed_value(value))
39
+ end
40
+
41
+ model
42
+ end
43
+
44
+ def suggestions
45
+ return @suggestions if @suggestions.is_a? Array
46
+
47
+ if @suggestions.respond_to? :call
48
+ return Avo::Hosts::RecordHost.new(block: @suggestions, record: model).handle
49
+ end
50
+
51
+ []
52
+ end
53
+
54
+ def disallowed
55
+ return @disallowed if @disallowed.is_a? Array
56
+
57
+ if @disallowed.respond_to? :call
58
+ return Avo::Hosts::RecordHost.new(block: @disallowed, record: model).handle
59
+ end
60
+
61
+ []
62
+ end
63
+
64
+ private
65
+
66
+ def act_as_taggable_attribute(key)
67
+ "#{key.singularize}_list="
68
+ end
69
+
70
+ def parsed_value(value)
71
+ JSON.parse(value).pluck("value")
72
+ rescue
73
+ []
74
+ end
75
+
76
+ private
77
+
78
+ def parse_suggestions_from_args(args)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -2,6 +2,7 @@ module Avo
2
2
  module Hosts
3
3
  class AssociationScopeHost < BaseHost
4
4
  option :parent
5
+ option :grandparent
5
6
  option :query
6
7
  end
7
8
  end
@@ -12,6 +12,8 @@ module Avo
12
12
  option :current_user, default: proc { Avo::App.current_user }
13
13
  option :block, optional: true
14
14
 
15
+ delegate :authorize, to: Avo::Services::AuthorizationService
16
+
15
17
  def handle
16
18
  instance_exec(&block)
17
19
  end
@@ -0,0 +1,7 @@
1
+ module Avo
2
+ module Hosts
3
+ class RecordHost < BaseHost
4
+ option :record
5
+ end
6
+ end
7
+ end
@@ -12,7 +12,8 @@ module Avo
12
12
  :searchable_associations,
13
13
  :resource_ordering,
14
14
  :dashboards,
15
- :menu_editor
15
+ :menu_editor,
16
+ :advanced_fields
16
17
  ]
17
18
  end
18
19
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.5.2.pre.6" unless const_defined?(:VERSION)
2
+ VERSION = "2.6.1.pre.1" unless const_defined?(:VERSION)
3
3
  end
@@ -3,7 +3,7 @@ class <%= class_name.camelize %> < Avo::Dashboards::ChartkickCard
3
3
  self.label = "<%= name.underscore.humanize %>"
4
4
  self.chart_type = :area_chart
5
5
 
6
- query do
6
+ def query
7
7
  data = 3.times.map do |index|
8
8
  {
9
9
  name: "Batch #{index}",
@@ -9,7 +9,7 @@ class <%= class_name.camelize %> < Avo::Dashboards::ChartkickCard
9
9
  # self.chart_options = { library: { plugins: { legend: { display: true } } } }
10
10
  # self.flush = true
11
11
 
12
- query do
12
+ def query
13
13
  points = 16
14
14
  i = Time.new.year.to_i - points
15
15
  base_data = Array.new(points).map do
@@ -2,7 +2,7 @@ class <%= class_name.camelize %> < Avo::Dashboards::MetricCard
2
2
  self.id = "<%= name.underscore %>"
3
3
  self.label = "<%= name.underscore.humanize %>"
4
4
 
5
- query do
5
+ def query
6
6
  result 101
7
7
  end
8
8
  end
@@ -8,7 +8,7 @@ class <%= class_name.camelize %> < Avo::Dashboards::MetricCard
8
8
  # self.prefix = ""
9
9
  # self.suffix = ""
10
10
 
11
- query do
11
+ def query
12
12
  # from = Date.today.midnight - 1.week
13
13
  # to = DateTime.current
14
14
 
@@ -39,6 +39,10 @@ en:
39
39
  zero: 'no %{item}'
40
40
  one: 'one %{item}'
41
41
  other: '%{count} %{item}'
42
+ x_items_more:
43
+ zero: 'no more items'
44
+ one: 'one more item'
45
+ other: '%{count} more items'
42
46
  are_you_sure: 'Are you sure?'
43
47
  filters: 'Filters'
44
48
  per_page: 'Per page'
@@ -5,11 +5,14 @@
5
5
 
6
6
  desc 'Installs Avo assets and bundles them for when you want to use the GitHub repo in your app'
7
7
  task 'avo:build-assets' do
8
+ spec = get_gem_spec 'avo'
9
+ # Uncomment to enable only when the source is github.com
10
+ # enabled = spec.source.to_s.include?('https://github.com/avo-hq/avo')
8
11
  enabled = true
9
12
 
10
13
  if enabled
11
14
  puts "Starting avo:build-assets"
12
- path = locate_gem 'avo'
15
+ path = spec.full_gem_path
13
16
 
14
17
  Dir.chdir(path) do
15
18
  system 'yarn'
@@ -24,11 +27,12 @@ end
24
27
 
25
28
  # From
26
29
  # https://stackoverflow.com/questions/9322078/programmatically-determine-gems-path-using-bundler
27
- def locate_gem(name)
30
+ def get_gem_spec(name)
28
31
  spec = Bundler.load.specs.find{|s| s.name == name }
29
32
  raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec
30
33
  if spec.name == 'bundler'
31
34
  return File.expand_path('../../../', __FILE__)
32
35
  end
33
- spec.full_gem_path
36
+
37
+ spec
34
38
  end