diff --git a/uvdat/core/rest/project.py b/uvdat/core/rest/project.py index 96de476b..f4479036 100644 --- a/uvdat/core/rest/project.py +++ b/uvdat/core/rest/project.py @@ -1,8 +1,8 @@ from django.contrib.auth.models import User from django.http import HttpResponse from rest_framework.decorators import action -from rest_framework.viewsets import ModelViewSet from rest_framework.response import Response +from rest_framework.viewsets import ModelViewSet from uvdat.core.models import Dataset, Project from uvdat.core.rest.access_control import GuardianFilter, GuardianPermission @@ -24,17 +24,17 @@ def perform_create(self, serializer): def partial_update(self, request, id): project = self.get_object() - project.datasets.set( - Dataset.objects.filter( - id__in=request.data.get('dataset_ids') - ) - ) + dataset_ids = request.data.pop('dataset_ids', None) + if dataset_ids is not None: + project.datasets.set(Dataset.objects.filter(id__in=dataset_ids)) + serializer = ProjectSerializer(project, data=request.data, partial=True) + if serializer.is_valid(): + serializer.save() project.save() response = ProjectSerializer(project).data - response.update(datasets=[ - DatasetSerializer(dataset).data - for dataset in project.datasets.all() - ]) + response.update( + datasets=[DatasetSerializer(dataset).data for dataset in project.datasets.all()] + ) return Response(response, status=200) @action(detail=True, methods=['get']) diff --git a/uvdat/core/rest/serializers.py b/uvdat/core/rest/serializers.py index 9d1d0aea..55668815 100644 --- a/uvdat/core/rest/serializers.py +++ b/uvdat/core/rest/serializers.py @@ -58,7 +58,7 @@ def to_internal_value(self, data): center = data.get('default_map_center') data = super().to_internal_value(data) if isinstance(center, list): - data['default_map_center'] = Point(center[1], center[0]) + data['default_map_center'] = Point(*center) return data class Meta: diff --git a/web/src/api/auth.js b/web/src/api/auth.js index 2c15abb6..9031b0c5 100644 --- a/web/src/api/auth.js +++ b/web/src/api/auth.js @@ -61,5 +61,5 @@ export const logout = async () => { currentUser.value = undefined; currentProject.value = undefined; clearState(); - setMapCenter(); + setMapCenter(undefined); }; diff --git a/web/src/api/rest.ts b/web/src/api/rest.ts index f7c7fb5a..f38eb42e 100644 --- a/web/src/api/rest.ts +++ b/web/src/api/rest.ts @@ -39,7 +39,7 @@ export async function patchProject( projectId: number, data: object ): Promise { - return await apiClient.patch(`projects/${projectId}/`, data); + return (await apiClient.patch(`projects/${projectId}/`, data)).data; } export async function deleteProject(projectId: number): Promise { @@ -52,17 +52,6 @@ export async function getProjectDatasets( return (await apiClient.get(`datasets?project=${projectId}`)).data.results; } -export async function setProjectDatasets( - projectId: number, - datasetIds: number[] -): Promise { - return ( - await apiClient.patch(`projects/${projectId}/`, { - dataset_ids: datasetIds, - }) - ).data; -} - export async function getProjectCharts(projectId: number): Promise { return (await apiClient.get(`charts?project=${projectId}`)).data.results; } diff --git a/web/src/components/DatasetList.vue b/web/src/components/DatasetList.vue index b2d783dc..38a8f5b8 100644 --- a/web/src/components/DatasetList.vue +++ b/web/src/components/DatasetList.vue @@ -282,6 +282,9 @@ export default { diff --git a/web/src/components/ProjectConfig.vue b/web/src/components/ProjectConfig.vue index 0d038a2b..f21f1235 100644 --- a/web/src/components/ProjectConfig.vue +++ b/web/src/components/ProjectConfig.vue @@ -1,14 +1,22 @@