2022-04-12 14:15:04 +02:00
|
|
|
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
2021-10-08 14:00:24 +02:00
|
|
|
import {Subscriber} from 'rxjs';
|
|
|
|
import {properties} from 'src/environments/environment';
|
|
|
|
|
|
|
|
import {CommunityService} from '../../connect/community/community.service';
|
|
|
|
import {ConnectHelper} from '../../connect/connectHelper';
|
|
|
|
import {UserManagementService} from '../../services/user-management.service';
|
2019-10-02 16:20:34 +02:00
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
2022-04-12 14:15:04 +02:00
|
|
|
import {Context} from "../../utils/entities/resultLandingInfo";
|
|
|
|
import {OpenaireEntities} from "../../utils/properties/searchFields";
|
2019-10-02 16:20:34 +02:00
|
|
|
|
|
|
|
@Component({
|
2022-04-12 14:15:04 +02:00
|
|
|
selector: 'relatedTo, [relatedTo]',
|
2019-10-02 16:20:34 +02:00
|
|
|
template: `
|
2022-04-12 14:15:04 +02:00
|
|
|
<ng-container *ngIf="communities && communities.length > 0">
|
2023-02-20 16:56:02 +01:00
|
|
|
<div *ngIf="!mobileView" class="uk-margin-small-bottom uk-flex uk-flex-between">
|
2022-04-12 14:15:04 +02:00
|
|
|
<span *ngIf="viewAll && !lessBtn" class="clickable uk-h6 uk-flex uk-flex-middle" (click)="viewLessClick()">
|
|
|
|
<icon class="uk-margin-small-right" name="arrow_back" flex="true" ratio="1.2"></icon>
|
|
|
|
{{title}}
|
|
|
|
</span>
|
2023-01-13 14:57:26 +01:00
|
|
|
<span *ngIf="!viewAll || lessBtn" class="uk-text-emphasis uk-text-bolder">{{title}}</span>
|
2023-02-21 02:01:21 +01:00
|
|
|
<a *ngIf="viewAll && lessBtn" (click)="viewAll = !viewAll; lessBtn=false;" class="view-more-less-link uk-link-text">View less</a>
|
2022-04-12 14:15:04 +02:00
|
|
|
<a *ngIf="communities && communities.length > threshold && !viewAll"
|
2023-02-21 02:01:21 +01:00
|
|
|
(click)="viewAllClick();" class="view-more-less-link uk-link-text">View all</a>
|
2022-04-12 14:15:04 +02:00
|
|
|
</div>
|
2023-02-20 16:56:02 +01:00
|
|
|
<div *ngFor="let community of communities.slice(0, viewAll?communities.length:threshold)" class="uk-text-truncate"
|
|
|
|
[class.uk-margin-small-bottom]="mobileView">
|
2022-04-12 14:15:04 +02:00
|
|
|
<!-- If there are any communities with dashboard -->
|
2022-04-16 09:47:30 +02:00
|
|
|
<a *ngIf="community.link" href="{{community.link}}" target="_blank" [attr.uk-tooltip]="community.labelContext" class="custom-external">
|
2022-04-12 14:15:04 +02:00
|
|
|
{{community.labelContext}}
|
|
|
|
</a>
|
|
|
|
<!-- Other communities (without dashboards) -->
|
|
|
|
<ng-container *ngIf="!community.link">
|
|
|
|
{{community.labelContext}}
|
|
|
|
<span *ngIf="community.labelCategory && (currentCommunity == community.idContext)">
|
|
|
|
<span uk-icon="icon: arrow-right"></span> {{community.labelCategory}}
|
|
|
|
</span>
|
|
|
|
<span *ngIf="community.labelConcept && (currentCommunity == community.idContext)">
|
|
|
|
: {{community.labelConcept}}
|
|
|
|
</span>
|
|
|
|
</ng-container>
|
|
|
|
</div>
|
|
|
|
</ng-container>
|
2019-10-02 16:20:34 +02:00
|
|
|
`
|
|
|
|
})
|
|
|
|
|
2021-11-08 16:24:32 +01:00
|
|
|
export class RelatedToComponent implements OnInit {
|
2023-02-20 16:56:02 +01:00
|
|
|
@Input() mobileView: boolean = false;
|
2022-04-12 14:15:04 +02:00
|
|
|
@Input() contexts: Context[];
|
|
|
|
@Input() viewAll: boolean = false;
|
|
|
|
@Output() viewAllClicked = new EventEmitter();
|
|
|
|
@Output() noCommunities = new EventEmitter();
|
|
|
|
public lessBtn: boolean = false;
|
|
|
|
public threshold: number = 4;
|
|
|
|
public communities: Context[] = [];
|
2021-11-23 12:50:44 +01:00
|
|
|
public currentCommunity = ConnectHelper.getCommunityFromDomain(properties.domain);
|
2021-10-08 14:00:24 +02:00
|
|
|
private subscriptions = [];
|
2022-04-12 14:15:04 +02:00
|
|
|
public title: string = "Related to "+OpenaireEntities.COMMUNITIES;
|
|
|
|
|
2021-10-08 14:00:24 +02:00
|
|
|
constructor(private communityService: CommunityService,
|
|
|
|
private userManagementService: UserManagementService) {
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-11-10 14:08:09 +01:00
|
|
|
this.contexts.sort(this.compare);
|
2021-11-24 15:52:58 +01:00
|
|
|
let index = 0;
|
|
|
|
this.contexts.forEach( context => {
|
|
|
|
if(context.idContext) {
|
|
|
|
this.subscriptions.push(
|
|
|
|
this.userManagementService.getUserInfo().subscribe( user => {
|
|
|
|
//- handling subscribe errors?
|
|
|
|
this.subscriptions.push(
|
2021-11-30 17:21:35 +01:00
|
|
|
this.communityService.getCommunityInfo(context.idContext).subscribe( community => {
|
2021-11-24 15:52:58 +01:00
|
|
|
if(community && !ConnectHelper.isPrivate(community,user) && (this.currentCommunity != context.idContext)) {
|
|
|
|
if(properties.environment == "beta") {
|
2021-11-30 17:21:35 +01:00
|
|
|
context.link = 'https://beta.' + context.idContext + '.openaire.eu';
|
2021-11-23 09:44:36 +01:00
|
|
|
} else {
|
2021-11-30 17:21:35 +01:00
|
|
|
context.link = 'https://' + context.idContext + '.openaire.eu';
|
2021-11-24 15:52:58 +01:00
|
|
|
}
|
|
|
|
}
|
2022-04-12 14:15:04 +02:00
|
|
|
for(let community of this.communities) {
|
|
|
|
if(community.link == context.link) {
|
|
|
|
index++;
|
|
|
|
if(index == this.contexts.length) {
|
|
|
|
this.communitiesInitialized();
|
|
|
|
}
|
|
|
|
return; // skips so that we don't get duplicate gateways
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.communities.push(context);
|
2021-11-24 15:52:58 +01:00
|
|
|
index++;
|
|
|
|
if(index == this.contexts.length) {
|
2022-04-12 14:15:04 +02:00
|
|
|
this.communitiesInitialized();
|
2021-11-24 15:52:58 +01:00
|
|
|
}
|
2022-04-12 14:15:04 +02:00
|
|
|
}, error => {
|
|
|
|
index++;
|
|
|
|
if(index == this.contexts.length) {
|
|
|
|
this.communitiesInitialized();
|
|
|
|
}
|
|
|
|
})
|
2021-11-24 15:52:58 +01:00
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
2021-10-08 14:00:24 +02:00
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if(subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
2019-10-02 16:20:34 +02:00
|
|
|
public scroll() {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
}
|
2021-11-10 14:08:09 +01:00
|
|
|
|
2022-04-12 14:15:04 +02:00
|
|
|
public communitiesInitialized() {
|
|
|
|
if(this.communities.length == 0) {
|
|
|
|
this.noCommunities.emit(true);
|
|
|
|
}
|
|
|
|
this.communities.sort(this.compare);
|
|
|
|
}
|
|
|
|
|
2021-11-10 14:08:09 +01:00
|
|
|
public compare(a, b) {
|
2022-04-12 14:15:04 +02:00
|
|
|
if (a.link && !b.link) {
|
|
|
|
return -1;
|
|
|
|
} else if(!a.link && b.link) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (a.labelContext < b.labelContext) {
|
|
|
|
return -1;
|
|
|
|
} else if (a.labelContext > b.labelContext) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2021-11-10 14:08:09 +01:00
|
|
|
}
|
2022-04-12 14:15:04 +02:00
|
|
|
|
|
|
|
public viewAllClick() {
|
|
|
|
if(this.communities.length <= this.threshold*2) {
|
|
|
|
this.viewAll = true;
|
|
|
|
this.lessBtn = true;
|
|
|
|
} else {
|
|
|
|
this.viewAll = true;
|
|
|
|
this.viewAllClicked.emit('relatedTo');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public viewLessClick() {
|
|
|
|
this.viewAll = false;
|
|
|
|
this.viewAllClicked.emit("");
|
|
|
|
}
|
2019-10-02 16:20:34 +02:00
|
|
|
}
|