import { SyncedSessionService } from "./session-service/synced-session.service" ; import { AppConfig } from "../app-config/app-config" ; import { SessionService } from "./session-service/session.service" ; import { AlertService } from "../alerts/alert.service" ; import { LoggingService } from "../logging/logging.service" ; import { EntitySchemaService } from "../entity/schema/entity-schema.service" ; import { LoginState } from "./session-states/login-state.enum" ; import { SessionType } from "./session-type" ; import { PouchDatabase } from "../database/pouch-database" ; import { HttpClient } from "@angular/common/http" ; import { LocalSession } from "./session-service/local-session" ; /**
 * Factory method for Angular DI provider of SessionService.
 *
 * see [sessionServiceProvider] sessionServiceProvider for details.
  export function sessionServiceFactory ( alertService , loggingService , entitySchemaService , httpClient ) { let sessionService ; switch ( AppConfig . settings . session_type ) { case SessionType . local : sessionService = new LocalSession ( PouchDatabase . createWithIndexedDB ( AppConfig . settings . database . name , loggingService ) ) ; break ; case SessionType . synced : sessionService = new SyncedSessionService ( alertService , loggingService , entitySchemaService , httpClient ) ; break ; default : sessionService = new LocalSession ( PouchDatabase . createWithInMemoryDB ( AppConfig . settings . database . name , loggingService ) ) ; break ; } updateLoggingServiceWithUserContext ( sessionService ) ; return sessionService ; } function updateLoggingServiceWithUserContext ( sessionService ) { sessionService . loginState . subscribe ( ( newState ) => { if ( newState === LoginState . LOGGED_IN ) { LoggingService . setLoggingContextUser ( sessionService . getCurrentUser ( ) . name ) ; } else { LoggingService . setLoggingContextUser ( undefined ) ; } } ) ; } /**
 * Provider for SessionService implementation based on the AppConfig settings.
 *
 * Set `"database": { "useTemporaryDatabase": true }` in your app-config.json
 * to use the MockSessionService which will set up an in-memory database with demo data.
 * Otherwise the SyncedSessionService is used, establishing a local and remote session and setting up sync between them.
 */ export const sessionServiceProvider = { provide : SessionService , useFactory : sessionServiceFactory , deps : [ AlertService , LoggingService , EntitySchemaService , HttpClient ] , } ;