Project

General

Profile

1
import {Component, ViewChild} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {DatasetService} from '../../services/dataset.service';
4
import {DatasetInfo} from '../../entities/datasetInfo';
5
import {ActivatedRoute} from '@angular/router';
6
import { OpenaireProperties} from '../../openaireProperties'
7
import {InlineClaimContextComponent} from '../../claimPages/inlineClaimContext/inlineClaimContext.component';
8
import {InlineClaimProjectComponent} from '../../claimPages/inlineClaimProject/inlineClaimProject.component';
9
import {InlineClaimResultComponent} from '../../claimPages/inlineClaimResult/inlineClaimResult.component';
10
@Component({
11
    selector: 'dataset',
12
    templateUrl: 'dataset.component.html',
13
})
14

    
15
export class DatasetComponent {
16
    constructor (private _datasetService: DatasetService, private  route: ActivatedRoute) {
17
        console.info('dataset constructor');
18
    }
19
    ngOnInit() {
20
      this.sub =  this.route.queryParams.subscribe(params => {
21
        this.datasetId = params['datasetId'];
22
         console.info("Id is :"+this.datasetId);
23
         if(this.datasetId){
24
            this.getDatasetInfo(this.datasetId);
25
        }else{
26
  		      this.warningMessage="No valid dataset id";
27
        }
28
      });
29

    
30
    }
31

    
32
    private datasetInfo: DatasetInfo;
33

    
34
    private showStyle: boolean = false;
35
    private showAllReferences: boolean = false;
36
    private showAllRelResData: boolean = false;
37
    private showAllSimilPubl: boolean = false;
38
    private showAllBioentities: boolean = false;
39
    private datasetId : string ;
40
    private result ;
41

    
42

    
43
    @ViewChild (InlineClaimProjectComponent) inlineClaimProject : InlineClaimProjectComponent ;
44
    @ViewChild (InlineClaimContextComponent) inlineClaimContext : InlineClaimContextComponent ;
45
    @ViewChild (InlineClaimResultComponent) inlineClaimResult : InlineClaimResultComponent ;
46

    
47
    public warningMessage = "";
48
    public errorMessage = "";
49
    ngOnDestroy() {
50
      this.sub.unsubscribe();
51
    }
52
      sub: any;
53
    getDatasetInfo(id:string) {
54
        this.warningMessage = '';
55
        this.errorMessage=""
56
        console.info("do request");
57
        this._datasetService.getDatasetInfo(id).subscribe(
58
                data => {
59
                    this.datasetInfo = data;
60

    
61
                    this.result = []
62
                    this.result = {id: id, type :"dataset", source : "openaire", title: this.datasetInfo.title,url: '', result: '', accessRights: this.datasetInfo.bestlicense, embargoEndDate: ''};
63

    
64
                },
65
                err => {
66
                    console.error(err)
67
                    console.info("error");
68

    
69
                    this.errorMessage = 'No dataset found';
70
                }
71
            );
72

    
73
    }
74

    
75
    /********** Methods for Inline Claim  of project / dataset ******/
76
    toggleClaimProject(){
77
        this.inlineClaimProject.toggle();
78
    }
79
    projectAdded($event){
80
        var projects =$event.value;
81
        if(projects){
82
            for(var i=0; i < projects.length; i++){
83

    
84
                if(this.datasetInfo.fundedByProjects == undefined) {
85
                    this.datasetInfo.fundedByProjects = new Array<
86
                        { "url": string, "acronym": string, "title": string,
87
                          "funderShortname": string, "funderName": string,
88
                          "funding": string, "inline": boolean
89
                        }>();
90
                }
91
                var project =projects[i];
92

    
93
                let counter = this.datasetInfo.fundedByProjects.length;
94
                this.datasetInfo.fundedByProjects[counter] = {
95
                    "url": "", "acronym": "", "title": "",
96
                    "funderShortname": "", "funderName": "",
97
                    "funding": "", "inline": true
98
                }
99
                this.datasetInfo.fundedByProjects[counter]['url'] =
100
                    OpenaireProperties.getsearchLinkToProject()+project.projectId;
101
                this.datasetInfo.fundedByProjects[counter]['acronym'] = project.projectAcronym;
102
                this.datasetInfo.fundedByProjects[counter]['title'] = project.projectName;
103
                this.datasetInfo.fundedByProjects[counter]['funderShortname'] = project.funderName;
104
            }
105
        }
106
    }
107
    toggleClaimContext(){
108
        this.inlineClaimContext.toggle();
109
    }
110
    contextAdded($event){
111
      var contexts =$event.value;
112

    
113
      if(contexts){
114
         for(var i=0; i < contexts.length; i++){
115
           var context = contexts[i];
116
           if(!this.datasetInfo.contexts){
117
             this.datasetInfo.contexts =  new Array<
118
                 { "labelContext": string, "labelCategory": string, "labelConcept": string, "inline": boolean}>();
119

    
120
           }
121
           var position:number = this.datasetInfo.contexts.length;
122

    
123
           this.datasetInfo.contexts[ position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", "inline": true };
124
           this.datasetInfo.contexts[position]['labelContext'] = context.community;
125
           this.datasetInfo.contexts[position]['labelCategory'] = context.category;
126
           this.datasetInfo.contexts[position]['labelConcept'] = context.concept.label;
127

    
128

    
129
         }
130
       }
131
     }
132
     toggleClaimResult(){
133
        this.inlineClaimResult.toggle();
134
     }
135
     resultsAdded($event, isPublication:boolean){
136
       var results =$event.value;
137

    
138
      //TODO
139
      }
140
    showChange($event) {
141
        this.showAllReferences=$event.value;
142
    }
143
}
(2-2/2)