import { Injectable , ApplicationRef , ChangeDetectorRef } from '@angular/core' ; import { Subject } from 'rxjs' ; import { ImportedData } from 'app/shared/schema' ; type RegExpWithGroups = RegExpExecArray & { groups ? : { [ key ] : string ; } ; } ; @ Injectable ( { providedIn : 'root' } ) export class ImportService { progress : Subject < number > = new Subject ( ) ; worker : Worker ; constructor ( private appRef ) { this . worker = new Worker ( "worker.js" ) ; } async importCityvizor ( files , options ? ) { return this . runImport ( "cityvizor" , files , options ) ; } async importGordic ( files ) { return this . runImport ( "ginis" , files ) ; } async importVera ( files ) { return this . runImport ( "vera" , files ) ; } runImport ( importer , files , options ? ) { return new Promise ( ( resolve , reject ) => { this . worker . postMessage ( { "type" : "import" , "importer" : importer , files , options } ) ; this . worker . onmessage = ( event ) => { switch ( event . data . type ) { case "progress" : this . progress . next ( event . data . data ) ; break ; case "data" : resolve ( event . data . data ) ; break ; } } ; this . worker . onerror = ( err ) => reject ( err ) ; } ) ; } }