connect-admin/src/app/pages/zenodo-communities/zenodo-communities.componen...

151 lines
7.0 KiB
TypeScript
Raw Normal View History

import { Component, ViewChild, OnInit, ViewEncapsulation, Input } from '@angular/core';
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";
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
@Component({
selector: 'zenodo-communities',
template: `
<div id="manage-communities">
<div class="menubar uk-margin-bottom ">
<a *ngIf="!toggle" (click)="updateCommunityProjects()" uk-toggle="target: .toggle-usage" class="uk-button uk-button-primary uk-float-right">{{toggleLinkMessage}}</a>
<div class="manage-projects-title uk-text-large">{{pageTitle}}</div>
</div>
<div class="toggle-usage">
<manage-zenodo-communities [masterCommunity]=masterZenodoCommunity [(selectedCommunities)]=selectedCommunities [properties]=properties [communityId]=communityId ></manage-zenodo-communities>
<fab (clicked)="updateCommunityProjects()" uk-toggle="target: .toggle-usage"></fab>
</div>
<div class="toggle-usage" hidden>
<add-zenodo-communities [masterCommunity]=masterZenodoCommunity [(selectedCommunities)]=selectedCommunities [properties]=properties [communityId]=communityId ></add-zenodo-communities>
</div>
</div>
`
})
//
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 = [];
constructor(private route: ActivatedRoute, private _router: Router, private _ΖenodoCommunitieService: ZenodoCommunitiesService,private _communityService: CommunityService,private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService) {}
ngOnInit() {
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.route.queryParams.subscribe(params => {
if(params['communityId']) {
this.communityId = params['communityId'];
if(!Session.isLoggedIn()){
console.info(this._router.url);
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if (this.communityId != null && this.communityId != '') {
//TODO
// this.showLoading = true;
// this.updateErrorMessage = "";
// this.errorMessage = "";
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
community => {
this.community = community;
this.masterZenodoCommunityId = this.community.zenodoCommunity;
console.log
if(this.masterZenodoCommunityId){
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+this.masterZenodoCommunityId, null).subscribe(
result => {
this.masterZenodoCommunity = result;
});
}
// this.showLoading = false;
},
error => {} //this.handleError('System error retrieving community profile', error)
);
this._searchZenodoCommunitiesService.searchZCommunities(this.properties,this.communityId).subscribe (
result => {
this.selectedCommunityIds = result;
for(let i=0; i< this.selectedCommunityIds.length; i++){
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+this.selectedCommunityIds[i]["zenodoid"], this.selectedCommunityIds[i]["id"]).subscribe(
result => {
this.selectedCommunities.push(result);
});
}
// this.showLoading = false;
},
error => {} //this.handleError('System error retrieving community profile', error)
);
//https://dev-openaire.d4science.org/openaire/community/dh-ch/zenodocommunities
}
}
}
});
});
}
public ngOnDestroy() {}
public updateCommunityProjects() {
if(!Session.isLoggedIn()){
console.info(this._router.url);
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.toggle = !this.toggle;
if(this.toggle) {
this.pageTitle = "Manage zenodo communities";
//TODO
// this.manageProjectsComponent._getCommunityProjects();
// this.addProjectsComponent.undo = {};
} else {
this.updateCommunityProjectsOnToggle = false;
this.pageTitle = "Search zenodo communities";
//this.toggleLinkMessage = "Manage projects";
}
}
}
//TODO
// public communityProjectsChanged($event) {
// this.communityProjects = $event.value;
// }
// public updateCommunityProjects($event) {
// this.updateCommunityProjectsOnToggle = true;
// }
}