Skip to content

Commit fa2f3e6

Browse files
committed
111638: Clean up autoRefreshing calls
1 parent 08299e5 commit fa2f3e6

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

src/app/collection-page/edit-collection-page/collection-source/collection-source-controls/collection-source-controls.component.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnDestroy } from '@angular/core';
1+
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
22
import { ScriptDataService } from '../../../../core/data/processes/script-data.service';
33
import { ContentSource } from '../../../../core/shared/content-source.model';
44
import { ProcessDataService } from '../../../../core/data/processes/process-data.service';
@@ -29,7 +29,7 @@ import { ContentSourceSetSerializer } from '../../../../core/shared/content-sour
2929
styleUrls: ['./collection-source-controls.component.scss'],
3030
templateUrl: './collection-source-controls.component.html',
3131
})
32-
export class CollectionSourceControlsComponent implements OnDestroy {
32+
export class CollectionSourceControlsComponent implements OnInit, OnDestroy {
3333

3434
/**
3535
* Should the controls be enabled.
@@ -48,6 +48,7 @@ export class CollectionSourceControlsComponent implements OnDestroy {
4848

4949
contentSource$: Observable<ContentSource>;
5050
private subs: Subscription[] = [];
51+
private autoRefreshIDs: string[] = [];
5152

5253
testConfigRunning$ = new BehaviorSubject(false);
5354
importRunning$ = new BehaviorSubject(false);
@@ -94,7 +95,10 @@ export class CollectionSourceControlsComponent implements OnDestroy {
9495
}),
9596
// filter out responses that aren't successful since the pinging of the process only needs to happen when the invocation was successful.
9697
filter((rd) => rd.hasSucceeded && hasValue(rd.payload)),
97-
switchMap((rd) => this.processDataService.autoRefreshUntilCompletion(rd.payload.processId)),
98+
switchMap((rd) => {
99+
this.autoRefreshIDs.push(rd.payload.processId);
100+
return this.processDataService.autoRefreshUntilCompletion(rd.payload.processId);
101+
}),
98102
map((rd) => rd.payload)
99103
).subscribe((process: Process) => {
100104
if (process.processStatus.toString() === ProcessStatus[ProcessStatus.FAILED].toString()) {
@@ -135,7 +139,10 @@ export class CollectionSourceControlsComponent implements OnDestroy {
135139
}
136140
}),
137141
filter((rd) => rd.hasSucceeded && hasValue(rd.payload)),
138-
switchMap((rd) => this.processDataService.autoRefreshUntilCompletion(rd.payload.processId)),
142+
switchMap((rd) => {
143+
this.autoRefreshIDs.push(rd.payload.processId);
144+
return this.processDataService.autoRefreshUntilCompletion(rd.payload.processId);
145+
}),
139146
map((rd) => rd.payload)
140147
).subscribe((process) => {
141148
if (process.processStatus.toString() === ProcessStatus[ProcessStatus.FAILED].toString()) {
@@ -170,7 +177,10 @@ export class CollectionSourceControlsComponent implements OnDestroy {
170177
}
171178
}),
172179
filter((rd) => rd.hasSucceeded && hasValue(rd.payload)),
173-
switchMap((rd) => this.processDataService.autoRefreshUntilCompletion(rd.payload.processId)),
180+
switchMap((rd) => {
181+
this.autoRefreshIDs.push(rd.payload.processId);
182+
return this.processDataService.autoRefreshUntilCompletion(rd.payload.processId);
183+
}),
174184
map((rd) => rd.payload)
175185
).subscribe((process) => {
176186
if (process.processStatus.toString() === ProcessStatus[ProcessStatus.FAILED].toString()) {
@@ -191,5 +201,9 @@ export class CollectionSourceControlsComponent implements OnDestroy {
191201
sub.unsubscribe();
192202
}
193203
});
204+
205+
this.autoRefreshIDs.forEach((id) => {
206+
this.processDataService.stopAutoRefreshing(id);
207+
});
194208
}
195209
}

src/app/process-page/detail/process-detail.component.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpClient } from '@angular/common/http';
2-
import { Component, Inject, NgZone, OnInit, PLATFORM_ID } from '@angular/core';
2+
import { Component, Inject, NgZone, OnInit, PLATFORM_ID, OnDestroy } from '@angular/core';
33
import { ActivatedRoute, Router } from '@angular/router';
44
import { BehaviorSubject, Observable } from 'rxjs';
55
import { finalize, map, switchMap, take, tap, find, startWith } from 'rxjs/operators';
@@ -36,7 +36,7 @@ import { PROCESS_PAGE_FOLLOW_LINKS } from '../process-page.resolver';
3636
/**
3737
* A component displaying detailed information about a DSpace Process
3838
*/
39-
export class ProcessDetailComponent implements OnInit {
39+
export class ProcessDetailComponent implements OnInit, OnDestroy {
4040

4141
/**
4242
* The AlertType enumeration
@@ -80,6 +80,8 @@ export class ProcessDetailComponent implements OnInit {
8080

8181
isRefreshing$: Observable<boolean>;
8282

83+
protected autoRefreshingID: string;
84+
8385
/**
8486
* Reference to NgbModal
8587
*/
@@ -108,7 +110,8 @@ export class ProcessDetailComponent implements OnInit {
108110
this.processRD$ = this.route.data.pipe(
109111
switchMap((data) => {
110112
if (isPlatformBrowser(this.platformId)) {
111-
return this.processService.autoRefreshUntilCompletion(this.route.snapshot.params.id, 5000, ...PROCESS_PAGE_FOLLOW_LINKS);
113+
this.autoRefreshingID = this.route.snapshot.params.id;
114+
return this.processService.autoRefreshUntilCompletion(this.autoRefreshingID, 5000, ...PROCESS_PAGE_FOLLOW_LINKS);
112115
} else {
113116
return [data.process as RemoteData<Process>];
114117
}
@@ -128,6 +131,15 @@ export class ProcessDetailComponent implements OnInit {
128131
);
129132
}
130133

134+
/**
135+
* Make sure the autoRefreshUntilCompletion is cleaned up properly
136+
*/
137+
ngOnDestroy() {
138+
if (hasValue(this.autoRefreshingID)) {
139+
this.processService.stopAutoRefreshing(this.autoRefreshingID);
140+
}
141+
}
142+
131143
/**
132144
* Get the name of a bitstream
133145
* @param bitstream

0 commit comments

Comments
 (0)