Merge pull request #5103 from jsangmeister/reference-projector-view
Added a view to change the reference projector in one api call
This commit is contained in:
commit
f62b506dee
@ -127,4 +127,12 @@ export class ProjectorRepositoryService extends BaseRepository<ViewProjector, Pr
|
||||
step: step
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given projector as the new reference projector for all projectors
|
||||
* @param projector the new default projector id
|
||||
*/
|
||||
public async setDefaultProjector(projector_id: number): Promise<void> {
|
||||
await this.http.post<void>(`/rest/core/projector/${projector_id}/set_default_projector/`);
|
||||
}
|
||||
}
|
||||
|
@ -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<Projector> = {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user