From 32bfd4599abfede90ad11f082f074ac2ac461300 Mon Sep 17 00:00:00 2001 From: GabrielMeyer Date: Mon, 2 Sep 2019 17:01:01 +0200 Subject: [PATCH] Improves the spinner - The spinner shouldn't appear, if the user is logged in. --- client/src/app/app.component.ts | 2 +- .../app/core/ui-services/overlay.service.ts | 15 ++------- .../services/motion-multiselect.service.ts | 32 +++++-------------- 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index ad2671448..0b06610f5 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -199,7 +199,7 @@ export class AppComponent { */ private checkConnectionProgress(): void { if ((this.user || this.operator.isAnonymous) && this.isStable) { - this.overlayService.setSpinner(false, null, true); + this.overlayService.setSpinner(false, null, false, true); } } } diff --git a/client/src/app/core/ui-services/overlay.service.ts b/client/src/app/core/ui-services/overlay.service.ts index 67dd3637f..de560e477 100644 --- a/client/src/app/core/ui-services/overlay.service.ts +++ b/client/src/app/core/ui-services/overlay.service.ts @@ -28,12 +28,7 @@ export class OverlayService { /** * Boolean, whether appearing of the spinner should be prevented next time. */ - private preventAppearingSpinner: boolean; - - /** - * Boolean to indicate, if the spinner has already appeared. - */ - private spinnerHasAppeared = false; + private preventAppearingSpinner = false; /** * @@ -48,12 +43,9 @@ export class OverlayService { * @param text optional. If the spinner should show a message. * @param preventAppearing optional. Wether to prevent showing the spinner the next time. */ - public setSpinner(isVisible: boolean, text?: string, preventAppearing?: boolean): void { - if (!(this.preventAppearingSpinner && !this.spinnerHasAppeared && isVisible)) { + public setSpinner(isVisible: boolean, text?: string, forceAppearing?: boolean, preventAppearing?: boolean): void { + if (!this.preventAppearingSpinner || forceAppearing) { setTimeout(() => this.spinner.next({ isVisible, text })); - if (isVisible) { - this.spinnerHasAppeared = true; - } } this.preventAppearingSpinner = preventAppearing; } @@ -93,7 +85,6 @@ export class OverlayService { * and still stays at the website. */ public logout(): void { - this.spinnerHasAppeared = false; this.preventAppearingSpinner = false; } } diff --git a/client/src/app/site/motions/services/motion-multiselect.service.ts b/client/src/app/site/motions/services/motion-multiselect.service.ts index 0ad51668b..4f31257cb 100644 --- a/client/src/app/site/motions/services/motion-multiselect.service.ts +++ b/client/src/app/site/motions/services/motion-multiselect.service.ts @@ -81,7 +81,7 @@ export class MotionMultiselectService { `\n${i} ` + this.translate.instant('of') + ` ${motions.length}`; - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); await this.repo.delete(motion); } this.overlayService.setSpinner(false); @@ -119,7 +119,7 @@ export class MotionMultiselectService { const selectedChoice = await this.choiceService.open(title, choices); if (selectedChoice) { const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner); - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); await this.repo.setMultiState(motions, selectedChoice.items as number); } } else { @@ -152,7 +152,7 @@ export class MotionMultiselectService { recommendation: selectedChoice.action ? 0 : (selectedChoice.items as number) })); const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner); - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); await this.httpService.post('/rest/motions/motion/manage_multiple_recommendation/', { motions: requestData }); @@ -181,13 +181,8 @@ export class MotionMultiselectService { ); if (selectedChoice) { const message = this.translate.instant(this.messageForSpinner); - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); await this.repo.setMultiCategory(motions, selectedChoice.items as number); - // .catch(error => { - // this.overlayService.setSpinner(false); - // throw error; - // }); - // this.overlayService.setSpinner(false); } } @@ -213,7 +208,6 @@ export class MotionMultiselectService { submitters: submitterIds }; }); - // await this.httpService.post('/rest/motions/motion/manage_multiple_submitters/', { motions: requestData }); } else if (selectedChoice.action === choices[1]) { requestData = motions.map(motion => { const submitterIdsToRemove = selectedChoice.items as number[]; @@ -226,9 +220,8 @@ export class MotionMultiselectService { } const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner); - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); await this.httpService.post('/rest/motions/motion/manage_multiple_submitters/', { motions: requestData }); - // this.overlayService.setSpinner(false); } } @@ -256,7 +249,6 @@ export class MotionMultiselectService { tags: tagIds }; }); - // await this.httpService.post('/rest/motions/motion/manage_multiple_tags/', { motions: requestData }); } else if (selectedChoice.action === choices[1]) { requestData = motions.map(motion => { const tagIdsToRemove = selectedChoice.items as number[]; @@ -266,7 +258,6 @@ export class MotionMultiselectService { tags: tagIds }; }); - // await this.httpService.post('/rest/motions/motion/manage_multiple_tags/', { motions: requestData }); } else if (selectedChoice.action === choices[2]) { requestData = motions.map(motion => { return { @@ -277,9 +268,8 @@ export class MotionMultiselectService { } const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner); - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); await this.httpService.post('/rest/motions/motion/manage_multiple_tags/', { motions: requestData }); - // this.overlayService.setSpinner(false); } } @@ -300,14 +290,9 @@ export class MotionMultiselectService { ); if (selectedChoice) { const message = this.translate.instant(this.messageForSpinner); - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); const blockId = selectedChoice.action ? null : (selectedChoice.items as number); await this.repo.setMultiMotionBlock(motions, blockId); - // .catch(error => { - // this.overlayService.setSpinner(false); - // throw error; - // }); - // this.overlayService.setSpinner(false); } } @@ -370,9 +355,8 @@ export class MotionMultiselectService { if (selectedChoice && motions.length) { const message = this.translate.instant(`I have ${motions.length} favorite motions. Please wait ...`); const star = (selectedChoice.items as number) === choices[0].id; - this.overlayService.setSpinner(true, message); + this.overlayService.setSpinner(true, message, true); await this.personalNoteService.bulkSetStar(motions, star); - // this.overlayService.setSpinner(false); } } }