2021-05-19 13:40:29 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnDestroy,
|
|
|
|
OnInit,
|
2022-07-05 00:31:56 +02:00
|
|
|
Output,
|
2021-05-19 13:40:29 +02:00
|
|
|
ViewChild,
|
|
|
|
ViewEncapsulation
|
|
|
|
} from '@angular/core';
|
|
|
|
import {FormBuilder, FormControl} from '@angular/forms';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
2022-07-05 00:31:56 +02:00
|
|
|
import {properties} from "../../../environments/environment";
|
2021-05-19 13:40:29 +02:00
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
|
|
|
import {ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service';
|
|
|
|
import {SearchInputComponent} from '../../openaireLibrary/sharedComponents/search-input/search-input.component';
|
|
|
|
import {Subscription} from 'rxjs';
|
2022-07-05 00:31:56 +02:00
|
|
|
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
|
|
|
|
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
2018-11-13 16:26:49 +01:00
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
declare var UIkit;
|
2018-11-21 10:42:37 +01:00
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'manage-zenodo-communities',
|
|
|
|
templateUrl: './manage-zenodo-communities.component.html',
|
|
|
|
encapsulation: ViewEncapsulation.None // this used in order styles to work
|
2018-10-30 16:31:16 +01:00
|
|
|
})
|
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
export class ManageZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
2022-07-05 00:31:56 +02:00
|
|
|
properties: EnvProperties = properties;
|
|
|
|
@Input() community: CommunityInfo = null;
|
|
|
|
@Input() public loading: boolean = true;
|
|
|
|
@Input() public disableAdd: boolean = false;
|
2021-05-19 13:40:29 +02:00
|
|
|
@Input() searchUtils: SearchUtilsClass = null;
|
|
|
|
|
|
|
|
errorCodes: ErrorCodes;
|
|
|
|
public rowsOnPage = 10;
|
|
|
|
@Input() masterCommunity = null;
|
|
|
|
@Input() selectedCommunities = [];
|
|
|
|
previewCommunities = [];
|
|
|
|
|
|
|
|
@ViewChild('AlertModalDeleteCommunity') alertModalDeleteCommunity;
|
|
|
|
selectedToDelete = null;
|
2022-07-05 00:31:56 +02:00
|
|
|
@Output() addZenodoCommunity: EventEmitter<any> = new EventEmitter();
|
|
|
|
@Output() zenodoCommunitiesChanged = new EventEmitter();
|
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
page = 1;
|
|
|
|
size = 10;
|
|
|
|
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
|
|
|
public filterForm: FormControl;
|
|
|
|
private subscriptions: any[] = [];
|
2022-07-05 00:31:56 +02:00
|
|
|
|
|
|
|
public stickyPageHeader: boolean = false;
|
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private _router: Router,
|
|
|
|
public _fb: FormBuilder,
|
|
|
|
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) {
|
|
|
|
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private init() {
|
|
|
|
this.filterForm = this._fb.control('');
|
|
|
|
this.filterPreviewCommunities("");
|
|
|
|
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
|
|
|
|
this.page = 1;
|
|
|
|
this.filterPreviewCommunities(value);
|
|
|
|
}));
|
|
|
|
this.searchUtils.keyword = "";
|
|
|
|
this.searchUtils.totalResults = this.selectedCommunities.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public filterPreviewCommunities(value: string) {
|
|
|
|
this.previewCommunities = this.selectedCommunities.filter(community => {
|
2022-07-05 00:31:56 +02:00
|
|
|
return !value || community.title.toLowerCase().indexOf(value.toLowerCase()) != -1
|
2021-05-19 13:40:29 +02:00
|
|
|
});
|
|
|
|
if (this.previewCommunities.slice((this.page - 1) * this.rowsOnPage, this.page * this.rowsOnPage).length == 0) {
|
|
|
|
this.page = 1;
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public confirmedDeleteCommunity(data: any) {
|
2022-07-05 00:31:56 +02:00
|
|
|
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.community.communityId, this.selectedToDelete.openaireId).subscribe(
|
|
|
|
data => {
|
|
|
|
var pos = -1;
|
|
|
|
for (var i = 0; i < this.selectedCommunities.length; i++) {
|
|
|
|
if (this.selectedCommunities[i].id == this.selectedToDelete.id) {
|
|
|
|
pos = i;
|
|
|
|
break;
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
}
|
|
|
|
if (pos != -1) {
|
|
|
|
this.selectedCommunities.splice(pos, 1);
|
2021-05-19 13:40:29 +02:00
|
|
|
this.searchUtils.totalResults = this.selectedCommunities.length;
|
2018-11-21 10:42:37 +01:00
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
this.searchUtils.totalResults = this.selectedCommunities.length;
|
|
|
|
this.filterPreviewCommunities(this.filterForm.value);
|
|
|
|
UIkit.notification('Community has been <b>successfully removed</b>!', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
this.zenodoCommunitiesChanged.emit({
|
|
|
|
value: this.selectedCommunities,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError('An error has been occurred. Try again later!');
|
|
|
|
console.log(err.status);
|
|
|
|
}
|
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public removeCommunity(comm) {
|
2022-07-05 00:31:56 +02:00
|
|
|
this.selectedToDelete = comm;
|
|
|
|
this.alertModalDeleteCommunity.cancelButton = true;
|
|
|
|
this.alertModalDeleteCommunity.okButton = true;
|
|
|
|
this.alertModalDeleteCommunity.alertTitle = "Remove zenodo community";
|
|
|
|
let title = "";
|
|
|
|
if (comm.title) {
|
|
|
|
title = comm.title;
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
|
|
|
|
this.alertModalDeleteCommunity.message = "Zenodo community";
|
|
|
|
if (title) {
|
|
|
|
this.alertModalDeleteCommunity.message += " '" + title + "' ";
|
|
|
|
}
|
|
|
|
this.alertModalDeleteCommunity.message += "will be removed from your community. Are you sure?";
|
|
|
|
this.alertModalDeleteCommunity.okButtonText = "Yes";
|
|
|
|
this.alertModalDeleteCommunity.open();
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
totalPages(): number {
|
|
|
|
let totalPages: any = this.searchUtils.totalResults / (this.rowsOnPage);
|
|
|
|
if (!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
2018-11-22 16:10:41 +01:00
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
return totalPages;
|
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
|
|
|
|
public updatePage($event) {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
this.page = $event.value;
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
addNew() {
|
|
|
|
this.addZenodoCommunity.emit();
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message: string) {
|
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
}
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|