1
|
import {Component, Input} from '@angular/core';
|
2
|
import {Router} from '@angular/router';
|
3
|
import {ActivatedRoute} from '@angular/router';
|
4
|
import {Title, Meta} from '@angular/platform-browser';
|
5
|
|
6
|
import {Observable} from 'rxjs/Observable';
|
7
|
|
8
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
9
|
|
10
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
11
|
|
12
|
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
|
13
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
14
|
|
15
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
16
|
import {OrganizationService} from '../../services/organization.service';
|
17
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
18
|
|
19
|
@Component({
|
20
|
selector: 'deposit-by-subject-result',
|
21
|
templateUrl: 'depositBySubjectResult.component.html'
|
22
|
})
|
23
|
|
24
|
export class DepositBySubjectResultComponent {
|
25
|
@Input() compatibility: string = '';
|
26
|
|
27
|
// Type of entity: Publication or Research Data
|
28
|
@Input() requestFor: string = "Research Data";
|
29
|
@Input() subject: string = "";
|
30
|
@Input() piwikSiteId = null;
|
31
|
public newSubject: string= "";
|
32
|
|
33
|
public fetchDataproviders : FetchDataproviders;
|
34
|
public linkToSearchDataproviders = "";
|
35
|
|
36
|
// url of Zenodo
|
37
|
public zenodo: string;
|
38
|
|
39
|
public page: number = 1;
|
40
|
|
41
|
public status: number;
|
42
|
|
43
|
public routerHelper:RouterHelper = new RouterHelper();
|
44
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
45
|
|
46
|
sub: any;
|
47
|
piwiksub: any;
|
48
|
properties:EnvProperties;
|
49
|
|
50
|
constructor (private _router: Router,
|
51
|
private route: ActivatedRoute,
|
52
|
private _searchDataprovidersService: SearchDataprovidersService,
|
53
|
private _meta: Meta,
|
54
|
private _title: Title,
|
55
|
private _piwikService:PiwikService) {
|
56
|
|
57
|
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
|
58
|
|
59
|
this.status = this.errorCodes.LOADING;
|
60
|
|
61
|
var description = "Openaire, repositories, open access, content provider, compatibility, organization, deposit "+ this.requestFor;
|
62
|
var title = "Deposit "+this.requestFor;
|
63
|
|
64
|
this.updateTitle(title);
|
65
|
this.updateDescription(description);
|
66
|
}
|
67
|
|
68
|
ngOnInit() {
|
69
|
this.route.data
|
70
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
71
|
this.properties = data.envSpecific;
|
72
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
73
|
this.zenodo = this.properties.zenodo;
|
74
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
75
|
this.piwiksub = this._piwikService.trackView(this.properties, "Deposit "+this.requestFor, this.piwikSiteId).subscribe();
|
76
|
}
|
77
|
|
78
|
});
|
79
|
console.info('depositResult init');
|
80
|
|
81
|
this.sub = this.route.queryParams.subscribe(params => {
|
82
|
this.subject = params['subject'];
|
83
|
this.newSubject = this.subject;
|
84
|
this.searchDataproviders();
|
85
|
});
|
86
|
}
|
87
|
|
88
|
// ngDoCheck() {
|
89
|
// if(this.organizationId == "" || this.organizationId == undefined) {
|
90
|
// this.organizationId = "";
|
91
|
// this.status = this.errorCodes.ERROR;
|
92
|
// }
|
93
|
// }
|
94
|
|
95
|
ngOnDestroy() {
|
96
|
this.sub.unsubscribe();
|
97
|
if(this.piwiksub){
|
98
|
this.piwiksub.unsubscribe();
|
99
|
}
|
100
|
}
|
101
|
|
102
|
public totalPages(): number {
|
103
|
let totalPages:any = this.fetchDataproviders.searchUtils.totalResults/(this.fetchDataproviders.searchUtils.size);
|
104
|
if(!(Number.isInteger(totalPages))) {
|
105
|
totalPages = (parseInt(totalPages, 10) + 1);
|
106
|
}
|
107
|
return totalPages;
|
108
|
}
|
109
|
|
110
|
public searchDataproviders() {
|
111
|
this.subject = this.newSubject;
|
112
|
this.fetchDataproviders.getResultsBySubjectsForDeposit( (this.subject =="")?"*":this.subject, this.requestFor, this.page, 10, this.properties);
|
113
|
this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders;
|
114
|
}
|
115
|
|
116
|
public goToDeposit() {
|
117
|
if(this.requestFor == "Publications") {
|
118
|
this._router.navigate( ['participate/deposit-publications'] );
|
119
|
} else if(this.requestFor == "Research Data") {
|
120
|
this._router.navigate( ['participate/deposit-datasets'] );
|
121
|
}
|
122
|
}
|
123
|
public pageChange($event) {
|
124
|
this.page = +$event.value;
|
125
|
this.searchDataproviders();
|
126
|
}
|
127
|
|
128
|
private updateDescription(description:string) {
|
129
|
this._meta.updateTag({content:description},"name='description'");
|
130
|
this._meta.updateTag({content:description},"property='og:description'");
|
131
|
}
|
132
|
private updateTitle(title:string) {
|
133
|
var _prefix ="OpenAIRE | ";
|
134
|
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
|
135
|
|
136
|
this._title.setTitle(_title);
|
137
|
this._meta.updateTag({content:_title},"property='og:title'");
|
138
|
}
|
139
|
private updateUrl(url:string) {
|
140
|
this._meta.updateTag({content:url},"property='og:url'");
|
141
|
}
|
142
|
}
|