Skip to content

Commit 6c2073b

Browse files
authored
Fix reference dataset on selecting admin (#318)
* Show plugins status on preference admin * Fix the reference layer handler when changing * Fix detail on management form * Bump commit version
1 parent 26d8b9d commit 6c2073b

File tree

14 files changed

+112
-70
lines changed

14 files changed

+112
-70
lines changed

django_project/_commit_hash.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5ee1fe9d8fedb0c3355534241a80cf36d91fc887
1+
0b044429cb4fda6ef2939f5e8ea987f83ae429fc

django_project/core/admin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class SitePreferencesAdmin(admin.ModelAdmin):
6464
}),
6565
('Plugins', {
6666
'fields': (
67+
'cloud_native_gis_enabled',
68+
'machine_info_fetcher_enabled',
69+
'reference_dataset_enabled',
70+
'tenants_enabled',
6771
'machine_info_fetcher_config',
6872
)
6973
}),
@@ -137,7 +141,13 @@ class SitePreferencesAdmin(admin.ModelAdmin):
137141
})
138142
)
139143
inlines = (SitePreferencesImageInline,)
140-
readonly_fields = ('sentry_dsn', 'sentry_environment')
144+
readonly_fields = (
145+
'sentry_dsn', 'sentry_environment',
146+
'cloud_native_gis_enabled',
147+
'machine_info_fetcher_enabled',
148+
'reference_dataset_enabled',
149+
'tenants_enabled'
150+
)
141151

142152

143153
admin.site.register(SitePreferences, SitePreferencesAdmin)

django_project/core/models/preferences.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,29 @@ def sentry_environment(self):
375375
"""Return admin emails."""
376376
return settings.SENTRY_ENVIRONMENT
377377

378+
# -------------------------------------
379+
# FOR PLUGINS
380+
# -------------------------------------
381+
@property
382+
def cloud_native_gis_enabled(self):
383+
"""Return if CLOUD_NATIVE_GIS_ENABLED is enabled."""
384+
return settings.CLOUD_NATIVE_GIS_ENABLED
385+
386+
@property
387+
def machine_info_fetcher_enabled(self):
388+
"""Return if MACHINE_INFO_FETCHER_ENABLED is enabled."""
389+
return settings.MACHINE_INFO_FETCHER_ENABLED
390+
391+
@property
392+
def reference_dataset_enabled(self):
393+
"""Return if REFERENCE_DATASET_ENABLED is enabled."""
394+
return settings.REFERENCE_DATASET_ENABLED
395+
396+
@property
397+
def tenants_enabled(self):
398+
"""Return if TENANTS_ENABLED is enabled."""
399+
return settings.TENANTS_ENABLED
400+
378401

379402
class SitePreferencesImage(models.Model):
380403
"""Preference images settings specifically for website."""

django_project/frontend/src/pages/Admin/Components/Input/ReferenceLayerGeometrySelector.jsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
*/
1515

1616
import React, { useEffect, useState } from 'react';
17-
import {
18-
axiosGet,
19-
fetchFeatureList,
20-
GeorepoUrls
21-
} from "../../../../utils/georepo";
17+
import { axiosGet, fetchFeatureList } from "../../../../utils/georepo";
2218
import { Select } from "../../../../components/Input";
19+
import { RefererenceLayerUrls } from "../../../../utils/referenceLayer";
2320

