decidim-navigation_maps 1.1.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -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 -3
  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. data/package.json +197 -0
  51. metadata +39 -48
  52. data/app/assets/config/admin/decidim_navigation_maps_manifest.css +0 -3
  53. data/app/assets/config/admin/decidim_navigation_maps_manifest.js +0 -3
  54. data/app/assets/config/decidim_navigation_maps_manifest.css +0 -3
  55. data/app/assets/config/decidim_navigation_maps_manifest.js +0 -1
  56. data/app/assets/images/decidim/navigation_maps/icon.svg +0 -1
  57. data/app/assets/javascripts/decidim/navigation_maps/admin/map_editor.js +0 -88
  58. data/app/assets/javascripts/decidim/navigation_maps/admin/navigation_maps.js +0 -143
  59. data/app/assets/javascripts/decidim/navigation_maps/map_view.js +0 -123
  60. data/app/assets/javascripts/decidim/navigation_maps/navigation_maps.js +0 -44
  61. data/vendor/assets/images/draw/layers-2x.png +0 -0
  62. data/vendor/assets/images/draw/layers.png +0 -0
  63. data/vendor/assets/images/draw/marker-icon-2x.png +0 -0
  64. data/vendor/assets/images/draw/marker-icon.png +0 -0
  65. data/vendor/assets/images/draw/marker-shadow.png +0 -0
  66. data/vendor/assets/images/draw/spritesheet-2x.png +0 -0
  67. data/vendor/assets/images/draw/spritesheet.png +0 -0
  68. data/vendor/assets/images/draw/spritesheet.svg +0 -156
  69. data/vendor/assets/images/images/layers-2x.png +0 -0
  70. data/vendor/assets/images/images/layers.png +0 -0
  71. data/vendor/assets/images/images/marker-icon-2x.png +0 -0
  72. data/vendor/assets/images/images/marker-icon.png +0 -0
  73. data/vendor/assets/images/images/marker-shadow.png +0 -0
  74. data/vendor/assets/javascripts/jquery.form.js +0 -1277
  75. data/vendor/assets/javascripts/jsrender.min.js +0 -4
  76. data/vendor/assets/javascripts/jsrender.min.js.map +0 -1
  77. data/vendor/assets/javascripts/leaflet-geoman.min.js +0 -1
  78. data/vendor/assets/javascripts/leaflet.js +0 -5
  79. data/vendor/assets/stylesheets/leaflet-geoman.css +0 -164
