forked from unicef-drp/GeoSight-OS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Context Layer type based on related table (unicef-drp#257)
* Context Layer based on related table Related Field on general context layer form WIP Filter related table data Clean django code Clean django code Clean django code Clean django code Clean django code * Fix autoformat changes * Rename fields
- Loading branch information
Showing
13 changed files
with
521 additions
and
60 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
django_project/frontend/src/pages/Admin/ContextLayer/Form/RelatedTableFields.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* GeoSight is UNICEF's geospatial web-based business intelligence platform. | ||
* | ||
* Contact : [email protected] | ||
* | ||
* .. 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__ = '[email protected]' | ||
* __date__ = '20/03/2024' | ||
* __copyright__ = ('Copyright 2024, Unicef') | ||
*/ | ||
|
||
import React, { Fragment, useEffect, useState } from 'react'; | ||
|
||
|
||
import { SelectWithSearch } from "../../../../components/Input/SelectWithSearch"; | ||
import WhereInputModal from "../../../../components/SqlQueryGenerator/WhereInputModal"; | ||
import { getRelatedTableFields } from "../../../../utils/relatedTable"; | ||
import { fetchingData } from "../../../../Requests"; | ||
import { dictDeepCopy } from "../../../../utils/main"; | ||
|
||
|
||
/** | ||
* Indicator Form App | ||
* @param {dict} data Data of context layer. | ||
* @param {boolean} checkConfig Checking config. | ||
*/ | ||
export default function RelatedTableFields( | ||
{ | ||
data, | ||
onSetData | ||
} | ||
) { | ||
const [relatedTableInfo, setRelatedTableInfo] = useState(null) | ||
const [relatedTableData, setRelatedTableData] = useState(null) | ||
|
||
// Loading data | ||
useEffect(() => { | ||
if (!open) { | ||
return | ||
} | ||
if (data.related_table) { | ||
const params = {} | ||
const url_info = `/api/related-table/${data.related_table}` | ||
const url_data = `/api/related-table/${data.related_table}/data` | ||
setRelatedTableInfo(null) | ||
setRelatedTableData(null) | ||
fetchingData( | ||
url_data, params, {}, function (response, error) { | ||
setRelatedTableData(dictDeepCopy(response)) | ||
} | ||
) | ||
fetchingData( | ||
url_info, params, {}, function (response, error) { | ||
setRelatedTableInfo(dictDeepCopy(response)) | ||
} | ||
) | ||
} | ||
}, [data.related_table]) | ||
|
||
const relatedFields = relatedTableInfo && relatedTableData ? getRelatedTableFields(relatedTableInfo, relatedTableData) : [] | ||
return ( | ||
<div> | ||
<div className='BasicFormSection'> | ||
<div className='form-label'>Latitude Field</div> | ||
<div className='InputInLine'> | ||
<SelectWithSearch | ||
value={data.latitude_field} | ||
onChangeFn={evt => { | ||
onSetData({ ...data, latitude_field: evt }) | ||
}} | ||
options={relatedFields.filter(rf => rf.type === 'number').map(rf => rf.name)} | ||
className='FilterInput' /> | ||
</div> | ||
</div> | ||
<div className='BasicFormSection'> | ||
<div className='form-label'>Longitude Field</div> | ||
<div className='InputInLine'> | ||
<SelectWithSearch | ||
value={data.longitude_field} | ||
onChangeFn={evt => { | ||
onSetData({ ...data, longitude_field: evt }) | ||
}} | ||
options={relatedFields.filter(rf => rf.type === 'number').map(rf => rf.name)} | ||
className='FilterInput' /> | ||
</div> | ||
</div> | ||
<div className='BasicFormSection'> | ||
<div className='form-label'>Datetime field</div> | ||
<div className='InputInLine'> | ||
<SelectWithSearch | ||
value={data.datetime_field} | ||
onChangeFn={evt => { | ||
onSetData({ ...data, datetime_field: evt }) | ||
}} | ||
options={relatedFields.filter(rf => rf.type === 'date').map(rf => rf.name)} | ||
className='FilterInput' /> | ||
</div> | ||
</div> | ||
|
||
<WhereInputModal | ||
value={data.query ? data.query : ''} | ||
fields={relatedFields} | ||
setValue={evt => { | ||
onSetData({ ...data, query: evt }) | ||
}} | ||
title={"Filter the Data"} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
django_project/frontend/src/pages/Admin/ContextLayer/StyleConfig/layerStyles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* GeoSight is UNICEF's geospatial web-based business intelligence platform. | ||
* | ||
* Contact : [email protected] | ||
* | ||
* .. 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__ = '[email protected]' | ||
* __date__ = '27/03/2024' | ||
* __copyright__ = ('Copyright 2024, Unicef') | ||
*/ | ||
|
||
export const defaultVectorTyleStyle = [ | ||
{ | ||
id: "country-line", | ||
type: "line", | ||
source: "source", | ||
"source-layer": "countries", | ||
filter: [ | ||
"==", | ||
"$type", | ||
"Polygon" | ||
], | ||
paint: { | ||
"line-width": 1, | ||
"line-color": "#AAAAAA" | ||
} | ||
}, | ||
{ | ||
id: "country-fill", | ||
type: "fill", | ||
source: "source", | ||
"source-layer": "countries", | ||
filter: [ | ||
"==", | ||
"$type", | ||
"Polygon" | ||
], | ||
paint: { | ||
"fill-opacity": 0 | ||
} | ||
} | ||
]; | ||
|
||
export const defaultPointStyle = [{ | ||
id: 'pointLayer', | ||
type: 'circle', | ||
source: 'source', | ||
paint: { | ||
'circle-color': '#ff7800', | ||
'circle-opacity': 0.6 | ||
}, | ||
'filter': ['==', '$type', 'Point'] | ||
}]; |
Oops, something went wrong.