decidim-decidim_awesome 0.7.2 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +181 -0
  3. data/README.md +61 -35
  4. data/Rakefile +11 -12
  5. data/app/cells/decidim/decidim_awesome/content_blocks/map/error.erb +11 -0
  6. data/app/cells/decidim/decidim_awesome/content_blocks/map/show.erb +1 -61
  7. data/app/cells/decidim/decidim_awesome/content_blocks/map_cell.rb +11 -0
  8. data/app/cells/decidim/decidim_awesome/content_blocks/map_form/show.erb +8 -4
  9. data/app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb +51 -0
  10. data/app/commands/decidim/decidim_awesome/admin/destroy_custom_redirect.rb +47 -0
  11. data/app/commands/decidim/decidim_awesome/admin/update_custom_redirect.rb +49 -0
  12. data/app/commands/decidim/decidim_awesome/create_editor_image.rb +12 -5
  13. data/app/controllers/concerns/decidim/decidim_awesome/not_found_redirect.rb +58 -0
  14. data/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +24 -24
  15. data/app/controllers/decidim/decidim_awesome/admin/config_controller.rb +9 -1
  16. data/app/controllers/decidim/decidim_awesome/admin/custom_redirects_controller.rb +91 -0
  17. data/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb +5 -8
  18. data/app/controllers/decidim/decidim_awesome/blank_component_controller.rb +19 -0
  19. data/app/controllers/decidim/decidim_awesome/editor_images_controller.rb +2 -3
  20. data/app/controllers/decidim/decidim_awesome/iframe_component/iframe_controller.rb +1 -1
  21. data/app/controllers/decidim/decidim_awesome/map_component/map_controller.rb +2 -6
  22. data/app/forms/decidim/decidim_awesome/admin/config_form.rb +2 -0
  23. data/app/forms/decidim/decidim_awesome/admin/custom_redirect_form.rb +45 -0
  24. data/app/forms/decidim/decidim_awesome/editor_image_form.rb +3 -2
  25. data/app/forms/decidim/decidim_awesome/proposals/proposal_wizard_create_step_form_override.rb +38 -0
  26. data/app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb +22 -9
  27. data/app/helpers/decidim/decidim_awesome/admin/system_checker_helpers.rb +36 -0
  28. data/app/helpers/decidim/decidim_awesome/map_helper.rb +18 -12
  29. data/app/helpers/decidim/decidim_awesome/proposals/application_helper_override.rb +2 -2
  30. data/app/jobs/decidim/decidim_awesome/migrate_legacy_images_job.rb +106 -0
  31. data/app/models/decidim/decidim_awesome/editor_image.rb +4 -9
  32. data/app/packs/entrypoints/decidim_admin_decidim_awesome.js +5 -0
  33. data/app/packs/entrypoints/decidim_admin_decidim_awesome.scss +1 -0
  34. data/app/packs/entrypoints/decidim_admin_decidim_awesome_custom_fields.js +2 -0
  35. data/app/packs/entrypoints/decidim_decidim_awesome.js +9 -0
  36. data/app/packs/entrypoints/decidim_decidim_awesome.scss +1 -0
  37. data/app/packs/entrypoints/decidim_decidim_awesome_admin_form_exit_warn.js +1 -0
  38. data/app/packs/entrypoints/decidim_decidim_awesome_custom_fields.js +1 -0
  39. data/app/packs/entrypoints/decidim_decidim_awesome_iframe.scss +1 -0
  40. data/app/packs/entrypoints/decidim_decidim_awesome_map.js +5 -0
  41. data/app/packs/entrypoints/decidim_decidim_awesome_map.scss +1 -0
  42. data/app/{assets → packs}/images/decidim/decidim_awesome/platoniq-logo.png +0 -0
  43. data/app/{assets/javascripts/decidim/decidim_awesome/admin/auto_edit.js.es6 → packs/src/decidim/decidim_awesome/admin/auto_edit.js} +39 -34
  44. data/app/packs/src/decidim/decidim_awesome/admin/check_redirections.js +48 -0
  45. data/app/{assets/javascripts/decidim/decidim_awesome/admin/codemirror.js.es6 → packs/src/decidim/decidim_awesome/admin/codemirror.js} +4 -4
  46. data/app/packs/src/decidim/decidim_awesome/admin/constraints.js +55 -0
  47. data/app/{assets/javascripts/decidim/decidim_awesome/admin/form_builder.js.es6 → packs/src/decidim/decidim_awesome/admin/custom_fields_builder.js} +23 -26
  48. data/app/{assets/javascripts/decidim/decidim_awesome/admin/form_exit_warn.js.es6 → packs/src/decidim/decidim_awesome/admin/form_exit_warn.js} +0 -2
  49. data/app/{assets/javascripts/decidim/decidim_awesome/admin/user_picker.js.es6 → packs/src/decidim/decidim_awesome/admin/user_picker.js} +3 -3
  50. data/app/packs/src/decidim/decidim_awesome/awesome_admin.js +23 -0
  51. data/app/packs/src/decidim/decidim_awesome/awesome_application.js +17 -0
  52. data/app/{assets/javascripts/decidim/decidim_awesome/awesome_map/api_fetcher.js.es6 → packs/src/decidim/decidim_awesome/awesome_map/api/api_fetcher.js} +1 -15
  53. data/app/packs/src/decidim/decidim_awesome/awesome_map/api/fetcher.js +134 -0
  54. data/app/packs/src/decidim/decidim_awesome/awesome_map/api/meetings_fetcher.js +59 -0
  55. data/app/packs/src/decidim/decidim_awesome/awesome_map/api/proposals_fetcher.js +52 -0
  56. data/app/packs/src/decidim/decidim_awesome/awesome_map/awesome_map.js +129 -0
  57. data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/controller.js +130 -0
  58. data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/meetings_controller.js +31 -0
  59. data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/proposals_controller.js +88 -0
  60. data/app/packs/src/decidim/decidim_awesome/awesome_map/controls_ui.js +221 -0
  61. data/app/packs/src/decidim/decidim_awesome/awesome_map/load_map.js +51 -0
  62. data/app/packs/src/decidim/decidim_awesome/editors/editor.js +191 -0
  63. data/app/{assets/javascripts/decidim/decidim_awesome/editors/tabs_focus.js.es6 → packs/src/decidim/decidim_awesome/editors/tabs_focus.js} +4 -6
  64. data/app/{assets/javascripts/decidim/decidim_awesome/forms/autosave.js.es6 → packs/src/decidim/decidim_awesome/forms/autosave.js} +20 -17
  65. data/app/packs/src/decidim/decidim_awesome/forms/custom_fields_renderer.js +207 -0
  66. data/app/{assets/javascripts/decidim/decidim_awesome/forms/rich_text_plugin.js.es6 → packs/src/decidim/decidim_awesome/forms/rich_text_plugin.js} +23 -21
  67. data/app/packs/src/decidim/decidim_awesome/proposals/custom_fields.js +22 -0
  68. data/app/packs/src/decidim/decidim_awesome/proposals/images.js +25 -0
  69. data/{vendor/assets/javascripts → app/packs/src/vendor}/image-resize.min.js +0 -0
  70. data/{vendor/assets/javascripts → app/packs/src/vendor}/image-upload.min.js +0 -0
  71. data/{vendor/assets/javascripts → app/packs/src/vendor}/jquery.truncate.js +0 -0
  72. data/app/packs/src/vendor/leaflet.featuregroup.subgroup.js +184 -0
  73. data/app/{assets → packs}/stylesheets/decidim/decidim_awesome/admin/auto_edits.scss +2 -1
  74. data/app/packs/stylesheets/decidim/decidim_awesome/admin/check_redirections.scss +28 -0
  75. data/app/{assets → packs}/stylesheets/decidim/decidim_awesome/admin/codemirror.scss +8 -6
  76. data/app/{assets → packs}/stylesheets/decidim/decidim_awesome/admin/constraints.scss +13 -13
  77. data/app/{assets → packs}/stylesheets/decidim/decidim_awesome/admin/custom_fields.scss +37 -10
  78. data/app/packs/stylesheets/decidim/decidim_awesome/admin/user_picker.scss +41 -0
  79. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_admin.scss +71 -0
  80. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_application.scss +19 -0
  81. data/app/{assets → packs}/stylesheets/decidim/decidim_awesome/awesome_iframe/iframe.scss +3 -3
  82. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_map/map.scss +176 -0
  83. data/app/{assets → packs}/stylesheets/decidim/decidim_awesome/editors/markdown_editor.scss +6 -4
  84. data/app/packs/stylesheets/decidim/decidim_awesome/editors/quill_editor.scss +58 -0
  85. data/app/{assets → packs}/stylesheets/decidim/decidim_awesome/forms/autosave.scss +2 -2
  86. data/app/packs/stylesheets/vendor/select2-foundation-theme.scss +348 -0
  87. data/app/presenters/decidim/decidim_awesome/menu_item_presenter_override.rb +25 -0
  88. data/app/presenters/decidim/decidim_awesome/menu_presenter_override.rb +23 -0
  89. data/app/uploaders/decidim/cw/decidim_awesome/image_uploader.rb +26 -0
  90. data/app/uploaders/decidim/decidim_awesome/image_uploader.rb +4 -16
  91. data/app/views/decidim/decidim_awesome/admin/checks/index.html.erb +28 -22
  92. data/app/views/decidim/decidim_awesome/admin/config/_constraints.html.erb +1 -1
  93. data/app/views/decidim/decidim_awesome/admin/config/_form_admins.html.erb +1 -1
  94. data/app/views/decidim/decidim_awesome/admin/config/_form_editors.html.erb +1 -0
  95. data/app/views/decidim/decidim_awesome/admin/config/_form_proposal_custom_fields.html.erb +1 -1
  96. data/app/views/decidim/decidim_awesome/admin/config/_form_styles.html.erb +7 -6
  97. data/app/views/decidim/decidim_awesome/admin/config/_modal.html.erb +1 -1
  98. data/app/views/decidim/decidim_awesome/admin/config/show.html.erb +3 -3
  99. data/app/views/decidim/decidim_awesome/admin/constraints/new.html.erb +1 -1
  100. data/app/views/decidim/decidim_awesome/admin/custom_redirects/_form.html.erb +6 -0
  101. data/app/views/decidim/decidim_awesome/admin/custom_redirects/edit.html.erb +13 -0
  102. data/app/views/decidim/decidim_awesome/admin/custom_redirects/index.html.erb +37 -0
  103. data/app/views/decidim/decidim_awesome/admin/custom_redirects/new.html.erb +13 -0
  104. data/app/views/decidim/decidim_awesome/admin/menu_hacks/edit.html.erb +1 -1
  105. data/app/views/decidim/decidim_awesome/admin/menu_hacks/new.html.erb +1 -1
  106. data/app/views/decidim/decidim_awesome/admin/proposals/_editor.html.erb +5 -3
  107. data/app/views/decidim/decidim_awesome/iframe_component/iframe/show.html.erb +1 -1
  108. data/app/views/decidim/decidim_awesome/map_component/map/_api_ready.html.erb +3 -0
  109. data/app/views/decidim/decidim_awesome/map_component/map/_map_template.html.erb +68 -0
  110. data/app/views/decidim/decidim_awesome/map_component/map/{error.erb → error.html.erb} +2 -0
  111. data/app/views/decidim/decidim_awesome/map_component/map/show.html.erb +3 -67
  112. data/app/views/decidim/proposals/admin/proposals/_form.html.erb +1 -1
  113. data/app/views/layouts/decidim/admin/decidim_awesome.html.erb +13 -9
  114. data/app/views/layouts/decidim/decidim_awesome/_awesome_config.html.erb +0 -2
  115. data/app/views/{v0.24 → v0.25}/decidim/proposals/collaborative_drafts/_show.html.erb +0 -0
  116. data/app/views/{v0.23 → v0.25}/layouts/decidim/_head.html.erb +12 -10
  117. data/app/views/v0.25/layouts/decidim/admin/_header.html.erb +11 -0
  118. data/app/views/{v0.23 → v0.26}/decidim/proposals/collaborative_drafts/_show.html.erb +1 -7
  119. data/app/views/{v0.24 → v0.26}/layouts/decidim/_head.html.erb +16 -10
  120. data/app/views/v0.26/layouts/decidim/admin/_header.html.erb +11 -0
  121. data/config/assets.rb +46 -0
  122. data/config/i18n-tasks.yml +6 -0
  123. data/config/locales/ca.yml +77 -13
  124. data/config/locales/cs.yml +65 -1
  125. data/config/locales/en.yml +69 -1
  126. data/config/locales/es.yml +65 -1
  127. data/config/locales/eu.yml +0 -232
  128. data/config/locales/fr.yml +117 -53
  129. data/config/locales/it.yml +65 -1
  130. data/config/locales/ja.yml +66 -3
  131. data/config/locales/nl.yml +5 -46
  132. data/config/locales/pt-BR.yml +348 -0
  133. data/config/locales/pt-PT.yml +7 -0
  134. data/config/locales/pt.yml +7 -0
  135. data/config/locales/sv.yml +67 -182
  136. data/lib/decidim/decidim_awesome/admin_engine.rb +10 -15
  137. data/lib/decidim/decidim_awesome/awesome.rb +214 -0
  138. data/lib/decidim/decidim_awesome/awesome_helpers.rb +0 -7
  139. data/lib/decidim/decidim_awesome/checksums.yml +13 -16
  140. data/lib/decidim/decidim_awesome/config.rb +1 -0
  141. data/lib/decidim/decidim_awesome/content_parsers/editor_images_parser.rb +39 -0
  142. data/lib/decidim/decidim_awesome/engine.rb +27 -55
  143. data/lib/decidim/decidim_awesome/iframe_component/admin_engine.rb +23 -0
  144. data/lib/decidim/decidim_awesome/iframe_component/component.rb +6 -6
  145. data/lib/decidim/decidim_awesome/map_component/admin_engine.rb +23 -0
  146. data/lib/decidim/decidim_awesome/map_component/component.rb +6 -5
  147. data/lib/decidim/decidim_awesome/map_component/engine.rb +34 -0
  148. data/lib/decidim/decidim_awesome/menu_hacker.rb +1 -0
  149. data/lib/decidim/decidim_awesome/test/factories.rb +2 -2
  150. data/lib/decidim/decidim_awesome/test/initializer.rb +25 -0
  151. data/lib/decidim/decidim_awesome/test/layouts/decidim/_head.html.erb +30 -2
  152. data/lib/decidim/decidim_awesome/test/layouts/decidim/admin/_header.html.erb +7 -2
  153. data/lib/decidim/decidim_awesome/test/shared_examples/config_examples.rb +18 -0
  154. data/lib/decidim/decidim_awesome/test/shared_examples/controller_examples.rb +13 -0
  155. data/lib/decidim/decidim_awesome/test/shared_examples/custom_redirects_contexts.rb +47 -0
  156. data/lib/decidim/decidim_awesome/test/shared_examples/menu_hack_contexts.rb +0 -17
  157. data/lib/decidim/decidim_awesome/test/shared_examples/scoped_admins_examples.rb +9 -17
  158. data/lib/decidim/decidim_awesome/test/shared_examples/summary_examples.rb +202 -0
  159. data/lib/decidim/decidim_awesome/version.rb +2 -2
  160. data/lib/decidim/decidim_awesome.rb +4 -152
  161. data/lib/tasks/decidim_awesome_active_storage_migrations_tasks.rake +37 -0
  162. data/lib/tasks/decidim_awesome_webpacker_tasks.rake +64 -0
  163. data/package.json +211 -0
  164. metadata +113 -113
  165. data/app/assets/config/decidim_admin_decidim_awesome_manifest.css +0 -3
  166. data/app/assets/config/decidim_admin_decidim_awesome_manifest.js +0 -2
  167. data/app/assets/config/decidim_decidim_awesome_manifest.css +0 -5
  168. data/app/assets/config/decidim_decidim_awesome_manifest.js +0 -4
  169. data/app/assets/config/legacy_decidim_admin_decidim_awesome_manifest.js +0 -2
  170. data/app/assets/config/legacy_decidim_decidim_awesome_manifest.js +0 -4
  171. data/app/assets/javascripts/decidim/decidim_awesome/admin/constraints.js.es6 +0 -54
  172. data/app/assets/javascripts/decidim/decidim_awesome/admin/legacy_form_builder.js.es6 +0 -80
  173. data/app/assets/javascripts/decidim/decidim_awesome/awesome_admin.js +0 -7
  174. data/app/assets/javascripts/decidim/decidim_awesome/awesome_application.js +0 -3
  175. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/categories.js.es6 +0 -25
  176. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/hashtags.js.es6 +0 -48
  177. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/layers.js.es6 +0 -107
  178. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/load_map.js.es6 +0 -15
  179. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/map.js.es6 +0 -207
  180. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/markers.js.es6 +0 -56
  181. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/meetings.js.es6 +0 -132
  182. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/proposals.js.es6 +0 -107
  183. data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/utilities.js.es6 +0 -57
  184. data/app/assets/javascripts/decidim/decidim_awesome/editors/legacy_quill_editor.js.es6 +0 -172
  185. data/app/assets/javascripts/decidim/decidim_awesome/editors/quill_editor.js.es6 +0 -185
  186. data/app/assets/javascripts/decidim/decidim_awesome/forms/custom_fields_builder.js.es6 +0 -211
  187. data/app/assets/javascripts/decidim/decidim_awesome/legacy_admin.js +0 -7
  188. data/app/assets/javascripts/decidim/decidim_awesome/legacy_application.js +0 -3
  189. data/app/assets/javascripts/decidim/decidim_awesome/proposals/custom_fields.js.es6 +0 -21
  190. data/app/assets/javascripts/decidim/decidim_awesome/proposals/images.js.es6 +0 -25
  191. data/app/assets/stylesheets/decidim/decidim_awesome/admin/user_picker.scss +0 -35
  192. data/app/assets/stylesheets/decidim/decidim_awesome/awesome_admin.scss +0 -64
  193. data/app/assets/stylesheets/decidim/decidim_awesome/awesome_application.scss +0 -22
  194. data/app/assets/stylesheets/decidim/decidim_awesome/awesome_map/leaflet.scss.erb +0 -18
  195. data/app/assets/stylesheets/decidim/decidim_awesome/awesome_map/map.scss +0 -160
  196. data/app/assets/stylesheets/decidim/decidim_awesome/editors/quill_editor.scss +0 -22
  197. data/app/awesome_overrides/forms/decidim/proposals/proposal_wizard_create_step_form_override.rb +0 -28
  198. data/app/awesome_overrides/presenters/decidim/menu_presenter_override.rb +0 -39
  199. data/app/controllers/concerns/decidim/decidim_awesome/admin_not_found_redirect.rb +0 -39
  200. data/app/controllers/decidim/decidim_awesome/iframe_component/application_controller.rb +0 -15
  201. data/app/controllers/decidim/decidim_awesome/map_component/application_controller.rb +0 -15
  202. data/app/views/v0.23/layouts/decidim/admin/_header.html.erb +0 -12
  203. data/app/views/v0.24/layouts/decidim/admin/_header.html.erb +0 -12
  204. data/lib/decidim/decidim_awesome/test/themes/css.lvh.me.css +0 -3
  205. data/lib/decidim/decidim_awesome/test/themes/erb.lvh.me.scss.erb +0 -2
  206. data/lib/decidim/decidim_awesome/test/themes/scss.lvh.me.scss +0 -1
  207. data/lib/decidim/decidim_awesome/test/themes/test-theme/body.scss +0 -4
  208. data/vendor/assets/images/layers-2x.png +0 -0
  209. data/vendor/assets/images/layers.png +0 -0
  210. data/vendor/assets/images/marker-icon.png +0 -0
  211. data/vendor/assets/javascripts/codemirror-4.inline-attachment.js +0 -89
  212. data/vendor/assets/javascripts/codemirror.js +0 -9801
  213. data/vendor/assets/javascripts/delta.min.js +0 -405
  214. data/vendor/assets/javascripts/delta.min.js.map +0 -1
  215. data/vendor/assets/javascripts/europa.min.js +0 -4
  216. data/vendor/assets/javascripts/form-builder.min.js +0 -19
  217. data/vendor/assets/javascripts/form-render.min.js +0 -19
  218. data/vendor/assets/javascripts/form-storage.js +0 -824
  219. data/vendor/assets/javascripts/highlight.min.js +0 -44
  220. data/vendor/assets/javascripts/inline-attachment.js +0 -399
  221. data/vendor/assets/javascripts/inscrybmde.min.js +0 -7
  222. data/vendor/assets/javascripts/jquery-ui.min.js +0 -13
  223. data/vendor/assets/javascripts/jquery.inline-attachment.js +0 -66
  224. data/vendor/assets/javascripts/jsrender.min.js +0 -4
  225. data/vendor/assets/javascripts/keymap/sublime.js +0 -720
  226. data/vendor/assets/javascripts/leaflet.featuregroup.subgroup.js +0 -6
  227. data/vendor/assets/javascripts/mode/css/css.js +0 -864
  228. data/vendor/assets/javascripts/select2.js +0 -6147
  229. data/vendor/assets/langs/en-US.lang +0 -110
  230. data/vendor/assets/stylesheets/codemirror.css +0 -350
  231. data/vendor/assets/stylesheets/default.min.css +0 -1
  232. data/vendor/assets/stylesheets/foundation.min.css +0 -1
  233. data/vendor/assets/stylesheets/github.min.css +0 -2
  234. data/vendor/assets/stylesheets/inscrybmde.min.scss +0 -194
  235. data/vendor/assets/stylesheets/jquery-ui.min.css +0 -7
  236. data/vendor/assets/stylesheets/select2-foundation-theme.css +0 -249
  237. data/vendor/assets/stylesheets/select2.css +0 -515
