/
project-tab-view.component.ts
126 lines (101 loc) · 3.79 KB
/
project-tab-view.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { Component, Input, OnInit } from '@angular/core';
import {
DataManagementPlan,
Grant, IId, IUrl, Organization, Person, Place, SingleProject
} from '@dasch-swiss/dsp-js';
import { MetadataService } from '../dataset-metadata.service';
@Component({
selector: 'app-project-tab-view',
templateUrl: './project-tab-view.component.html',
styleUrls: ['./project-tab-view.component.scss']
})
export class ProjectTabViewComponent implements OnInit {
// metadata object
@Input() selectedProject: SingleProject;
@Input() subProperties: Object;
projectObject: {[key: string]: any};
// metadata keys that we do not want to display in template
excludeKeys = ['contactPoint'];
// list of date keys from metadata object
// used for formatting
dateKeys = ['startDate', 'endDate'];
// keys that require IUrl template
iUrlTemplatesKeys = ['discipline', 'temporalCoverage', 'url'];
dmps: DataManagementPlan[] = [];
funders: Person[] | Organization[] = [];
funderType: string;
grants = [];
constructor(private _metadataService: MetadataService) {
}
ngOnInit() {
this.projectObject = this.selectedProject;
// get DMP
if (this.selectedProject.dataManagementPlan) {
this.dmps = this.getDMP(this.selectedProject.dataManagementPlan);
}
// get funder details
this.getFunders(this.selectedProject.funder);
// get grants if present
if (this.selectedProject.grant) {
this.getGrants(this.selectedProject.grant);
}
}
getDMP(currenDmps: DataManagementPlan | IId[]): DataManagementPlan[] {
if (currenDmps instanceof DataManagementPlan) {
return [currenDmps];
}
const tmp: DataManagementPlan[] = [];
for (const iid of currenDmps) {
tmp.push(this.subProperties[iid.id]);
}
return tmp;
}
getFunders(flist: any[]) {
// check if it is person, organization or IId
this.funderType = this._metadataService.getContactType(flist[0]);
if (this.funderType) {
this.funders = flist;
return;
}
for (const funder of flist) {
this.funders.push(this.subProperties[funder.id]);
}
this.funderType = this._metadataService.getContactType(this.funders[0]);
}
getGrants(glist: any[]) {
let tmpGrants: Grant[] = [];
if (glist[0] instanceof Grant) {
tmpGrants = glist;
} else {
// if it is IId objects array, retrive it's details
for (const iid of glist) {
tmpGrants.push(this.subProperties[iid.id]);
}
}
// get funder details along with other details
for (const grant of tmpGrants) {
// checck if grant contains person, organization or IId objects
let ftype = this._metadataService.getContactType(grant.funder[0]);
let flist = [];
if (ftype) {
// it is a person of organization object
flist = grant.funder;
} else {
// it means it is a IId object. So we need to retrive the details
// of every funder using the id provided here
for (const fund of grant.funder) {
flist.push(this.subProperties[fund.id]);
}
ftype = this._metadataService.getContactType(flist[0]);
}
const tmpGrantObj = {
funder : flist,
funderType: ftype,
name: grant.name ? grant.name : undefined,
number: grant.number ? grant.number : undefined,
url: grant.url ? grant.url : undefined
};
this.grants.push(tmpGrantObj);
}
}
}