From 9da11820aae008ed738db178fc7cdce7d22a0de3 Mon Sep 17 00:00:00 2001 From: Alex Martzios Date: Fri, 8 Oct 2021 15:00:24 +0300 Subject: [PATCH] Landing page: add link to RC dashboards in community context --- .../landing-utils/relatedTo.component.ts | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/landingPages/landing-utils/relatedTo.component.ts b/landingPages/landing-utils/relatedTo.component.ts index f03fee38..4bbfbfac 100644 --- a/landingPages/landing-utils/relatedTo.component.ts +++ b/landingPages/landing-utils/relatedTo.component.ts @@ -1,4 +1,11 @@ import {Component, Input} from '@angular/core'; +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'; import {HelperFunctions} from "../../utils/HelperFunctions.class"; @Component({ @@ -7,7 +14,10 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class";
Communities
- {{item['labelContext']}} + {{item['labelContext']}} + + {{item['labelContext']}} + {{item['labelCategory']}} : {{item['labelConcept']}} @@ -27,16 +37,51 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class"; }) export class RelatedToComponent { - @Input() contexts: { "labelContext": string, "labelCategory": string, "labelConcept": string }[]; + @Input() contexts: { "idContext": string, "labelContext": string, "labelCategory": string, "labelConcept": string, "link": string }[]; public threshold: number = 5; public showNum: number = 5; + private subscriptions = []; - constructor() { + constructor(private communityService: CommunityService, + private userManagementService: UserManagementService) { } ngOnInit() { + this.contexts.forEach( context => { + if(context.idContext) { + this.subscriptions.push( + this.userManagementService.getUserInfo().subscribe( user => { + //- handling subscribe errors? + this.subscriptions.push( + this.communityService.getCommunity(context.idContext).subscribe( community => { + // swap the == of the last condition to != // testing this way for now + if(community && !ConnectHelper.isPrivate(community,user) && (ConnectHelper.getCommunityFromDomain(properties.domain) != context.idContext)) { + // creating the link, based on the enviroment + let url = ''; + if(properties.environment == "beta") { + url = 'https://beta.' + context.idContext + '.openaire.eu'; + } else { + url = 'https://' + context.idContext + '.openaire.eu'; + } + console.log(url); + context.link = url; + } + }) + ); + }) + ); + } + }); } + + ngOnDestroy() { + this.subscriptions.forEach(subscription => { + if(subscription instanceof Subscriber) { + subscription.unsubscribe(); + } + }); + } public scroll() { HelperFunctions.scroll();