diff --git a/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx b/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx index adb709b0c..86f5be0f2 100644 --- a/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx +++ b/django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx @@ -14,6 +14,7 @@ */ import React, { Fragment, useEffect, useState } from 'react'; +import $ from 'jquery'; import { SelectWithSearch } from "../../../../components/Input/SelectWithSearch"; @@ -21,7 +22,9 @@ import WhereInputModal from "../../../../components/SqlQueryGenerator/WhereInput import { getRelatedTableFields } from "../../../../utils/relatedTable"; import { fetchingData } from "../../../../Requests"; import { dictDeepCopy } from "../../../../utils/main"; - +import { + RelatedTableInputSelector +} from "../../ModalSelector/InputSelector"; /** * Indicator Form App @@ -62,8 +65,45 @@ export default function RelatedTableFields( }, [data.related_table]) const relatedFields = relatedTableInfo && relatedTableData ? getRelatedTableFields(relatedTableInfo, relatedTableData) : [] + + useEffect(() => { + if (relatedFields && !data.data_fields) { + onSetData({ + ...data, + data_fields: relatedFields.map(field => ({ + alias: field.alias, + defaultValue: null, + domain: null, + editable: false, + name: field.name, + nullable: false, + sqlType: "sqlTypeOther", + type: field.type + })) + }) + } + }, [relatedFields]) + + const handleRelatedTableChange = newRelatedTable => { + onSetData({ ...data, related_table: newRelatedTable[0]?.id }) + setRelatedTableInfo(newRelatedTable[0]) + } + return (
+
+
+ +
+ +
Latitude Field
diff --git a/django_project/frontend/src/pages/Admin/ContextLayer/Form/index.jsx b/django_project/frontend/src/pages/Admin/ContextLayer/Form/index.jsx index d1bb580b5..2e6266b4f 100644 --- a/django_project/frontend/src/pages/Admin/ContextLayer/Form/index.jsx +++ b/django_project/frontend/src/pages/Admin/ContextLayer/Form/index.jsx @@ -31,7 +31,6 @@ import { dictDeepCopy } from "../../../../utils/main"; import './style.scss'; let currentArcGis = null -let currentRelatedTable = null let init = false /** * Context Layer Form App @@ -89,6 +88,7 @@ export default function ContextLayerForm() { $('*[name="label_styles"]').val(JSON.stringify(newData['label_styles'])) $('*[name="data_fields"]').val(JSON.stringify(newData['data_fields'])) $('*[name="styles"]').val(JSON.stringify(newData['styles'])) + $('*[name="related_table"]').val(newData['related_table']) $('*[name="latitude_field"]').val(newData['latitude_field']) $('*[name="longitude_field"]').val(newData['longitude_field']) $('*[name="query"]').val(newData['query']) @@ -99,18 +99,15 @@ export default function ContextLayerForm() { const typeChange = (value) => { if (value === 'ARCGIS') { $('div[data-wrapper-name="arcgis_config"]').show() - $('div[data-wrapper-name="related_table"]').hide() } else if (value === 'Related Table') { $('div[data-wrapper-name="arcgis_config"]').hide() $('div[data-wrapper-name="token"]').hide() $('div[data-wrapper-name="username"]').hide() $('div[data-wrapper-name="password"]').hide() $('div[data-wrapper-name="url"]').hide() - $('div[data-wrapper-name="related_table"]').show() } else { $('div[data-wrapper-name="arcgis_config"]').hide() - $('div[data-wrapper-name="related_table"]').hide() $('div[data-wrapper-name="url"]').show() } setData({ ...data, layer_type: value }) @@ -134,15 +131,6 @@ export default function ContextLayerForm() { } } - const relatedTableConfigChange = (value) => { - currentRelatedTable = value - if (value) { - setData({ - ...data, - related_table: value - }) - } - } return ( diff --git a/django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/RelatedTable/index.jsx b/django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/RelatedTable/index.jsx new file mode 100644 index 000000000..3f8edf34d --- /dev/null +++ b/django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/RelatedTable/index.jsx @@ -0,0 +1,78 @@ +/** + * GeoSight is UNICEF's geospatial web-based business intelligence platform. + * + * Contact : geosight-no-reply@unicef.org + * + * .. note:: This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * __author__ = 'fpsampayo@geomatico.es' + * __date__ = '12/04/2024' + * __copyright__ = ('Copyright 2024, Unicef') + */ + +/* ========================================================================== + ARCGIS STYLE + ========================================================================== */ + +import React, { Fragment } from 'react'; +import { Checkbox, FormControlLabel, FormGroup } from "@mui/material"; + +import FieldConfig from "../../../../../components/FieldConfig"; + +/** + * Map Config component. + */ +export default function RelatedTableConfig( + { + originalData, + setData, + RelatedTableData, + useOverride = false, + useOverrideLabel = true + } +) { + const data = JSON.parse(JSON.stringify(originalData)) + + const update = () => { + setData({ ...data }) + } + return +
+ { + useOverride ? + + { + setData({ + ...data, + data_fields: RelatedTableData?.data?.fields, + override_field: evt.target.checked + }) + }} /> + } + label="Override field config from default" /> + : null + } + { + (!useOverride || data.override_field) ? + data.data_fields ? + +
+ { + data.data_fields = fields + update() + }} /> +
+
:
Loading
: null + } +
+
+} diff --git a/django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/index.jsx b/django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/index.jsx index 3fae605b5..1c80be4c0 100644 --- a/django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/index.jsx +++ b/django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/index.jsx @@ -21,6 +21,7 @@ import { getLayer } from '../../../Dashboard/LeftPanel/ContextLayers/Layer' import { defaultPointStyle, defaultVectorTyleStyle } from './layerStyles'; import './style.scss'; +import RelatedTableConfig from './RelatedTable'; /** @@ -195,6 +196,11 @@ export default function StyleConfig( originalData={data} setData={setData} ArcgisData={layerData} useOverride={useOverride} useOverrideLabel={useOverrideLabel} + /> : data.layer_type === 'Related Table' ? + :
diff --git a/django_project/frontend/src/pages/Admin/ModalSelector/RelatedTable.jsx b/django_project/frontend/src/pages/Admin/ModalSelector/RelatedTable.jsx index d3ffbf573..1e11d875f 100644 --- a/django_project/frontend/src/pages/Admin/ModalSelector/RelatedTable.jsx +++ b/django_project/frontend/src/pages/Admin/ModalSelector/RelatedTable.jsx @@ -38,7 +38,7 @@ export default function RelatedTableSelector( ) { return { return popupFeature( - featureProperties, contextLayerData.name, null, Object.keys(featureProperties).map(property => { - return { - name: property, - alias: property, - } - }) + featureProperties, + contextLayerData.name, + null, + contextLayerData.data_fields ) }, contextLayerOrder ) diff --git a/django_project/geosight/data/forms/context_layer.py b/django_project/geosight/data/forms/context_layer.py index d20de053b..d466afb80 100644 --- a/django_project/geosight/data/forms/context_layer.py +++ b/django_project/geosight/data/forms/context_layer.py @@ -20,6 +20,7 @@ from django.forms.models import model_to_dict from geosight.data.models.context_layer import ContextLayer, ContextLayerGroup +from geosight.data.models.related_table import RelatedTable class ContextLayerForm(forms.ModelForm): @@ -67,6 +68,11 @@ class ContextLayerForm(forms.ModelForm): widget=forms.HiddenInput() ) + related_table = forms.CharField( + label='Related Table', + widget=forms.HiddenInput() + ) + def __init__(self, *args, **kwargs): """Init.""" super().__init__(*args, **kwargs) @@ -89,6 +95,12 @@ def clean_group(self): name=self.cleaned_data['group'] ) return group + + def clean_related_table(self): + """Return related table.""" + if self.instance and self.cleaned_data['related_table']: + return RelatedTable.objects.get(pk=self.cleaned_data['related_table']) + return None def clean_styles(self): """Return styles."""