avo 2.8.0 → 2.9.0

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +11 -0
  4. data/app/assets/stylesheets/avo.css +4 -4
  5. data/app/assets/stylesheets/css/{components → fields}/code.css +0 -0
  6. data/app/assets/stylesheets/css/{components → fields}/progress.css +0 -0
  7. data/app/assets/stylesheets/css/{components → fields}/status.css +0 -0
  8. data/app/assets/stylesheets/css/fields/trix.css +17 -0
  9. data/app/components/avo/actions_component.html.erb +5 -13
  10. data/app/components/avo/actions_component.rb +39 -1
  11. data/app/components/avo/common_field_wrapper_component.html.erb +1 -1
  12. data/app/components/avo/fields/belongs_to_field/edit_component.rb +1 -1
  13. data/app/components/avo/fields/trix_field/edit_component.html.erb +1 -0
  14. data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
  15. data/app/components/avo/sidebar/item_switcher_component.html.erb +2 -2
  16. data/app/components/avo/views/resource_edit_component.html.erb +6 -4
  17. data/app/components/avo/views/resource_edit_component.rb +31 -3
  18. data/app/components/avo/views/resource_index_component.html.erb +1 -1
  19. data/app/components/avo/views/resource_show_component.html.erb +2 -2
  20. data/app/controllers/avo/base_controller.rb +11 -6
  21. data/app/helpers/avo/url_helpers.rb +8 -9
  22. data/app/javascript/js/controllers.js +0 -2
  23. data/app/views/avo/base/edit.html.erb +2 -1
  24. data/app/views/avo/base/new.html.erb +1 -1
  25. data/app/views/avo/partials/_custom_tools_alert.html.erb +21 -7
  26. data/app/views/avo/partials/_table_header.html.erb +9 -1
  27. data/bin/test +1 -0
  28. data/lib/avo/app.rb +18 -1
  29. data/lib/avo/base_action.rb +7 -2
  30. data/lib/avo/base_resource.rb +6 -1
  31. data/lib/avo/concerns/fetches_things.rb +19 -12
  32. data/lib/avo/concerns/has_model.rb +11 -0
  33. data/lib/avo/dynamic_router.rb +1 -1
  34. data/lib/avo/engine.rb +1 -3
  35. data/lib/avo/fields/base_field.rb +1 -0
  36. data/lib/avo/fields/concerns/is_required.rb +17 -0
  37. data/lib/avo/hosts/view_record_host.rb +7 -0
  38. data/lib/avo/menu/base_item.rb +4 -0
  39. data/lib/avo/menu/dashboard.rb +5 -0
  40. data/lib/avo/menu/resource.rb +5 -0
  41. data/lib/avo/version.rb +1 -1
  42. data/lib/avo.rb +1 -0
  43. data/lib/generators/avo/install_generator.rb +1 -4
  44. data/public/avo-assets/avo.css +467 -1069
  45. data/public/avo-assets/avo.js +70 -70
  46. data/public/avo-assets/avo.js.map +3 -3
  47. metadata +9 -8
  48. data/app/components/avo/views/resource_new_component.html.erb +0 -60
  49. data/app/components/avo/views/resource_new_component.rb +0 -39
  50. data/app/javascript/js/controllers/custom/course_resource_controller.js +0 -102
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-08 00:00:00.000000000 Z
12
+ date: 2022-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -253,9 +253,10 @@ files:
253
253
  - app/assets/stylesheets/css/active-storage.css
254
254
  - app/assets/stylesheets/css/breadcrumbs.css
255
255
  - app/assets/stylesheets/css/buttons.css
256
- - app/assets/stylesheets/css/components/code.css
257
- - app/assets/stylesheets/css/components/progress.css
258
- - app/assets/stylesheets/css/components/status.css
256
+ - app/assets/stylesheets/css/fields/code.css
257
+ - app/assets/stylesheets/css/fields/progress.css
258
+ - app/assets/stylesheets/css/fields/status.css
259
+ - app/assets/stylesheets/css/fields/trix.css
259
260
  - app/assets/stylesheets/css/fonts.css
260
261
  - app/assets/stylesheets/css/loader.css
261
262
  - app/assets/stylesheets/css/pagination.css
@@ -1032,8 +1033,6 @@ files:
1032
1033
  - app/components/avo/views/resource_edit_component.rb
1033
1034
  - app/components/avo/views/resource_index_component.html.erb
1034
1035
  - app/components/avo/views/resource_index_component.rb
1035
- - app/components/avo/views/resource_new_component.html.erb
1036
- - app/components/avo/views/resource_new_component.rb
1037
1036
  - app/components/avo/views/resource_show_component.html.erb
