decidim-decidim_awesome 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -7
  3. data/app/assets/config/decidim_admin_decidim_awesome_manifest.js +1 -0
  4. data/app/assets/config/decidim_decidim_awesome_manifest.js +1 -1
  5. data/app/assets/javascripts/decidim/decidim_awesome/admin.js +1 -0
  6. data/app/assets/javascripts/decidim/decidim_awesome/admin/codemirror.js.es6 +15 -0
  7. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/hashtags.js.es6 +48 -0
  8. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/layers.js.es6 +106 -0
  9. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/map.js.es6 +166 -170
  10. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/markers.js.es6 +56 -0
  11. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/meetings.js.es6 +6 -5
  12. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/proposals.js.es6 +17 -4
  13. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/utilities.js.es6 +48 -0
  14. data/app/assets/javascripts/decidim/decidim_awesome/editors/legacy_quill_editor.js.es6 +160 -0
  15. data/app/assets/javascripts/decidim/decidim_awesome/editors/quill_editor.js.es6 +16 -5
  16. data/app/assets/javascripts/decidim/decidim_awesome/legacy_admin.js +3 -0
  17. data/app/assets/javascripts/decidim/decidim_awesome/legacy_application.js +4 -0
  18. data/app/assets/stylesheets/decidim/decidim_awesome/admin.scss +10 -3
  19. data/app/assets/stylesheets/decidim/decidim_awesome/admin/codemirror.scss +16 -0
  20. data/app/assets/stylesheets/decidim/decidim_awesome/awesome_map/leaflet.scss.erb +9 -0
  21. data/app/assets/stylesheets/decidim/decidim_awesome/awesome_map/map.scss +95 -0
  22. data/app/assets/stylesheets/decidim/decidim_awesome/editors/markdown_editor.scss +1 -1
  23. data/app/awesome_overrides/presenters/decidim/menu_presenter_override.rb +39 -0
  24. data/app/awesome_overrides/presenters/decidim/proposals/proposal_presenter_override.rb +3 -9
  25. data/app/commands/decidim/decidim_awesome/admin/create_menu_hack.rb +51 -0
  26. data/app/commands/decidim/decidim_awesome/admin/destroy_menu_hack.rb +47 -0
  27. data/app/commands/decidim/decidim_awesome/admin/update_config.rb +5 -2
  28. data/app/commands/decidim/decidim_awesome/admin/update_menu_hack.rb +47 -0
  29. data/app/controllers/decidim/decidim_awesome/admin/application_controller.rb +4 -3
  30. data/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +1 -1
  31. data/app/controllers/decidim/decidim_awesome/admin/config_controller.rb +12 -3
  32. data/app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb +13 -0
  33. data/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb +116 -0
  34. data/app/controllers/decidim/decidim_awesome/map_component/map_controller.rb +1 -4
  35. data/app/forms/decidim/decidim_awesome/admin/config_form.rb +21 -2
  36. data/app/forms/decidim/decidim_awesome/admin/constraint_form.rb +0 -2
  37. data/app/forms/decidim/decidim_awesome/admin/intergram_form.rb +0 -2
  38. data/app/forms/decidim/decidim_awesome/admin/menu_form.rb +39 -0
  39. data/app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb +5 -1
  40. data/app/helpers/decidim/decidim_awesome/map_helper.rb +12 -50
  41. data/app/permissions/decidim/decidim_awesome/admin/permissions.rb +19 -0
  42. data/app/permissions/decidim/decidim_awesome/permissions.rb +2 -0
  43. data/app/uploaders/decidim/decidim_awesome/image_uploader.rb +0 -5
  44. data/app/views/decidim/decidim_awesome/admin/checks/index.html.erb +1 -1
  45. data/app/views/decidim/decidim_awesome/admin/config/_form_styles.html.erb +1 -1
  46. data/app/views/decidim/decidim_awesome/admin/config/show.html.erb +1 -2
  47. data/app/views/decidim/decidim_awesome/admin/menu_hacks/_form.html.erb +7 -0
  48. data/app/views/decidim/decidim_awesome/admin/menu_hacks/edit.html.erb +13 -0
  49. data/app/views/decidim/decidim_awesome/admin/menu_hacks/index.html.erb +44 -0
  50. data/app/views/decidim/decidim_awesome/admin/menu_hacks/new.html.erb +13 -0
  51. data/app/views/decidim/decidim_awesome/map_component/map/show.html.erb +4 -31
  52. data/app/views/layouts/decidim/admin/decidim_awesome.html.erb +5 -0
  53. data/app/views/layouts/decidim/decidim_awesome/_awesome_config.html.erb +4 -1
  54. data/app/views/v0.23/layouts/decidim/_head.html.erb +1 -1
  55. data/app/views/v0.23/layouts/decidim/admin/_header.html.erb +1 -1
  56. data/app/views/{v0.22 → v0.24}/layouts/decidim/_head.html.erb +2 -0
  57. data/app/views/{v0.22 → v0.24}/layouts/decidim/admin/_header.html.erb +1 -0
  58. data/config/locales/ca.yml +70 -2
  59. data/config/locales/cs.yml +71 -3
  60. data/config/locales/en.yml +61 -4
  61. data/config/locales/es.yml +70 -2
  62. data/config/locales/eu.yml +225 -0
  63. data/config/locales/fr.yml +172 -104
  64. data/config/locales/nl.yml +225 -0
  65. data/config/locales/sv.yml +93 -25
  66. data/lib/decidim/decidim_awesome.rb +15 -0
  67. data/lib/decidim/decidim_awesome/admin_engine.rb +1 -0
  68. data/lib/decidim/decidim_awesome/awesome_helpers.rb +1 -1
  69. data/lib/decidim/decidim_awesome/checksums.yml +7 -4
  70. data/lib/decidim/decidim_awesome/config.rb +1 -3
  71. data/lib/decidim/decidim_awesome/engine.rb +3 -3
  72. data/lib/decidim/decidim_awesome/iframe_component/component.rb +1 -1
  73. data/lib/decidim/decidim_awesome/map_component/component.rb +8 -2
  74. data/lib/decidim/decidim_awesome/menu_hacker.rb +90 -0
  75. data/lib/decidim/decidim_awesome/system_checker.rb +1 -1
  76. data/lib/decidim/decidim_awesome/test/shared_examples/config_examples.rb +4 -2
  77. data/lib/decidim/decidim_awesome/test/shared_examples/menu_hack_contexts.rb +71 -0
  78. data/lib/decidim/decidim_awesome/version.rb +2 -2
  79. data/vendor/assets/javascripts/codemirror.js +9801 -0
  80. data/vendor/assets/javascripts/jquery.truncate.js +105 -0
  81. data/vendor/assets/javascripts/keymap/sublime.js +720 -0
  82. data/vendor/assets/javascripts/mode/css/css.js +864 -0
  83. data/vendor/assets/stylesheets/codemirror.css +350 -0
  84. data/vendor/assets/stylesheets/inscrybmde.min.scss +180 -0
  85. metadata +61 -20
  86. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_map.js.es6 +0 -225
  87. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_proposals.js.es6 +0 -82
  88. data/vendor/assets/stylesheets/inscrybmde.min.css +0 -8
