2021-05-19 13:40:29 +02:00
|
|
|
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
|
|
|
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';
|
2021-05-19 13:40:29 +02:00
|
|
|
import {SearchZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
2019-03-05 15:53:50 +01:00
|
|
|
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';
|
2021-05-19 13:40:29 +02:00
|
|
|
import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class';
|
2020-04-01 15:40:48 +02:00
|
|
|
import {Title} from '@angular/platform-browser';
|
2021-05-19 13:40:29 +02:00
|
|
|
import {properties} from '../../../environments/environment';
|
|
|
|
import {Subscription} from 'rxjs';
|
|
|
|
import {FullScreenModalComponent} from '../../openaireLibrary/utils/modal/full-screen-modal/full-screen-modal.component';
|
|
|
|
import {ManageZenodoCommunitiesComponent} from './manage-zenodo-communities.component';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
|
|
|
@Component({
|
2021-05-19 13:40:29 +02:00
|
|
|
selector: 'zenodo-communities',
|
|
|
|
template: `
|
|
|
|
<div *ngIf="zenodoSearchUtils.status == errorCodes.LOADING" page-content>
|
|
|
|
<div header>
|
|
|
|
<community-info tab="zenodo-communities"></community-info>
|
|
|
|
</div>
|
|
|
|
<div inner>
|
|
|
|
<div class="uk-position-center">
|
|
|
|
<loading></loading>
|
2018-11-21 10:42:37 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-05-19 13:40:29 +02:00
|
|
|
</div>
|
|
|
|
<ng-container *ngIf="zenodoSearchUtils.status != errorCodes.LOADING">
|
|
|
|
<manage-zenodo-communities #manage *ngIf="communityId && zenodoSearchUtils" [masterCommunity]=masterZenodoCommunity [selectedCommunities]=selectedCommunities
|
|
|
|
[properties]=properties [communityId]=communityId [searchUtils]=zenodoSearchUtils
|
|
|
|
(toggleView)="toggleAction()"></manage-zenodo-communities>
|
|
|
|
</ng-container>
|
|
|
|
<fs-modal #fsModal (cancelEmitter)="toggleAction()">
|
|
|
|
<add-zenodo-communities *ngIf="zenodoSearchUtils.status != errorCodes.LOADING" [masterCommunity]=masterZenodoCommunity [selectedCommunities]=selectedCommunities
|
|
|
|
[properties]=properties [communityId]=communityId></add-zenodo-communities>
|
|
|
|
</fs-modal>
|
|
|
|
`
|
2018-11-21 10:42:37 +01:00
|
|
|
})
|
2019-03-05 15:53:50 +01:00
|
|
|
export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
2021-05-19 13:40:29 +02:00
|
|
|
public communityId: string = null;
|
2019-03-05 15:53:50 +01:00
|
|
|
private community: CommunityInfo = null;
|
2021-05-19 13:40:29 +02:00
|
|
|
public toggle = false;
|
2019-03-05 15:53:50 +01:00
|
|
|
public updateCommunityProjectsOnToggle = false;
|
|
|
|
public pageTitle = 'Manage zenodo communities';
|
2018-11-21 10:42:37 +01:00
|
|
|
masterZenodoCommunityId = null;
|
|
|
|
masterZenodoCommunity = null;
|
2019-03-05 15:53:50 +01:00
|
|
|
public properties: EnvProperties = null;
|
|
|
|
selectedCommunityIds = null;
|
2018-11-21 10:42:37 +01:00
|
|
|
selectedCommunities = [];
|
2018-11-22 16:10:41 +01:00
|
|
|
zenodocommunitiesloadedCount = 0;
|
2019-03-05 15:53:50 +01:00
|
|
|
zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
2021-05-19 13:40:29 +02:00
|
|
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
|
|
|
subscriptions = [];
|
2021-07-14 14:04:42 +02:00
|
|
|
@ViewChild('fsModal', { static: true }) fullscreen: FullScreenModalComponent;
|
2021-05-19 13:40:29 +02:00
|
|
|
@ViewChild('manage') manage: ManageZenodoCommunitiesComponent;
|
|
|
|
|
2019-03-05 15:53:50 +01:00
|
|
|
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
|
2021-05-19 13:40:29 +02:00
|
|
|
private _zenodoCommunitieService: ZenodoCommunitiesService, private title: Title,
|
2019-03-05 15:53:50 +01:00
|
|
|
private _communityService: CommunityService,
|
2021-05-19 13:40:29 +02:00
|
|
|
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.properties = properties;
|
|
|
|
this.route.params.subscribe(params => {
|
|
|
|
this.communityId = params['community'];
|
|
|
|
if (this.communityId) {
|
|
|
|
this.title.setTitle(this.communityId.toUpperCase() + ' | Zenodo Communities');
|
|
|
|
if (this.communityId != null && this.communityId !== '') {
|
|
|
|
this.subscriptions.push(this._communityService.getCommunityAsObservable().subscribe(
|
|
|
|
community => {
|
|
|
|
this.community = community;
|
|
|
|
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
|
|
|
if (this.masterZenodoCommunityId) {
|
|
|
|
this.subscriptions.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties,
|
|
|
|
this.properties.zenodoCommunities + this.masterZenodoCommunityId,
|
|
|
|
null).subscribe(
|
|
|
|
result => {
|
|
|
|
this.masterZenodoCommunity = result;
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
const 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
|
|
|
}
|
2021-05-19 13:40:29 +02: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.DONE;
|
|
|
|
} // this.handleError('System error retrieving community profile', error)
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.fullscreen.title = "Search and Add Zenodo Communities";
|
|
|
|
this.fullscreen.okButtonText = "Done";
|
|
|
|
this.fullscreen.okButton = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-22 16:10:41 +01:00
|
|
|
public toggleAction() {
|
2019-03-05 15:53:50 +01:00
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this._router.navigate(['/user-info'], {
|
2021-05-19 13:40:29 +02:00
|
|
|
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
|
|
|
});
|
2018-11-21 10:42:37 +01:00
|
|
|
} else {
|
2019-04-24 13:44:46 +02:00
|
|
|
HelperFunctions.scroll();
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
this.toggle = !this.toggle;
|
2019-03-05 15:53:50 +01:00
|
|
|
if (this.toggle) {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.fullscreen.open();
|
2019-03-05 15:53:50 +01:00
|
|
|
this.pageTitle = 'Manage zenodo communities';
|
2018-11-21 10:42:37 +01:00
|
|
|
} else {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.manage.filterPreviewCommunities(this.manage.filterForm.value);
|
2018-11-21 10:42:37 +01:00
|
|
|
this.updateCommunityProjectsOnToggle = false;
|
2019-03-05 15:53:50 +01:00
|
|
|
this.pageTitle = 'Search zenodo communities';
|
2018-11-21 10:42:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2019-03-05 15:53:50 +01:00
|
|
|
getZenodoCommunityById(zenodoid, openaireId) {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.subscriptions.push(this._zenodoCommunitieService.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 => {
|
|
|
|
const 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-11-22 16:10:41 +01:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
));
|
2018-11-22 16:10:41 +01:00
|
|
|
}
|
2018-11-21 10:42:37 +01:00
|
|
|
}
|