From 427df5e7f90c2d03dd92ec8dfb05792221c3c107 Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Wed, 2 Sep 2020 13:05:48 +0300 Subject: [PATCH] Fixed Map filters; Fixed View; --- .../DiscodataOpenlayersMapBlock/View.jsx | 65 ++++++++++++------- .../manage/Blocks/FiltersBlock/View.jsx | 60 +++++++++++++---- src/components/theme/View/RedirectView.jsx | 10 ++- .../volto/components/theme/View/View.jsx | 4 +- src/helpers/api.jsx | 2 +- 5 files changed, 95 insertions(+), 46 deletions(-) diff --git a/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx b/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx index b14c557..38372d5 100644 --- a/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx +++ b/src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx @@ -184,7 +184,7 @@ const OpenlayersMapView = (props) => { }, [ JSON.stringify(props.discodata_query.search.siteTerm), JSON.stringify(props.discodata_query.search.locationTerm), - JSON.stringify(props.discodata_query.search.EEASector), + JSON.stringify(props.discodata_query.search.EEASubSector), JSON.stringify(props.discodata_query.search.siteCountry), JSON.stringify(props.discodata_query.search.region), JSON.stringify(props.discodata_query.search.riverBasin), @@ -230,26 +230,30 @@ const OpenlayersMapView = (props) => { sql: `(siteName LIKE ':options%')`, type: 'string', }, - //? Industries - EEASector: { - sql: `(EEASector IN (:options))`, + // Industries + EEASubSector: { + sql: `(eea_activities IN (:options))`, }, - // Country - siteCountry: { - sql: `(country IN (:options))`, - }, - //? Regions - region: { - sql: `(region IN (:options))`, - }, - //? River Basin - riverBasin: { - sql: `(riverBasinDistrict IN (:options))`, - }, - //? Town/Village - townVillage: { - sql: `(townVillage IN (:options))`, + nuts_regions: { + sql: `(nuts_regions LIKE '%:options%')`, + type: 'multiple', }, + // // Country + // siteCountry: { + // sql: `(countryCode IN (:options))`, + // }, + // //? Regions + // region: { + // sql: `(region IN (:options))`, + // }, + // //? River Basin + // riverBasin: { + // sql: `(riverBasinDistrict IN (:options))`, + // }, + // //? Town/Village + // townVillage: { + // sql: `(townVillage IN (:options))`, + // }, // Pollutant groups // pollutantGroup: { // sql: `(pollutantGroup IN (:options))`, @@ -260,7 +264,7 @@ const OpenlayersMapView = (props) => { }, // Reporting year reportingYear: { - sql: `(rep_yr IN (:options))`, + sql: `(Site_reporting_year IN (:options))`, }, //! Installation specifics //? BAT conclusion @@ -282,12 +286,27 @@ const OpenlayersMapView = (props) => { let options; if (where.type === 'string') { options = props.discodata_query.search[id]; + } else if (where.type === 'multiple') { + options = props.discodata_query.search[id]; } else if (!props.discodata_query.search[id]) { options = null; } else { options = splitBy(props.discodata_query.search[id], ','); } - where.sql = options ? where.sql.replace(':options', options) : null; + if (where.type === 'multiple') { + const conditions = []; + if (options?.length) { + options.forEach((option) => { + let baseSql = where.sql; + option && conditions.push(baseSql.replace(':options', option)); + }); + where.sql = conditions.join(' AND '); + } else { + where.sql = null; + } + } else { + where.sql = options ? where.sql.replace(':options', options) : null; + } if (!where.sql) delete sitesSourceQuery.whereStatements[id]; }); @@ -720,12 +739,12 @@ const OpenlayersMapView = (props) => { layers: [worldLightGrayBase, worldHillshade], }), ); - // Append popups to the map - popup && map.addOverlay(popup); popupDetails && map.addOverlay(popupDetails); // Append dynamic filters to the map dynamicFilters && map.addOverlay(dynamicFilters); dynamicFilters && dynamicFilters.setPosition([0, 0]); + // Append popups to the map + popup && map.addOverlay(popup); // Append source layers to the map map.addLayer( new Group({ diff --git a/src/components/manage/Blocks/FiltersBlock/View.jsx b/src/components/manage/Blocks/FiltersBlock/View.jsx index 422560d..bc2891c 100644 --- a/src/components/manage/Blocks/FiltersBlock/View.jsx +++ b/src/components/manage/Blocks/FiltersBlock/View.jsx @@ -103,7 +103,7 @@ const View = ({ content, ...props }) => { ? { factId: 'Country_quick_facts', sql: `SELECT DISTINCT MP.siteCountry, MP.siteCountryName, MM.siteCount - FROM [IED].[latest].[vw_Browse2_MapPOPUP] as MP + FROM [IED].[latest].[Browse2_MapPOPUP] as MP LEFT JOIN [IED].[latest].[vw_MainMap_totalSitesPerCountry] as MM ON MP.siteCountry = MM.countryCode WHERE siteCountry = '${alphaFeature.getProperties().country}'`, @@ -211,38 +211,38 @@ const View = ({ content, ...props }) => { const onMountRequests = { sqls: [ // INDUSTRIES QUERY - `SELECT DISTINCT EEASector + `SELECT DISTINCT EEASubSector FROM [IED].[latest].[EPRTR_sectors] - ORDER BY EEASector`, + ORDER BY EEASubSector`, // COUNTRIES QUERY `SELECT DISTINCT siteCountry, siteCountryName - FROM [IED].[latest].[vw_Browse2_MapPOPUP] + FROM [IED].[latest].[Browse2_MapPOPUP] ORDER BY siteCountryName`, // POLLUTANT GROUPS QUERY `SELECT DISTINCT pollutantgroup - FROM [IED].[latest].[vw_Browse2_MapPOPUP] + FROM [IED].[latest].[Browse2_MapPOPUP] WHERE NOT(pollutantgroup='') ORDER BY pollutantgroup`, // REPORTING YEARS QUERY `SELECT DISTINCT reportingYear FROM [IED].[latest].[ReportData] ORDER BY reportingYear`, // BAT CONCLUSSIONS QUERY - `SELECT DISTINCT code, Label, AcceptedDate FROM [IED].[latest].[BATConclusionValue] ORDER BY Label`, + `SELECT DISTINCT id, Label, AcceptedDate FROM [IED].[latest].[BATConclusionValue] ORDER BY Label`, ], meta: [ // INDUSTRIES META { key: 'industries', title: 'Industries', - queryToSet: 'EEASector', + queryToSet: 'EEASubSector', firstInput: { id: _uniqueId('select_'), type: 'select', position: 0, }, placeholder: 'Select industry', - optionKey: 'EEASector', - optionValue: 'EEASector', - optionText: 'EEASector', + optionKey: 'EEASubSector', + optionValue: 'EEASubSector', + optionText: 'EEASubSector', static: true, }, // COUNTRIES META @@ -304,8 +304,8 @@ const View = ({ content, ...props }) => { position: 0, }, placeholder: 'Select BAT conclusion', - optionKey: 'code', - optionValue: 'code', + optionKey: 'id', + optionValue: 'id', optionText: 'Label', static: true, }, @@ -509,7 +509,7 @@ const View = ({ content, ...props }) => { /* eslint-disable-next-line */ }, [ state.mounted, - state.filters?.EEASector && JSON.stringify(state.filters.EEASector), + state.filters?.EEASubSector && JSON.stringify(state.filters.EEASubSector), state.filters?.siteCountry && JSON.stringify(state.filters.siteCountry), state.filters?.region && JSON.stringify(state.filters.region), state.filters?.townVillage && JSON.stringify(state.filters.townVillage), @@ -635,6 +635,7 @@ const View = ({ content, ...props }) => { queryParam: { ...props.discodata_query.search, ...newFilters, + nuts_regions: [], }, }); }; @@ -730,6 +731,36 @@ const View = ({ content, ...props }) => { : 'locationTerm'; const emptyTermType = searchTermType === 'siteTerm' ? 'locationTerm' : 'siteTerm'; + const siteCountries = state.filters.siteCountry; + const regions = state.filters.region; + const townVillages = state.filters.townVillage; + let nuts = []; + siteCountries && + siteCountries.forEach((country) => { + const filteredRegions = regions + ? regions.filter((region) => { + return region.includes(country); + }) + : []; + if (filteredRegions.length) { + filteredRegions.forEach((region) => { + const filteredTowns = townVillages + ? townVillages.filter((town) => { + return town.includes(region); + }) + : []; + if (filteredTowns.length) { + filteredTowns.forEach((town) => { + nuts.push(`${town},${region},${country}`); + }); + } else { + nuts.push(`${region},${country}`); + } + }); + } else { + nuts.push(country); + } + }); props.setQueryParam({ queryParam: { ...state.filters, @@ -738,6 +769,7 @@ const View = ({ content, ...props }) => { ? locationResults[locationResultsTexts.indexOf(searchTerm)] : searchTerm, [emptyTermType]: null, + nuts_regions: nuts, }, }); setState({ ...state, open: false }); @@ -1017,7 +1049,7 @@ const View = ({ content, ...props }) => { }} placeholder={state.filtersMeta['industries']?.placeholder} options={state.filtersMeta['industries']?.options} - value={state.filters['EEASector']?.[0]} + value={state.filters['EEASubSector']?.[0]} /> diff --git a/src/components/theme/View/RedirectView.jsx b/src/components/theme/View/RedirectView.jsx index 8272d64..9d0fb39 100644 --- a/src/components/theme/View/RedirectView.jsx +++ b/src/components/theme/View/RedirectView.jsx @@ -2,10 +2,8 @@ import React, { useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { connect } from 'react-redux'; -/* ROOT IMPORTS */ -import DiscodataView from './DiscodataView'; -/* LOCAL IMPORTS */ import { getBasePath } from '~/helpers'; +import { Dimmer, Loader } from 'semantic-ui-react'; const RedirectView = (props) => { const history = useHistory(); const [redirect, setRedirect] = useState(false); @@ -27,9 +25,9 @@ const RedirectView = (props) => { } } return ( -
-

Redirecting...

-
+ + European Environment Agency + ); }; diff --git a/src/customizations/volto/components/theme/View/View.jsx b/src/customizations/volto/components/theme/View/View.jsx index 4f16224..a49f6e0 100644 --- a/src/customizations/volto/components/theme/View/View.jsx +++ b/src/customizations/volto/components/theme/View/View.jsx @@ -132,7 +132,7 @@ class View extends Component { } componentDidUpdate(prevProps, prevState) { - if (prevProps.content['@id'] !== this.props.content['@id']) { + if (prevProps.content?.['@id'] !== this.props.content?.['@id']) { const RenderedView = this.getRenderedView(); this.setState({ RenderedView }); } @@ -187,7 +187,7 @@ class View extends Component { ] || null; getRenderedView = () => - getBasePath(this.props.content['@id']) === this.props.pathname + getBasePath(this.props.content?.['@id']) === this.props.pathname ? this.getViewByType() || this.getViewByLayout() || this.getViewDefault() : null; diff --git a/src/helpers/api.jsx b/src/helpers/api.jsx index 333eee5..81e3bb8 100644 --- a/src/helpers/api.jsx +++ b/src/helpers/api.jsx @@ -81,7 +81,7 @@ export const getLcps = (dispatch, siteInspireId) => { facilityInspireId, installationInspireId, string_agg(concat(lcpInspireId, ''), ',') as lcps - FROM [IED].[latest].[vw_Browse10_Header] as Results + FROM [IED].[latest].[Browse10_Header] as Results WHERE siteInspireId = '${siteInspireId}' GROUP BY facilityInspireId, installationInspireId`); const url = `${settings.providerUrl}?query=${sql}`;