2018-11-21 10:42:37 +01:00
|
|
|
|
import {Component, OnInit, Input, ViewChild} from '@angular/core';
|
2018-10-30 16:31:16 +01:00
|
|
|
|
import {SimpleChanges, OnChanges} from '@angular/core';
|
|
|
|
|
import {FormGroup, FormArray, FormBuilder, Validators} from '@angular/forms';
|
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
import { Subject } from 'rxjs/Subject';
|
|
|
|
|
|
|
|
|
|
import { DataTableDirective } from 'angular-datatables';
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
|
|
import {HelpContentService} from '../../services/help-content.service';
|
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
|
|
|
|
|
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
|
|
|
|
import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo';
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
2018-11-13 16:26:49 +01:00
|
|
|
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
|
|
|
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
2018-11-21 10:42:37 +01:00
|
|
|
|
import{ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service';
|
2018-11-13 16:26:49 +01:00
|
|
|
|
|
2018-10-30 16:31:16 +01:00
|
|
|
|
@Component({
|
|
|
|
|
selector: 'manage-zenodo-communities',
|
|
|
|
|
templateUrl: './manage-zenodo-communities.component.html',
|
2018-11-21 10:42:37 +01:00
|
|
|
|
styles: [`
|
|
|
|
|
#dpTable_info, #dpTable_paginate, #dpTable_length, #dpTable_filter{
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
`]
|
2018-10-30 16:31:16 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export class ManageZenodoCommunitiesComponent implements OnInit {
|
2018-11-21 10:42:37 +01:00
|
|
|
|
@Input() properties:EnvProperties = null;
|
|
|
|
|
@Input() communityId = null;
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
|
|
public zenodoCommunitySearchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
|
|
|
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
|
public rowsOnPage = 10;
|
2018-11-21 10:42:37 +01:00
|
|
|
|
@Input() masterCommunity = null;
|
|
|
|
|
@Input() selectedCommunities = [];
|
|
|
|
|
|
|
|
|
|
@ViewChild(DataTableDirective) datatableElement: DataTableDirective;
|
|
|
|
|
dtTrigger: Subject<any> = new Subject(); //necessary
|
|
|
|
|
dtOptions: DataTables.Settings = {};
|
|
|
|
|
private triggered: boolean = false;
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
@ViewChild('AlertModalDeleteCommunity') alertModalDeleteCommunity;
|
|
|
|
|
selectedToDelete = null;
|
2018-10-30 16:31:16 +01:00
|
|
|
|
constructor (private route: ActivatedRoute,
|
|
|
|
|
private _router: Router,
|
|
|
|
|
public _fb: FormBuilder,
|
|
|
|
|
private _helpContentService: HelpContentService,
|
2018-11-21 10:42:37 +01:00
|
|
|
|
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
|
|
|
|
|
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) {
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.LOADING;
|
2018-11-21 10:42:37 +01:00
|
|
|
|
this.zenodoCommunitySearchUtils.totalResults = this.selectedCommunities.length;
|
2018-10-30 16:31:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-11-21 10:42:37 +01:00
|
|
|
|
|
|
|
|
|
// this.route.queryParams.subscribe(
|
|
|
|
|
// communityId => {
|
|
|
|
|
// this.communityId = communityId['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 != '') {
|
|
|
|
|
// this._ΖenodoCommunitieService.getZenodoCommunities(this.properties, this.properties.zenodoCommunities+"?page="+this.zenodoCommunitySearchUtils.page+"&size="+this.rowsOnPage).subscribe(
|
|
|
|
|
// zenodoCommunities => {
|
|
|
|
|
// this.zenodoCommunities = zenodoCommunities;
|
|
|
|
|
// console.log(zenodoCommunities);
|
|
|
|
|
// console.log(this.zenodoCommunitySearchUtils.page);
|
|
|
|
|
// });
|
|
|
|
|
// this._ΖenodoCommunitieService.getTotalZenodoCommunities(this.properties, this.properties.zenodoCommunities).subscribe(
|
|
|
|
|
// totalZenodoCommunities => {
|
|
|
|
|
// this.totalZenodoCommunities = totalZenodoCommunities;
|
|
|
|
|
// this.zenodoCommunitySearchUtils.totalResults = totalZenodoCommunities;
|
|
|
|
|
// console.log(totalZenodoCommunities);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
|
|
this.zenodoCommunitySearchUtils.keyword = "";
|
2018-11-21 10:42:37 +01:00
|
|
|
|
this.dtOptions = {
|
|
|
|
|
// "paging": true,
|
|
|
|
|
// "searching": true,
|
|
|
|
|
// "lengthChange": false,
|
|
|
|
|
"pageLength": this.rowsOnPage,
|
|
|
|
|
"language": {
|
|
|
|
|
"search": "",
|
|
|
|
|
"searchPlaceholder": "Search projects..."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
if(!this.triggered) {
|
|
|
|
|
this.triggerInitialLoad();
|
|
|
|
|
} else {
|
|
|
|
|
var table = $('#dpTable').DataTable();
|
|
|
|
|
table.clear();
|
|
|
|
|
|
|
|
|
|
this.rerender();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
|
|
|
|
|
|
$.fn['dataTable'].ext.search.pop();
|
|
|
|
|
}
|
|
|
|
|
rerender(): void {
|
|
|
|
|
this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
|
|
|
|
|
// Destroy the table first
|
|
|
|
|
dtInstance.destroy();
|
|
|
|
|
|
|
|
|
|
// Call the dtTrigger to rerender again
|
|
|
|
|
this.dtTrigger.next();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
$.fn['dataTable'].ext.search.push((settings, data, dataIndex) => {
|
|
|
|
|
|
|
|
|
|
if (this.filterData(data, this.zenodoCommunitySearchUtils.keyword )) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.info("ngAfterViewInit");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filterData(row: any, query: string) {
|
|
|
|
|
let returnValue: boolean = false;
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
if(query) {
|
|
|
|
|
for(var i=0; i <3; i++){
|
|
|
|
|
var r= this.filterQuery(row[i], query);
|
|
|
|
|
if(r) {
|
|
|
|
|
returnValue = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!returnValue) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filterQuery(data, query){
|
|
|
|
|
if(data.toLowerCase().indexOf(query.toLowerCase()) > -1){
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Trigger a table draw in order to get the initial filtering
|
|
|
|
|
*/
|
|
|
|
|
triggerInitialLoad(){
|
|
|
|
|
this.triggered = true;
|
|
|
|
|
console.info("triggerInitialLoad");
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
var table = (<any>$('#dpTable')).DataTable();
|
|
|
|
|
table.page( 0 ).draw( false );
|
|
|
|
|
}, 500);
|
|
|
|
|
this.dtTrigger.next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goTo(page:number = 1){
|
|
|
|
|
this.zenodoCommunitySearchUtils.page=page;
|
|
|
|
|
|
|
|
|
|
var table = $('#dpTable').DataTable();
|
|
|
|
|
table.page( page - 1 ).draw( false );
|
|
|
|
|
|
|
|
|
|
var info = table.page.info();
|
|
|
|
|
console.info("records: "+info.recordsDisplay);
|
|
|
|
|
this.zenodoCommunitySearchUtils.totalResults = info.recordsDisplay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public confirmedDeleteCommunity(data : any) {
|
|
|
|
|
// if(!Session.isLoggedIn()){
|
|
|
|
|
// console.info(this._router.url);
|
|
|
|
|
// this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
|
|
|
|
// } else {
|
|
|
|
|
// console.info("REMOVE: "+ this.selectedCommunityProject.id);
|
|
|
|
|
// this.subRemove = this._manageCommunityProjectsService.removeProject(this.properties, this.community, this.selectedCommunityProject.id).subscribe(
|
|
|
|
|
// data => {
|
|
|
|
|
// console.info("data REMOVE");
|
|
|
|
|
// console.info(data);
|
|
|
|
|
// },
|
|
|
|
|
// err => {
|
|
|
|
|
// console.info("error REMOVE");
|
|
|
|
|
// console.log(err);
|
|
|
|
|
// },
|
|
|
|
|
// () => {
|
|
|
|
|
// console.info("completed REMOVE");
|
|
|
|
|
// let index = this.communityProjects.indexOf(this.selectedCommunityProject);
|
|
|
|
|
// this.communityProjects.splice(index, 1);
|
|
|
|
|
//
|
|
|
|
|
// this.communitySearchUtils.totalResults--;
|
|
|
|
|
// this.communitySearchUtils.page=1;
|
|
|
|
|
//
|
|
|
|
|
// this.rerender();
|
|
|
|
|
// }
|
|
|
|
|
// )
|
|
|
|
|
// }
|
2018-11-13 16:26:49 +01:00
|
|
|
|
if(!Session.isLoggedIn()){
|
|
|
|
|
console.info(this._router.url);
|
|
|
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
|
|
|
|
} else {
|
2018-11-21 10:42:37 +01:00
|
|
|
|
console.info("REMOVE: "+ this.communityId + " "+this.selectedToDelete.openaireId);
|
|
|
|
|
this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(pos != -1){
|
|
|
|
|
this.selectedCommunities.splice(pos, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var table = $('#dpTable').DataTable();
|
|
|
|
|
table.clear();
|
|
|
|
|
|
|
|
|
|
this.rerender();
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
err => {
|
|
|
|
|
console.info("error remove");
|
|
|
|
|
console.log(err.status);
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
console.info("completed remove");
|
|
|
|
|
}
|
|
|
|
|
)
|
2018-11-13 16:26:49 +01:00
|
|
|
|
}
|
2018-10-30 16:31:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 10:42:37 +01:00
|
|
|
|
public removeCommunity( comm) {
|
2018-11-13 16:26:49 +01:00
|
|
|
|
if(!Session.isLoggedIn()){
|
|
|
|
|
console.info(this._router.url);
|
|
|
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
|
|
|
|
} else {
|
2018-11-21 10:42:37 +01: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
|
|
|
|
|
2018-11-21 10:42:37 +01: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();
|
2018-10-30 16:31:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-21 10:42:37 +01:00
|
|
|
|
|
|
|
|
|
// public removeCommunity( comm) {
|
|
|
|
|
// if(!Session.isLoggedIn()){
|
|
|
|
|
// console.info(this._router.url);
|
|
|
|
|
// this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
|
|
|
|
// } else {
|
|
|
|
|
// console.info("REMOVE: "+ this.communityId + " "+comm.openaireId);
|
|
|
|
|
// this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.communityId,comm.openaireId ).subscribe(
|
|
|
|
|
// data => {
|
|
|
|
|
// var pos = -1;
|
|
|
|
|
// for(var i=0; i< this.selectedCommunities.length;i++) {
|
|
|
|
|
// if( this.selectedCommunities[i].id == comm.id) {
|
|
|
|
|
// pos= i;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if(pos != -1){
|
|
|
|
|
// this.selectedCommunities.splice(pos, 1);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// },
|
|
|
|
|
// err => {
|
|
|
|
|
// console.info("error remove");
|
|
|
|
|
// console.log(err.status);
|
|
|
|
|
// },
|
|
|
|
|
// () => {
|
|
|
|
|
// console.info("completed remove");
|
|
|
|
|
// }
|
|
|
|
|
// )
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2018-10-30 16:31:16 +01:00
|
|
|
|
}
|