Correct projector scroll reset

Fixes the "everytime reset" with #4887
This commit is contained in:
FinnStutzenstein 2019-08-01 08:03:34 +02:00
parent 62c55094bb
commit 35e88b8386
2 changed files with 21 additions and 5 deletions

View File

@ -158,7 +158,7 @@ export class ProjectorService {
changed = true; changed = true;
} }
if (changed) { if (changed) {
await this.projectRequest(projector, projector.elements, null, removedElements); await this.projectRequest(projector, projector.elements, null, removedElements, false, true);
} }
} }
} }
@ -211,7 +211,8 @@ export class ProjectorService {
elements?: ProjectorElements, elements?: ProjectorElements,
preview?: ProjectorElements, preview?: ProjectorElements,
appendToHistory?: ProjectorElements, appendToHistory?: ProjectorElements,
deleteLastHistroyElement?: boolean deleteLastHistroyElement?: boolean,
resetScroll?: boolean
): Promise<void> { ): Promise<void> {
const requestData: any = {}; const requestData: any = {};
if (elements) { if (elements) {
@ -229,6 +230,9 @@ export class ProjectorService {
if (appendToHistory && appendToHistory.length && deleteLastHistroyElement) { if (appendToHistory && appendToHistory.length && deleteLastHistroyElement) {
throw new Error('You cannot append to the history and delete the last element at the same time'); throw new Error('You cannot append to the history and delete the last element at the same time');
} }
if (resetScroll) {
requestData.reset_scroll = resetScroll;
}
await this.http.post(`/rest/core/projector/${projector.id}/project/`, requestData); await this.http.post(`/rest/core/projector/${projector.id}/project/`, requestData);
} }
@ -361,7 +365,14 @@ export class ProjectorService {
const removedElements = projector.removeAllNonStableElements(); const removedElements = projector.removeAllNonStableElements();
projector.addElement(projector.elements_preview.splice(previewIndex, 1)[0]); projector.addElement(projector.elements_preview.splice(previewIndex, 1)[0]);
await this.projectRequest(projector, projector.elements, projector.elements_preview, removedElements); await this.projectRequest(
projector,
projector.elements,
projector.elements_preview,
removedElements,
false,
true
);
} }
/** /**
@ -388,7 +399,7 @@ export class ProjectorService {
if (lastElement) { if (lastElement) {
projector.addElement(lastElement); projector.addElement(lastElement);
} }
await this.projectRequest(projector, projector.elements, projector.elements_preview, null, true); await this.projectRequest(projector, projector.elements, projector.elements_preview, null, true, true);
} }
/** /**

View File

@ -177,15 +177,17 @@ class ProjectorViewSet(ModelViewSet):
If `delete_last_history_element` is True, the last element is deleted. If `delete_last_history_element` is True, the last element is deleted.
Note: You cannot give `append_to_history` and `delete_last_history_element` Note: You cannot give `append_to_history` and `delete_last_history_element`
at the same time. at the same time.
If `reset_scroll` is True, the scoll of the projector will reset.
""" """
projector = self.get_object() projector = self.get_object()
projector.scroll = 0
elements = request.data.get("elements") elements = request.data.get("elements")
preview = request.data.get("preview") preview = request.data.get("preview")
history_element = request.data.get("append_to_history") history_element = request.data.get("append_to_history")
delete_last_history_element = request.data.get( delete_last_history_element = request.data.get(
"delete_last_history_element", False "delete_last_history_element", False
) )
reset_scroll = request.data.get("reset_scroll", False)
if elements is not None: if elements is not None:
elements_validator(elements) elements_validator(elements)
@ -204,6 +206,9 @@ class ProjectorViewSet(ModelViewSet):
elements_array_validator(elements_history) elements_array_validator(elements_history)
projector.elements_history = elements_history projector.elements_history = elements_history
if reset_scroll:
projector.scroll = 0
projector.save() projector.save()
return Response() return Response()