avo 0.5.0.beta2 → 0.5.0.beta7

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 (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/Gemfile.lock +1 -5
  4. data/app/components/avo/index/grid_item_component.html.erb +8 -8
  5. data/app/components/avo/index/grid_item_component.rb +6 -12
  6. data/app/components/avo/index/resource_grid_component.html.erb +1 -1
  7. data/app/components/avo/index/resource_table_component.html.erb +2 -2
  8. data/app/components/avo/index/table_row_component.html.erb +1 -1
  9. data/app/controllers/avo/actions_controller.rb +2 -5
  10. data/app/controllers/avo/application_controller.rb +12 -4
  11. data/app/controllers/avo/base_controller.rb +1 -9
  12. data/app/controllers/avo/relations_controller.rb +1 -1
  13. data/app/controllers/avo/search_controller.rb +1 -1
  14. data/app/frontend/packs/application.js +1 -1
  15. data/app/views/avo/base/_actions.html.erb +0 -6
  16. data/app/views/avo/base/_boolean_filter.html.erb +1 -1
  17. data/app/views/avo/base/_filters.html.erb +3 -11
  18. data/app/views/avo/base/_select_filter.html.erb +1 -1
  19. data/app/views/avo/home/_resources.html.erb +0 -1
  20. data/app/views/avo/partials/_table_header.html.erb +1 -1
  21. data/app/views/layouts/avo/_filter_wrapper.html.erb +1 -1
  22. data/app/views/layouts/avo/application.html.erb +5 -0
  23. data/avo.gemspec +0 -1
  24. data/config/webpacker.yml +10 -23
  25. data/lib/avo.rb +5 -16
  26. data/lib/avo/app.rb +204 -0
  27. data/lib/avo/base_action.rb +123 -0
  28. data/lib/avo/base_resource.rb +326 -0
  29. data/lib/avo/configuration.rb +8 -0
  30. data/lib/avo/engine.rb +12 -31
  31. data/lib/avo/{app/fields → fields}/badge_field.rb +1 -1
  32. data/lib/avo/{app/fields/field.rb → fields/base_field.rb} +3 -7
  33. data/lib/avo/{app/fields/belongs_to.rb → fields/belongs_to_field.rb} +3 -3
  34. data/lib/avo/{app/fields → fields}/boolean_field.rb +1 -1
  35. data/lib/avo/{app/fields → fields}/boolean_group_field.rb +1 -1
  36. data/lib/avo/{app/fields → fields}/code_field.rb +1 -1
  37. data/lib/avo/{app/fields → fields}/country_field.rb +1 -1
  38. data/lib/avo/{app/fields → fields}/currency_field.rb +1 -1
  39. data/lib/avo/{app/fields → fields}/date_field.rb +0 -2
  40. data/lib/avo/{app/fields → fields}/date_time_field.rb +0 -2
  41. data/lib/avo/{app/fields → fields}/external_image_field.rb +1 -1
  42. data/lib/avo/{app/fields → fields}/field_extensions/has_field_name.rb +0 -0
  43. data/lib/avo/{app/fields → fields}/field_extensions/visible_in_different_views.rb +1 -1
  44. data/lib/avo/{app/fields → fields}/file_field.rb +1 -2
  45. data/lib/avo/{app/fields → fields}/files_field.rb +1 -2
  46. data/lib/avo/{app/fields → fields}/gravatar_field.rb +1 -1
  47. data/lib/avo/{app/fields/has_and_belongs_to_many.rb → fields/has_and_belongs_to_many_field.rb} +1 -1
  48. data/lib/avo/{app/fields/has_many.rb → fields/has_many_field.rb} +1 -1
  49. data/lib/avo/{app/fields/has_one.rb → fields/has_one_field.rb} +1 -1
  50. data/lib/avo/{app/fields → fields}/heading_field.rb +1 -1
  51. data/lib/avo/{app/fields → fields}/hidden_field.rb +0 -2
  52. data/lib/avo/{app/fields → fields}/id_field.rb +1 -1
  53. data/lib/avo/{app/fields → fields}/key_value_field.rb +1 -1
  54. data/lib/avo/{app/fields → fields}/markdown_field.rb +1 -3
  55. data/lib/avo/{app/fields → fields}/number_field.rb +0 -2
  56. data/lib/avo/{app/fields → fields}/password_field.rb +0 -2
  57. data/lib/avo/{app/fields → fields}/select_field.rb +1 -1
  58. data/lib/avo/{app/fields → fields}/status_field.rb +1 -1
  59. data/lib/avo/{app/fields → fields}/text_field.rb +1 -1
  60. data/lib/avo/{app/fields → fields}/textarea_field.rb +0 -2
  61. data/lib/avo/{app/fields → fields}/trix_field.rb +1 -3
  62. data/lib/avo/filters/base_filter.rb +20 -0
  63. data/lib/avo/filters/boolean_filter.rb +7 -0
  64. data/lib/avo/filters/select_filter.rb +7 -0
  65. data/lib/avo/{app/grid_fields → grid_fields}/body_field.rb +0 -2
  66. data/lib/avo/{app/grid_fields → grid_fields}/grid_field.rb +0 -0
  67. data/lib/avo/{app/grid_fields → grid_fields}/preview_field.rb +0 -2
  68. data/lib/avo/{app/grid_fields → grid_fields}/title_field.rb +0 -2
  69. data/lib/avo/licensing/community_license.rb +6 -0
  70. data/lib/avo/licensing/h_q.rb +88 -0
  71. data/lib/avo/licensing/license.rb +50 -0
  72. data/lib/avo/licensing/license_manager.rb +22 -0
  73. data/lib/avo/licensing/null_license.rb +14 -0
  74. data/lib/avo/licensing/pro_license.rb +11 -0
  75. data/lib/avo/loaders/actions_loader.rb +6 -0
  76. data/lib/avo/loaders/fields_loader.rb +27 -0
  77. data/lib/avo/loaders/filters_loader.rb +6 -0
  78. data/lib/avo/loaders/loader.rb +15 -0
  79. data/lib/avo/services/authorization_service.rb +93 -0
  80. data/lib/avo/services/panel_service.rb +27 -0
  81. data/lib/avo/{app/tools_manager.rb → tools_manager.rb} +0 -0
  82. data/lib/avo/version.rb +1 -1
  83. data/lib/generators/avo/action_generator.rb +11 -5
  84. data/lib/generators/avo/controller_generator.rb +14 -8
  85. data/lib/generators/avo/filter_generator.rb +14 -8
  86. data/lib/generators/avo/install_generator.rb +14 -10
  87. data/lib/generators/avo/locales_generator.rb +11 -7
  88. data/lib/generators/avo/partials_generator.rb +11 -5
  89. data/lib/generators/avo/resource_generator.rb +33 -15
  90. data/lib/generators/avo/templates/{action.rb → action.tt} +2 -4
  91. data/lib/generators/avo/templates/filters/boolean_filter.tt +11 -0
  92. data/lib/generators/avo/templates/filters/select_filter.tt +11 -0
  93. data/lib/generators/avo/templates/initializer/{avo.rb → avo.tt} +6 -0
  94. data/lib/generators/avo/templates/resource/controller.tt +2 -0
  95. data/lib/generators/avo/templates/resource/resource.tt +17 -0
  96. data/public/avo-packs/css/{application-3598cfbb.css → application-c75ac28c.css} +1 -1
  97. data/public/avo-packs/css/application-c75ac28c.css.br +0 -0
  98. data/public/avo-packs/css/{application-3598cfbb.css.gz → application-c75ac28c.css.gz} +0 -0
  99. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js → application-8849c6e2c8f75d55c666.js} +3 -3
  100. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js.LICENSE.txt → application-8849c6e2c8f75d55c666.js.LICENSE.txt} +0 -0
  101. data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.br +0 -0
  102. data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.gz +0 -0
  103. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js.map → application-8849c6e2c8f75d55c666.js.map} +1 -1
  104. data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.map.br +0 -0
  105. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js.map.gz → application-8849c6e2c8f75d55c666.js.map.gz} +0 -0
  106. data/public/avo-packs/manifest.json +6 -6
  107. data/public/avo-packs/manifest.json.br +0 -0
  108. data/public/avo-packs/manifest.json.gz +0 -0
  109. metadata +72 -87
  110. data/config/webpacker_packed.yml +0 -86
  111. data/lib/avo/app/action.rb +0 -145
  112. data/lib/avo/app/actions_loader.rb +0 -11
  113. data/lib/avo/app/app.rb +0 -181
  114. data/lib/avo/app/fields_loader.rb +0 -29
  115. data/lib/avo/app/filter.rb +0 -23
  116. data/lib/avo/app/filters/boolean_filter.rb +0 -13
  117. data/lib/avo/app/filters/select_filter.rb +0 -13
  118. data/lib/avo/app/licensing/community_license.rb +0 -4
  119. data/lib/avo/app/licensing/hq.rb +0 -86
  120. data/lib/avo/app/licensing/license.rb +0 -48
  121. data/lib/avo/app/licensing/license_manager.rb +0 -25
  122. data/lib/avo/app/licensing/null_license.rb +0 -12
  123. data/lib/avo/app/licensing/pro_license.rb +0 -9
  124. data/lib/avo/app/resource.rb +0 -291
  125. data/lib/avo/app/resource_grid_fields.rb +0 -30
  126. data/lib/avo/app/services/authorization_service.rb +0 -110
  127. data/lib/avo/app/services/panel_service.rb +0 -25
  128. data/lib/avo/app/tool.rb +0 -5
  129. data/lib/generators/avo/templates/filters/boolean_filter.rb +0 -17
  130. data/lib/generators/avo/templates/filters/select_filter.rb +0 -17
  131. data/lib/generators/avo/templates/resource/%plural_name%_controller.tt +0 -2
  132. data/lib/generators/avo/templates/resource/%singular_name%.tt +0 -20
  133. data/public/avo-packs/css/application-3598cfbb.css.br +0 -0
  134. data/public/avo-packs/js/application-6ba2bd1bca05d69b96e0.js.br +0 -0
  135. data/public/avo-packs/js/application-6ba2bd1bca05d69b96e0.js.gz +0 -0
  136. data/public/avo-packs/js/application-6ba2bd1bca05d69b96e0.js.map.br +0 -0
