Project

General

Profile

1
import {Component, Input, ElementRef} from '@angular/core';
2
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
3

    
4
@Component({
5
    selector: 'publishedIn',
6
    template: `
7
      <dl class="uk-description-list-line">
8
        <dt class="title">Published in</dt>
9
        <dd class="line" *ngFor="let key of getKeys(publishedIn) let i=index">
10
          <div *ngIf="i<5 || showAll" class="{{publishedIn.get(key)['bestAccessMode']}}">
11
            <span [class]="publishedIn.get(key)['url'].length > 0 ? 'custom-external custom-icon' : ''">
12
              <span *ngIf="publishedIn.get(key)['url'].length > 1">
13
                {{key}}
14
                <span *ngFor="let url of publishedIn.get(key)['url']; let i=index">
15
                  <a  href="{{url}}" target="_blank"
16
                      [attr.uk-tooltip]="publishedIn.get(key)['accessMode'][i] ? 'pos:right; delay:10' : 'cls: uk-invisible'"
17
                      [title]="publishedIn.get(key)['accessMode'][i]">
18
                    [{{i+1}}]
19
                  </a>
20
                </span>
21
              </span>
22
              <a *ngIf="publishedIn.get(key)['url'].length == 1"
23
                  href="{{publishedIn.get(key)['url']}}"
24
                  target="_blank"
25
                  [attr.uk-tooltip]="publishedIn.get(key)['bestAccessMode'] ? 'pos:right; delay:10' : 'cls: uk-invisible'"
26
                  [title]="publishedIn.get(key)['bestAccessMode']">
27
                {{key}}
28
              </a>
29
              <span *ngIf="publishedIn.get(key)['url'].length == 0"
30
                    [attr.uk-tooltip]="publishedIn.get(key)['bestAccessMode'] ? 'pos:right; delay:10' : 'cls: uk-invisible'"
31
                    [title]="publishedIn.get(key)['bestAccessMode']">
32
                {{key}}
33
              </span>
34
            </span>
35
          </div>
36
        </dd>
37
        <dd *ngIf="showAll" class="uk-text-right">
38
          <a class="uk-text-muted" (click)="showAll = !showAll; scroll()">
39
            View less
40
          </a>
41
        </dd>
42
        <dd *ngIf="!showAll && publishedIn.size > 5">...</dd>
43
        <dd *ngIf="!showAll && publishedIn.size > 5" class="uk-text-right">
44
          <a class="uk-text-muted" (click)="showAll = !showAll;">
45
            View more
46
          </a>
47
        </dd>
48
      </dl>
49
    `
50
    })
51

    
52
export class PublishedInComponent {
53
    //key is name
54
    @Input() publishedIn: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>;
55

    
56
    public showAll: boolean = false;
57

    
58
    constructor (private element: ElementRef) {}
59

    
60
    ngOnInit() {}
61

    
62
    public scroll() {
63
      console.info("scroll into view");
64
      if (typeof document !== 'undefined') {
65
         this.element.nativeElement.scrollIntoView();
66
      }
67
    }
68
    public getKeys( map) {
69
      return Array.from(map.keys());
70
    }
71
}
(8-8/17)