openaire-library/claims/linking/linkingGeneric.component.ts

127 lines
3.6 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {ActivatedRoute, Router} from '@angular/router';
import {EntitiesSearchService} from '../../utils/entitiesAutoComplete/entitySearch.service';
import {ClaimProject, ClaimResult} from '../claim-utils/claimEntities.class';
import {SearchPublicationsService} from '../../services/searchPublications.service';
import {SearchDatasetsService} from '../../services/searchDatasets.service';
import { Meta} from '../../sharedComponents/metaService';
import{EnvProperties} from '../../utils/properties/env-properties';
declare var UIkit:any;
@Component({
selector: 'linking-generic',
templateUrl: 'linkingGeneric.component.html'
})
export class LinkingGenericComponent {
@Input() bulkMode: boolean = false;
sourceType:string;
targetType:string;
step:number = 1;
contexts=[];
projects=[];
results = [];
show = "project";
date='8-6-2016';
keyword: string = "";
linkType:string ="project"; // link type (selected in home page) : project, context, software, etc
/* url Parameters for inline linking */
id:string = null; //entity id
type:string = null; // entity type (publication or research data)
linkTo:string = null; // entity type (project or context or result)
entityTypes=["dataset", "publication", "project","context"];
inlineResult:ClaimResult =null;
sub:any =null;
properties:EnvProperties;
constructor ( private _router: Router, private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
private publicationsSearch:SearchPublicationsService, private datasetsSearch:SearchDatasetsService, private _meta: Meta) {
this._meta.setTitle("OpenAIRE | Linking");
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
});
if( typeof localStorage !== 'undefined') {
if(localStorage.getItem("projects")){
this.projects = JSON.parse(localStorage.getItem("projects"));
}
if(localStorage.getItem("contexts")){
this.contexts = JSON.parse(localStorage.getItem("contexts"));
}
if(localStorage.getItem("results")){
this.results = JSON.parse(localStorage.getItem("results"));
}
localStorage.removeItem("projects");
localStorage.removeItem("contexts");
localStorage.removeItem("results");
}
}
next(){
if((this.show == 'result' && this.keyword == '')||(this.show == 'dataset' || this.show == 'publication')){
this.show='claim';
}
}
prev(){
if(this.show == 'claim'){
this.show='result';
}
}
resultsChange($event) {
this.results=$event.value;
}
projectsChange($event) {
this.projects=$event.value;
}
linkTypeChange($event) {
this.linkType =$event.value;
this.show="result";
if(this.bulkMode){
this.show="claim";
}
}
showChange($event) {
this.show=$event.value;
this.showChangedType($event.value);
}
showChangedType(type:string) {
this.show=type;
if(this.show == 'project' || this.show == 'context' || this.show == 'software'){
this.linkType = this.show;
}
}
canProceedToMetadata(){
if(this.results.length == 0){
UIkit.notification({
message : 'No research results selected!<br>Please select research results to link with projects and/ or ommunities.',
status : 'warning',
timeout : 1000,
pos : 'top-center'
});
}else{
this.show = 'claim';
this.step = 3;
}
}
}