File

projects/maplander/components/src/lib/components/filters/filters.service.ts

Index

Properties
Methods

Constructor

constructor(_config: boolean)
Parameters :
Name Type Optional
_config boolean No

Methods

getChanges
getChanges()
Returns : Observable<FiltersChange>
Static getFiltersSaved
getFiltersSaved()
Returns : FiltersSaved
onStartComponent
onStartComponent()
Static removeFiltersSaved
removeFiltersSaved()
Returns : void
Static saveFilters
saveFilters(config: FiltersSaved)
Parameters :
Name Type Optional
config FiltersSaved No
Returns : void
setChange
setChange(change: FiltersChange)
Parameters :
Name Type Optional
change FiltersChange No
Returns : void
startComponent
startComponent(wrapper: FiltersWrapper)
Parameters :
Name Type Optional
wrapper FiltersWrapper No
Returns : void

Properties

Private _notifier
Type : BehaviorSubject<FiltersChange>
Private _startComponent
Type : Subject<FiltersWrapper>
Private Static FILTERS_SAVED_KEY
Type : string
Default value : 'FILTERS'
import {Inject, Injectable, Optional} from '@angular/core';
import {BehaviorSubject, Observable, Subject} from 'rxjs';
import {LocalStorageService} from '@maplander/static';
import {FiltersChangeType} from '../../utils/enums/filters-change-type';
import {FiltersChange} from './../../utils/models/filters-change';
import {Utils} from '../../utils';
import {FILTERS_TOKEN} from './token';
import {FiltersWrapper} from '../../utils/classes';
import {FiltersSaved} from '../../utils/models';

@Injectable()
export class FiltersService {

  private static FILTERS_SAVED_KEY = 'FILTERS';
  private _notifier: BehaviorSubject<FiltersChange>;
  private _startComponent: Subject<FiltersWrapper>;

  constructor(
    @Optional() @Inject(FILTERS_TOKEN) private _config: boolean
  ) {
    this._startComponent = new Subject<FiltersWrapper>();
    this._notifier = new BehaviorSubject<FiltersChange>({
      filter: Utils.getDefaultFilter(this._config || false),
      type: FiltersChangeType.INIT,
      ft: false
    });
  }

  static removeFiltersSaved(): void {
    LocalStorageService.removeItem<FiltersSaved>(FiltersService.FILTERS_SAVED_KEY);
  }

  static getFiltersSaved(): FiltersSaved {
    return LocalStorageService.getItem<FiltersSaved>(FiltersService.FILTERS_SAVED_KEY);
  }

  static saveFilters(config: FiltersSaved): void {
    LocalStorageService.setItem<FiltersSaved>(FiltersService.FILTERS_SAVED_KEY, {
      filters: config.filters,
      ft: config.ft || false,
      isSharedProperties: config.isSharedProperties || false
    });
  }

  setChange(change: FiltersChange): void {
    this._notifier.next(change);
  }

  getChanges(): Observable<FiltersChange> {
    return this._notifier.asObservable();
  }

  startComponent(wrapper: FiltersWrapper): void {
    this._startComponent.next(wrapper);
  }

  onStartComponent(): Observable<FiltersWrapper> {
    return this._startComponent.asObservable();
  }
}

result-matching ""

    No results matching ""