2018-12-03 12:33:03 +01:00
|
|
|
|
import { Component, ViewChild, OnInit, ViewEncapsulation, Input, ElementRef } from '@angular/core';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
|
|
|
|
|
|
import {ManageZenodoCommunitiesComponent} from './manage-zenodo-communities.component';
|
|
|
|
|
import {AddZenodoCommunitiesComponent} from './add-zenodo-communities.component';
|
|
|
|
|
|
|
|
|
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
|
|
|
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
|
|
|
|
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
|
|
|
|
import { SearchZenodoCommunitiesService } from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
|
|
|
|
|
|
|
|
|
|
import {CommunityService} from "../../openaireLibrary/connect/community/community.service";
|
2018-11-22 16:10:41 +01:00
|
|
|
|
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
|
|
|
|
|
import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo';
|
|
|
|
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'zenodo-communities',
|
|
|
|
|
template: `
|
|
|
|
|
<div id="manage-communities">
|
|
|
|
|
<div class="menubar uk-margin-bottom ">
|
2018-11-22 16:10:41 +01:00
|
|
|
|
<a *ngIf="!toggle" (click)="toggleAction()" class="uk-button uk-button-primary uk-float-right">{{toggleLinkMessage}}</a>
|
2018-11-21 10:42:37 +01:00
|
|
|
|
<div class="manage-projects-title uk-text-large">{{pageTitle}}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2018-11-22 16:10:41 +01:00
|
|
|
|
<div *ngIf="toggle" >
|
|
|
|
|
<div *ngIf="zenodoSearchUtils.status == errorCodes.LOADING "
|
|
|
|
|
class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert">
|
|
|
|
|
<span class="loading-gif uk-align-center" ></span>
|
|
|
|
|
</div>
|
|
|
|
|
<div *ngIf="zenodoSearchUtils.status == errorCodes.ERROR "
|
|
|
|
|
class="uk-animation-fade uk-margin-top uk-width-1-1 uk-alert uk-alert-warning" role="alert">
|
|
|
|
|
No zenodo communities found
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<manage-zenodo-communities *ngIf="zenodoSearchUtils.status != errorCodes.LOADING && zenodoSearchUtils.status != errorCodes.ERROR" [masterCommunity]=masterZenodoCommunity [(selectedCommunities)]=selectedCommunities [properties]=properties [communityId]=communityId [(searchUtils)]=zenodoSearchUtils></manage-zenodo-communities>
|
|
|
|
|
<fab *ngIf="zenodoSearchUtils.status != errorCodes.LOADING && zenodoSearchUtils.status != errorCodes.ERROR" (clicked)="toggleAction()" ></fab>
|
2018-11-21 10:42:37 +01:00
|
|
|
|
</div>
|
2018-11-22 16:10:41 +01:00
|
|
|
|
<div *ngIf="!toggle" >
|
2018-11-21 10:42:37 +01:00
|
|
|
|
<add-zenodo-communities [masterCommunity]=masterZenodoCommunity [(selectedCommunities)]=selectedCommunities [properties]=properties [communityId]=communityId ></add-zenodo-communities>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
})
|
2018-11-22 16:10:41 +01:00
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
export class ZenodoCommunitiesComponent implements OnInit {
|
|
|
|
|
private communityId: string = null;
|
|
|
|
|
private community:CommunityInfo = null;
|
|
|
|
|
|
|
|
|
|
@Input() communityProjects =[];
|
|
|
|
|
@ViewChild (ManageZenodoCommunitiesComponent) manageZenodoCommunitiesComponent : ManageZenodoCommunitiesComponent ;
|
|
|
|
|
@ViewChild (AddZenodoCommunitiesComponent) addZenodoCommunitiesComponent : AddZenodoCommunitiesComponent ;
|
|
|
|
|
|
|
|
|
|
public warningMessage = "";
|
|
|
|
|
public infoMessage = "";
|
|
|
|
|
|
|
|
|
|
public toggle: boolean = true;
|
|
|
|
|
public updateCommunityProjectsOnToggle: boolean = false;
|
|
|
|
|
public pageTitle: string = "Manage zenodo communities";
|
|
|
|
|
public toggleLinkMessage: string = "Manage zenodo communities";
|
|
|
|
|
|
|
|
|
|
masterZenodoCommunityId = null;
|
|
|
|
|
masterZenodoCommunity = null;
|
|
|
|
|
public properties:EnvProperties = null;
|
|
|
|
|
|
|
|
|
|
selectedCommunityIds = null;//["ecfunded", "zenodo", "lory_hslu", "cs19", "","hbp","dighl", "wind_energy", "lory", "fp7-bmc","fp7postgrantoapilotoutputs","cernopenlab"];
|
|
|
|
|
selectedCommunities = [];
|
2018-11-22 16:10:41 +01:00
|
|
|
|
|
|
|
|
|
zenodocommunitiesloadedCount = 0;
|
|
|
|
|
zenodoSearchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
|
private errorCodes: ErrorCodes = new ErrorCodes();;
|
|
|
|
|
|
2018-12-03 12:33:03 +01:00
|
|
|
|
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router, private _ΖenodoCommunitieService: ZenodoCommunitiesService,private _communityService: CommunityService,private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService) {}
|
2018-11-21 10:42:37 +01:00
|
|
|
|
ngOnInit() {
|
2018-11-22 16:10:41 +01:00
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;;
|
2018-11-21 10:42:37 +01:00
|
|
|
|
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
|
this.route.queryParams.subscribe(params => {
|
2018-12-03 12:33:03 +01:00
|
|
|
|
this.scroll();
|
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
if(params['communityId']) {
|
|
|
|
|
this.communityId = params['communityId'];
|
|
|
|
|
if(!Session.isLoggedIn()){
|
|
|
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
|
|
|
|
} else {
|
|
|
|
|
if (this.communityId != null && this.communityId != '') {
|
|
|
|
|
|
|
|
|
|
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
|
|
|
|
|
community => {
|
|
|
|
|
this.community = community;
|
|
|
|
|
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
|
|
|
|
if(this.masterZenodoCommunityId){
|
|
|
|
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+this.masterZenodoCommunityId, null).subscribe(
|
|
|
|
|
result => {
|
|
|
|
|
this.masterZenodoCommunity = result;
|
|
|
|
|
|
2018-11-22 16:10:41 +01:00
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
|
|
|
|
emptyCommunity.id = this.masterZenodoCommunityId;
|
|
|
|
|
emptyCommunity.title = this.masterZenodoCommunityId;
|
|
|
|
|
this.masterZenodoCommunity = emptyCommunity;
|
|
|
|
|
console.log("Master Zenodo community'"+this.masterZenodoCommunityId+"' couldn't be loaded");
|
2018-11-21 10:42:37 +01:00
|
|
|
|
|
|
|
|
|
|
2018-11-22 16:10:41 +01:00
|
|
|
|
}
|
|
|
|
|
);
|
2018-11-21 10:42:37 +01:00
|
|
|
|
}
|
2018-11-22 16:10:41 +01:00
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;;
|
|
|
|
|
this._searchZenodoCommunitiesService.searchZCommunities(this.properties,this.communityId).subscribe (
|
|
|
|
|
result => {
|
|
|
|
|
this.selectedCommunityIds = result;
|
|
|
|
|
this.zenodoSearchUtils.totalResults = this.selectedCommunityIds.length;
|
|
|
|
|
if(this.selectedCommunityIds.length == 0){
|
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.NONE;
|
|
|
|
|
}
|
|
|
|
|
for(let i=0; i< this.selectedCommunityIds.length; i++){
|
|
|
|
|
this.getZenodoCommunityById(this.selectedCommunityIds[i]["zenodoid"], this.selectedCommunityIds[i]["id"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
console.log("list of zenodo communities couldn't be loaded");
|
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
|
|
|
|
} //this.handleError('System error retrieving community profile', error)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
console.log("Community couldn't be loaded");
|
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
|
|
|
|
}
|
2018-11-21 10:42:37 +01:00
|
|
|
|
);
|
2018-11-22 16:10:41 +01:00
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {}
|
|
|
|
|
|
2018-11-22 16:10:41 +01:00
|
|
|
|
public toggleAction() {
|
2018-11-21 10:42:37 +01:00
|
|
|
|
if(!Session.isLoggedIn()){
|
|
|
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
|
|
|
|
} else {
|
2018-12-03 12:33:03 +01:00
|
|
|
|
this.scroll();
|
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
this.toggle = !this.toggle;
|
|
|
|
|
if(this.toggle) {
|
|
|
|
|
this.pageTitle = "Manage zenodo communities";
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
this.updateCommunityProjectsOnToggle = false;
|
|
|
|
|
this.pageTitle = "Search zenodo communities";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-22 16:10:41 +01:00
|
|
|
|
getZenodoCommunityById(zenodoid, openaireId){
|
|
|
|
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+zenodoid, openaireId).subscribe(
|
|
|
|
|
result => {
|
|
|
|
|
this.selectedCommunities.push(result);
|
|
|
|
|
this.zenodocommunitiesloadedCount++;
|
|
|
|
|
if(this.zenodocommunitiesloadedCount >= this.selectedCommunityIds.length){
|
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
|
|
|
|
emptyCommunity.id = zenodoid;
|
|
|
|
|
emptyCommunity.openaireId = openaireId;
|
|
|
|
|
emptyCommunity.title = zenodoid;
|
|
|
|
|
this.selectedCommunities.push(emptyCommunity);
|
|
|
|
|
this.zenodocommunitiesloadedCount++;
|
|
|
|
|
if(this.zenodocommunitiesloadedCount >= this.selectedCommunityIds.length){
|
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
|
|
|
|
}
|
|
|
|
|
console.log("Zenodo community'"+zenodoid+"' couldn't be loaded");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-03 12:33:03 +01:00
|
|
|
|
public scroll() {
|
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
|
this.element.nativeElement.scrollIntoView();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
}
|