2018-03-14 14:28:45 +01:00
|
|
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
|
|
|
import {ViewChild, ChangeDetectionStrategy} from '@angular/core';
|
|
|
|
import {ViewEncapsulation} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {Location} from '@angular/common';
|
2018-04-11 13:24:57 +02:00
|
|
|
import {Title, Meta} from '@angular/platform-browser';
|
2018-03-14 14:28:45 +01:00
|
|
|
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
2018-04-11 13:24:57 +02:00
|
|
|
|
2018-01-26 16:00:07 +01:00
|
|
|
import "rxjs/add/observable/zip";
|
2018-03-06 14:54:17 +01:00
|
|
|
|
2018-04-11 13:24:57 +02:00
|
|
|
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
|
2018-03-14 14:28:45 +01:00
|
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
|
|
|
|
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
|
|
|
|
import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service';
|
2018-04-11 13:24:57 +02:00
|
|
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
2018-05-03 13:57:19 +02:00
|
|
|
import {Session} from '../openaireLibrary/login/utils/helper.class';
|
2018-01-26 16:00:07 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'communities',
|
|
|
|
templateUrl: 'communities.component.html',
|
|
|
|
})
|
2018-03-14 14:28:45 +01:00
|
|
|
|
2018-01-26 16:00:07 +01:00
|
|
|
export class CommunitiesComponent {
|
|
|
|
public piwiksub: any;
|
|
|
|
public subfunders: any;
|
|
|
|
|
|
|
|
public pageTitle = "OpenAIRE"
|
|
|
|
|
2018-02-27 11:25:34 +01:00
|
|
|
public communitiesResults = null;
|
2018-10-05 01:10:13 +02:00
|
|
|
public communitiesToShow = null;
|
2018-02-27 11:25:34 +01:00
|
|
|
|
2018-04-11 13:24:57 +02:00
|
|
|
properties:EnvProperties;
|
2018-10-05 01:10:13 +02:00
|
|
|
public keyword:string="";
|
|
|
|
public type:string="all";
|
2018-01-26 16:00:07 +01:00
|
|
|
constructor (
|
2018-03-14 14:28:45 +01:00
|
|
|
private route: ActivatedRoute,
|
2018-01-26 16:00:07 +01:00
|
|
|
private _router: Router,
|
2018-04-11 13:24:57 +02:00
|
|
|
private location: Location,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
2018-03-06 14:54:17 +01:00
|
|
|
private _piwikService:PiwikService,
|
|
|
|
private _communitiesService:CommunitiesService,
|
2018-04-11 13:24:57 +02:00
|
|
|
private config: ConfigurationService) {
|
|
|
|
|
2018-10-24 11:15:13 +02:00
|
|
|
var description = "OpenAIRE - Connect, Community Dashboard, research community";
|
|
|
|
var title = "OpenAIRE - Connect";
|
2018-01-26 16:00:07 +01:00
|
|
|
|
2018-04-11 13:24:57 +02:00
|
|
|
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);
|
|
|
|
}
|
2018-02-12 12:41:40 +01:00
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
var url = data.envSpecific.baseLink+this._router.url
|
2018-04-11 13:24:57 +02:00
|
|
|
this._meta.updateTag({content:url},"property='og:url'");
|
2018-02-12 12:41:40 +01:00
|
|
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
2018-04-11 12:40:29 +02:00
|
|
|
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
|
2018-02-12 12:41:40 +01:00
|
|
|
}
|
2018-03-14 15:38:57 +01:00
|
|
|
|
2018-04-04 16:02:53 +02:00
|
|
|
this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe(
|
2018-03-14 15:38:57 +01:00
|
|
|
communitiesResults => {
|
|
|
|
this.communitiesResults = communitiesResults;
|
2018-10-05 01:10:13 +02:00
|
|
|
this.communitiesToShow = this.communitiesResults.slice();
|
2018-03-14 15:38:57 +01:00
|
|
|
//console.log(communitiesResults);
|
|
|
|
});
|
2018-02-12 12:41:40 +01:00
|
|
|
});
|
2018-02-27 11:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if(this.piwiksub){
|
|
|
|
this.piwiksub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2018-03-22 16:38:42 +01:00
|
|
|
isProduction():boolean{
|
2019-02-18 16:15:53 +01:00
|
|
|
return this.properties.environment!="development";
|
2018-03-22 16:38:42 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
getProductionPrefix():string{
|
2019-02-18 16:15:53 +01:00
|
|
|
return (this.properties.environment =="beta")?"beta.":""
|
2018-03-22 16:38:42 +01:00
|
|
|
}
|
2018-05-03 13:57:19 +02:00
|
|
|
showCommunity(community):boolean{
|
|
|
|
if(community['status'] == "hidden"){
|
|
|
|
return false;
|
|
|
|
}else if(community['status'] == "manager"){
|
|
|
|
var mail = Session.getUserEmail();
|
|
|
|
if(mail == null){ // no user
|
|
|
|
return false;
|
|
|
|
}else if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
|
|
|
|
return true;
|
|
|
|
}else if(community.managers.indexOf(mail)!=-1){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
2018-10-05 01:10:13 +02:00
|
|
|
}
|
|
|
|
existsIn(word, keyword):boolean{
|
|
|
|
if(word!= null && (keyword=="" || word.toLowerCase().indexOf(keyword.toLowerCase())!=-1)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
isType(communityType):boolean{
|
|
|
|
if(this.type == "all" || communityType == this.type){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
searchChanged(){
|
|
|
|
this.communitiesToShow = [];
|
|
|
|
for(var i=0; i <this.communitiesResults.length; i++){
|
|
|
|
if((this.existsIn(this.communitiesResults[i].description, this.keyword) ||
|
|
|
|
this.existsIn(this.communitiesResults[i].title, this.keyword) ||
|
|
|
|
this.existsIn(this.communitiesResults[i].shortTitle, this.keyword))
|
|
|
|
&& this.isType(this.communitiesResults[i].type)){
|
|
|
|
this.communitiesToShow.push(this.communitiesResults[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-03 13:57:19 +02:00
|
|
|
}
|
2018-01-26 16:00:07 +01:00
|
|
|
}
|