2022-06-03 16:22:41 +02:00
|
|
|
import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core';
|
2019-06-05 15:39:02 +02:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {Meta, Title} from '@angular/platform-browser';
|
|
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service';
|
|
|
|
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
|
2018-03-14 14:28:45 +01:00
|
|
|
|
2019-06-05 15:39:02 +02:00
|
|
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
|
|
|
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
2019-04-08 14:17:39 +02:00
|
|
|
|
2019-06-05 15:39:02 +02:00
|
|
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
|
2019-07-18 13:36:05 +02:00
|
|
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
2019-08-02 16:56:03 +02:00
|
|
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
2020-09-18 15:27:26 +02:00
|
|
|
import {properties} from "../../environments/environment";
|
2020-11-12 16:59:26 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2022-01-20 00:15:04 +01:00
|
|
|
import {Session, User} from "../openaireLibrary/login/utils/helper.class";
|
|
|
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
2022-06-02 16:30:48 +02:00
|
|
|
import {QuickContactService} from "../openaireLibrary/sharedComponents/quick-contact/quick-contact.service";
|
2022-06-17 18:49:40 +02:00
|
|
|
import {StakeholderInfo} from "../openaireLibrary/monitor/entities/stakeholder";
|
|
|
|
import {OpenaireEntities} from "../openaireLibrary/utils/properties/searchFields";
|
2018-03-14 14:28:45 +01:00
|
|
|
|
2018-01-26 16:00:07 +01:00
|
|
|
@Component({
|
2019-07-18 13:36:05 +02:00
|
|
|
selector: 'communities',
|
|
|
|
templateUrl: 'communities.component.html',
|
2022-07-20 10:03:53 +02:00
|
|
|
styleUrls: ['communities.component.less']
|
2018-01-26 16:00:07 +01:00
|
|
|
})
|
2018-03-14 14:28:45 +01:00
|
|
|
|
2022-06-02 16:30:48 +02:00
|
|
|
export class CommunitiesComponent implements OnInit, OnDestroy, AfterViewInit {
|
2020-11-12 16:59:26 +01:00
|
|
|
private subscriptions = [];
|
2022-01-20 00:15:04 +01:00
|
|
|
private user: User;
|
2018-01-26 16:00:07 +01:00
|
|
|
public pageTitle = "OpenAIRE"
|
2021-11-12 11:56:15 +01:00
|
|
|
public researchCommunities: CommunityInfo[] = [];
|
2019-07-18 13:36:05 +02:00
|
|
|
public pageContents = null;
|
|
|
|
public divContents = null;
|
2019-04-08 14:17:39 +02:00
|
|
|
// Message variables
|
|
|
|
public status: number;
|
|
|
|
public loading: boolean = true;
|
2019-04-09 20:48:03 +02:00
|
|
|
public subscriberErrorMessage: string = "";
|
2019-04-08 14:17:39 +02:00
|
|
|
public errorCodes: ErrorCodes;
|
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2022-06-03 16:22:41 +02:00
|
|
|
@ViewChildren('scrolling_element') elements: QueryList<ElementRef>;
|
2022-06-02 16:30:48 +02:00
|
|
|
@ViewChild('contact') contact: ElementRef;
|
2022-06-17 18:49:40 +02:00
|
|
|
public entities = OpenaireEntities;
|
2022-06-02 16:30:48 +02:00
|
|
|
public properties: EnvProperties = properties;
|
2019-07-18 13:36:05 +02:00
|
|
|
public keyword: string = "";
|
|
|
|
public type: string = "all";
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private _router: Router,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
|
|
|
private _piwikService: PiwikService,
|
|
|
|
private _communitiesService: CommunitiesService,
|
2019-08-02 16:56:03 +02:00
|
|
|
private helper: HelperService,
|
2022-01-20 00:15:04 +01:00
|
|
|
private seoService: SEOService,
|
2022-06-02 16:30:48 +02:00
|
|
|
private userManagementService: UserManagementService,
|
|
|
|
private quickContactService: QuickContactService) {
|
2019-07-18 13:36:05 +02:00
|
|
|
|
|
|
|
var description = "OpenAIRE - Connect, Community Dashboard, research community";
|
|
|
|
var title = "OpenAIRE - Connect";
|
|
|
|
|
|
|
|
this._meta.updateTag({content: description}, "name='description'");
|
|
|
|
this._meta.updateTag({content: description}, "property='og:description'");
|
|
|
|
this._meta.updateTag({content: title}, "property='og:title'");
|
|
|
|
this._title.setTitle(title);
|
|
|
|
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.status = this.errorCodes.LOADING;
|
2023-07-07 09:12:25 +02:00
|
|
|
this.quickContactService.setDisplay(false);
|
2019-04-08 14:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2020-11-12 16:59:26 +01:00
|
|
|
var url = this.properties.domain + this.properties.baseLink + this._router.url;
|
|
|
|
this.seoService.createLinkForCanonicalURL(url, false);
|
|
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
2023-07-13 10:48:23 +02:00
|
|
|
this.subscriptions.push(this._piwikService.trackView(this.properties, "OpenAIRE Connect").subscribe());
|
2022-01-20 00:15:04 +01:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
|
|
|
this.user = user;
|
|
|
|
this.getCommunities();
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.getCommunities();
|
|
|
|
}));
|
2020-11-12 16:59:26 +01:00
|
|
|
//this.getDivContents();
|
|
|
|
this.getPageContents();
|
2019-07-18 13:36:05 +02:00
|
|
|
}
|
2022-06-02 16:30:48 +02:00
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
2023-07-17 11:41:32 +02:00
|
|
|
} else if ((typeof MutationObserver != 'undefined' && subscription instanceof MutationObserver) ||
|
|
|
|
(typeof IntersectionObserver != 'undefined' && subscription instanceof IntersectionObserver)) {
|
2023-07-07 09:12:25 +02:00
|
|
|
subscription.disconnect();
|
|
|
|
}
|
2022-06-02 16:30:48 +02:00
|
|
|
});
|
2023-07-07 09:12:25 +02:00
|
|
|
this.quickContactService.setDisplay(true);
|
2022-06-02 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2023-07-17 11:41:32 +02:00
|
|
|
if(typeof IntersectionObserver !== "undefined" && typeof MutationObserver !== "undefined") {
|
2022-06-02 16:30:48 +02:00
|
|
|
this.createObservers();
|
|
|
|
}
|
|
|
|
}
|
2018-01-26 16:00:07 +01:00
|
|
|
|
2019-07-18 18:03:37 +02:00
|
|
|
private getPageContents() {
|
2020-11-12 16:59:26 +01:00
|
|
|
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
2019-07-18 13:36:05 +02:00
|
|
|
this.pageContents = contents;
|
2020-11-12 16:59:26 +01:00
|
|
|
}));
|
2019-07-18 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 18:03:37 +02:00
|
|
|
private getDivContents() {
|
2020-11-12 16:59:26 +01:00
|
|
|
this.subscriptions.push(this.helper.getDivHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
2019-07-18 13:36:05 +02:00
|
|
|
this.divContents = contents;
|
2020-11-12 16:59:26 +01:00
|
|
|
}));
|
2019-07-18 13:36:05 +02:00
|
|
|
}
|
2022-06-02 16:30:48 +02:00
|
|
|
|
|
|
|
createObservers() {
|
|
|
|
let options = {
|
|
|
|
root: null,
|
|
|
|
rootMargin: '200px',
|
|
|
|
threshold: 1.0
|
|
|
|
};
|
|
|
|
let intersectionObserver = new IntersectionObserver(entries => {
|
|
|
|
entries.forEach(entry => {
|
2023-07-07 09:12:25 +02:00
|
|
|
this.quickContactService.setDisplay(!entry.isIntersecting);
|
2022-06-02 16:30:48 +02:00
|
|
|
});
|
|
|
|
}, options);
|
|
|
|
intersectionObserver.observe(this.contact.nativeElement);
|
2022-06-03 16:22:41 +02:00
|
|
|
let mutationObserver = new MutationObserver(entries => {
|
|
|
|
entries.forEach(entry => {
|
|
|
|
if (entry.attributeName === 'style') {
|
|
|
|
let opacities: number[] = this.elements.map(element => +element.nativeElement.style.opacity);
|
|
|
|
let active: number = opacities.indexOf(Math.max(...opacities));
|
|
|
|
this.elements.forEach((element, index) => {
|
|
|
|
if (index === active) {
|
|
|
|
element.nativeElement.classList.remove('uk-disabled');
|
|
|
|
} else {
|
|
|
|
element.nativeElement.classList.add('uk-disabled');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.elements.forEach(element => {
|
|
|
|
mutationObserver.observe(element.nativeElement, {attributes: true});
|
|
|
|
});
|
2022-06-02 16:30:48 +02:00
|
|
|
this.subscriptions.push(intersectionObserver);
|
2022-06-03 16:22:41 +02:00
|
|
|
this.subscriptions.push(mutationObserver);
|
2022-06-02 16:30:48 +02:00
|
|
|
}
|
2019-07-18 13:36:05 +02:00
|
|
|
|
|
|
|
public getCommunities() {
|
|
|
|
this.loading = true;
|
|
|
|
this.status = this.errorCodes.LOADING;
|
|
|
|
this.subscriberErrorMessage = "";
|
2019-04-08 14:17:39 +02:00
|
|
|
|
2019-07-18 13:36:05 +02:00
|
|
|
this.researchCommunities = [];
|
|
|
|
|
2020-11-12 16:59:26 +01:00
|
|
|
this.subscriptions.push(this._communitiesService.getCommunitiesState().subscribe(
|
2019-07-18 13:36:05 +02:00
|
|
|
communitiesResults => {
|
2022-06-03 16:22:41 +02:00
|
|
|
// console.log("getCommunitiesState", communitiesResults);
|
2022-01-20 00:15:04 +01:00
|
|
|
|
2019-07-30 10:59:40 +02:00
|
|
|
if(!communitiesResults){
|
|
|
|
return;
|
|
|
|
}
|
2019-07-30 17:25:30 +02:00
|
|
|
if(communitiesResults.length == 0) {
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
return;
|
|
|
|
}
|
2019-07-18 13:36:05 +02:00
|
|
|
this.sort(communitiesResults);
|
|
|
|
communitiesResults.forEach((community, index) => {
|
|
|
|
let showCommunity: boolean = true;
|
2022-01-20 00:15:04 +01:00
|
|
|
community.isSubscribed = Session.isSubscribedTo('community', community.communityId, this.user);
|
|
|
|
|
2023-07-19 13:21:39 +02:00
|
|
|
if (community.isPrivate() || community.isRestricted()) {
|
2019-07-18 13:36:05 +02:00
|
|
|
showCommunity = false;
|
|
|
|
}
|
|
|
|
if (showCommunity) {
|
|
|
|
this.researchCommunities.push(community);
|
|
|
|
}
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
});
|
2019-08-28 14:54:35 +02:00
|
|
|
this.loading = false;
|
2019-07-18 13:36:05 +02:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.status = this.handleError("Error getting communities", error);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
2020-11-12 16:59:26 +01:00
|
|
|
));
|
2019-07-18 13:36:05 +02:00
|
|
|
}
|
2022-06-17 18:49:40 +02:00
|
|
|
|
|
|
|
hasPermission(communityInfo: CommunityInfo) {
|
2023-07-19 13:21:39 +02:00
|
|
|
return communityInfo.isPublic() || (communityInfo.isRestricted() && communityInfo.isManager);
|
2019-07-18 13:36:05 +02:00
|
|
|
}
|
2019-04-08 14:17:39 +02:00
|
|
|
|
2019-07-18 13:36:05 +02:00
|
|
|
private sort(results: CommunityInfo[]) {
|
|
|
|
results.sort((left, right): number => {
|
|
|
|
if (!right.date || left.date > right.date) {
|
|
|
|
return -1;
|
|
|
|
} else if (!left.date || left.date < right.date) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (left.title > right.title) {
|
2019-04-15 12:06:58 +02:00
|
|
|
return 1;
|
2019-07-18 13:36:05 +02:00
|
|
|
} else if (left.title < right.title) {
|
|
|
|
return -1;
|
2019-04-15 12:06:58 +02:00
|
|
|
} else {
|
2019-07-18 13:36:05 +02:00
|
|
|
return 0;
|
2019-04-15 12:06:58 +02:00
|
|
|
}
|
2019-07-18 13:36:05 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-04-15 12:06:58 +02:00
|
|
|
|
2019-07-18 13:36:05 +02:00
|
|
|
public quote(param: string): string {
|
|
|
|
return StringUtils.quote(param);
|
|
|
|
}
|
2022-06-02 16:30:48 +02:00
|
|
|
|
2019-07-18 13:36:05 +02:00
|
|
|
private handleError(message: string, error): number {
|
|
|
|
var code = "";
|
2020-11-12 16:59:26 +01:00
|
|
|
try {
|
|
|
|
if (!error.status) {
|
|
|
|
var error = error.json();
|
|
|
|
code = error.code;
|
|
|
|
} else {
|
|
|
|
code = error.status;
|
|
|
|
}
|
|
|
|
}catch(e){}
|
2019-07-18 13:36:05 +02:00
|
|
|
console.error("Communities (component): " + message, error);
|
|
|
|
return this.errorMessages.getErrorCode(code);
|
|
|
|
}
|
2018-01-26 16:00:07 +01:00
|
|
|
}
|