Merge pull request #4646 from FinnStutzenstein/resetClientCache

Added button to reset the clients cache
This commit is contained in:
Emanuel Schütze 2019-04-30 10:24:19 +02:00 committed by GitHub
commit 4507840788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 11 deletions

View File

@ -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<void> {
await this.websocketService.close();
this._booted = false;
}
@ -141,7 +137,17 @@ export class OpenSlidesService {
* Shutdown and bootup.
*/
public async reboot(): Promise<void> {
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<void> {
await this.shutdown();
await this.storageService.clear();
await this.bootup();
}

View File

@ -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<void> {
this.shouldBeClosed = true;
this.dismissConnectionErrorNotice();
if (this.websocket) {
this.websocket.close();
this.websocket = null;
await this.closeEvent.pipe(take(1)).toPromise();
}
}

View File

@ -6,4 +6,10 @@
<os-legal-notice-content></os-legal-notice-content>
<mat-card class="os-card">
<button type="button" mat-button (click)="resetCache()">
<span translate>Reset cache</span>
</button>
</mat-card>
<os-count-users></os-count-users>

View File

@ -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();
}
}