Project

General

Profile

1
import {Component, Input, ElementRef} from '@angular/core';
2

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

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

    
55
    public showAll: boolean = false;
56

    
57
    constructor (private element: ElementRef) {}
58

    
59
    ngOnInit() {}
60

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