Project

General

Profile

1
import {Component} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import { ActivatedRoute } from '@angular/router';
4
import {PersonService} from '../../services/person.service';
5
import { PersonInfo } from '../../utils/entities/personInfo';
6

    
7
import { SearchPublicationsComponent } from '../../searchPages/simple/searchPublications.component';
8
import { SearchPublicationsService } from '../../services/searchPublications.service';
9
import { SearchDatasetsComponent } from '../../searchPages/simple/searchDatasets.component';
10
import { SearchDatasetsService } from '../../services/searchDatasets.service';
11
import { SearchResultComponent } from '../../searchPages/searchUtils/searchResult.component';
12

    
13
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
14

    
15
@Component({
16
    selector: 'person',
17
    templateUrl: 'person.component.html',
18
})
19

    
20
export class PersonComponent {
21

    
22
    sub: any;
23
    subPublications: any;
24
    subDatasets: any;
25
    subDatasetsCount: any;
26

    
27
    private searchPublicationsComponent : SearchPublicationsComponent;
28
    private linkToSearchPublications = "";
29
    private searchDatasetsComponent : SearchDatasetsComponent;
30
    private linkToSearchDatasets = "";
31

    
32
    personInfo: PersonInfo;
33
    private personId: string;
34
    public warningMessage = "";
35
    public errorMessage = "";
36

    
37
    constructor (private _personService: PersonService,
38
                 private  route: ActivatedRoute,
39
                 private _searchPublicationsService: SearchPublicationsService,
40
                 private _searchDatasetsService: SearchDatasetsService) {
41
            console.info('person constructor');
42
            this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
43
            this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
44
        }
45

    
46
    ngOnInit() {
47
        console.info('person init');
48
        this.sub =  this.route.queryParams.subscribe(params => {
49
          this.personId = params['personId'];
50
           console.info("Id is :"+this.personId);
51
           if(this.personId){
52
              this.getPersonInfo();
53
          }else{
54
    		      this.warningMessage="No valid person id";
55
          }
56

    
57
       });
58

    
59
       this.subPublications =  this.route.queryParams.subscribe(params => {
60
             this.searchPublications();
61
       });
62

    
63
       this.subDatasetsCount = this.route.queryParams.subscribe(params => {
64
           this._searchDatasetsService.numOfEntityDatasets(this.personId, "people/").subscribe(
65
             data => {
66
                 this.searchDatasetsComponent.searchUtils.totalResults = data;
67
             },
68
             err => {
69
                 console.log(err);
70
              }
71
           );
72
       })
73
    }
74

    
75
    private searchDatasetsInit() {
76
        if(this.subDatasets == undefined && this.searchDatasetsComponent.searchUtils.totalResults > 0) {
77
            this.subDatasets =  this.route.queryParams.subscribe(params => {
78
                  this.searchDatasets();
79
            });
80
        }
81
    }
82

    
83
    ngOnDestroy() {
84
      this.sub.unsubscribe();
85
      this.subPublications.unsubscribe();
86
      if(this.subDatasets != undefined) {
87
          this.subDatasets.unsubscribe();
88
      }
89
      this.subDatasetsCount.unsubscribe();
90
    }
91

    
92

    
93
    private getPersonInfo ()  {
94
        console.info("inside getPersonInfo of component");
95

    
96
        this.warningMessage = '';
97
        this.errorMessage=""
98
        console.info("do request");
99

    
100
        this._personService.getPersonInfo(this.personId).subscribe(
101
            data => {
102
                this.personInfo = data;
103
            },
104
            err => {
105
                console.log(err)
106
                console.info("error");
107

    
108
                this.errorMessage = 'No person found';
109
            }
110
        );
111
    }
112

    
113
    private searchPublications() {
114
      this.searchPublicationsComponent.getResultsForEntity("person", this.personId, 1, 10);
115
      this.linkToSearchPublications = OpenaireProperties.getLinkToAdvancedSearchPublications() + "?person=" + this.personId + "&pe=and";
116
     }
117

    
118
     private searchDatasets() {
119
       this.searchDatasetsComponent.getResultsForEntity("person", this.personId, 1, 10);
120
       this.linkToSearchDatasets = OpenaireProperties.getLinkToAdvancedSearchDatasets() + "?person=" + this.personId + "&pe=and";
121
     }
122
}
(2-2/2)