Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ElementRef, Input} from '@angular/core';
3
import {ActivatedRoute, Router} from '@angular/router';
4

    
5
import {EnvProperties} from '../../../utils/properties/env-properties';
6
import {ResultLandingInfo} from '../../../utils/entities/resultLandingInfo';
7
import {RouterHelper} from '../../../utils/routerHelper.class';
8
import {ErrorCodes} from '../../../utils/properties/errorCodes';
9

    
10
import {DeletedByInferenceService} from './deletedByInference.service';
11
import {ResultPreview} from "../../../utils/result-preview/result-preview";
12
import {AlertModal} from "../../../utils/modal/alert";
13
import {Subscriber} from "rxjs";
14
import {properties} from "../../../../../environments/environment";
15

    
16
@Component({
17
  selector: 'deletedByInference',
18
  template: `
19
    <errorMessages [status]="[status]" [type]="type" tab_error_class=true></errorMessages>
20
    <no-load-paging *ngIf="results.length > pageSize" [type]="type"
21
                    (pageChange)="updatePage($event)"
22
                    [page]="page" [pageSize]="pageSize"
23
                    [totalResults]="results.length">
24
    </no-load-paging>
25
    <ul class="uk-list uk-list-divider  uk-margin">
26
      <li *ngFor="let result of results.slice((page-1)*pageSize, page*pageSize)">
27
        <result-preview [modal]="modal" [properties]="properties" [hasLink]="false" [result]="getResultPreview(result)" [showOrcid]="false"></result-preview>
28
      </li>
29
    </ul>
30
    <no-load-paging *ngIf="results.length > pageSize" [type]="type"
31
                    (pageChange)="updatePage($event)"
32
                    [page]="page" [pageSize]="pageSize"
33
                    [totalResults]="results.length">
34
    </no-load-paging>
35
  `
36
})
37
export class DeletedByInferenceComponent {
38
  public results: ResultLandingInfo[] = [];
39
  @Input() id: string;
40
  @Input() ids: string[] = [];
41
  @Input() type: string;
42
  @Input() resultType: string;
43
  @Input() modal: AlertModal;
44
  
45
  // Custom tab paging variables
46
  public page: number = 1;
47
  public pageSize: number = 5;
48
  
49
  public status: number;
50
  public routerHelper: RouterHelper = new RouterHelper();
51
  public errorCodes: ErrorCodes = new ErrorCodes();
52
  
53
  subscriptions = [];
54
  properties: EnvProperties;
55
  
56
  constructor(private element: ElementRef,
57
              private _deletedByInferenceService: DeletedByInferenceService,
58
              private route: ActivatedRoute) {
59
  }
60
  
61
  ngOnInit() {
62

    
63
        this.properties = properties;
64
        
65

    
66
    this.subscriptions.push(this.route.queryParams.subscribe(data => {
67
      this.errorCodes = new ErrorCodes();
68
      this.status = this.errorCodes.LOADING;
69
      
70
      this.getDeletedByInference();
71
    }));
72
  }
73

    
74
  ngOnDestroy() {
75
    this.subscriptions.forEach(subscription => {
76
      if (subscription instanceof Subscriber) {
77
        subscription.unsubscribe();
78
      }
79
    });
80
  }
81
  
82
  getDeletedByInference() {
83
    this.results = [];
84
    this.status = this.errorCodes.LOADING;
85
    this.subscriptions.push(this._deletedByInferenceService.getDeletedByInferenceResults(this.id, String(this.ids.length), this.properties).subscribe(
86
      data => {
87
        this.results = data;
88
        this.status = this.errorCodes.DONE;
89
      },
90
      error => {
91
        if (error.status == '404') {
92
          this.status = this.errorCodes.NOT_FOUND;
93
        } else if (error.status == '500') {
94
          this.status = this.errorCodes.ERROR;
95
        } else {
96
          this.status = this.errorCodes.NOT_AVAILABLE;
97
        }
98
      }
99
    ));
100
  }
101
  
102
  public getResultPreview(result: ResultLandingInfo): ResultPreview {
103
    return ResultPreview.resultLandingInfoConvert(result, this.resultType);
104
  }
105
  
106
  public totalPages(totalResults: number): number {
107
    let totalPages: any = totalResults / this.pageSize;
108
    if (!(Number.isInteger(totalPages))) {
109
      totalPages = (parseInt(totalPages, this.pageSize) + 1);
110
    }
111
    return totalPages;
112
  }
113
  
114
  public updatePage($event) {
115
    this.page = $event.value;
116
  }
117
}
(1-1/3)