2021-05-19 13:40:29 +02:00
|
|
|
import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
|
|
import {Subscriber} from 'rxjs';
|
|
|
|
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {ManageCommunityProjectsService} from '../../services/manageProjects.service';
|
|
|
|
import {SearchCommunityProjectsService} from '../../openaireLibrary/connect/projects/searchProjects.service';
|
|
|
|
import {RouterHelper} from '../../openaireLibrary/utils/routerHelper.class';
|
2022-09-23 16:14:20 +02:00
|
|
|
import {UntypedFormArray, UntypedFormBuilder, UntypedFormGroup} from "@angular/forms";
|
2021-05-19 13:40:29 +02:00
|
|
|
import {properties} from "../../../environments/environment";
|
|
|
|
import {CommunityService} from "../../openaireLibrary/connect/community/community.service";
|
|
|
|
import {Option} from "../../openaireLibrary/sharedComponents/input/input.component";
|
|
|
|
import {SearchInputComponent} from "../../openaireLibrary/sharedComponents/search-input/search-input.component";
|
2022-07-05 00:31:56 +02:00
|
|
|
import {DropdownFilterComponent} from "../../openaireLibrary/utils/dropdown-filter/dropdown-filter.component";
|
|
|
|
import {OpenaireEntities} from "../../openaireLibrary/utils/properties/searchFields";
|
|
|
|
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
|
|
|
|
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
2022-07-13 19:26:10 +02:00
|
|
|
import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler";
|
2022-08-11 11:58:20 +02:00
|
|
|
import {ClearCacheService} from "../../openaireLibrary/services/clear-cache.service";
|
2023-09-19 14:59:37 +02:00
|
|
|
import {debounceTime, distinctUntilChanged} from "rxjs/operators";
|
2023-10-26 08:49:04 +02:00
|
|
|
import {IndexInfoService} from "../../openaireLibrary/utils/indexInfo.service";
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'remove-projects',
|
|
|
|
templateUrl: './remove-projects.component.html'
|
|
|
|
})
|
|
|
|
export class RemoveProjectsComponent implements OnInit {
|
2022-07-05 00:31:56 +02:00
|
|
|
@Input() public community: CommunityInfo;
|
|
|
|
@Input() public loading: boolean = true;
|
|
|
|
@Output() addProjects: EventEmitter<void> = new EventEmitter();
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
|
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
2022-07-13 19:26:10 +02:00
|
|
|
public projectUrl = "https://" + ((properties.environment == "beta" || properties.environment == "development") ? "beta." : "") + "explore.openaire.eu" + properties.searchLinkToProject.split("?")[0];
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
@Output() communityProjectsChanged = new EventEmitter();
|
2023-09-19 14:59:37 +02:00
|
|
|
// @Input() public communityProjects = [];
|
2021-05-19 13:40:29 +02:00
|
|
|
public previewCommunityProjects = [];
|
|
|
|
public communitySearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public errorCodes: ErrorCodes;
|
|
|
|
properties: EnvProperties = properties;
|
|
|
|
|
|
|
|
private selectedCommunityProject: any;
|
|
|
|
@ViewChild('AlertModalDeleteCommunity') alertModalDeleteCommunity;
|
|
|
|
|
|
|
|
/* Paging */
|
|
|
|
page: number = 1;
|
|
|
|
resultsPerPage: number = properties.resultsPerPage;
|
|
|
|
|
|
|
|
/* Search */
|
|
|
|
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
2022-09-23 16:14:20 +02:00
|
|
|
filterForm: UntypedFormGroup;
|
2021-05-19 13:40:29 +02:00
|
|
|
private searchText: RegExp = new RegExp('');
|
|
|
|
public keyword: string = '';
|
2023-10-04 15:04:42 +02:00
|
|
|
allFunderOptions: Option[] = [];
|
|
|
|
previewFunderOptions: Option[] = [];
|
2021-05-19 13:40:29 +02:00
|
|
|
sortOptions: Option[] = [
|
2023-10-04 15:04:42 +02:00
|
|
|
{label: "Title ", value: {sort: "name", descending: false}},
|
|
|
|
{label: "Grant ID ", value: {sort: "grantId", descending: false}},
|
2021-05-19 13:40:29 +02:00
|
|
|
{label: "Funder ", value: {sort: "funder", descending: false}}
|
|
|
|
];
|
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
public openaireEntiites = OpenaireEntities;
|
2023-10-26 08:49:04 +02:00
|
|
|
lastDBLoadDate = null;
|
2021-05-19 13:40:29 +02:00
|
|
|
constructor(private route: ActivatedRoute, private _router: Router,
|
2022-09-23 16:14:20 +02:00
|
|
|
private _fb: UntypedFormBuilder,
|
2021-05-19 13:40:29 +02:00
|
|
|
private communityService: CommunityService,
|
|
|
|
private _manageCommunityProjectsService: ManageCommunityProjectsService,
|
2022-08-11 11:58:20 +02:00
|
|
|
private _searchCommunityProjectsService: SearchCommunityProjectsService,
|
2023-10-26 08:49:04 +02:00
|
|
|
private _clearCacheService: ClearCacheService, private indexInfoService: IndexInfoService) {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.communitySearchUtils.status = this.errorCodes.LOADING;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2023-10-26 08:49:04 +02:00
|
|
|
this.subscriptions.push(this.indexInfoService.getDBLoadLastDate(this.properties).subscribe(res => {
|
|
|
|
this.lastDBLoadDate = res;
|
|
|
|
}));
|
2021-05-19 13:40:29 +02:00
|
|
|
this.communitySearchUtils.keyword = "";
|
|
|
|
|
|
|
|
this.filterForm = this._fb.group({
|
|
|
|
keyword: [''],
|
2023-10-04 15:04:42 +02:00
|
|
|
funder: this._fb.control(null),
|
2021-05-19 13:40:29 +02:00
|
|
|
sort: this._fb.control(this.sortOptions[0].value)
|
|
|
|
});
|
|
|
|
|
2023-09-19 14:59:37 +02:00
|
|
|
this.subscriptions.push(this.filterForm.get('keyword').valueChanges.pipe(debounceTime(500), distinctUntilChanged()).subscribe(value => {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.page = 1;
|
2023-10-04 15:04:42 +02:00
|
|
|
this._getCommunityProjects(this.page, this.filterForm.get('keyword').value,(this.filterForm.get("funder").value? this.filterForm.get("funder").value.id:null),
|
|
|
|
this.filterForm.get("sort").value.sort );
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2023-09-19 14:59:37 +02:00
|
|
|
}));
|
2021-05-19 13:40:29 +02:00
|
|
|
this.subscriptions.push(this.filterForm.get('sort').valueChanges.subscribe(value => {
|
|
|
|
this.page = 1;
|
2023-10-04 15:04:42 +02:00
|
|
|
this._getCommunityProjects(this.page, this.filterForm.get('keyword').value, this.filterForm.get("funder").value? this.filterForm.get("funder").value.id:null, this.filterForm.get("sort").value.sort );
|
2021-05-19 13:40:29 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe(community => {
|
|
|
|
if (community) {
|
2022-07-05 00:31:56 +02:00
|
|
|
this.community = community;
|
2021-05-19 13:40:29 +02:00
|
|
|
this.projectUrl = "https://"
|
|
|
|
+ ((this.properties.environment == "beta" || this.properties.environment == "development") ? "beta." : "")
|
2022-07-05 00:31:56 +02:00
|
|
|
+ this.community.communityId + ".openaire.eu" + this.properties.searchLinkToProject.split("?")[0];
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
this.keyword = '';
|
2023-10-04 15:04:42 +02:00
|
|
|
this._getCommunityFunders();
|
2023-09-19 14:59:37 +02:00
|
|
|
this._getCommunityProjects(1,this.keyword, null);
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(sub => {
|
|
|
|
if (sub instanceof Subscriber) {
|
|
|
|
sub.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
totalPages(): number {
|
|
|
|
let totalPages: any = this.communitySearchUtils.totalResults / (this.resultsPerPage);
|
|
|
|
if (!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
|
|
|
return totalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
public confirmedDeleteProject(data: any) {
|
2023-07-14 10:43:27 +02:00
|
|
|
this.subscriptions.push(this._manageCommunityProjectsService.removeProject(this.properties, this.community.communityId, this.selectedCommunityProject.openaireId).subscribe(
|
2022-07-11 17:48:24 +02:00
|
|
|
data => {
|
2023-10-04 15:04:42 +02:00
|
|
|
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache(this.openaireEntiites.PROJECT+" removed", this.community.communityId);
|
2022-07-13 19:26:10 +02:00
|
|
|
NotificationHandler.rise(OpenaireEntities.PROJECT+' successfully removed!');
|
2023-09-19 14:59:37 +02:00
|
|
|
this._getCommunityProjects(this.communitySearchUtils.page, this.keyword,null);
|
|
|
|
|
2022-07-11 17:48:24 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError('An error has been occurred. Try again later!');
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public removeProject(communityProject: any) {
|
2022-07-11 17:48:24 +02:00
|
|
|
this.selectedCommunityProject = communityProject;
|
|
|
|
this.alertModalDeleteCommunity.cancelButton = true;
|
|
|
|
this.alertModalDeleteCommunity.okButton = true;
|
|
|
|
this.alertModalDeleteCommunity.alertTitle = "Remove "+OpenaireEntities.PROJECT;
|
|
|
|
let title = "";
|
|
|
|
if (communityProject.name) {
|
|
|
|
title = communityProject.name;
|
|
|
|
}
|
|
|
|
if (communityProject.name && communityProject.acronym) {
|
|
|
|
title += " (";
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2022-07-11 17:48:24 +02:00
|
|
|
if (communityProject.acronym) {
|
|
|
|
title += communityProject.acronym;
|
|
|
|
}
|
|
|
|
if (communityProject.name && communityProject.acronym) {
|
|
|
|
title += ")";
|
|
|
|
}
|
|
|
|
this.alertModalDeleteCommunity.message = OpenaireEntities.PROJECT;
|
|
|
|
if (title) {
|
|
|
|
this.alertModalDeleteCommunity.message += " <b>" + title + "</b> ";
|
|
|
|
}
|
|
|
|
this.alertModalDeleteCommunity.message += "will be removed from your "+OpenaireEntities.COMMUNITY.toLowerCase()+". Are you sure?";
|
|
|
|
this.alertModalDeleteCommunity.okButtonText = "Yes";
|
|
|
|
this.alertModalDeleteCommunity.open();
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2023-09-19 14:59:37 +02:00
|
|
|
public getCommunityProjects() {
|
|
|
|
this._getCommunityProjects(this.communitySearchUtils.page, this.keyword,null );
|
|
|
|
}
|
2023-10-04 15:04:42 +02:00
|
|
|
public _getCommunityProjects(page, keyword, funder, orderBy = "name" ) {
|
2022-07-11 17:48:24 +02:00
|
|
|
this.communitySearchUtils.status = this.errorCodes.LOADING;
|
2023-09-19 14:59:37 +02:00
|
|
|
this.communitySearchUtils.page = page;
|
|
|
|
this.communitySearchUtils.keyword = keyword;
|
2023-10-04 15:04:42 +02:00
|
|
|
this.subscriptions.push(this._searchCommunityProjectsService.searchProjectsWithPaging(this.properties, this.community.communityId, this.communitySearchUtils.page, this.resultsPerPage, this.communitySearchUtils.keyword, funder, orderBy).subscribe(
|
2022-07-11 17:48:24 +02:00
|
|
|
data => {
|
2023-09-19 14:59:37 +02:00
|
|
|
this.previewCommunityProjects = data.content;
|
|
|
|
this.communitySearchUtils.totalResults = data.totalElements;
|
2022-07-11 17:48:24 +02:00
|
|
|
this.communitySearchUtils.status = this.errorCodes.DONE;
|
|
|
|
this.communityProjectsChanged.emit({
|
2023-09-19 14:59:37 +02:00
|
|
|
value: this.communitySearchUtils.totalResults
|
2022-07-11 17:48:24 +02:00
|
|
|
});
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.error(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
|
|
|
|
if (err.status == '404') {
|
|
|
|
this.communitySearchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if (err.status == '500') {
|
|
|
|
this.communitySearchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.communitySearchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2022-07-11 17:48:24 +02:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2023-10-04 15:04:42 +02:00
|
|
|
public _getCommunityFunders() {
|
|
|
|
this.subscriptions.push(this._searchCommunityProjectsService.getProjectFunders(this.properties, this.community.communityId).subscribe(
|
|
|
|
data => {
|
|
|
|
for (let funder of data) {
|
|
|
|
this.allFunderOptions.push({label: funder, value: {id: funder, label: funder}});
|
|
|
|
}
|
|
|
|
this.previewFunderOptions =[...this.allFunderOptions];
|
|
|
|
},
|
|
|
|
err => {
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2023-10-04 15:04:42 +02:00
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public updatePage($event) {
|
2022-07-05 00:31:56 +02:00
|
|
|
HelperFunctions.scroll();
|
2021-05-19 13:40:29 +02:00
|
|
|
this.page = $event.value;
|
2023-09-19 14:59:37 +02:00
|
|
|
this._getCommunityProjects(this.page, this.filterForm.get('keyword').value, null);
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addNew() {
|
2022-07-05 00:31:56 +02:00
|
|
|
this.addProjects.emit();
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public onSearchClose() {
|
|
|
|
this.communitySearchUtils.keyword = this.filterForm.get('keyword').value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public resetInput() {
|
|
|
|
this.communitySearchUtils.keyword = null;
|
|
|
|
this.searchInputComponent.reset()
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message: string) {
|
2022-07-13 19:26:10 +02:00
|
|
|
NotificationHandler.rise(message, 'danger');
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
|
2023-10-04 15:04:42 +02:00
|
|
|
select(option, event, dropdownFilter: DropdownFilterComponent) {
|
|
|
|
console.log(option)
|
2022-07-05 00:31:56 +02:00
|
|
|
if(event.target instanceof HTMLInputElement) {
|
|
|
|
dropdownFilter.closeDropdown();
|
2023-10-04 15:04:42 +02:00
|
|
|
if(event.target.checked) {
|
|
|
|
this.filterForm.get("funder").setValue(option.value);
|
|
|
|
this._getCommunityProjects(1, this.filterForm.get('keyword').value, this.filterForm.get('funder').value.id );
|
|
|
|
this.previewFunderOptions =[option];
|
2022-07-05 00:31:56 +02:00
|
|
|
} else if(!event.target.checked) {
|
2023-10-04 15:04:42 +02:00
|
|
|
this.filterForm.get("funder").setValue(null);
|
|
|
|
this._getCommunityProjects(1, this.filterForm.get('keyword').value,null);
|
|
|
|
this.previewFunderOptions =[...this.allFunderOptions];
|
2022-07-05 00:31:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isSelected(value: string) {
|
2023-10-04 15:04:42 +02:00
|
|
|
return this.filterForm && this.filterForm.get('funder').value && this.filterForm.get('funder').value.id === value;
|
2022-07-05 00:31:56 +02:00
|
|
|
}
|
2023-10-26 08:49:04 +02:00
|
|
|
|
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|