2019-07-23 14:23:12 +02:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
import {ClaimEntity, ClaimProject, ShowOptions} from '../claim-utils/claimHelper.class';
|
|
|
|
import {EntitiesSearchService} from '../../utils/entitiesAutoComplete/entitySearch.service';
|
2019-09-11 11:45:54 +02:00
|
|
|
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {LinkingGenericComponent} from "../linking/linkingGeneric.component";
|
|
|
|
import {ClaimResultSearchFormComponent} from "../claim-utils/claimResultSearchForm.component";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2020-11-18 17:06:27 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-07-23 14:23:12 +02:00
|
|
|
selector: 'directLinking',
|
|
|
|
templateUrl: 'directLinking.component.html'
|
2017-12-19 13:53:46 +01:00
|
|
|
})
|
|
|
|
export class DirectLinkingComponent {
|
2019-08-02 16:55:32 +02:00
|
|
|
@Input() piwikSiteId = null;
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
@ViewChild(LinkingGenericComponent) linking: LinkingGenericComponent;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
results: ClaimEntity[] = [];
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
// linkType: string = "project"; // link type (selected in home page) : project, context, software, etc
|
2017-12-19 13:53:46 +01:00
|
|
|
/* url Parameters for inline linking */
|
2019-07-23 14:23:12 +02:00
|
|
|
id: string = null; //entity id
|
|
|
|
type: string = null; // entity type (publication or dataset)
|
|
|
|
// linkTo: string = null; // entity type (project or context or entity)
|
|
|
|
// linkToEntities: string[] = [];
|
|
|
|
showOptions:ShowOptions = new ShowOptions();
|
|
|
|
validEntityTypes = ["dataset", "publication", "software", "orp", "project", "context"];
|
|
|
|
sources: ClaimEntity[] = [];
|
|
|
|
inlineEntity: ClaimEntity = null;
|
|
|
|
validInput: boolean = null;//'true;
|
|
|
|
properties: EnvProperties;
|
|
|
|
@Input() communityId: string = null;
|
|
|
|
localStoragePrefix: string = "";
|
|
|
|
constructor(private _router: Router, private route: ActivatedRoute,private entitySearch:EntitiesSearchService,
|
2019-09-11 11:45:54 +02:00
|
|
|
private _searchResearchResultsService: SearchResearchResultsService) {}
|
2020-11-11 15:43:13 +01:00
|
|
|
subscriptions = [];
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
ngOnInit() {
|
2020-11-18 17:06:27 +01:00
|
|
|
this.properties = properties;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
2019-07-23 14:23:12 +02:00
|
|
|
this.id = params['id'];
|
|
|
|
this.type = params['type'];
|
|
|
|
this.showOptions.linkTo = params['linkTo'];
|
|
|
|
if (this.type != null && this.showOptions.linkTo != null) {
|
|
|
|
this.type = (this.validEntityTypes.indexOf(this.type) != -1) ? this.type : 'publication';
|
|
|
|
this.showOptions.linkTo = (this.validEntityTypes.indexOf(this.showOptions.linkTo) != -1 || this.showOptions.linkTo == "result") ? this.showOptions.linkTo : 'project';
|
|
|
|
this.localStoragePrefix = (this.communityId ? (this.communityId + "_") : '') + this.type.substr(0, 3) + "_" + this.showOptions.linkTo.substr(0, 3) + "_";
|
|
|
|
|
|
|
|
if (localStorage.getItem(this.localStoragePrefix + "results")) {
|
|
|
|
this.results = JSON.parse(localStorage.getItem(this.localStoragePrefix + "results"));
|
|
|
|
}
|
|
|
|
if (localStorage.getItem(this.localStoragePrefix + "sources")) {
|
|
|
|
this.sources = JSON.parse(localStorage.getItem(this.localStoragePrefix + "sources"));
|
|
|
|
}
|
|
|
|
//console.log("\n\nGetting inline entity "+this.type+"\n\n");
|
|
|
|
if (this.type == "project") {
|
|
|
|
// this.linkType = "project";
|
|
|
|
this.getProjectById(this.id);
|
|
|
|
} else if (this.type == "publication") {
|
2019-09-16 11:34:49 +02:00
|
|
|
this.getResearchResultById("publication", this.id);
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (this.type == "dataset") {
|
2019-09-16 11:34:49 +02:00
|
|
|
this.getResearchResultById("dataset", this.id);
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (this.type == "software") {
|
2019-09-16 11:34:49 +02:00
|
|
|
this.getResearchResultById("software", this.id);
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (this.type == "orp") {
|
2019-09-16 11:34:49 +02:00
|
|
|
this.getResearchResultById("other", this.id);
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
|
|
|
this.validInput = this.isValidInput(null);
|
|
|
|
}
|
|
|
|
//set which entities it is allowed to link to.
|
|
|
|
// add first the
|
|
|
|
if(this.type == "project"){
|
|
|
|
this.showOptions.linkToEntities = ["result"];
|
|
|
|
this.showOptions.linkTo = "result";
|
|
|
|
}else{
|
|
|
|
// entity type (project or context or entity)
|
|
|
|
if(this.showOptions.linkTo == "project"){
|
|
|
|
this.showOptions.linkToEntities = ["project","context" ,"result"];
|
|
|
|
}else if(this.showOptions.linkTo == "context"){
|
|
|
|
this.showOptions.linkToEntities = ["context","project", "result" ];
|
|
|
|
}else{
|
|
|
|
this.showOptions.linkTo = "result";
|
|
|
|
this.showOptions.linkToEntities = ["result","project","context" ];
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
|
|
|
this.validInput = this.isValidInput(null);
|
|
|
|
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
isValidInput(result: ClaimEntity) {
|
|
|
|
if (result == null) {
|
2017-12-19 13:53:46 +01:00
|
|
|
return false;
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (this.type == "project" && this.showOptions.linkTo != "result") {
|
2017-12-19 13:53:46 +01:00
|
|
|
return false;
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (["dataset", "publication", "software", "orp"].indexOf(this.type) != -1 && (["project", "context", "result"].indexOf(this.showOptions.linkTo) == -1)) {
|
2017-12-19 13:53:46 +01:00
|
|
|
return false;
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (["project", "dataset", "publication", "software", "orp"].indexOf(this.type) == -1) {
|
2017-12-19 13:53:46 +01:00
|
|
|
return false;
|
2019-07-23 14:23:12 +02:00
|
|
|
} else {
|
2017-12-19 13:53:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
getProjectById(id: string) {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.entitySearch.fetchByType(id,"project", this.properties).subscribe(
|
2019-07-23 14:23:12 +02:00
|
|
|
data => {
|
|
|
|
this.createClaimEntity(data, "project");
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.validInput = this.isValidInput(null);
|
|
|
|
//console.log("An error occured")
|
|
|
|
this.handleError("Error getting project by id: " + id, err);
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-09-16 11:34:49 +02:00
|
|
|
getResearchResultById(resultType: string, id: string) {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this._searchResearchResultsService.searchById(resultType, id, this.properties).subscribe(data => {
|
2019-09-16 11:34:49 +02:00
|
|
|
this.createClaimEntity(data, resultType);
|
2019-07-23 14:23:12 +02:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.validInput = this.isValidInput(null);
|
|
|
|
//console.log("An error occured")
|
2019-09-16 11:34:49 +02:00
|
|
|
this.handleError("Error getting "+this.getEntityName(resultType, false, true)+" by id: " + id, err);
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createClaimEntity(data, type: string) {
|
|
|
|
let results: ClaimEntity[] =[] ;
|
|
|
|
if(type =="project"){
|
|
|
|
let project = data[0];
|
|
|
|
let entity:ClaimEntity = new ClaimEntity();
|
|
|
|
entity.id = project.id;
|
|
|
|
entity.type = "project";
|
|
|
|
entity.title = project.projectName;
|
|
|
|
entity.project = new ClaimProject();
|
|
|
|
entity.project.acronym = project.projectAcronym;
|
|
|
|
entity.project.code = project.code;
|
|
|
|
entity.project.endDate = project.endDate;
|
|
|
|
entity.project.funderId = project.funderId;
|
|
|
|
entity.project.funderName = project.funderName;
|
|
|
|
entity.project.fundingLevel0 = project.fundingLevel0;
|
|
|
|
entity.project.jurisdiction = project.jurisdiction;
|
|
|
|
entity.project.startDate = project.startDate;
|
|
|
|
this.inlineEntity = entity;
|
|
|
|
}else{
|
2020-08-10 17:14:48 +02:00
|
|
|
results = ClaimResultSearchFormComponent.openaire2ClaimResults(data, this.properties);
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (results.length > 0) {
|
|
|
|
this.inlineEntity = results[0]
|
|
|
|
}
|
|
|
|
this.validInput = this.isValidInput(this.inlineEntity);
|
|
|
|
}
|
2019-02-18 15:00:43 +01:00
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
2019-07-23 14:23:12 +02:00
|
|
|
console.error("Direct Linking Page: " + message, error);
|
2019-02-18 15:00:43 +01:00
|
|
|
}
|
2019-09-16 11:34:49 +02:00
|
|
|
|
|
|
|
private getEntityName (entityType:string, plural:boolean, full:boolean): string {
|
|
|
|
if(entityType == "publication") {
|
|
|
|
return "publication" + (plural ? "s" : "");
|
|
|
|
} else if(entityType == "dataset") {
|
|
|
|
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
|
|
|
|
} else if(entityType == "software") {
|
|
|
|
return "software";
|
|
|
|
} else if(entityType == "other") {
|
|
|
|
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|