From cf5909241ec9af9ac7a2101b2763fd897ea750cd Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Wed, 21 Nov 2018 09:42:37 +0000 Subject: [PATCH] zenodo communities: add-zenodo-communities complete searching in zenodo API add button for save a zenodo community manage-zenodo-communities fetch and display selected communities from CNR API (datatables: initial rendering is not properly working) remove button general page that toggles the above views git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@53905 d315682c-612b-4755-9ff5-7f18f6832af3 --- package.json | 2 +- src/app/app.component.html | 23 +- src/app/app.module.ts | 4 +- src/app/app.routing.ts | 4 +- .../add-zenodo-communities.component.html | 71 ++++ .../add-zenodo-communities.component.ts | 173 ++++++++++ .../manage-zenodo-communities.component.html | 121 ++++--- .../manage-zenodo-communities.component.ts | 323 ++++++++++++++---- .../manage-zenodo-communities.module.ts | 26 -- .../manage-zenodo-communities.service.ts | 44 --- .../remove-projects.component.html | 94 +++++ .../zenodo-communities.component.ts | 150 ++++++++ .../zenodo-communities.module.ts | 34 ++ .../zenodoCommunity/zenodoCommunityInfo.ts | 9 - .../manageZenodoCommunities.service.ts | 43 +++ 15 files changed, 913 insertions(+), 208 deletions(-) create mode 100644 src/app/pages/zenodo-communities/add-zenodo-communities.component.html create mode 100644 src/app/pages/zenodo-communities/add-zenodo-communities.component.ts delete mode 100644 src/app/pages/zenodo-communities/manage-zenodo-communities.module.ts delete mode 100644 src/app/pages/zenodo-communities/manage-zenodo-communities.service.ts create mode 100644 src/app/pages/zenodo-communities/remove-projects.component.html create mode 100644 src/app/pages/zenodo-communities/zenodo-communities.component.ts create mode 100644 src/app/pages/zenodo-communities/zenodo-communities.module.ts delete mode 100644 src/app/pages/zenodo-communities/zenodoCommunity/zenodoCommunityInfo.ts create mode 100644 src/app/services/manageZenodoCommunities.service.ts diff --git a/package.json b/package.json index 90f3594..6008bee 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "MIT", "scripts": { "ng": "ng", - "start": "ng serve --host 0.0.0.0 --disable-host-check", + "start": "ng serve --host 0.0.0.0 --disable-host-check --port=5000", "build": "ng build", "test": "ng test", "lint": "ng lint", diff --git a/src/app/app.component.html b/src/app/app.component.html index d1e0e60..f66aa43 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -30,6 +30,16 @@ Profile +
  • + + Manage subscribers + +
  • +
  • + + Manage user notifications (temporary position) + +
  • @@ -53,21 +63,12 @@ Manage subjects - +
  • diff --git a/src/app/app.module.ts b/src/app/app.module.ts index c59b11b..abeb22a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -49,7 +49,7 @@ import { CookieLawModule } from './openaireLibrary/sharedComponents/cookie-law/c import {BottomModule} from './openaireLibrary/sharedComponents/bottom.module'; import {FeedbackModule} from './openaireLibrary/sharedComponents/feedback/feedback.module'; import {CommunityEditFormModule} from './pages/community/community-edit-form/community-edit-form.module'; -import {ManageZenodoCommunitiesModule} from './pages/zenodo-communities/manage-zenodo-communities.module'; +import {ZenodoCommunitiesModule} from './pages/zenodo-communities/zenodo-communities.module'; import {ManageSubscribersModule} from './pages/subscribers/manage-subscribers.module'; import {SubjectsEditFormModule} from './pages/subjects/subjects-edit-form/subjects-edit-form.module'; import { LoginGuard} from './openaireLibrary/login/loginGuard.guard'; @@ -100,7 +100,7 @@ import {ManageUserNotificationsModule} from './pages/usernotifications/manage-us CommunityProjectsModule, CommunityContentProvidersModule, CommunityEditFormModule, - ManageZenodoCommunitiesModule, + ZenodoCommunitiesModule, ManageSubscribersModule, SubjectsEditFormModule, DataTablesModule, diff --git a/src/app/app.routing.ts b/src/app/app.routing.ts index 05b6571..867cb50 100644 --- a/src/app/app.routing.ts +++ b/src/app/app.routing.ts @@ -6,7 +6,7 @@ import { Routes, RouterModule } from '@angular/router'; import { DashboardComponent } from "./dashboard.component"; import { CommunitiesComponent } from './pages/community/communities.component'; -import { ManageZenodoCommunitiesComponent } from "./pages/zenodo-communities/manage-zenodo-communities.component"; +import { ZenodoCommunitiesComponent } from "./pages/zenodo-communities/zenodo-communities.component"; import { ManageSubscribersComponent } from "./pages/subscribers/manage-subscribers.component"; import { CommunityEditFormComponent } from "./pages/community/community-edit-form/community-edit-form.component"; import { SubjectsEditFormComponent } from "./pages/subjects/subjects-edit-form/subjects-edit-form.component"; @@ -74,7 +74,7 @@ const appRoutes: Routes = [ }, { path: 'manage-zenodo-communities', - component: ManageZenodoCommunitiesComponent, + component: ZenodoCommunitiesComponent, canActivate: [IsCommunity,ConnectAdminLoginGuard],resolve: { envSpecific: EnvironmentSpecificResolver } }, { diff --git a/src/app/pages/zenodo-communities/add-zenodo-communities.component.html b/src/app/pages/zenodo-communities/add-zenodo-communities.component.html new file mode 100644 index 0000000..b66bca3 --- /dev/null +++ b/src/app/pages/zenodo-communities/add-zenodo-communities.component.html @@ -0,0 +1,71 @@ +
    +
    +
    + + +
    +
    + +
    +
    + + {{zenodoCommunitySearchUtils.totalResults | number}} zenodo communities, page {{zenodoCommunitySearchUtils.page | number}} of {{(totalPages()) | number}} + + + + +
    +
    + + + + +
    +
    + + {{zenodoCommunitySearchUtils.totalResults | number}} zenodo communities, page {{zenodoCommunitySearchUtils.page | number}} of {{(totalPages()) | number}} + + + + +
    +
    + +
    diff --git a/src/app/pages/zenodo-communities/add-zenodo-communities.component.ts b/src/app/pages/zenodo-communities/add-zenodo-communities.component.ts new file mode 100644 index 0000000..920a8be --- /dev/null +++ b/src/app/pages/zenodo-communities/add-zenodo-communities.component.ts @@ -0,0 +1,173 @@ +import {Component, OnInit, Input} from '@angular/core'; +import {SimpleChanges, OnChanges} from '@angular/core'; +import {FormGroup, FormArray, FormBuilder, Validators} from '@angular/forms'; +import {ActivatedRoute, Router} from '@angular/router'; + +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'; +import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service'; +import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo'; + +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; +import{ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service'; +@Component({ + selector: 'add-zenodo-communities', + templateUrl: './add-zenodo-communities.component.html', +}) + +export class AddZenodoCommunitiesComponent implements OnInit { + + public zenodoCommunities = null; // zenodo search API results + public totalZenodoCommunities = null; + @Input() properties:EnvProperties = null; + @Input() communityId = null; + + public zenodoCommunitySearchUtils:SearchUtilsClass = new SearchUtilsClass(); + + private errorCodes: ErrorCodes; + public rowsOnPage = 10; + @Input() masterCommunity = null; + @Input() selectedCommunities = []; + constructor (private route: ActivatedRoute, + private _router: Router, + public _fb: FormBuilder, + private _helpContentService: HelpContentService, + private _zenodoCommunitieService: ZenodoCommunitiesService, + private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) { + + this.errorCodes = new ErrorCodes(); + this.zenodoCommunitySearchUtils.status = this.errorCodes.LOADING; + } + + ngOnInit() { + this.zenodoCommunitySearchUtils.keyword = ""; + 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._zenodoCommunitieService.getZenodoCommunities(this.properties, this.properties.zenodoCommunities+"?page="+this.zenodoCommunitySearchUtils.page+"&size="+this.rowsOnPage).subscribe( + result => { + this.zenodoCommunities = result[0]; + this.totalZenodoCommunities = result[1]; + this.zenodoCommunitySearchUtils.totalResults = result[1]; + this.zenodoCommunitySearchUtils.page = 1; + this.zenodoCommunitySearchUtils.size =this.rowsOnPage; + + }); + } + } + + } + + public goTo(page:number = 1) { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.zenodoCommunitySearchUtils.page=page; + this._zenodoCommunitieService.getZenodoCommunities(this.properties, + this.properties.zenodoCommunities+"?page="+this.zenodoCommunitySearchUtils.page + +"&size="+this.rowsOnPage + +((this.zenodoCommunitySearchUtils.keyword)?("&q="+this.zenodoCommunitySearchUtils.keyword):"") + ).subscribe( + result => { + this.zenodoCommunities = result[0]; + this.totalZenodoCommunities = result[1]; + this.zenodoCommunitySearchUtils.totalResults = result[1]; + this.zenodoCommunitySearchUtils.size =this.rowsOnPage; + }); + } + } + + totalPages(): number { + let totalPages:any = this.zenodoCommunitySearchUtils.totalResults/(this.rowsOnPage); + if(!(Number.isInteger(totalPages))) { + totalPages = (parseInt(totalPages, 10) + 1); + } + return totalPages; + } + + + public addCommunity(community) { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this._manageZenodoCommunitiesService.addZCommunity(this.properties, this.communityId, community.id ).subscribe( + data => { + console.info("data ADD"); + console.info(data); + // this.undo[project.id] = data.id; + community["openaireId"]=data.id; + this.selectedCommunities.push(community); + }, + err => { + console.info("error ADD"); + console.log(err.status); + }, + () => { + console.info("completed ADD"); + } + ) + } + } + + /* 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 { + var openaireId = this.getOpenaireId(comm); + this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.communityId,openaireId, ).subscribe( + data => { + console.log(this.selectedCommunities.length); + console.info("REMOVE: "+ this.communityId + " "+openaireId); + console.log(comm); + var pos = -1; + for(var i=0; i< this.selectedCommunities.length;i++) { + console.info(this.selectedCommunities[i].id+ " "+ this.selectedCommunities[i].openaireId+" "+ comm.id); + if( this.selectedCommunities[i].id == comm.id) { + pos= i; + break; + } + } + console.log(pos); + if(pos != -1){ + this.selectedCommunities.splice(pos, 1); + } + console.log(this.selectedCommunities.length); + + }, + err => { + console.info("error remove"); + console.log(err.status); + }, + () => { + console.info("completed remove"); + } + ) + } + }*/ + + public inCommunity(community: any): any { + for(let com of this.selectedCommunities) { + if(com.id == community.id) { + return true; + } + } + return false; + } + public getOpenaireId(community: any): string { + for(let com of this.selectedCommunities) { + if(com.id == community.id) { + return com.openaireId; + } + } + return null; + } +} diff --git a/src/app/pages/zenodo-communities/manage-zenodo-communities.component.html b/src/app/pages/zenodo-communities/manage-zenodo-communities.component.html index 76bc9df..2d408fd 100644 --- a/src/app/pages/zenodo-communities/manage-zenodo-communities.component.html +++ b/src/app/pages/zenodo-communities/manage-zenodo-communities.component.html @@ -1,9 +1,8 @@ -
    -
    Manage zenodo communities
    +
    -
    +
    +
    Master Zenodo community
    +
    + +
    + + + +
    +
    +

    + {{masterCommunity.title}} + [no name available] + + + +

    +
    + last update: {{masterCommunity.date | date:'yyyy/MM/dd'}} +
    +
    +
    +
    +

    {{masterCommunity.description}}

    +
    +
    - {{zenodoCommunitySearchUtils.totalResults | number}} zenodo communities, page {{zenodoCommunitySearchUtils.page | number}} of {{(totalPages()) | number}} + {{zenodoCommunitySearchUtils.totalResults | number}} projects, page {{zenodoCommunitySearchUtils.page | number}} of {{(totalPages()) | number}} - +
    - - - - - - + -
    -
    - - {{zenodoCommunitySearchUtils.totalResults | number}} zenodo communities, page {{zenodoCommunitySearchUtils.page | number}} of {{(totalPages()) | number}} - - - - +
    + + +
    - +
    +
    + + + + + + + + + + + + - - -
    NameLast update onAction
    + + {{item.title}} + [no name available] +
    +
    +
    + {{item.date | date:'yyyy/MM/dd'}} +
    +
    + + +
    + diff --git a/src/app/pages/zenodo-communities/manage-zenodo-communities.component.ts b/src/app/pages/zenodo-communities/manage-zenodo-communities.component.ts index 2e33ea8..31d1135 100644 --- a/src/app/pages/zenodo-communities/manage-zenodo-communities.component.ts +++ b/src/app/pages/zenodo-communities/manage-zenodo-communities.component.ts @@ -1,114 +1,309 @@ -import {Component, OnInit, Input} from '@angular/core'; +import {Component, OnInit, Input, ViewChild} from '@angular/core'; import {SimpleChanges, OnChanges} from '@angular/core'; import {FormGroup, FormArray, FormBuilder, Validators} from '@angular/forms'; import {ActivatedRoute, Router} from '@angular/router'; +import { Subject } from 'rxjs/Subject'; + +import { DataTableDirective } from 'angular-datatables'; 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'; -import {ManageZenodoCommunitiesService} from './manage-zenodo-communities.service'; -import {ZenodoCommunityInfo} from './zenodoCommunity/zenodoCommunityInfo'; +import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service'; +import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo'; import {Session} from '../../openaireLibrary/login/utils/helper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; +import{ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service'; @Component({ selector: 'manage-zenodo-communities', templateUrl: './manage-zenodo-communities.component.html', + styles: [` + #dpTable_info, #dpTable_paginate, #dpTable_length, #dpTable_filter{ + display: none; + } + + `] }) export class ManageZenodoCommunitiesComponent implements OnInit { - - public zenodoCommunities = null; - public totalZenodoCommunities = null; - public properties:EnvProperties = null; - public communityId = null; + @Input() properties:EnvProperties = null; + @Input() communityId = null; public zenodoCommunitySearchUtils:SearchUtilsClass = new SearchUtilsClass(); private errorCodes: ErrorCodes; public rowsOnPage = 10; + @Input() masterCommunity = null; + @Input() selectedCommunities = []; + @ViewChild(DataTableDirective) datatableElement: DataTableDirective; + dtTrigger: Subject = new Subject(); //necessary + dtOptions: DataTables.Settings = {}; + private triggered: boolean = false; + + @ViewChild('AlertModalDeleteCommunity') alertModalDeleteCommunity; + selectedToDelete = null; constructor (private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder, private _helpContentService: HelpContentService, - private _manageΖenodoCommunitieService: ManageZenodoCommunitiesService) { + private _ΖenodoCommunitieService: ZenodoCommunitiesService, + private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) { this.errorCodes = new ErrorCodes(); this.zenodoCommunitySearchUtils.status = this.errorCodes.LOADING; + this.zenodoCommunitySearchUtils.totalResults = this.selectedCommunities.length; } ngOnInit() { - this.route.data.subscribe((data: { envSpecific: EnvProperties }) => { - this.properties = data.envSpecific; - 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._manageΖ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._manageΖenodoCommunitieService.getTotalZenodoCommunities(this.properties, this.properties.zenodoCommunities).subscribe( - totalZenodoCommunities => { - this.totalZenodoCommunities = totalZenodoCommunities; - this.zenodoCommunitySearchUtils.totalResults = totalZenodoCommunities; - console.log(totalZenodoCommunities); - }); - } - } - }); - }); + + // 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); + // }); + // } + // } + // }); this.zenodoCommunitySearchUtils.keyword = ""; - } + this.dtOptions = { + // "paging": true, + // "searching": true, + // "lengthChange": false, + "pageLength": this.rowsOnPage, + "language": { + "search": "", + "searchPlaceholder": "Search projects..." + } - public search() { - if(!Session.isLoggedIn()){ - console.info(this._router.url); - this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); - } else { - this.zenodoCommunitySearchUtils.page = 1; - if (this.communityId != null && this.communityId != '') { - this._manageΖenodoCommunitieService.getZenodoCommunities(this.properties, this.properties.zenodoCommunities+"?q="+this.zenodoCommunitySearchUtils.keyword+"&page="+this.zenodoCommunitySearchUtils.page+"&size="+this.rowsOnPage).subscribe( - zenodoCommunities => { - this.zenodoCommunities = zenodoCommunities; - console.log(zenodoCommunities); - }); + }; + if(!this.triggered) { + this.triggerInitialLoad(); + } else { + var table = $('#dpTable').DataTable(); + table.clear(); + + this.rerender(); } - } - } - public goTo(page:number = 1) { + + } + + 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; + + 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 = ($('#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(); + // } + // ) + // } if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this.zenodoCommunitySearchUtils.page=page; - console.log("Page is: "+page); - this._manageΖ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); - }); + 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"); + } + ) } } - totalPages(): number { - let totalPages:any = this.zenodoCommunitySearchUtils.totalResults/(this.rowsOnPage); - if(!(Number.isInteger(totalPages))) { - totalPages = (parseInt(totalPages, 10) + 1); + 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 { + 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; + } + + + 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(); } - return totalPages; } + + // 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"); + // } + // ) + // } + // } + } diff --git a/src/app/pages/zenodo-communities/manage-zenodo-communities.module.ts b/src/app/pages/zenodo-communities/manage-zenodo-communities.module.ts deleted file mode 100644 index 03bb93b..0000000 --- a/src/app/pages/zenodo-communities/manage-zenodo-communities.module.ts +++ /dev/null @@ -1,26 +0,0 @@ -import {NgModule} from '@angular/core'; -import {CommonModule} from '@angular/common'; -import {FormsModule} from '@angular/forms'; -import {RouterModule} from '@angular/router'; - -import {PagingModule} from '../../openaireLibrary/utils/paging.module'; -import {ManageZenodoCommunitiesComponent} from './manage-zenodo-communities.component'; -import {ManageZenodoCommunitiesService} from './manage-zenodo-communities.service'; - -@NgModule({ - imports:[ - CommonModule, FormsModule, RouterModule, - PagingModule - ], - declarations:[ - ManageZenodoCommunitiesComponent - ], - providers:[ - ManageZenodoCommunitiesService - ], - exports: [ - ManageZenodoCommunitiesComponent - ] -}) - -export class ManageZenodoCommunitiesModule { } diff --git a/src/app/pages/zenodo-communities/manage-zenodo-communities.service.ts b/src/app/pages/zenodo-communities/manage-zenodo-communities.service.ts deleted file mode 100644 index d5a04a3..0000000 --- a/src/app/pages/zenodo-communities/manage-zenodo-communities.service.ts +++ /dev/null @@ -1,44 +0,0 @@ -import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Headers, RequestOptions} from '@angular/http'; -import {Observable} from 'rxjs/Rx'; - -import {ZenodoCommunityInfo} from './zenodoCommunity/zenodoCommunityInfo'; -import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; - -@Injectable() -export class ManageZenodoCommunitiesService { - - constructor(private http:Http) { - } - - getZenodoCommunities(properties:EnvProperties, url: string) { - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) - .map(res => res.json()).map(res => this.parseZenodoCommunities(res.hits.hits)); - } - - parseZenodoCommunities(data: any): ZenodoCommunityInfo[] { - let zenodoCommunities: ZenodoCommunityInfo[] = []; - - for (let i=0; i res.json()).map(res => res.hits.total); - } -} diff --git a/src/app/pages/zenodo-communities/remove-projects.component.html b/src/app/pages/zenodo-communities/remove-projects.component.html new file mode 100644 index 0000000..99b608d --- /dev/null +++ b/src/app/pages/zenodo-communities/remove-projects.component.html @@ -0,0 +1,94 @@ +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + + + +
    +
    + + {{communitySearchUtils.totalResults | number}} projects, page {{communitySearchUtils.page | number}} of {{(totalPages()) | number}} + + + + +
    +
    + + +
    +
    + + + + + + + + + + + + + + + + + + +
    ProjectGrant IdFunderAction
    + + {{result.name}} + ({{result.acronym}}) + [no title available] + + + {{result.grantId}} + - + + {{result.funder}} + - + + +
    +
    +
    + +
    +
    + + {{communitySearchUtils.totalResults | number}} projects, page {{communitySearchUtils.page | number}} of {{(totalPages()) | number}} + + + + +
    +
    + + + + diff --git a/src/app/pages/zenodo-communities/zenodo-communities.component.ts b/src/app/pages/zenodo-communities/zenodo-communities.component.ts new file mode 100644 index 0000000..76d884b --- /dev/null +++ b/src/app/pages/zenodo-communities/zenodo-communities.component.ts @@ -0,0 +1,150 @@ +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: ` +
    + + +
    + + + +
    + +
    + ` +}) +// +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; + // } +} diff --git a/src/app/pages/zenodo-communities/zenodo-communities.module.ts b/src/app/pages/zenodo-communities/zenodo-communities.module.ts new file mode 100644 index 0000000..53a0bea --- /dev/null +++ b/src/app/pages/zenodo-communities/zenodo-communities.module.ts @@ -0,0 +1,34 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; + +import {PagingModule} from '../../openaireLibrary/utils/paging.module'; +import {ManageZenodoCommunitiesComponent} from './manage-zenodo-communities.component'; +import {AddZenodoCommunitiesComponent} from './add-zenodo-communities.component'; +import {ZenodoCommunitiesComponent} from './zenodo-communities.component'; +import {FABModule} from '../../utils/fabModule.module'; +import { DataTablesModule } from 'angular-datatables'; +import { SearchZenodoCommunitiesServiceModule } from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunitiesService.module'; +import{ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service'; +import{ZenodoCommunitiesServiceModule} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communitiesService.module'; +import {AlertModalModule} from '../../openaireLibrary/utils/modal/alertModal.module'; + +@NgModule({ + imports:[ + CommonModule, FormsModule, RouterModule, + PagingModule, FABModule, DataTablesModule, SearchZenodoCommunitiesServiceModule, ZenodoCommunitiesServiceModule, + AlertModalModule + ], + declarations:[ + ManageZenodoCommunitiesComponent, ZenodoCommunitiesComponent, AddZenodoCommunitiesComponent + ], + providers:[ + ManageZenodoCommunitiesService + ], + exports: [ + ZenodoCommunitiesComponent + ] +}) + +export class ZenodoCommunitiesModule { } diff --git a/src/app/pages/zenodo-communities/zenodoCommunity/zenodoCommunityInfo.ts b/src/app/pages/zenodo-communities/zenodoCommunity/zenodoCommunityInfo.ts deleted file mode 100644 index 5fb7df3..0000000 --- a/src/app/pages/zenodo-communities/zenodoCommunity/zenodoCommunityInfo.ts +++ /dev/null @@ -1,9 +0,0 @@ -export class ZenodoCommunityInfo { - title: string; - id: string; - description: string; - link: string; - logoUrl: string; - date: Date; - page: string; -} diff --git a/src/app/services/manageZenodoCommunities.service.ts b/src/app/services/manageZenodoCommunities.service.ts new file mode 100644 index 0000000..90bbb6f --- /dev/null +++ b/src/app/services/manageZenodoCommunities.service.ts @@ -0,0 +1,43 @@ +import {Injectable} from '@angular/core'; +import {Http, Response, Headers, RequestOptions} from '@angular/http'; +import {Observable} from 'rxjs/Observable'; +import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; + +import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; +import { ErrorObservable } from 'rxjs/observable/ErrorObservable'; +import { catchError } from 'rxjs/operators'; + +@Injectable() +export class ManageZenodoCommunitiesService { + constructor(private http: Http ) {} + + removeZCommunity (properties:EnvProperties,communityId: string,id: string):any { + let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'}); + let options = new RequestOptions({headers: headers, body: id}); + + let url = properties.communityAPI+communityId+"/zenodocommunities"; + console.info(url); + + return this.http.delete(url, options) + } + + addZCommunity(properties:EnvProperties, communityId: string,zenodoid: string) { + let headers = new Headers({'Content-Type': 'application/json'}); + let options = new RequestOptions({headers: headers}); + + let url = properties.communityAPI+communityId+"/zenodocommunities"; + console.info(url); + var zCommunity: any = { + "communityId": communityId, + + "zenodoid": zenodoid + }; + console.info(zCommunity); + return this.http.post(url, JSON.stringify(zCommunity), options) + .map(res => res.json()) + } + + + + +}