@@ -2,55 +2,70 @@ sv:
2
2
  activemodel:
3
3
  attributes:
4
4
  config:
5
- allow_images_in_full_editor: Allow images in the full HTML editor
6
- allow_images_in_markdown_editor: Allow images in the markdown editor
7
- allow_images_in_proposals: Allow images in the proposals editor
8
- allow_images_in_small_editor: Allow images in the minimal HTML editor
9
- auto_save_forms: Auto save forms in local storage
5
+ allow_images_in_full_editor: Tillåt bilder i den fullständiga HTML-editorn
6
+ allow_images_in_markdown_editor: Tillåt bilder i den fullständiga Markdown-editorn
7
+ allow_images_in_proposals: Tillåt bilder i förslagsfältet
8
+ allow_images_in_small_editor: Tillåt bilder i den minimala HTML-editorn
9
+ auto_save_forms: Spara formulär automatiskt i lokal lagring
10
10
  intergram_auto_no_response: A message that is sent one minute after the user sends its first message and no response was received
11
11
  intergram_auto_response: A message that is sent immediately after the user sends its first message
12
- intergram_chat_id: Chat ID
13
- intergram_color: Color of the widget
12
+ intergram_chat_id: Chatt ID
13
+ intergram_color: Huvudfärg för widget
14
14
  intergram_for_admins: Enable Intergram Chat in the admin backend