@@ -19,6 +19,8 @@ module Avo
19
19
  attr_accessor :id_links_to_resource
20
20
  attr_accessor :full_width_container
21
21
  attr_accessor :full_width_index_view
22
+ attr_accessor :cache_resources_on_index_view
23
+ attr_accessor :context
22
24
 
23
25
  def initialize
24
26
  @root_path = '/avo'
@@ -48,6 +50,8 @@ module Avo
48
50
  @id_links_to_resource = false
49
51
  @full_width_container = false
50
52
  @full_width_index_view = false
53
+ @cache_resources_on_index_view = Avo::PACKED
54
+ @context = proc {}
51
55
  end
52
56
 
53
57
  def locale_tag
@@ -69,6 +73,10 @@ module Avo
69
73
  def authenticate_with(&block)
70
74
  @authenticate = block if block.present?
71
75
  end
76
+
77
+ def set_context(&block)
78
+ @context = block if block.present?
79
+ end
72
80
  end
73
81
 
74
82
  def self.configuration
data/lib/avo/engine.rb CHANGED
@@ -8,44 +8,25 @@ module Avo
8
8
  class Engine < ::Rails::Engine
9
9
  isolate_namespace Avo
10
10
 
11
- initializer 'avo.autoload', before: :set_autoload_paths do |app|
12
- {
13
- 'Avo::Resources': ['app', 'avo', 'resources'],
14
- 'Avo::Filters': ['app', 'avo', 'filters'],
15
- 'Avo::Actions': ['app', 'avo', 'actions'],
16
- }.each do |namespace, path|
17
- next unless Rails.root.join(*path).exist?
18
-
19
- Rails.autoloaders.main.push_dir(Rails.root.join(*path), namespace: namespace.to_s.safe_constantize)
20
- end
11
+ config.after_initialize do
12
+ # Boot Avo
13
+ ::Avo::App.boot
21
14
  end
