import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; import { AppState } from '../../../../../app/reducers/index'; import { Store } from '@ngrx/store'; import { GeoActions } from './geo.actions'; import { GeoInfoService } from './geo-info/geo-info.service'; import { TranslateService } from '@ngx-translate/core'; import { GEO_LIMITS } from './geo.constants'; @Injectable() export class GeoService { appClickOutsideOfComponent$ = new Subject(); init () { this._store.dispatch(this.geoActions.init()); } destroy () { this._store.dispatch(this.geoActions.destroy()); } /** * Show notification that some locations exceed its limit * @param mode * @param type * @param limit */ informAboutOverLimit (mode, type, limit) { this.geoInfoService.showInfo({ level: 'error', message: this.translateService.instant(`app-geo-info.LIMIT`, { type: this.translateService.instant(`app-geo-dropdown.${type}_many`), mode: this.translateService.instant(`app-geo-mode.${mode}_past`), limit: limit }) }); } /** * Process and inform about over limit * @param isWithinLimit */ processOverLimit (isWithinLimit) { for (const mode in isWithinLimit) { if (isWithinLimit.hasOwnProperty(mode)) { for (const type in isWithinLimit[mode]) { if (isWithinLimit[mode].hasOwnProperty(type)) { if (!isWithinLimit[mode][type]) { return this.informAboutOverLimit(mode, type, GEO_LIMITS[type]); } } } } } } constructor (private _store: Store, private geoInfoService: GeoInfoService, private translateService: TranslateService, private geoActions: GeoActions) { } }