2421
let requestTime = null
2522
/**
@@ -40,7 +37,8 @@ export default function ReferenceLayerGeometrySelector(
4037
setLevels(null)
4138
const currentDate = new Date().getTime();
4239
requestTime = currentDate;
43-
axiosGet(GeorepoUrls.ViewDetail(referenceLayer)).then(response => {
40+
const url = RefererenceLayerUrls.ViewDetail(referenceLayer)
41+
axiosGet(url).then(response => {
4442
if (requestTime === currentDate) {
4543
const data = response.data
4644
const newLevels = data.dataset_levels.map(level => {

django_project/frontend/src/pages/Admin/Components/Input/ReferenceLayerLevelConfiguration/index.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { GeorepoUrls } from "../../../../../utils/georepo";
2929
import { FormControlLabel, FormGroup } from "@mui/material";
3030
import { InternalReferenceDatasets } from "../../../../../utils/urls";
3131
import { Actions } from "../../../../../store/dashboard";
32+
import { RefererenceLayerUrls } from "../../../../../utils/referenceLayer";
3233

3334
import './styles.scss';
3435

@@ -84,10 +85,7 @@ export const ViewLevelConfiguration = forwardRef(
8485

8586
useEffect(() => {
8687
if (referenceLayer.identifier && !referenceLayerData) {
87-
let url = GeorepoUrls.ViewDetail(referenceLayer.identifier)
88-
if (referenceLayer.is_local) {
89-
url = InternalReferenceDatasets.detail(referenceLayer.identifier)
90-
}
88+
const url = RefererenceLayerUrls.ViewDetail(referenceLayer)
9189
dispatch(
9290
Actions.ReferenceLayerData.fetch(
9391
dispatch, referenceLayer.identifier, url

django_project/frontend/src/pages/Admin/Importer/Form/Extensions/FormulaBasedOnOtherIndicators/base.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export const FormulaBasedForm = forwardRef(
207207
}}
208208
>
209209
<ReferenceLayerGeometrySelector
210-
referenceLayer={data.reference_layer}
210+
referenceLayer={data}
211211
onChange={config => {
212212
setGeomConfig(config)
213213
}}

django_project/frontend/src/pages/Admin/Importer/LogDetail/index.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import {
2727
replaceWithBr
2828
} from "../../../../utils/main";
2929
import { getScheduleText } from "../../../../utils/cron";
30-
import { axiosGet, GeorepoUrls } from "../../../../utils/georepo";
30+
import { axiosGet } from "../../../../utils/georepo";
3131
import { resourceActions } from "../Logs";
32+
import { RefererenceLayerUrls } from "../../../../utils/referenceLayer";
3233

3334
import '../ImporterDetail/style.scss';
3435
import './style.scss';
@@ -82,7 +83,8 @@ export function ImporterDetailSection({ inputData }) {
8283

8384
useEffect(() => {
8485
if (data.attributes?.admin_level_type === 'Specific Level') {
85-
axiosGet(GeorepoUrls.ViewDetail(data.reference_layer)).then(response => response.data).then(response => {
86+
const url = RefererenceLayerUrls.ViewDetail(data)
87+
axiosGet(url).then(response => response.data).then(response => {
8688
const level = response.dataset_levels.find(level => level.level + '' === data.attributes?.admin_level_value + '')
8789
data.attributes.admin_level_type = level ? level.level_name : data.attributes?.admin_level_value
8890
setData({ ...data })
@@ -458,7 +460,7 @@ export default function ImporterLogDetail() {
458460
</div>
459461
<div className='DetailButtonButton'>
460462
<div className='Separator'/>
461-
<a href={urls.api.dataView+'?status=Warning and Error'}>
463+
<a href={urls.api.dataView + '?status=Warning and Error'}>
462464
<ThemeButton
463465
variant="primary">
464466
See the data

django_project/frontend/src/pages/Admin/Indicator/ValueManagementForm/index.jsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* GeoSight is UNICEF's geospatial web-based business intelligence platform.
3-
*
4-
* Contact : [email protected]
5-
*
6-
* .. note:: This program is free software; you can redistribute it and/or modify
7-
* it under the terms of the GNU Affero General Public License as published by
8-
* the Free Software Foundation; either version 3 of the License, or
9-
* (at your option) any later version.
10-
*
11-
* __author__ = '[email protected]'
12-
* __date__ = '13/06/2023'
13-
* __copyright__ = ('Copyright 2023, Unicef')
14-
*/
2+
* GeoSight is UNICEF's geospatial web-based business intelligence platform.
3+
*
4+
* Contact : [email protected]
5+
*
6+
* .. note:: This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* __author__ = '[email protected]'
12+
* __date__ = '13/06/2023'
13+
* __copyright__ = ('Copyright 2023, Unicef')
14+
*/
1515

1616
import React, { Fragment, useEffect, useRef, useState } from 'react';
1717
import $ from "jquery";
@@ -31,17 +31,14 @@ import {
3131
} from "../../../../components/Elements/Button";
3232
import { SelectWithList } from "../../../../components/Input/SelectWithList";
3333
import InputFile from './InputFile'
34-
import {
35-
axiosGet,
36-
fetchReferenceLayerList,
37-
GeorepoUrls
38-
} from '../../../../utils/georepo'
34+
import { axiosGet, fetchReferenceLayerList } from '../../../../utils/georepo'
3935
import { jsonToXlsx } from '../../../../utils/main'
4036
import { GeorepoViewInputSelector } from "../../ModalSelector/InputSelector";
4137
import {
4238
Notification,
4339
NotificationStatus
4440
} from "../../../../components/Notification";
41+
import { RefererenceLayerUrls } from "../../../../utils/referenceLayer";
4542

4643
import './style.scss';
4744

@@ -79,7 +76,7 @@ export default function ValueManagement() {
7976
}
8077