15
- intergram_intro_message: First message when the user opens the chat for the first time
16
- intergram_require_login: Only for logged users
15
+ intergram_intro_message: Första meddelandet när användaren öppnar chatten för första gången
16
+ intergram_require_login: Endast för inloggade användare
17
17
  intergram_title_closed: Closed chat title
18
18
  intergram_title_open: Opened chat title
19
19
  intergram_use_floating_button: If checked, the closed chat is always a button instead of a text
20
+ scoped_styles: 'Custom styles #%{id}'
20
21
  use_markdown_editor: Use a Markdown editor instead of the HTML editor
21
22
  constraint:
22
23
  component_id: or specifically in
23
24
  component_manifest: Only in components of type
24
25
  participatory_space_manifest: Apply to participatory spaces of type
25
- participatory_space_slug: Only in
26
+ participatory_space_slug: Endast i
27
+ menu:
28
+ position: Position
29
+ raw_label: Etikett
30
+ target: Opens in
31
+ url: Webbadress
32
+ visibility: Synlighet
26
33
  decidim:
27
34
  admin:
28
35
  menu:
29
- decidim_awesome: Decidim awesome
36
+ decidim_awesome: Decidim Awesome
30
37
  components:
31
38
  awesome_iframe:
32
39
  name: Fullscreen Iframe
33
40
  settings:
34
41
  global:
35
- announcement: Announcement
36
- iframe: Iframe code
42
+ announcement: Meddelande
43
+ iframe: Iframe kod
37
44
  iframe_help: 'Put your code as html: <iframe width="100%" height="700" frameBorder="0" allowFullscreen src="..."></iframe>. Content will be sanitized from other HTML tags. Ensure to use 100% as width to fill the screen.'
38
45
  no_margins: No margins between the iframe and the rest of the page
39
46
  viewport_width: Limit maximum width to the application viewport
40
47
  step:
41
48
  announcement: Announcement
42
- iframe: Iframe code
49
+ iframe: Iframe kod
43
50
  awesome_map:
44
- name: Awesome Map
51
+ name: Karta
45
52
  settings:
46
53
  global:
47
- announcement: Announcement
54
+ announcement: Meddelande
48
55
  collapse: Start with collapsed menu
56
+ map_center: Map center (Latitude, Longitude)
57
+ map_center_help: 'Use decimal points (ie: 41.38879, 2.15899). Leave it empty to automatically fit all the markers'
49
58
  map_height: Map height (px)
59
+ map_zoom: Zoom (any number betwen 0 and 18)
60
+ map_zoom_help: Only applies if a map center is defined
61
+ menu_amendments: Show amendments
62
+ menu_hashtags: Show Hasthag search menu
63
+ menu_meetings: Visa möten
64
+ truncate: Maximum characters for popup descriptions
50
65
  step:
51
- announcement: Announcement
52
- show_accepted: Show accepted proposals
53
- show_evaluating: Show evaluating proposals
66
+ announcement: Meddelande
67
+ show_accepted: Visa godkända förslag
68
+ show_evaluating: Visa förslag som utvärderas
54
69
  show_not_answered: Show not answered proposals
55
70
  show_rejected: Show rejected proposals
56
71
  show_withdrawn: Show withdrawn proposals
@@ -75,8 +90,16 @@ sv:
75
90
  delete: Delete
76
91
  edit: Edit
77
92
  title: 'Applicable only in these cases:'
