[plugins-functionality | DONE | CHANGED ] update the way we manage zenodo communities and master zenodo community

This commit is contained in:
argirok 2024-06-10 09:03:55 +03:00
parent a9945d5da4
commit 59e9c77e49
7 changed files with 167 additions and 164 deletions

View File

@ -24,26 +24,6 @@
</div>
<div class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<div *ngIf="!inThelist(item, selectedCommunities) && !(masterCommunity && item.id==masterCommunity.id)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="addCommunity(item)" class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">
Add
</span>
</a>
</div>
</div>
<div *ngIf="!inThelist(item, selectedCommunities) && !(masterCommunity)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="updateMasterCommunity(item)" class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">
Add as Main
</span>
</a>
</div>
</div>
<div *ngIf="inThelist(item, selectedCommunities) && !(masterCommunity && item.id==masterCommunity.id)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="removeCommunity(item)"
@ -55,13 +35,34 @@
</div>
<div *ngIf="(masterCommunity && item.id==masterCommunity.id)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="updateMasterCommunity(null, false)"
<a (click)="removeCommunity(item, true)"
class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="remove" [flex]="true"></icon>
<span class="uk-margin-small-left">Remove</span>
<span class="uk-margin-small-left">Remove as master</span>
</a>
</div>
</div>
<div *ngIf="!inThelist(item, selectedCommunities)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="addCommunity(item)" class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">
Add
</span>
</a>
</div>
</div>
<div *ngIf="!(masterCommunity)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="addCommunity(item,true)" class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">
Add as Main
</span>
</a>
</div>
</div>
</div>
</div>
</div>

View File

