Skip to content
Snippets Groups Projects
Commit 7e7fae01 authored by Andrew Kapuscinski's avatar Andrew Kapuscinski
Browse files

WS-922: properly unsubscribe from polled reqs and button back to active reqs page now...

parent aca3c3e5
No related branches found
No related tags found
1 merge request!955WS-922: properly unsubscribe from polled reqs and button back to active reqs page now...
Pipeline #5375 failed
......@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
*/
import { Component, OnInit } from "@angular/core";
import { Component, OnInit, OnDestroy } from "@angular/core";
import { Title } from "@angular/platform-browser";
import { ActivatedRoute, Router, Params } from "@angular/router";
import { Capability } from "../../model/capability";
......@@ -40,7 +40,7 @@ export const defaultSortOrder = "desc"
templateUrl: "./active-capability-requests.component.html",
styleUrls: ["./active-capability-requests.component.scss"],
})
export class ActiveCapabilityRequestsComponent implements OnInit {
export class ActiveCapabilityRequestsComponent implements OnInit, OnDestroy {
public title = 'Active Capability Requests';
public activeCapabilityRequests: Array<CapabilityRequest>;
public capability: Capability;
......@@ -123,7 +123,7 @@ export class ActiveCapabilityRequestsComponent implements OnInit {
}
// to signal when all subscribers should unsubscribe (triggered in tear down)
private subscribeFlag = new Subject<boolean>();
private ngUnsubscribe = new Subject();
constructor(
private capabilityRequestService: CapabilityRequestService,
......@@ -158,8 +158,8 @@ export class ActiveCapabilityRequestsComponent implements OnInit {
this.pollingDataUpdaterService
.getDataPoller$(this.dataRetriever.getCapabilityUrl(this.capabilityName)).pipe(
takeUntil(this.subscribeFlag),
repeatWhen(() => this.subscribeFlag)
takeUntil(this.ngUnsubscribe),
repeatWhen(() => this.ngUnsubscribe)
)
.subscribe(this.capabilityObserver);
......@@ -323,18 +323,18 @@ export class ActiveCapabilityRequestsComponent implements OnInit {
public toggleSRDPCompatibility(request_id: string, version_id: number, isSRDP: boolean): void {
// stop polling when user clicks checkbox
this.subscribeFlag.next(false);
this.ngUnsubscribe.next(false);
const toggleSRDPCompatibilityObservable = {
next: (request) => {
// start polling again after SRDP status has changed
// TODO: success message to user
this.subscribeFlag.next(true);
this.ngUnsubscribe.next(true);
},
error: (error) => {
console.error("Error when toggling SRDP-Compatibility:", error);
// start polling again with SRDP status unchanged
// TODO: error message to user
this.subscribeFlag.next(true);
this.ngUnsubscribe.next(true);
},
};
this.capabilityRequestService
......@@ -363,18 +363,18 @@ export class ActiveCapabilityRequestsComponent implements OnInit {
public setStaff(requestId: string, staffMember: Staff): void {
// stop polling when user opens dropdown
this.subscribeFlag.next(false);
this.ngUnsubscribe.next(false);
const assignQaStaffObservable = {
next: () => {
// start polling again when user selects qa staff and req is successful
// TODO: success message to user
this.subscribeFlag.next(true);
this.ngUnsubscribe.next(true);
},
error: (error) => {
console.error("Error when setting" + staffMember.group + ", error: ", error);
// start polling again when user selects qa staff and req fails
// TODO: error message to user
this.subscribeFlag.next(true);
this.ngUnsubscribe.next(true);
},
};
this.capabilityRequestService.assignQaStaff(requestId, staffMember).subscribe(assignQaStaffObservable);
......@@ -382,7 +382,7 @@ export class ActiveCapabilityRequestsComponent implements OnInit {
// pause polling when user opens qa staff dropdown
public pausePolling(isDropdownOpen: Event): void {
isDropdownOpen ? this.subscribeFlag.next(false) : this.subscribeFlag.next(true);
isDropdownOpen ? this.ngUnsubscribe.next(false) : this.ngUnsubscribe.next(true);
}
public clearStaff(requestId: string, group: string): void {
......@@ -397,8 +397,8 @@ export class ActiveCapabilityRequestsComponent implements OnInit {
return this.pollingDataUpdaterService
.getDataPoller$(this.capabilityRequestService.getActiveCapabilityRequestsUrl(this.capabilityName, this.filters))
.pipe(
takeUntil(this.subscribeFlag),
repeatWhen(() => this.subscribeFlag),
takeUntil(this.ngUnsubscribe),
repeatWhen(() => this.ngUnsubscribe),
);
}
......@@ -504,4 +504,9 @@ export class ActiveCapabilityRequestsComponent implements OnInit {
this.filterSets[filter.filter]
}
ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
......@@ -46,14 +46,13 @@ export class CapabilityRequestComponent implements OnInit, OnDestroy {
public capabilityExecution: CapabilityExecution;
public currentVersion: CapabilityVersion;
public latestVersion: CapabilityVersion;
public linkToPrevUrl: string
public previousUrlString: string
activeRequestsPageDefaultUrl: string = "/workspaces/active-requests"
previousUrl: Observable<string> = this.urlService.previousUrl$;
// public qaNotes: string;
private ngUnsubscribe = new Subject(); // to signal when all subscribers should unsubscribe (triggered in tear down)
private subscribeFlag = new Subject<boolean>();
// Observer for capability request objects
private capabilityRequestObserver = {
......@@ -137,15 +136,15 @@ export class CapabilityRequestComponent implements OnInit, OnDestroy {
this.pollingDataUpdaterService
.getDataPoller$(this.capabilityRequestService.getCapabilityRequestURL(requestID))
.pipe(
takeUntil(this.subscribeFlag || this.ngUnsubscribe),
repeatWhen(() => this.subscribeFlag)
takeUntil(this.ngUnsubscribe),
repeatWhen(() => this.ngUnsubscribe)
)
.subscribe(this.capabilityRequestObserver);
this.pollingDataUpdaterService
.getDataPoller$(this.capabilityRequestService.getLatestVersionURL(requestID))
.pipe(
takeUntil(this.subscribeFlag || this.ngUnsubscribe),
repeatWhen(() => this.subscribeFlag)
takeUntil(this.ngUnsubscribe),
repeatWhen(() => this.ngUnsubscribe)
)
.subscribe(this.capabilityVersionObserver);
}
......@@ -179,7 +178,7 @@ export class CapabilityRequestComponent implements OnInit, OnDestroy {
catchOpenEditorEventFromChild(isEditorOpen: boolean): void {
let shouldPausePoller = !isEditorOpen
this.subscribeFlag.next(shouldPausePoller);
this.ngUnsubscribe.next(shouldPausePoller);
}
/**
......@@ -196,12 +195,14 @@ export class CapabilityRequestComponent implements OnInit, OnDestroy {
}
public goToActiveRequestsPage() {
this.router.navigateByUrl(this.linkToPrevUrl)
this.ngOnDestroy()
this.previousUrlString = (this.previousUrlString) ? this.previousUrlString : `${this.activeRequestsPageDefaultUrl}?capability=${this.capabilityRequest.capability_name}`
this.router.navigateByUrl(this.previousUrlString)
}
ngOnInit(): void {
this.urlService.previousUrl$.subscribe((previousUrl: string) => {
this.linkToPrevUrl = (previousUrl) ? previousUrl : this.activeRequestsPageDefaultUrl
this.previousUrlString = previousUrl
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment