[new-UI | Library]: displayClaims.component.ts: Added property "subResults" for subscription of getClaims methods in ClaimsService, to unsubscribe (cancel old request) when new request comes.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60712 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2021-03-24 10:00:30 +00:00
parent 553472cb34
commit aa637e73ea
1 changed files with 17 additions and 10 deletions

View File

@ -34,6 +34,7 @@ export class DisplayClaimsComponent {
properties: EnvProperties;
public searchTermStream = new Subject<string>();
subscriptions: any = [];
public subResults: any;
//string because comes as input from component directive
@Input() enableDelete: boolean = false;
@Input() showUserEmail: boolean = true;
@ -175,6 +176,9 @@ export class DisplayClaimsComponent {
subscription.unsubscribe();
}
});
if(this.subResults){
this.subResults.unsubscribe();
}
}
getClaims() {
@ -195,8 +199,11 @@ export class DisplayClaimsComponent {
types += (this.entitiesCtrl.getRawValue().length > 0 ? '&' : '') + "types=" + type.id;
}
this.pageLoading = true;
if(this.subResults){
this.subResults.unsubscribe();
}
if (this.fetchBy == "Project") {
this.subscriptions.push(this._claimService.getClaimsByProject(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
this.subResults = this._claimService.getClaimsByProject(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
data => {
this.manageAPIData(data);
this.pageLoading = false;
@ -204,9 +211,9 @@ export class DisplayClaimsComponent {
err => {
this.handleErrors(err, "Error getting claims for project with id: " + this.fetchId);
}
));
);
} else if (this.fetchBy == "User") {
this.subscriptions.push(this._claimService.getClaimsByUser(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
this.subResults = this._claimService.getClaimsByUser(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
data => {
this.manageAPIData(data);
this.pageLoading = false;
@ -215,9 +222,9 @@ export class DisplayClaimsComponent {
this.handleErrors(err, "Error getting claims for user with id: " + this.fetchId);
this.pageLoading = false;
}
));
);
} else if (this.fetchBy == "Result") {
this.subscriptions.push(this._claimService.getClaimsByResult(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
this.subResults = this._claimService.getClaimsByResult(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
data => {
this.manageAPIData(data);
this.pageLoading = false;
@ -226,9 +233,9 @@ export class DisplayClaimsComponent {
this.handleErrors(err, "Error getting claims for entity with id: " + this.fetchId);
this.pageLoading = false;
}
));
);
} else if (this.fetchBy == "Context") {
this.subscriptions.push(this._claimService.getClaimsBycontext(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
this.subResults = this._claimService.getClaimsBycontext(this.size, this.page, this.fetchId, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
data => {
this.manageAPIData(data);
this.pageLoading = false;
@ -237,9 +244,9 @@ export class DisplayClaimsComponent {
this.handleErrors(err, "Error getting claims for context with id: " + this.fetchId);
this.pageLoading = false;
}
));
);
} else {
this.subscriptions.push(this._claimService.getClaims(this.size, this.page, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
this.subResults = this._claimService.getClaims(this.size, this.page, this.keyword, this.filterForm.get("sort").value.sort, this.filterForm.get("sort").value.descending, types, this.properties.claimsAPIURL).subscribe(
data => {
this.manageAPIData(data);
this.pageLoading = false;
@ -248,7 +255,7 @@ export class DisplayClaimsComponent {
this.handleErrors(err, "Error getting claims");
this.pageLoading = false;
}
));
);
}
}
}