From 96ac370f6185f2eb24e05046796f6f6b5f6eff7c Mon Sep 17 00:00:00 2001 From: jsangmeister Date: Fri, 1 Nov 2019 09:48:58 +0100 Subject: [PATCH] added a view to change the reference projector in one api call --- .../projector/projector-repository.service.ts | 8 ++++++++ .../projector-list/projector-list.component.ts | 12 +++++------- openslides/core/views.py | 14 +++++++++++++- tests/integration/core/test_views.py | 17 +++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/client/src/app/core/repositories/projector/projector-repository.service.ts b/client/src/app/core/repositories/projector/projector-repository.service.ts index 57004ba46..c4e3a46d0 100644 --- a/client/src/app/core/repositories/projector/projector-repository.service.ts +++ b/client/src/app/core/repositories/projector/projector-repository.service.ts @@ -127,4 +127,12 @@ export class ProjectorRepositoryService extends BaseRepository { + await this.http.post(`/rest/core/projector/${projector_id}/set_default_projector/`); + } } diff --git a/client/src/app/site/projector/components/projector-list/projector-list.component.ts b/client/src/app/site/projector/components/projector-list/projector-list.component.ts index b97d25baa..7852275c8 100644 --- a/client/src/app/site/projector/components/projector-list/projector-list.component.ts +++ b/client/src/app/site/projector/components/projector-list/projector-list.component.ts @@ -162,13 +162,11 @@ export class ProjectorListComponent extends BaseViewComponent implements OnInit, } } + /** + * Event handler when the reference projector is changed + * @param change the change event that contains the new id + */ public onSelectReferenceProjector(change: MatSelectChange): void { - const update: Partial = { - reference_projector_id: change.value - }; - const promises = this.projectors.map(projector => { - return this.repo.update(update, projector); - }); - Promise.all(promises).catch(this.raiseError); + this.repo.setDefaultProjector(change.value).catch(this.raiseError); } } diff --git a/openslides/core/views.py b/openslides/core/views.py index a39031d1e..4ccf1290d 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -132,7 +132,7 @@ class ProjectorViewSet(ModelViewSet): "destroy", "control_view", "set_scroll", - "set_projectiondefault", + "set_default_projector", "project", ): result = has_perm(self.request.user, "core.can_see_projector") and has_perm( @@ -329,6 +329,18 @@ class ProjectorViewSet(ModelViewSet): {"detail": "Setting scroll to {0} was successful.", "args": [request.data]} ) + @detail_route(methods=["post"]) + def set_default_projector(self, request, pk): + """ + REST API operation to set the projector with the given pk as the new default. + """ + reference_projector = self.get_object() + for projector in self.queryset.all(): + projector.reference_projector = reference_projector + projector.save() + + return Response() + class ProjectionDefaultViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): """ diff --git a/tests/integration/core/test_views.py b/tests/integration/core/test_views.py index 1f5d014b8..0d96d51ef 100644 --- a/tests/integration/core/test_views.py +++ b/tests/integration/core/test_views.py @@ -105,6 +105,23 @@ def test_project_view(client): assert projector.elements_preview == [{"name": "topics/topic", "id": 3}] +@pytest.mark.django_db(transaction=False) +def test_set_default_projector(client): + client.login(username="admin", password="admin") + Projector.objects.create(name="test_name_rePaODETymV4eFM3aOBD") + reference_projector = Projector.objects.create( + name="test_name_S2vXmumTMKyT4yjgEoyF" + ) + + response = client.post( + reverse("projector-set-default-projector", args=[reference_projector.pk]) + ) + assert response.status_code == 200 + + for projector in Projector.objects.all(): + assert projector.reference_projector_id == reference_projector.id + + @pytest.mark.django_db(transaction=False) def test_get(client): client.login(username="admin", password="admin")