decidim-decidim_awesome 0.7.2 → 0.8.0

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