Project

General

Profile

1
import {Component, ViewChild, OnInit} from '@angular/core';
2
import {Observable} from 'rxjs/Observable';
3
import {ActivatedRoute, Params} from '@angular/router';
4
import {ProjectService} from '../../services/project.service';
5
import {ProjectInfo} from '../../utils/entities/projectInfo';
6
import {InlineClaimResultComponent} from '../../claimPages/inlineClaims/inlineClaimResult.component';
7

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

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

    
16
@Component({
17
    selector: 'project',
18
    templateUrl: 'project.component.html',
19
 })
20
export class ProjectComponent  implements OnInit{
21

    
22

    
23
  private projectId : string ;
24
  private projectInfo: ProjectInfo;
25

    
26
  private project ;
27

    
28
   @ViewChild (InlineClaimResultComponent) inlineClaimResult : InlineClaimResultComponent ;
29

    
30

    
31
  public warningMessage = "";
32
  public errorMessage = "";
33

    
34
  sub: any;
35
  subPublications: any;
36
  subDatasets: any;
37
  subDatasetsCount: any;
38

    
39
  private searchPublicationsComponent : SearchPublicationsComponent;
40
  private linkToSearchPublications = "";
41
  private searchDatasetsComponent : SearchDatasetsComponent;
42
  private linkToSearchDatasets = "";
43

    
44
  constructor (private _projectService: ProjectService,
45
      private  route: ActivatedRoute,
46
      private _searchPublicationsService: SearchPublicationsService,
47
      private _searchDatasetsService: SearchDatasetsService) {
48
    console.info('project constructor');
49

    
50
    this.searchPublicationsComponent = new SearchPublicationsComponent(this.route, this._searchPublicationsService);
51
    this.searchDatasetsComponent = new SearchDatasetsComponent(this.route, this._searchDatasetsService);
52
  }
53

    
54
  ngOnInit() {
55
    this.sub =  this.route.queryParams.subscribe(params => {
56
      this.projectId = params['projectId'];
57
       console.info("Id is :"+this.projectId);
58
       if(this.projectId){
59
          this.getProjectInfo(this.projectId);
60
      }else{
61
		      this.warningMessage="No valid project id";
62
      }
63

    
64
   });
65

    
66
   this.subPublications =  this.route.queryParams.subscribe(params => {
67
         this.searchPublications();
68
   });
69

    
70
   this.subDatasetsCount = this.route.queryParams.subscribe(params => {
71
       this._searchDatasetsService.numOfEntityDatasets(this.projectId, "projects/").subscribe(
72
         data => {
73
             this.searchDatasetsComponent.totalResults = data;
74
         },
75
         err => {
76
   		    console.error(err);
77
   		 }
78
       );
79
   })
80

    
81
}
82

    
83

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

    
95
  private searchPublications() {
96
    this.searchPublicationsComponent.getResultsForEntity("project", this.projectId, 1, 10);
97
    this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications();
98
  }
99

    
100
  private searchDatasets() {
101
      this.searchDatasetsComponent.getResultsForEntity("project", this.projectId, 1, 10);
102
      this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets();
103
  }
104

    
105
  private searchDatasetsInit() {
106
      if(this.subDatasets == undefined && this.searchDatasetsComponent.totalResults > 0) {
107
          this.subDatasets =  this.route.queryParams.subscribe(params => {
108
               this.searchDatasets();
109
          });
110
      }
111
  }
112

    
113
  getProjectInfo (id:string)  {
114
    console.info("inside getProjectInfo of component");
115
	this.warningMessage = '';
116
    this.errorMessage=""
117
    this._projectService.getProjectInfo(id).subscribe(
118
      data => {
119
          this.projectInfo = data;
120
          this.project= { funderId: "", funderName: this.projectInfo.funder, projectId: this.projectId, projectName: this.projectInfo.title, projectAcronym: this.projectInfo.acronym, startDate: this.projectInfo.startDate, endDate: this.projectInfo.endDate };
121
      },
122
      err => {
123
		console.error(err);
124
		this.errorMessage = 'No project found';
125
		}
126
    );
127
   }
128

    
129
      /*
130
      ********* Methods for Inline Claim  of results *****
131
        */
132
      toggleClaimResult(){
133
          this.inlineClaimResult.toggle();
134
      }
135
      publicationAdded($event){
136
       //TODO
137
       }
138

    
139
       datasetAdded($event){
140
         var contexts =$event.value;
141

    
142
 //TODO
143
        }
144

    
145
}
(2-2/2)