1
|
import {Component, ViewChild, Input} from '@angular/core';
|
2
|
import {Location} from '@angular/common';
|
3
|
import {Observable} from 'rxjs/Observable';
|
4
|
import {ActivatedRoute, Router, Params} from '@angular/router';
|
5
|
import {ClaimsByTokenService} from './claimsByToken.service';
|
6
|
|
7
|
import {ModalSelect} from '../../utils/modal/selectModal.component';
|
8
|
import {ModalLoading} from '../../utils/modal/loading.component';
|
9
|
|
10
|
import {Session} from '../../login/utils/helper.class';
|
11
|
|
12
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
13
|
|
14
|
@Component({
|
15
|
selector: 'claims-project-manager',
|
16
|
template: `
|
17
|
|
18
|
<!--div *ngIf="accessStatus=='empty'" class="uk-margin-top uk-width-medium-2-3 uk-container-center">
|
19
|
<div class="uk-block uk-block-primary uk-block-large uk-contrast uk-text-center">
|
20
|
<p class="uk-text-large">Please enter your email and then press 'See Claims' button.</p>
|
21
|
<form class="uk-form">
|
22
|
<fieldset data-uk-margin>
|
23
|
<input type="text" placeholder="example@email.com" name="email" [(ngModel)]="email">
|
24
|
<button (click)="validateJWTandToken()" class="uk-button">See Claims</button>
|
25
|
</fieldset>
|
26
|
</form>
|
27
|
</div>
|
28
|
</div-->
|
29
|
|
30
|
<div *ngIf="accessStatus=='invalid'" class="uk-margin-top uk-width-medium-2-3 uk-container-center">
|
31
|
<div class="uk-block uk-block-primary uk-block-large uk-contrast uk-text-center">
|
32
|
<!--p class="uk-text-large">Oops! There is no entry for you! Please retry with another email or for another project.</p-->
|
33
|
<!--button (click)="accessStatus='empty'" class="uk-button">Retry</button-->
|
34
|
<p class="uk-text-large">Oops! Your email does not give you the authority to view claims for the selected project. Please contact the administrators.</p>
|
35
|
</div>
|
36
|
</div>
|
37
|
|
38
|
<div *ngIf="accessStatus=='valid'">
|
39
|
<h1 class="page-header">
|
40
|
<a [queryParams]="routerHelper.createQueryParam('projectId',project['openaireId'])"
|
41
|
routerLinkActive="router-link-active"
|
42
|
routerLink="/search/project" >
|
43
|
{{project['name']}} ({{project['funderName']}})
|
44
|
</a>
|
45
|
</h1>
|
46
|
<h2> Pending Claims</h2>
|
47
|
|
48
|
<div *ngIf=" pending_claims && pending_claims.length == 0" >
|
49
|
<div class = "uk-alert uk-alert-info " >No pending claims found.</div>
|
50
|
</div>
|
51
|
|
52
|
<div class="uk-overflow-container">
|
53
|
<!--table *ngIf="pending_claims && pending_claims.length > 0" class="uk-table uk-table-striped">
|
54
|
<thead>
|
55
|
<tr>
|
56
|
<th>Research Result</th>
|
57
|
<th class="uk-text-center">Claimed by</th>
|
58
|
<th class="uk-text-center">Claimed Date</th>
|
59
|
<th class="uk-text-center">Approve</th>
|
60
|
</tr>
|
61
|
</thead>
|
62
|
<tbody>
|
63
|
<tr class="uk-table-middle" *ngFor="let claim of pending_claims ">
|
64
|
<td class="uk-width-2-6" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
|
65
|
<td class="uk-width-1-6 uk-text-center" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
|
66
|
<td class="uk-width-1-6 uk-text-center">{{claim.userMail}}</td>
|
67
|
<td class="uk-width-1-6 uk-text-center">{{claim.date}}</td>
|
68
|
<td class="uk-width-1-6 uk-text-center">
|
69
|
|
70
|
<label>
|
71
|
Yes <input [id]="claim.id" type="checkbox" (click)="selectApprove(claim.id,$event)" [ngModel]="isSelectedRight(claim.id)"/>
|
72
|
</label>
|
73
|
<label>
|
74
|
No <input [id]="claim.id" type="checkbox" (click)="selectDisapprove(claim.id,$event)" [ngModel]="isSelectedWrong(claim.id)"/>
|
75
|
</label>
|
76
|
</td>
|
77
|
</tr>
|
78
|
</tbody>
|
79
|
</table-->
|
80
|
|
81
|
<table *ngIf="pending_claims && pending_claims.length > 0" class="uk-table uk-table-striped custom-dataTable-content"
|
82
|
[mfData]="pending_claims" #mf1="mfDataTable" [mfRowsOnPage]="rowsOnPage" [mfActivePage]="1">
|
83
|
<!--[(mfSortBy)]="sortByClaimDate1" (mfSortOrder)="sortOrder"-->
|
84
|
<thead>
|
85
|
<tr>
|
86
|
<th><mfDefaultSorter [by]="sortByTitle1">Research Result</mfDefaultSorter></th>
|
87
|
<th class="uk-text-center"><mfDefaultSorter by="claim1.userMail">Claimed By</mfDefaultSorter></th>
|
88
|
<th class="uk-text-center"><mfDefaultSorter [by]="sortByClaimDate1">Claimed Date</mfDefaultSorter></th>
|
89
|
<th class="uk-text-center">Approve</th>
|
90
|
</tr>
|
91
|
</thead>
|
92
|
<tbody>
|
93
|
<tr class="uk-table-middle" *ngFor="let claim1 of mf1.data">
|
94
|
<td class="uk-width-2-6" *ngIf="claim1.targetType != 'project'"><claim-entity [entity]="claim1.target" [type]="claim1.targetType" > </claim-entity></td>
|
95
|
<td class="uk-width-1-6 uk-text-center" *ngIf="claim1.sourceType != 'project'"><claim-entity [entity]="claim1.source" [type]="claim1.sourceType" > </claim-entity></td>
|
96
|
<td class="uk-width-1-6 uk-text-center">{{claim1.userMail}}</td>
|
97
|
<td class="uk-width-1-6 uk-text-center">{{claim1.date}}</td>
|
98
|
<td class="uk-width-1-6 uk-text-center">
|
99
|
|
100
|
<label>
|
101
|
Yes <input [id]="claim1.id" type="checkbox" (click)="selectApprove(claim1.id,$event)" [ngModel]="isSelectedRight(claim1.id)"/>
|
102
|
</label>
|
103
|
<label>
|
104
|
No <input [id]="claim1.id" type="checkbox" (click)="selectDisapprove(claim1.id,$event)" [ngModel]="isSelectedWrong(claim1.id)"/>
|
105
|
</label>
|
106
|
</td>
|
107
|
</tr>
|
108
|
</tbody>
|
109
|
<tfoot>
|
110
|
<tr>
|
111
|
<td>
|
112
|
</td>
|
113
|
<td></td>
|
114
|
<td></td>
|
115
|
<td>
|
116
|
<paging-no-load [currentPage]="1" [totalResults]="pending_claims.length" [size]="rowsOnPage" (pageChange)="refreshTable(mf1, $event)"></paging-no-load>
|
117
|
</td>
|
118
|
</tr>
|
119
|
</tfoot>
|
120
|
</table>
|
121
|
</div>
|
122
|
|
123
|
<h2> Already Curated Claims</h2>
|
124
|
|
125
|
<div *ngIf=" curated_claims && curated_claims.length == 0" >
|
126
|
<div class = "uk-alert uk-alert-info " >No curated claims found.</div>
|
127
|
</div>
|
128
|
|
129
|
<div class="uk-overflow-container">
|
130
|
<!--table *ngIf="curated_claims && curated_claims.length > 0" class="uk-table uk-table-striped">
|
131
|
<thead>
|
132
|
<tr>
|
133
|
<th>Research Result</th>
|
134
|
<th class="uk-text-center">Claimed by</th>
|
135
|
<th class="uk-text-center">Claimed Date</th>
|
136
|
<th class="uk-text-center">Curated by</th>
|
137
|
<th class="uk-text-center">Curation Date</th>
|
138
|
<th class="uk-text-center">Approved</th>
|
139
|
</tr>
|
140
|
</thead>
|
141
|
<tbody>
|
142
|
<tr class="uk-table-middle" *ngFor="let claim of curated_claims let i=index">
|
143
|
<td class="uk-width-1-6" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
|
144
|
<td class="uk-width-1-6" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
|
145
|
<td class="uk-width-1-6 uk-text-center">{{claim.userMail}}</td>
|
146
|
<td class="uk-width-1-6 uk-text-center">{{claim.date}}</td>
|
147
|
<td class="uk-width-1-6 uk-text-center">{{claim.curatedBy}}</td>
|
148
|
<td class="uk-width-1-6 uk-text-center">{{claim.curationDate}}</td>
|
149
|
<td class="uk-width-1-6 uk-text-center">
|
150
|
|
151
|
<label>
|
152
|
Yes <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isRight(claim)"/>
|
153
|
</label>
|
154
|
|
155
|
<label>
|
156
|
No <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isWrong(claim)"/>
|
157
|
</label>
|
158
|
</td>
|
159
|
</tr>
|
160
|
</tbody>
|
161
|
</table-->
|
162
|
|
163
|
<table *ngIf="curated_claims && curated_claims.length > 0" class="uk-table uk-table-striped"
|
164
|
[mfData]="curated_claims" #mf2="mfDataTable" [mfRowsOnPage]="rowsOnPage" [mfActivePage]="1">
|
165
|
<!--[(mfSortBy)]="sortByCurationDate2" [(mfSortOrder)]="sortOrder"-->
|
166
|
<thead>
|
167
|
<tr>
|
168
|
<th><mfDefaultSorter [by]="sortByTitle1">Research Result</mfDefaultSorter></th>
|
169
|
<!--th>Link to</th-->
|
170
|
<th class="uk-text-center"><mfDefaultSorter by="userMail">Claimed by</mfDefaultSorter></th>
|
171
|
<th class="uk-text-center"><mfDefaultSorter [by]="sortByClaimDate2">Claimed Date</mfDefaultSorter></th>
|
172
|
<th class="uk-text-center"><mfDefaultSorter by="curatedBy">Curated by</mfDefaultSorter></th>
|
173
|
<th class="uk-text-center"><mfDefaultSorter [by]="sortByCurationDate2">Curation Date</mfDefaultSorter></th>
|
174
|
<th class="uk-text-center">Approved</th>
|
175
|
</tr>
|
176
|
</thead>
|
177
|
<tbody>
|
178
|
<tr class="uk-table-middle" *ngFor="let claim of mf2.data let i=index">
|
179
|
<td class="uk-width-1-6" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
|
180
|
<td class="uk-width-1-6" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
|
181
|
<td class="uk-width-1-6 uk-text-center">{{claim.userMail}}</td>
|
182
|
<td class="uk-width-1-6 uk-text-center">{{claim.date}}</td>
|
183
|
<td class="uk-width-1-6 uk-text-center">{{claim.curatedBy}}</td>
|
184
|
<td class="uk-width-1-6 uk-text-center">{{claim.curationDate}}</td>
|
185
|
<td class="uk-width-1-6 uk-text-center">
|
186
|
|
187
|
<label>
|
188
|
Yes <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isRight(claim)"/>
|
189
|
</label>
|
190
|
|
191
|
<label>
|
192
|
No <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isWrong(claim)"/>
|
193
|
</label>
|
194
|
|
195
|
</td>
|
196
|
<!--td><input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" (click)="selectDisapprove(claim.id,$event)" [ngModel]="isWrong(claim)"/></td-->
|
197
|
<!--td><button class="uk-button" (click)="editable.add(i)">Edit</button></td-->
|
198
|
</tr>
|
199
|
</tbody>
|
200
|
<tfoot>
|
201
|
<tr>
|
202
|
<td>
|
203
|
<!--mfBootstrapPaginator></mfBootstrapPaginator-->
|
204
|
</td>
|
205
|
<td></td>
|
206
|
<td></td>
|
207
|
<td></td>
|
208
|
<td></td>
|
209
|
<td>
|
210
|
<paging-no-load [currentPage]="1" [totalResults]="curated_claims.length" [size]="rowsOnPage" (pageChange)="refreshTable(mf2, $event)"> </paging-no-load>
|
211
|
</td>
|
212
|
</tr>
|
213
|
</tfoot>
|
214
|
</table>
|
215
|
|
216
|
</div>
|
217
|
|
218
|
<div class="uk-text-small uk-text-right">*Note that claims you did not approved or disapproved are considered as right (but not curated)</div>
|
219
|
<button class="uk-button uk-button-success uk-float-right" type="button" (click)="saveChanges()">Save Changes</button>
|
220
|
|
221
|
<!--modal-select (alertOutput)="curatorSelected($event)"></modal-select-->
|
222
|
<modal-loading [message]= "'Loading...'"></modal-loading>
|
223
|
</div>
|
224
|
`,
|
225
|
|
226
|
})
|
227
|
export class ClaimsByTokenComponent {
|
228
|
//change true - false to accept: yes - no
|
229
|
public token: string = "";
|
230
|
public sub: any;
|
231
|
public project: any;
|
232
|
private claims:any = [];
|
233
|
public pending_claims: any = [];
|
234
|
public curated_claims: any = [];
|
235
|
public selectedRight: Set<string>;
|
236
|
public selectedWrong: Set<string>;
|
237
|
public editable: Set<string>;
|
238
|
public contact_person: string[] = ["Konstantina", "Argiro", "Katerina"];
|
239
|
|
240
|
// when 'empty' show form to fill email, when 'valid' show proper claims, when 'invalid' show no matched entry-wanna retry
|
241
|
public accessStatus: string;// = "empty";
|
242
|
|
243
|
public rowsOnPage = 5;
|
244
|
public sortOrder = "asc";
|
245
|
|
246
|
|
247
|
@ViewChild (ModalSelect) selectModal : ModalSelect;
|
248
|
@ViewChild (ModalLoading) loading : ModalLoading ;
|
249
|
|
250
|
public routerHelper:RouterHelper = new RouterHelper();
|
251
|
|
252
|
constructor ( private route: ActivatedRoute, private _router:Router, private claimsByTokenService: ClaimsByTokenService ) {
|
253
|
|
254
|
}
|
255
|
ngOnInit() {
|
256
|
this.sub = this.route.queryParams.subscribe(params => {
|
257
|
this.token = params['token'];
|
258
|
this.selectedRight = new Set<string>();
|
259
|
this.selectedWrong = new Set<string>();
|
260
|
this.editable = new Set<string>();
|
261
|
//this.openSelect();
|
262
|
//this.setMessageSelect("Please select your identity:");
|
263
|
//this.setOptionsSelect(this.contact_person);
|
264
|
this.validateJWTandToken();
|
265
|
}
|
266
|
);
|
267
|
}
|
268
|
|
269
|
refreshTable(mf:any, $event:any) {
|
270
|
mf.mfActivePage=$event.value;
|
271
|
mf.setPage(mf.mfActivePage, this.rowsOnPage);
|
272
|
}
|
273
|
|
274
|
public sortByClaimDate1 = (claim: any) => {
|
275
|
return new Date(claim.date);
|
276
|
}
|
277
|
|
278
|
public sortByCurationDate1 = (claim: any) => {
|
279
|
return new Date(claim.curationDate);
|
280
|
}
|
281
|
|
282
|
public sortByTitle1 = (claim: any) => {
|
283
|
if(claim.targetType != 'project') {
|
284
|
return claim.target.title;
|
285
|
} else {
|
286
|
return claim.source.title;
|
287
|
}
|
288
|
}
|
289
|
|
290
|
public sortByClaimDate2 = (claim: any) => {
|
291
|
return new Date(claim.date);
|
292
|
}
|
293
|
|
294
|
public sortByCurationDate2 = (claim: any) => {
|
295
|
console.info(new Date(claim.curationDate));
|
296
|
return new Date(claim.curationDate);
|
297
|
}
|
298
|
|
299
|
public sortByTitle2= (claim: any) => {
|
300
|
if(claim.targetType != 'project') {
|
301
|
return claim.target.title;
|
302
|
} else {
|
303
|
return claim.source.title;
|
304
|
}
|
305
|
}
|
306
|
|
307
|
|
308
|
validateJWTandToken() {
|
309
|
var jwtToken=Session.getUserJwt();
|
310
|
if(this.token) {
|
311
|
this.claimsByTokenService.getClaims(this.token, jwtToken).subscribe(
|
312
|
data => {
|
313
|
this.closeLoading();
|
314
|
this.accessStatus = "valid";
|
315
|
//console.info(data);
|
316
|
this.claims = data.data;
|
317
|
for(let claim of this.claims) {
|
318
|
if(claim.targetType == "project") {
|
319
|
this.project = claim.target;
|
320
|
} else {
|
321
|
this.project = claim.source;
|
322
|
}
|
323
|
if(claim.curatedBy) {
|
324
|
this.curated_claims.push(claim);
|
325
|
} else {
|
326
|
this.pending_claims.push(claim);
|
327
|
}
|
328
|
}
|
329
|
},
|
330
|
err => {
|
331
|
this.accessStatus = "invalid";
|
332
|
console.log(err);
|
333
|
}
|
334
|
);
|
335
|
} else {
|
336
|
this.accessStatus = "invalid";
|
337
|
}
|
338
|
}
|
339
|
|
340
|
selectApprove(id:string, event) {
|
341
|
var value = event.currentTarget.checked;
|
342
|
if(value){
|
343
|
this.selectedRight.add(id);
|
344
|
this.selectedWrong.delete(id);
|
345
|
console.info(this.selectedRight);
|
346
|
}else{
|
347
|
this.selectedRight.delete(id);
|
348
|
console.info(this.selectedRight);
|
349
|
}
|
350
|
}
|
351
|
|
352
|
selectDisapprove(id:string,event) {
|
353
|
var value = event.currentTarget.checked;
|
354
|
if(value){
|
355
|
this.selectedWrong.add(id);
|
356
|
this.selectedRight.delete(id);
|
357
|
}else{
|
358
|
this.selectedWrong.delete(id);
|
359
|
}
|
360
|
}
|
361
|
|
362
|
isSelectedRight(id:string) {
|
363
|
return this.selectedRight.has(id);
|
364
|
}
|
365
|
|
366
|
isSelectedWrong(id:string) {
|
367
|
return this.selectedWrong.has(id);
|
368
|
}
|
369
|
|
370
|
isRight(claim: any) {
|
371
|
//claim.approved = true;
|
372
|
if(this.isSelectedRight(claim.id)) {
|
373
|
return true;
|
374
|
} else if(claim.approved == true && !this.isSelectedWrong(claim.id)) {
|
375
|
return true;
|
376
|
}
|
377
|
|
378
|
return false;
|
379
|
}
|
380
|
|
381
|
isWrong(claim: any) {
|
382
|
if(this.isSelectedWrong(claim.id)) {
|
383
|
return true;
|
384
|
} else if(claim.approved == false && !this.isSelectedRight(claim.id)) {
|
385
|
return true;
|
386
|
}
|
387
|
|
388
|
return false;
|
389
|
}
|
390
|
|
391
|
saveChanges() {
|
392
|
console.info("Changes Saved!");
|
393
|
var jwtToken=Session.getUserJwt();
|
394
|
|
395
|
this.claimsByTokenService.updateClaimsCuration(jwtToken, this.selectedRight, this.selectedWrong).subscribe(
|
396
|
data => {
|
397
|
console.info(data);
|
398
|
},
|
399
|
err => {
|
400
|
console.log(err);
|
401
|
}
|
402
|
);
|
403
|
|
404
|
}
|
405
|
|
406
|
public closeLoading(){
|
407
|
if(this.loading){
|
408
|
this.loading.close();
|
409
|
}
|
410
|
}
|
411
|
|
412
|
curatorSelected(selected: string) {
|
413
|
console.info("selected curator: "+selected);
|
414
|
}
|
415
|
|
416
|
public openSelect(){
|
417
|
if(this.selectModal){
|
418
|
this.selectModal.open();
|
419
|
}
|
420
|
}
|
421
|
|
422
|
public setMessageSelect(message: string){
|
423
|
if(this.selectModal){
|
424
|
this.selectModal.message = message;
|
425
|
}
|
426
|
}
|
427
|
|
428
|
public setOptionsSelect(options: string[]){
|
429
|
if(this.selectModal){
|
430
|
this.selectModal.options = options;
|
431
|
}
|
432
|
}
|
433
|
}
|