2023-04-26 13:27:41 +02:00
|
|
|
import {Component, Input} from '@angular/core';
|
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {AffiliationService} from "../openaireLibrary/connect/affiliations/affiliation.service";
|
|
|
|
import {Affiliation} from "../openaireLibrary/utils/entities/CuratorInfo";
|
|
|
|
import {ConnectHelper} from "../openaireLibrary/connect/connectHelper";
|
2020-11-12 16:59:26 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2020-11-30 18:04:05 +01:00
|
|
|
import {properties} from "../../environments/environment";
|
2019-06-07 15:03:33 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'affiliations',
|
2022-06-16 14:01:41 +02:00
|
|
|
templateUrl: './affiliations.component.html',
|
2023-04-26 13:27:41 +02:00
|
|
|
styleUrls: ['./affiliations.component.less']
|
2019-06-07 15:03:33 +02:00
|
|
|
})
|
|
|
|
export class AffiliationsComponent {
|
|
|
|
@Input() getAffiliationsFromAPI: boolean = false;
|
2019-08-26 14:21:13 +02:00
|
|
|
@Input() longView: boolean = false;
|
2019-06-10 17:48:29 +02:00
|
|
|
@Input() communityFirstPage: boolean = false;
|
2019-06-07 15:03:33 +02:00
|
|
|
@Input() affiliationsInSlider: number = 5;
|
|
|
|
@Input() affiliations: Affiliation[] = [];
|
2019-06-08 19:24:03 +02:00
|
|
|
@Input() sliderOptions = '';
|
|
|
|
@Input() arrows = true;
|
2023-04-26 13:27:41 +02:00
|
|
|
|
2019-06-10 17:48:29 +02:00
|
|
|
public showLoading: boolean = false;
|
2023-04-26 13:27:41 +02:00
|
|
|
public communityId: string;
|
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
private subscriptions = [];
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute, private affiliationService: AffiliationService) {
|
|
|
|
}
|
|
|
|
|
2019-06-07 15:03:33 +02:00
|
|
|
public ngOnInit() {
|
2023-04-26 13:27:41 +02:00
|
|
|
this.communityId = ConnectHelper.getCommunityFromDomain(properties.domain);
|
|
|
|
if (this.getAffiliationsFromAPI) {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.affiliationService.initAffiliations(this.communityId);
|
|
|
|
this.subscriptions.push(this.affiliationService.affiliations.subscribe(
|
|
|
|
affiliations => {
|
|
|
|
this.affiliations = affiliations.filter((affiliation) => this.longView || !!affiliation['logo_url']);
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
console.error("Affiliations Component: Error getting affiliations for community with id: " + this.communityId, error);
|
|
|
|
this.showLoading = false;
|
2020-11-30 18:04:05 +01:00
|
|
|
}
|
2023-04-26 13:27:41 +02:00
|
|
|
));
|
|
|
|
}
|
2019-06-07 15:03:33 +02:00
|
|
|
}
|
2023-04-26 13:27:41 +02:00
|
|
|
|
2020-11-12 16:59:26 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.affiliationService.clearSubscriptions();
|
2019-08-02 16:56:03 +02:00
|
|
|
}
|
2019-06-07 15:03:33 +02:00
|
|
|
}
|