decidim-navigation_maps 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -5
  3. data/Rakefile +18 -0
  4. data/app/cells/decidim/navigation_maps/content_blocks/groups_navigation_map_cell.rb +21 -0
  5. data/app/cells/decidim/navigation_maps/content_blocks/navigation_map/_tabs_content.erb +1 -1
  6. data/app/cells/decidim/navigation_maps/content_blocks/navigation_map/show.erb +6 -6
  7. data/app/cells/decidim/navigation_maps/content_blocks/navigation_map_cell.rb +31 -0
  8. data/app/cells/decidim/navigation_maps/content_blocks/navigation_map_settings_form/_form.erb +4 -4
  9. data/app/cells/decidim/navigation_maps/content_blocks/navigation_map_settings_form/_tabs_content.erb +0 -1
  10. data/app/cells/decidim/navigation_maps/content_blocks/navigation_map_settings_form/show.erb +7 -4
  11. data/app/cells/decidim/navigation_maps/content_blocks/navigation_map_settings_form_cell.rb +10 -1
  12. data/app/commands/decidim/navigation_maps/save_blueprints.rb +7 -1
  13. data/app/controllers/decidim/navigation_maps/admin/blueprints_controller.rb +3 -3
  14. data/app/forms/decidim/navigation_maps/area_form.rb +1 -1
  15. data/app/forms/decidim/navigation_maps/blueprint_form.rb +1 -0
  16. data/app/forms/decidim/navigation_maps/blueprint_forms.rb +1 -0
  17. data/app/jobs/decidim/navigation_maps/migrate_legacy_images_job.rb +32 -0
  18. data/app/models/decidim/navigation_maps/blueprint.rb +5 -3
  19. data/app/packs/entrypoints/decidim_admin_navigation_maps.js +4 -0
  20. data/app/packs/entrypoints/decidim_admin_navigation_maps.scss +1 -0
  21. data/app/packs/entrypoints/decidim_navigation_maps.js +7 -0
  22. data/app/packs/entrypoints/decidim_navigation_maps.scss +1 -0
  23. data/app/packs/src/decidim/navigation_maps/admin/map_editor.js +83 -0
  24. data/app/packs/src/decidim/navigation_maps/admin/navigation_maps.js +154 -0
  25. data/app/packs/src/decidim/navigation_maps/map_view.js +125 -0
  26. data/app/packs/src/decidim/navigation_maps/navigation_maps.js +43 -0
  27. data/app/{assets → packs}/stylesheets/decidim/navigation_maps/_variables.scss +0 -0
  28. data/app/{assets → packs}/stylesheets/decidim/navigation_maps/admin/navigation_maps.scss +4 -4
  29. data/app/{assets → packs}/stylesheets/decidim/navigation_maps/navigation_maps.scss +1 -2
  30. data/app/queries/decidim/navigation_maps/content_block_blueprints.rb +20 -0
  31. data/app/uploaders/decidim/navigation_maps/blueprint_uploader.rb +4 -12
  32. data/app/uploaders/decidim/navigation_maps/cw/blueprint_uploader.rb +24 -0
  33. data/config/assets.rb +41 -0
  34. data/config/locales/ca.yml +1 -0
  35. data/config/locales/cs.yml +2 -1
  36. data/config/locales/en.yml +1 -0
  37. data/config/locales/es.yml +1 -0
  38. data/db/migrate/20201105130724_add_reference_to_content_block_to_blueprints_table.rb +12 -0
  39. data/db/seeds/pla-cerda.jpg +0 -0
  40. data/db/seeds.rb +62 -11
  41. data/lib/decidim/navigation_maps/admin_engine.rb +0 -4
  42. data/lib/decidim/navigation_maps/engine.rb +16 -4
  43. data/lib/decidim/navigation_maps/navigation_map_cell_helpers.rb +4 -4
  44. data/lib/decidim/navigation_maps/test/factories.rb +1 -0
  45. data/lib/decidim/navigation_maps/version.rb +2 -2
  46. data/lib/decidim/navigation_maps.rb +0 -2
  47. data/lib/tasks/custom_seeds.rake +8 -0
  48. data/lib/tasks/decidim_navigation_maps_webpacker_tasks.rake +58 -0
  49. data/lib/tasks/navigation_maps_active_storage_migration_tasks.rake +37 -0
  50. metadata +38 -29
  51. data/app/assets/config/admin/decidim_navigation_maps_manifest.css +0 -3
  52. data/app/assets/config/admin/decidim_navigation_maps_manifest.js +0 -3
  53. data/app/assets/config/decidim_navigation_maps_manifest.css +0 -3
  54. data/app/assets/config/decidim_navigation_maps_manifest.js +0 -1
  55. data/app/assets/images/decidim/navigation_maps/icon.svg +0 -1
  56. data/app/assets/javascripts/decidim/navigation_maps/admin/map_editor.js +0 -88
  57. data/app/assets/javascripts/decidim/navigation_maps/admin/navigation_maps.js +0 -143
  58. data/app/assets/javascripts/decidim/navigation_maps/map_view.js +0 -123
  59. data/app/assets/javascripts/decidim/navigation_maps/navigation_maps.js +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3095b1ee4ac0d8128711b37b7a59bcc5eb0b42d4ffebfb0021bcc1b549c80dab
