"git@version.helsinki.fi:hugg/douar-wsmp.git" did not exist on "2ad5e970b00d5ed3c030f59107b23e13348b1787"
Newer
Older
export interface TagValue {
name: string;
}
import {Component, Element, h, Listen, Prop, Watch} from '@stencil/core';
import {CourseVariants} from '../../../utils/utils';
let keys = {
enter: 'Enter',
};
@Component({
tag: 'hy-content-list-item',
styleUrl: 'hy-content-list-item.scss',
shadow: true,
})
export class HyContentLstItem {
@Prop() variant: CourseVariants = CourseVariants.default;
@Prop() courseCode?: string;
@Prop() courseName?: string;
@Prop() courseCredits?: string;
private _courseTags: TagValue[];
@Prop() courseTags: TagValue[] | string;
@Prop() courseStartDate?: string;
@Prop() courseEndDate?: string;
@Prop() courseStudyFormat?: string;
druid
committed
@Prop() courseOrganisation?: string;
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@Prop() courseEnrollmentLink?: string;
@Prop() courseTeachingLanguage?: string;
@Prop() courseLinkLabel?: string;
private _dateValue: string = '';
@Element() el: HTMLElement;
@Watch('courseTags')
arrayDataWatcher(newValue: TagValue[] | string) {
if (typeof newValue === 'string') {
this._courseTags = JSON.parse(newValue);
} else {
this._courseTags = newValue;
}
}
componentWillLoad() {
this.arrayDataWatcher(this.courseTags);
// Convert to date format: 25.05. - 30.07.2020. Incoming date is in format YYYY-MM-DD
let startDate = this.courseStartDate ? this.courseStartDate.split(/\-|\s/) : '';
let endDate = this.courseEndDate ? this.courseEndDate.split(/\-|\s/) : '';
if (!startDate && endDate) {
this._dateValue = ` - ${endDate[2]}.${endDate[1]}.${endDate[0]}`;
} else if (startDate && !endDate) {
this._dateValue = `${startDate[2]}.${startDate[1]}. - `;
} else if (startDate && endDate) {
this._dateValue = `${startDate[2]}.${startDate[1]}. - ${endDate[2]}.${endDate[1]}.${endDate[0]}`;
}
}
@Listen('keydown')
handleKeyDown(event) {
const key = (event as KeyboardEvent).code;
if (key == keys.enter) {
let card = this.el;
window.open(card.dataset.location, '_blank');
}
}
render() {
const classAttributes = [this.variant, 'hy-content-list-item'].join(' ');
const target = '_blank';
const ariaLabel = 'Link points outside the current website.';
return [
<div class={classAttributes} tabindex="0">
<div class="hy-content-list-item--item-name">{this.courseName}</div>
<div class="hy-content-list-item--metadata">
<div class="hy-content-list-item--metadata--item hy-content-list-item--metadata--item--first">
<span>{this._dateValue}</span>
</div>
druid
committed
{this.courseOrganisation
? [
<div class="hy-content-list-item--metadata--item">
<span>{this.courseStudyFormat}</span>
</div>,
<div class="hy-content-list-item--metadata--item hy-content-list-item--metadata--item--last">
<span>{this.courseOrganisation}</span>
</div>,
]
: [
<div class="hy-content-list-item--metadata--item hy-content-list-item--metadata--item--last">
<span>{this.courseStudyFormat}</span>
</div>,
]}
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<div class="hy-content-list-item--tags">
{this._courseTags.map((x) => {
return <hy-tag>{x.name}</hy-tag>;
})}
</div>
)}
<div class="hy-content-list-item--link">
<a
href={this.courseEnrollmentLink}
target={target}
aria-label={ariaLabel}
class="hy-content-list-item--link--link"
tabindex="-1"
>
<span class="label">{this.courseLinkLabel}</span>
<span class="icon-wrapper">
<div class="icon">
<hy-icon icon={'hy-icon-arrow-to-right'} size={40} />
</div>
</span>
</a>
</div>
</div>,
];
}
}