93
+ create_scoped_style:
94
+ error: Error creating a new CSS box! %{error}
95
+ success: CSS box %{key} created successfully
96
+ destroy_scoped_style:
97
+ error: Error removing CSS box! %{error}
98
+ success: CSS box %{key} removed successfully
78
99
  experimental: Experimental options
79
100
  form:
101
+ errors:
102
+ incorrect_css: 'CSS in box #%{key} is invalid'
80
103
  help:
81
104
  allow_images_in_full_editor: This will add an image uploader icon in all the editors WYSIWYG with the full toolbar enabled.
82
105
  allow_images_in_markdown_editor: This will allow markdown editor to upload images by copy & paste or drag & drop.
@@ -86,7 +109,13 @@ sv:
86
109
  drag_and_drop_supported: When uploading images, Drag & Drop is supported. Images will be uploaded to the server and inserted as external resources (it doesn't use base64 inline encoding).
87
110
  intergram_about: Intergram uses Telegram messenger to handle a live support chat widget embedded in the bottom of the page.
88
111
  intergram_config: 'Invite the <a href="https://web.telegram.org/#/im?p=@IntergramBot">@Intergram bot</a> to your group or start a chat with it directly. <a href="https://github.com/idoco/intergram#embed-intergram-in-your-website-with-these-2-simple-steps">+ info</a>'
112
+ scoped_styles: Create custom CSS that applies only in certain parts of the public web (use the restrictions editor for that)
113
+ scoped_styles_variables: 'You can use the following CSS variables for organization customized colors:'
89
114
  use_markdown_editor: This will substitute the Quill WYSIWYG editor, use a Markdown editor instead. Text will be rendered as HTML in the public pages (text in database will be saved as markdown text)
115
+ form_styles:
116
+ new: Add a new CSS box
117
+ remove: Remove this CSS box
118
+ sure_to_remove: Are you sure you want to destroy this CSS box?
90
119
  rich_text_editor_in_public_views: 'NOTE: "Rich text editor for participants" is enabled, this option won''t apply. Use the editors hacks instead to enable images in proposals.'
91
120
  show:
92
121
  title: Tweaks for %{setting}
@@ -94,7 +123,7 @@ sv:
94
123
  system: Everywhere except participatory spaces
95
124
  update:
96
125
  error: Error updating configuration! %{error}
97
- success: Configuration updated successfully!
126
+ success: Configuration updated successfully
98
127
  constraints:
99
128
  create:
100
129
  error: Error creating condition case
@@ -119,8 +148,44 @@ sv:
119
148
  checks: System compatibility
120
149
  editors: Editor hacks
121
150
  livechat: Live Chat
151
+ menu_hacks: Menu tweaks
122
152
  proposals: Proposals hacks
153
+ styles: Custom styles
123
154
  surveys: Surveys & forms
155
+ menu_hacks:
156
+ create:
157
+ error: Error creating menu item! %{error}
158
+ success: Menu item created successfully
159
+ destroy:
160
+ error: Error removing menu item! %{error}
161
+ success: Menu item removed successfully
162
+ edit:
163
+ save: Spara
164
+ title: Redigera menyobjekt
165
+ form:
166
+ label_help: Translations aren't automatically detected, be sure to fill in all the fields!
167
+ target:
168
+ blank: Nytt fönster
169
+ self: Samma fönster
170
+ visibility:
171
+ default: Synligt
172
+ hidden: Alltid dolt
173
+ logged: Endast synlig för inloggade användare
174
+ non_logged: Only visible for non-logged users
175
+ index:
176
+ confirm_destroy: Are you sure to remove this customization?
177
+ edit: Edit
178
+ new: New item
179
+ remove: Remove addition
180
+ remove_hack: Remove customization
181
+ title: Main menu
182
+ new:
183
+ save: Spara
184
+ title: New menu item
185
+ update:
186
+ error: Error updating menu item! %{error}
187
+ success: Menu item updated successfully
188
+ url_exists: The same URL is already configured, please edit that instead of creating it again.
124
189
  config:
125
190
  intergram:
126
191
  auto_no_response: It seems that no one is available to answer right now. Please tell us how we can contact you, and we will get back to you as soon as we can.
@@ -132,14 +197,14 @@ sv:
132
197
  editor_images:
133
198
  create:
134
199
  error: Error uploading image!
135
- success: Image uploaded successfully!
200
+ success: Image uploaded successfully
136
201
  map_component:
137
202
  map:
138
203
  error:
139
204
  unavailable: The map is unavailable. Please configure geocoding to enable this component.
140
205
  show:
141
- view_meeting: View meeting
142
- view_proposal: View proposal
206
+ view_meeting: Visa möte
207
+ view_proposal: Visa förslag
143
208
  layouts:
144
209
  decidim:
145
210
  admin:
@@ -153,5 +218,8 @@ sv:
153
218
  autosaved_success: Data saved in local storage
154
219
  categories: Categories
155
220
  drag_and_drop_image: Add images by dragging & dropping or pasting them.
156
- meetings: Meetings
157
- proposals: Proposals
221
+ hashtags: Hashtags
222
+ items: items
223
+ meetings: Möten
224
+ proposals: Förslag
225
+ select_deselect_all: Select/deselect all
@@ -18,6 +18,7 @@ module Decidim
18
18
  autoload :SystemChecker, "decidim/decidim_awesome/system_checker"
19
19
  autoload :ContentRenderes, "decidim/decidim_awesome/content_renderers"
20
20
  autoload :ContextAnalyzers, "decidim/decidim_awesome/context_analyzers"
21
+ autoload :MenuHacker, "decidim/decidim_awesome/menu_hacker"
21
22
 
22
23
  # Boolean configuration options
23
24
  #
@@ -71,6 +72,20 @@ module Decidim
71
72
  {}
72
73
  end
73
74
 
75
+ # allows to keep modifications for the main menu
76
+ # can return :disabled to completly remove this feature
77
+ # otherwise it should be an array (some overrides can be specified by default):
78
+ # [
79
+ # {
80
+ # url: "/a-new-link",
81
+ # label: { "en" => "The label to show in the menu" },
82
+ # position: 10
83
+ # }
84
+ # ]
85
+ config_accessor :menu do
86
+ []
87
+ end
88
+
74
89
  # these settings do not follow the :disabled convention but
75
90
  # depends on the previous intergram configurations
76
91
  config_accessor :intergram_url do
@@ -12,6 +12,7 @@ module Decidim
12
12
  routes do
13
13
  # Add admin engine routes here
14
14
  resources :constraints
15
+ resources :menu_hacks, except: [:show]
15
16
  resources :config, param: :var, only: [:show, :update]
16
17
  post :new_scoped_style, to: "config#new_scoped_style"
17
18
  post :destroy_scoped_style, param: :key, to: "config#destroy_scoped_style"
@@ -56,7 +56,7 @@ module Decidim
56
56
 
57
57
  styles = awesome_config[:scoped_styles]&.filter do |key, _value|
58
58
  config = AwesomeConfig.find_by(var: "scoped_style_#{key}", organization: current_organization)
59
- @awesome_config_instance.valid_in_context?(config.constraints)
59
+ @awesome_config_instance.valid_in_context?(config&.constraints)
60
60
  end
61
61
  @awesome_custom_styles = styles.values.join("\n")
62
62
  end
@@ -1,17 +1,20 @@
1
1
  decidim-admin:
2
2
  /app/views/layouts/decidim/admin/_header.html.erb:
3
- decidim-0.22: 6af51ec6b8a760b0ee6e00a7834f5f9a
4
3
  decidim-0.23: 45f0e15f1b02a1c1a73b1a2184fd55af
5
4
  decidim-core:
6
5
  /app/views/layouts/decidim/_head.html.erb:
7
- decidim-0.22: bf16a58cd9e6d3f73e6875ff3d0b1e48
8
6
  decidim-0.23: e7f5eea07e884665474948ea750fc720
9
7
  /app/assets/javascripts/decidim/editor.js.es6:
10
- decidim-0.22: 797d0ec1c9e79453cf6718f82d2fdd27
11
8
  decidim-0.23: cb059b8ff0ffc62c67eb99d8d7a6637b
12
9
  decidim-0.23.1: 4787f73f0f33661e3897404f10019d26
10
+ decidim-0.24: 35262835144421baa700a34ca0939396
11
+ /app/presenters/decidim/menu_presenter.rb:
12
+ decidim-0.23: 042743c44a2aff284b493c7bebbccbb3
13
+ decidim-0.24: 284c96f19cd98df091d8178d6db5a8b3
14
+ /app/presenters/decidim/menu_item_presenter.rb:
15
+ decidim-0.23: 70db39954b5840924530bf94d2a0a73a
13
16
  decidim-proposals:
14
17
  /app/presenters/decidim/proposals/proposal_presenter.rb:
15
- decidim-0.22: 7d60c8310d7fa4e38d9a27080c22b12c
16
18
  decidim-0.23: 437c0c25151f605401a4f14d090ba5ea
17
19
  decidim-0.23.1: 892021b2ce9ac10c2e1b738e6948cde0
20
+ decidim-0.24: 0b6717a3eeecad03277cea5ed6ba1fb7
@@ -119,9 +119,7 @@ module Decidim
119
119
  def enabled_for_organization?(key)
120
120
  case key.to_sym
121
121
  when :allow_images_in_proposals
122
- if @organization.respond_to? :rich_text_editor_in_public_views
123
- return false if @organization.rich_text_editor_in_public_views
124
- end
122
+ return false if @organization.rich_text_editor_in_public_views
125
123
  end
126
124
  true
127
125
  end
@@ -15,13 +15,13 @@ module Decidim
15
15
  end
16
16
 
17
17
  initializer "decidim_awesome.view_helpers" do
18
- ActionView::Base.send :include, AwesomeHelpers
18
+ ActionView::Base.include AwesomeHelpers
19
19
  end
20
20
 
21
21
  initializer "decidim_decidim_awesome.assets" do |app|
22
22
  app.config.assets.precompile += %w(decidim_decidim_awesome_manifest.js decidim_decidim_awesome_manifest.css)
23
- # add to precompile any present
24
- Dir.glob(Rails.root.join("app", "assets", "themes", "*.*")).each do |path|
23
+ # add to precompile any present theme asset
24
+ Dir.glob(Rails.root.join("app/assets/themes/*.*")).each do |path|
25
25
  app.config.assets.precompile << path
26
26
  end
27
27
  end
@@ -43,7 +43,7 @@ Decidim.register_component(:awesome_iframe) do |component|
43
43
  published_at: Time.current,
44
44
  participatory_space: participatory_space,
45
45
  settings: {
46
- announcement: { en: Faker::Lorem.paragraphs(2).join("\n") }
46
+ announcement: { en: Faker::Lorem.paragraphs(number: 2).join("\n") }
47
47
  }
48
48
  }
