]>
Commit | Line | Data |
---|---|---|
b06f1ead | 1 | import { Component, Input, OnChanges } from '@angular/core' |
e8050208 JM |
2 | import { FromNowPipe } from '../angular/from-now.pipe' |
3 | ||
4 | @Component({ | |
5 | selector: 'my-date-toggle', | |
6 | templateUrl: './date-toggle.component.html', | |
67ed6552 | 7 | styleUrls: [ './date-toggle.component.scss' ] |
e8050208 | 8 | }) |
68f6c87a | 9 | export class DateToggleComponent implements OnChanges { |
e8050208 JM |
10 | @Input() date: Date |
11 | @Input() toggled = false | |
12 | ||
13 | dateRelative: string | |
14 | dateAbsolute: string | |
15 | ||
b06f1ead | 16 | constructor (private fromNowPipe: FromNowPipe) { } |
e8050208 | 17 | |
e8050208 JM |
18 | ngOnChanges () { |
19 | this.updateDates() | |
20 | } | |
21 | ||
22 | toggle () { | |
23 | this.toggled = !this.toggled | |
24 | } | |
25 | ||
26 | getTitle () { | |
68f6c87a C |
27 | return this.toggled |
28 | ? this.dateRelative | |
29 | : this.dateAbsolute | |
e8050208 JM |
30 | } |
31 | ||
32 | getContent () { | |
68f6c87a C |
33 | return this.toggled |
34 | ? this.dateAbsolute | |
35 | : this.dateRelative | |
e8050208 JM |
36 | } |
37 | ||
38 | private updateDates () { | |
39 | this.dateRelative = this.fromNowPipe.transform(this.date) | |
68f6c87a | 40 | this.dateAbsolute = this.date.toLocaleDateString() |
e8050208 JM |
41 | } |
42 | } |