Allow to toggle video publication date to display absolute date
authorJulien Maulny <julien.maulny@protonmail.com>
Sat, 5 Oct 2019 16:10:49 +0000 (18:10 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Wed, 23 Oct 2019 08:47:34 +0000 (10:47 +0200)
client/src/app/shared/date/date-toggle.component.html [new file with mode: 0644]
client/src/app/shared/date/date-toggle.component.scss [new file with mode: 0644]
client/src/app/shared/date/date-toggle.component.ts [new file with mode: 0644]
client/src/app/shared/shared.module.ts
client/src/app/shared/video/video-miniature.component.html
client/src/app/videos/+video-watch/video-watch.component.html

diff --git a/client/src/app/shared/date/date-toggle.component.html b/client/src/app/shared/date/date-toggle.component.html
new file mode 100644 (file)
index 0000000..ebd4ce4
--- /dev/null
@@ -0,0 +1,6 @@
+<span
+  class="date-toggle"
+  [title]="getTitle()"
+  [innerHtml]="getContent()"
+  (click)="toggle()"
+></span>
diff --git a/client/src/app/shared/date/date-toggle.component.scss b/client/src/app/shared/date/date-toggle.component.scss
new file mode 100644 (file)
index 0000000..86700d1
--- /dev/null
@@ -0,0 +1,5 @@
+.date-toggle {
+  &:hover {
+    cursor: default
+  }
+}
diff --git a/client/src/app/shared/date/date-toggle.component.ts b/client/src/app/shared/date/date-toggle.component.ts
new file mode 100644 (file)
index 0000000..fa48da8
--- /dev/null
@@ -0,0 +1,47 @@
+import { Component, Input, OnInit, OnChanges } from '@angular/core'
+import { DatePipe } from '@angular/common'
+import { FromNowPipe } from '../angular/from-now.pipe'
+
+@Component({
+  selector: 'my-date-toggle',
+  templateUrl: './date-toggle.component.html',
+  styleUrls: [ './date-toggle.component.scss' ],
+  providers: [ DatePipe, FromNowPipe ]
+})
+export class DateToggleComponent implements OnInit, OnChanges {
+  @Input() date: Date
+  @Input() toggled = false
+
+  dateRelative: string
+  dateAbsolute: string
+
+  constructor (
+    private datePipe: DatePipe,
+    private fromNowPipe: FromNowPipe
+  ) { }
+
+  ngOnInit () {
+    this.updateDates()
+  }
+
+  ngOnChanges () {
+    this.updateDates()
+  }
+
+  toggle () {
+    this.toggled = !this.toggled
+  }
+
+  getTitle () {
+    return this.toggled ? this.dateRelative : this.dateAbsolute
+  }
+
+  getContent () {
+    return this.toggled ? this.dateAbsolute : this.dateRelative
+  }
+
+  private updateDates () {
+    this.dateRelative = this.fromNowPipe.transform(this.date)
+    this.dateAbsolute = this.datePipe.transform(this.date, 'long')
+  }
+}
index f6991a66da8ccfb5ef4b56b9ac71f9f92a800cf0..8cbb15bfaf955ecb1ca66e5dc914ab03fb65e4d6 100644 (file)
@@ -73,6 +73,7 @@ import { UserNotificationsComponent } from '@app/shared/users/user-notifications
 import { InstanceService } from '@app/shared/instance/instance.service'
 import { HtmlRendererService, LinkifierService, MarkdownService } from '@app/shared/renderer'
 import { ConfirmComponent } from '@app/shared/confirm/confirm.component'
+import { DateToggleComponent } from '@app/shared/date/date-toggle.component'
 import { SmallLoaderComponent } from '@app/shared/misc/small-loader.component'
 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
 import { PreviewUploadComponent } from '@app/shared/images/preview-upload.component'
@@ -165,6 +166,7 @@ import { FeatureBooleanComponent } from '@app/shared/instance/feature-boolean.co
     TopMenuDropdownComponent,
     UserNotificationsComponent,
     ConfirmComponent,
+    DateToggleComponent,
 
     GlobalIconComponent,
     PreviewUploadComponent
@@ -232,6 +234,7 @@ import { FeatureBooleanComponent } from '@app/shared/instance/feature-boolean.co
     TopMenuDropdownComponent,
     UserNotificationsComponent,
     ConfirmComponent,
+    DateToggleComponent,
 
     GlobalIconComponent,
     PreviewUploadComponent,
index 5d5691b7573d20546f1fbd73e0ce5f2a03be57ca..abd193bb193874c720618778aba3334c5ea22fda 100644 (file)
@@ -17,7 +17,7 @@
       </a>
 
       <span class="video-miniature-created-at-views">
-        <ng-container *ngIf="displayOptions.date">{{ video.publishedAt | myFromNow }}</ng-container>
+        <my-date-toggle *ngIf="displayOptions.date" [date]="video.publishedAt"></my-date-toggle>
         <ng-container *ngIf="displayOptions.date && displayOptions.views"> - </ng-container>
         <ng-container i18n *ngIf="displayOptions.views">{{ video.views | myNumberFormatter }} views</ng-container>
       </span>
index cd60c407f1e43ffc17be413f9988eecfc796eeee..68f284be3be1ab986b7f3c7b407d3483f6741b51 100644 (file)
@@ -42,7 +42,7 @@
           <div class="d-block d-md-none"> <!-- only shown on medium devices, has its conterpart for larger viewports below -->
             <h1 class="video-info-name">{{ video.name }}</h1>
             <div i18n class="video-info-date-views">
-              Published {{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views
+              Published <my-date-toggle [date]="video.publishedAt"></my-date-toggle> - {{ video.views | myNumberFormatter }} views
             </div>
           </div>
 
@@ -51,7 +51,7 @@
               <h1 class="video-info-name">{{ video.name }}</h1>
 
               <div i18n class="video-info-date-views">
-                Published {{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views
+                Published <my-date-toggle [date]="video.publishedAt"></my-date-toggle> - {{ video.views | myNumberFormatter }} views
               </div>
             </div>