diff --git a/django_project/_commit_hash.txt b/django_project/_commit_hash.txt index 9052858ed..87024ad5f 100644 --- a/django_project/_commit_hash.txt +++ b/django_project/_commit_hash.txt @@ -1 +1 @@ -158730d76e51290ce01ac8d3c45d299d961bbae2 \ No newline at end of file +e4cef959b65e8c7832b1eaf412a568de153b67b5 \ No newline at end of file diff --git a/django_project/_version.txt b/django_project/_version.txt index 10bf840ed..f93ea0ca3 100644 --- a/django_project/_version.txt +++ b/django_project/_version.txt @@ -1 +1 @@ -2.0.1 \ No newline at end of file +2.0.2 \ No newline at end of file diff --git a/django_project/frontend/src/components/Widget/Summary/Editor.jsx b/django_project/frontend/src/components/Widget/Summary/Editor.jsx index b931e578a..4aa571876 100644 --- a/django_project/frontend/src/components/Widget/Summary/Editor.jsx +++ b/django_project/frontend/src/components/Widget/Summary/Editor.jsx @@ -139,7 +139,11 @@ export default function WidgetEditor( }) const indicatorLayerList = indicatorLayersLikeIndicator(indicatorLayers).map(function (indicator) { return [indicator.id, indicator.name] - }) + }).concat( + indicatorLayers.filter(layer => layer.indicators.length === 1).map(function (indicator) { + return [indicator.id, indicator.name] + }) + ) let selectedData = { diff --git a/django_project/frontend/src/components/Widget/Summary/SummaryGroupWidget/index.jsx b/django_project/frontend/src/components/Widget/Summary/SummaryGroupWidget/index.jsx index bfd12a52d..43e2bcf0b 100644 --- a/django_project/frontend/src/components/Widget/Summary/SummaryGroupWidget/index.jsx +++ b/django_project/frontend/src/components/Widget/Summary/SummaryGroupWidget/index.jsx @@ -46,7 +46,7 @@ export default function Index( * @returns {JSX.Element} */ function getValue() { - if (data !== null) { + if (data !== null && geometries) { switch (operation) { case DEFINITION.WidgetOperation.SUM: let maxValue = 0; diff --git a/django_project/frontend/src/components/Widget/Summary/View.jsx b/django_project/frontend/src/components/Widget/Summary/View.jsx index 67e5c7c10..d13cd966b 100644 --- a/django_project/frontend/src/components/Widget/Summary/View.jsx +++ b/django_project/frontend/src/components/Widget/Summary/View.jsx @@ -31,9 +31,11 @@ import SummaryWidget from "./SummaryWidget" import SummaryGroupWidget from "./SummaryGroupWidget" import { dynamicLayerIndicatorList, - fetchDynamicLayerData + fetchDynamicLayerData, + isIndicatorLayerLikeIndicator } from "../../../utils/indicatorLayer"; import { Session } from "../../../utils/Sessions"; +import { UpdateStyleData } from "../../../utils/indicatorData"; /** * Base widget that handler widget rendering. @@ -69,6 +71,43 @@ export default function SummaryWidgetView({ idx, data }) { } }, [indicatorLayerData]) + const fetchIndicatorData = async (indicator, params, session, config) => { + if (indicator) { + await fetchingData( + indicator.url, params, {}, function (response, error) { + let newState = { + fetching: false, + fetched: true, + receivedAt: Date.now(), + data: null, + error: null + }; + + if (error) { + newState.error = error; + } else { + newState.data = UpdateStyleData(response, config.override_style ? config : indicator); + } + if (!session.isValid) { + return + } + setLayerData(newState); + } + ) + } else { + if (!session.isValid) { + return + } + setLayerData({ + fetching: false, + fetched: true, + receivedAt: Date.now(), + data: null, + error: 'Indicator does not found, please reconfig the widget.' + }); + } + } + // Fetch the data if it is using no filter or custom useEffect(() => { ( @@ -107,46 +146,20 @@ export default function SummaryWidgetView({ idx, data }) { const indicator = indicators.find((layer) => { return layer.id === layer_id; }) - if (indicator) { - await fetchingData( - indicator.url, params, {}, function (response, error) { - let newState = { - fetching: false, - fetched: true, - receivedAt: Date.now(), - data: null, - error: null - }; - - if (error) { - newState.error = error; - } else { - newState.data = response; - } - if (!session.isValid) { - return - } - setLayerData(newState); - } - ) - } else { - if (!session.isValid) { - return - } - setLayerData({ - fetching: false, - fetched: true, - receivedAt: Date.now(), - data: null, - error: 'Indicator does not found, please reconfig the widget.' - }); - } + await fetchIndicatorData(indicator, params, session, indicator) break; // This is for indicator layer case definition.WidgetLayerUsed.INDICATOR_LAYER: const indicatorLayer = indicatorLayers.find((layer) => { return layer.id === layer_id; }) + if (!isIndicatorLayerLikeIndicator(indicatorLayer)) { + const indicator = indicators.find((indicator) => { + return indicator.id === indicatorLayer.indicators[0].id; + }) + await fetchIndicatorData(indicator, params, session, indicatorLayer) + return; + } const dynamicLayerIndicators = dynamicLayerIndicatorList(indicatorLayer, indicators) const indicatorsData = {} for (let x = 0; x < dynamicLayerIndicators.length; x++) { @@ -183,7 +196,8 @@ export default function SummaryWidgetView({ idx, data }) { data: null, error: error }); - }, response => { + }, + response => { if (!session.isValid) { return } @@ -194,7 +208,7 @@ export default function SummaryWidgetView({ idx, data }) { data: response, error: null }); - } + }, false, true ) } } @@ -230,7 +244,6 @@ export default function SummaryWidgetView({ idx, data }) { layers = indicatorLayers break; } - // render widget by the type switch (type) { case DEFINITION.WidgetType.SUMMARY_WIDGET: diff --git a/django_project/frontend/src/components/Widget/style.scss b/django_project/frontend/src/components/Widget/style.scss index 8fa426915..af434309d 100644 --- a/django_project/frontend/src/components/Widget/style.scss +++ b/django_project/frontend/src/components/Widget/style.scss @@ -101,7 +101,7 @@ text-align: left; .widget__sw__title, - .widget__gw__title{ + .widget__gw__title { color: $widget-title; font-size: 1rem; margin-bottom: 10px; @@ -132,6 +132,7 @@ .widget__sgw__row__name { width: 1%; + white-space: nowrap; } .widget__sgw__row { diff --git a/django_project/frontend/src/pages/Admin/Components/AdminForm/PermissionFormAdmin.jsx b/django_project/frontend/src/pages/Admin/Components/AdminForm/PermissionFormAdmin.jsx index 3305dba1f..ed703b740 100644 --- a/django_project/frontend/src/pages/Admin/Components/AdminForm/PermissionFormAdmin.jsx +++ b/django_project/frontend/src/pages/Admin/Components/AdminForm/PermissionFormAdmin.jsx @@ -38,6 +38,14 @@ export default function PermissionFormAdmin({ permissionApi }) { /** Fetch data when modal is opened **/ useEffect(() => { + try { + if (permissionFormData) { + setData(permissionFormData) + return + } + } catch (err) { + + } if (permissionApi) { let url = permissionApi if (selectableInput) { diff --git a/django_project/frontend/src/pages/Dashboard/MapLibre/ReferenceLayerCentroid/index.jsx b/django_project/frontend/src/pages/Dashboard/MapLibre/ReferenceLayerCentroid/index.jsx index 4cae91340..37907b11c 100644 --- a/django_project/frontend/src/pages/Dashboard/MapLibre/ReferenceLayerCentroid/index.jsx +++ b/django_project/frontend/src/pages/Dashboard/MapLibre/ReferenceLayerCentroid/index.jsx @@ -181,7 +181,7 @@ export default function ReferenceLayerCentroid({ map }) { if (!indicatorLayer.override_style && indicatorDetail) { styleConfig = indicatorDetail } - if (!labelConfig || !indicatorLayer.override_label && indicatorDetail) { + if (indicatorDetail && (!labelConfig || !indicatorLayer.override_label)) { labelConfig = indicatorDetail.label_config } } diff --git a/django_project/frontend/src/utils/indicatorLayer.jsx b/django_project/frontend/src/utils/indicatorLayer.jsx index 6af634c9d..0f51781ab 100644 --- a/django_project/frontend/src/utils/indicatorLayer.jsx +++ b/django_project/frontend/src/utils/indicatorLayer.jsx @@ -17,7 +17,7 @@ import { capitalize, dictDeepCopy } from "./main"; import nunjucks from "nunjucks"; import { extractCode } from "./georepo"; import { getRelatedTableData } from "./relatedTable"; -import { getIndicatorDataByLayer } from "./indicatorData"; +import { getIndicatorDataByLayer, UpdateStyleData } from "./indicatorData"; export const SingleIndicatorType = 'Single Indicator' export const SingleIndicatorTypes = [SingleIndicatorType, 'Float'] @@ -86,12 +86,12 @@ export function dynamicLayerData(indicatorLayer, context) { */ export function fetchDynamicLayerData( indicatorLayer, indicators, indicatorsData, geoField, - onError, onSuccess, skipAggregate + onError, onSuccess, skipAggregate, updateStyle = false ) { const dynamicLayerIndicators = dynamicLayerIndicatorList(indicatorLayer, indicators) let error = '' - const data = [] + let data = [] dynamicLayerIndicators.map(indicator => { if (indicatorsData[indicator.id]?.data) { indicatorsData[indicator.id].data.map(row => { @@ -148,6 +148,9 @@ export function fetchDynamicLayerData( value: dynamicLayerData(indicatorLayer, value) }) } + if (updateStyle) { + response = UpdateStyleData(response, indicatorLayer) + } onSuccess(response) } } diff --git a/django_project/frontend/templates/frontend/admin/basemap/form.html b/django_project/frontend/templates/frontend/admin/basemap/form.html index 093c12e69..e45869c26 100644 --- a/django_project/frontend/templates/frontend/admin/basemap/form.html +++ b/django_project/frontend/templates/frontend/admin/basemap/form.html @@ -10,6 +10,7 @@