/
url-template.component.ts
54 lines (47 loc) · 1.72 KB
/
url-template.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Component, Input, OnInit } from '@angular/core';
import { IUrl } from '@dasch-swiss/dsp-js';
@Component({
selector: 'app-url-template',
template: `
<div *ngIf="urls">
<div *ngIf="templateType === 'string'">
<p *ngFor="let str of urls" class="remove-top-margin"> {{ str }} </p>
</div>
<div *ngIf="templateType === 'IUrl'">
<div class="metadata-property">
<div *ngIf="displayLabel" class="property-label display-inline-block">
{{ label }}:
</div>
<div [ngClass]="{'display-inline-block add-left-margin': displayLabel}">
<span *ngFor="let entry of urls" class="comma">
<a *ngIf="entry.name" href="{{ entry.url }}" target="_blank"> {{ entry.name }} </a>
<a *ngIf="!entry.name" href="{{ entry.url }}" target="_blank"> {{ entry.url }} </a>
</span>
</div>
</div>
</div>
</div>
`
})
export class UrlTemplateComponent implements OnInit {
@Input() urls: IUrl | IUrl[] | string[];
@Input() label = 'URL(s)';
@Input() displayLabel = false;
templateType: string;
ngOnInit() {
if (!(this.urls instanceof Array)) {
this.urls = [this.urls];
}
this.templateType = this.getTemplateType(this.urls[0]);
}
/**
* determine if the object is of type string or IUrl
* @param obj string | IUrl
*/
getTemplateType (obj: IUrl | string): string {
if (typeof obj === 'string') {
return 'string';
}
return 'IUrl';
}
}