@@ -0,0 +1,154 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+ // import "jquery-form"; // we use a CDN instead due a bug in webpacker
4
+ import NavigationMapEditor from "src/decidim/navigation_maps/admin/map_editor.js";
5
+
6
+ $(() => {
7
+
8
+ let $maps = $(".navigation_maps.admin .map");
9
+ let $progress = $(".navigation_maps.admin .progress");
10
+ let $bar = $(".navigation_maps.admin .progress-meter");
11
+ let $loading = $(".navigation_maps.admin .loading");
12
+ let $callout = $(".navigation_maps.admin .callout");
13
+ let $modal = $("#mapEditModal");
14
+ let $form = $("form");
15
+ let $tabs = $("#navigation_maps-tabs");
16
+ let $accordion = $(".navigation_maps.admin .accordion");
17
+ let editors = {};
18
+ let new_areas = {};
19
+
20
+ $maps.each((_i, el) => {
21
+ let id = $(el).data("id");
22
+ let table = document.getElementById(`navigation_maps-table-${id}`);
23
+ editors[id] = new NavigationMapEditor(el, table);
24
+ editors[id].onCreateArea((area_id) => {
25
+ new_areas[area_id] = true;
26
+ });
27
+
28
+ editors[id].onClickArea((area_id, area) => {
29
+ $modal.find(".modal-content").html("");
30
+ $modal.addClass("loading").foundation("open");
31
+ $callout.hide();
32
+ $callout.removeClass("alert success");
33
+ // "new" form insted of editing
34
+ let rel = new_areas[area_id]
35
+ ? "new"
36
+ : area_id;
37
+ $modal.find(".modal-content").load(`/admin/navigation_maps/blueprints/${id}/areas/${rel}`, () => {
38
+ let $input1 = $modal.find('input[name="blueprint_area[area_id]"]');
39
+ let $input2 = $modal.find('input[name="blueprint_area[area_type]"]');
40
+ let $input3 = $modal.find('input[name="blueprint_area[area]"]');
41
+ let a = area.toGeoJSON();
42
+ $modal.removeClass("loading");
43
+ if ($input1.length) {
44
+ $input1.val(area_id);
45
+ }
46
+ if ($input2.length) {
47
+ $input2.val(a.type);
48
+ }
49
+ if ($input3.length) {
50
+ $input3.val(JSON.stringify(a));
51
+ }
52
+ $modal.find("ul[data-tabs=true]").each(() => {
53
+ new Foundation.Tabs($(el)); // eslint-disable-line
54
+ });
55
+ });
56
+ });
57
+ });
58
+
59
+ // Rails AJAX events
60
+ document.body.addEventListener("ajax:error", (responseText) => {
61
+ $callout.contents("p").html(`${responseText.detail[0].message}: <strong>${responseText.detail[0].error}</strong>`);
62
+ $callout.addClass("alert");
63
+ });
64
+
65
+ document.body.addEventListener("ajax:success", (responseText) => {
66
+ if (new_areas[responseText.detail[0].area]) {
67
+ delete new_areas[responseText.detail[0].area]
68
+ }
69
+ let blueprint_id = responseText.detail[0].blueprint_id;
70
+ let area_id = responseText.detail[0].area_id;
71
+ let area = responseText.detail[0].area;
72
+ editors[blueprint_id].setLayerProperties(editors[blueprint_id].map._layers[area_id], area);
73
+ editors[blueprint_id].blueprint[area_id] = area;
74
+ $callout.contents("p").html(responseText.detail[0].message);
75
+ $callout.addClass("success");
76
+ });
77
+
78
+ document.body.addEventListener("ajax:complete", () => {
79
+ $callout.show();
80
+ $modal.foundation("close");
81
+ })
82
+
83
+ $tabs.on("change.zf.tabs", (e, $tab, $content) => {
84
+ let id = $content.find(".map").data("id");
85
+ if (id) {
86
+ editors[id].reload();
87
+ }
88
+ });
89
+
90
+ $accordion.on("down.zf.accordion", () => {
91
+ let id = $accordion.find(".map").data("id");
92
+ if (id) {
93
+ editors[id].reload();
94
+ }
95
+ });
96
+
97
+ // If a new item si going to be created o the image is changed a reload is needed
98
+ let needsReload = () => {
99
+ let reload = false;
100
+ if ($form.find("#map-new input:checked").length) {
101
+ return true;
102
+ }
103
+ if ($form.find(".delete-tab input[type=checkbox]:checked").length) {
104
+ return true;
105
+ }
106
+
107
+ $form.find("input[type=file],input[tabs_id=blueprints___title]").each((_i, el) => {
108
+ if ($(el).val()) {
109
+ reload = true;
110
+ return false;
111
+ }
112
+ });
113
+ return reload;
114
+ };
115
+
116
+ $form.ajaxForm({
117
+ url: $form.find("[name=action]").val(),
118
+ beforeSerialize: () => {
119
+ Object.keys(editors).forEach((key) => {
120
+ let editor = editors[key];
121
+ $(`#blueprints_${editor.id}_blueprint`).val(JSON.stringify(editor.getBlueprint()));
122
+ });
123
+ },
124
+ beforeSend: () => {
125
+ let percentVal = "0%";
126
+ $bar.width(percentVal).html(percentVal);
127
+ $progress.show();
128
+ $callout.hide();
129
+ $callout.removeClass("alert success");
130
+ $loading.show();
131
+ },
132
+ uploadProgress: (event, position, total, percentComplete) => { // eslint-disable-line
133
+ let percentVal = `${percentComplete}%`;
134
+ $bar.width(percentVal).html(percentVal);
135
+ },
136
+ success: (responseText) => {
137
+ $callout.show();
138
+ $progress.hide();
139
+ $callout.contents("p").html(responseText);
140
+ $callout.addClass("success");
141
+ $loading.hide();
142
+ if (needsReload()) {
143
+ $loading.show();
144
+ location.reload();
145
+ }
146
+ },
147
+ error: (xhr) => {
148
+ $loading.hide();
149
+ $callout.show();
150
+ $callout.contents("p").html(xhr.responseText);
151
+ $callout.addClass("alert");
152
+ }
153
+ });
154
+ });
@@ -0,0 +1,125 @@
1
+ // Creates a map view
2
+ import "leaflet";
3
+ import "leaflet/dist/leaflet.css";
4
+ import "@geoman-io/leaflet-geoman-free";
5
+ import "@geoman-io/leaflet-geoman-free/dist/leaflet-geoman.css";
6
+
7
+ export default class NavigationMapView {
8
+ constructor(map_object, imageDecorator) {
9
+ this.features = {};
10
+ this.map_object = map_object;
11
+ this.id = map_object.dataset.id;
12
+ this.image_path = map_object.dataset.image;
13
+ this.blueprint = map_object.dataset.blueprint
14
+ ? JSON.parse(map_object.dataset.blueprint)
15
+ : {};
16
+ this.image = new Image();
17
+ this.image.onload = () => {
18
+ this.createMap();
19
+ if (typeof imageDecorator === "function") {
20
+ imageDecorator(this);
21
+ } else if (this.blueprint) {
22
+ this.createAreas();
23
+ }
24
+ };
25
+ this.image.src = this.image_path;
26
+ this.clickAreaCallback = () => {};
27
+ this.setLayerPropertiesCallback = () => {};
28
+ }
29
+
30
+ createMap() {
31
+ let bounds = [[0, 0], [this.image.height, this.image.width]];
32
+ this.map = L.map(this.map_object, {
33
+ minZoom: -1,
34
+ maxZoom: 2,
35
+ crs: L.CRS.Simple,
36
+ noWrap: true,
37
+ zoomSnap: 0,
38
+ // zoomDelta: 0.1,
39
+ maxBounds: [[0, 0], [this.image.height, this.image.width]],
40
+ center: [this.image.height / 2, this.image.width / 2],
41
+ zoom: -1,
42
+ scrollWheelZoom: false,
43
+ attributionControl: false
44
+ });
45
+
46
+ L.imageOverlay(this.image.src, bounds).addTo(this.map);
47
+ this.fitBounds();
48
+ };
49
+
50
+ fitBounds() {
51
+ let image_ratio = this.image.height / this.image.width;
52
+ let map_ratio = this.map_object.offsetHeight / this.map_object.offsetWidth;
53
+
54
+ if (image_ratio > map_ratio) {
55
+ this.map.fitBounds([[0, 0], [0, this.image.width]]);
56
+ }
57
+ else {
58
+ this.map.fitBounds([[0, 0], [this.image.height, 0]]);
59
+ }
60
+ this.map.setView([this.image.height / 2, this.image.width / 2]);
61
+ };
62
+
63
+ createAreas() {
64
+ this.forEachBlueprint((id, geoarea) => {
65
+ new L.GeoJSON(geoarea, {
66
+ onEachFeature: (feature, layer) => {
67
+ layer._leaflet_id = id;
68
+ this.setLayerProperties(layer, geoarea);
69
+ this.attachEditorEvents(layer);
70
+ }
71
+ }).addTo(this.map);
72
+ });
73
+ };
74
+
75
+ setLayerProperties (layer, area) {
76
+ let props = area.properties;
77
+ if (props) {
78
+ if (props.color) {
79
+ layer.setStyle({fillColor: props.color, color: props.color});
80
+ }
81
+ this.setLayerPropertiesCallback(layer, props);
82
+ }
83
+ };
84
+
85
+ attachEditorEvents (layer) {
86
+ layer.on("mouseover", (e) => {
87
+ e.target.getElement().classList.add("selected")
88
+ });
89
+
90
+ layer.on("mouseout", (e) => {
91
+ e.target.getElement().classList.remove("selected")
92
+ });
93
+
94
+ layer.on("click", (e) => {
95
+ this.clickAreaCallback(e.target, this);
96
+ });
97
+ };
98
+
99
+ // register callback to handle area clicks
100
+ onClickArea(callback) {
101
+ this.clickAreaCallback = callback;
102
+ };
103
+
104
+ onSetLayerProperties(callback) {
105
+ this.setLayerPropertiesCallback = callback;
106
+ };
107
+
108
+ forEachBlueprint (decorator) {
109
+ for (let id in this.blueprint) {
110
+ let geoarea = this.blueprint[id];
111
+ // avoid non-polygons for the moment
112
+ if (geoarea.geometry && geoarea.geometry.type === "Polygon") {
113
+ decorator(id, geoarea);
114
+ }
115
+ }
116
+ };
117
+
118
+ reload () {
119
+ if (this.map) {
120
+ this.map.invalidateSize(true);
121
+ this.fitBounds();
122
+ }
123
+ };
124
+ }
125
+
@@ -0,0 +1,43 @@
1
+ import NavigationMapView from "src/decidim/navigation_maps/map_view.js";
2
+ import "jsviews/jsrender";
3
+
4
+ $(function() {
5
+
6
+ let $maps = $(".navigation_maps .map");
7
+ let $tabs = $("#navigation_maps-tabs");
8
+ let maps = {};
9
+ let tmpl = $.templates("#navigation_maps-popup");
10
+
11
+ $maps.each(function() {
12
+ let id = $(this).data("id");
13
+ maps[id] = new NavigationMapView(this);
14
+ maps[id].onSetLayerProperties(function(layer, props) {
15
+ if (!props.popup) {
16
+ let node = document.createElement("div");
17
+ let html = tmpl.render(props);
18
+ $(node).html(html);
19
+
20
+ layer.bindPopup(node, {
21
+ maxHeight: 400,
22
+ // autoPan: false,
23
+ maxWidth: 640,
24
+ minWidth: 200,
25
+ keepInView: true,
26
+ className: `navigation_map-info map-info-${id}-${layer._leaflet_id}`
27
+ });
28
+ }
29
+ });
30
+ maps[id].onClickArea(function(area) {
31
+ let popup = area.feature.properties && area.feature.properties.link && area.feature.properties.popup;
32
+ if (popup) {
33
+ location = area.feature.properties.link;
34
+ }
35
+ });
36
+ });
37
+
38
+ $tabs.on("change.zf.tabs", function(e, $tab, $content) {
39
+ let id = $content.find(".map").data("id");
40
+ maps[id].reload();
41
+ });
42
+
43
+ });
@@ -2,10 +2,10 @@
2
2
  //= require leaflet-geoman
