decidim-decidim_awesome 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +307 -0
- data/Rakefile +51 -0
- data/app/assets/config/decidim_admin_decidim_awesome_manifest.css +3 -0
- data/app/assets/config/decidim_admin_decidim_awesome_manifest.js +1 -0
- data/app/assets/config/decidim_decidim_awesome_manifest.css +5 -0
- data/app/assets/config/decidim_decidim_awesome_manifest.js +2 -0
- data/app/assets/images/decidim/decidim_awesome/loading.gif +0 -0
- data/app/assets/images/decidim/decidim_awesome/platoniq-logo.png +0 -0
- data/app/assets/javascripts/decidim/decidim_awesome/admin.js +2 -0
- data/app/assets/javascripts/decidim/decidim_awesome/admin/constraints.js.es6 +54 -0
- data/app/assets/javascripts/decidim/decidim_awesome/application.js +4 -0
- data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/api_fetcher.js.es6 +38 -0
- data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/categories.js.es6 +25 -0
- data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/map.js.es6 +215 -0
- data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/meetings.js.es6 +129 -0
- data/app/assets/javascripts/decidim/decidim_awesome/awesome_map/proposals.js.es6 +78 -0
- data/app/assets/javascripts/decidim/decidim_awesome/editors/markdown_view.js.es6 +12 -0
- data/app/assets/javascripts/decidim/decidim_awesome/editors/quill_editor.js.es6 +162 -0
- data/app/assets/javascripts/decidim/decidim_awesome/forms/autosave.js.es6 +90 -0
- data/app/assets/javascripts/decidim/decidim_awesome/proposals/images.js.es6 +25 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/admin.scss +45 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/admin/constraints.scss +37 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/application.scss +8 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/awesome_iframe/iframe.scss +10 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/awesome_map/leaflet.scss.erb +9 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/awesome_map/map.scss +66 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/editors/markdown_editor.scss +17 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/editors/markdown_view.scss +27 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/editors/quill_editor.scss +7 -0
- data/app/assets/stylesheets/decidim/decidim_awesome/forms/autosave.scss +17 -0
- data/app/awesome_overrides/presenters/decidim/proposals/proposal_presenter_override.rb +31 -0
- data/app/commands/decidim/decidim_awesome/admin/create_constraint.rb +47 -0
- data/app/commands/decidim/decidim_awesome/admin/destroy_constraint.rb +31 -0
- data/app/commands/decidim/decidim_awesome/admin/update_config.rb +44 -0
- data/app/commands/decidim/decidim_awesome/admin/update_constraint.rb +44 -0
- data/app/commands/decidim/decidim_awesome/create_editor_image.rb +34 -0
- data/app/controllers/concerns/decidim/decidim_awesome/needs_awesome_config.rb +17 -0
- data/app/controllers/decidim/decidim_awesome/admin/application_controller.rb +21 -0
- data/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +37 -0
- data/app/controllers/decidim/decidim_awesome/admin/config_controller.rb +44 -0
- data/app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb +126 -0
- data/app/controllers/decidim/decidim_awesome/application_controller.rb +14 -0
- data/app/controllers/decidim/decidim_awesome/editor_images_controller.rb +50 -0
- data/app/controllers/decidim/decidim_awesome/iframe_component/application_controller.rb +15 -0
- data/app/controllers/decidim/decidim_awesome/iframe_component/iframe_controller.rb +33 -0
- data/app/controllers/decidim/decidim_awesome/map_component/application_controller.rb +15 -0
- data/app/controllers/decidim/decidim_awesome/map_component/map_controller.rb +31 -0
- data/app/forms/decidim/decidim_awesome/admin/config_form.rb +22 -0
- data/app/forms/decidim/decidim_awesome/admin/constraint_form.rb +20 -0
- data/app/forms/decidim/decidim_awesome/admin/intergram_form.rb +21 -0
- data/app/forms/decidim/decidim_awesome/editor_image_form.rb +16 -0
- data/app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb +90 -0
- data/app/helpers/decidim/decidim_awesome/application_helper.rb +10 -0
- data/app/helpers/decidim/decidim_awesome/map_helper.rb +121 -0
- data/app/models/decidim/decidim_awesome/application_record.rb +10 -0
- data/app/models/decidim/decidim_awesome/awesome_config.rb +23 -0
- data/app/models/decidim/decidim_awesome/config_constraint.rb +13 -0
- data/app/models/decidim/decidim_awesome/editor_image.rb +24 -0
- data/app/permissions/decidim/decidim_awesome/permissions.rb +29 -0
- data/app/uploaders/decidim/decidim_awesome/image_uploader.rb +22 -0
- data/app/views/decidim/decidim_awesome/admin/checks/index.html.erb +35 -0
- data/app/views/decidim/decidim_awesome/admin/config/_constraints.html.erb +27 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_editors.html.erb +20 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_livechat.html.erb +44 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_proposals.html.erb +12 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_surveys.html.erb +9 -0
- data/app/views/decidim/decidim_awesome/admin/config/_modal.html.erb +11 -0
- data/app/views/decidim/decidim_awesome/admin/config/show.html.erb +15 -0
- data/app/views/decidim/decidim_awesome/admin/constraints/_form.html.erb +56 -0
- data/app/views/decidim/decidim_awesome/admin/constraints/new.html.erb +14 -0
- data/app/views/decidim/decidim_awesome/admin/constraints/show.html.erb +14 -0
- data/app/views/decidim/decidim_awesome/iframe_component/iframe/show.html.erb +9 -0
- data/app/views/decidim/decidim_awesome/map_component/map/error.erb +7 -0
- data/app/views/decidim/decidim_awesome/map_component/map/show.html.erb +74 -0
- data/app/views/layouts/decidim/_head.html.erb +5 -0
- data/app/views/layouts/decidim/admin/_header.html.erb +5 -0
- data/app/views/layouts/decidim/admin/decidim_awesome.html.erb +47 -0
- data/app/views/layouts/decidim/decidim_awesome/_awesome_config.html.erb +20 -0
- data/app/views/layouts/decidim/decidim_awesome/_intergram_widget.html.erb +16 -0
- data/app/views/v0.21/layouts/decidim/_head.html.erb +34 -0
- data/app/views/v0.21/layouts/decidim/admin/_header.html.erb +9 -0
- data/app/views/v0.22/layouts/decidim/_head.html.erb +36 -0
- data/app/views/v0.22/layouts/decidim/admin/_header.html.erb +11 -0
- data/config/i18n-tasks.yml +10 -0
- data/config/locales/ca.yml +125 -0
- data/config/locales/cs.yml +125 -0
- data/config/locales/en.yml +176 -0
- data/config/locales/es.yml +125 -0
- data/config/locales/fr.yml +125 -0
- data/config/locales/sv.yml +125 -0
- data/db/migrate/20200324170000_create_decidim_awesome_config.rb +16 -0
- data/db/migrate/20200324230936_create_awesome_editor_images.rb +14 -0
- data/db/migrate/20200403142257_create_decidim_awesome_config_constraints.rb +13 -0
- data/db/seeds.rb +27 -0
- data/lib/decidim/decidim_awesome.rb +110 -0
- data/lib/decidim/decidim_awesome/admin.rb +10 -0
- data/lib/decidim/decidim_awesome/admin_engine.rb +45 -0
- data/lib/decidim/decidim_awesome/awesome_helpers.rb +55 -0
- data/lib/decidim/decidim_awesome/checksums.yml +15 -0
- data/lib/decidim/decidim_awesome/config.rb +129 -0
- data/lib/decidim/decidim_awesome/content_renderers.rb +9 -0
- data/lib/decidim/decidim_awesome/content_renderers/markdown_renderer.rb +18 -0
- data/lib/decidim/decidim_awesome/context_analyzers.rb +11 -0
- data/lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb +38 -0
- data/lib/decidim/decidim_awesome/context_analyzers/participatory_space_analyzer.rb +31 -0
- data/lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb +97 -0
- data/lib/decidim/decidim_awesome/engine.rb +38 -0
- data/lib/decidim/decidim_awesome/iframe_component/component.rb +59 -0
- data/lib/decidim/decidim_awesome/iframe_component/engine.rb +23 -0
- data/lib/decidim/decidim_awesome/map_component/component.rb +74 -0
- data/lib/decidim/decidim_awesome/map_component/engine.rb +23 -0
- data/lib/decidim/decidim_awesome/system_checker.rb +63 -0
- data/lib/decidim/decidim_awesome/test/factories.rb +36 -0
- data/lib/decidim/decidim_awesome/test/shared_examples/config_examples.rb +25 -0
- data/lib/decidim/decidim_awesome/test/themes/css.lvh.me.css +3 -0
- data/lib/decidim/decidim_awesome/test/themes/erb.lvh.me.scss.erb +2 -0
- data/lib/decidim/decidim_awesome/test/themes/scss.lvh.me.scss +1 -0
- data/lib/decidim/decidim_awesome/test/themes/test-theme/body.scss +4 -0
- data/lib/decidim/decidim_awesome/version.rb +10 -0
- data/vendor/assets/images/layers-2x.png +0 -0
- data/vendor/assets/images/layers.png +0 -0
- data/vendor/assets/images/marker-icon.png +0 -0
- data/vendor/assets/javascripts/codemirror-4.inline-attachment.js +89 -0
- data/vendor/assets/javascripts/form-storage.js +824 -0
- data/vendor/assets/javascripts/highlight.min.js +44 -0
- data/vendor/assets/javascripts/image-resize.min.js +1 -0
- data/vendor/assets/javascripts/image-upload.min.js +6 -0
- data/vendor/assets/javascripts/inline-attachment.js +399 -0
- data/vendor/assets/javascripts/inscrybmde.min.js +7 -0
- data/vendor/assets/javascripts/jquery.inline-attachment.js +66 -0
- data/vendor/assets/javascripts/leaflet.featuregroup.subgroup.js +6 -0
- data/vendor/assets/stylesheets/default.min.css +1 -0
- data/vendor/assets/stylesheets/foundation.min.css +1 -0
- data/vendor/assets/stylesheets/github.min.css +2 -0
- data/vendor/assets/stylesheets/inscrybmde.min.css +8 -0
- metadata +267 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
((exports) => {
|
2
|
+
|
3
|
+
const getCategory = (category) => {
|
4
|
+
let defaultCat = {
|
5
|
+
color: getComputedStyle(document.documentElement).getPropertyValue('--primary'),
|
6
|
+
children: () => {},
|
7
|
+
parent: null,
|
8
|
+
name: null
|
9
|
+
};
|
10
|
+
if(category) {
|
11
|
+
let id = category.id ? parseInt(category.id, 10) : parseInt(category, 10);
|
12
|
+
let cat = exports.AwesomeMap.categories.find((c) => c.id == id);
|
13
|
+
if(cat) {
|
14
|
+
cat.children = () => {
|
15
|
+
return exports.AwesomeMap.categories.filter((c) => c.parent === cat.id );
|
16
|
+
}
|
17
|
+
return cat;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return defaultCat;
|
21
|
+
};
|
22
|
+
|
23
|
+
exports.AwesomeMap = exports.AwesomeMap || {};
|
24
|
+
exports.AwesomeMap.getCategory = getCategory;
|
25
|
+
})(window);
|
@@ -0,0 +1,215 @@
|
|
1
|
+
// = require decidim/map
|
2
|
+
// = require leaflet.featuregroup.subgroup
|
3
|
+
// = require decidim/decidim_awesome/awesome_map/categories
|
4
|
+
// = require decidim/decidim_awesome/awesome_map/proposals
|
5
|
+
// = require decidim/decidim_awesome/awesome_map/meetings
|
6
|
+
// = require_self
|
7
|
+
|
8
|
+
((exports) => {
|
9
|
+
const { fetchProposals, fetchMeetings, getCategory } = exports.AwesomeMap;
|
10
|
+
|
11
|
+
const collapsedMenu = $("#map").data("collapsed");
|
12
|
+
const components = $("#map").data("components");
|
13
|
+
const popupMeetingTemplateId = "marker-meeting-popup";
|
14
|
+
const popupProposalTemplateId = "marker-proposal-popup";
|
15
|
+
|
16
|
+
const cluster = L.markerClusterGroup();
|
17
|
+
const amendments = [];
|
18
|
+
|
19
|
+
const layers = {};
|
20
|
+
|
21
|
+
const control = L.control.layers(null, null, {
|
22
|
+
position: 'topleft',
|
23
|
+
sortLayers: false,
|
24
|
+
collapsed: collapsedMenu,
|
25
|
+
// hideSingleBase: true
|
26
|
+
});
|
27
|
+
const allMarkers = [];
|
28
|
+
|
29
|
+
const drawMarker = (element, marker, component) => {
|
30
|
+
let tmpl = component.type === "proposals" ? popupProposalTemplateId : popupMeetingTemplateId,
|
31
|
+
node = document.createElement("div");
|
32
|
+
|
33
|
+
$.tmpl($(`#${tmpl}`), element).appendTo(node);
|
34
|
+
|
35
|
+
marker.bindPopup(node, {
|
36
|
+
maxwidth: 640,
|
37
|
+
minWidth: 500,
|
38
|
+
keepInView: true,
|
39
|
+
className: "map-info"
|
40
|
+
}).openPopup();
|
41
|
+
|
42
|
+
allMarkers.push({
|
43
|
+
marker: marker,
|
44
|
+
component: component,
|
45
|
+
element: element
|
46
|
+
});
|
47
|
+
|
48
|
+
// Check if it has amendments, add it to a list
|
49
|
+
if(element.amendments && element.amendments.length) {
|
50
|
+
element.amendments.forEach((amendment) => {
|
51
|
+
amendments.push(amendment.emendation.id);
|
52
|
+
});
|
53
|
+
}
|
54
|
+
// Add to category layer
|
55
|
+
let cat = getCategory(element.category);
|
56
|
+
if(layers[cat.id]) {
|
57
|
+
marker.addTo(layers[cat.id].group);
|
58
|
+
// show category if hidden
|
59
|
+
const $label = $(`.awesome_map-category_${cat.id}`).closest("label");
|
60
|
+
const $parent = $(`.awesome_map-category_${cat.parent}`).closest("label");
|
61
|
+
$label.show();
|
62
|
+
// update number of items
|
63
|
+
$label.attr("title", parseInt($label.attr("title") || 0) + 1);
|
64
|
+
// show parent if apply
|
65
|
+
$parent.show();
|
66
|
+
$parent.attr("title", parseInt($parent.attr("title") || 0) + 1);
|
67
|
+
// update component stats
|
68
|
+
const $component = $(`#awesome_map-component-${component.id}`);
|
69
|
+
$component.attr("title", parseInt($component.attr("title") || 0) + 1);
|
70
|
+
}
|
71
|
+
|
72
|
+
return marker;
|
73
|
+
};
|
74
|
+
|
75
|
+
const loadElements = (map) => {
|
76
|
+
// legends
|
77
|
+
control.addTo(map);
|
78
|
+
cluster.addTo(map);
|
79
|
+
|
80
|
+
// Load markers
|
81
|
+
components.forEach((component) => {
|
82
|
+
if(component.type == "proposals") {
|
83
|
+
// add control layer for proposals
|
84
|
+
layers.proposals = {
|
85
|
+
label: `<span id="awesome_map-component-${component.id}" title="0">${component.name || window.DecidimAwesome.texts.proposals}</span>`,
|
86
|
+
group: L.featureGroup.subGroup(cluster)
|
87
|
+
};
|
88
|
+
control.addOverlay(layers.proposals.group, layers.proposals.label);
|
89
|
+
layers.proposals.group.addTo(map);
|
90
|
+
|
91
|
+
// add control layer for amendments if any
|
92
|
+
if(component.amendments) {
|
93
|
+
layers.amendments = {
|
94
|
+
label: `<span id="awesome_map-component-${component.d}" title="0">${window.DecidimAwesome.texts.amendment}/span>`,
|
95
|
+
group: L.featureGroup.subGroup(cluster)
|
96
|
+
}
|
97
|
+
control.addOverlay(layers.amendments.group, layers.amendments.label);
|
98
|
+
layers.amendments.group.addTo(map);
|
99
|
+
}
|
100
|
+
|
101
|
+
fetchProposals(component, '', (element, marker) => {
|
102
|
+
drawMarker(element, marker, component).addTo(layers.proposals.group);
|
103
|
+
}, () => {
|
104
|
+
// finall call
|
105
|
+
map.fitBounds(cluster.getBounds(), { padding: [50, 50] });
|
106
|
+
allMarkers.forEach((item) => {
|
107
|
+
// add marker to amendments layers if it's an amendment
|
108
|
+
if(amendments.find((a) => a == item.element.id)) {
|
109
|
+
item.marker.removeFrom(layers.proposals.group);
|
110
|
+
item.marker.addTo(layers.amendments.group);
|
111
|
+
}
|
112
|
+
});
|
113
|
+
});
|
114
|
+
}
|
115
|
+
|
116
|
+
if(component.type == "meetings") {
|
117
|
+
// add control layer for meetings
|
118
|
+
layers.meetings = {
|
119
|
+
label: `<span id="awesome_map-component-${component.id}" title="0">${component.name || window.DecidimAwesome.texts.meetings}/span>`,
|
120
|
+
group: L.featureGroup.subGroup(cluster)
|
121
|
+
};
|
122
|
+
control.addOverlay(layers.meetings.group, layers.meetings.label);
|
123
|
+
layers.meetings.group.addTo(map);
|
124
|
+
|
125
|
+
fetchMeetings(component, '', (element, marker) => {
|
126
|
+
drawMarker(element, marker, component).addTo(layers.meetings.group);
|
127
|
+
}, () => {
|
128
|
+
map.fitBounds(cluster.getBounds(), { padding: [50, 50] });
|
129
|
+
});
|
130
|
+
}
|
131
|
+
});
|
132
|
+
|
133
|
+
|
134
|
+
// add categories control layers
|
135
|
+
if(window.AwesomeMap.categories.length) {
|
136
|
+
let lastLayer = layers[Object.keys(layers)[Object.keys(layers).length - 1]];
|
137
|
+
// Add Categories "title"
|
138
|
+
if(lastLayer) {
|
139
|
+
lastLayer.label = `${lastLayer.label}<hr><b>${window.DecidimAwesome.texts.categories}</b>`;
|
140
|
+
control.removeLayer(lastLayer.group);
|
141
|
+
control.addOverlay(lastLayer.group, lastLayer.label);
|
142
|
+
}
|
143
|
+
|
144
|
+
window.AwesomeMap.categories.forEach((category) => {
|
145
|
+
// add control layer for this category
|
146
|
+
layers[category.id] = {
|
147
|
+
label: `<i class="awesome_map-category_${category.id}"></i> ${category.name}`,
|
148
|
+
group: L.featureGroup.subGroup(cluster)
|
149
|
+
};
|
150
|
+
layers[category.id].group.addTo(map);
|
151
|
+
control.addOverlay(layers[category.id].group, layers[category.id].label);
|
152
|
+
// hide layer by default, it will be activated if there's any marker in it
|
153
|
+
setTimeout(() => {
|
154
|
+
$(`.awesome_map-category_${category.id}`).closest("label").hide();
|
155
|
+
});
|
156
|
+
});
|
157
|
+
|
158
|
+
// watch events for subcategories syncronitzation
|
159
|
+
const getCatFromClass = (name) => {
|
160
|
+
let id = name.match(/awesome_map-category_(\d+)/)
|
161
|
+
if(!id) return;
|
162
|
+
const cat = getCategory(id[1]);
|
163
|
+
if(!cat || !cat.name) return;
|
164
|
+
|
165
|
+
return cat;
|
166
|
+
};
|
167
|
+
|
168
|
+
const indeterminateInput = (id) => {
|
169
|
+
$('[class^="awesome_map-category_"]').parent().prev().prop("indeterminate", false);
|
170
|
+
if(id) {
|
171
|
+
let $input = $(`.awesome_map-category_${id}`).parent().prev();
|
172
|
+
if(!$input.prop("checked")) {
|
173
|
+
$input.prop("indeterminate", true);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
};
|
177
|
+
|
178
|
+
map.on('overlayadd', (e) => {
|
179
|
+
const cat = getCatFromClass(e.name);
|
180
|
+
if(!cat) return;
|
181
|
+
// if it's a children, put the parent to indeterminate
|
182
|
+
indeterminateInput(cat.parent);
|
183
|
+
});
|
184
|
+
|
185
|
+
// on remove a parent category, remove all children
|
186
|
+
map.on('overlayremove', (e) => {
|
187
|
+
const cat = getCatFromClass(e.name);
|
188
|
+
if(!cat) return;
|
189
|
+
cat.children().forEach((c) => {
|
190
|
+
let $el = $(`.awesome_map-category_${c.id}`);
|
191
|
+
if($el.parent().prev().prop("checked")) {
|
192
|
+
$el.click();
|
193
|
+
}
|
194
|
+
});
|
195
|
+
});
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
};
|
200
|
+
|
201
|
+
// currentMap might not be loaded yet so let's delay a bit
|
202
|
+
// TODO: improve this
|
203
|
+
const waitMap = () => {
|
204
|
+
if(exports.Decidim && exports.Decidim.currentMap) {
|
205
|
+
loadElements(exports.Decidim.currentMap);
|
206
|
+
} else {
|
207
|
+
setTimeout(() => {
|
208
|
+
waitMap();
|
209
|
+
}, 100);
|
210
|
+
}
|
211
|
+
};
|
212
|
+
|
213
|
+
waitMap();
|
214
|
+
|
215
|
+
})(window);
|
@@ -0,0 +1,129 @@
|
|
1
|
+
// = require decidim/decidim_awesome/awesome_map/api_fetcher
|
2
|
+
// = require decidim/decidim_awesome/awesome_map/categories
|
3
|
+
|
4
|
+
((exports) => {
|
5
|
+
const { getCategory } = exports.AwesomeMap;
|
6
|
+
const 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
|
+
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
|
+
const MeetingIcon = L.DivIcon.SVGIcon.extend({
|
60
|
+
options: {
|
61
|
+
fillColor: "#ef604d",
|
62
|
+
iconSize: {x: 300, y:150},
|
63
|
+
opacity: 0
|
64
|
+
},
|
65
|
+
_createPathDescription: function() {
|
66
|
+
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";
|
67
|
+
},
|
68
|
+
_createCircle: function() {
|
69
|
+
return ""
|
70
|
+
},
|
71
|
+
// Improved version of the _createSVG, essentially the same as in later
|
72
|
+
// versions of Leaflet. It adds the `px` values after the width and height
|
73
|
+
// CSS making the focus borders work correctly across all browsers.
|
74
|
+
_createSVG: function() {
|
75
|
+
const path = this._createPath();
|
76
|
+
const circle = this._createCircle();
|
77
|
+
const text = this._createText();
|
78
|
+
const className = `${this.options.className}-svg`;
|
79
|
+
|
80
|
+
const style = `width:${this.options.iconSize.x}px; height:${this.options.iconSize.y}px;`;
|
81
|
+
|
82
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="${className}" style="${style}">${path}${circle}${text}</svg>`;
|
83
|
+
|
84
|
+
return svg;
|
85
|
+
}
|
86
|
+
});
|
87
|
+
|
88
|
+
const createMarker = (element, callback) => {
|
89
|
+
const marker = L.marker([element.coordinates.latitude, element.coordinates.longitude], {
|
90
|
+
icon: new MeetingIcon({
|
91
|
+
fillColor: getCategory(element.category).color
|
92
|
+
})
|
93
|
+
});
|
94
|
+
|
95
|
+
element.title.translation = ApiFetcher.findTranslation(element.title.translations);
|
96
|
+
element.description.translation = ApiFetcher.findTranslation(element.description.translations);
|
97
|
+
element.location.translation = ApiFetcher.findTranslation(element.location.translations);
|
98
|
+
element.locationHints.translation = ApiFetcher.findTranslation(element.locationHints.translations);
|
99
|
+
callback(element, marker);
|
100
|
+
};
|
101
|
+
|
102
|
+
const fetchMeetings = (component, after, callback, finalCall = () => {}) => {
|
103
|
+
|
104
|
+
const variables = {
|
105
|
+
"id": component.id,
|
106
|
+
"after": after
|
107
|
+
};
|
108
|
+
const api = new ApiFetcher(query, variables);
|
109
|
+
api.fetchAll((result) => {
|
110
|
+
result.component.meetings.edges.forEach((element) => {
|
111
|
+
if(!element.node) return;
|
112
|
+
|
113
|
+
if(element.node.coordinates) {
|
114
|
+
element.node.link = component.url + '/meetings/' + element.node.id;
|
115
|
+
createMarker(element.node, callback);
|
116
|
+
}
|
117
|
+
});
|
118
|
+
|
119
|
+
if (result.component.meetings.pageInfo.hasNextPage) {
|
120
|
+
fetchMeetings(component, result.component.meetings.pageInfo.endCursor, callback, finalCall);
|
121
|
+
} else {
|
122
|
+
finalCall();
|
123
|
+
}
|
124
|
+
});
|
125
|
+
};
|
126
|
+
|
127
|
+
exports.AwesomeMap = exports.AwesomeMap || {};
|
128
|
+
exports.AwesomeMap.fetchMeetings = fetchMeetings;
|
129
|
+
})(window);
|
@@ -0,0 +1,78 @@
|
|
1
|
+
// = require decidim/decidim_awesome/awesome_map/api_fetcher
|
2
|
+
// = require decidim/decidim_awesome/awesome_map/categories
|
3
|
+
|
4
|
+
((exports) => {
|
5
|
+
const { getCategory } = exports.AwesomeMap;
|
6
|
+
const 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
|
+
title
|
20
|
+
body
|
21
|
+
address
|
22
|
+
coordinates {
|
23
|
+
latitude
|
24
|
+
longitude
|
25
|
+
}
|
26
|
+
amendments {
|
27
|
+
emendation {
|
28
|
+
id
|
29
|
+
}
|
30
|
+
}
|
31
|
+
category {
|
32
|
+
id
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}`;
|
40
|
+
|
41
|
+
const ProposalIcon = L.DivIcon.SVGIcon.DecidimIcon;
|
42
|
+
|
43
|
+
const createMarker = (element, callback) => {
|
44
|
+
const marker = L.marker([element.coordinates.latitude, element.coordinates.longitude], {
|
45
|
+
icon: new ProposalIcon({
|
46
|
+
fillColor: getCategory(element.category).color
|
47
|
+
})
|
48
|
+
});
|
49
|
+
|
50
|
+
callback(element, marker);
|
51
|
+
};
|
52
|
+
|
53
|
+
const fetchProposals = (component, after, callback, finalCall = () => {}) => {
|
54
|
+
const variables = {
|
55
|
+
"id": component.id,
|
56
|
+
"after": after
|
57
|
+
};
|
58
|
+
const api = new ApiFetcher(query, variables);
|
59
|
+
api.fetchAll((result) => {
|
60
|
+
result.component.proposals.edges.forEach((element) => {
|
61
|
+
if(!element.node) return;
|
62
|
+
|
63
|
+
if(element.node.coordinates) {
|
64
|
+
element.node.link = component.url + '/proposals/' + element.node.id;
|
65
|
+
createMarker(element.node, callback);
|
66
|
+
}
|
67
|
+
});
|
68
|
+
if (result.component.proposals.pageInfo.hasNextPage) {
|
69
|
+
fetchProposals(component, result.component.proposals.pageInfo.endCursor, callback, finalCall);
|
70
|
+
} else {
|
71
|
+
finalCall();
|
72
|
+
}
|
73
|
+
});
|
74
|
+
};
|
75
|
+
|
76
|
+
exports.AwesomeMap = exports.AwesomeMap || {};
|
77
|
+
exports.AwesomeMap.fetchProposals = fetchProposals;
|
78
|
+
})(window);
|