1038
1037
  - app/components/avo/views/resource_show_component.rb
1039
1038
  - app/controllers/avo/actions_controller.rb
@@ -1063,7 +1062,6 @@ files:
1063
1062
  - app/javascript/js/controllers/base_controller.js
1064
1063
  - app/javascript/js/controllers/boolean_filter_controller.js
1065
1064
  - app/javascript/js/controllers/copy_to_clipboard_controller.js
1066
- - app/javascript/js/controllers/custom/course_resource_controller.js
1067
1065
  - app/javascript/js/controllers/dashboard_card_controller.js
1068
1066
  - app/javascript/js/controllers/fields/belongs_to_field_controller.js
1069
1067
  - app/javascript/js/controllers/fields/code_field_controller.js
@@ -1169,6 +1167,7 @@ files:
1169
1167
  - lib/avo/concerns/handles_field_args.rb
1170
1168
  - lib/avo/concerns/has_fields.rb
1171
1169
  - lib/avo/concerns/has_html_attributes.rb
1170
+ - lib/avo/concerns/has_model.rb
1172
1171
  - lib/avo/concerns/has_stimulus_controllers.rb
1173
1172
  - lib/avo/concerns/has_tools.rb
1174
1173
  - lib/avo/configuration.rb
@@ -1186,6 +1185,7 @@ files:
1186
1185
  - lib/avo/fields/boolean_field.rb
1187
1186
  - lib/avo/fields/boolean_group_field.rb
1188
1187
  - lib/avo/fields/code_field.rb
1188
+ - lib/avo/fields/concerns/is_required.rb
1189
1189
  - lib/avo/fields/country_field.rb
1190
1190
  - lib/avo/fields/currency_field.rb
1191
1191
  - lib/avo/fields/date_field.rb
@@ -1231,6 +1231,7 @@ files:
1231
1231
  - lib/avo/hosts/dashboard_visibility.rb
1232
1232
  - lib/avo/hosts/ordering.rb
1233
1233
  - lib/avo/hosts/record_host.rb
1234
+ - lib/avo/hosts/view_record_host.rb
1234
1235
  - lib/avo/html/builder.rb
1235
1236
  - lib/avo/licensing/community_license.rb
1236
1237
  - lib/avo/licensing/h_q.rb