22
15
 
23
- initializer 'avo.init' do |app|
24
- avo_root_path = Avo::Engine.root.to_s
25
-
26
- app.config.middleware.use I18n::JS::Middleware
27
-
28
- if Avo::IN_DEVELOPMENT
29
- # Register reloader
30
- app.reloaders << app.config.file_watcher.new([], {
31
- Avo::Engine.root.join('lib', 'avo').to_s => ['rb'],
32
- }) {}
33
-
34
- # What to do on file change
35
- config.to_prepare do
36
- Dir.glob(avo_root_path + '/lib/avo/app/**/*.rb'.to_s).each { |c| load c }
37
- Avo::App.boot
38
- end
39
- else
40
- Dir.glob(avo_root_path + '/lib/avo/app/**/*.rb'.to_s).each { |c| require c }
16
+ initializer 'avo.autoload', before: :set_autoload_paths do |app|
17
+ Rails.autoloaders.main.push_dir(Rails.root.join('app', 'avo', 'filters'))
18
+ Rails.autoloaders.main.push_dir(Rails.root.join('app', 'avo', 'actions'))
19
+ Rails.autoloaders.main.push_dir(Rails.root.join('app', 'avo', 'resources'))
20
+ end
41
21
 
42
- Avo::App.boot if Avo::PACKED
43
- end
22
+ initializer 'avo.init_fields' do |app|
23
+ # Init the fields
24
+ ::Avo::App.init_fields
44
25
  end
