Skip to content

Commit

Permalink
GeoContext keys management (#4319)
Browse files Browse the repository at this point in the history
* GeoContext keys management

* Add select native layers

* Keep location context group name
  • Loading branch information
dimasciput authored Oct 22, 2024
1 parent 50373a6 commit 2624b70
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 14 deletions.
10 changes: 9 additions & 1 deletion bims/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
IsHarvestingGeocontext, HarvestGeocontextView, ClearHarvestingGeocontextCache,
GetGeocontextLogLinesView
)
from bims.api_views.layers import CloudNativeLayerList
from bims.api_views.minisass_observations import MiniSASSObservationsView
from bims.api_views.invasions import InvasionsList
from bims.api_views.taxon_update import UpdateTaxon, ReviewTaxonProposal
Expand Down Expand Up @@ -64,7 +65,8 @@
from bims.api_views.hide_popup_info_user import HidePopupInfoUser
from bims.api_views.send_notification_to_validator import \
SendNotificationValidation
from bims.views.context_layers import ContextLayerGroup, CloudNativeLayerAutoCompleteAPI, ContextFilter
from bims.views.context_layers import ContextLayerGroup, CloudNativeLayerAutoCompleteAPI, ContextFilter, \
ContextLayerKeys
from bims.views.locate import filter_farm_ids_view, get_farm_view
from bims.api_views.user_boundary import (
UserBoundaryList,
Expand Down Expand Up @@ -400,4 +402,10 @@
path('cloud-native-layer-autocomplete/',
CloudNativeLayerAutoCompleteAPI.as_view(),
name='cloud-native-layer-autocomplete'),
path('context-layer-keys/',
ContextLayerKeys.as_view(),
name='context-layer-keys'),
path('cloud-native-layers/',
CloudNativeLayerList.as_view(),
name='cloud-native-layers'),
]
37 changes: 37 additions & 0 deletions bims/api_views/layers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json

from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.views import APIView

from cloud_native_gis.models import Layer


class CloudNativeLayerSerializer(serializers.ModelSerializer):

attributes = serializers.SerializerMethodField()

def get_attributes(self, obj: Layer):
return obj.attribute_names

class Meta:
model = Layer
fields = [
'id', 'unique_id',
'name', 'abstract',
'attributes', 'default_style'
]


class CloudNativeLayerList(APIView):
"""API for listing all cloud native layers."""

def get(self, request, *args):
layers = Layer.objects.all()
layers_data = CloudNativeLayerSerializer(
layers,
many=True
).data
return Response(
layers_data
)
22 changes: 16 additions & 6 deletions bims/models/location_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,23 @@ def add_context_group(self, group_key):
coordinates=[(self.longitude, self.latitude)],
tolerance=10
)
context_group, _ = LocationContextGroup.objects.update_or_create(
geocontext_group_key=group_key,
key=group_key,
defaults={
'name': layer.name
}
# Find by name first
context_groups = LocationContextGroup.objects.filter(
name=layer.name
)
if context_groups.exists():
context_groups.update(
geocontext_group_key=group_key,
key=group_key)
context_group = context_groups.first()
else:
context_group, _ = LocationContextGroup.objects.get_or_create(
geocontext_group_key=group_key,
key=group_key,
defaults={
'name': layer.name
}
)
for result in feature_data['result']:
if context_key in result['feature']:
LocationContext.objects.update_or_create(
Expand Down
2 changes: 1 addition & 1 deletion bims/static/react/js/ContextLayersView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ContextFilterView from "./components/ContextFilterView";

const ContextLayersView = (props) => {
return (
<ContextFilterView csrfToken={props.csrfToken}/>
<ContextFilterView csrfToken={props.csrfToken} geocontextUrl={props.geocontexturl}/>
)
}

Expand Down
21 changes: 19 additions & 2 deletions bims/static/react/js/components/ContextFilterView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { arrayMoveImmutable } from "array-move";
import "bootstrap-icons/font/bootstrap-icons.css";
import {Button, Form, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader} from "reactstrap";
import AddContextGroup from "./AddContextGroup";
import GeocontextListModal from "./GeocontextListModal";


const ContextFilterView = (props) => {
Expand All @@ -20,6 +21,7 @@ const ContextFilterView = (props) => {
const [isAddNewFilterModalOpen, setIsAddNewFilterModalOpen] = useState(false);
const [newFilterName, setNewFilterName] = useState('');
const [savingNewFilter, setSavingNewFilter] = useState(false);
const [isGeocontextListOpen, setIsGeocontextListOpen] = useState(false);

const contextLayerFilterAPI = '/api/context-filter/';
const contextLayerGroupAPI = '/api/context-layer-group/';
Expand Down Expand Up @@ -185,6 +187,10 @@ const ContextFilterView = (props) => {
setIsAddNewFilterModalOpen(!isAddNewFilterModalOpen)
}

const toggleGeocontextListModal = () => {
setIsGeocontextListOpen(!isGeocontextListOpen);
}

const handleAddNewGroup = (e, contextFilter) => {
e.stopPropagation();
toggleAddNewGropModal();
Expand All @@ -196,10 +202,17 @@ const ContextFilterView = (props) => {

const handleDeleteFilter = (e, contextFilter) => {
e.stopPropagation();
deleteContextFilter(contextFilter.id);
const isConfirmed = window.confirm(`Are you sure you want to delete "${contextFilter.title}"?`);
if (isConfirmed) {
deleteContextFilter(contextFilter.id);
}
}

const handleRemoveGroup = (filter, group) => {
const isConfirmed = window.confirm(`Are you sure you want to delete "${group.group.name}"?`);
if (!isConfirmed) {
return;
}
let groupId = group.group.id;
const updatedGroups = {
[filter.id]: filter.location_context_groups.map((group, index) => ({
Expand Down Expand Up @@ -230,10 +243,13 @@ const ContextFilterView = (props) => {
className="form-control mb-2"
/>
</div>
<div>
<div style={{ width: '100%' }}>
<Button color={'success'} size={'sm'} style={{ marginBottom: 5 }} onClick={toggleAddNewFilterModal}>
<i className="bi bi-plus"></i> Add new filter section
</Button>
<Button color='warning' size={'sm'} style={{ marginBottom: 5, float: 'right' }} onClick={toggleGeocontextListModal}>
<i className="bi bi-list"></i> GeoContext keys
</Button>
</div>
<div className="row">
<SortableList onSortEnd={onSortParent} className='context-filter-list col-md-12' draggedItemClassName={'dragged'}>
Expand Down Expand Up @@ -318,6 +334,7 @@ const ContextFilterView = (props) => {
</ModalFooter>
</Modal>

<GeocontextListModal toggle={toggleGeocontextListModal} isOpen={isGeocontextListOpen} csrfToken={props.csrfToken} geocontextUrl={props.geocontextUrl}/>
</div>
);
}
Expand Down
Loading

0 comments on commit 2624b70

Please sign in to comment.