mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
111638: Clean up autoRefreshing calls
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, Input, OnDestroy } from '@angular/core';
|
||||
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
||||
import { ScriptDataService } from '../../../../core/data/processes/script-data.service';
|
||||
import { ContentSource } from '../../../../core/shared/content-source.model';
|
||||
import { ProcessDataService } from '../../../../core/data/processes/process-data.service';
|
||||
@@ -29,7 +29,7 @@ import { ContentSourceSetSerializer } from '../../../../core/shared/content-sour
|
||||
styleUrls: ['./collection-source-controls.component.scss'],
|
||||
templateUrl: './collection-source-controls.component.html',
|
||||
})
|
||||
export class CollectionSourceControlsComponent implements OnDestroy {
|
||||
export class CollectionSourceControlsComponent implements OnInit, OnDestroy {
|
||||
|
||||
/**
|
||||
* Should the controls be enabled.
|
||||
@@ -48,6 +48,7 @@ export class CollectionSourceControlsComponent implements OnDestroy {
|
||||
|
||||
contentSource$: Observable<ContentSource>;
|
||||
private subs: Subscription[] = [];
|
||||
private autoRefreshIDs: string[] = [];
|
||||
|
||||
testConfigRunning$ = new BehaviorSubject(false);
|
||||
importRunning$ = new BehaviorSubject(false);
|
||||
@@ -94,7 +95,10 @@ export class CollectionSourceControlsComponent implements OnDestroy {
|
||||
}),
|
||||
// filter out responses that aren't successful since the pinging of the process only needs to happen when the invocation was successful.
|
||||
filter((rd) => rd.hasSucceeded && hasValue(rd.payload)),
|
||||
switchMap((rd) => this.processDataService.autoRefreshUntilCompletion(rd.payload.processId)),
|
||||
switchMap((rd) => {
|
||||
this.autoRefreshIDs.push(rd.payload.processId);
|
||||
return this.processDataService.autoRefreshUntilCompletion(rd.payload.processId);
|
||||
}),
|
||||
map((rd) => rd.payload)
|
||||
).subscribe((process: Process) => {
|
||||
if (process.processStatus.toString() === ProcessStatus[ProcessStatus.FAILED].toString()) {
|
||||
@@ -135,7 +139,10 @@ export class CollectionSourceControlsComponent implements OnDestroy {
|
||||
}
|
||||
}),
|
||||
filter((rd) => rd.hasSucceeded && hasValue(rd.payload)),
|
||||
switchMap((rd) => this.processDataService.autoRefreshUntilCompletion(rd.payload.processId)),
|
||||
switchMap((rd) => {
|
||||
this.autoRefreshIDs.push(rd.payload.processId);
|
||||
return this.processDataService.autoRefreshUntilCompletion(rd.payload.processId);
|
||||
}),
|
||||
map((rd) => rd.payload)
|
||||
).subscribe((process) => {
|
||||
if (process.processStatus.toString() === ProcessStatus[ProcessStatus.FAILED].toString()) {
|
||||
@@ -170,7 +177,10 @@ export class CollectionSourceControlsComponent implements OnDestroy {
|
||||
}
|
||||
}),
|
||||
filter((rd) => rd.hasSucceeded && hasValue(rd.payload)),
|
||||
switchMap((rd) => this.processDataService.autoRefreshUntilCompletion(rd.payload.processId)),
|
||||
switchMap((rd) => {
|
||||
this.autoRefreshIDs.push(rd.payload.processId);
|
||||
return this.processDataService.autoRefreshUntilCompletion(rd.payload.processId);
|
||||
}),
|
||||
map((rd) => rd.payload)
|
||||
).subscribe((process) => {
|
||||
if (process.processStatus.toString() === ProcessStatus[ProcessStatus.FAILED].toString()) {
|
||||
@@ -191,5 +201,9 @@ export class CollectionSourceControlsComponent implements OnDestroy {
|
||||
sub.unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
this.autoRefreshIDs.forEach((id) => {
|
||||
this.processDataService.stopAutoRefreshing(id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, Inject, NgZone, OnInit, PLATFORM_ID } from '@angular/core';
|
||||
import { Component, Inject, NgZone, OnInit, PLATFORM_ID, OnDestroy } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { finalize, map, switchMap, take, tap, find, startWith } from 'rxjs/operators';
|
||||
@@ -36,7 +36,7 @@ import { PROCESS_PAGE_FOLLOW_LINKS } from '../process-page.resolver';
|
||||
/**
|
||||
* A component displaying detailed information about a DSpace Process
|
||||
*/
|
||||
export class ProcessDetailComponent implements OnInit {
|
||||
export class ProcessDetailComponent implements OnInit, OnDestroy {
|
||||
|
||||
/**
|
||||
* The AlertType enumeration
|
||||
@@ -80,6 +80,8 @@ export class ProcessDetailComponent implements OnInit {
|
||||
|
||||
isRefreshing$: Observable<boolean>;
|
||||
|
||||
protected autoRefreshingID: string;
|
||||
|
||||
/**
|
||||
* Reference to NgbModal
|
||||
*/
|
||||
@@ -108,7 +110,8 @@ export class ProcessDetailComponent implements OnInit {
|
||||
this.processRD$ = this.route.data.pipe(
|
||||
switchMap((data) => {
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
return this.processService.autoRefreshUntilCompletion(this.route.snapshot.params.id, 5000, ...PROCESS_PAGE_FOLLOW_LINKS);
|
||||
this.autoRefreshingID = this.route.snapshot.params.id;
|
||||
return this.processService.autoRefreshUntilCompletion(this.autoRefreshingID, 5000, ...PROCESS_PAGE_FOLLOW_LINKS);
|
||||
} else {
|
||||
return [data.process as RemoteData<Process>];
|
||||
}
|
||||
@@ -128,6 +131,15 @@ export class ProcessDetailComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the autoRefreshUntilCompletion is cleaned up properly
|
||||
*/
|
||||
ngOnDestroy() {
|
||||
if (hasValue(this.autoRefreshingID)) {
|
||||
this.processService.stopAutoRefreshing(this.autoRefreshingID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of a bitstream
|
||||
* @param bitstream
|
||||
|
Reference in New Issue
Block a user