45
26
 
46
27
  initializer 'webpacker.proxy' do |app|
47
28
  app.config.debug_exception_response_format = :api
48
- app.config.logger = ::Logger.new(STDOUT)
29
+ # app.config.logger = ::Logger.new(STDOUT)
49
30
 
50
31
  insert_middleware = begin
51
32
  Avo.webpacker.config.dev_server.present?
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class BadgeField < Field
3
+ class BadgeField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  partial_name: 'badge-field',
@@ -1,11 +1,9 @@
1
- require_relative 'field_extensions/visible_in_different_views'
2
- require_relative 'field_extensions/has_field_name'
3
-
4
1
  module Avo
5
2
  module Fields
6
- class Field
7
- include Avo::Fields::FieldExtensions::VisibleOnDifferentViews
3
+ class BaseField
4
+ extend ActiveSupport::DescendantsTracker
8
5
  extend Avo::Fields::FieldExtensions::HasFieldName
6
+ include Avo::Fields::FieldExtensions::VisibleInDifferentViews
9
7
 
10
8
  attr_accessor :id
11
9
  attr_accessor :name
@@ -32,7 +30,6 @@ module Avo
32
30
  attr_accessor :view
33
31
  attr_accessor :user
34
32
  attr_accessor :action
35
- attr_accessor :grid_position
36
33
  attr_accessor :meta
37
34
  attr_accessor :panel_name
38
35
  attr_accessor :link_to_resource
@@ -67,7 +64,6 @@ module Avo
67
64
  help: nil,
68
65
  default: nil,
69
66
  can_see: nil,
70
- grid_position: false,
71
67
  meta: {},
72
68
  panel_name: nil,
73
69
  }
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class BelongsToField < Field
3
+ class BelongsToField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  partial_name: 'belongs-to-field',
@@ -17,7 +17,7 @@ module Avo
17
17
  target_resource.model_class.all.map do |model|
18
18
  {
19
19
  value: model.id,
20
- label: model.send(target_resource.title)
20
+ label: model.send(target_resource.class.title)
21
21
  }
22
22
  end
23
23
  end
@@ -43,7 +43,7 @@ module Avo
43
43
  end
44
44
 
45
45
  def label
46
- value.send(target_resource.title)
46
+ value.send(target_resource.class.title)
47
47
  end
48
48
 
49
49
  def to_permitted_param
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class BooleanField < Field
3
+ class BooleanField < BaseField
4
4
  attr_reader :true_value
5
5
  attr_reader :false_value
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class BooleanGroupField < Field
3
+ class BooleanGroupField < BaseField
4
4
  attr_reader :options
5
5
 
6
6
  def initialize(name, **args, &block)
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class CodeField < Field
3
+ class CodeField < BaseField
4
4
  attr_reader :height
5
5
  attr_reader :language
6
6
  attr_reader :theme
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class CountryField < Field
3
+ class CountryField < BaseField
4
4
  attr_reader :countries
5
5
  attr_reader :display_code
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class CurrencyField < Field
3
+ class CurrencyField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  partial_name: 'currency-field',
@@ -1,5 +1,3 @@
1
- require_relative 'text_field'
2
-
3
1
  module Avo
4
2
  module Fields
5
3
  class DateField < TextField
@@ -1,5 +1,3 @@
1
- require_relative 'date_field'
2
-
3
1
  module Avo
4
2
  module Fields
5
3
  class DateTimeField < DateField
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class ExternalImageField < Field
3
+ class ExternalImageField < BaseField
4
4
  attr_reader :width
5
5
  attr_reader :height
6
6
  attr_reader :radius
@@ -1,7 +1,7 @@
1
1
  module Avo
2
2
  module Fields
3
3
  module FieldExtensions
4
- module VisibleOnDifferentViews
4
+ module VisibleInDifferentViews
5
5
  attr_accessor :show_on_index
6
6
  attr_accessor :show_on_show