@@ -1,60 +0,0 @@
1
- <%= content_tag :div,
2
- class: "space-y-12",
3
- data: {
4
- 'model-id': @resource.model.id,
5
- **@resource.stimulus_data_attributes
6
- } do %>
7
- <% @resource.panels.each do |resource_panel| %>
8
- <%= form_with model: @resource.model,
9
- scope: @resource.form_scope,
10
- url: helpers.resources_path(
11
- resource: @resource,
12
- via_relation_class: params[:via_relation_class],
13
- via_relation: params[:via_relation],
14
- via_resource_id: params[:via_resource_id]
15
- ),
16
- local: true,
17
- multipart: true do |form| %>
18
- <%= render Avo::ReferrerParamsComponent.new back_path: back_path %>
19
- <%= render Avo::PanelComponent.new(title: resource_panel[:name], description: @resource.resource_description, display_breadcrumbs: true) do |c| %>
20
- <% c.tools do %>
21
- <div class="flex justify-end space-x-2">
22
- <%= a_link back_path,
23
- style: :text,
24
- icon: 'arrow-left' do %>
25
- <%= t('avo.cancel').capitalize %>
26
- <% end %>
27
- <% if can_see_the_save_button? %>
28
- <%= a_button color: :primary,
29
- style: :primary,
30
- loading: true,
31
- type: :submit,
32
- icon: 'save' do %>
33
- <%= t('avo.save').capitalize %>
34
- <% end %>
35
- <% end %>
36
- </div>
37
- <% end %>
38
- <% if Avo.configuration.buttons_on_form_footers %>
39
- <% c.footer_tools do %>
40
- <%= a_link back_path, icon: 'arrow-left' do %>
41
- <%= t('avo.cancel').capitalize %>
42
- <% end %>
43
- <% if can_see_the_save_button? %>
44
- <%= a_button color: :green, loading: true, type: :submit, icon: 'save' do %>
45
- <%= t('avo.save').capitalize %>
46
- <% end %>
47
- <% end %>
48
- <% end %>
49
- <% end %>
50
- <% c.body do %>
51
- <div class="divide-y">
52
- <% @resource.get_fields.each_with_index do |field, index| %>
53
- <%= render field.component_for_view(:edit).new(field: field, resource: @resource, index: index, form: form) unless field.computed %>
54
- <% end %>
55
- </div>
56
- <% end %>
57
- <% end %>
58
- <% end %>
59
- <% end %>
60
- <% end %>
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Avo::Views::ResourceNewComponent < Avo::ResourceComponent
4
- include Avo::ResourcesHelper
5
- include Avo::ApplicationHelper
6
-
7
- def initialize(
8
- resource: nil,
9
- model: nil
10
- )
11
- @resource = resource
12
- @model = model
13
- @view = :new
14
- end
15
-
16
- def back_path
17
- if via_resource?
18
- helpers.resource_path(model: params[:via_relation_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_id])
19
- else
20
- helpers.resources_path(resource: @resource)
21
- end
22
- end
23
-
24
- # The create button is dependent on the new? policy method.
25
- # The create? should be called only when the user clicks the Save button so the developers gets access to the params from the form.
26
- def can_see_the_save_button?
27
- @resource.authorization.authorize_action :new, raise_exception: false
28
- end
29
-
30
- private
31
-
32
- def via_resource?
33
- params[:via_relation_class].present? && params[:via_resource_id].present?
34
- end
35
-
36
- def relation_resource
37
- ::Avo::App.get_resource_by_model_name params[:via_relation_class].safe_constantize
38
- end
39
- end
@@ -1,102 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus'
2
-
3
- const LOADER_CLASSES = 'absolute bg-gray-100 opacity-10 w-full h-full'
4
-
5
- export default class extends Controller {
6
- static targets = ['countrySelectInput', 'citySelectInput', 'citySelectWrapper'];
7
-
8
- static values = {
9
- view: String,
10
- }
11
-
12
- // Te fields initial value
13
- static initialValue
14
-
15
- get placeholder() {
16
- return this.citySelectInputTarget.ariaPlaceholder
17
- }
18
-
19
- set loading(isLoading) {
20
- if (isLoading) {
21
- // create a loader overlay
22
- const loadingDiv = document.createElement('div')
23
- loadingDiv.className = LOADER_CLASSES
24
- loadingDiv.dataset.target = 'city-loader'
25
-
26
- // add the loader overlay
27
- this.citySelectWrapperTarget.prepend(loadingDiv)
28
- this.citySelectWrapperTarget.classList.add('opacity-50')
29
- } else {
30
- // remove the loader overlay
31
- this.citySelectWrapperTarget.querySelector('[data-target="city-loader"]').remove()
32
- this.citySelectWrapperTarget.classList.remove('opacity-50')
33
- }
34
- }
35
-
36
- async connect() {
37
- // Add the controller functionality only on forms
38
- if (['edit', 'new'].includes(this.viewValue)) {
39
- this.captureTheInitialValue()
40
-
41
- // Trigger the change on load
42
- await this.onCountryChange()
43
- }
44
- }
45
-
46
- // Read the country select.
47
- // If there's any value selected show the cities and prefill them.
48
- async onCountryChange() {
49
- if (this.hasCountrySelectInputTarget && this.countrySelectInputTarget) {
50
- // Get the country
51
- const country = this.countrySelectInputTarget.value
52
- // Dynamically fetch the cities for this country
53
- const cities = await this.fetchCitiesForCountry(country)
54
-
55
- // Clear the select of options
56
- Object.keys(this.citySelectInputTarget.options).forEach(() => {
57
- this.citySelectInputTarget.options.remove(0)
58
- })
59
-
60
- // Add blank option
61
- this.citySelectInputTarget.add(new Option(this.placeholder))
62
-
63
- // Add the new cities
64
- cities.forEach((city) => {
65
- this.citySelectInputTarget.add(new Option(city, city))
66
- })
67
-
68
- // Check if the initial value is present in the cities array and select it.
69
- // If not, select the first item
70
- const currentOptions = Array.from(this.citySelectInputTarget.options).map((item) => item.value)
71
- if (currentOptions.includes(this.initialValue)) {
72
- this.citySelectInputTarget.value = this.initialValue
73
- } else {
74
- // Select the first item
75
- this.citySelectInputTarget.value = this.citySelectInputTarget.options[0].value
76
- }
77
- }
78
- }
79
-
80
- // Private
81
-
82
- captureTheInitialValue() {
83
- this.initialValue = this.citySelectInputTarget.value
84
- }
85
-
86
- async fetchCitiesForCountry(country) {
87
- if (!country) {
88
- return []
89
- }
90
-
91
- this.loading = true
92
-
93
- const response = await fetch(
94
- `${window.Avo.configuration.root_path}/resources/courses/cities?country=${country}`,
95
- )
96
- const data = await response.json()
97
-
98
- this.loading = false
99
-
100
- return data
101
- }
102
- }