1
|
import { Component, Input, Output, EventEmitter} from '@angular/core';
|
2
|
import { Observable } from 'rxjs/Observable';
|
3
|
import { SearchDataciteService } from '../../services/searchDatacite.service';
|
4
|
import {SearchDatasetsService} from '../../services/searchDatasets.service';
|
5
|
import {ClaimResult} from '../../utils/entities/claimEntities.class';
|
6
|
import { ErrorCodes} from '../../utils/properties/openaireProperties';
|
7
|
import{DOI} from '../../utils/string-utils.class';
|
8
|
|
9
|
|
10
|
@Component({
|
11
|
selector: 'claim-dataset',
|
12
|
template: `
|
13
|
|
14
|
<!--div *ngIf="warningMessage.length > 0" class="alert alert-warning" role="alert">{{warningMessage}}</div>
|
15
|
<div *ngIf="infoMessage.length > 0" class="alert alert-info" role="alert">{{infoMessage}}</div-->
|
16
|
|
17
|
<div class="panel ">
|
18
|
<div class="">
|
19
|
|
20
|
<ul class="nav nav-tabs">
|
21
|
<li class="active"><a data-toggle="tab" href="#datacite">Datacite ({{(dataciteResultsNum==null)?'0':dataciteResultsNum}})</a></li>
|
22
|
<li><a data-toggle="tab" href="#openaire">Openaire ({{(openaireResultsNum==null)?'0':openaireResultsNum}})</a></li>
|
23
|
</ul>
|
24
|
<div class="tab-content">
|
25
|
<div id="datacite" class="tab-pane fade in active">
|
26
|
<div class = "panel-body">
|
27
|
<div *ngIf="dataciteResultsNum != null && dataciteResultsNum > 0">
|
28
|
<p > {{dataciteResultsNum }} Total Results </p>
|
29
|
<paging-no-load [currentPage]="datacitePage" [totalResults]="dataciteResultsNum" [navigateTo]="navigateTo" [term]="keyword" [size]="size" (pageChange)="datacitePageChange($event)"> </paging-no-load>
|
30
|
</div>
|
31
|
<div *ngIf="dataciteResultsNum == null || dataciteResultsNum == 0" class="alert alert-info" role="alert">No results found</div>
|
32
|
<div >
|
33
|
<ul *ngIf="dataciteResults.length > 0 " class="list-group">
|
34
|
<li *ngFor=" let item of dataciteResults " [class]="(isSelected(item.doi))?'list-group-item panel-footer':'list-group-item'" >
|
35
|
<div >
|
36
|
<a *ngIf="item.doi" target="_blank" href="{{'http://dx.doi.org/'+item.doi}}" >{{item.title}}</a>
|
37
|
<span *ngIf="!item.doi" >{{item.title}}</span>
|
38
|
<span *ngIf="!isSelected(item.doi)" (click)="add(item, item.doi,'dataset','datacite',item.title,'http://dx.doi.org/'+item.doi, null,'OPEN')" aria-hidden="true" class= " btn glyphicon glyphicon-plus"></span>
|
39
|
</div>
|
40
|
<span *ngIf="item.publisher" class="sub-title-elements">Publisher: {{item.publisher}}</span>
|
41
|
<div *ngIf="item.creator" class="sub-title-elements">Authors: <span *ngFor="let author of item.creator let i = index">{{author}}{{(i < (item.creator.length-1))?"; ":""}}</span></div>
|
42
|
|
43
|
</li>
|
44
|
</ul>
|
45
|
|
46
|
</div>
|
47
|
</div>
|
48
|
</div>
|
49
|
<div id="openaire" class="tab-pane fade">
|
50
|
<div class = "panel-body">
|
51
|
<div *ngIf="openaireResultsNum != null && openaireResultsNum > 0">
|
52
|
<paging-no-load [currentPage]="openairePage" [totalResults]="openaireResultsNum" [navigateTo]="navigateTo" [term]="keyword" [size]="size" (pageChange)="openairePageChange($event)"> </paging-no-load>
|
53
|
</div>
|
54
|
<div >
|
55
|
<ul *ngIf="openaireResults.length > 0 " class="list-group">
|
56
|
<li *ngFor=" let result of openaireResults " [class]="(isSelected(result.id))?'list-group-item panel-footer':'list-group-item'">
|
57
|
<div >
|
58
|
<a *ngIf="result['title'].url" target="_blank" [href]="result['title'].url" >{{result['title'].name}}</a>
|
59
|
<span *ngIf="!result['title'].url" >{{result['title'].name}}</span>
|
60
|
<span *ngIf="!isSelected(result.id)"
|
61
|
(click)="add(result, result.id, 'dataset', 'openaire', result['title'].name, result['title'].url, result.year, result['title'].accessMode)" aria-hidden="true" class= " btn glyphicon glyphicon-plus"></span>
|
62
|
</div>
|
63
|
<span *ngIf="result.publisher" class="sub-title-elements">Publisher: {{result.publisher}}</span><span *ngIf="(result.year)">({{result.year}})</span>
|
64
|
<div *ngIf="result.authors" class="sub-title-elements">Authors: <span *ngFor="let author of result.authors let i = index">{{author.name}}{{(i < (result.authors.length-1))?"; ":""}}</span></div>
|
65
|
|
66
|
</li>
|
67
|
</ul>
|
68
|
<div *ngIf="openaireResults.length == 0" class = "alert alert-info " > No results found </div>
|
69
|
</div>
|
70
|
</div>
|
71
|
</div>
|
72
|
</div>
|
73
|
</div>
|
74
|
|
75
|
`
|
76
|
})
|
77
|
export class ClaimDatasetComponent {
|
78
|
constructor (private _searchDataciteService: SearchDataciteService, private _searchDatasetsService:SearchDatasetsService){
|
79
|
var myDate = new Date();
|
80
|
this.todayDate = myDate.getFullYear()+ "-" +(myDate.getMonth() + 1) + "-" + myDate.getDate() ;
|
81
|
this.nextDate = (myDate.getFullYear()+100)+ "-" +(myDate.getMonth() + 1) + "-" + myDate.getDate() ;
|
82
|
|
83
|
}
|
84
|
ngOnInit() {
|
85
|
if(this.keyword !=null && this.keyword.length > 0){
|
86
|
this.search(this.keyword,this.size,1);
|
87
|
}
|
88
|
}
|
89
|
|
90
|
@Input() public select:boolean = true ;
|
91
|
@Input() public keyword:string = '';
|
92
|
@Input() public selectedDatasets = [] ;
|
93
|
@Output() datasetsChange = new EventEmitter();
|
94
|
public size:number = 10;
|
95
|
public navigateTo: string = "Search";
|
96
|
public source: string = "datacite";
|
97
|
public type : string = "dataset";
|
98
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
99
|
|
100
|
dataciteResults=[];
|
101
|
dataciteResultsNum : Observable<number> = null;
|
102
|
dataciteStatus = this.errorCodes.NONE;
|
103
|
datacitePage : number = 1;
|
104
|
|
105
|
openaireResults=[];
|
106
|
openaireResultsNum:number = 0 ;
|
107
|
openaireStatus = this.errorCodes.NONE;
|
108
|
openairePage : number = 1;
|
109
|
|
110
|
public warningMessage = "";
|
111
|
public infoMessage = "";
|
112
|
|
113
|
public todayDate = '';
|
114
|
public nextDate = '';
|
115
|
public DOIs:string[] = [];
|
116
|
|
117
|
public search(term: string, size : number, page : number){
|
118
|
this.DOIs = DOI.getDOIsFromString(term);
|
119
|
this.searchDatacite(term,10,1);
|
120
|
this.searchOpenaire(term,10,1);
|
121
|
}
|
122
|
private searchDatacite (term: string, size : number, page : number) {
|
123
|
this.getDataciteResults(term,size,page);
|
124
|
this.warningMessage = "";
|
125
|
this.infoMessage = "";
|
126
|
|
127
|
}
|
128
|
private searchOpenaire (term: string, size : number, page : number) {
|
129
|
if(this.DOIs.length > 0 ){
|
130
|
this.openaireStatus = this.errorCodes.LOADING;
|
131
|
this._searchDatasetsService.searchDatasetsByDois(this.DOIs, null, page, size, []).subscribe(
|
132
|
data => {
|
133
|
if(data != null) {
|
134
|
this.openairePage=page;
|
135
|
this.openaireResultsNum = data[0];
|
136
|
this.openaireResults = data[1];
|
137
|
this.openaireStatus = this.errorCodes.DONE;
|
138
|
if(this.openaireResultsNum == 0){
|
139
|
this.openaireStatus = this.errorCodes.NONE;
|
140
|
}
|
141
|
}
|
142
|
},
|
143
|
err => {
|
144
|
this.openaireStatus = this.errorCodes.ERROR;
|
145
|
console.error(err.status);
|
146
|
}
|
147
|
);
|
148
|
}else{
|
149
|
this._searchDatasetsService.searchDatasets('q="'+term+'"', null, page, size, []).subscribe(
|
150
|
data => {
|
151
|
if(data != null) {
|
152
|
this.openairePage=page;
|
153
|
this.openaireResultsNum = data[0];
|
154
|
this.openaireResults = data[1];
|
155
|
this.openaireStatus = this.errorCodes.DONE;
|
156
|
if(this.openaireResultsNum == 0){
|
157
|
this.openaireStatus = this.errorCodes.NONE;
|
158
|
}
|
159
|
}
|
160
|
},
|
161
|
err => {
|
162
|
this.openaireStatus = this.errorCodes.ERROR;
|
163
|
console.error(err.status);
|
164
|
}
|
165
|
);
|
166
|
}
|
167
|
this.warningMessage = "";
|
168
|
this.infoMessage = "";
|
169
|
|
170
|
}
|
171
|
private getDataciteResults (term: string, size : number, page : number) {
|
172
|
this._searchDataciteService.searchDataciteResults(term, size, page).subscribe(
|
173
|
data => {
|
174
|
this.dataciteResults = data.docs;
|
175
|
this.datacitePage=page;
|
176
|
this.dataciteResultsNum = data.numFound;
|
177
|
this.dataciteStatus = this.errorCodes.DONE;
|
178
|
|
179
|
|
180
|
},
|
181
|
err => {
|
182
|
this.dataciteStatus = this.errorCodes.ERROR;
|
183
|
console.error(err);
|
184
|
}
|
185
|
|
186
|
);
|
187
|
}
|
188
|
|
189
|
add(item, itemId,itemType,itemSource,itemTitle, itemUrl, date, accessmode){
|
190
|
console.log(' adding dataset '+ itemSource+" "+ itemTitle);
|
191
|
var result: ClaimResult ;
|
192
|
if(itemSource == 'datacite'){
|
193
|
result = {id: itemId, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: 'OPEN', embargoEndDate: this.nextDate, date : date};
|
194
|
}else if (itemSource == 'openaire'){
|
195
|
//TODO put right access rights
|
196
|
result = {id: itemId, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: accessmode, embargoEndDate: this.nextDate, date : date};
|
197
|
}
|
198
|
var found:boolean = this.isSelected( result.id);
|
199
|
this.warningMessage = "";
|
200
|
if (!found) {
|
201
|
this.selectedDatasets.push(result);
|
202
|
this.datasetsChange.emit({
|
203
|
value: this.selectedDatasets
|
204
|
});
|
205
|
}else{
|
206
|
this.warningMessage = "Dataset already in selected list";
|
207
|
}
|
208
|
|
209
|
}
|
210
|
|
211
|
|
212
|
datacitePageChange($event) {
|
213
|
this.datacitePage=$event.value;
|
214
|
this.dataciteResults=[];
|
215
|
this.searchDatacite(this.keyword,10,this.datacitePage);
|
216
|
this.warningMessage = "";
|
217
|
this.infoMessage = "";
|
218
|
|
219
|
}
|
220
|
openairePageChange($event) {
|
221
|
this.openairePage=$event.value;
|
222
|
this.openaireResults=[];
|
223
|
this.searchOpenaire(this.keyword,10,this.openairePage);
|
224
|
this.warningMessage = "";
|
225
|
this.infoMessage = "";
|
226
|
|
227
|
}
|
228
|
isSelected(id:string){
|
229
|
|
230
|
var found:boolean = false;
|
231
|
this.warningMessage = "";
|
232
|
for (var _i = 0; _i < this.selectedDatasets.length; _i++) {
|
233
|
let item = this.selectedDatasets[_i];
|
234
|
if(item.id == id){
|
235
|
found=true;
|
236
|
break;
|
237
|
}
|
238
|
}
|
239
|
return found;
|
240
|
}
|
241
|
}
|