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 {SearchResult} from '../../openaireLibrary/utils/entities/searchResult';
|
|
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {SearchProjectsService} from '../../openaireLibrary/services/searchProjects.service';
|
|
|
|
import {RouterHelper} from '../../openaireLibrary/utils/routerHelper.class';
|
|
|
|
import {StringUtils} from '../../openaireLibrary/utils/string-utils.class';
|
|
|
|
import {ManageCommunityProjectsService} from '../../services/manageProjects.service';
|
|
|
|
|
|
|
|
import {properties} from "../../../environments/environment";
|
|
|
|
import {Subscriber} from "rxjs";
|
2022-09-23 16:14:20 +02:00
|
|
|
import {UntypedFormBuilder, UntypedFormGroup} from "@angular/forms";
|
2021-05-19 13:40:29 +02:00
|
|
|
import {debounceTime, distinctUntilChanged} from "rxjs/operators";
|
|
|
|
import {ResultPreview} from "../../openaireLibrary/utils/result-preview/result-preview";
|
|
|
|
import {SearchInputComponent} from "../../openaireLibrary/sharedComponents/search-input/search-input.component";
|
2022-07-05 00:31:56 +02:00
|
|
|
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
|
|
|
|
import {OpenaireEntities} from "../../openaireLibrary/utils/properties/searchFields";
|
|
|
|
import {Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
|
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 {SearchCommunityProjectsService} from "../../openaireLibrary/connect/projects/searchProjects.service";
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
declare var UIkit;
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'add-projects',
|
|
|
|
templateUrl: './add-projects.component.html',
|
|
|
|
})
|
|
|
|
|
|
|
|
export class AddProjectsComponent implements OnInit {
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
public subResults: any;
|
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
@Input() community: CommunityInfo = null;
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
public errorCodes: ErrorCodes;
|
|
|
|
public openaireSearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
@Output() communityProjectsChanged = new EventEmitter();
|
2023-09-19 14:59:37 +02:00
|
|
|
// @Input() communityProjects = [];
|
2021-05-19 13:40:29 +02:00
|
|
|
public openaireProjects = [];
|
|
|
|
public queryParameters: string = "";
|
|
|
|
|
|
|
|
// public pagingLimit: number = properties.pagingLimit;
|
|
|
|
public resultsPerPage: number = properties.resultsPerPage;
|
|
|
|
public selectedFunderId: string = "";
|
2022-07-11 17:48:24 +02:00
|
|
|
public selectedFunder: Value = null;
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2022-09-23 16:14:20 +02:00
|
|
|
filterForm: UntypedFormGroup;
|
2022-07-05 00:31:56 +02:00
|
|
|
funders: Filter = null;
|
2021-05-19 13:40:29 +02:00
|
|
|
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
|
|
|
|
|
|
|
private projectUrl: string = "https://" + ((properties.environment == "beta" || properties.environment == "development") ? "beta." : "") + "explore.openaire.eu" + properties.searchLinkToProject;
|
|
|
|
public body: string = "Send from page";
|
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
openaireEntities = OpenaireEntities;
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute, private _router: Router, private _searchProjectsService: SearchProjectsService,
|
|
|
|
private _manageCommunityProjectsService: ManageCommunityProjectsService,
|
2023-09-19 14:59:37 +02:00
|
|
|
private _clearCacheService: ClearCacheService, private _searchCommunityProjectsService: SearchCommunityProjectsService,
|
2022-09-23 16:14:20 +02:00
|
|
|
private _fb: UntypedFormBuilder) {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.openaireSearchUtils.status = this.errorCodes.LOADING;
|
2022-07-05 00:31:56 +02:00
|
|
|
this.openaireSearchUtils.refineStatus = this.errorCodes.LOADING;
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2022-07-05 00:31:56 +02:00
|
|
|
this.openaireSearchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.openaireSearchUtils.refineStatus = this.errorCodes.LOADING;
|
|
|
|
this.getFunders();
|
|
|
|
this._getOpenaireProjects("", 1, this.resultsPerPage);
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
this.body = "[Please write your message here]";
|
|
|
|
this.body = StringUtils.URIEncode(this.body);
|
2021-05-19 13:40:29 +02:00
|
|
|
|
|
|
|
this.openaireSearchUtils.keyword = "";
|
|
|
|
|
|
|
|
this.filterForm = this._fb.group({
|
|
|
|
keyword: [''],
|
|
|
|
funder: []
|
|
|
|
});
|
|
|
|
|
|
|
|
this.subscriptions.push(this.filterForm.get('keyword').valueChanges
|
|
|
|
.pipe(debounceTime(1000), distinctUntilChanged())
|
|
|
|
.subscribe(value => {
|
|
|
|
this.keywordChanged(value);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(sub => {
|
|
|
|
if (sub instanceof Subscriber) {
|
|
|
|
sub.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.subResults) {
|
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
get loading() {
|
|
|
|
return this.openaireSearchUtils.status == this.errorCodes.LOADING
|
|
|
|
}
|
|
|
|
|
|
|
|
get disabled() {
|
|
|
|
return this.openaireSearchUtils.status == this.errorCodes.LOADING || this.openaireSearchUtils.refineStatus == this.errorCodes.LOADING;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:48:24 +02:00
|
|
|
get infoMessage(): string {
|
|
|
|
return "<div>" +
|
|
|
|
"If you cannot find a funder that is relevant for your "+OpenaireEntities.COMMUNITY.toLowerCase()+", please contact us " +
|
|
|
|
"(<a href=\"mailto:" + properties.feedbackmailForMissingEntities +
|
|
|
|
"?Subject=[OpenAIRE Connect - "+ this.community.shortTitle + "] report missing Funder" + "&body=" + this.body + "\" " +
|
|
|
|
"target=\"_top\">"+properties.feedbackmailForMissingEntities+"</a>) " +
|
|
|
|
"and we will try to get the funder on board!" +
|
|
|
|
"</div>";
|
|
|
|
}
|
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
public addProject(project: SearchResult) {
|
2022-07-05 00:31:56 +02:00
|
|
|
this.subscriptions.push(this._manageCommunityProjectsService.addProject(this.properties, this.community.communityId, project).subscribe(
|
|
|
|
data => {
|
2023-09-19 14:59:37 +02:00
|
|
|
// this.communityProjects.push(data);
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache(this.openaireEntities.PROJECT+" added", this.community.communityId);
|
2023-09-19 14:59:37 +02:00
|
|
|
|
2022-08-11 11:58:20 +02:00
|
|
|
UIkit.notification(this.openaireEntities.PROJECT+' successfully added!', {
|
2022-07-05 00:31:56 +02:00
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2023-09-19 14:59:37 +02:00
|
|
|
project["isPart"] = true;
|
2022-07-05 00:31:56 +02:00
|
|
|
this.communityProjectsChanged.emit({
|
2023-09-19 14:59:37 +02:00
|
|
|
value: project,
|
2022-07-05 00:31:56 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError('An error has been occurred. Try again later!');
|
|
|
|
console.error(err.status);
|
|
|
|
}
|
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public removeProject(project: any) {
|
2023-09-19 14:59:37 +02:00
|
|
|
// let communityProject = this.getCommunityProject(project);
|
|
|
|
this.subscriptions.push(this._manageCommunityProjectsService.removeProject(this.properties, this.community.communityId, project['id']).subscribe(
|
2022-07-05 00:31:56 +02:00
|
|
|
data => {
|
2023-09-19 14:59:37 +02:00
|
|
|
// let index = this.communityProjects.indexOf(communityProject);
|
|
|
|
// this.communityProjects.splice(index, 1);
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache(this.openaireEntities.PROJECT+" removed", this.community.communityId);
|
|
|
|
UIkit.notification(this.openaireEntities.PROJECT+' successfully removed!', {
|
2022-07-05 00:31:56 +02:00
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2023-09-19 14:59:37 +02:00
|
|
|
project["isPart"] = false;
|
2022-07-05 00:31:56 +02:00
|
|
|
this.communityProjectsChanged.emit({
|
2023-09-19 14:59:37 +02:00
|
|
|
value: project,
|
2022-07-05 00:31:56 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError('An error has been occurred. Try again later!');
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
2023-09-19 14:59:37 +02:00
|
|
|
public getCommunityProject(project: any) {
|
|
|
|
this.subscriptions.push(this._searchCommunityProjectsService.searchProjectsWithPaging(this.properties, this.community.communityId, 1, this.resultsPerPage, project.id, null).subscribe(
|
|
|
|
data => {
|
|
|
|
if(data.totalElements > 0){
|
|
|
|
project["isPart"] = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.error(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2023-09-19 14:59:37 +02:00
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getFunders() {
|
2022-07-05 00:31:56 +02:00
|
|
|
this.openaireSearchUtils.refineStatus = this.errorCodes.LOADING;
|
|
|
|
this.subscriptions.push(this._searchProjectsService.getFunders(this.queryParameters, this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
this.funders = data[1][0];
|
|
|
|
this.funders.values.map((value) => {
|
|
|
|
if(value.id == this.selectedFunderId) {
|
|
|
|
value.selected = true;
|
|
|
|
this.funders.countSelectedValues++;
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
})
|
|
|
|
if(this.funders.values && this.funders.values.length == 0) {
|
|
|
|
this.openaireSearchUtils.refineStatus = this.errorCodes.NONE;
|
|
|
|
} else {
|
|
|
|
this.openaireSearchUtils.refineStatus = this.errorCodes.DONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.openaireSearchUtils.refineStatus = this.errorCodes.ERROR;
|
|
|
|
console.error("Server error fetching funders: ", err)
|
|
|
|
}
|
|
|
|
));
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getResultPreview(result: SearchResult): ResultPreview {
|
|
|
|
return ResultPreview.searchResultConvert(result, "project");
|
|
|
|
}
|
|
|
|
|
|
|
|
private _getOpenaireProjects(parameters: string, page: number, size: number) {
|
2022-07-05 00:31:56 +02:00
|
|
|
if (this.openaireSearchUtils.status == this.errorCodes.LOADING) {
|
|
|
|
this.openaireSearchUtils.status = this.errorCodes.LOADING;
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
this.openaireProjects = [];
|
|
|
|
this.openaireSearchUtils.totalResults = 0;
|
2021-05-19 13:40:29 +02:00
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
if (this.subResults) {
|
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
this.subResults = this._searchProjectsService.searchProjects(parameters, null, page, size, [], this.properties).subscribe(
|
|
|
|
data => {
|
|
|
|
this.openaireSearchUtils.totalResults = data[0];
|
|
|
|
this.openaireProjects = data[1];
|
2023-09-19 14:59:37 +02:00
|
|
|
for(let project of this.openaireProjects){
|
|
|
|
this.getCommunityProject(project);
|
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
this.openaireSearchUtils.status = this.errorCodes.DONE;
|
|
|
|
if (this.openaireSearchUtils.totalResults == 0) {
|
|
|
|
this.openaireSearchUtils.status = this.errorCodes.NONE;
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.error(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
if (err.status == '404') {
|
|
|
|
this.openaireSearchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if (err.status == '500') {
|
|
|
|
this.openaireSearchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.openaireSearchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
totalPages(): number {
|
|
|
|
let totalPages: any = this.openaireSearchUtils.totalResults / (this.resultsPerPage);
|
|
|
|
if (!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
|
|
|
return totalPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
keywordChanged(keyword) {
|
|
|
|
this.openaireSearchUtils.keyword = keyword;
|
|
|
|
this.buildQueryParameters();
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
funderChanged(filter: Filter) {
|
|
|
|
this.getSelectedValues(filter);
|
2021-05-19 13:40:29 +02:00
|
|
|
this.buildQueryParameters();
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildQueryParameters() {
|
|
|
|
this.queryParameters = "";
|
|
|
|
|
|
|
|
if (this.openaireSearchUtils.keyword) {
|
|
|
|
this.queryParameters = "q=" + StringUtils.URIEncode(this.openaireSearchUtils.keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selectedFunderId) {
|
|
|
|
this.queryParameters += this.queryParameters ? "&" : "";
|
|
|
|
this.queryParameters += "fq=funder exact " + '"' + StringUtils.URIEncode(this.selectedFunderId) + '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 00:31:56 +02:00
|
|
|
goTo(page: number = 1, refineQuery: boolean = true) {
|
2021-05-19 13:40:29 +02:00
|
|
|
this.openaireSearchUtils.page = page;
|
|
|
|
this.openaireSearchUtils.status = this.errorCodes.LOADING;
|
2022-07-05 00:31:56 +02:00
|
|
|
if(refineQuery) {
|
|
|
|
this.openaireSearchUtils.refineStatus = this.errorCodes.LOADING;
|
|
|
|
this.getFunders();
|
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
this._getOpenaireProjects(this.queryParameters, page, this.resultsPerPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
public onSearchClose() {
|
|
|
|
this.openaireSearchUtils.keyword = this.filterForm.get('keyword').value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public resetInput() {
|
|
|
|
this.openaireSearchUtils.keyword = null;
|
|
|
|
this.searchInputComponent.reset()
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message: string) {
|
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
|
|
|
|
getSelectedValues(filter): any {
|
|
|
|
var selected = [];
|
2022-07-11 17:48:24 +02:00
|
|
|
if(filter.values.length == 0 && this.selectedFunderId) {
|
|
|
|
return [this.selectedFunder];
|
|
|
|
} else {
|
|
|
|
this.selectedFunderId = "";
|
|
|
|
this.selectedFunder = null;
|
|
|
|
if (filter.countSelectedValues > 0) {
|
|
|
|
for (var i = 0; i < filter.values.length; i++) {
|
|
|
|
if (filter.values[i].selected) {
|
|
|
|
selected.push(filter.values[i]);
|
|
|
|
this.selectedFunderId = filter.values[i].id;
|
|
|
|
this.selectedFunder = filter.values[i];
|
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-11 17:48:24 +02:00
|
|
|
return selected;
|
2022-07-05 00:31:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clearFilters() {
|
|
|
|
for (var j = 0; j < this.funders.countSelectedValues; j++) {
|
|
|
|
if (this.funders.values[j].selected) {
|
|
|
|
this.removeFilter(this.funders.values[j], this.funders);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeFilter(value: Value, filter: Filter) {
|
|
|
|
this.selectedFunderId = "";
|
2022-07-11 17:48:24 +02:00
|
|
|
this.selectedFunder = null;
|
|
|
|
|
|
|
|
if(value) {
|
|
|
|
filter.countSelectedValues--;
|
|
|
|
if (value.selected == true) {
|
|
|
|
value.selected = false;
|
|
|
|
}
|
|
|
|
if (filter.filterType == "radio") {
|
|
|
|
filter.radioValue = "";
|
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
}
|
|
|
|
this.buildQueryParameters();
|
|
|
|
this.goTo(1);
|
|
|
|
}
|
2021-05-19 13:40:29 +02:00
|
|
|
}
|