Skip to content

Commit

Permalink
feat: create/delete projects, edit project names and default map posi…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
annehaley committed Oct 1, 2024
1 parent bb21859 commit d91be55
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 109 deletions.
20 changes: 10 additions & 10 deletions uvdat/core/rest/project.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'])
Expand Down
2 changes: 1 addition & 1 deletion uvdat/core/rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion web/src/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ export const logout = async () => {
currentUser.value = undefined;
currentProject.value = undefined;
clearState();
setMapCenter();
setMapCenter(undefined);
};
13 changes: 1 addition & 12 deletions web/src/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function patchProject(
projectId: number,
data: object
): Promise<Project> {
return await apiClient.patch(`projects/${projectId}/`, data);
return (await apiClient.patch(`projects/${projectId}/`, data)).data;
}

export async function deleteProject(projectId: number): Promise<Project> {
Expand All @@ -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<Project> {
return (
await apiClient.patch(`projects/${projectId}/`, {
dataset_ids: datasetIds,
})
).data;
}

export async function getProjectCharts(projectId: number): Promise<Chart[]> {
return (await apiClient.get(`charts?project=${projectId}`)).data.results;
}
Expand Down
3 changes: 3 additions & 0 deletions web/src/components/DatasetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ export default {
</template>

<style scoped>
.v-list-item--active > * {
background: transparent !important;
}
.group {
border-bottom: 1px solid lightgray;
}
Expand Down
73 changes: 68 additions & 5 deletions web/src/components/MainDrawerContents.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<script lang="ts">
import { ref, computed } from "vue";
import { ref, Ref, computed } from "vue";
import { availableProjects, currentProject, projectConfigMode } from "@/store";
import ProjectContents from "./ProjectContents.vue";
import { getCurrentMapPosition, resetMap } from "@/storeFunctions";
import { Project } from "@/types";
import { patchProject } from "@/api/rest";
export default {
components: { ProjectContents },
setup() {
const searchText = ref();
const saving: Ref<string | boolean> = ref(false);
const filteredProjects = computed(() => {
return availableProjects.value.filter((proj) => {
return (
Expand All @@ -20,11 +24,33 @@ export default {
projectConfigMode.value = create ? "new" : true;
}
function saveProjectMapLocation(project: Project) {
const { center, zoom } = getCurrentMapPosition();
saving.value = true;
patchProject(project.id, {
default_map_center: center,
default_map_zoom: zoom,
}).then((project) => {
availableProjects.value = availableProjects.value.map((p) => {
if (p.id == project.id) {
p.default_map_center = project.default_map_center;
p.default_map_zoom = project.default_map_zoom;
}
return p;
});
resetMap(project);
saving.value = "done";
});
}
return {
filteredProjects,
currentProject,
searchText,
saving,
openProjectConfig,
resetMap,
saveProjectMapLocation,
};
},
};
Expand Down Expand Up @@ -96,6 +122,39 @@ export default {
<span class="mr-3">{{ project.item_counts.simulations }}</span>
</div>
</div>
<div class="location-menu">
<v-icon icon="mdi-map-marker-right" size="small" color="primary" />
<v-menu
activator="parent"
location="end"
open-on-hover
:close-on-content-click="false"
@update:model-value="saving = false"
>
<v-card width="250">
<v-list selectable>
<v-list-item @click="resetMap(project)">
Go to project default map position
</v-list-item>
<v-list-item @click="saveProjectMapLocation(project)">
Set current map position as project default
<v-icon
v-if="saving == 'done'"
icon="mdi-check"
color="green"
style="float: right"
/>
<v-progress-circular
v-else-if="saving"
size="15"
indeterminate
style="float: right"
/>
</v-list-item>
</v-list>
</v-card>
</v-menu>
</div>
</v-expansion-panel-title>
<v-expansion-panel-text class="pa-0">
<v-card rounded="0" flat color="grey-lighten-2" class="pa-2">
Expand All @@ -114,20 +173,24 @@ export default {
.v-expansion-panel-text__wrapper {
padding: 0 !important;
}
.v-checkbox .v-selection-control {
max-width: 100%;
}
.expand-icon {
float: right;
}
.v-expansion-panel-title__overlay {
background-color: transparent !important;
}
.v-expansion-panel:not(:first-child)::after {
border-top-width: 0px !important;
}
.v-expansion-panel-title__icon {
align-self: flex-start;
}
.location-menu {
position: absolute;
right: 25px;
bottom: 15px;
}
</style>
Loading

0 comments on commit d91be55

Please sign in to comment.