Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Oct 5, 2021
1 parent d251bbb commit 64ce512
Show file tree
Hide file tree
Showing 6 changed files with 1,775 additions and 283 deletions.
2 changes: 1 addition & 1 deletion docker-image.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eeacms/eprtr-frontend
eeacms/eprtr-frontend:2.2.0
2 changes: 1 addition & 1 deletion locales/de.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion locales/en.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,14 @@ const OpenlayersMapView = (props) => {
},
// Facility type
facilityTypes: {
sql: `(facilityTypes LIKE ':options')`,
sql: (options) => {
const isEprtr = options.indexOf('EPRTR') !== -1;
const isNonEprtr = options.indexOf('NONEPRTR') !== -1;
if (isEprtr && isNonEprtr) return null;
if (isEprtr)
return `((facilityTypes LIKE 'EPRTR%') OR (facilityTypes LIKE '% EPRTR'))`;
return `((facilityTypes LIKE 'NONEPRTR%') OR (facilityTypes LIKE '% NONEPRTR'))`;
},
type: 'multiple',
},
// Plant type
Expand Down Expand Up @@ -565,7 +572,9 @@ const OpenlayersMapView = (props) => {
if (where.type === 'multiple') {
options = isArray(options) ? options?.filter((option) => option) : [];
const conditions = [];
if (options?.length) {
if (typeof where.sql === 'function' && options?.length) {
where.sql = where.sql(props.query[id]);
} else if (options?.length) {
options.forEach((option) => {
let baseSql = where.sql;
option && conditions.push(baseSql.replace(/:options/g, option));
Expand Down
93 changes: 55 additions & 38 deletions src/components/manage/Blocks/FiltersBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
import React, { useState, useEffect, useRef } from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { Header, Modal, Select, Input, List } from 'semantic-ui-react';
import {
Header,
Modal,
Select,
Input,
List,
Checkbox,
} from 'semantic-ui-react';
import { Portal } from 'react-portal';
import _uniqueId from 'lodash/uniqueId';
import axios from 'axios';
Expand Down Expand Up @@ -48,7 +55,6 @@ const View = ({ content, ...props }) => {
'pollutant_groups',
'pollutants',
'reporting_years',
'facility_types',
'plant_types',
'bat_conclusions',
'permit_types',
Expand Down Expand Up @@ -452,42 +458,6 @@ const View = ({ content, ...props }) => {
delete filtersMeta[key];
}
});
filtersMeta['facility_types'] = {
filteringInputs: [
{
id: _uniqueId('select_'),
type: 'select',
position: 0,
},
],
placeholder: 'Select facility type',
queryToSet: 'facilityTypes',
title: 'Facility type',
static: true,
options: [
{ key: null, value: null, text: 'No value' },
{
key: 'EPRTR',
value: 'EPRTR',
text: 'EPRTR',
},
{
key: 'NONEPRTR',
value: 'NONEPRTR',
text: 'NONEPRTR',
},
{
key: 'EPRTR, NONEPRTR',
value: 'EPRTR, NONEPRTR',
text: 'EPRTR, NONEPRTR',
},
{
key: 'NONEPRTR, EPRTR',
value: 'NONEPRTR, EPRTR',
text: 'NONEPRTR, EPRTR',
},
],
};
response.forEach((res, index) => {
const results = JSON.parse(res.request.response).results;
let filteringInputs = [];
Expand Down Expand Up @@ -1224,6 +1194,34 @@ const View = ({ content, ...props }) => {
</div>
);

const setCheckboxValue = (_, data) => {
let values = props.discodata_query.search[data.name] || [];
const checked = data.checked;
const index = values.indexOf(data.label);
if (checked && index === -1) {
values.push(data.label);
}
if (!checked && index !== -1) {
values.splice(index, 1);
}
props.setQueryParam({
queryParam: {
[data.name]: values,
locationTerm: null,
siteTerm: null,
advancedFiltering: true,
filtersCounter: props.discodata_query.search['filtersCounter']
? props.discodata_query.search['filtersCounter'] + 1
: 1,
},
});
setSearchTerm('');
};

const isChecked = (name, label) => {
return (props.discodata_query.search[name] || []).indexOf(label) !== -1;
};

if (!__CLIENT__) return '';
return (
<div className="filters-container">
Expand Down Expand Up @@ -1566,6 +1564,25 @@ const View = ({ content, ...props }) => {
/>
</form>
</div>

<Header as="h3">Facility type</Header>
<div className="input-container">
<form autoComplete="facilityTypes">
<Checkbox
name="facilityTypes"
label="EPRTR"
style={{ marginRight: '1rem' }}
checked={isChecked('facilityTypes', 'EPRTR')}
onChange={setCheckboxValue}
/>
<Checkbox
name="facilityTypes"
label="NONEPRTR"
checked={isChecked('facilityTypes', 'NONEPRTR')}
onChange={setCheckboxValue}
/>
</form>
</div>
</div>
<div className="dynamic-filter-actions">
<button
Expand Down
Loading

0 comments on commit 64ce512

Please sign in to comment.