Project

General

Profile

1
import {Component, ViewChild, Input} from '@angular/core';
2
import {Location} from '@angular/common';
3
import {Observable}       from 'rxjs/Observable';
4
import {ActivatedRoute, 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
import { Meta} from '../../../angular2-meta';
14
import {ClaimsDatatablePipe} from '../../utils/pipes/claimsDatatable.pipe';
15

    
16
//import {DataTable} from "angular2-datatable";
17

    
18
@Component({
19
    selector: 'claims-project-manager',
20
    template: `
21
    <div id="tm-main" class=" uk-section  uk-margin-small-top tm-middle"   >
22
      <div uk-grid uk-grid>
23
       <div class="tm-main uk-width-1-1@s uk-width-1-1@m  uk-width-1-1@l uk-row-first ">
24
<div class="uk-container">
25
      <!--div *ngIf="accessStatus=='empty'" class="uk-margin-top uk-width-medium-2-3 uk-container-center">
26
        <div class="uk-block uk-block-primary uk-block-large uk-contrast uk-text-center">
27
          <p class="uk-text-large">Please enter your email and then press 'See Claims' button.</p>
28
          <form class="uk-form">
29
            <fieldset data-uk-margin>
30
                <input type="text" placeholder="example@email.com" name="email" [(ngModel)]="email">
31
                <button (click)="validateJWTandToken()" class=" uk-button uk-button-default">See Claims</button>
32
            </fieldset>
33
          </form>
34
        </div>
35
      </div-->
36

    
37
      <div *ngIf="accessStatus=='invalid'" class="uk-margin-top uk-width-medium-2-3 uk-container-center">
38
        <div class="uk-block uk-block-primary uk-block-large uk-contrast uk-text-center">
39
          <!--p class="uk-text-large">Oops! There is no entry for you! Please retry with another email or for another project.</p-->
40
          <!--button (click)="accessStatus='empty'" class=" uk-button uk-button-default">Retry</button-->
41
          <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>
42
        </div>
43
      </div>
44

    
45
      <div *ngIf="accessStatus=='valid'">
46
      <div class="uk-article-title custom-article-title">
47
          Claims Administrator        
48
          <a [queryParams]="routerHelper.createQueryParam('projectId',project['openaireId'])"
49
              routerLinkActive="router-link-active"
50
              routerLink="/search/project" >
51
                {{project['name']}} ({{project['funderName']}})
52
          </a>
53

    
54
        </div>
55
        <h2> Pending Claims</h2>
56

    
57
        <div *ngIf=" pending_claims && pending_claims.length == 0" >
58
          <div class = "uk-alert uk-alert-primary " >No pending claims found.</div>
59
        </div>
60

    
61
        <div class="uk-overflow-container custom-dataTable-content">
62

    
63
          <div  class="uk-width-1-1  uk-margin uk-padding uk-panel  uk-background-muted">
64
            <form class="uk-text-center uk-panel">
65
              <input type="text" class="uk-input uk-width-1-3" placeholder="Type keywords..." aria-describedby="sizing-addon2"  [(ngModel)]="filterQuery"  name="keyword" />
66
            </form>
67
          </div>
68

    
69
          <span *ngIf="pending_claims && pending_claims.length > 0 && totalPendingResults.count > 0">
70
            {{totalPendingResults.count}} pending claims, page {{activePendingPage.page}} of {{totalPages(totalPendingResults.count)}}
71
            <paging-no-load class="uk-float-right" [currentPage]="activePendingPage.page" [totalResults]="totalPendingResults.count" [size]="rowsOnPage" (pageChange)="refreshTable(table1, $event, 'pending')"></paging-no-load>
72
          </span>
73
          <table #filtered1 *ngIf="pending_claims && pending_claims.length > 0" class="uk-table uk-table-striped"
74
                  [mfData]="pending_claims | claimsDatatable : [filterQuery, totalPendingResults, activePendingPage]" #mf1="mfDataTable" [mfRowsOnPage]="rowsOnPage" [mfActivePage]="1">
75
                  <!--[(mfSortBy)]="sortByClaimDate1" (mfSortOrder)="sortOrder"-->
76
            <thead>
77
               <tr>
78
                  <th><mfDefaultSorter [by]="sortByTitle1">Research Result</mfDefaultSorter></th>
79
                  <th class="uk-text-center"><mfDefaultSorter by="userMail">Claimed By</mfDefaultSorter></th>
80
                  <th class="uk-text-center"><mfDefaultSorter [by]="sortByClaimDate1">Claimed Date</mfDefaultSorter></th>
81
                  <th class="uk-text-center">Approve</th>
82
               </tr>
83
            </thead>
84
            <tbody>
85
                <tr class="uk-table-middle" *ngFor="let claim1 of mf1.data">
86
                  <td  class="uk-width-2-5" *ngIf="claim1.targetType != 'project'"><claim-entity [entity]="claim1.target" [type]="claim1.targetType" > </claim-entity></td>
87
                  <td class="uk-width-2-5 uk-text-center" *ngIf="claim1.sourceType != 'project'"><claim-entity [entity]="claim1.source" [type]="claim1.sourceType" > </claim-entity></td>
88
                  <td class="uk-width-1-5 uk-text-center">{{claim1.userMail}}</td>
89
                  <td class="uk-width-1-5 uk-text-center">{{claim1.date}}</td>
90
                  <td class="uk-width-1-5 uk-text-center">
91

    
92
                    <label>
93
                      Yes <input [id]="claim1.id" type="checkbox" (click)="selectApprove(claim1.id,$event)"  [ngModel]="isSelectedRight(claim1.id)"/>
94
                    </label>
95
                    <label>
96
                      No  <input [id]="claim1.id" type="checkbox" (click)="selectDisapprove(claim1.id,$event)"  [ngModel]="isSelectedWrong(claim1.id)"/>
97
                    </label>
98
                  </td>
99
                </tr>
100
            </tbody>
101
          </table>
102
         </div>
103

    
104
         <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>
105
         <button class="uk-button uk-button-primary uk-float-right" type="submit" (click)="saveChanges()">Save Changes</button>
106

    
107
        <h2> Already Curated Claims</h2>
108

    
109
        <div *ngIf=" curated_claims && curated_claims.length == 0" >
110
          <div class = "uk-alert uk-alert-primary " >No curated claims found.</div>
111
        </div>
112

    
113
        <div class="uk-overflow-container custom-dataTable-content">
114

    
115
          <div  class="uk-width-1-1  uk-margin uk-padding uk-panel  uk-background-muted">
116
            <form class="uk-text-center uk-panel">
117
              <input type="text" class="uk-input uk-width-1-3" placeholder="Type keywords..." aria-describedby="sizing-addon2"  [(ngModel)]="filterQuery2"  name="keyword" />
118
            </form>
119
          </div>
120

    
121
          <span *ngIf="curated_claims && curated_claims.length > 0 && totalCuratedResults.count > 0">
122
            {{totalCuratedResults.count}} curated claims, page {{activeCuratedPage.page}} of {{totalPages(totalCuratedResults.count)}}
123
            <paging-no-load class="uk-float-right" [currentPage]="activeCuratedPage.page" [totalResults]="totalCuratedResults.count" [size]="rowsOnPage"  (pageChange)="refreshTable(table2, $event, 'curated')"> </paging-no-load>
124
          </span>
125

    
126
          <table *ngIf="curated_claims && curated_claims.length > 0" class="uk-table uk-table-striped"
127
                        [mfData]="curated_claims | claimsDatatable : [filterQuery2, totalCuratedResults, activeCuratedPage]" #mf2="mfDataTable" [mfRowsOnPage]="rowsOnPage" [mfActivePage]="1">
128
                        <!--[(mfSortBy)]="sortByCurationDate2" [(mfSortOrder)]="sortOrder"-->
129
            <thead>
130
              <!--tr>
131
                <td colspan="6">
132
                  <form class="uk-text-center uk-panel uk-background-muted">
133
                    <input type="text" class="uk-input uk-width-1-3" placeholder="Type keywords..." aria-describedby="sizing-addon2"  [(ngModel)]="filterQuery2"  name="keyword" />
134
                  </form>
135
                </td>
136
              </tr-->
137
              <!--tr>
138
                <td>
139
                  Filter curated claims:
140
                  <input class="uk-input uk-width-1-3" [(ngModel)]="filterQuery2"/>
141
                </td>
142
              </tr-->
143
              <tr>
144
                <th><mfDefaultSorter [by]="sortByTitle1">Research Result</mfDefaultSorter></th>
145
                <!--th>Link to</th-->
146
                <th class="uk-text-center"><mfDefaultSorter by="userMail">Claimed by</mfDefaultSorter></th>
147
                <th class="uk-text-center"><mfDefaultSorter [by]="sortByClaimDate2">Claimed Date</mfDefaultSorter></th>
148
                <th class="uk-text-center"><mfDefaultSorter by="curatedBy">Curated by</mfDefaultSorter></th>
149
                <th class="uk-text-center"><mfDefaultSorter [by]="sortByCurationDate2">Curation Date</mfDefaultSorter></th>
150
                <th class="uk-text-center">Approved</th>
151
              </tr>
152
            </thead>
153
            <tbody>
154
                <tr class="uk-table-middle" *ngFor="let claim of mf2.data let i=index">
155
                  <td class="uk-width-1-6" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
156
                  <td class="uk-width-1-6" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
157
                  <td class="uk-width-1-6 uk-text-center">{{claim.userMail}}</td>
158
                  <td class="uk-width-1-6 uk-text-center">{{claim.date}}</td>
159
                  <td class="uk-width-1-6 uk-text-center">{{claim.curatedBy}}</td>
160
                  <td class="uk-width-1-6 uk-text-center">{{claim.curationDate}}</td>
161
                  <td class="uk-width-1-6 uk-text-center">
162

    
163
                   <label>
164
                      Yes <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isRight(claim)"/>
165
                    </label>
166

    
167
                    <label>
168
                      No  <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isWrong(claim)"/>
169
                    </label>
170

    
171
                  </td>
172
                  <!--td><input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" (click)="selectDisapprove(claim.id,$event)"  [ngModel]="isWrong(claim)"/></td-->
173
                  <!--td><button class="uk-button" (click)="editable.add(i)">Edit</button></td-->
174
                </tr>
175
            </tbody>
176
          </table>
177
        </div>
178

    
179
        <!--modal-select (alertOutput)="curatorSelected($event)"></modal-select-->
180
        <modal-loading [message]= "'Loading...'"></modal-loading>
181
      </div>
182

    
183
</div>
184
</div>
185
</div>
186
</div>
187
    `,
188

    
189
})
190
export class ClaimsByTokenComponent {
191
  public token: string = "";
192
  public sub: any;
193
  public project: any;
194
  private claims:any = [];
195
  public pending_claims: any = [];
196
  public curated_claims: any = [];
197
  public selectedRight: Set<string>;
198
  public selectedWrong: Set<string>;
199
  public editable: Set<string>;
200
  public contact_person: string[] = ["Konstantina", "Argiro", "Katerina"];
201

    
202
  // when 'valid' show proper claims, when 'invalid' show no matched entry-wanna retry
203
  public accessStatus: string;// = "empty";
204

    
205
  public rowsOnPage = 5;
206
  public sortOrder = "asc";
207
  public filterQuery:string = "";
208
  public filterQuery2:string = "";
209

    
210
  public activePendingPage:any = {page: 1};
211
  public totalPendingResults:any = {count: 0};
212
  public activeCuratedPage:any = {page: 1};
213
  public totalCuratedResults:any = {count: 0};
214

    
215

    
216
  @ViewChild('mf1') table1: any;//DataTable;
217
  @ViewChild('mf2') table2: any;//DataTable;
218
  @ViewChild('filtered1') filteredItems1;
219

    
220

    
221
  @ViewChild (ModalSelect) selectModal : ModalSelect;
222
  @ViewChild (ModalLoading) loading : ModalLoading ;
223

    
224
  public routerHelper:RouterHelper = new RouterHelper();
225

    
226
  constructor ( private route: ActivatedRoute, private claimsByTokenService: ClaimsByTokenService, private _meta: Meta) {
227

    
228
  }
229
  ngOnInit() {
230
    this.sub =  this.route.queryParams.subscribe(params => {
231
        this.token = params['token'];
232
        this.selectedRight = new Set<string>();
233
        this.selectedWrong = new Set<string>();
234
        this.editable = new Set<string>();
235
        //this.openSelect();
236
        //this.setMessageSelect("Please select your identity:");
237
        //this.setOptionsSelect(this.contact_person);
238
        this.validateJWTandToken();
239
        this.updateTitle("Claims For Project Managers");
240
      }
241
    );
242
  }
243

    
244
refreshTable(table:any, $event:any, whichTable: string) {
245
  if(whichTable == "pending") {
246
    this.activePendingPage.page = $event.value;
247
  } else if(whichTable == 'curated') {
248
    this.activeCuratedPage.page = $event.value;
249
  }
250
  table.mfActivePage=$event.value;
251
  table.setPage(table.mfActivePage, this.rowsOnPage);
252
}
253

    
254
public sortByClaimDate1 = (claim: any) => {
255
  return new Date(claim.date);
256
}
257

    
258
public sortByCurationDate1 = (claim: any) => {
259
  return new Date(claim.curationDate);
260
}
261

    
262
public sortByTitle1 = (claim: any) => {
263
  if(claim.targetType != 'project') {
264
    return claim.target.title;
265
  } else {
266
    return claim.source.title;
267
  }
268
}
269

    
270
public sortByClaimDate2 = (claim: any) => {
271
  return new Date(claim.date);
272
}
273

    
274
public sortByCurationDate2 = (claim: any) => {
275
  console.info(new Date(claim.curationDate));
276
  return new Date(claim.curationDate);
277
}
278

    
279
public sortByTitle2= (claim: any) => {
280
  if(claim.targetType != 'project') {
281
    return claim.target.title;
282
  } else {
283
    return claim.source.title;
284
  }
285
}
286

    
287

    
288
  validateJWTandToken() {
289
    var jwtToken=Session.getUserJwt();
290
    if(this.token) {
291
      this.claimsByTokenService.getClaims(this.token, jwtToken).subscribe(
292
          data => {
293
            this.closeLoading();
294
            this.accessStatus = "valid";
295
              //console.info(data);
296
              this.claims = data.data;
297
              for(let claim of this.claims) {
298
                if(claim.targetType == "project") {
299
                  this.project = claim.target;
300
                } else {
301
                  this.project = claim.source;
302
                }
303
                if(claim.curatedBy) {
304
                  this.curated_claims.push(claim);
305
                } else {
306
                  this.pending_claims.push(claim);
307
                }
308
              }
309

    
310
              this.totalPendingResults.count = this.pending_claims.length;
311
              this.totalCuratedResults.count = this.curated_claims.length;
312

    
313
              this.updateTitle("Claims For Project Managers - "+this.project.name);
314
          },
315
          err => {
316
              this.accessStatus = "invalid";
317
              console.log(err);
318
          }
319
        );
320
      } else {
321
        this.accessStatus = "invalid";
322
      }
323
  }
324

    
325
  selectApprove(id:string, event) {
326
    var value = event.currentTarget.checked;
327
    if(value){
328
      this.selectedRight.add(id);
329
      this.selectedWrong.delete(id);
330
      console.info(this.selectedRight);
331
    }else{
332
      this.selectedRight.delete(id);
333
      console.info(this.selectedRight);
334
    }
335
  }
336

    
337
  selectDisapprove(id:string,event) {
338
    var value = event.currentTarget.checked;
339
    if(value){
340
      this.selectedWrong.add(id);
341
      this.selectedRight.delete(id);
342
    }else{
343
      this.selectedWrong.delete(id);
344
    }
345
  }
346

    
347
  isSelectedRight(id:string) {
348
    return this.selectedRight.has(id);
349
  }
350

    
351
  isSelectedWrong(id:string) {
352
    return this.selectedWrong.has(id);
353
  }
354

    
355
  isRight(claim: any) {
356
    //claim.approved = true;
357
    if(this.isSelectedRight(claim.id)) {
358
      return true;
359
    } else if(claim.approved == true && !this.isSelectedWrong(claim.id)) {
360
      return true;
361
    }
362

    
363
    return false;
364
  }
365

    
366
  isWrong(claim: any) {
367
    if(this.isSelectedWrong(claim.id)) {
368
      return true;
369
    } else if(claim.approved == false && !this.isSelectedRight(claim.id)) {
370
      return true;
371
    }
372

    
373
    return false;
374
  }
375

    
376
  saveChanges() {
377
    console.info("Changes Saved!");
378
    var jwtToken=Session.getUserJwt();
379

    
380
    this.claimsByTokenService.updateClaimsCuration(this.selectedRight, this.selectedWrong).subscribe(
381
        data => {
382
            console.info(data);
383
        },
384
        err => {
385
            console.log(err);
386
        }
387
      );
388

    
389
  }
390

    
391
  public closeLoading(){
392
    if(this.loading){
393
      this.loading.close();
394
    }
395
  }
396

    
397
  curatorSelected(selected: string) {
398
    console.info("selected curator: "+selected);
399
  }
400

    
401
  public openSelect(){
402
    if(this.selectModal){
403
      this.selectModal.open();
404
    }
405
  }
406

    
407
  public setMessageSelect(message: string){
408
    if(this.selectModal){
409
      this.selectModal.message = message;
410
    }
411
  }
412

    
413
  public setOptionsSelect(options: string[]){
414
    if(this.selectModal){
415
      this.selectModal.options = options;
416
    }
417
  }
418

    
419
  totalPages(totalResults: number): number {
420
      let totalPages:any = totalResults/(this.rowsOnPage);
421
      if(!(Number.isInteger(totalPages))) {
422
          totalPages = (parseInt(totalPages, 10) + 1);
423
      }
424
      return totalPages;
425
  }
426

    
427
  updateTitle(title:string){
428
    var _prefix ="OpenAIRE | ";
429
    var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
430
    this._meta.setTitle(_title );
431
  }
432

    
433
}
(2-2/4)