2021-11-08 16:24:32 +01:00
|
|
|
import {Component, Input, OnInit} 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";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'relatedTo',
|
|
|
|
template: `
|
2021-11-24 15:52:58 +01:00
|
|
|
<div *ngIf="(gateways && gateways.length > 0) || (otherCommunities && otherCommunities.length > 0)" class="sideInfoTitle">
|
2021-11-23 09:44:36 +01:00
|
|
|
<span>Communities</span>
|
|
|
|
</div>
|
|
|
|
<!-- If there are any communities with dashboard -->
|
|
|
|
<ng-container *ngIf="gateways && gateways.length > 0">
|
2021-11-25 10:57:49 +01:00
|
|
|
<div class="uk-padding-small uk-flex">
|
2021-11-23 09:44:36 +01:00
|
|
|
<div class="uk-width-2-3">
|
|
|
|
<div class="uk-text-muted">Communities with gateway</div>
|
|
|
|
<ul class="custom-list">
|
|
|
|
<li *ngFor="let gateway of gateways">
|
|
|
|
<a href="{{gateway.link}}" target="_blank" [attr.uk-tooltip]="gateway.labelContext">
|
|
|
|
{{ gateway.labelContext.length > 26 ? gateway.labelContext.substr(0,25) + '…' : gateway.labelContext }}
|
|
|
|
<span class="custom-external custom-icon space"></span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="uk-width-1-3 uk-position-relative">
|
|
|
|
<img class="uk-position-bottom-right connect-image" src="assets/common-assets/connect_image_faded.png" alt="OpenAIRE Connect image">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ng-container>
|
|
|
|
<!-- Other communities (without dashboards) -->
|
|
|
|
<ng-container *ngIf="otherCommunities && otherCommunities.length > 0">
|
|
|
|
<div class="uk-padding-small border-top">
|
|
|
|
<div>
|
|
|
|
<div *ngIf="gateways && gateways.length > 0" class="uk-text-muted">Other Communities</div>
|
|
|
|
<ul class="custom-list" [ngClass]="{'uk-padding-remove uk-margin-remove': !gateways || gateways.length == 0}">
|
2021-11-25 10:57:49 +01:00
|
|
|
<li *ngFor="let community of otherCommunities.slice(0, showNum); let i = index">
|
2021-11-23 09:44:36 +01:00
|
|
|
{{community.labelContext}}
|
2021-11-23 12:50:44 +01:00
|
|
|
<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>
|
2021-11-23 09:44:36 +01:00
|
|
|
</li>
|
2021-11-25 10:57:49 +01:00
|
|
|
<div *ngIf="showNum > threshold" class="uk-text-right">
|
|
|
|
<a (click)="showNum = threshold;">View less</a>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="otherCommunities.length > threshold && showNum == threshold" class="uk-text-right">
|
|
|
|
<a (click)="showNum = otherCommunities.length;">View more</a>
|
|
|
|
</div>
|
2021-11-23 09:44:36 +01:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ng-container>
|
2019-10-02 16:20:34 +02:00
|
|
|
`
|
|
|
|
})
|
|
|
|
|
2021-11-08 16:24:32 +01:00
|
|
|
export class RelatedToComponent implements OnInit {
|
|
|
|
@Input() contexts: { "idContext": string, "labelContext": string, "labelCategory": string, "labelConcept": string, "link": string, "logo": string }[];
|
|
|
|
|
2021-11-25 10:57:49 +01:00
|
|
|
public threshold: number = 3;
|
|
|
|
public showNum: number = 3;
|
2021-11-08 16:24:32 +01:00
|
|
|
public gateways = [];
|
2021-11-23 09:44:36 +01:00
|
|
|
public otherCommunities = [];
|
2021-11-23 12:50:44 +01:00
|
|
|
public currentCommunity = ConnectHelper.getCommunityFromDomain(properties.domain);
|
2021-10-08 14:00:24 +02:00
|
|
|
private subscriptions = [];
|
2020-03-16 14:09:46 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
for(let gateway of this.gateways) {
|
|
|
|
if(gateway.link == context.link) {
|
|
|
|
return; // skips so that we don't get duplicate gateways
|
2021-11-23 09:44:36 +01:00
|
|
|
}
|
2021-10-08 14:00:24 +02:00
|
|
|
}
|
2021-11-24 15:52:58 +01:00
|
|
|
this.gateways.push(context);
|
|
|
|
} else {
|
|
|
|
if(this.currentCommunity != context.idContext) {
|
|
|
|
for(let other of this.otherCommunities) {
|
|
|
|
if(other.idContext == context.idContext) {
|
|
|
|
return; // skips so that we don't get duplicate communities because of the multiple concepts
|
|
|
|
}
|
|
|
|
}
|
2021-11-10 14:08:09 +01:00
|
|
|
}
|
2021-11-24 15:52:58 +01:00
|
|
|
this.otherCommunities.push(context);
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
if(index == this.contexts.length) {
|
|
|
|
this.gateways.sort(this.compare);
|
|
|
|
this.otherCommunities.sort(this.compare);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
|
|
|
|
public compare(a, b) {
|
|
|
|
if(a.labelContext < b.labelContext) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(a.labelContext > b.labelContext) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2019-10-02 16:20:34 +02:00
|
|
|
}
|