49
49
 
@@ -16,7 +16,13 @@ Decidim.register_component(:awesome_map) do |component|
16
16
  # Available types: :integer, :boolean
17
17
  settings.attribute :announcement, type: :text, translated: true, editor: true
18
18
  settings.attribute :map_height, type: :integer, default: 700
19
+ settings.attribute :map_center, type: :string, default: ""
20
+ settings.attribute :map_zoom, type: :integer, default: 8
21
+ settings.attribute :truncate, type: :integer, default: 255
19
22
  settings.attribute :collapse, type: :boolean, default: false
23
+ settings.attribute :menu_amendments, type: :boolean, default: true
24
+ settings.attribute :menu_meetings, type: :boolean, default: true
25
+ settings.attribute :menu_hashtags, type: :boolean, default: true
20
26
  end
21
27
 
22
28
  component.settings(:step) do |settings|
@@ -26,7 +32,7 @@ Decidim.register_component(:awesome_map) do |component|
26
32
  settings.attribute :show_evaluating, type: :boolean, default: true
27
33
  settings.attribute :show_accepted, type: :boolean, default: true
28
34
  # Not possible yet (needs graphql update):
29
- # settings.attribute :show_rejected, type: :boolean, default: false
35
+ settings.attribute :show_rejected, type: :boolean, default: false
30
36
  settings.attribute :show_withdrawn, type: :boolean, default: false