@@ -0,0 +1,17 @@
1
+ import "src/decidim/decidim_awesome/proposals/images"
2
+ import "src/decidim/decidim_awesome/forms/autosave"
3
+ import {destroyQuillEditor, createQuillEditor, createMarkdownEditor} from "src/decidim/decidim_awesome/editors/editor"
4
+
5
+ $(() => {
6
+ // rebuild editors
7
+ if (window.DecidimAwesome.allow_images_in_full_editor || window.DecidimAwesome.allow_images_in_small_editor || window.DecidimAwesome.use_markdown_editor) {
8
+ $(".editor-container").each((_idx, container) => {
9
+ destroyQuillEditor(container);
10
+ if (window.DecidimAwesome.use_markdown_editor) {
11
+ createMarkdownEditor(container);
12
+ } else {
13
+ createQuillEditor(container);
14
+ }
15
+ });
16
+ }
17
+ });
@@ -1,5 +1,4 @@
1
- class ApiFetcher { // eslint-disable-line no-unused-vars
2
-
1
+ export default class ApiFetcher { // eslint-disable-line no-unused-vars
3
2
  constructor(query, variables) {
4
3
  this.query = query;
5
4
  this.variables = variables;
@@ -22,17 +21,4 @@ class ApiFetcher { // eslint-disable-line no-unused-vars
22
21
  fetchAll (callback) {
23
22
  this.fetch(callback);
24
23
  }
25
-
26
- static findTranslation(translations) {
27
- let text, lang = document.querySelector('html').getAttribute('lang');
28
-
29
- translations.forEach((t) => {
30
- if(t.text) {
31
- if(!text || t.locale == lang) {
32
- text = t.text
33
- }
34
- }
35
- });
36
- return text;
37
- }
38
24
  }
@@ -0,0 +1,134 @@
1
+ import ApiFetcher from "src/decidim/decidim_awesome/awesome_map/api/api_fetcher";
2
+
3
+ export default class Fetcher {
4
+ constructor(controller) {
5
+ this.controller = controller;
6
+ this.config = {
7
+ length: controller.awesomeMap.config.length || 255
8
+ };
9
+ this.onFinished = () => {};
10
+ this.onNode = () => {};
11
+ this.onCollection = () => {};
12
+ this.hashtags = [];
13
+
14
+ this.collection = this.controller.component.type;
15
+ // override in specific components:
16
+ this.query = `query ($id: ID!, $after: String!) {
17
+ component(id: $id) {
18
+ id
19
+ __typename
20
+ }
21
+ }`;
22
+ }
23
+
24
+ fetch(after = "") {
25
+ const variables = {
26
+ "id": this.controller.component.id,
27
+ "after": after
28
+ };
29
+ const api = new ApiFetcher(this.query, variables);
30
+ api.fetchAll((result) => {
31
+ if (result) {
32
+ const collection = result.component[this.collection];
33
+ // console.log("collection",collection)
34
+
35
+ collection.edges.forEach((element) => {
36
+ let node = element.node;
37
+ if (!node) {
38
+ return;
39
+ }
40
+
41
+ if (node.coordinates && node.coordinates.latitude && node.coordinates.longitude) {
42
+ this.decorateNode(node);
43
+ this.onNode(node)
44
+ }
45
+ });
46
+
47
+ this.onCollection(collection);
48
+
49
+ if (collection.pageInfo.hasNextPage) {
50
+ this.fetch(collection.pageInfo.endCursor);
51
+ } else {
52
+ this.onFinished();
53
+ }
54
+ }
55
+ });
56
+ }
57
+
58
+ decorateNode(node) {
59
+ const body = this.findTranslation(node.body.translations);
60
+ const title = this.findTranslation(node.title.translations);
61
+ node.hashtags = this.collectHashtags(title);
62
+ node.hashtags = node.hashtags.concat(this.collectHashtags(body));
63
+ // hashtags in the title look ugly, lets replace the gid:... structure with the tag #name
64
+ node.title.translation = this.replaceHashtags(title, node.hashtags);
65
+ node.body.translation = this.appendHtmlHashtags(this.truncate(this.removeHashtags(body)).replace(/\n/g, "<br>"), node.hashtags);
66
+ node.link = `${this.controller.component.url}/${this.collection}/${node.id}`;
67
+ }
68
+
69
+ findTranslation(translations) {
70
+ let text,
71
+ lang = document.querySelector("html").getAttribute("lang");
72
+
73
+ translations.forEach((t) => {
74
+ if (t.text) {
75
+ if (!text || t.locale == lang) {
76
+ text = t.text
77
+ }
78
+ }
79
+ });
80
+ return text;
81
+ }
82
+
83
+ collectHashtags(text) {
84
+ let tags = [];
85
+ if (text) {
86
+ const gids = text.match(/gid:\/\/[^\s<&]+/g)
87
+ if (gids) {
88
+ tags = gids.filter((gid) => gid.indexOf("/Decidim::Hashtag/") != -1).map((gid) => {
89
+ const parts = gid.split("/");
90
+ const fromSelector = parts[5].charAt(0) == "_";
91
+ const tag = fromSelector
92
+ ? parts[5].substr(1)
93
+ : parts[5];
94
+ const name = `#${tag}`;
95
+ const html = `<a href="/search?term=${name}">${name}</a>`;
96
+ const hashtag = {
97
+ color: getComputedStyle(document.documentElement).getPropertyValue("--secondary"),
98
+ gid: gid,
99
+ id: parseInt(parts[4], 10),
100
+ fromSelector: fromSelector,
101
+ tag: tag,
102
+ name: name,
103
+ html: html
104
+ }
105
+ this.hashtags.push(hashtag)
106
+ return hashtag;
107
+ });
108
+ }
109
+ }
110
+ return tags;
111
+ }
112
+
113
+ replaceHashtags(text, hashtags) {
114
+ hashtags.forEach((tag) => {
115
+ text = text.replace(tag.gid, tag.name)
116
+ });
117
+ return text;
118
+ }
119
+
120
+ removeHashtags(text) {
121
+ return text.replace(/gid:\/\/[^\s<&]+/g, "");
122
+ }
123
+
124
+ appendHtmlHashtags(text, tags) {
125
+ tags.forEach((tag) => {
126
+ text += ` ${tag.html}`;
127
+ });
128
+ return text;
129
+ }
130
+
131
+ truncate(html) {
132
+ return $.truncate(html, this.config);
133
+ }
134
+ }
@@ -0,0 +1,59 @@
1
+ import Fetcher from "src/decidim/decidim_awesome/awesome_map/api/fetcher";
2
+
3
+ export default class MeetingsFetcher extends Fetcher {
4
+ constructor(controller) {
5
+ super(controller);
6
+ this.query = `query ($id: ID!, $after: String!) {
7
+ component(id: $id) {
8
+ id
9
+ __typename
10
+ ... on Meetings {
11
+ meetings(first: 50, after: $after) {
12
+ pageInfo {
13
+ hasNextPage
14
+ endCursor
15
+ }
16
+ edges {
17
+ node {
18
+ id
19
+ title {
20
+ translations {
21
+ text
22
+ locale
23
+ }
24
+ }
25
+ body: description {
26
+ translations {
27
+ text
28
+ locale
29
+ }
30
+ }
31
+ startTime
32
+ location {
33
+ translations {
34
+ text
35
+ locale
36
+ }
37
+ }
38
+ address
39
+ locationHints {
40
+ translations {
41
+ text
42
+ locale
43
+ }
44
+ }
45
+ coordinates {
46
+ latitude
47
+ longitude
48
+ }
49
+ category {
50
+ id
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }`;
58
+ }
59
+ }
@@ -0,0 +1,52 @@
1
+ import Fetcher from "src/decidim/decidim_awesome/awesome_map/api/fetcher";
2
+
3
+ export default class ProposalsFetcher extends Fetcher {
4
+ constructor(controller) {
5
+ super(controller);
6
+ this.query = `query ($id: ID!, $after: String!) {
7
+ component(id: $id) {
8
+ id
9
+ __typename
10
+ ... on Proposals {
11
+ proposals(first: 50, after: $after){
12
+ pageInfo {
13
+ hasNextPage
14
+ endCursor
15
+ }
16
+ edges {
17
+ node {
18
+ id
19
+ state
20
+ title {
21
+ translations {
22
+ text
23
+ locale
24
+ }
25
+ }
26
+ body {
27
+ translations {
28
+ text
29
+ locale
30
+ }
31
+ }
32
+ address
33
+ coordinates {
34
+ latitude
35
+ longitude
36
+ }
37
+ amendments {
38
+ emendation {
39
+ id
40
+ }
41
+ }
42
+ category {
43
+ id
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }`;
51
+ }
52
+ }
@@ -0,0 +1,129 @@
1
+ import * as L from "leaflet";
2
+ import "src/decidim/map/icon.js" // comes with Decidim
3
+ import "src/decidim/vendor/leaflet-tilelayer-here"
4
+ import "leaflet.markercluster"; // Comes with Decidim
5
+ import "leaflet.featuregroup.subgroup" // included in this package.json
6
+ import "src/vendor/jquery.truncate"
7
+ import "jsrender"
8
+
9
+ import ControlsUI from "src/decidim/decidim_awesome/awesome_map/controls_ui";
10
+ import ProposalsController from "src/decidim/decidim_awesome/awesome_map/controllers/proposals_controller";
11
+ import MeetingsController from "src/decidim/decidim_awesome/awesome_map/controllers/meetings_controller";
12
+
13
+ export default class AwesomeMap {
14
+ constructor(map, config) {
15
+ this.map = map;
16
+ this.categories = window.AwesomeMap && window.AwesomeMap.categories || []
17
+ this.config = $.extend({
18
+ length: 255,
19
+ center: null,
20
+ zoom: 8,
21
+ menu: {
22
+ amendments: false,
23
+ meetings: false,
24
+ categories: true,
25
+ hashtags: false,
26
+ mergeComponents: false
27
+ },
28
+ show: {
29
+ withdrawn: false,
30
+ accepted: false,
31
+ evaluating: false,
32
+ notAnswered: false,
33
+ rejected: false
34
+ },
35
+ hideControls: false,
36
+ collapsedMenu: false,
37
+ components: []
38
+ }, config);
39
+ this.layers = {};
40
+ this.cluster = new L.MarkerClusterGroup();
41
+ this.map.addLayer(this.cluster);
42
+ this.controls = new ControlsUI(this);
43
+ this.onFinished = () => {};
44
+ this.controllers = {};
45
+ this.loading = [];
46
+ this._firstController = {};
47
+ }
48
+
49
+ // Queries the API and load all the markers
50
+ loadControllers() {
51
+ this.autoResize();
52
+ this.controls.attach();
53
+
54
+ this.config.components.forEach((component) => {
55
+ const controller = this._getController(component);
56
+ if (controller) {
57
+ controller.loadNodes();
58
+ this.loading.push(component.type);
59
+ controller.onFinished = () => {
60
+ this.loading.pop();
61
+ this.autoResize();
62
+
63
+ if (this.loading.length == 0) {
64
+ this.controls.$loading.hide();
65
+ // call trigger as all loads are finished
66
+ this.onFinished();
67
+ }
68
+ };
69
+ }
70
+ });
71
+ }
72
+
73
+ autoResize() {
74
+ // Setup center/zoom options if specified, otherwise fitbounds
75
+ const bounds = this.cluster.getBounds()
76
+ if (this.config.center && this.config.zoom) {
77
+ this.map.setView(this.config.center, this.config.zoom);
78
+ } else if (bounds.isValid()) {
79
+ // this.map.fitBounds(bounds, { padding: [50, 50] }); // this doesn't work much of the time, probably some race condition
80
+ this.map.fitBounds([[bounds.getNorth(), bounds.getEast()], [bounds.getSouth(), bounds.getWest()]], { padding: [50, 50] });
81
+ }
82
+ }
83
+
84
+ getCategory(category) {
85
+ let defaultCat = {
86
+ color: getComputedStyle(document.documentElement).getPropertyValue("--primary"),
87
+ children: () => {},
88
+ parent: null,
89
+ name: null
90
+ };
91
+
92
+ if (category) {
93
+ let id = category.id
94
+ ? parseInt(category.id, 10)
95
+ : parseInt(category, 10);
96
+ let cat = this.categories.find((c) => c.id == id);
97
+ if (cat) {
98
+ cat.children = () => {
99
+ return this.categories.filter((c) => c.parent === cat.id);
100
+ }
101
+ return cat;
102
+ }
103
+ }
104
+ return defaultCat;
105
+ }
106
+
107
+ _getController(component) {
108
+ let controller;
109
+
110
+ if (component.type == "proposals") {
111
+ controller = new ProposalsController(this, component);
112
+ }
113
+ if (component.type == "meetings" && this.config.menu.meetings) {
114
+ controller = new MeetingsController(this, component);
115
+ }
116
+
117
+ if (controller) {
118
+ // Agrupate layers for controlling components
119
+ if (this._firstController[component.type] && this.config.menu.mergeComponents) {
120
+ controller.controls = this._firstController[component.type].controls;
121
+ } else {
122
+ controller.addControls();
123
+ }
124
+ this._firstController[component.type] = this._firstController[component.type] || controller;
125
+ this.controllers[component.type] = controller;
126
+ return this.controllers[component.type]
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,130 @@
1
+ import * as L from "leaflet";
2
+
3
+ export default class Controller {
4
+ constructor(awesomeMap, component) {
5
+ this.awesomeMap = awesomeMap;
6
+ this.component = component;
7
+ this.templateId = "marker-meeting-popup";
8
+ this.controls = {
9
+ label: this.getLabel(),
10
+ group: new L.FeatureGroup.SubGroup(this.awesomeMap.cluster)
11
+ };
12
+ this.onFinished = () => {};
13
+ this.allNodes = [];
14
+ }
15
+
16
+ getLabel() {
17
+ let text = this.awesomeMap.config.menu.mergeComponents || !this.component.name
18
+ ? window.DecidimAwesome.texts[this.component.type]
19
+ : this.component.name;
20
+ return `<span class="awesome_map-component" id="awesome_map-component_${this.component.id}" title="0" data-layer="${this.component.type}">${text}</span>`
21
+ }
22
+
23
+ setFetcher(Fetcher) {
24
+ this.fetcher = new Fetcher(this);
25
+ this.fetcher.onFinished = () => {
26
+ // console.log(`all ${this.component.type} loaded`, this)
27
+ this._onFinished();
28
+ };
29
+ this.fetcher.onCollection = (collection) => {
30
+ if (collection && collection.edges) {
31
+ // Add markers to the main cluster group
32
+ try {
33
+ this.awesomeMap.cluster.addLayers(collection.edges.map((item) => item.node.marker));
34
+ } catch (e) {
35
+ console.error("Failed marker collection assignation", collection);
36
+ }
37
+ // subgroups don't have th addLayers utility
38
+ collection.edges.forEach((item) => {
39
+ this.addMarkerCategory(item.node.marker, item.node.category);
40
+ this.addMarkerHashtags(item.node.marker, item.node.hashtags);
41
+ });
42
+ }
43
+ };
44
+ }
45
+
46
+ addControls() {
47
+ this.awesomeMap.controls.main.addOverlay(this.controls.group, this.controls.label);
48
+ this.awesomeMap.map.addLayer(this.controls.group);
49
+ }
50
+
51
+ loadNodes() {
52
+ // to override
53
+ }
54
+
55
+ addMarker(marker, node) {
56
+
57
+ /*
58
+ theorically, this should be enough to create popups on markers but it looks that
59
+ there is some bug in leaflet that sometimes prevents this to work
60
+ */
61
+ /*
62
+ let dom = document.createElement("div");
63
+ // console.log("addMarker", marker, "dom", dom)
64
+ dom.innerHTML = $.templates(`#${this.templateId}`).render(node);
65
+ marker.bindPopup(dom, {
66
+ maxwidth: 640,
67
+ minWidth: 500,
68
+ keepInView: true,
69
+ className: "map-info"
70
+ }); //*/
71
+
72
+ marker.on("click", () => {
73
+ let dom = document.createElement("div");
74
+ dom.innerHTML = $.templates(`#${this.templateId}`).render(node);
75
+
76
+ let pop = L.popup({
77
+ maxwidth: 640,
78
+ minWidth: 500,
79
+ keepInView: true,
80
+ className: "map-info"
81
+
82
+ }).setLatLng(marker.getLatLng()).setContent(dom);
83
+ this.awesomeMap.map.addLayer(pop);
84
+ });
85
+ node.marker = marker;
86
+ node.component = this.component;
87
+ this.allNodes.push(node);
88
+ }
89
+
90
+ addMarkerCategory(marker, category) {
91
+ // Add to category layer
92
+ const cat = this.awesomeMap.getCategory(category);
93
+ if (this.awesomeMap.layers[cat.id]) {
94
+ try {
95
+ this.awesomeMap.layers[cat.id].group.addLayer(marker);
96
+ this.awesomeMap.controls.showCategory(cat);
97
+ } catch (e) {
98
+ console.error("Failed category marker assignation", marker, e.message);
99
+ }
100
+ }
101
+ }
102
+
103
+ addMarkerHashtags(marker, hashtags) {
104
+ // Add hashtag layer
105
+ if (this.awesomeMap.config.menu.hashtags) {
106
+ try {
107
+ this.awesomeMap.controls.addHashtagsControls(hashtags, marker);
108
+ } catch (e) {
109
+ console.error("Failed hashtags marker assignation", marker, e.message);
110
+ }
111
+ }
112
+ }
113
+
114
+ // Override if needed (call this.onFinished() at the end!)
115
+ _onFinished() {
116
+ this.awesomeMap.controls.updateStats(`component_${this.component.id}`, this.allNodes.length);
117
+ this.onFinished();
118
+ }
119
+
120
+ createIcon(Builder, color) {
121
+ return new Builder({
122
+ color: "#000000",
123
+ fillColor: color,
124
+ circleFillColor: color,
125
+ weight: 1,
126
+ stroke: color,
127
+ fillOpacity: 0.9
128
+ });
129
+ }
130
+ }
@@ -0,0 +1,31 @@
1
+ import * as L from "leaflet";
2
+ import Controller from "src/decidim/decidim_awesome/awesome_map/controllers/controller";
3
+ import MeetingsFetcher from "src/decidim/decidim_awesome/awesome_map/api/meetings_fetcher";
4
+
5
+ const MeetingIcon = L.DivIcon.SVGIcon.DecidimIcon.extend({
6
+ _createPathDescription: function() {
7
+ return "M 15.991543,4 C 7.3956015,4 2.9250351,10.5 3.000951,16.999999 3.1063486,26.460968 12.747693,30.000004 15.991543,43 19.242091,30.000004 29,26.255134 29,16.999999 29,10.5 23.951131,4 15.996007,4 m -0.153508,2.6000001 a 2.1720294,2.1076698 0 0 1 2.330514,2.1124998 2.177008,2.1125006 0 0 1 -4.354016,0 2.1720294,2.1076698 0 0 1 2.023502,-2.1124998 m -2.651707,4.8056679 h 5.610202 l 3.935584,7.569899 -1.926038,0.934266 -2.009546,-3.859265 v 14.557403 h -2.484243 v -9.126003 h -0.642162 v 9.126003 H 13.190347 V 16.050568 l -2.009545,3.859265 -1.926036,-0.934266 3.935581,-7.569899";
8
+ }
9
+ });
10
+
11
+ export default class MeetingsController extends Controller {
12
+ constructor(awesomeMap, component) {
13
+ super(awesomeMap, component)
14
+ this.templateId = "marker-meeting-popup";
15
+ this.setFetcher(MeetingsFetcher);
16
+ }
17
+
18
+ loadNodes() {
19
+ // for each meeting, create a marker with an associated popup
20
+ this.fetcher.onNode = (meeting) => {
21
+ let marker = new L.Marker([meeting.coordinates.latitude, meeting.coordinates.longitude], {
22
+ icon: this.createIcon(MeetingIcon, this.awesomeMap.getCategory(meeting.category).color),
23
+ title: meeting.title.translation
24
+ });
25
+ // console.log("new meeting", meeting, marker)
26
+ this.addMarker(marker, meeting);
27
+ };
28
+
29
+ this.fetcher.fetch();
30
+ }
31
+ }
@@ -0,0 +1,88 @@
1
+ import * as L from "leaflet";
2
+ import Controller from "src/decidim/decidim_awesome/awesome_map/controllers/controller";
3
+ import ProposalsFetcher from "src/decidim/decidim_awesome/awesome_map/api/proposals_fetcher";
4
+
5
+ const ProposalIcon = L.DivIcon.SVGIcon.DecidimIcon.extend({
6
+ options: {
7
+ fillColor: "#ef604d",
8
+ fillOpacity: 0.8,
9
+ strokeWidth: 1,
10
+ strokeOpcacity: 1
11
+ }
12
+ });
13
+ export default class ProposalsController extends Controller {
14
+ constructor(awesomeMap, component) {
15
+ super(awesomeMap, component)
16
+ this.templateId = "marker-proposal-popup";
17
+ this.amendments = {};
18
+ this.setFetcher(ProposalsFetcher);
19
+ }
20
+
21
+ addControls() {
22
+ super.addControls();
23
+
24
+ // add control layer for amendments if any
25
+ if (this.awesomeMap.config.menu.amendments && this.component.amendments && !this.awesomeMap.layers.amendments) {
26
+ this.awesomeMap.layers.amendments = {
27
+ label: `<span class="awesome_map-component" id="awesome_map-amendments_${this.component.id}" title="0" data-layer="amendments">${window.DecidimAwesome.texts.amendments}</span>`,
28
+ group: new L.FeatureGroup.SubGroup(this.awesomeMap.cluster)
29
+ }
30
+ this.awesomeMap.controls.main.addOverlay(this.awesomeMap.layers.amendments.group, this.awesomeMap.layers.amendments.label);
31
+ this.awesomeMap.layers.amendments.group.addTo(this.awesomeMap.map);
32
+ }
33
+ }
34
+
35
+ loadNodes() {
36
+ // for each proposal, create a marker with an associated popup
37
+ this.fetcher.onNode = (proposal) => {
38
+ let marker = new L.Marker([proposal.coordinates.latitude, proposal.coordinates.longitude], {
39
+ icon: this.createIcon(ProposalIcon, this.awesomeMap.getCategory(proposal.category).color),
40
+ title: proposal.title.translation
41
+ });
42
+
43
+ // Check if it has amendments, add it to a list
44
+ // also assign parent's proposal categories to it
45
+ if (proposal.amendments && proposal.amendments.length) {
46
+ proposal.amendments.forEach((amendment) => {
47
+ this.amendments[amendment.emendation.id] = proposal;
48
+ });
49
+ }
50
+
51
+ // console.log("new proposal", proposal, "marker", marker)
52
+ this.addMarker(marker, proposal);
53
+ };
54
+
55
+ this.fetcher.fetch();
56
+ }
57
+
58
+ _onFinished() {
59
+ const iterableAmendments = Object.entries(this.amendments);
60
+ this.awesomeMap.controls.updateStats(`component_${this.component.id}`, this.allNodes.length - iterableAmendments.length);
61
+ this.awesomeMap.controls.updateStats(`amendments_${this.component.id}`, iterableAmendments.length);
62
+
63
+ // Process all amendments
64
+ iterableAmendments.forEach((amendment) => {
65
+ const marker = this.allNodes.find((node) => node.id == amendment[0]);
66
+ const parent = amendment[1];
67
+ // console.log("marker", marker, "parent proposal", parent)
68
+ // add marker to amendments layers and remove it from proposals
69
+ if (marker) {
70
+ try {
71
+ marker.marker.removeFrom(this.controls.group)
72
+ } catch (e) {
73
+ console.error("error removeFrom marker", marker, "layer", this.controls.group, e);
74
+ }
75
+ if (this.awesomeMap.config.menu.amendments) {
76
+ marker.marker.addTo(this.awesomeMap.layers.amendments.group);
77
+ // mimic parent category (amendments doesn't have categories)
78
+ if (parent.category) {
79
+ marker.marker.setIcon(this.createIcon(ProposalIcon, this.awesomeMap.getCategory(parent.category).color));
80
+ this.addMarkerCategory(marker.marker, parent.category)
81
+ }
82
+ }
83
+ }
84
+ });
85
+
86
+ this.onFinished();
87
+ }
88
+ }