Project

General

Profile

1
import {Component, ViewChild} 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 {SearchResult} from "../../../utils/entities/searchResult";
12
import {ResultPreview} from "../../../utils/result-preview/result-preview";
13

    
14
@Component({
15
  selector: 'deletedByInference',
16
  template: `
17
    <errorMessages [status]="[status]" [type]="type" tab_error_class=true></errorMessages>
18
    <no-load-paging *ngIf="results.length > pageSize" [type]="type"
19
                    (pageChange)="updatePage($event)"
20
                    [page]="page" [pageSize]="pageSize"
21
                    [totalResults]="results.length">
22
    </no-load-paging>
23
    <ul class="uk-list uk-list-divider  uk-margin">
24
      <li *ngFor="let result of results.slice((page-1)*pageSize, page*pageSize)">
25
        <result-preview [properties]="properties" [result]="getResultPreview(result)"></result-preview>
26
      </li>
27
    </ul>
28
    <no-load-paging *ngIf="results.length > pageSize" [type]="type"
29
                    (pageChange)="updatePage($event)"
30
                    [page]="page" [pageSize]="pageSize"
31
                    [totalResults]="results.length">
32
    </no-load-paging>
33
  `
34
})
35

    
36
export class DeletedByInferenceComponent {
37
  public results: ResultLandingInfo[] = [];
38
  @Input() id: string;
39
  @Input() ids: string[] = [];
40
  @Input() type: string;
41
  @Input() resultType: string;
42
  
43
  // Custom tab paging variables
44
  public page: number = 1;
45
  public pageSize: number = 5;
46
  
47
  public status: number;
48
  public routerHelper: RouterHelper = new RouterHelper();
49
  public errorCodes: ErrorCodes = new ErrorCodes();
50
  
51
  sub: any;
52
  properties: EnvProperties;
53
  
54
  constructor(private element: ElementRef,
55
              private _deletedByInferenceService: DeletedByInferenceService,
56
              private route: ActivatedRoute,
57
              private _router: Router) {
58
  }
59
  
60
  ngOnInit() {
61
    this.route.data
62
      .subscribe((data: { envSpecific: EnvProperties }) => {
63
        this.properties = data.envSpecific;
64
        
65
      });
66
    this.sub = 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
  }
76
  
77
  getDeletedByInference() {
78
    this.results = [];
79
    this.status = this.errorCodes.LOADING;
80
    /*
81
        if(this.ids) {
82
          var allRequests = [];
83
          for(let id of this.ids) {
84
            allRequests.push(this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties));
85
          }
86
    
87
          zip.apply(null, allRequests).subscribe(
88
         //   this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties).subscribe(
89
             data => {
90
               this.results = data;
91
               this.status = this.errorCodes.DONE;
92
             },
93
             error => {
94
               if(error.status == '404') {
95
                 this.status = this.errorCodes.NOT_FOUND;
96
               } else if(error.status == '500') {
97
                 this.status = this.errorCodes.ERROR;
98
               } else {
99
                 this.status = this.errorCodes.NOT_AVAILABLE;
100
               }
101
             }
102
           );
103
         }
104
     */
105
    this._deletedByInferenceService.getDeletedByInferenceResults(this.id, String(this.ids.length), this.properties).subscribe(
106
      data => {
107
        this.results = data;
108
        this.status = this.errorCodes.DONE;
109
      },
110
      error => {
111
        if (error.status == '404') {
112
          this.status = this.errorCodes.NOT_FOUND;
113
        } else if (error.status == '500') {
114
          this.status = this.errorCodes.ERROR;
115
        } else {
116
          this.status = this.errorCodes.NOT_AVAILABLE;
117
        }
118
      }
119
    );
120
  }
121
  
122
  public getResultPreview(result: ResultLandingInfo): ResultPreview {
123
    return ResultPreview.resultLandingInfoConvert(result, this.resultType);
124
  }
125
  
126
  public totalPages(totalResults: number): number {
127
    let totalPages: any = totalResults / this.pageSize;
128
    if (!(Number.isInteger(totalPages))) {
129
      totalPages = (parseInt(totalPages, this.pageSize) + 1);
130
    }
131
    return totalPages;
132
  }
133
  
134
  public updatePage($event) {
135
    this.page = $event.value;
136
  }
137
}
(1-1/3)