From 102df3f25b9e89f49f8e83b8fcfb275840b09812 Mon Sep 17 00:00:00 2001 From: Brook Elgie Date: Thu, 30 Mar 2017 10:02:00 +0100 Subject: [PATCH 1/5] [#967] Map for place pages Fixes sponsor, embed_title and site name for map. --- census/static/scripts/map/ui.js | 4 ++-- census/views/embed/embed.html | 6 ++---- census/views/embed/map_embed.html | 6 ++---- index/generate.js | 13 +++++++------ index/metalsmith-godi-updatedatafiles.js | 7 +++++++ 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/census/static/scripts/map/ui.js b/census/static/scripts/map/ui.js index f0ac1f4f..d5bdd4aa 100644 --- a/census/static/scripts/map/ui.js +++ b/census/static/scripts/map/ui.js @@ -1,12 +1,12 @@ /* eslint-disable */ define(['leaflet', 'proj4', 'proj4leaflet', 'leaflet_zoommin', 'leaflet_label', 'jquery', 'pubsub', 'lodash', 'chroma', 'marked', 'data'], - function(leaflet, proj4, proj4leaflet, leaflet_zoommin, leaflet_label, $, pubsub, _, chroma, + function(leaflet, proj4, proj4leaflet, leaflet_zoommin, leaflet_label, $, pubsub, _, chroma, marked, data) { proj4.defs("EPSG:3410", "+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +a=6371228 +b=6371228 +units=m +no_defs"); - var $container = $('.odi-vis.odi-vis-choropleth'), + var $container = $('.odi-vis.odi-vis-choropleth'), $tools = $('.odi-vis-tools'), $miniLegend = $('.odi-vis-legend ul'), $fullLegend = $('.odi-vis-legend-full ul'), diff --git a/census/views/embed/embed.html b/census/views/embed/embed.html index dcbdb84e..f76d1bbb 100644 --- a/census/views/embed/embed.html +++ b/census/views/embed/embed.html @@ -14,10 +14,8 @@ previousYear = 2015, // years = {{ scope.odi.years|dump|safe }}, years = {{ map.years|dump|safe }}, - // sitename = {{ SITENAME|dump|safe }}, - sitename = 'placeholder for site name', - // sponsor = {{ scope.odi.sponsor.name|dump|safe }}; - sponsor = 'placeholder for sponsor'; + sitename = {{ site_title|dump|safe }}, + sponsor = {{ map.sponsor.name|dump|safe }}; {% block head_scripts %}{% endblock head_scripts %} diff --git a/census/views/embed/map_embed.html b/census/views/embed/map_embed.html index 5a77149c..b4e802be 100644 --- a/census/views/embed/map_embed.html +++ b/census/views/embed/map_embed.html @@ -1,7 +1,5 @@ {% extends 'embed/embed.html' %} -{#{% from '_scope.html' import scope with context %}#} - {% block head_css %} {{ super() }} @@ -17,11 +15,11 @@
diff --git a/index/generate.js b/index/generate.js index 787f220f..37b34f46 100644 --- a/index/generate.js +++ b/index/generate.js @@ -195,18 +195,19 @@ Metalsmith(__dirname) // format function needs to be available in templates format: i18n.format, site_url: baseUrl, - map: { // Initial map presets. + map: { // Initial map presets. May be overridden in godiDataFiles. embed_width: '100%', embed_height: '300px', - // filter_year: filter_year, filter_year: year, - // filter_dataset: filter_dataset, filter_dataset: 'all', years: [year], panel_tools: 'true', panel_share: 'true', - // map_place: map_place - map_place: '' + map_place: '', + sponsor: { + name: 'Open Knowledge', + domain: 'https://okfn.org/' + } } }) .source('./src') @@ -218,7 +219,7 @@ Metalsmith(__dirname) questionsApi: `${surveyUrl}/api/questions.json`, placesApi: `${surveyUrl}/api/places/score/${year}.json` }, {json: true})) - .use(godiApiDataToFiles()) // Set api stored on metaddata, retrieved using metalsmith-request above, to files. + .use(godiApiDataToFiles()) // Set api stored on metadata, retrieved using metalsmith-request above, to files. .use(godiGetData({domain: domain, year: year})) // Populate metadata with data from Survey .use(jsonToFiles({use_metadata: true})) .use(paths({property: 'paths', directoryIndex: 'index.html'})) diff --git a/index/metalsmith-godi-updatedatafiles.js b/index/metalsmith-godi-updatedatafiles.js index 37c7b1c8..4d47e5da 100644 --- a/index/metalsmith-godi-updatedatafiles.js +++ b/index/metalsmith-godi-updatedatafiles.js @@ -50,6 +50,13 @@ function plugin(options) { if (file.metadata_key === 'places') { file.place = file.data; file.stats = file.data.stats; + + file.map = _.clone(metadata.map); + file.map.map_place = file.place.id; + file.map.panel_tools = false; + file.map.panel_share = false; + file.map.embed_title = `${file.place.name} ; ${file.map.filter_year}`; + delete file.data; } From df5f7ff9842c2f1e74c7ae1779cd1bf41664eff8 Mon Sep 17 00:00:00 2001 From: Brook Elgie Date: Thu, 30 Mar 2017 11:38:11 +0100 Subject: [PATCH 2/5] [#967] Fix dataset stats. Looks like a typo. --- index/metalsmith-godi-updatedatafiles.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index/metalsmith-godi-updatedatafiles.js b/index/metalsmith-godi-updatedatafiles.js index 4d47e5da..472bdb1f 100644 --- a/index/metalsmith-godi-updatedatafiles.js +++ b/index/metalsmith-godi-updatedatafiles.js @@ -62,7 +62,8 @@ function plugin(options) { if (file.metadata_key === 'datasets') { file.dataset = file.data; - file.stats = file.data.datas; + file.stats = file.data.stats; + delete file.data; } } From 40f594121a878c00c3d672ed63cf11161bd5d514 Mon Sep 17 00:00:00 2001 From: Brook Elgie Date: Thu, 30 Mar 2017 12:16:01 +0100 Subject: [PATCH 3/5] [#967] Move analytics template snippet to an include. So it can be used in the embed template. --- census/views/base.html | 24 +----------------------- census/views/embed/embed.html | 2 +- census/views/includes/analytics.html | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 census/views/includes/analytics.html diff --git a/census/views/base.html b/census/views/base.html index 0fecc02c..60cf2dca 100644 --- a/census/views/base.html +++ b/census/views/base.html @@ -191,29 +191,7 @@ - {% if site.settings.google_analytics_key or google_analytics_key %} - - - {% endif %} - - diff --git a/census/views/embed/embed.html b/census/views/embed/embed.html index f76d1bbb..08bb8f2b 100644 --- a/census/views/embed/embed.html +++ b/census/views/embed/embed.html @@ -22,7 +22,7 @@ {% block content %}{% endblock content %} {% block body_scripts %} - {# {% include '_analytics.html' %} #} + {% include 'includes/analytics.html' %} {% endblock body_scripts %} diff --git a/census/views/includes/analytics.html b/census/views/includes/analytics.html new file mode 100644 index 00000000..0f6fb439 --- /dev/null +++ b/census/views/includes/analytics.html @@ -0,0 +1,24 @@ +{% if site.settings.google_analytics_key or google_analytics_key %} + + +{% endif %} + + From f2b65bddcfeebb8c6a3474abf8e68216de2ceaef Mon Sep 17 00:00:00 2001 From: Brook Elgie Date: Thu, 30 Mar 2017 14:04:26 +0100 Subject: [PATCH 4/5] [#967] Map for dataset pages --- census/static/scripts/map/ui.js | 6 +++--- index/metalsmith-godi-updatedatafiles.js | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/census/static/scripts/map/ui.js b/census/static/scripts/map/ui.js index d5bdd4aa..75098143 100644 --- a/census/static/scripts/map/ui.js +++ b/census/static/scripts/map/ui.js @@ -397,7 +397,7 @@ define(['leaflet', 'proj4', 'proj4leaflet', 'leaflet_zoommin', 'leaflet_label', // calculate for this dataset/year/place from entries data match = _.find(dataStore.entries, { 'place': feature.properties.iso_a2.toLowerCase(), - 'year': uiState.filter.year, + 'year': parseInt(uiState.filter.year, 10), 'dataset': uiState.filter.dataset }); if (match) { @@ -606,7 +606,7 @@ define(['leaflet', 'proj4', 'proj4leaflet', 'leaflet_zoommin', 'leaflet_label', // calculate for this dataset/year/place from entries data match = _.find(dataStore.entries, { 'place': place.id, - 'year': uiState.filter.year, + 'year': parseInt(uiState.filter.year, 10), 'dataset': uiState.filter.dataset }); if (match) { @@ -672,7 +672,7 @@ define(['leaflet', 'proj4', 'proj4leaflet', 'leaflet_zoommin', 'leaflet_label', // calculate for this dataset/year/place from entries data match = _.find(dataStore.entries, { 'place': properties.iso_a2.toLowerCase(), - 'year': uiState.filter.year, + 'year': parseInt(uiState.filter.year, 10), 'dataset': uiState.filter.dataset }); previousMatch = _.find(dataStore.entries, { diff --git a/index/metalsmith-godi-updatedatafiles.js b/index/metalsmith-godi-updatedatafiles.js index 472bdb1f..b1ea6711 100644 --- a/index/metalsmith-godi-updatedatafiles.js +++ b/index/metalsmith-godi-updatedatafiles.js @@ -64,6 +64,12 @@ function plugin(options) { file.dataset = file.data; file.stats = file.data.stats; + file.map = _.clone(metadata.map); + file.map.filter_dataset = file.dataset.id; + file.map.panel_tools = false; + file.map.panel_share = false; + file.map.embed_title = `${file.dataset.name} ; ${file.map.filter_year}`; + delete file.data; } } From eb6fcf24898835a6fd7e0c23e98f0de7b6406d11 Mon Sep 17 00:00:00 2001 From: Brook Elgie Date: Thu, 30 Mar 2017 14:57:09 +0100 Subject: [PATCH 5/5] [#967] Map for entry pages. --- census/views/entry.html | 2 +- index/metalsmith-godi-updatedatafiles.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/census/views/entry.html b/census/views/entry.html index 992d156d..d3cf4195 100644 --- a/census/views/entry.html +++ b/census/views/entry.html @@ -54,7 +54,7 @@
{{ gettext("See other years") }}
{% if is_index %}
- + {% include 'includes/dataviews/embed_map.html' %}
{% endif %} diff --git a/index/metalsmith-godi-updatedatafiles.js b/index/metalsmith-godi-updatedatafiles.js index b1ea6711..de48db64 100644 --- a/index/metalsmith-godi-updatedatafiles.js +++ b/index/metalsmith-godi-updatedatafiles.js @@ -44,6 +44,13 @@ function plugin(options) { file.place.id); } + file.map = _.clone(metadata.map); + file.map.map_place = file.place.id; + file.map.filter_dataset = file.dataset.id; + file.map.panel_tools = false; + file.map.panel_share = false; + file.map.embed_title = `${file.place.name} ; ${file.dataset.name} ; ${file.map.filter_year}`; + delete file.data; }