8178
const fetchData = (level, page) => {
82-
axiosGet(level.url + '?page=' + page).then(response => {
79+
axiosGet(level.url, { page: page }).then(response => {
8380
const data = response.data
8481
if (!level.layer) {
8582
level.layer = []
@@ -106,7 +103,8 @@ export default function ValueManagement() {
106103
return
107104
}
108105
if (!referenceLayer.data) {
109-
axiosGet(GeorepoUrls.ViewDetail(reference.identifier)).then(response => {
106+
const url = RefererenceLayerUrls.ViewDetail(referenceLayer)
107+
axiosGet(url).then(response => {
110108
const data = response.data
111109
referenceLayer.data = data.dataset_levels.map(level => {
112110
level.value = level.level

django_project/frontend/src/pages/Admin/Indicator/ValueManagementMap/Map.jsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* GeoSight is UNICEF's geospatial web-based business intelligence platform.
3-
*
4-
* Contact : [email protected]
5-
*
6-
* .. note:: This program is free software; you can redistribute it and/or modify
7-
* it under the terms of the GNU Affero General Public License as published by
8-
* the Free Software Foundation; either version 3 of the License, or
9-
* (at your option) any later version.
10-
*
11-
* __author__ = '[email protected]'
12-
* __date__ = '13/06/2023'
13-
* __copyright__ = ('Copyright 2023, Unicef')
14-
*/
2+
* GeoSight is UNICEF's geospatial web-based business intelligence platform.
3+
*
4+
* Contact : [email protected]
5+
*
6+
* .. note:: This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* __author__ = '[email protected]'
12+
* __date__ = '13/06/2023'
13+
* __copyright__ = ('Copyright 2023, Unicef')
14+
*/
1515

1616
/* ==========================================================================
1717
MAP CONFIG CONTAINER
@@ -22,8 +22,9 @@ import $ from 'jquery';
2222
import L from 'leaflet';
2323

2424
import { SelectWithList } from "../../../../components/Input/SelectWithList";
25-
import { axiosGet, fetchGeojson, GeorepoUrls } from '../../../../utils/georepo'
25+
import { axiosGet, fetchGeojson } from '../../../../utils/georepo'
2626
import { GeorepoViewInputSelector } from "../../ModalSelector/InputSelector";
27+
import { RefererenceLayerUrls } from "../../../../utils/referenceLayer";
2728

2829
/**
2930
* Map component.
@@ -240,7 +241,8 @@ export default function Map() {
240241
return
241242
}
242243
if (!referenceLayer.data) {
243-
axiosGet(GeorepoUrls.ViewDetail(reference.identifier)).then(response => {
244+
const url = RefererenceLayerUrls.ViewDetail(referenceLayer)
245+
axiosGet(url).then(response => {
244246
const data = response.data
245247
referenceLayer.data = data.dataset_levels.map(level => {
246248
level.value = level.level

django_project/frontend/src/pages/Dashboard/MapLibre/Controllers/DatasetGeometryData.jsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ import { useEffect } from "react";
2222
import { datasetListFromDashboardData } from "../../../../utils/geometry";
2323
import { dictDeepCopy } from "../../../../utils/main";
2424
import { Actions } from "../../../../store/dashboard";
25-
import {
26-
axiosGet,
27-
extractCode,
28-
GeorepoUrls,
29-
headers
30-
} from "../../../../utils/georepo";
25+
import { axiosGet, extractCode, headers } from "../../../../utils/georepo";
3126
import { apiReceive } from "../../../../store/reducers_api";
3227
import { fetchJSON } from "../../../../Requests";
3328
import { InternalReferenceDatasets } from "../../../../utils/urls";
29+
import { RefererenceLayerUrls } from "../../../../utils/referenceLayer";
3430

3531
/**
3632
* Handling geometry data.
@@ -54,17 +50,15 @@ export default function DatasetGeometryData() {
5450

5551
const referenceLayerData = dictDeepCopy(referenceLayerDataState)
5652
for (let i = 0; i < datasets.length; i++) {
57-
const identifier = datasets[i].identifier
53+
const referenceLayer = datasets[i]
54+
const identifier = referenceLayer.identifier
5855
if (!referenceLayerData[identifier]) {
5956
dispatch(
6057
Actions.ReferenceLayerData.request(identifier)
6158
)
6259

6360
// Fetch the data
64-
let url = GeorepoUrls.ViewDetail(identifier)
65-
if (datasets[i].is_local) {
66-
url = InternalReferenceDatasets.detail(identifier)
67-
}
61+
const url = RefererenceLayerUrls.ViewDetail(referenceLayer)
6862
await axiosGet(url).then(response => {
6963
referenceLayerData[identifier] = apiReceive({
7064
data: response.data,

0 commit comments

Comments
 (0)