avo 1.3.0 → 1.3.5.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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +1 -1
  4. data/app/components/avo/common/key_value_component.html.erb +53 -0
  5. data/app/components/avo/common/key_value_component.rb +11 -0
  6. data/app/components/avo/edit/fields/key_value_field_component.html.erb +3 -0
  7. data/app/components/avo/edit/fields/key_value_field_component.rb +4 -0
  8. data/app/components/avo/edit/fields/markdown_field_component.html.erb +1 -0
  9. data/app/components/avo/edit/fields/trix_field_component.html.erb +19 -10
  10. data/app/components/avo/panel_component.html.erb +5 -3
  11. data/app/components/avo/panel_component.rb +6 -1
  12. data/app/components/avo/show/fields/key_value_field_component.html.erb +3 -0
  13. data/app/components/avo/show/fields/key_value_field_component.rb +4 -0
  14. data/app/components/avo/show/fields/markdown_field_component.html.erb +1 -0
  15. data/app/components/avo/views/resource_index_component.html.erb +1 -1
  16. data/app/components/avo/views/resource_show_component.html.erb +1 -1
  17. data/app/controllers/avo/application_controller.rb +5 -1
  18. data/app/controllers/avo/attachments_controller.rb +14 -3
  19. data/app/packs/entrypoints/application.js +14 -11
  20. data/app/packs/js/controllers/fields/code_field_controller.js +1 -0
  21. data/app/packs/js/controllers/fields/date_field_controller.js +1 -1
  22. data/app/packs/js/controllers/fields/key_value_controller.js +137 -0
  23. data/app/packs/js/controllers/fields/simple_mde_controller.js +9 -0
  24. data/app/packs/js/controllers/fields/trix_field_controller.js +121 -0
  25. data/app/views/avo/partials/_javascript.html.erb +3 -1
  26. data/config/routes.rb +4 -0
  27. data/lib/avo.rb +1 -1
  28. data/lib/avo/fields/base_field.rb +3 -1
  29. data/lib/avo/fields/key_value_field.rb +24 -1
  30. data/lib/avo/fields/markdown_field.rb +3 -4
  31. data/lib/avo/fields/trix_field.rb +4 -0
  32. data/lib/avo/version.rb +1 -1
  33. data/lib/generators/avo/action_generator.rb +1 -1
  34. data/lib/generators/avo/locales_generator.rb +2 -2
  35. data/lib/generators/avo/templates/action.tt +5 -9
  36. data/lib/generators/avo/templates/locales/avo.en.yml +1 -0
  37. data/lib/generators/avo/templates/locales/avo.nb-NO.yml +81 -0
  38. data/lib/generators/avo/templates/locales/avo.pt-BR.yml +82 -0
  39. data/lib/generators/avo/templates/locales/avo.ro.yml +70 -0
  40. data/public/avo-packs/css/{application-af3e670d.css → application-5bdca030.css} +92 -18
  41. data/public/avo-packs/css/application-5bdca030.css.br +0 -0
  42. data/public/avo-packs/css/application-5bdca030.css.gz +0 -0
  43. data/public/avo-packs/css/application-5bdca030.css.map +1 -0
  44. data/public/avo-packs/css/application-5bdca030.css.map.br +0 -0
  45. data/public/avo-packs/css/application-5bdca030.css.map.gz +0 -0
  46. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js +26 -0
  47. data/public/avo-packs/js/{application-274069794e43352bbda8.js.LICENSE.txt → application-16a456a2b7cb56b01153.js.LICENSE.txt} +0 -0
  48. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.br +0 -0
  49. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.gz +0 -0
  50. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.map +1 -0
  51. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.map.br +0 -0
  52. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.map.gz +0 -0
  53. data/public/avo-packs/manifest.json +15 -15
  54. metadata +28 -17
  55. data/public/avo-packs/css/application-af3e670d.css.br +0 -0
  56. data/public/avo-packs/css/application-af3e670d.css.gz +0 -0
  57. data/public/avo-packs/css/application-af3e670d.css.map +0 -1
  58. data/public/avo-packs/css/application-af3e670d.css.map.br +0 -0
  59. data/public/avo-packs/css/application-af3e670d.css.map.gz +0 -0
  60. data/public/avo-packs/js/application-274069794e43352bbda8.js +0 -26
  61. data/public/avo-packs/js/application-274069794e43352bbda8.js.br +0 -0
  62. data/public/avo-packs/js/application-274069794e43352bbda8.js.gz +0 -0
  63. data/public/avo-packs/js/application-274069794e43352bbda8.js.map +0 -1
  64. data/public/avo-packs/js/application-274069794e43352bbda8.js.map.br +0 -0
  65. data/public/avo-packs/js/application-274069794e43352bbda8.js.map.gz +0 -0