3
3
  //= require_self
4
4
 
5
- @import "decidim/variables";
6
- @import "decidim/utils/settings";
7
- @import "decidim/utils/mixins";
8
- @import "decidim/navigation_maps/variables";
5
+ @import "stylesheets/decidim/variables";
6
+ @import "stylesheets/decidim/utils/settings";
7
+ @import "stylesheets/decidim/utils/mixins";
8
+ @import "stylesheets/decidim/navigation_maps/variables";
9
9
 
10
10
  .navigation_maps.admin {
11
11
  .accordion-item {
@@ -1,8 +1,7 @@
1
1
  //= require leaflet
2
2
  //= require leaflet-geoman
3
3
  //= require_self
4
-
5
- @import "decidim/navigation_maps/variables";
4
+ @import "stylesheets/decidim/navigation_maps/variables";
6
5
 
7
6
  .home-section {
8
7
  .navigation_maps {
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module NavigationMaps
5
+ # This query finds the published blueprints for a content block
6
+ class ContentBlockBlueprints < Rectify::Query
7
+ def initialize(content_block)
8
+ @content_block = content_block
9
+ end
10
+
11
+ def query
12
+ Decidim::NavigationMaps::Blueprint.where(content_block: @content_block)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :content_block
18
+ end
19
+ end
20
+ end
@@ -4,18 +4,10 @@ module Decidim
4
4
  module NavigationMaps
5
5
  # This class deals with uploading images to a Blueprints.
6
6
  class BlueprintUploader < Decidim::ImageUploader
7
- process :validate_size, :validate_dimensions
8
-
9
- version :thumbnail do
10
- process resize_to_fit: [nil, 237]
11
- end
12
-
13
- def extension_white_list
14
- %w(jpg jpeg png svg)
15
- end
16
-
17
- def max_image_height_or_width
18
- 8000
7
+ set_variants do
8
+ {
9
+ thumbnail: { resize_to_fit: [nil, 237] }
10
+ }
19
11
  end
20
12
  end
21
13
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module NavigationMaps
5
+ module Cw
6
+ # This class deals with uploading images to a Blueprints.
7
+ class BlueprintUploader < Decidim::Cw::ImageUploader
8
+ process :validate_size, :validate_dimensions
9
+
10
+ version :thumbnail do
11
+ process resize_to_fit: [nil, 237]
12
+ end
13
+
14
+ def extension_white_list
15
+ %w(jpg jpeg png svg)
16
+ end
17
+
18
+ def max_image_height_or_width
19
+ 8000
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
data/config/assets.rb ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is located at `config/assets.rb` of your module.
4
+
5
+ # Define the base path of your module. Please note that `Rails.root` may not be
6
+ # used because we are not inside the Rails environment when this file is loaded.
7
+ base_path = File.expand_path("..", __dir__)
8
+
9
+ # Register an additional load path for webpack. All the assets within these
10
+ # directories will be available for inclusion within the Decidim assets. For
11
+ # example, if you have `app/packs/src/decidim/foo.js`, you can include that file
12
+ # in your JavaScript entrypoints (or other JavaScript files within Decidim)
13
+ # using `import "src/decidim/foo"` after you have registered the additional path
14
+ # as follows.
15
+ Decidim::Webpacker.register_path("#{base_path}/app/packs")
16
+
17
+ # Register the entrypoints for your module. These entrypoints can be included
18
+ # within your application using `javascript_pack_tag` and if you include any
19
+ # SCSS files within the entrypoints, they become available for inclusion using
20
+ # `stylesheet_pack_tag`.
21
+ Decidim::Webpacker.register_entrypoints(
22
+ decidim_navigation_maps: "#{base_path}/app/packs/entrypoints/decidim_navigation_maps.js",
23
+ decidim_admin_navigation_maps: "#{base_path}/app/packs/entrypoints/decidim_admin_navigation_maps.js"
24
+ )
25
+
26
+ # If you want to import some extra SCSS files in the Decidim main SCSS file
27
+ # without adding any extra stylesheet inclusion tags, you can use the following
28
+ # method to register the stylesheet import for the main application.
29
+ # Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/navigation_maps/navigation_maps")
30
+
31
+ # If you want to do the same but include the SCSS file for the admin panel's
32
+ # main SCSS file, you can use the following method.
33
+ # Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/navigation_maps/admin", group: :admin)
34
+
35
+ # If you want to override some SCSS variables/settings for Foundation from the
36
+ # module, you can add the following registered import.
37
+ # Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/foo/settings", type: :settings)
38
+
39
+ # If you want to do the same but override the SCSS variables of the admin
40
+ # panel's styles, you can use the following method.
41
+ # Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/foo/admin_settings", type: :settings, group: :admin)
@@ -29,6 +29,7 @@ ca:
29
29
  view: Participa
30
30
  navigation_map_settings_form:
31
31
  add: Afegeix
32
+ autohide_tabs: Amaga les pestanyes de navegació si només hi ha un mapa
32
33
  blueprint_image: Imatge del plànol
33
34
  description: Descripció
34
35
  editor: Editor del mapa
@@ -29,10 +29,11 @@ cs:
29
29
  view: Zapojte se
30
30
  navigation_map_settings_form:
31
31
  add: Přidat
32
+ autohide_tabs: Skrýt navigaci v záložkách, pokud je pouze jedna mapa
32
33
  blueprint_image: Obrázek plánu
33
34
  description: Popis
34
35
  editor: Editor mapy
35
- height: Height (px)
36
+ height: Výška (px)
36
37
  id: Id
37
38
  image_missing: Pro začátek přidejte obrázek plánu
38
39
  info: Obecné informace
@@ -30,6 +30,7 @@ en:
30
30
  view: Take part
31
31
  navigation_map_settings_form:
32
32
  add: Add
33
+ autohide_tabs: Hide tabs navigation if there's only one map
33
34
  blueprint_image: Blueprint image
34
35
  description: Description
35
36
  editor: Map Editor
@@ -29,6 +29,7 @@ es:
29
29
  view: Participar
30
30
  navigation_map_settings_form:
31
31
  add: Añadir
32
+ autohide_tabs: Ocultar las pestañas de navegación si sólo hay un mapa
32
33
  blueprint_image: Imagen del plano
33
34
  description: Descripción
34
35
  editor: Editor de Mapa
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddReferenceToContentBlockToBlueprintsTable < ActiveRecord::Migration[5.2]
4
+ def change
5
+ add_reference(
6
+ :decidim_navigation_maps_blueprints,
7
+ :decidim_content_block,
8
+ foreign_key: true,
9
+ index: { name: "decidim_navigation_maps_constraint_content_block" }
10
+ )
11
+ end
12
+ end
Binary file
data/db/seeds.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if !Rails.env.production? || ENV["SEED"]
3
+ print "Skipping seeds for decidim_navigation maps as required by SKIP_MODULE_SEEDS\n" if ENV["SKIP_MODULE_SEEDS"]
4
+
5
+ if !ENV["SKIP_MODULE_SEEDS"] && (!Rails.env.production? || ENV["SEED"])
6
+
4
7
  print "Creating seeds for decidim_navigation maps...\n" unless Rails.env.test?
5
8
 
6
9
  require "decidim/faker/localized"
@@ -8,29 +11,32 @@ if !Rails.env.production? || ENV["SEED"]
8
11
 
9
12
  organization = Decidim::Organization.first
10
13
 
11
- Decidim::ContentBlock.create(
14
+ # homepage blueprint
15
+ content_block = Decidim::ContentBlock.create(
12
16
  decidim_organization_id: organization.id,
13
17
  weight: 1,
14
18
  scope_name: :homepage,
15
19
  manifest_name: :navigation_map,
16
20
  published_at: Time.current,
17
- settings: { title: Decidim::Faker::Localized.sentence(5) }
21
+ settings: { title: Decidim::Faker::Localized.sentence(word_count: 5) }
18
22
  )
19
23
 
20
24
  blueprint1 = Decidim::NavigationMaps::Blueprint.create(
21
25
  organization: organization,
22
- image: File.new(File.join(seeds_root, "antarctica.png")),
23
- title: Decidim::Faker::Localized.sentence(2),
24
- description: Decidim::Faker::Localized.sentence(10)
26
+ content_block: content_block,
27
+ title: Decidim::Faker::Localized.sentence(word_count: 2),
28
+ description: Decidim::Faker::Localized.sentence(word_count: 10)
25
29
  )
26
30
 
27
- Decidim::NavigationMaps::Blueprint.create(
31
+ blueprint2 = Decidim::NavigationMaps::Blueprint.create(
28
32
  organization: organization,
29
- image: File.new(File.join(seeds_root, "penguins.jpg")),
30
- title: Decidim::Faker::Localized.sentence(2),
31
- description: Decidim::Faker::Localized.sentence(10)
33
+ title: Decidim::Faker::Localized.sentence(word_count: 2),
34
+ description: Decidim::Faker::Localized.sentence(word_count: 10)
32
35
  )
33
36
 
37
+ blueprint1.image.attach(io: File.open(File.join(seeds_root, "antarctica.png")), filename: "antarctica.png", content_type: "image/png")
38
+ blueprint2.image.attach(io: File.open(File.join(seeds_root, "penguins.jpg")), filename: "penguins.jpg", content_type: "image/jpeg")
39
+
34
40
  Decidim::NavigationMaps::BlueprintArea.create(
35
41
  blueprint: blueprint1,
36
42
  area_id: "10",
@@ -79,7 +85,7 @@ if !Rails.env.production? || ENV["SEED"]
79
85
  link_type: "link",
80
86
  color: "#ffbb00",
81
87
  title: { en: "Penguins" },
82
- description: { en: "Penguins are beatiful animals" }
88
+ description: { en: "Penguins are beautiful animals" }
83
89
  )
84
90
 
85
91
  Decidim::NavigationMaps::BlueprintArea.create(
@@ -100,4 +106,49 @@ if !Rails.env.production? || ENV["SEED"]
100
106
  link: "#map1",
101
107
  link_type: "direct"
102
108
  )
109
+
110
+ # participatory process groups blueprint
111
+ Decidim::ParticipatoryProcessGroup.find_each do |group|
112
+ content_block = Decidim::ContentBlock.create(
113
+ decidim_organization_id: organization.id,
114
+ weight: 1,
115
+ scope_name: :participatory_process_group_homepage,
116
+ scoped_resource_id: group.id,
117
+ manifest_name: :navigation_map,
118
+ published_at: Time.current,
119
+ settings: { title: Decidim::Faker::Localized.sentence(word_count: 5), autohide_tabs: true }
120
+ )
121
+
122
+ blueprint = Decidim::NavigationMaps::Blueprint.create(
123
+ organization: organization,
124
+ content_block: content_block,
125
+ title: Decidim::Faker::Localized.sentence(word_count: 2),
126
+ description: Decidim::Faker::Localized.sentence(word_count: 10)
127
+ )
128
+ blueprint1.image.attach(io: File.open(File.join(seeds_root, "pla-cerda.jpg")), filename: "pla-cerda.jpg", content_type: "image/jpeg")
129
+
130
+ Decidim::NavigationMaps::BlueprintArea.create(
131
+ blueprint: blueprint,
132
+ area_id: "10",
133
+ area_type: "Feature",
134
+ area: {
135
+ type: "Polygon",
136
+ coordinates: [[
137
+ [286.211699, 216.817532],
138
+ [342.618384, 252.332852],
139
+ [449.164345, 210.550122],
140
+ [447.075209, 191.747894],
141
+ [429.665738, 147.179649],
142
+ [323.816156, 126.288284],
143
+ [285.51532, 170.856529],
144
+ [286.211699, 216.817532]
145
+ ]]
146
+ },
147
+ link: "https://en.wikipedia.org/wiki/Centelles",
148
+ link_type: "link",
149
+ color: "#ff4700",
150
+ title: { en: "Pla Cerdà" },
151
+ description: { en: "Cerdà was from the town of Centelles" }
152
+ )
153
+ end
103
154
  end
@@ -22,10 +22,6 @@ module Decidim
22
22
  end
23
23
  end
24
24
 
25
- initializer "decidim_navigation_maps.admin_assets" do |app|
26
- app.config.assets.precompile += %w(admin/decidim_navigation_maps_manifest.js admin/decidim_navigation_maps_manifest.css)
27
- end
28
-
29
25
  def load_seed
30
26
  nil
31
27
  end