explore-services/portal-2/src/app/landingPages/dataset/dataset.component.ts

144 lines
5.3 KiB
TypeScript

import {Component, ViewChild} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {DatasetService} from '../../services/dataset.service';
import {DatasetInfo} from '../../utils/entities/datasetInfo';
import {ActivatedRoute} from '@angular/router';
import { OpenaireProperties} from '../../utils/properties/openaireProperties'
import {InlineClaimContextComponent} from '../../claimPages/inlineClaims/inlineClaimContext.component';
import {InlineClaimProjectComponent} from '../../claimPages/inlineClaims/inlineClaimProject.component';
import {InlineClaimResultComponent} from '../../claimPages/inlineClaims/inlineClaimResult.component';
@Component({
selector: 'dataset',
templateUrl: 'dataset.component.html',
})
export class DatasetComponent {
constructor (private _datasetService: DatasetService, private route: ActivatedRoute) {
console.info('dataset constructor');
}
ngOnInit() {
this.sub = this.route.queryParams.subscribe(params => {
this.datasetId = params['datasetId'];
console.info("Id is :"+this.datasetId);
if(this.datasetId){
this.getDatasetInfo(this.datasetId);
}else{
this.warningMessage="No valid dataset id";
}
});
}
private datasetInfo: DatasetInfo;
private showStyle: boolean = false;
private showAllReferences: boolean = false;
private showAllRelResData: boolean = false;
private showAllSimilPubl: boolean = false;
private showAllBioentities: boolean = false;
private datasetId : string ;
private result ;
@ViewChild (InlineClaimProjectComponent) inlineClaimProject : InlineClaimProjectComponent ;
@ViewChild (InlineClaimContextComponent) inlineClaimContext : InlineClaimContextComponent ;
@ViewChild (InlineClaimResultComponent) inlineClaimResult : InlineClaimResultComponent ;
public warningMessage = "";
public errorMessage = "";
ngOnDestroy() {
this.sub.unsubscribe();
}
sub: any;
getDatasetInfo(id:string) {
this.warningMessage = '';
this.errorMessage=""
console.info("do request");
this._datasetService.getDatasetInfo(id).subscribe(
data => {
this.datasetInfo = data;
this.result = []
this.result = {id: id, type :"dataset", source : "openaire", title: this.datasetInfo.title,url: '', result: '', accessRights: this.datasetInfo.bestlicense, embargoEndDate: ''};
},
err => {
console.error(err)
console.info("error");
this.errorMessage = 'No dataset found';
}
);
}
/********** Methods for Inline Claim of project / dataset ******/
toggleClaimProject(){
this.inlineClaimProject.toggle();
}
projectAdded($event){
var projects =$event.value;
if(projects){
for(var i=0; i < projects.length; i++){
if(this.datasetInfo.fundedByProjects == undefined) {
this.datasetInfo.fundedByProjects = new Array<
{ "url": string, "acronym": string, "title": string,
"funderShortname": string, "funderName": string,
"funding": string, "inline": boolean
}>();
}
var project =projects[i];
let counter = this.datasetInfo.fundedByProjects.length;
this.datasetInfo.fundedByProjects[counter] = {
"url": "", "acronym": "", "title": "",
"funderShortname": "", "funderName": "",
"funding": "", "inline": true
}
this.datasetInfo.fundedByProjects[counter]['url'] =
OpenaireProperties.getsearchLinkToProject()+project.projectId;
this.datasetInfo.fundedByProjects[counter]['acronym'] = project.projectAcronym;
this.datasetInfo.fundedByProjects[counter]['title'] = project.projectName;
this.datasetInfo.fundedByProjects[counter]['funderShortname'] = project.funderName;
}
}
}
toggleClaimContext(){
this.inlineClaimContext.toggle();
}
contextAdded($event){
var contexts =$event.value;
if(contexts){
for(var i=0; i < contexts.length; i++){
var context = contexts[i];
if(!this.datasetInfo.contexts){
this.datasetInfo.contexts = new Array<
{ "labelContext": string, "labelCategory": string, "labelConcept": string, "inline": boolean}>();
}
var position:number = this.datasetInfo.contexts.length;
this.datasetInfo.contexts[ position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", "inline": true };
this.datasetInfo.contexts[position]['labelContext'] = context.community;
this.datasetInfo.contexts[position]['labelCategory'] = context.category;
this.datasetInfo.contexts[position]['labelConcept'] = context.concept.label;
}
}
}
toggleClaimResult(){
this.inlineClaimResult.toggle();
}
resultsAdded($event, isPublication:boolean){
var results =$event.value;
//TODO
}
showChange($event) {
this.showAllReferences=$event.value;
}
}