From 3432c66d4d3b560b19dec5f9dc634e35b0f67b36 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Thu, 28 Feb 2019 11:04:19 +0100 Subject: [PATCH] clear repositories and extra DS clear on logout --- .../app/core/core-services/auth.service.ts | 6 +++++- .../core/core-services/data-store.service.ts | 21 +++++++++++++++---- .../app/core/repositories/base-repository.ts | 10 +++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/client/src/app/core/core-services/auth.service.ts b/client/src/app/core/core-services/auth.service.ts index 502c5aa55..32262a09f 100644 --- a/client/src/app/core/core-services/auth.service.ts +++ b/client/src/app/core/core-services/auth.service.ts @@ -6,6 +6,7 @@ import { environment } from 'environments/environment'; import { User } from '../../shared/models/users/user'; import { OpenSlidesService } from './openslides.service'; import { HttpService } from './http.service'; +import { DataStoreService } from './data-store.service'; /** * The data returned by a post request to the login route. @@ -34,7 +35,8 @@ export class AuthService { private http: HttpService, private operator: OperatorService, private OpenSlides: OpenSlidesService, - private router: Router + private router: Router, + private DS: DataStoreService ) {} /** @@ -71,6 +73,8 @@ export class AuthService { } catch (e) { // We do nothing on failures. Reboot OpenSlides anyway. } + // Clear the DataStore + this.DS.clear(); this.router.navigate(['/']); this.OpenSlides.reboot(); } diff --git a/client/src/app/core/core-services/data-store.service.ts b/client/src/app/core/core-services/data-store.service.ts index 46974db24..457c5d8d2 100644 --- a/client/src/app/core/core-services/data-store.service.ts +++ b/client/src/app/core/core-services/data-store.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, EventEmitter } from '@angular/core'; import { Observable, Subject } from 'rxjs'; @@ -123,6 +123,20 @@ export class DataStoreService { return this.changedOrDeletedSubject.asObservable(); } + /** + * Observable subject for changed or deleted models in the datastore. + */ + private readonly clearEvent: EventEmitter = new EventEmitter(); + + /** + * Observe the datastore for changes and deletions. + * + * @return an observable for changed and deleted objects. + */ + public get clearObservable(): Observable { + return this.clearEvent.asObservable(); + } + /** * The maximal change id from this DataStore. */ @@ -171,9 +185,7 @@ export class DataStoreService { }); }); } else { - this.jsonStore = {}; - this.modelStore = {}; - this._maxChangeId = 0; + await this.clear(); } return this.maxChangeId; } @@ -207,6 +219,7 @@ export class DataStoreService { this._maxChangeId = 0; await this.storageService.remove(DataStoreService.cachePrefix + 'DS'); await this.storageService.remove(DataStoreService.cachePrefix + 'maxChangeId'); + this.clearEvent.next(); } /** diff --git a/client/src/app/core/repositories/base-repository.ts b/client/src/app/core/repositories/base-repository.ts index 24de04d11..c8314d3e7 100644 --- a/client/src/app/core/repositories/base-repository.ts +++ b/client/src/app/core/repositories/base-repository.ts @@ -68,6 +68,8 @@ export abstract class BaseRepository this.clear()); + // Populate the local viewModelStore with ViewModel Objects. this.DS.getAll(this.baseModelCtor).forEach((model: M) => { this.viewModelStore[model.id] = this.createViewModel(model); @@ -152,6 +154,14 @@ export abstract class BaseRepository