@@ -8,9 +8,18 @@ export default class extends Controller {
8
8
  return this.elementTarget.dataset.view
9
9
  }
10
10
 
11
+ get componentOptions() {
12
+ try {
13
+ return JSON.parse(this.elementTarget.dataset.componentOptions)
14
+ } catch (error) {
15
+ return {}
16
+ }
17
+ }
18
+
11
19
  connect() {
12
20
  const options = {
13
21
  element: this.elementTarget,
22
+ spellChecker: this.componentOptions.spell_checker,
14
23
  }
15
24
 
16
25
  if (this.view === 'show') {
@@ -0,0 +1,121 @@
1
+ import 'trix'
2
+ import { Controller } from 'stimulus'
3
+ import { castBoolean } from '@/js/helpers/cast_boolean'
4
+
5
+ export default class extends Controller {
6
+ static targets = ['editor', 'controller']
7
+
8
+ get resourceId() {
9
+ return this.controllerTarget.dataset.resourceId
10
+ }
11
+
12
+ get resourceName() {
13
+ return this.controllerTarget.dataset.resourceName
14
+ }
15
+
16
+ get attachmentKey() {
17
+ return this.controllerTarget.dataset.attachmentKey
18
+ }
19
+
20
+ get attachmentsDisabled() {
21
+ return castBoolean(this.controllerTarget.dataset.attachmentsDisabled)
22
+ }
23
+
24
+ get uploadUrl() {
25
+ return `${window.location.origin}${window.Avo.configuration.root_path}/avo_api/resources/${this.resourceName}/${this.resourceId}/attachments`
26
+ }
27
+
28
+ connect() {
29
+ if (this.attachmentsDisabled) {
30
+ // Remove the attachments button
31
+ this.controllerTarget.querySelector('.trix-button-group--file-tools').remove()
32
+ }
33
+
34
+ window.addEventListener('trix-file-accept', (event) => {
35
+ if (event.target === this.editorTarget) {
36
+ // Prevent file uploads for fields that have attachments disabled.
37
+ if (this.attachmentsDisabled) {
38
+ event.preventDefault()
39
+ window.toastr.warning('This field has attachments disabled.')
40
+
41
+ return
42
+ }
43
+
44
+ // Prevent file uploads for resources that haven't been saved yet.
45
+ if (this.resourceId === '') {
46
+ event.preventDefault()
47
+ window.toastr.warning("You can't upload files into the Trix editor until you save the resource.")
48
+
49
+ return
50
+ }
51
+
52
+ // Prevent file uploads for fields without an attachment key.
53
+ if (this.attachmentKey === '') {
54
+ event.preventDefault()
55
+ window.toastr.warning("You haven't set an <a href='https://google.com' class='!text-blue-700 underline'>attachment_key</a> to this Trix field.")
56
+ }
57
+ }
58
+ })
59
+
60
+ window.addEventListener('trix-attachment-add', (event) => {
61
+ if (event.target === this.editorTarget) {
62
+ if (event.attachment.file) {
63
+ this.uploadFileAttachment(event.attachment)
64
+ }
65
+ }
66
+ })
67
+ }
68
+
69
+ uploadFileAttachment(attachment) {
70
+ this.uploadFile(
71
+ attachment.file,
72
+ (progress) => attachment.setUploadProgress(progress),
73
+ (attributes) => attachment.setAttributes(attributes),
74
+ )
75
+ }
76
+
77
+ uploadFile(file, progressCallback, successCallback) {
78
+ const formData = this.createFormData(file)
79
+ const xhr = new XMLHttpRequest()
80
+
81
+ xhr.open('POST', this.uploadUrl, true)
82
+
83
+ xhr.setRequestHeader('X-CSRF-Token', document.querySelector('meta[name="csrf-token"]').content)
84
+
85
+ xhr.upload.addEventListener('progress', (event) => {
86
+ // eslint-disable-next-line no-mixed-operators
87
+ const progress = event.loaded / event.total * 100
88
+ progressCallback(progress)
89
+ })
90
+
91
+ xhr.addEventListener('load', () => {
92
+ if (xhr.status === 200) {
93
+ let response
94
+ try {
95
+ response = JSON.parse(xhr.response)
96
+ } catch (error) {
97
+ response = {}
98
+ }
99
+
100
+ const attributes = {
101
+ url: response.url,
102
+ href: response.href,
103
+ }
104
+
105
+ successCallback(attributes)
106
+ }
107
+ })
108
+
109
+ xhr.send(formData)
110
+ }
111
+
112
+ createFormData(file) {
113
+ const data = new FormData()
114
+ data.append('Content-Type', file.type)
115
+ data.append('file', file)
116
+ data.append('filename', file.name)
117
+ data.append('attachment_key', this.attachmentKey)
118
+
119
+ return data
120
+ }
121
+ }
@@ -1,3 +1,5 @@
1
1
  <%= javascript_tag nonce: true do %>
2
- var timezone = '<%= Avo.configuration.timezone %>';
2
+ window.Avo = window.Avo || { configuration: {} }
3
+ Avo.configuration.timezone = '<%= Avo.configuration.timezone %>'
4
+ Avo.configuration.root_path = '<%= Avo.configuration.root_path %>'
3
5
  <% end %>
data/config/routes.rb CHANGED
@@ -3,6 +3,10 @@ Avo::Engine.routes.draw do
3
3
 
4
4
  get "resources", to: redirect("/avo")
5
5
 
6
+ scope "avo_api", as: "avo_api" do
7
+ post "/resources/:resource_name/:id/attachments/", to: "attachments#create"
8
+ end
9
+
6
10
  scope "resources", as: "resources" do
7
11
  # Attachments
8
12
  get "/:resource_name/:id/active_storage_attachments/:attachment_name/:signed_attachment_id", to: "attachments#show"
data/lib/avo.rb CHANGED
@@ -27,7 +27,7 @@ module Avo
27
27
  root_path: ROOT_PATH,
28
28
  public_output_dir: "avo-packs",
29
29
  cache_manifest: Rails.env.production?,
30
- fallback_to_webpacker: -> { Avo::IN_DEVELOPMENT || Rails.env.test?}
30
+ fallback_to_webpacker: -> { Avo::IN_DEVELOPMENT || Rails.env.test? }
31
31
  )
32
32
  end
33
33
  end
@@ -33,6 +33,7 @@ module Avo
33
33
  attr_accessor :meta
34
34
  attr_accessor :panel_name
35
35
  attr_accessor :link_to_resource
36
+ attr_accessor :options
36
37
 
37
38
  class_attribute :field_name_attribute
38
39
 
@@ -67,7 +68,8 @@ module Avo
67
68
  default: nil,
68
69
  visible: true,
69
70
  meta: {},
70
- panel_name: nil
71
+ panel_name: nil,
72
+ options: {}
71
73
  }
