From ec7a7aadae565f964ec4ac8ab856e819339e8985 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Mon, 29 Apr 2019 10:26:00 +0200 Subject: [PATCH] Added button to reset the clients cache --- .../core/core-services/openslides.service.ts | 24 ++++++++++++------- .../core/core-services/websocket.service.ts | 4 +++- .../legal-notice/legal-notice.component.html | 6 +++++ .../legal-notice/legal-notice.component.ts | 7 +++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/client/src/app/core/core-services/openslides.service.ts b/client/src/app/core/core-services/openslides.service.ts index 8d8bd7c8f..16e0568da 100644 --- a/client/src/app/core/core-services/openslides.service.ts +++ b/client/src/app/core/core-services/openslides.service.ts @@ -1,8 +1,6 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; -import { take } from 'rxjs/operators'; - import { WebsocketService } from './websocket.service'; import { OperatorService } from './operator.service'; import { StorageService } from './storage.service'; @@ -122,18 +120,16 @@ export class OpenSlidesService { // is changed, the WS needs to reconnect, so the new connection holds the new // user information. if (this.websocketService.isConnected) { - this.websocketService.close(); - // Wait for the disconnect. - await this.websocketService.closeEvent.pipe(take(1)).toPromise(); + await this.websocketService.close(); } this.websocketService.connect({ changeId: changeId }); // Request changes after changeId. } /** - * Shuts OpenSlides down. The websocket is closed and the operator is not set. + * Shuts down OpenSlides. The websocket connection is closed and the operator is not set. */ - public shutdown(): void { - this.websocketService.close(); + public async shutdown(): Promise { + await this.websocketService.close(); this._booted = false; } @@ -141,7 +137,17 @@ export class OpenSlidesService { * Shutdown and bootup. */ public async reboot(): Promise { - this.shutdown(); + await this.shutdown(); + await this.bootup(); + } + + /** + * Clears the client cache and restarts OpenSlides. Results in "flickering" of the + * login mask, because the cached operator is also cleared. + */ + public async reset(): Promise { + await this.shutdown(); + await this.storageService.clear(); await this.bootup(); } diff --git a/client/src/app/core/core-services/websocket.service.ts b/client/src/app/core/core-services/websocket.service.ts index 03cbfd625..d70a9bce6 100644 --- a/client/src/app/core/core-services/websocket.service.ts +++ b/client/src/app/core/core-services/websocket.service.ts @@ -3,6 +3,7 @@ import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material'; import { Router } from '@angular/router'; import { Observable, Subject } from 'rxjs'; +import { take } from 'rxjs/operators'; import { TranslateService } from '@ngx-translate/core'; import { formatQueryParams, QueryParams } from '../query-params'; @@ -293,12 +294,13 @@ export class WebsocketService { /** * Closes the websocket connection. */ - public close(): void { + public async close(): Promise { this.shouldBeClosed = true; this.dismissConnectionErrorNotice(); if (this.websocket) { this.websocket.close(); this.websocket = null; + await this.closeEvent.pipe(take(1)).toPromise(); } } diff --git a/client/src/app/site/common/components/legal-notice/legal-notice.component.html b/client/src/app/site/common/components/legal-notice/legal-notice.component.html index 30b81be85..c4f4158c7 100644 --- a/client/src/app/site/common/components/legal-notice/legal-notice.component.html +++ b/client/src/app/site/common/components/legal-notice/legal-notice.component.html @@ -6,4 +6,10 @@ + + + + diff --git a/client/src/app/site/common/components/legal-notice/legal-notice.component.ts b/client/src/app/site/common/components/legal-notice/legal-notice.component.ts index 387297c85..6408145ab 100644 --- a/client/src/app/site/common/components/legal-notice/legal-notice.component.ts +++ b/client/src/app/site/common/components/legal-notice/legal-notice.component.ts @@ -1,9 +1,14 @@ import { Component } from '@angular/core'; +import { OpenSlidesService } from 'app/core/core-services/openslides.service'; @Component({ selector: 'os-legal-notice', templateUrl: './legal-notice.component.html' }) export class LegalNoticeComponent { - public constructor() {} + public constructor(private openSlidesService: OpenSlidesService) {} + + public resetCache(): void { + this.openSlidesService.reset(); + } }