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 {Observable}                   from 'rxjs';
6

    
7
import {EnvProperties}                from '../../../utils/properties/env-properties';
8
import {DeletedByInferenceResult}     from '../../../utils/entities/deletedByInferenceResult';
9
import {RouterHelper}                 from '../../../utils/routerHelper.class';
10
import {ErrorCodes}                   from '../../../utils/properties/errorCodes';
11

    
12
import {DeletedByInferenceService}    from './deletedByInference.service';
13

    
14
import {zip} from 'rxjs';
15

    
16

    
17
@Component({
18
    selector: 'deletedByInference',
19
    template: `
20
    <errorMessages [status]="[status]" [type]="type" tab_error_class=true></errorMessages>
21

    
22
    <div>
23
      <div *ngIf="results.length > pageSize" class="uk-margin-bottom">
24
        <span class="uk-h6">{{results.length | number}} {{type}}, page {{page | number}} of {{totalPages(results.length) | number}}</span>
25
        <paging-no-load class="uk-float-right" [currentPage]="page" [totalResults]="results.length" [size]="pageSize" (pageChange)="updatePage($event)"></paging-no-load>
26
      </div>
27

    
28
      <ul class="uk-list uk-list-divider  uk-margin">
29
        <li *ngFor="let result of results.slice((page-1)*pageSize, page*pageSize)">
30
          <h5 *ngIf="result.title" class="uk-margin-remove-bottom">
31
            <span [innerHTML]="result.title"></span>
32
          </h5>
33
          <h5 *ngIf="!result.title">
34
            <span>[no title available]</span>
35
          </h5>
36

    
37
          <span *ngIf="result.types && result.types.length > 0"class="uk-label custom-label label-blue label-publication" title="Type">{{result.types.join(", ")}}</span>{{" "}}
38
          <span *ngIf="result.languages && result.languages.length > 0" class="uk-label custom-label  label-language " title="Language">{{result.languages.join(", ")}}</span>{{" "}}
39
          <span *ngIf="result.countries && result.countries.length > 0" class="uk-label custom-label  label-country " title="Country">{{result.countries.join(", ")}}</span>{{" "}}
40
          <span *ngIf="result.accessMode" [class]="'uk-label custom-label  label-'+ result.accessMode " title="Access Mode">{{result.accessMode}}</span>{{" "}}
41

    
42
          <div>
43
              <showAuthors [authors]="result.authors"></showAuthors>
44
              <span *ngIf="result.date != ''">({{result.date}})</span>
45
          </div>
46

    
47
          <div *ngIf="result.identifiers && result.identifiers.size > 0">
48
            <showIdentifiers [identifiers]="result.identifiers"></showIdentifiers>
49
          </div>
50

    
51
          <div *ngIf="result['fundedByProjects'] != undefined">
52
              <span class="uk-text-bold"> Project: </span>
53
              <span *ngFor="let project of result['fundedByProjects'].slice(0,15) let i=index">
54
                  {{project['funderShortname']?project['funderShortname']:project['funderName']}}
55
                    | {{ project['acronym']?project['acronym']:(project['title'].length>25?project['title'].substring(0,25)+'...':project['title'])}} ({{project.code}})<span
56

    
57
                  *ngIf="!project.id">{{project['funderShortname']?project['funderShortname']:project['funderName']}}<span
58
                  *ngIf="project['acronym'] || project['title']"> | {{ project['acronym']?project['acronym']:(project['title'].length>25?project['title'].substring(0,25)+'...':project['title'])}}</span><span
59
                  *ngIf="project.code">({{project.code}})</span></span><span
60

    
61
              *ngIf="i < result['fundedByProjects'].length-1">,</span>
62
              </span>
63
              <span *ngIf="result['fundedByProjects'].length > 15">...</span>
64
          </div>
65

    
66
          <!--div class="uk-margin-top" *ngIf="result.hostedBy_collectedFrom && result.hostedBy_collectedFrom.length > 0">
67
              <availableOn [availableOn]="result.hostedBy_collectedFrom"></availableOn>
68
          </div-->
69

    
70
          <div *ngIf="result.hostedBy_collectedFrom != undefined">
71
            <span class="uk-text-bold"> Collected From: </span>
72
            <span *ngFor="let available of result.hostedBy_collectedFrom let i=index">
73
              <span *ngIf="available.downloadUrl.length > 1"
74
                    class="custom-external custom-icon">
75
                    {{available.downloadName}}
76
                <span *ngFor="let url of available.downloadUrl; let i=index;">
77
                    <a  href="{{url}}" target="_blank"
78
                        attr.uk-tooltip="pos:right; delay:10">
79
                        [{{(i+1) | number}}]
80
                    </a>
81
                </span>
82
              </span><a
83
              class="custom-external custom-icon"
84
                  *ngIf="available['downloadUrl'].length == 1"
85
                  href="{{available['downloadUrl']}}"
86
                  target="_blank"
87
                  attr.uk-tooltip="pos:right; delay:10">
88
                  {{available.downloadName}}</a><span
89
              *ngIf="i < result['hostedBy_collectedFrom'].length-1">,</span>
90
            </span>
91
            <span *ngIf="result['hostedBy_collectedFrom'].length > 15">...</span>
92
          </div>
93

    
94
          <div *ngIf="result.description" class="uk-margin-bottom uk-text-justify descriptionText">
95
            {{result.description}}
96
          </div>
97

    
98

    
99

    
100
        </li>
101
      </ul>
102
    </div>
103
    `
104
})
105

    
106
export class DeletedByInferenceComponent {
107
  public results: DeletedByInferenceResult[] = [];
108
  @Input() id: string;
109
  @Input() ids: string[] = [];
110
  @Input() type: string;
111

    
112
  // Custom tab paging variables
113
  public page: number = 1;
114
  public pageSize: number = 10;
115

    
116
  public status: number;
117
  public routerHelper:RouterHelper = new RouterHelper();
118
  public errorCodes:ErrorCodes = new ErrorCodes();
119

    
120
  sub: any;
121
  properties:EnvProperties;
122

    
123
  constructor ( private element: ElementRef,
124
                private _deletedByInferenceService: DeletedByInferenceService,
125
                private route: ActivatedRoute,
126
                private _router: Router) {
127
  }
128

    
129
  ngOnInit() {
130
    this.route.data
131
      .subscribe((data: { envSpecific: EnvProperties }) => {
132
         this.properties = data.envSpecific;
133

    
134
      });
135
       this.sub =  this.route.queryParams.subscribe(data => {
136
         this.errorCodes = new ErrorCodes();
137
         this.status = this.errorCodes.LOADING;
138

    
139
         this.getDeletedByInference();
140
    });
141
  }
142

    
143
  ngOnDestroy() {}
144

    
145
  getDeletedByInference() {
146
    this.results = [];
147
    this.status = this.errorCodes.LOADING;
148

    
149
    if(this.ids) {
150
      var allRequests = [];
151
      for(let id of this.ids) {
152
        allRequests.push(this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties));
153
      }
154

    
155
      zip.apply(null, allRequests).subscribe(
156
     //   this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties).subscribe(
157
         data => {
158
           this.results = data;
159
           this.status = this.errorCodes.DONE;
160
         },
161
         error => {
162
           if(error.status == '404') {
163
             this.status = this.errorCodes.NOT_FOUND;
164
           } else if(error.status == '500') {
165
             this.status = this.errorCodes.ERROR;
166
           } else {
167
             this.status = this.errorCodes.NOT_AVAILABLE;
168
           }
169
         }
170
       );
171
     }
172
  }
173

    
174
  public totalPages(totalResults: number): number {
175
    let totalPages:any = totalResults/this.pageSize;
176
    if(!(Number.isInteger(totalPages))) {
177
        totalPages = (parseInt(totalPages, this.pageSize) + 1);
178
    }
179
    return totalPages;
180
  }
181

    
182
  public updatePage($event) {
183
    this.page = $event.value;
184
  }
185
}
(1-1/3)