7
7
  attr_accessor :show_on_new
@@ -1,7 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class FileField < Field
4
- include Rails.application.routes.url_helpers
3
+ class FileField < BaseField
5
4
  attr_accessor :is_avatar
6
5
  attr_accessor :is_image
7
6
 
@@ -1,7 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class FilesField < Field
4
- include Rails.application.routes.url_helpers
3
+ class FilesField < BaseField
5
4
  attr_accessor :is_image
6
5
 
7
6
  def initialize(name, **args, &block)
@@ -3,7 +3,7 @@ require 'erb'
3
3
 
4
4
  module Avo
5
5
  module Fields
6
- class GravatarField < Field
6
+ class GravatarField < BaseField
7
7
  attr_reader :size
8
8
  attr_reader :rounded
9
9
  attr_reader :default
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class HasAndBelongsToManyField < Field
3
+ class HasAndBelongsToManyField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  updatable: false,
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class HasManyField < Field
3
+ class HasManyField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  updatable: false,
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class HasOneField < Field
3
+ class HasOneField < BaseField
4
4
  attr_accessor :relation_method
5
5
  attr_accessor :display
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class HeadingField < Field
3
+ class HeadingField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  updatable: false,
@@ -1,5 +1,3 @@
1
- require_relative 'text_field'
2
-
3
1
  module Avo
4
2
  module Fields
5
3
  class HiddenField < TextField
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class IdField < Field
3
+ class IdField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  default_value = 'id'
6
6
 
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Avo
4
4
  module Fields
5
- class KeyValueField < Field
5
+ class KeyValueField < BaseField
6
6
  def initialize(name, **args, &block)
7
7
  @defaults = {
8
8
  partial_name: 'key-value-field',
@@ -1,8 +1,6 @@
1
- require_relative 'field'
2
-
3
1
  module Avo
4
2
  module Fields
5
- class MarkdownField < Field
3
+ class MarkdownField < BaseField
6
4
  def initialize(name, **args, &block)
7
5
  @defaults = {
8
6
  partial_name: 'markdown-field',
@@ -1,5 +1,3 @@
1
- require_relative 'text_field'
2
-
3
1
  module Avo
4
2
  module Fields
5
3
  class NumberField < TextField
@@ -1,5 +1,3 @@
1
- require_relative 'text_field'
2
-
3
1
  module Avo
4
2
  module Fields
5
3
  class PasswordField < TextField
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class SelectField < Field
3
+ class SelectField < BaseField
4
4
  attr_reader :options
5
5
  attr_reader :enum
6
6
  attr_reader :display_value
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class StatusField < Field
3
+ class StatusField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  partial_name: 'status-field',
@@ -1,6 +1,6 @@
1
1
  module Avo
2
2
  module Fields
3
- class TextField < Field
3
+ class TextField < BaseField
4
4
  def initialize(name, **args, &block)
5
5
  @defaults = {
6
6
  partial_name: 'text-field',
@@ -1,5 +1,3 @@
1
- require_relative 'text_field'
2
-
3
1
  module Avo
4
2
  module Fields
5
3
  class TextareaField < TextField
@@ -1,8 +1,6 @@
1
- require_relative 'field'
2
-
3
1
  module Avo
4
2
  module Fields
5
- class TrixField < Field
3
+ class TrixField < BaseField
6
4
  attr_reader :always_show
7
5
 
8
6
  def initialize(name, **args, &block)
@@ -0,0 +1,20 @@
1
+ module Avo
2
+ module Filters
3
+ class BaseFilter
4
+ class_attribute :name, default: 'Filter'
5
+ class_attribute :component, default: 'boolean-filter'
6
+ class_attribute :default, default: ''
7
+ class_attribute :template, default: 'avo/base/select_filter'
8
+
9
+ def apply_query(request, query, value)
10
+ value.symbolize_keys! if value.is_a? Hash
11
+
12
+ self.apply(request, query, value)
13
+ end
14
+
15
+ def id
16
+ self.class.name.underscore.gsub('/', '_')
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Avo
2
+ module Filters
3
+ class BooleanFilter < BaseFilter
4
+ self.template = 'avo/base/boolean_filter'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Avo
2
+ module Filters
3
+ class SelectFilter < BaseFilter
4
+ self.template = 'avo/base/select_filter'
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,3 @@
1
- require_relative 'grid_field'
2
-
3
1
  module Avo
4
2
  module GridFields
5
3
  class BodyField < GridField