4
- data.tar.gz: 468c412868fb61196861df0aeceef155551d8f83e4d58dc556778ecbd2ebed2e
3
+ metadata.gz: 555b93edb92b69f19e3cc10841179b04fb57502a13d347fe69132d01833f88d6
4
+ data.tar.gz: 76da0880561f5e1e5b1201a048d90c8a862194134f3e485c1d2d045401f61551
5
5
  SHA512:
6
- metadata.gz: b440bff8af84241131b5e5c11c0b8567d1667a379d1156ca0d3b49c96992366ec304bc394aa8e7382efd38b05d22908471cdf98daf1a181c6b6de436d13abe9b
7
- data.tar.gz: af9064b540070fe4cb45b242a2445d8170f7bfda68457fc4ad5a3eae917d0254afc55c9241c30278bad64115783357c2cbdc645ec97289b5a95380373d42c71f
6
+ metadata.gz: d90681644ff2111df383e19b5e7e7568c97cc225aad75645dcd86369332e91d4ef0d0fcc0ea6413c7bcb83bab0239333fb926958d8a32e62df5e2b52bd7353d1
7
+ data.tar.gz: bbc246049572a74e697a0382bd084213cdff071149ea1c2ef1a93eae78da2d1ceeba110b394c16c9877b5c88ecd96fca0c674b1f72193b7b86b993a5707c6daf
data/README.md CHANGED
@@ -4,9 +4,9 @@
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/f69b2b0ab0ffcd26f002/maintainability)](https://codeclimate.com/github/Platoniq/decidim-module-navigation_maps/maintainability)
5
5
  [![Codecov](https://codecov.io/gh/Platoniq/decidim-module-navigation_maps/branch/master/graph/badge.svg?token=XhzWO0IiWt)](https://codecov.io/gh/Platoniq/decidim-module-navigation_maps)
6
6
 
7
- Allows to map processes to image parts using maps.
7
+ This module allows admins to upload any arbitrary image and draw sensible zones over it with direct links to other places (ie: a specific participatory process) or display a popup explaining something.
8
8
 
9
- > NOTE: This module is ready to use but in Beta status. Feel free to report any bug!
9
+ Maps can be displayed in the homepage or as part of a process group landing.
10
10
 
11
11
  ## Usage
12
12
 
@@ -24,23 +24,43 @@ homepage only).
24
24
  Add this line to your application's Gemfile:
25
25
 
26
26
  ```ruby
27
- gem "decidim-navigation_maps", "~> 1.1.0"
27
+ gem "decidim-navigation_maps"
28
28
  ```
29
29
 
30
- And then execute:
30
+ And then execute (remember to repeat this if you are upgrading from version 1.1):
31
31
 
32
32
  ```bash
33
33
  bundle
34
34
  bundle exec rails decidim_navigation_maps:install:migrations
35
+ bundle exec rails decidim_navigation_maps:webpacker:install
35
36
  bundle exec rails db:migrate
36
37
  ```
37
38
 
39
+ > NOTE: the `decidim_notify:webpacker:install` is only necessary for Decidim versions starting at 0.25.
40
+
41
+ If you are upgrading from a version prior to 1.3, make sure that you migrate your existing images to Active Storae:
42
+
43
+ ```
44
+ RAILS_ENV=production bin/rails navigation_maps:active_storage_migrations:migrate_from_carrierwave
45
+ ```
46
+
47
+ Or check your migration status with:
48
+ ```
49
+ RAILS_ENV=production bin/rails navigation_maps:active_storage_migrations:check_migration_from_carrierwave
50
+ ```
51
+
52
+ The correct version of Navigation Maps should resolved automatically by the Bundler.
53
+ However you can force some specific version using `gem "decidim-navigation_maps", "~> 1.3.0"` in the Gemfile.
54
+
55
+
38
56
  Depending on your Decidim version, choose the corresponding Plugin version to ensure compatibility:
39
57
 
40
58
  | Navigation Maps version | Compatible Decidim versions |
41
59
  |---|---|
42
- | 1.0.x | 0.18.x - 0.21.x |
60
+ | 1.3.x | 0.25.x, 0.26.x |
61
+ | 1.2.x | 0.24.x |
43
62
  | 1.1.x | 0.22.x, 0.23.x |
63
+ | 1.0.x | 0.18.x - 0.21.x |
44
64
 
45
65
  ## Contributing
46
66
 
@@ -134,6 +154,13 @@ SIMPLECOV=1 bundle exec rspec
134
154
  This will generate a folder named `coverage` in the project root which contains
135
155
  the code coverage report.
136
156
 
157
+ ### Localization
158
+
159
+ If you would like to see this module in your own language, you can help with its
160
+ translation at Crowdin:
161
+
162
+ https://crowdin.com/translate/decidim-module-navigation_maps
163
+
137
164
  ## License
138
165
 
139
166
  This engine is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
data/Rakefile CHANGED
@@ -9,16 +9,29 @@ def install_module(path)
9
9
  end
10
10
  end
11
11
 
12
+ def override_webpacker_config_files(path)
13
+ Dir.chdir(path) do
14
+ system("bundle exec rake decidim_navigation_maps:webpacker:install")
15
+ end
16
+ end
17
+
12
18
  def seed_db(path)
13
19
  Dir.chdir(path) do
14
20
  system("bundle exec rake db:seed")
15
21
  end
16
22
  end
17
23
 
24
+ def seed_module_db(path)
25
+ Dir.chdir(path) do
26
+ system("bundle exec rake decidim_navigation_maps:seed")
27
+ end
28
+ end
29
+
18
30
  desc "Generates a dummy app for testing"
19
31
  task test_app: "decidim:generate_external_test_app" do
20
32
  ENV["RAILS_ENV"] = "test"
21
33
  install_module("spec/decidim_dummy_app")
34
+ override_webpacker_config_files("spec/decidim_dummy_app")
22
35
  end
23
36
 
24
37
  desc "Generates a development app"
@@ -36,5 +49,10 @@ task :development_app do
36
49
  end
37
50
 
38
51
  install_module("development_app")
52
+ override_webpacker_config_files("development_app")
53
+ ENV["SKIP_MODULE_SEEDS"] = "1"
39
54
  seed_db("development_app")
55
+ # manually seed navigation maps to ensure participatory process groups are created
56
+ ENV.delete "SKIP_MODULE_SEEDS"
57
+ seed_module_db("development_app")
40
58
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module NavigationMaps
5
+ module ContentBlocks
6
+ class GroupsNavigationMapCell < NavigationMapCell
7
+ def section_classes
8
+ "section"
9
+ end
10
+
11
+ def wrapper_classes
12
+ nil
13
+ end
14
+
15
+ def row_classes
16
+ "row column"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,7 +2,7 @@
2
2
  <div class="tabs-content admin" data-tabs-content="navigation_maps-tabs">
3
3
  <% tabs.each_with_index do |item, index| %>
4
4
  <div class="tabs-panel<%= " is-active" if index.zero? %>" id="map<%= index %>">
5
- <%= content_tag(:div, "", id: "navigation_maps-map-#{item.id}", class: "map", style: "height: #{item.height}px", data: { id: item.id, image: item.image.url, blueprint: item.blueprint }) %>
5
+ <%= content_tag(:div, "", id: "navigation_maps-map-#{item.id}", class: "map", style: "height: #{item.height}px", data: { id: item.id, image: image_path(item.image), blueprint: item.blueprint }) %>
6
6
  </div>
7
7
  <% end %>
8
8
  </div>
@@ -1,16 +1,16 @@
1
- <%= stylesheet_link_tag "decidim/navigation_maps/navigation_maps" %>
1
+ <%= stylesheet_pack_tag "decidim_navigation_maps" %>
2
2
  <%= render partial: "styles", locals: { blueprints: valid_blueprints } %>
3
3
 
4
- <section class="extended home-section">
5
- <div class="wrapper-home">
6
- <div class="row column text-center">
4
+ <section<%= class_tag(section_classes) %>>
5
+ <div<%= class_tag(wrapper_classes) %>>
6
+ <div<%= class_tag(row_classes) %>>
7
7
 
8
8
  <% if translated_title.present? %>
9
9
  <h3 class="heading3"><%= decidim_sanitize translated_title %></h3>
10
10
  <% end %>
11
11
 
12
12
  <div class="navigation_maps">
13
- <%= render partial: "tabs", locals: { tabs: valid_blueprints } %>
13
+ <%= tabs %>
14
14
  <%= render partial: "tabs_content", locals: { tabs: valid_blueprints } %>
15
15
  </div>
16
16
  </div>
@@ -18,4 +18,4 @@
18
18
  </section>
19
19
 
20
20
  <%= render partial: "template" %>
21
- <%= javascript_include_tag "decidim/navigation_maps/navigation_maps" %>
21
+ <%= javascript_pack_tag "decidim_navigation_maps" %>
@@ -7,15 +7,46 @@ module Decidim
7
7
  include NavigationMaps::NavigationMapCellHelpers
8
8
  include Decidim::SanitizeHelper
9
9
 
10
+ alias content_block model
11
+
10
12
  view_paths << "#{Decidim::NavigationMaps::Engine.root}/app/cells/decidim/navigation_maps/content_blocks/navigation_map"
11
13
 
12
14
  def show
13
15
  render if valid_blueprints?
14
16
  end
15
17
 
18
+ def tabs
19
+ return if model.settings.autohide_tabs? && valid_blueprints.count < 2
20
+
21
+ render partial: "tabs", locals: { tabs: valid_blueprints }
22
+ end
23
+
16
24
  def translated_title
17
25
  translated_attribute(model.settings.title)
18
26
  end
27
+
28
+ def section_classes
29
+ "extended home-section"
30
+ end
31
+
32
+ def wrapper_classes
33
+ "wrapper-home"
34
+ end
35
+
36
+ def row_classes
37
+ "row column text-center"
38
+ end
39
+
40
+ def class_tag(class_string)
41
+ return if class_string.blank?
42
+
43
+ " class=\"#{class_string}\""
44
+ end
45
+
46
+ def image_path(image, options = {})
47
+ options.merge!({ only_path: true })
48
+ Rails.application.routes.url_helpers.rails_blob_url(image, options)
49
+ end
19
50
  end
20
51
  end
21
52
  end
@@ -1,5 +1,5 @@
1
1
  <ul class="accordion" data-accordion>
2
- <li class="accordion-item<%= " is-active" unless form.image? %>" data-accordion-item>
2
+ <li class="accordion-item<%= " is-active" unless image?(form) %>" data-accordion-item>
3
3
  <a href="#" class="accordion-title"><%= t("navigation_map_settings_form.info", scope: "decidim.navigation_maps.content_blocks") %></a>
4
4
 
5
5
  <div class="accordion-content" data-tab-content>
@@ -9,7 +9,7 @@
9
9
 
10
10
  <%= label_tag t("navigation_map_settings_form.blueprint_image", scope: "decidim.navigation_maps.content_blocks") %>
11
11
  <div class="thumbnail">
12
- <%= image_tag form.image.thumbnail.url if form.image? %>
12
+ <%= image_tag image_path(form.image, variant: :thumbnail) if image?(form) %>
13
13
  </div>
14
14
  <%= file_field_tag "blueprints[#{form.ident}][image]", { id: "blueprints_#{form.ident}_image", label: t("navigation_map_settings_form.title", scope: "decidim.navigation_maps.content_blocks") } %>
15
15
 
@@ -25,12 +25,12 @@
25
25
  </div>
26
26
  </li>
27
27
 
28
- <% if form.image? %>
28
+ <% if image?(form) %>
29
29
  <li class="accordion-item is-active" data-accordion-item>
30
30
  <a href="#" class="accordion-title"><%= t("navigation_map_settings_form.editor", scope: "decidim.navigation_maps.content_blocks") %></a>
31
31
  <div class="accordion-content navigation_maps-content" data-tab-content>
32
32
 
33
- <%= content_tag(:div, "", id: "navigation_maps-map-#{form.ident}", class: "map", data: { id: form.ident, image: form.image.url, blueprint: form.blueprint }) %>
33
+ <%= content_tag(:div, "", id: "navigation_maps-map-#{form.ident}", class: "map", data: { id: form.ident, image: image_path(form.image), blueprint: form.blueprint }) %>
34
34
 
35
35
  </div>
36
36
  </li>
@@ -1,4 +1,3 @@
1
-
2
1
  <div class="tabs-content" data-tabs-content="navigation_maps-tabs">
3
2
  <% tabs.each_with_index do |item, index| %>
4
3
  <div class="tabs-panel<%= " is-active" if index.zero? %>" id="map<%= index %>">
@@ -1,11 +1,13 @@
1
1
  <!-- Original settings -->
2
2
  <% form.fields_for :settings, form.object.settings do |settings_fields| %>
3
- <%= settings_fields.translated :text_field, :title %>
3
+ <%= settings_fields.translated :text_field, :title, label: t("content_blocks.navigation_map_settings_form.title", scope: "decidim.navigation_maps") %>
4
+ <%= settings_fields.check_box :autohide_tabs, label: t("content_blocks.navigation_map_settings_form.autohide_tabs", scope: "decidim.navigation_maps") %>
4
5
  <% end %>
5
6
 
6
7
  <!-- Override rails default patch (using post via ajax) -->
7
8
  <%= hidden_field_tag :_method, "post" %>
8
9
  <%= hidden_field_tag :action, blueprints_path %>
10
+ <%= hidden_field_tag :content_block_id, content_block.id %>
9
11
 
10
12
  <div class="navigation_maps admin">
11
13
  <div class="callout" style="display:none" data-closable>
@@ -31,6 +33,7 @@
31
33
  </div>
32
34
 
33
35
  <%= render partial: "modal" %>
34
- <%= javascript_include_tag "decidim/navigation_maps/admin/navigation_maps" %>
35
- <%= stylesheet_link_tag "decidim/navigation_maps/admin/navigation_maps" %>
36
- <% console %>
36
+ <%# we need to rely on a CDN due a bug in webpacker that renders twice jquery if importing a plugin %>
37
+ <%= javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js", integrity: "sha384-qlmct0AOBiA2VPZkMY3+2WqkHtIQ9lSdAsAn5RUJD/3vA5MKDgSGcdmIv4ycVxyn", crossorigin: "anonymous" %>
38
+ <%= javascript_pack_tag "decidim_admin_navigation_maps" %>
39
+ <%= stylesheet_pack_tag "decidim_admin_navigation_maps" %>
@@ -10,7 +10,7 @@ module Decidim
10
10
  view_paths << "#{Decidim::NavigationMaps::Engine.root}/app/cells/decidim/navigation_maps/content_blocks/navigation_map_settings_form"
11
11
 
12
12
  def blueprint_form(blueprint = nil)
13
- blueprint ||= Blueprint.new
13
+ blueprint ||= Blueprint.new(content_block: content_block)
14
14
  BlueprintForm.from_model(blueprint).with_context(organization: current_organization)
15
15
  end
16
16
 
@@ -26,6 +26,15 @@ module Decidim
26
26
  def label
27
27
  I18n.t("decidim.content_blocks.html.html_content")
28
28
  end
29
+
30
+ def image?(frm)
31
+ frm.image.attached?
32
+ end
33
+
34
+ def image_path(image, options = {})
35
+ options.merge!({ only_path: true })
36
+ Rails.application.routes.url_helpers.rails_blob_url(image, options)
37
+ end
29
38
  end
30
39
  end
31
40
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  module Decidim
4
4
  module NavigationMaps
5
- # This command creates or updates the blueprints for the organization.
5
+ # This command creates or updates the blueprints for the organization and
6
+ # content block.
6
7
  class SaveBlueprints < Rectify::Command
7
8
  # Creates a blueprint.
8
9
  #
@@ -42,6 +43,7 @@ module Decidim
42
43
  def initialize_blueprint(form)
43
44
  @blueprint = Blueprint.find_or_initialize_by(id: form.id) do |blueprint|
44
45
  blueprint.organization = @forms.current_organization
46
+ blueprint.content_block = content_block
45
47
  end
46
48
  end
47
49
 
@@ -61,6 +63,10 @@ module Decidim
61
63
  @blueprint.areas.where.not(area_id: except).destroy_all
62
64
  end
63
65
 
66
+ def content_block
67
+ Decidim::ContentBlock.where(organization: @forms.current_organization, manifest_name: :navigation_map).find_by(id: @forms.content_block_id)
68
+ end
69
+
64
70
  def create_areas(blueprint)
65
71
  blueprint.each do |key, area|
66
72
  a = BlueprintArea.find_or_initialize_by(area_id: key, blueprint: @blueprint)
@@ -13,7 +13,7 @@ module Decidim
13
13
  end
14
14
 
15
15
  def show
16
- render json: organization_blueprints.find(params[:id])
16
+ render json: organization_blueprints.find(params[:id]).to_json(except: :image)
17
17
  end
18
18
 
19
19
  def create
@@ -39,11 +39,11 @@ module Decidim
39
39
  return unless params[:content_block][:settings]
40
40
 
41
41
  @form = form(Decidim::Admin::ContentBlockForm).from_params(params)
42
- Decidim::Admin::UpdateContentBlock.call(@form, content_block, :homepage)
42
+ Decidim::Admin::UpdateContentBlock.call(@form, content_block, content_block.scope_name&.to_sym)
43
43
  end
44
44
 
45
45
  def content_block
46
- @content_block ||= Decidim::ContentBlock.for_scope(:homepage, organization: current_organization).find_by(manifest_name: :navigation_map)
46
+ @content_block ||= Decidim::ContentBlock.where(organization: current_organization, manifest_name: :navigation_map).find(params[:content_block_id])
47
47
  end
48
48
 
49
49
  # Convert blueprint data to an object
@@ -28,7 +28,7 @@ module Decidim
28
28
  def color
29
29
  return "#2262cc" if super.blank?
30
30
 
31
- return "#" + super unless super.match?(/^#/)
31
+ return "##{super}" unless super.match?(/^#/)
32
32
 
33
33
  super
34
34
  end
@@ -11,6 +11,7 @@ module Decidim
11
11
 
12
12
  attribute :blueprint, Object
13
13
  attribute :id, Integer
14
+ attribute :decidim_content_block_id, Integer
14
15
  attribute :remove, Boolean
15
16
  attribute :image
16
17
  translatable_attribute :title, String
@@ -4,6 +4,7 @@ module Decidim
4
4
  module NavigationMaps
5
5
  class BlueprintForms < Decidim::Form
6
6
  attribute :blueprints, Array[BlueprintForm]
7
+ attribute :content_block_id, Integer
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module NavigationMaps
5
+ class MigrateLegacyImagesJob < ApplicationJob
6
+ queue_as :default
7
+
8
+ def perform(organization_id, mappings = [], logger = Rails.logger)
9
+ @organization_id = organization_id
10
+ @routes_mappings = mappings
11
+ @logger = logger
12
+
13
+ migrate_all!
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :routes_mappings, :logger
19
+
20
+ def migrate_all!
21
+ Decidim::CarrierWaveMigratorService.migrate_attachment!(
22
+ klass: Decidim::NavigationMaps::BluePrint,
23
+ cw_attribute: "image",
24
+ cw_uploader: Decidim::NavigationMaps::Cw::ImageUploader,
25
+ as_attribute: "image",
26
+ logger: @logger,
27
+ routes_mappings: routes_mappings
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
@@ -4,22 +4,24 @@ module Decidim
4
4
  module NavigationMaps
5
5
  # Abstract class from which all models in this engine inherit.
6
6
  class Blueprint < ApplicationRecord
7
+ include Decidim::HasUploadValidations
8
+
7
9
  self.table_name = "decidim_navigation_maps_blueprints"
8
10
 
9
11
  attribute :height, :integer, default: 475
10
12
 
11
13
  belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization"
14
+ belongs_to :content_block, foreign_key: :decidim_content_block_id, class_name: "Decidim::ContentBlock"
12
15
  has_many :areas,
13
16
  foreign_key: "decidim_navigation_maps_blueprint_id",
14
17
  class_name: "Decidim::NavigationMaps::BlueprintArea",
15
18
  dependent: :destroy
16
19
 
17
20
  validates :organization, presence: true
18
- validates :image,
19
- file_content_type: { allow: ["image/jpeg", "image/png", "image/svg+xml"] }
20
21
  validates :height, numericality: { greater_than: 0 }
21
22
 
22
- mount_uploader :image, Decidim::NavigationMaps::BlueprintUploader
23
+ has_one_attached :image
24
+ validates_upload :image, uploader: Decidim::NavigationMaps::BlueprintUploader
23
25
 
24
26
  def blueprint
25
27
  areas.map { |area| [area.area_id.to_s, area.to_geoson] }.to_h
@@ -0,0 +1,4 @@
1
+ import "src/decidim/navigation_maps/admin/navigation_maps.js"
2
+
3
+ // CSS
4
+ import "entrypoints/decidim_admin_navigation_maps.scss";
@@ -0,0 +1 @@
1
+ @import "stylesheets/decidim/navigation_maps/admin/navigation_maps";
@@ -0,0 +1,7 @@
1
+ import "src/decidim/navigation_maps/navigation_maps.js"
2
+
3
+ // Images
4
+ require.context("../images", true)
5
+
6
+ // CSS
7
+ import "entrypoints/decidim_navigation_maps.scss";
@@ -0,0 +1 @@
1
+ @import "stylesheets/decidim/navigation_maps/navigation_maps";
@@ -0,0 +1,83 @@
1
+ // Creates a map
2
+ import NavigationMapView from "src/decidim/navigation_maps/map_view.js";
3
+
4
+ export default class NavigationMapEditor extends NavigationMapView {
5
+ constructor(map_object, table_object) {
6
+ // Call constructor of superclass to initialize superclass-derived members.
7
+ super(map_object, () => {
8
+ this.createControls();
9
+ if (this.blueprint) {
10
+ this.createAreas();
11
+ }
12
+ });
13
+ this.table_object = table_object;
14
+ this.createAreaCallback = function () {};
15
+ this.editAreaCallback = function () {};
16
+ this.removeAreaCallback = function () {};
17
+ }
18
+
19
+ createControls() {
20
+ this.map.pm.addControls({
21
+ position: "topleft",
22
+ drawCircle: false,
23
+ drawMarker: false,
24
+ drawCircleMarker: false,
25
+ drawPolyline: false,
26
+ cutPolygon: false
27
+ });
28
+
29
+ this.map.on("pm:create", (e) => {
30
+ let geojson = e.layer.toGeoJSON();
31
+ this.blueprint[e.layer._leaflet_id] = geojson;
32
+ this.attachEditorEvents(e.layer);
33
+ this.createAreaCallback(e.layer._leaflet_id, e.layer, this);
34
+ });
35
+
36
+ this.map.on("pm:remove", (e) => {
37
+ delete this.blueprint[e.layer._leaflet_id];
38
+ this.removeAreaCallback(e.layer._leaflet_id, e.layer, this);
39
+ });
40
+ };
41
+
42
+ editing() {
43
+ let pm = this.map.pm;
44
+ return pm.globalRemovalEnabled() || pm.globalDragModeEnabled() || pm.globalEditEnabled();
45
+ };
46
+
47
+ // register callback to handle area edits,removals and creations
48
+ onCreateArea(callback) {
49
+ this.createAreaCallback = callback;
50
+ };
51
+ onEditArea(callback) {
52
+ this.editAreaCallback = callback;
53
+ };
54
+ onRemoveArea(callback) {
55
+ this.removeCreateCallback = callback;
56
+ };
57
+
58
+ attachEditorEvents (layer) {
59
+ layer.on("mouseover", (e) => {
60
+ e.target.getElement().classList.add("selected")
61
+ });
62
+
63
+ layer.on("mouseout", (e) => {
64
+ e.target.getElement().classList.remove("selected")
65
+ });
66
+
67
+ layer.on("pm:edit", (e) => {
68
+ this.blueprint[e.target._leaflet_id] = e.target.toGeoJSON();
69
+ this.editAreaCallback(e.target._leaflet_id, e.target, this);
70
+ });
71
+
72
+ layer.on("click", (e) => {
73
+ if (!this.editing()) {
74
+ this.clickAreaCallback(e.target._leaflet_id, e.target, this);
75
+ }
76
+ });
77
+ };
78
+
79
+ getBlueprint () {
80
+ return this.blueprint;
81
+ };
82
+
83
+ }