From 806bb296419278d2a15b2a6980491b3391f399f6 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Thu, 19 Sep 2024 20:34:50 +0000 Subject: [PATCH] feat: create/delete projects, edit project names and default map positions --- uvdat/core/rest/project.py | 13 +- uvdat/core/rest/serializers.py | 2 +- web/src/api/auth.js | 4 +- web/src/api/rest.ts | 13 +- web/src/components/DatasetList.vue | 3 + web/src/components/MainDrawerContents.vue | 73 +++++- web/src/components/ProjectConfig.vue | 273 ++++++++++++++++------ web/src/components/ProjectContents.vue | 2 +- web/src/components/map/Map.vue | 4 +- web/src/storeFunctions.ts | 11 +- 10 files changed, 293 insertions(+), 105 deletions(-) diff --git a/uvdat/core/rest/project.py b/uvdat/core/rest/project.py index 3858a61f..58ade39e 100644 --- a/uvdat/core/rest/project.py +++ b/uvdat/core/rest/project.py @@ -20,11 +20,16 @@ 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=[ diff --git a/uvdat/core/rest/serializers.py b/uvdat/core/rest/serializers.py index 696e9fc9..a2f41a06 100644 --- a/uvdat/core/rest/serializers.py +++ b/uvdat/core/rest/serializers.py @@ -51,7 +51,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 d02dbc6d..40799381 100644 --- a/web/src/api/auth.js +++ b/web/src/api/auth.js @@ -1,7 +1,7 @@ import axios from "axios"; import OauthClient from "@resonant/oauth-client"; import { currentError, currentUser, currentProject } from "@/store"; -import { clearState, clearMap } from "@/storeFunctions"; +import { clearState, resetMap } from "@/storeFunctions"; export const baseURL = `${process.env.VUE_APP_API_ROOT}api/v1/`; @@ -61,5 +61,5 @@ export const logout = async () => { currentUser.value = undefined; currentProject.value = undefined; clearState(); - clearMap(); + resetMap(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 @@