Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions projects/laji-api-client-b/src/laji-api-client-b.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Inject, Injectable, InjectionToken } from '@angular/core';
import { paths } from 'projects/laji-api-client-b/generated/api.d';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { shareReplay, tap } from 'rxjs/operators';
import { share, tap } from 'rxjs/operators';

type WithResponses<T> = T & { responses: unknown };
type Parameters<T> = 'parameters' extends keyof T ? T['parameters'] : never;
Expand Down Expand Up @@ -189,7 +189,7 @@ export class LajiApiClientBService {
lastRefresh: Date.now()
});
}),
shareReplay(1)
share()
) as any;

cachedPath?.set(paramsHash, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import { toHtmlSelectElement } from '../../../shared/service/html-element.servic
import { ModalRef, ModalService } from 'projects/laji-ui/src/lib/modal/modal.service';

import type { components } from 'projects/laji-api-client-b/generated/api';
import type { paths } from 'projects/laji-api-client-b/generated/api';

type Document = components['schemas']['document'];
type PublicityRestrictions = Document['publicityRestrictions'];
type PublicityRestrictions = NonNullable<paths['/documents/batch/{jobID}']['post']['parameters']['query']>['publicityRestrictions'];
type BatchJob = components['schemas']['BatchJobValidationStatusResponse'];

@Component({
Expand Down Expand Up @@ -525,11 +525,7 @@ export class ImporterComponent implements OnInit, OnDestroy {

const rowData = this.parsedData!.filter(data => data.document !== null);

this.importService.sendData({
...this.job,
dataOrigin: 'MY.dataOriginSpreadsheetFile',
publicityRestrictions
} as any).pipe(
this.importService.sendData(this.job!.id, 'MY.dataOriginSpreadsheetFile', publicityRestrictions).pipe(
switchMap(() => this.importService.waitToComplete(this.job!, (status) => {
ticker += add;
this.current = status.processed === this.total ?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { EMPTY, Observable, of, Subject, timer } from 'rxjs';
import {
IFormField,
LEVEL_DOCUMENT,
Expand All @@ -10,12 +10,15 @@ import {
} from '../model/excel';
import { MappingService } from './mapping.service';
import * as Hash from 'object-hash';
import { catchError, delay, switchMap } from 'rxjs/operators';
import { catchError, delay, expand, switchMap, tap } from 'rxjs/operators';
import { LajiApiClientBService } from 'projects/laji-api-client-b/src/laji-api-client-b.service';
import type { components } from 'projects/laji-api-client-b/generated/api';
import type { paths } from 'projects/laji-api-client-b/generated/api';

type Document = components['schemas']['document'];
type BatchJob = components['schemas']['BatchJobValidationStatusResponse'];
type DataOrigin = NonNullable<paths['/documents/batch/{jobID}']['post']['parameters']['query']>['dataOrigin'];
type PublicityRestrictions = NonNullable<paths['/documents/batch/{jobID}']['post']['parameters']['query']>['publicityRestrictions'];

export interface IData {
rowIdx: number;
Expand Down Expand Up @@ -87,31 +90,23 @@ export class ImportService {
}

waitToComplete(job: BatchJob, processCB: (status: BatchJob['status']) => void): Observable<BatchJob> {
return this.api.get('/documents/batch/{jobID}', { path: { jobID: job.id }, query: { validationErrorFormat: 'dotNotation' } }).pipe(
switchMap(response => {
const req$ = () => this.api.get('/documents/batch/{jobID}', { path: { jobID: job.id } }, 0);
return req$().pipe(
expand(response => {
processCB(response.status);
if (!['VALIDATING', 'COMPLETING'].includes(response.phase)) {
return of(response);
}
return of(response).pipe(
delay(1000),
switchMap(() => this.waitToComplete(job, processCB))
);
}),
catchError((e) => {
console.log('ERROR', e);
return of(e).pipe(
delay(1000),
switchMap(() => this.waitToComplete(job, processCB))
);
return !['VALIDATING', 'COMPLETING'].includes(response.phase)
? EMPTY
: req$().pipe(delay(1000));
})
);
}

sendData(
job: BatchJob
): Observable<any> {
return this.api.post('/documents/batch/{jobID}', { path: { jobID: job.id } });
jobID: string,
dataOrigin: DataOrigin,
publicityRestrictions: PublicityRestrictions
) {
return this.api.post('/documents/batch/{jobID}', { path: { jobID }, query: { dataOrigin, publicityRestrictions } });
}

flatFieldsToDocuments(
Expand Down