[Library | develop]: resultLanding.component.ts: Added ContextsService and call to get public communities, and then filter out contexts (related to communities) of resultLandingInfo if they are hidden.

This commit is contained in:
Konstantina Galouni 2023-07-28 16:04:14 +03:00
parent 4e3df67f7e
commit a53c4e90d0
1 changed files with 50 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import {NumberUtils} from '../../utils/number-utils.class';
import {FullScreenModalComponent} from "../../utils/modal/full-screen-modal/full-screen-modal.component";
import {SdgFosSuggestComponent} from '../landing-utils/sdg-fos-suggest/sdg-fos-suggest.component';
import {LayoutService} from "../../dashboard/sharedComponents/sidebar/layout.service";
import {ContextsService} from "../../claims/claim-utils/service/contexts.service";
declare var ResizeObserver;
@ -174,6 +175,8 @@ export class ResultLandingComponent {
@ViewChild('fosFsModal') fosFsModal: FullScreenModalComponent;
public noCommunities: boolean = false;
private promise: Promise<void> = null;
private publicCommunities: string[] = [];
public rightSidebarOffcanvasClicked: boolean = false;
public egiTransferModalOpen = false;
@ -192,7 +195,8 @@ export class ResultLandingComponent {
private _location: Location,
private indexInfoService: IndexInfoService,
private userManagementService: UserManagementService,
private layoutService: LayoutService) {
private layoutService: LayoutService,
private _contextService: ContextsService) {
}
ngOnInit() {
@ -256,6 +260,7 @@ export class ResultLandingComponent {
this.type="publication";
}
if ((this.id && StringUtils.isOpenAIREID(this.id)) || (this.identifier)) {
this.getPublicCommunities();
this.getVocabulariesAndResultLandingInfo();
} else {
this.showLoading = false;
@ -496,7 +501,10 @@ export class ResultLandingComponent {
this.resultLandingInfo = null;
this.hasAltMetrics = false;
this.subscriptions.push(this._resultLandingService.getResultLandingInfo(this.id, this.identifier, this.type, subjectsVocabulary, this.properties).subscribe(
data => {
async data => {
let contexts = data.contexts;
data.contexts = [];
this.resultLandingInfo = data;
this.id = this.resultLandingInfo.objIdentifier;
//old
@ -552,7 +560,10 @@ export class ResultLandingComponent {
this.relatedClassFilters = [{"label": "All relations", "value": ""}];
if (this.resultLandingInfo.relatedClassFilters.size > 1) {
for (let relClass of this.resultLandingInfo.relatedClassFilters) {
this.relatedClassFilters.push({"label": HelperFunctions.getVocabularyLabel(relClass, this.relationsVocabulary), "value": relClass});
this.relatedClassFilters.push({
"label": HelperFunctions.getVocabularyLabel(relClass, this.relationsVocabulary),
"value": relClass
});
}
} else {
this.relatedClassFilters.pop();
@ -577,6 +588,14 @@ export class ResultLandingComponent {
this.setActiveTab();
this.cdr.detectChanges();
if (contexts) {
await this.promise;
if(this.publicCommunities && this.publicCommunities.length > 0) {
this.resultLandingInfo.contexts = contexts.filter(context => this.publicCommunities.includes(context.idContext));
this.cdr.detectChanges();
}
}
},
err => {
this.handleError("Error getting " + this.type + " for " + (this.id ? ("id: " + this.id) : ("pid: " + this.identifier.id + " ("+this.identifier.class+")")), err);
@ -593,6 +612,21 @@ export class ResultLandingComponent {
));
}
public getPublicCommunities() {
this.promise = new Promise<void>(resolve => {
this._contextService.getPublicCommunitiesByState().subscribe(
data => {
this.publicCommunities = data.map(value => value.id);
// this.publicCommunities = data;
resolve();
},
error => {
this.handleError("Error getting communities status", error);
resolve();
});
});
}
public metricsResults($event) {
this.totalViews = $event.totalViews;
this.totalDownloads = $event.totalDownloads;