From bb2185903fba8ee4189c415206ed8a24250233fb Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Thu, 19 Sep 2024 15:14:24 +0000 Subject: [PATCH] feat: Add Dataset selection panel to Project Config page --- uvdat/core/rest/project.py | 20 +- web/src/App.vue | 70 ++-- web/src/api/rest.ts | 20 + web/src/components/DatasetList.vue | 216 +++++----- web/src/components/MainDrawerContents.vue | 24 +- web/src/components/ProjectConfig.vue | 485 ++++++++++++++-------- web/src/components/ProjectContents.vue | 56 ++- web/src/store.ts | 1 + 8 files changed, 557 insertions(+), 335 deletions(-) diff --git a/uvdat/core/rest/project.py b/uvdat/core/rest/project.py index 448f943c..96de476b 100644 --- a/uvdat/core/rest/project.py +++ b/uvdat/core/rest/project.py @@ -2,10 +2,11 @@ from django.http import HttpResponse from rest_framework.decorators import action from rest_framework.viewsets import ModelViewSet +from rest_framework.response import Response -from uvdat.core.models import Project +from uvdat.core.models import Dataset, Project from uvdat.core.rest.access_control import GuardianFilter, GuardianPermission -from uvdat.core.rest.serializers import ProjectSerializer +from uvdat.core.rest.serializers import DatasetSerializer, ProjectSerializer from uvdat.core.tasks.osmnx import load_roads @@ -21,6 +22,21 @@ def perform_create(self, serializer): user: User = self.request.user project.set_permissions(owner=user) + def partial_update(self, request, id): + project = self.get_object() + project.datasets.set( + Dataset.objects.filter( + id__in=request.data.get('dataset_ids') + ) + ) + project.save() + response = ProjectSerializer(project).data + response.update(datasets=[ + DatasetSerializer(dataset).data + for dataset in project.datasets.all() + ]) + return Response(response, status=200) + @action(detail=True, methods=['get']) def regions(self, request, **kwargs): project = self.get_object() diff --git a/web/src/App.vue b/web/src/App.vue index 15c01dec..75a93fc2 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -8,6 +8,7 @@ import { availableProjects, currentChart, currentSimulationType, + projectConfigMode, } from "./store"; import { oauthClient, logout } from "./api/auth"; import { loadProjects } from "./storeFunctions"; @@ -16,6 +17,7 @@ import MainDrawerContents from "./components/MainDrawerContents.vue"; import OptionsDrawerContents from "./components/OptionsDrawerContents.vue"; import ChartJS from "./components/ChartJS.vue"; import SimulationsPanel from "./components/SimulationsPanel.vue"; +import ProjectConfig from "./components/ProjectConfig.vue"; export default defineComponent({ components: { @@ -24,6 +26,7 @@ export default defineComponent({ OptionsDrawerContents, ChartJS, SimulationsPanel, + ProjectConfig, }, setup() { const drawer = ref(true); @@ -54,6 +57,7 @@ export default defineComponent({ showError, currentChart, currentSimulationType, + projectConfigMode, }; }, }); @@ -94,7 +98,10 @@ export default defineComponent({ - + UVDAT
@@ -113,35 +120,38 @@ export default defineComponent({
- - - - - - -
- - - + +
+ + + + + + +
+ + + +
diff --git a/web/src/api/rest.ts b/web/src/api/rest.ts index 36a6becd..f7c7fb5a 100644 --- a/web/src/api/rest.ts +++ b/web/src/api/rest.ts @@ -1,5 +1,6 @@ import { apiClient } from "./auth"; import { + User, Project, Dataset, NetworkNode, @@ -12,6 +13,10 @@ import { Network, } from "@/types"; +export async function getUsers(): Promise { + return (await apiClient.get(`users`)).data.results; +} + export async function getProjects(): Promise { return (await apiClient.get("projects")).data.results; } @@ -47,6 +52,17 @@ 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; } @@ -65,6 +81,10 @@ export async function getProjectSimulationTypes( .data; } +export async function getDatasets(): Promise { + return (await apiClient.get(`datasets`)).data.results; +} + export async function getDataset(datasetId: number): Promise { return (await apiClient.get(`datasets/${datasetId}`)).data; } diff --git a/web/src/components/DatasetList.vue b/web/src/components/DatasetList.vue index cc17e700..b2d783dc 100644 --- a/web/src/components/DatasetList.vue +++ b/web/src/components/DatasetList.vue @@ -1,14 +1,8 @@ diff --git a/web/src/components/MainDrawerContents.vue b/web/src/components/MainDrawerContents.vue index cc9de39c..0c270439 100644 --- a/web/src/components/MainDrawerContents.vue +++ b/web/src/components/MainDrawerContents.vue @@ -1,6 +1,6 @@ diff --git a/web/src/components/ProjectContents.vue b/web/src/components/ProjectContents.vue index 5d897572..5f4f2f4b 100644 --- a/web/src/components/ProjectContents.vue +++ b/web/src/components/ProjectContents.vue @@ -1,5 +1,5 @@