Project

General

Profile

1
import {Component, ViewChild} 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/simple/searchPublications.component';
9
import {SearchPublicationsService} from '../../services/searchPublications.service';
10
import { SearchDatasetsComponent } from '../../searchPages/simple/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{
21

    
22

    
23
  private projectId : string ;
24
  public projectInfo: ProjectInfo;
25
  private metrics: string;
26

    
27
  private project ;
28

    
29
   @ViewChild (InlineClaimResultComponent) inlineClaimResult : InlineClaimResultComponent ;
30

    
31

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

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

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

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

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

    
55
  ngOnInit() {
56
    this.sub =  this.route.queryParams.subscribe(params => {
57
      this.projectId = params['projectId'];
58
       console.info("Id is :"+this.projectId);
59
       if(this.projectId){
60
          this.getProjectInfo(this.projectId);
61
          //  this.subPublications =  this.route.queryParams.subscribe(params => {
62
          this.searchPublications();
63
          //  });
64

    
65
          this.subDatasetsCount = this._searchDatasetsService.numOfEntityDatasets(this.projectId, "projects/").subscribe(
66
            data => {
67
              this.searchDatasetsComponent.searchUtils.totalResults = data;
68
            },
69
            err => {
70
              console.error(err);
71
            });
72
      }else{
73
		      this.warningMessage="No valid project id";
74
      }
75

    
76
  });
77

    
78
}
79

    
80

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

    
92
  private searchPublications() {
93
    this.searchPublicationsComponent.getResultsForEntity("project", this.projectId, 1, 10);
94
    this.linkToSearchPublications = OpenaireProperties.getLinkToAdvancedSearchPublications() + "?project=" + this.projectId+"&pr=and";
95
  }
96

    
97
  private searchDatasets() {
98
      this.searchDatasetsComponent.getResultsForEntity("project", this.projectId, 1, 10);
99
      this.linkToSearchDatasets = OpenaireProperties.getLinkToAdvancedSearchDatasets() + "?project=" + this.projectId+"&pr=and";
100
  }
101

    
102
  private searchDatasetsInit() {
103
      if(this.subDatasets == undefined && this.searchDatasetsComponent.searchUtils.totalResults > 0) {
104
          // this.subDatasets =  this.route.queryParams.subscribe(params => {
105
               this.searchDatasets();
106
          // });
107
      }
108
  }
109

    
110
  getProjectInfo (id:string)  {
111
    console.info("inside getProjectInfo of component");
112
	this.warningMessage = '';
113
    this.errorMessage=""
114
    this._projectService.getProjectInfo(id).subscribe(
115
      data => {
116
          this.projectInfo = data;
117
          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 };
118
      },
119
      err => {
120
		console.error(err);
121
		this.errorMessage = 'No project found';
122
		}
123
    );
124
   }
125

    
126
   getMetrics() {
127
       console.info("getProjectMetrics: component");
128
       this._projectService.getMetrics(this.projectId).subscribe(
129
        data => {
130
            this.metrics = data;
131
        },
132
        err => {
133
          console.error(err);
134
          console.info("error");
135

    
136
          this.errorMessage = 'No project metrics found';
137
        }
138
      );
139
   }
140

    
141
      /*
142
      ********* Methods for Inline Claim  of results *****
143
        */
144
      toggleClaimResult(){
145
          this.inlineClaimResult.toggle();
146
      }
147
      publicationAdded($event){
148
       //TODO
149
       }
150

    
151
       datasetAdded($event){
152
         var contexts =$event.value;
153

    
154
 //TODO
155
        }
156

    
157
}
(2-2/2)