blob: c2c5c5e00f620d01168a2843c1cd02176d504d4e [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import { Store } from '@ngrx/store';
import { Observable, Subject } from 'rxjs';
import * as store from '@shared/store';
import { localeDateString } from '@shared/utility';
import { OnDestroy } from '@angular/core';
import * as settingsActions from '@shared/store/actions/settings.action';
export abstract class BaseSandbox implements OnDestroy {
protected _endSubscriptions$: Subject<boolean> = new Subject();
public culture$: Observable<string> = this.appState$.select(store.getSelectedCulture);
public culture: string;
constructor(protected appState$: Store<store.State>) {}
public ngOnDestroy() {
this._endSubscriptions$.next(true);
}
/**
* Formats date string based on selected culture
*
* @param value
*/
public formatDate(value: string) {
return localeDateString(value, this.culture);
}
/**
* Clears all data from local storage set at by
* code during application rutime (user session)
*
* @author Martin Gardyan <martin.gardyan@pta.de>
* @memberof BaseSandbox
*/
public clearStorage(): void {
localStorage.clear();
}
/**
* Removes user form redux store
*
* @author Martin Gardyan <martin.gardyan@pta.de>
* @memberof BaseSandbox
*/
public removeUser(): void {
this.appState$.dispatch(settingsActions.setUser(null));
}
}