107873: Implement autoRefreshingSearchBy for process-data service

This commit is contained in:
Andreas Awouters
2024-01-02 09:11:38 +01:00
parent c7922b7e67
commit 64befd2e30

View File

@@ -6,7 +6,7 @@ import { HALEndpointService } from '../../shared/hal-endpoint.service';
import { Process } from '../../../process-page/processes/process.model';
import { PROCESS } from '../../../process-page/processes/process.resource-type';
import { Observable } from 'rxjs';
import { switchMap, filter, distinctUntilChanged, find } from 'rxjs/operators';
import { switchMap, filter, distinctUntilChanged, find, tap, throttleTime } from 'rxjs/operators';
import { PaginatedList } from '../paginated-list.model';
import { Bitstream } from '../../shared/bitstream.model';
import { RemoteData } from '../remote-data';
@@ -113,7 +113,6 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
}
/**
*
* @param searchMethod The search method for the Process
* @param options The FindListOptions object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
@@ -129,6 +128,28 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/**
* @param searchMethod The search method for the Process
* @param options The FindListOptions object
* @param pollingIntervalInMs The interval by which the search will be repeated
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should automatically be resolved.
* @return {Observable<RemoteData<PaginatedList<Process>>>}
* Return an observable that emits a paginated list of processes every interval
*/
autoRefreshingSearchBy(searchMethod: string, options?: FindListOptions, pollingIntervalInMs: number = 5000, ...linksToFollow: FollowLinkConfig<Process>[]): Observable<RemoteData<PaginatedList<Process>>> {
return this.searchBy(searchMethod, options, false, true, ...linksToFollow)
.pipe(
getAllCompletedRemoteData(),
throttleTime(pollingIntervalInMs),
tap((processListRD: RemoteData<PaginatedList<Process>>) => {
setTimeout(() => {
this.invalidateByHref(processListRD.payload._links.self.href);
}, pollingIntervalInMs);
}),
);
}
/**
* Delete an existing object on the server
* @param objectId The id of the object to be removed