@ -12,6 +12,7 @@ import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
import {CommunityService} from "../../openaireLibrary/connect/community/community.service";
import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler";
declare var UIkit;
@ -40,7 +41,8 @@ export class AddZenodoCommunitiesComponent implements OnInit {
private _router: Router,
public _fb: UntypedFormBuilder,
private _zenodoCommunitieService: ZenodoCommunitiesService,
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) {
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService,
private _communityService: CommunityService) {
this.errorCodes = new ErrorCodes();
this.zenodoCommunitySearchUtils.status = this.errorCodes.LOADING;
@ -131,12 +133,19 @@ export class AddZenodoCommunitiesComponent implements OnInit {
}
public addCommunity(community) {
this.subscriptions.push(this._manageZenodoCommunitiesService.addZCommunity(this.properties, this.community.communityId, community.id).subscribe(
public addCommunity(community, master:boolean = false) {
if(master && this.getPosition(community) == -1 ){
this.addCommunity(community, false);
}
this.subscriptions.push(this._manageZenodoCommunitiesService.addZenodoCommunity(this.properties, this.community.communityId, community.id, master).subscribe(
data => {
community["openaireId"] = data.id;
this.selectedCommunities.push(community);
UIkit.notification('Community successfully added!', {
// this._communityService.setCommunity(this._communityService.parseCommunity(data));
if(master){
this.masterCommunity = community;
}else {
this.selectedCommunities.push(community);
}
UIkit.notification('Community successfully added' + (master?" as master!":"!"), {
status: 'success',
timeout: 6000,
pos: 'bottom-right'
@ -152,36 +161,12 @@ export class AddZenodoCommunitiesComponent implements OnInit {
}
));
}
public updateMasterCommunity(community, add=true) {
this.subscriptions.push(this._manageZenodoCommunitiesService.updateMasterZCommunity(this.properties ,this.community.communityId,community?community.id:"").subscribe(
data => {
let comm = Object.assign({}, this.masterCommunity)
this.masterCommunity = community;
if(!add){
this.afterRemoveActions(comm)
}else {
UIkit.notification('Community successfully added', {
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
this.zenodoCommunitiesChanged.emit({
communities: this.selectedCommunities,
main: this.masterCommunity
});
}
},
err => {
this.handleError('An error has been occurred. Try again later!');
console.log(err.status);
}
));
}
public removeCommunity(comm, master:boolean = false) {
var openaireId = this.getOpenaireId(comm);
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.community.communityId, openaireId,).subscribe(
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZenodoCommunity(this.properties, this.community.communityId, openaireId, master).subscribe(
data => {
this.afterRemoveActions(comm);
this.afterRemoveActions(comm, master);
},
err => {
this.handleError('An error has been occurred. Try again later!');
@ -189,7 +174,7 @@ export class AddZenodoCommunitiesComponent implements OnInit {
}
));
}
afterRemoveActions(comm){
getPosition(comm){
var pos = -1;
for (var i = 0; i < this.selectedCommunities.length; i++) {
if (this.selectedCommunities[i].id == comm.id) {
@ -197,18 +182,22 @@ export class AddZenodoCommunitiesComponent implements OnInit {
break;
}
}
if (pos != -1) {
this.selectedCommunities.splice(pos, 1);
return pos;
}
afterRemoveActions(comm, master:boolean = false){
if(master){
this.masterCommunity = null;
NotificationHandler.rise('Community has been <b>removed from master</b>!')
}else {
var pos = this.getPosition(comm)
if (pos != -1) {
this.selectedCommunities.splice(pos, 1);
}
}
UIkit.notification('Community successfully removed!', {
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
NotificationHandler.rise('Community has been <b>removed</b>!')
this.zenodoCommunitiesChanged.emit({
communities: this.selectedCommunities,
main:this.masterCommunity
main: this.masterCommunity
});
}
public inThelist(community: any, list): any {

View File

@ -8,7 +8,7 @@ import {Component, Input} from '@angular/core';
<a target="_blank" [href]="item.link">
<img *ngIf="item.logoUrl"
src="{{item.logoUrl}}" width="80" height="80"
alt="{{item.title}}">
alt="">
</a>
</div>
<div class="uk-width-expand">

View File

@ -19,6 +19,7 @@
</div>
<div inner>
<div class="uk-section uk-section-small uk-position-relative" style="min-height: 60vh">
<validate-page-enabled pageRoute="/participate/deposit/zenodo"></validate-page-enabled>
<div *ngIf="searchUtils.status == errorCodes.LOADING" class="uk-position-center">
<loading></loading>
</div>
@ -43,9 +44,9 @@
<div class="uk-card-body">
<preview-zenodo-community [item]="item" [master]="masterCommunity && item.id==masterCommunity.id"></preview-zenodo-community>
</div>
<div *ngIf="item.id!==masterZenodoCommunityId" class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<div>
<div class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<div *ngIf="item.id!==masterZenodoCommunityId" >
<div class="uk-padding-small uk-padding-remove-horizontal">
<button class="uk-button uk-button-link uk-flex uk-flex-middle"
(click)="removeCommunity(item)">
@ -54,16 +55,22 @@
</button>
</div>
</div>
</div>
</div>
<div *ngIf="(item.id==masterZenodoCommunityId)" class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<div>
<div *ngIf="(item.id==masterZenodoCommunityId)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="updateMasterCommunity()"
<a (click)="removeFromMasterCommunity(item)"
class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="remove" [flex]="true"></icon>
<span class="uk-margin-small-left">Remove</span>
<span class="uk-margin-small-left">Remove as master</span>
</a>
</div>
</div>
<div *ngIf="(!masterZenodoCommunityId)">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="addAsMasterCommunity(item)"
class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">Add as master</span>
</a>
</div>
</div>
@ -87,7 +94,7 @@
<modal-alert #AlertModalDeleteCommunity (alertOutput)="confirmedDeleteCommunity($event)" [overflowBody]="false"></modal-alert>
<fs-modal #fsModal>
<add-zenodo-communities [masterCommunity]=masterCommunity
<add-zenodo-communities *ngIf="community" [masterCommunity]=masterCommunity
[selectedCommunities]=selectedCommunities
[community]="community" (zenodoCommunitiesChanged)="zenodoCommunitiesChanged($event)"></add-zenodo-communities>
</fs-modal>

View File

@ -57,6 +57,7 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
size = 10;
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
public filterForm: UntypedFormControl;
deleteMaster = false;
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
private _zenodoCommunitieService: ZenodoCommunitiesService, private title: Title,
private _communityService: CommunityService,
@ -68,32 +69,27 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
ngOnInit() {
this.searchUtils.status = this.errorCodes.LOADING;
this.properties = properties;
this.subscriptions.push(this._communityService.getCommunityAsObservable().subscribe(
community => {
this.community = community;
this.title.setTitle(this.community.shortTitle.toUpperCase() + ' | Zenodo Communities');
this.masterZenodoCommunityId = this.community.zenodoCommunity;
this.selectedCommunities = [];
this.searchUtils.status = this.errorCodes.LOADING;
this.selectedCommunityIds = this.community.otherZenodoCommunities;
if(this.masterZenodoCommunityId){
this.selectedCommunityIds.unshift(this.masterZenodoCommunityId)
}
this.searchUtils.totalResults = this.selectedCommunityIds.length;
if (this.selectedCommunityIds.length === 0) {
this.searchUtils.status = this.errorCodes.NONE;
}
for (let i = 0; i < this.selectedCommunityIds.length; i++) {
this.getZenodoCommunityById(
this.selectedCommunityIds[i]);
}
this.init();
})
);
this.subscriptions.push(this.route.params.subscribe(params => {
//use this method to ensure that get the lattest version of the community and the updated information for the list of zenodo communities
this.subscriptions.push(this._communityService.getCommunity(params['community'],true).subscribe(
community => {
this.community = community;
this.title.setTitle(this.community.shortTitle.toUpperCase() + ' | Zenodo Communities');
this.masterZenodoCommunityId = this.community.zenodoCommunity;
this.selectedCommunities = [];
this.searchUtils.status = this.errorCodes.LOADING;
this.selectedCommunityIds = this.community.otherZenodoCommunities;
this.searchUtils.totalResults = this.selectedCommunityIds.length;
if (this.selectedCommunityIds.length === 0) {
this.searchUtils.status = this.errorCodes.NONE;
}
for (let i = 0; i < this.selectedCommunityIds.length; i++) {
this.getZenodoCommunityById(this.selectedCommunityIds[i]);
}
this.init();
})
);
}));
this.fullscreen.title = "Search and Add Zenodo Communities";
this.fullscreen.okButtonText = "Done";
this.fullscreen.okButton = true;
@ -162,7 +158,6 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
this.filterPreviewCommunities(this.searchUtils.keyword);
}
private init() {
console.log(this.selectedCommunities.length)
this.filterForm = this._fb.control('');
this.filterPreviewCommunities("");
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
@ -171,7 +166,6 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
}));
this.searchUtils.keyword = "";
this.searchUtils.totalResults = this.selectedCommunities.length;
console.log(this.selectedCommunities.length, this.previewCommunities.length)
}
public filterPreviewCommunities(value: string) {
@ -185,30 +179,45 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
}
public confirmedDeleteCommunity(data: any) {
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.community.communityId, this.selectedToDelete.id).subscribe(
data => {
this.afterRemoveActions();
}
));
if(this.deleteMaster){
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZenodoCommunity(this.properties, this.community.communityId, this.selectedToDelete.id, true).subscribe(
data => {
this.afterRemoveActions();
}
));
}else {
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZenodoCommunity(this.properties, this.community.communityId, this.selectedToDelete.id).subscribe(
data => {
this.afterRemoveActions();
}
));
}
}
afterRemoveActions(){
var pos = -1;
for (var i = 0; i < this.selectedCommunities.length; i++) {
if (this.selectedCommunities[i].id == this.selectedToDelete.id) {
pos = i;
break;
if(this.deleteMaster){
this.masterCommunity = null;
this.masterZenodoCommunityId = null
NotificationHandler.rise('Community has been <b>removed from master</b>!')
}else {
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);
this.selectedCommunityIds.splice(pos,1)
this.searchUtils.totalResults = this.selectedCommunities.length;
}
}
if (pos != -1) {
this.selectedCommunities.splice(pos, 1);
this.searchUtils.totalResults = this.selectedCommunities.length;
this.filterPreviewCommunities(this.filterForm.value);
NotificationHandler.rise('Community has been <b>successfully removed</b>!')
}
this.searchUtils.totalResults = this.selectedCommunities.length;
this.filterPreviewCommunities(this.filterForm.value);
NotificationHandler.rise('Community has been <b>successfully removed</b>!')
}
public removeCommunity(comm) {
this.deleteMaster = false;
this.selectedToDelete = comm;
this.alertModalDeleteCommunity.cancelButton = true;
this.alertModalDeleteCommunity.okButton = true;
@ -227,6 +236,26 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
this.alertModalDeleteCommunity.open();
}
public removeFromMasterCommunity(comm) {
this.deleteMaster = true;
this.selectedToDelete = comm;
this.alertModalDeleteCommunity.cancelButton = true;
this.alertModalDeleteCommunity.okButton = true;
this.alertModalDeleteCommunity.alertTitle = "Remove master 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 as master from your community, but will remain in the list of the related communities. Do you want to proceed?";
this.alertModalDeleteCommunity.okButtonText = "Yes";
this.alertModalDeleteCommunity.open();
}
totalPages(): number {
let totalPages: any = this.searchUtils.totalResults / (this.rowsOnPage);
@ -248,19 +277,11 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
handleError(message: string) {
NotificationHandler.rise(message, 'danger');
}
public updateMasterCommunity() {
this.subscriptions.push(this._manageZenodoCommunitiesService.updateMasterZCommunity(this.properties ,this.community.communityId,"").subscribe(
public addAsMasterCommunity(community) {
this.subscriptions.push(this._manageZenodoCommunitiesService.addZenodoCommunity(this.properties ,this.community.communityId,community.id, true).subscribe(
data => {
this.selectedToDelete = this.masterCommunity;
this.masterCommunity = null;
this.masterZenodoCommunityId = null
this.afterRemoveActions();
/* UIkit.notification('Community successfully ' + (community?'added!':'removed!'), {
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});*/
this.masterCommunity = community;
this.masterZenodoCommunityId = community.id
},
err => {
this.handleError('An error has been occurred. Try again later!');
@ -268,4 +289,5 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
}
));
}
}

View File

@ -17,11 +17,12 @@ import {PageContentModule} from '../../openaireLibrary/dashboard/sharedComponent
import {FullScreenModalModule} from '../../openaireLibrary/utils/modal/full-screen-modal/full-screen-modal.module';
import {HTMLToStringPipeModule} from '../../openaireLibrary/utils/pipes/HTMLToStringPipe.module';
import {PagingModule} from "../../openaireLibrary/utils/paging.module";
import {ValidateEnabledPageModule} from "../../utils/validateEnabledPage.module";
@NgModule({
imports: [
CommonModule, FormsModule, RouterModule, ZenodoCommunitiesServiceModule,
AlertModalModule, ZenodoCommunitiesRoutingModule, PageContentModule, SearchInputModule, IconsModule, NoLoadPaging, LoadingModule, FullScreenModalModule, HTMLToStringPipeModule, PagingModule
AlertModalModule, ZenodoCommunitiesRoutingModule, PageContentModule, SearchInputModule, IconsModule, NoLoadPaging, LoadingModule, FullScreenModalModule, HTMLToStringPipeModule, PagingModule, ValidateEnabledPageModule
],
declarations: [
ZenodoCommunitiesComponent, AddZenodoCommunitiesComponent, PreviewZenodoCommunityComponent

View File

@ -5,42 +5,25 @@ import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
@Injectable()
export class ManageZenodoCommunitiesService {
constructor(private http: HttpClient ) {}
removeZCommunity (properties: EnvProperties, pid: string,id: string):any {
//let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'});
//let options = new RequestOptions({headers: headers, body: id});
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'});
let url = properties.communityAPI + pid + "/zenodocommunities?zenodocommunity="+id;
//return this.http.delete(url, options);
return this.http.request('delete', url, { headers: headers})
}
addZCommunity(properties:EnvProperties, pid: string,zenodoid: string) {
//let headers = new Headers({'Content-Type': 'application/json'});
//let options = new RequestOptions({headers: headers});
let headers = new HttpHeaders({'Content-Type': 'application/json'});
let url = properties.communityAPI+pid+"/zenodocommunities?zenodocommunity="+zenodoid;
return this.http.post<any>(url, headers);
//.map(res => <any> res.json())
}
updateMasterZCommunity(properties:EnvProperties, pid: string,zenodoid: string) {
removeZenodoCommunity(properties:EnvProperties, pid: string,zenodoid: string, main:boolean = false) {
const options = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
})
};
let url = properties.communityAPI+pid;
let url = properties.communityAPI+pid+"/zenodocommunities?zenodocommunity="+zenodoid + "&main=" + main;
return this.http.delete<any>(url, options);
}
addZenodoCommunity(properties:EnvProperties, pid: string,zenodoid: string, main:boolean = false) {
return this.http.post<any>(url, {mainZenodoCommunity:zenodoid}, options);
//.map(res => <any> res.json())
const options = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
})
};
let url = properties.communityAPI+pid+"/zenodocommunities?zenodocommunity="+zenodoid + "&main=" + main;
return this.http.post<any>(url, options);
}
}