72
74
 
73
75
  # Set the values in the following order
@@ -3,6 +3,11 @@ require "json"
3
3
  module Avo
4
4
  module Fields
5
5
  class KeyValueField < BaseField
6
+ attr_reader :key_label
7
+ attr_reader :value_label
8
+ attr_reader :action_text
9
+ attr_reader :disable_adding_rows
10
+
6
11
  def initialize(name, **args, &block)
7
12
  @defaults = {
8
13
  partial_name: "key-value-field"
@@ -33,7 +38,13 @@ module Avo
33
38
  [:"#{id}", "#{id}": {}]
34
39
  end
35
40
 
36
- def hydrate_field(fields, model, resource, view)
41
+ def parsed_value
42
+ value.to_json
43
+ rescue
44
+ {}
45
+ end
46
+
47
+ def options
37
48
  {
38
49
  key_label: @key_label,
39
50
  value_label: @value_label,
@@ -44,6 +55,18 @@ module Avo
44
55
  disable_deleting_rows: @disable_deleting_rows
45
56
  }
46
57
  end
58
+
59
+ def fill_field(model, key, value)
60
+ begin
61
+ new_value = JSON.parse(value)
62
+ rescue
63
+ new_value = {}
64
+ end
65
+
66
+ model[key] = new_value
67
+
68
+ model
69
+ end
47
70
  end
48
71
  end
49
72
  end
@@ -12,10 +12,9 @@ module Avo
12
12
 
13
13
  @always_show = args[:always_show].present? ? args[:always_show] : false
14
14
  @height = args[:height].present? ? args[:height].to_s : "auto"
15
- end
16
-
17
- def hydrate_field(fields, model, resource, view)
18
- {
15
+ @spell_checker = args[:spell_checker].present? ? args[:spell_checker] : false
16
+ @options = {
17
+ spell_checker: @spell_checker,
19
18
  always_show: @always_show,
20
19
  height: @height
21
20
  }
@@ -2,6 +2,8 @@ module Avo
2
2
  module Fields
3
3
  class TrixField < BaseField
4
4
  attr_reader :always_show
5
+ attr_reader :attachments_disabled
6
+ attr_reader :attachment_key
5
7
 
6
8
  def initialize(name, **args, &block)
7
9
  @defaults = {
@@ -13,6 +15,8 @@ module Avo
13
15
  hide_on :index
14
16
 
15
17
  @always_show = args[:always_show].present? ? args[:always_show] : false
18
+ @attachments_disabled = args[:attachments_disabled].present? ? args[:attachments_disabled] : false
19
+ @attachment_key = args[:attachment_key].present? ? args[:attachment_key] : nil
16
20
  end
17
21
  end
18
22
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.5.pre.1"
3
3
  end
@@ -7,7 +7,7 @@ module Generators
7
7
  namespace "avo:action"
8
8
 
9
9
  def create_resource_file
10
- template "action.rb", "app/avo/actions/#{singular_name}.rb"
10
+ template "action.tt", "app/avo/actions/#{singular_name}.rb"
11
11
  end
12
12
  end
13
13
  end
@@ -6,10 +6,10 @@ module Generators
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
8
  namespace "avo:locales"
9
- desc "Creates an Avo initializer adds the route to the routes file."
9
+ desc "Add Avo locale files to your project."
10
10
 
11
11
  def create_files
12
- template "locales/avo.en.yml", "config/locales/avo.en.yml"
12
+ directory File.join(__dir__, "templates", "locales"), "config/locales"
13
13
  end
14
14
  end
15
15
  end
@@ -1,13 +1,9 @@
1
- module Avo
2
- module Actions
3
- class <%= class_name.camelize %> < Action
4
- self.name = '<%= name.underscore.humanize %>'
1
+ class <%= class_name.camelize %> < Avo::BaseAction
2
+ self.name = '<%= name.underscore.humanize %>'
5
3
 
6
- def handle(models:, fields:)
7
- models.each do |model|
8
- # Do something with your models.
9
- end
10
- end
4
+ def handle(models:, fields:)
5
+ models.each do |model|
6
+ # Do something with your models.
11
7
  end
12
8
  end
13
9
  end
@@ -59,6 +59,7 @@ en:
59
59
  and_x_other_resources: 'and %{count} other resources'
60
60
  go_back: 'Go back'
61
61
  home: 'Home'
62
+ new: 'new'
62
63
  attach_item: 'Attach %{item}'
63
64
  choose_item: 'Choose %{item}'
64
65
  create_new_item: 'Create new %{item}'
@@ -0,0 +1,81 @@
1
+ nb:
2
+ avo:
3
+ dashboard: 'Dashboard'
4
+ choose_a_country: 'Velg et land'
5
+ choose_an_option: 'Velg et alternativ'
6
+ are_you_sure_you_want_to_run_this_option: 'Er du sikker?'
7
+ are_you_sure_detach_item: 'Er du sikker på at du vil koble fra %{item}.'
8
+ run: 'Kjør'
9
+ cancel: 'Avslutt'
10
+ action_ran_successfully: 'Suksess!'
11
+ resource_details: "%{item} detaljer: %{title}"
12
+ update_item: 'Oppdatert %{item}: %{title}'
13
+ unauthorized: 'Ikke autorisert'
14
+ attachment_class_attached: '%{attachment_class} lagt til.'
15
+ attachment_class_detached: '%{attachment_class} fjernet.'
16
+ resource_updated: 'Ressurs oppdatert'
17
+ resource_created: 'Ressurs generert'
18
+ resource_destroyed: 'Ressurs slettet'
19
+ switch_to_view: "Bytt til %{view_type} vis"
20
+ click_to_reveal_filters: "Vis filter"
21
+ attachment_destroyed: 'Vedlett slettet'
22
+ failed_to_find_attachment: 'Fant ikke vedlegg'
23
+ you_missed_something_check_form: 'Her mangler du noe. Vennligst sjekk skjemaet.'
24
+ remove_selection: 'Fjern valg'
25
+ select_item: 'Velg'
26
+ delete_file: 'Slett fil'
27
+ delete: 'slett'
28
+ delete_item: 'Slett %{item}'
29
+ download_item: 'Last ned %{item}'
30
+ download_file: 'Last ned fil'
31
+ download: 'Last ned'
32
+ view: 'Vis'
33
+ view_item: 'vis %{item}'
34
+ edit: 'endre'
35
+ edit_item: 'endre %{item}'
36
+ detach_item: 'koble fra %{item}'
37
+ number_of_items:
38
+ zero: 'ingen %{item}'
39
+ one: 'en %{item}'
40
+ other: '%{count} %{item}'
41
+ are_you_sure: 'Er du sikker?'
42
+ filters: 'Filter'
43
+ per_page: 'Per side'
44
+ more: 'Mer'
45
+ attach: 'Legg til'
46
+ cancel: 'Avslutt'
47
+ save: 'Lagre'
48
+ attach_and_attach_another: 'Legg til & Legg til ny'
49
+ hide_content: 'Skjul innhold'
50
+ show_content: 'Vis innhold'
51
+ no_related_item_found: 'Ingen relaterte %{item} funnet'
52
+ no_item_found: 'Ingen %{item} funnet'
53
+ loading: 'Laster'
54
+ confirm: 'Bekreft'
55
+ actions: 'Handlinger'
56
+ resources: 'Ressurser'
57
+ oops_nothing_found: 'Oops! Ingen ting funnet...'
58
+ type_to_search: 'Søk.'
59
+ and_x_other_resources: 'og %{count} andre ressurser'
60
+ go_back: 'Gå tilbake'
61
+ home: 'Hjem'
62
+ attach_item: 'Legg til %{item}'
63
+ choose_item: 'Velge %{item}'
64
+ create_new_item: 'Lag ny %{item}'
65
+ table_view: 'Tabell visning'
66
+ grid_view: 'Grid visning'
67
+ next_page: 'Neste side'
68
+ prev_page: 'Forrige side'
69
+ list_is_empty: 'Listen er tom'
70
+ field_translations:
71
+ file:
72
+ zero: 'filer'
73
+ one: 'fil'
74
+ other: 'filer'
75
+ resource_translations:
76
+ user:
77
+ zero: 'brukere'
78
+ one: 'bruker'
79
+ other: 'brukere'
80
+ reset_filters: 'Nullstill filter'
81
+ not_authorized: 'Du er ikke autorisert til å gjøre denne handlingen.'
@@ -0,0 +1,82 @@
1
+ pt:
2
+ avo:
3
+ dashboard: 'Painel'
4
+ choose_a_country: 'Escolha um país'
5
+ choose_an_option: 'Escolha uma opção'
6
+ are_you_sure_you_want_to_run_this_option: 'Você tem certeza que deseja executar esta ação?'
7
+ are_you_sure_detach_item: 'Você tem certeza que deseja separar este %{item}.'
8
+ run: 'Executar'
9
+ cancel: 'Cancelar'
10
+ action_ran_successfully: 'Ação executada com sucesso!'
11
+ resource_details: "Detalhe %{item}: %{title}"
12
+ update_item: 'atualizar %{item}: %{title}'
13
+ unauthorized: 'Não autorizado'
14
+ attachment_class_attached: '%{attachment_class} anexado.'
15
+ attachment_class_detached: '%{attachment_class} separado.'
16
+ resource_updated: 'Recurso atualizado'
17
+ resource_created: 'Recurso criado'
18
+ resource_destroyed: 'Recurso destruído'
19
+ switch_to_view: "Alterar para visão %{view_type}"
20
+ click_to_reveal_filters: "Clique para revelar os filtros"
21
+ attachment_destroyed: 'Anexo destruído'
22
+ failed_to_find_attachment: 'Falhou ao achar anexo'
23
+ you_missed_something_check_form: 'Você pode ter esquecido algo. Por favor, cheque o formulário.'
24
+ remove_selection: 'Remover seleção'
25
+ select_item: 'Selecionar item'
26
+ delete_file: 'Deletar arquivo'
27
+ delete: 'deletar'
28
+ delete_item: 'Deletar %{item}'
29
+ download_item: 'Baixar %{item}'
30
+ download_file: 'Baixar arquivo'
31
+ download: 'Baixar'
32
+ view: 'Visualizar'
33
+ view_item: 'visualizar %{item}'
34
+ edit: 'editar'
35
+ edit_item: 'editar %{item}'
36
+ detach_item: 'separar %{item}'
37
+ number_of_items:
38
+ zero: 'sem %{item}'
39
+ one: 'um %{item}'
40
+ other: '%{count} %{item}'
41
+ are_you_sure: 'Você tem certeza?'
42
+ filters: 'Filtros'
43
+ per_page: 'Por página'
44
+ more: 'Mais'
45
+ attach: 'Anexar'
46
+ cancel: 'Cancelar'
47
+ save: 'Salvar'
48
+ attach_and_attach_another: 'Anexar & anexar outro'
49
+ hide_content: 'Esconder conteúdo'
50
+ show_content: 'Mostrar conteúdo'
51
+ no_related_item_found: 'Nenhum %{item} relacionado encontrado'
52
+ no_item_found: 'Nenhum %{item} encontrado'
53
+ loading: 'Carregando'
54
+ confirm: 'Confirmar'
55
+ actions: 'Ações'
56
+ resources: 'Recursos'
57
+ oops_nothing_found: 'Oops! Nada encontrado...'
58
+ type_to_search: 'Digite para buscar.'
59
+ and_x_other_resources: 'e %{count} outros recursos'
60
+ go_back: 'Voltar'
61
+ home: 'Início'
62
+ new: 'novo'
63
+ attach_item: 'Anexar %{item}'
64
+ choose_item: 'Escolher %{item}'
65
+ create_new_item: 'Criar novo %{item}'
66
+ table_view: 'Visualização em tabela'
67
+ grid_view: 'Visualização em grade'
68
+ next_page: 'Próxima página'
69
+ prev_page: 'Página anterior'
70
+ list_is_empty: 'Lista vazia'
71
+ field_translations:
72
+ file:
73
+ zero: 'arquivos'
74
+ one: 'arquivo'
75
+ other: 'arquivos'
76
+ resource_translations:
77
+ user:
78
+ zero: 'usuários'
79
+ one: 'usuário'
80
+ other: 'usuários'
81
+ reset_filters: 'Limpar filtros'
82
+ not_authorized: 'Você não está autorizado à executar essa ação.'