31
37
  end
32
38
 
@@ -47,7 +53,7 @@ Decidim.register_component(:awesome_map) do |component|
47
53
  published_at: Time.current,
48
54
  participatory_space: participatory_space,
49
55
  settings: {
50
- announcement: { en: Faker::Lorem.paragraphs(2).join("\n") }
56
+ announcement: { en: Faker::Lorem.paragraphs(number: 2).join("\n") }
51
57
  }
52
58
  }
53
59
 
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DecidimAwesome
5
+ class MenuHacker
6
+ include Decidim::TranslatableAttributes
7
+ def initialize(name, view)
8
+ @name = name
9
+ @organization = view.try(:current_organization)
10
+ @user = view.try(:current_user)
11
+ @view = view
12
+ end
13
+
14
+ # returns a combined array of the Decidim defined menu and the hacked stored as config vars
15
+ def items(include_invisible: false)
16
+ return @items if @items
17
+
18
+ @items = default_items
19
+ menu_overrides.each do |item|
20
+ default = default_items.find { |i| i.url.gsub(/\?.*/, "") == item.url }
21
+ if default
22
+ item.send("overrided?=", true)
23
+ @items.reject! { |i| i.url.gsub(/\?.*/, "") == item.url }
24
+ end
25
+ @items << item
26
+ end
27
+
28
+ @items.select!(&:visible?) unless include_invisible
29
+ @items.sort_by!(&:position)
30
+ end
31
+
32
+ private
33
+
34
+ attr_accessor :organization, :user
35
+ attr_reader :name, :view
36
+
37
+ def default_items
38
+ @default_items ||= build_menu.instance_variable_get(:@items).map do |item|
39
+ item.instance_variable_set(:@active, method(:activate?)) unless item.active == :exact
40
+ item
41
+ end
42
+ end
43
+
44
+ def build_menu
45
+ menu = Decidim::Menu.new(name)
46
+ menu.build_for(view)
47
+ menu
48
+ end
49
+
50
+ def menu_overrides
51
+ @menu_overrides ||= current_config.map do |item|
52
+ OpenStruct.new(
53
+ label: translated_attribute(item["label"], organization),
54
+ raw_label: item["label"],
55
+ url: item["url"],
56
+ position: item["position"] || 1,
57
+ # see options in https://github.com/comfy/active_link_to
58
+ active: method(:activate?),
59
+ visibility: item["visibility"],
60
+ visible?: visible?(item),
61
+ target: item["target"],
62
+ overrided?: false
63
+ )
64
+ end
65
+ end
66
+
67
+ def activate?(url, view)
68
+ urls = @items.map(&:url).sort_by(&:length).reverse
69
+ url == urls.find { |u| view.request.original_fullpath.start_with?(u) }
70
+ end
71
+
72
+ def visible?(item)
73
+ case item["visibility"]
74
+ when "hidden"
75
+ false
76
+ when "logged"
77
+ user.present?
78
+ when "non_logged"
79
+ user.blank?
80
+ else
81
+ true
82
+ end
83
+ end
84
+
85
+ def current_config
86
+ @current_config ||= (AwesomeConfig.find_by(var: name, organization: organization)&.value || []).filter { |i| i.is_a? Hash }
87
+ end
88
+ end
89
+ end
90
+ end
@@ -14,7 +14,7 @@ module Decidim
14
14
  @overrides = checksums.map do |package, files|
15
15
  props = {
16
16
  spec: ::Gem::Specification.find_by_name(package),
17
- files: files.map { |file, signatures| [file, signatures.values] }.to_h
17
+ files: files.transform_values(&:values)
18
18
  }
19
19
  [package, to_struct(props)]
20
20
  end