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