[plugins-functionality | DONE | CHANGED ] allow add/remove main zenodo community
This commit is contained in:
parent
488ac615d4
commit
37f8c73720
|
@ -22,7 +22,7 @@
|
|||
<div class="uk-card-body">
|
||||
<preview-zenodo-community [item]="item" [master]="masterCommunity && item.id==masterCommunity.id"></preview-zenodo-community>
|
||||
</div>
|
||||
<div *ngIf="!masterCommunity || item.id!==masterCommunity.id" class="uk-card-footer uk-padding-remove-vertical">
|
||||
<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">
|
||||
|
@ -34,7 +34,17 @@
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="inThelist(item, selectedCommunities)">
|
||||
<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)"
|
||||
class="uk-button uk-button-link uk-flex uk-flex-middle">
|
||||
|
@ -43,6 +53,15 @@
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="(masterCommunity && item.id==masterCommunity.id)">
|
||||
<div class="uk-padding-small uk-padding-remove-horizontal">
|
||||
<a (click)="updateMasterCommunity(null, false)"
|
||||
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>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -11,6 +11,7 @@ import {Subject, Subscription} from 'rxjs';
|
|||
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";
|
||||
|
||||
declare var UIkit;
|
||||
|
||||
|
@ -141,7 +142,8 @@ export class AddZenodoCommunitiesComponent implements OnInit {
|
|||
pos: 'bottom-right'
|
||||
});
|
||||
this.zenodoCommunitiesChanged.emit({
|
||||
value: this.selectedCommunities,
|
||||
communities: this.selectedCommunities,
|
||||
main:this.masterCommunity
|
||||
});
|
||||
},
|
||||
err => {
|
||||
|
@ -150,30 +152,36 @@ export class AddZenodoCommunitiesComponent implements OnInit {
|
|||
}
|
||||
));
|
||||
}
|
||||
|
||||
public removeCommunity(comm) {
|
||||
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(
|
||||
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);
|
||||
}
|
||||
|
||||
UIkit.notification('Community successfully removed!', {
|
||||
status: 'success',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
this.zenodoCommunitiesChanged.emit({
|
||||
value: this.selectedCommunities,
|
||||
});
|
||||
this.afterRemoveActions(comm);
|
||||
},
|
||||
err => {
|
||||
this.handleError('An error has been occurred. Try again later!');
|
||||
|
@ -181,7 +189,28 @@ export class AddZenodoCommunitiesComponent implements OnInit {
|
|||
}
|
||||
));
|
||||
}
|
||||
afterRemoveActions(comm){
|
||||
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);
|
||||
}
|
||||
|
||||
UIkit.notification('Community successfully removed!', {
|
||||
status: 'success',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
this.zenodoCommunitiesChanged.emit({
|
||||
communities: this.selectedCommunities,
|
||||
main:this.masterCommunity
|
||||
});
|
||||
}
|
||||
public inThelist(community: any, list): any {
|
||||
for (let com of list) {
|
||||
if (com.id == community.id) {
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
import {
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
Output, SimpleChanges,
|
||||
ViewChild,
|
||||
ViewEncapsulation
|
||||
} from '@angular/core';
|
||||
import {UntypedFormBuilder, UntypedFormControl} from '@angular/forms';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
||||
import {properties} from "../../../environments/environment";
|
||||
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';
|
||||
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
|
||||
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
||||
import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler";
|
||||
|
||||
@Component({
|
||||
selector: 'manage-zenodo-communities',
|
||||
templateUrl: './manage-zenodo-communities.component.html'
|
||||
})
|
||||
export class ManageZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
||||
properties: EnvProperties = properties;
|
||||
@Input() community: CommunityInfo = null;
|
||||
@Input() public loading: boolean = true;
|
||||
@Input() searchUtils: SearchUtilsClass = null;
|
||||
errorCodes: ErrorCodes;
|
||||
public rowsOnPage = 10;
|
||||
@Input() masterCommunity;
|
||||
@Input() selectedCommunities;
|
||||
previewCommunities = [];
|
||||
@ViewChild('AlertModalDeleteCommunity') alertModalDeleteCommunity;
|
||||
selectedToDelete = null;
|
||||
@Output() addZenodoCommunity: EventEmitter<any> = new EventEmitter();
|
||||
@Output() zenodoCommunitiesChanged = new EventEmitter();
|
||||
page = 1;
|
||||
size = 10;
|
||||
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
||||
public filterForm: UntypedFormControl;
|
||||
private subscriptions: any[] = [];
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private _router: Router,
|
||||
public _fb: UntypedFormBuilder,
|
||||
private cdr: ChangeDetectorRef,
|
||||
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) {
|
||||
this.errorCodes = new ErrorCodes();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(subscription => {
|
||||
if (subscription instanceof Subscription) {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private init() {
|
||||
console.log(this.selectedCommunities.length)
|
||||
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;
|
||||
console.log(this.selectedCommunities.length, this.previewCommunities.length)
|
||||
}
|
||||
|
||||
public filterPreviewCommunities(value: string) {
|
||||
this.previewCommunities = this.selectedCommunities.filter(community => {
|
||||
return !value || community.title.toLowerCase().indexOf(value.toLowerCase()) != -1
|
||||
});
|
||||
console.log("filter", this.previewCommunities.length)
|
||||
if (this.previewCommunities.slice((this.page - 1) * this.rowsOnPage, this.page * this.rowsOnPage).length == 0) {
|
||||
this.page = 1;
|
||||
}
|
||||
console.log("filter - slice", this.previewCommunities.length)
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
public confirmedDeleteCommunity(data: any) {
|
||||
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.community.communityId, this.selectedToDelete.id).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);
|
||||
this.searchUtils.totalResults = this.selectedCommunities.length;
|
||||
}
|
||||
this.searchUtils.totalResults = this.selectedCommunities.length;
|
||||
this.filterPreviewCommunities(this.filterForm.value);
|
||||
NotificationHandler.rise('Community has been <b>successfully removed</b>!')
|
||||
this.zenodoCommunitiesChanged.emit({
|
||||
value: this.selectedCommunities,
|
||||
});
|
||||
},
|
||||
err => {
|
||||
this.handleError('An error has been occurred. Try again later!');
|
||||
console.log(err.status);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
public removeCommunity(comm) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
totalPages(): number {
|
||||
let totalPages: any = this.searchUtils.totalResults / (this.rowsOnPage);
|
||||
if (!(Number.isInteger(totalPages))) {
|
||||
totalPages = (parseInt(totalPages, 10) + 1);
|
||||
}
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
public updatePage($event) {
|
||||
HelperFunctions.scroll();
|
||||
this.page = $event.value;
|
||||
}
|
||||
|
||||
addNew() {
|
||||
this.addZenodoCommunity.emit();
|
||||
}
|
||||
|
||||
handleError(message: string) {
|
||||
NotificationHandler.rise(message, 'danger');
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<div page-content>
|
||||
<div page-content *ngIf="community && searchUtils">
|
||||
<div actions>
|
||||
<div class="uk-section-xsmall uk-margin-top">
|
||||
<div class="uk-flex uk-flex-right@m uk-flex-center uk-flex-middle uk-grid" uk-grid>
|
||||
|
@ -6,7 +6,7 @@
|
|||
placeholder="Search Zenodo Community" [disabled]="searchUtils.status === errorCodes.LOADING"
|
||||
class="uk-width-1-3@xl uk-width-2-5@l uk-width-1-2@m uk-width-1-1"></div>
|
||||
<div>
|
||||
<button class="uk-button uk-button-default uk-flex uk-flex-middle" (click)="addNew()"
|
||||
<button class="uk-button uk-button-default uk-flex uk-flex-middle" (click)="openAddZenodoCommunites()"
|
||||
uk-tooltip="title:<div class='uk-text-bold'> Search and add more Zenodo Communities</div><div>The research results of a Zenodo community specified here will be automatically linked to your community dashboard.</div>"
|
||||
[disabled]="searchUtils.status === errorCodes.LOADING"
|
||||
[class.uk-disabled]="searchUtils.status === errorCodes.LOADING">
|
||||
|
@ -36,14 +36,14 @@
|
|||
[page]="page" [pageSize]="size"
|
||||
[totalResults]="previewCommunities.length">
|
||||
</no-load-paging>
|
||||
<!-- <ul class="uk-margin-medium-top uk-margin-bottom uk-list uk-list-xlarge">-->
|
||||
<!-- <ul class="uk-margin-medium-top uk-margin-bottom uk-list uk-list-xlarge">-->
|
||||
<div class="uk-grid uk-grid-large uk-child-width-1-1 uk-margin-medium-top uk-margin-bottom" uk-grid>
|
||||
<div *ngFor="let item of previewCommunities.slice((this.page - 1)*this.size, this.page*this.size); let i=index">
|
||||
<div class="uk-card uk-card-default">
|
||||
<div class="uk-card-body">
|
||||
<preview-zenodo-community [item]="item" [master]="masterCommunity && item.id==masterCommunity.id"></preview-zenodo-community>
|
||||
</div>
|
||||
<div *ngIf="!masterCommunity || item.id!==masterCommunity.id" class="uk-card-footer uk-padding-remove-vertical">
|
||||
<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-padding-small uk-padding-remove-horizontal">
|
||||
|
@ -56,10 +56,23 @@
|
|||
</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 class="uk-padding-small uk-padding-remove-horizontal">
|
||||
<a (click)="updateMasterCommunity()"
|
||||
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>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- </ul>-->
|
||||
<!-- </ul>-->
|
||||
<div class="uk-margin-small-top">
|
||||
<paging-no-load [currentPage]="page"
|
||||
[totalResults]="previewCommunities.length" [size]="size"
|
||||
|
@ -72,3 +85,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<modal-alert #AlertModalDeleteCommunity (alertOutput)="confirmedDeleteCommunity($event)" [overflowBody]="false"></modal-alert>
|
||||
|
||||
<fs-modal #fsModal>
|
||||
<add-zenodo-communities [masterCommunity]=masterCommunity
|
||||
[selectedCommunities]=selectedCommunities
|
||||
[community]="community" (zenodoCommunitiesChanged)="zenodoCommunitiesChanged($event)"></add-zenodo-communities>
|
||||
</fs-modal>
|
|
@ -1,4 +1,14 @@
|
|||
import {Component, ElementRef, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
||||
import {
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
ElementRef,
|
||||
EventEmitter,
|
||||
Input,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
Output,
|
||||
ViewChild
|
||||
} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
|
||||
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
||||
|
@ -12,47 +22,51 @@ import {Title} from '@angular/platform-browser';
|
|||
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';
|
||||
import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler";
|
||||
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
||||
import {SearchInputComponent} from "../../openaireLibrary/sharedComponents/search-input/search-input.component";
|
||||
import {UntypedFormBuilder, UntypedFormControl} from "@angular/forms";
|
||||
import {ManageZenodoCommunitiesService} from "../../services/manageZenodoCommunities.service";
|
||||
|
||||
@Component({
|
||||
selector: 'zenodo-communities',
|
||||
template: `
|
||||
<manage-zenodo-communities #manage *ngIf="community && zenodoSearchUtils"
|
||||
[loading]="showLoadingInRemove"
|
||||
[masterCommunity]=masterZenodoCommunity [selectedCommunities]=selectedCommunities
|
||||
[community]="community" [searchUtils]=zenodoSearchUtils (addZenodoCommunity)="openAddZenodoCommunites()"
|
||||
(zenodoCommunitiesChanged)="zenodoCommunitiesChanged($event)"></manage-zenodo-communities>
|
||||
<fs-modal #fsModal>
|
||||
<add-zenodo-communities [masterCommunity]=masterZenodoCommunity
|
||||
[selectedCommunities]=selectedCommunities
|
||||
[community]="community" (zenodoCommunitiesChanged)="zenodoCommunitiesChanged($event)"></add-zenodo-communities>
|
||||
</fs-modal>
|
||||
`
|
||||
templateUrl: 'zenodo-communities.component.html'
|
||||
})
|
||||
export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
||||
public community: CommunityInfo = null;
|
||||
public toggle = false;
|
||||
public pageTitle = 'Manage zenodo communities';
|
||||
masterZenodoCommunityId = null;
|
||||
masterZenodoCommunity = null;
|
||||
masterCommunity = null;
|
||||
public properties: EnvProperties = null;
|
||||
selectedCommunityIds = null;
|
||||
selectedCommunities = null;
|
||||
zenodocommunitiesloadedCount = 0;
|
||||
zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
||||
public errorCodes: ErrorCodes = new ErrorCodes();
|
||||
subscriptions = [];
|
||||
@ViewChild('fsModal', {static: true}) fullscreen: FullScreenModalComponent;
|
||||
@ViewChild(ManageZenodoCommunitiesComponent) manage: ManageZenodoCommunitiesComponent;
|
||||
public showLoadingInRemove: boolean = true;
|
||||
|
||||
@Input() public loading: boolean = true;
|
||||
@Input() searchUtils: SearchUtilsClass = new SearchUtilsClass();
|
||||
public rowsOnPage = 10;
|
||||
previewCommunities = [];
|
||||
@ViewChild('AlertModalDeleteCommunity') alertModalDeleteCommunity;
|
||||
selectedToDelete = null;
|
||||
@Output() addZenodoCommunity: EventEmitter<any> = new EventEmitter();
|
||||
page = 1;
|
||||
size = 10;
|
||||
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
||||
public filterForm: UntypedFormControl;
|
||||
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
|
||||
private _zenodoCommunitieService: ZenodoCommunitiesService, private title: Title,
|
||||
private _communityService: CommunityService) {
|
||||
private _communityService: CommunityService,
|
||||
public _fb: UntypedFormBuilder,
|
||||
private cdr: ChangeDetectorRef,
|
||||
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
||||
this.searchUtils.status = this.errorCodes.LOADING;
|
||||
this.properties = properties;
|
||||
|
||||
this.subscriptions.push(this._communityService.getCommunityAsObservable().subscribe(
|
||||
|
@ -62,21 +76,21 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
|||
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
||||
this.selectedCommunities = [];
|
||||
|
||||
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
||||
this.searchUtils.status = this.errorCodes.LOADING;
|
||||
|
||||
this.selectedCommunityIds = this.community.otherZenodoCommunities;
|
||||
if(this.masterZenodoCommunityId){
|
||||
this.selectedCommunityIds.unshift(this.masterZenodoCommunityId)
|
||||
}
|
||||
this.zenodoSearchUtils.totalResults = this.selectedCommunityIds.length;
|
||||
this.searchUtils.totalResults = this.selectedCommunityIds.length;
|
||||
if (this.selectedCommunityIds.length === 0) {
|
||||
this.zenodoSearchUtils.status = this.errorCodes.NONE;
|
||||
this.searchUtils.status = this.errorCodes.NONE;
|
||||
}
|
||||
for (let i = 0; i < this.selectedCommunityIds.length; i++) {
|
||||
this.getZenodoCommunityById(
|
||||
this.selectedCommunityIds[i]);
|
||||
}
|
||||
|
||||
this.init();
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -98,7 +112,7 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
|||
zenodoid).subscribe(
|
||||
result => {
|
||||
if(zenodoid == this.masterZenodoCommunityId){
|
||||
this.masterZenodoCommunity = result;
|
||||
this.masterCommunity = result;
|
||||
result.master = true;
|
||||
this.selectedCommunities.unshift(result);
|
||||
}else {
|
||||
|
@ -106,7 +120,7 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
this.zenodocommunitiesloadedCount++;
|
||||
if (this.zenodocommunitiesloadedCount >= this.selectedCommunityIds.length) {
|
||||
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
||||
this.searchUtils.status = this.errorCodes.DONE;
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -117,7 +131,7 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
|||
this.selectedCommunities.push(emptyCommunity);
|
||||
this.zenodocommunitiesloadedCount++;
|
||||
if (this.zenodocommunitiesloadedCount >= this.selectedCommunityIds.length) {
|
||||
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
||||
this.searchUtils.status = this.errorCodes.DONE;
|
||||
}
|
||||
console.log('Zenodo community\'' + zenodoid + '\' couldn\'t be loaded');
|
||||
}
|
||||
|
@ -134,11 +148,124 @@ export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
public zenodoCommunitiesChanged($event) {
|
||||
this.selectedCommunities = $event.value;
|
||||
this.showLoadingInRemove = false;
|
||||
|
||||
if (this.fullscreen.isOpen) {
|
||||
this.manage.filterPreviewCommunities(this.manage.filterForm.value);
|
||||
this.selectedCommunities = $event.communities;
|
||||
this.masterCommunity = $event.main;
|
||||
if(!this.masterZenodoCommunityId && $event.main){
|
||||
this.selectedCommunityIds.unshift($event.main.id)
|
||||
this.selectedCommunities.unshift($event.main);
|
||||
}
|
||||
this.masterZenodoCommunityId = $event.main?$event.main.id:null;
|
||||
this.showLoadingInRemove = false;
|
||||
if (this.fullscreen.isOpen) {
|
||||
this.filterPreviewCommunities(this.filterForm.value);
|
||||
}
|
||||
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 => {
|
||||
this.page = 1;
|
||||
this.filterPreviewCommunities(value);
|
||||
}));
|
||||
this.searchUtils.keyword = "";
|
||||
this.searchUtils.totalResults = this.selectedCommunities.length;
|
||||
console.log(this.selectedCommunities.length, this.previewCommunities.length)
|
||||
}
|
||||
|
||||
public filterPreviewCommunities(value: string) {
|
||||
this.previewCommunities = this.selectedCommunities.filter(community => {
|
||||
return !value || community.title.toLowerCase().indexOf(value.toLowerCase()) != -1
|
||||
});
|
||||
if (this.previewCommunities.slice((this.page - 1) * this.rowsOnPage, this.page * this.rowsOnPage).length == 0) {
|
||||
this.page = 1;
|
||||
}
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
public confirmedDeleteCommunity(data: any) {
|
||||
this.subscriptions.push(this._manageZenodoCommunitiesService.removeZCommunity(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 (pos != -1) {
|
||||
this.selectedCommunities.splice(pos, 1);
|
||||
this.searchUtils.totalResults = this.selectedCommunities.length;
|
||||
}
|
||||
this.searchUtils.totalResults = this.selectedCommunities.length;
|
||||
this.filterPreviewCommunities(this.filterForm.value);
|
||||
NotificationHandler.rise('Community has been <b>successfully removed</b>!')
|
||||
|
||||
}
|
||||
public removeCommunity(comm) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
totalPages(): number {
|
||||
let totalPages: any = this.searchUtils.totalResults / (this.rowsOnPage);
|
||||
if (!(Number.isInteger(totalPages))) {
|
||||
totalPages = (parseInt(totalPages, 10) + 1);
|
||||
}
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
public updatePage($event) {
|
||||
HelperFunctions.scroll();
|
||||
this.page = $event.value;
|
||||
}
|
||||
|
||||
addNew() {
|
||||
this.addZenodoCommunity.emit();
|
||||
}
|
||||
|
||||
handleError(message: string) {
|
||||
NotificationHandler.rise(message, 'danger');
|
||||
}
|
||||
public updateMasterCommunity() {
|
||||
this.subscriptions.push(this._manageZenodoCommunitiesService.updateMasterZCommunity(this.properties ,this.community.communityId,"").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'
|
||||
});*/
|
||||
|
||||
},
|
||||
err => {
|
||||
this.handleError('An error has been occurred. Try again later!');
|
||||
console.log(err.status);
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import {NgModule} from '@angular/core';
|
|||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {RouterModule} from '@angular/router';
|
||||
import {ManageZenodoCommunitiesComponent} from './manage-zenodo-communities.component';
|
||||
import {AddZenodoCommunitiesComponent} from './add-zenodo-communities.component';
|
||||
import {ZenodoCommunitiesComponent} from './zenodo-communities.component';
|
||||
import {ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service';
|
||||
|
@ -25,7 +24,7 @@ import {PagingModule} from "../../openaireLibrary/utils/paging.module";
|
|||
AlertModalModule, ZenodoCommunitiesRoutingModule, PageContentModule, SearchInputModule, IconsModule, NoLoadPaging, LoadingModule, FullScreenModalModule, HTMLToStringPipeModule, PagingModule
|
||||
],
|
||||
declarations: [
|
||||
ManageZenodoCommunitiesComponent, ZenodoCommunitiesComponent, AddZenodoCommunitiesComponent, PreviewZenodoCommunityComponent
|
||||
ZenodoCommunitiesComponent, AddZenodoCommunitiesComponent, PreviewZenodoCommunityComponent
|
||||
],
|
||||
providers: [
|
||||
ManageZenodoCommunitiesService
|
||||
|
|
Loading…
Reference in New Issue