decidim-navigation_maps 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,123 +0,0 @@
1
- // Creates a map view
2
- //= require leaflet
3
- //= require leaflet-geoman.min
4
-
5
- function NavigationMapView(map_object, callback) {
6
- var self = this;
7
- self.features = {};
8
- self.map_object = map_object;
9
- self.id = map_object.dataset.id;
10
- self.image_path = map_object.dataset.image;
11
- self.blueprint = map_object.dataset.blueprint ? JSON.parse(map_object.dataset.blueprint) : {};
12
- self.image = new Image();
13
- self.image.onload = function() {
14
- self.createMap();
15
- if(typeof callback === "function") {
16
- callback(self);
17
- } else {
18
- if(self.blueprint) {
19
- self.createAreas();
20
- }
21
- }
22
- };
23
- self.image.src = self.image_path;
24
- this.clickAreaCallback = function () {};
25
- this.setLayerPropertiesCallback = function () {};
26
- }
27
-
28
- NavigationMapView.prototype.createMap = function() {
29
- var bounds = [[0,0], [this.image.height,this.image.width]];
30
-
31
- this.map = L.map(this.map_object, {
32
- minZoom: -1,
33
- maxZoom: 2,
34
- crs: L.CRS.Simple,
35
- noWrap: true,
36
- zoomSnap: 0,
37
- // zoomDelta: 0.1,
38
- maxBounds: [[0,0], [this.image.height,this.image.width]],
39
- center: [this.image.height/2, this.image.width/2],
40
- zoom: -1,
41
- scrollWheelZoom: false
42
- });
43
-
44
- L.imageOverlay(this.image.src, bounds).addTo(this.map);
45
- this.fitBounds();
46
- };
47
-
48
- NavigationMapView.prototype.fitBounds = function() {
49
- var image_ratio = this.image.height / this.image.width;
50
- var map_ratio = this.map_object.offsetHeight / this.map_object.offsetWidth;
51
-
52
- if(image_ratio > map_ratio) {
53
- this.map.fitBounds([[0,0], [0,this.image.width]]);
54
- }
55
- else {
56
- this.map.fitBounds([[0,0], [this.image.height,0]]);
57
- }
58
- this.map.setView([this.image.height/2, this.image.width/2]);
59
- };
60
-
61
- NavigationMapView.prototype.createAreas = function() {
62
- var self = this;
63
- self.forEachBlueprint(function(id, geoarea) {
64
- new L.GeoJSON(geoarea, {
65
- onEachFeature: function(feature, layer) {
66
- layer._leaflet_id = id;
67
- self.setLayerProperties(layer, geoarea);
68
- self.attachEditorEvents(layer);
69
- }
70
- }).addTo(self.map);
71
- });
72
- };
73
-
74
- NavigationMapView.prototype.setLayerProperties = function (layer, area) {
75
- var props = area.properties;
76
- if(props) {
77
- if(props.color) {
78
- layer.setStyle({fillColor: props.color, color: props.color});
79
- }
80
- this.setLayerPropertiesCallback(layer, props);
81
- }
82
- };
83
-
84
- NavigationMapView.prototype.attachEditorEvents = function (layer) {
85
- var self = this;
86
-
87
- layer.on('mouseover', function(e) {
88
- e.target.getElement().classList.add('selected')
89
- });
90
-
91
- layer.on('mouseout', function(e) {
92
- e.target.getElement().classList.remove('selected')
93
- });
94
-
95
- layer.on('click', function(e) {
96
- self.clickAreaCallback(e.target, self);
97
- });
98
- };
99
-
100
- // register callback to handle area clicks
101
- NavigationMapView.prototype.onClickArea = function(callback) {
102
- this.clickAreaCallback = callback;
103
- };
104
-
105
- NavigationMapView.prototype.onSetLayerProperties = function(callback) {
106
- this.setLayerPropertiesCallback = callback;
107
- };
108
-
109
- NavigationMapView.prototype.forEachBlueprint = function (callback) {
110
- for (var id in this.blueprint) {
111
- var geoarea = this.blueprint[id];
112
- // avoid non-polygons for the moment
113
- if(!geoarea.geometry || geoarea.geometry.type !== 'Polygon') continue;
114
- callback(id, geoarea);
115
- }
116
- };
117
-
118
- NavigationMapView.prototype.reload = function () {
119
- if(this.map) {
120
- this.map.invalidateSize(true);
121
- this.fitBounds();
122
- }
123
- };
@@ -1,44 +0,0 @@
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
- //= require decidim/navigation_maps/map_view
4
- //= require jsrender.min
5
- //= require_self
6
-
7
- $(function() {
8
-
9
- var $maps = $('.navigation_maps .map');
10
- var $tabs = $('#navigation_maps-tabs');
11
- var maps = {};
12
- var tmpl = $.templates("#navigation_maps-popup");
13
-
14
- $maps.each(function() {
15
- var id = $(this).data('id');
16
- maps[id] = new NavigationMapView(this);
17
- maps[id].onSetLayerProperties(function(layer, props) {
18
- if(!props.popup) {
19
- var node = document.createElement("div");
20
- var html = tmpl.render(props);
21
- $(node).html(html);
22
-
23
- layer.bindPopup(node, {
24
- maxHeight: 400,
25
- // autoPan: false,
26
- maxWidth: 640,
27
- minWidth: 200,
28
- keepInView: true,
29
- className: `navigation_map-info map-info-${id}-${layer._leaflet_id}`
30
- });
31
- }
32
- });
33
- maps[id].onClickArea(function(area) {
34
- var popup = area.feature.properties && area.feature.properties.link && area.feature.properties.popup;
35
- if(popup) location = area.feature.properties.link;
36
- });
37
- });
38
-
39
- $tabs.on('change.zf.tabs', function(e, $tab, $content) {
40
- var id = $content.find('.map').data('id');
41
- maps[id].reload();
42
- });
43
-
44
- });