F: season page: add mark episode/season as watched
This commit is contained in:
1 parent
30ad2fbf03
commit
09cd4b205a
13 files changed
+185
-61
No files matched your search
+7
-7
@@ -5,7 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
import { EpisodeSeenDto } from '../../../shared/models/dtos/episode-seen.dto';
|
||||
import { EpisodeSeenCreateDto } from '../../../shared/models/dtos/episode-seen.dto';
|
||||
|
||||
import { UserCollectionsModalComponent } from '../../../shared/components/modals/list-selection-modal/user-collections-modal.component';
|
||||
import { SeenModalComponent } from '../../../shared/components/modals/seen-modal/seen-modal.component';
|
||||
@@ -451,7 +451,7 @@ export class AlternateEntryPageComponent implements OnInit {
|
||||
|
||||
this.episodeSeenService.getEpisodeSeenByEntryId(this.entry.id).subscribe({
|
||||
next: (data) => {
|
||||
let episodeSeens = [] as EpisodeSeenDto[];
|
||||
let episodeSeens = [] as EpisodeSeenCreateDto[];
|
||||
|
||||
// mapping
|
||||
data.forEach((item) => {
|
||||
@@ -469,7 +469,7 @@ export class AlternateEntryPageComponent implements OnInit {
|
||||
|
||||
createdAt: item.createdAt,
|
||||
updatedAt: item.updatedAt,
|
||||
} as EpisodeSeenDto;
|
||||
} as EpisodeSeenCreateDto;
|
||||
|
||||
episodeSeens.push(e);
|
||||
});
|
||||
@@ -479,7 +479,7 @@ export class AlternateEntryPageComponent implements OnInit {
|
||||
this.filterEpisodesSeenHistory();
|
||||
},
|
||||
error: (error) => {
|
||||
this.seenHistory = [] as EpisodeSeenDto[];
|
||||
this.seenHistory = [] as EpisodeSeenCreateDto[];
|
||||
this.filterEpisodesSeenHistory();
|
||||
console.log(`Error getting episodes watch history`, error);
|
||||
},
|
||||
@@ -488,7 +488,7 @@ export class AlternateEntryPageComponent implements OnInit {
|
||||
|
||||
// ? filter episode seen history
|
||||
filterEpisodesSeenHistory() {
|
||||
var temp = [] as EpisodeSeenDto[];
|
||||
var temp = [] as EpisodeSeenCreateDto[];
|
||||
|
||||
temp = this.seenHistory;
|
||||
|
||||
@@ -543,7 +543,7 @@ export class AlternateEntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
editEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
||||
editEpisodeSeen(episodeSeen: EpisodeSeenCreateDto) {
|
||||
if (episodeSeen == null) return;
|
||||
|
||||
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
|
||||
@@ -563,7 +563,7 @@ export class AlternateEntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
deleteEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
||||
deleteEpisodeSeen(episodeSeen: EpisodeSeenCreateDto) {
|
||||
if (episodeSeen.id == null) return;
|
||||
|
||||
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
import { EpisodeSeenDto } from '../../../shared/models/dtos/episode-seen.dto';
|
||||
import { EpisodeSeenCreateDto } from '../../../shared/models/dtos/episode-seen.dto';
|
||||
|
||||
import { UserCollectionsModalComponent } from '../../../shared/components/modals/list-selection-modal/user-collections-modal.component';
|
||||
import { SeenModalComponent } from '../../../shared/components/modals/seen-modal/seen-modal.component';
|
||||
@@ -450,7 +450,7 @@ export class EntryPageComponent implements OnInit {
|
||||
|
||||
this.episodeSeenService.getEpisodeSeenByEntryId(this.entry.id).subscribe({
|
||||
next: (data) => {
|
||||
let episodeSeens = [] as EpisodeSeenDto[];
|
||||
let episodeSeens = [] as EpisodeSeenCreateDto[];
|
||||
|
||||
// mapping
|
||||
data.forEach((item) => {
|
||||
@@ -468,7 +468,7 @@ export class EntryPageComponent implements OnInit {
|
||||
|
||||
createdAt: item.createdAt,
|
||||
updatedAt: item.updatedAt,
|
||||
} as EpisodeSeenDto;
|
||||
} as EpisodeSeenCreateDto;
|
||||
|
||||
episodeSeens.push(e);
|
||||
});
|
||||
@@ -478,7 +478,7 @@ export class EntryPageComponent implements OnInit {
|
||||
this.filterEpisodesSeenHistory();
|
||||
},
|
||||
error: (error) => {
|
||||
this.seenHistory = [] as EpisodeSeenDto[];
|
||||
this.seenHistory = [] as EpisodeSeenCreateDto[];
|
||||
this.filterEpisodesSeenHistory();
|
||||
console.log(`Error getting episodes watch history`, error);
|
||||
},
|
||||
@@ -487,7 +487,7 @@ export class EntryPageComponent implements OnInit {
|
||||
|
||||
// ? filter episode seen history
|
||||
filterEpisodesSeenHistory() {
|
||||
var temp = [] as EpisodeSeenDto[];
|
||||
var temp = [] as EpisodeSeenCreateDto[];
|
||||
|
||||
temp = this.seenHistory;
|
||||
|
||||
@@ -542,7 +542,7 @@ export class EntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
editEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
||||
editEpisodeSeen(episodeSeen: EpisodeSeenCreateDto) {
|
||||
if (episodeSeen == null) return;
|
||||
|
||||
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
|
||||
@@ -562,7 +562,7 @@ export class EntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
deleteEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
||||
deleteEpisodeSeen(episodeSeen: EpisodeSeenCreateDto) {
|
||||
if (episodeSeen.id == null) return;
|
||||
|
||||
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
:host {
|
||||
--bg-opacity: 0.9;
|
||||
--bg-opacity: 0.3;
|
||||
--bg-opacity-secondary: 0.5;
|
||||
--bg-color: rgba(255, 255, 255, var(--bg-opacity));
|
||||
--text-color: #333;
|
||||
--text-muted: #666;
|
||||
--border-color: #dee2e6;
|
||||
--card-bg: rgba(255, 255, 255, 0.8);
|
||||
--card-bg: rgba(255, 255, 255, var(--bg-opacity-secondary));
|
||||
--hover-bg: #e9ecef;
|
||||
--shadow-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
[data-bs-theme="dark"] :host {
|
||||
--bg-opacity: 0.9;
|
||||
--bg-opacity: 0.3;
|
||||
--bg-opacity-secondary: 0.5;
|
||||
--bg-color: rgba(33, 37, 41, var(--bg-opacity));
|
||||
--text-color: #fff;
|
||||
--text-muted: #adb5bd;
|
||||
--border-color: #495057;
|
||||
--card-bg: rgba(33, 37, 41, 0.8);
|
||||
--card-bg: rgba(33, 37, 41, var(--bg-opacity-secondary));
|
||||
--hover-bg: #495057;
|
||||
--shadow-color: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
@@ -148,11 +150,11 @@
|
||||
}
|
||||
|
||||
.watch-history-section {
|
||||
background: var(--card-bg);
|
||||
backdrop-filter: blur(5px);
|
||||
-webkit-backdrop-filter: blur(5px);
|
||||
/* background: var(--card-bg); */
|
||||
/* backdrop-filter: blur(5px); */
|
||||
/* -webkit-backdrop-filter: blur(5px); */
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
/* padding: 20px; */
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
@@ -183,16 +185,22 @@
|
||||
.table {
|
||||
margin-bottom: 0;
|
||||
color: var(--text-color);
|
||||
background-color: var(--bg-color-secondary);
|
||||
}
|
||||
|
||||
.table th {
|
||||
border-top: none;
|
||||
color: var(--text-color);
|
||||
background-color: var(--bg-color-secondary);
|
||||
}
|
||||
|
||||
.table td {
|
||||
color: var(--text-color);
|
||||
border-color: var(--border-color);
|
||||
background-color: var(--bg-color-secondary);
|
||||
align-items: center;
|
||||
align-content: center;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.btn-outline-primary {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<!-- Fixed Background -->
|
||||
<div class="fixed-image" [style.background-image]="'url(http://localhost:4000/api/v1/media/entries/backdrops/original/1fb338bd-46ee-4caf-b736-f3c0e797ed88.jpg)'"></div>
|
||||
<div class="fixed-image"
|
||||
[style.background-image]="'url(http://localhost:4000/api/v1/media/entries/backdrops/original/1fb338bd-46ee-4caf-b736-f3c0e797ed88.jpg)'">
|
||||
</div>
|
||||
|
||||
<div class="container content-wrapper main-container">
|
||||
<div class="row">
|
||||
@@ -51,11 +53,8 @@
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<h2 class="title">{{selectedSeason.name}} </h2>
|
||||
<div class="season-actions">
|
||||
<button class="btn btn-icon-only-success wh-48">
|
||||
<span class="material-symbols-outlined">playlist_add_check</span>
|
||||
</button>
|
||||
<button class="btn btn-icon-only-success wh-48" (click)="addToPlaylist()">
|
||||
<span class="material-symbols-outlined">playlist_add</span>
|
||||
<button class="btn btn-icon-only-success wh-48" (click)="markSeasonAsWatched()">
|
||||
<span class="material-symbols-outlined">check</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -77,7 +76,9 @@
|
||||
|
||||
<!-- Episodes List -->
|
||||
<div class="episodes-section">
|
||||
<h3 class="mb-3">Episodes</h3>
|
||||
<h3 class="mb-3">
|
||||
Episodes <span class="text-muted">({{selectedSeason.episodes.length}})</span>
|
||||
</h3>
|
||||
<div class="episode-cards">
|
||||
<div class="card mb-3" *ngFor="let episode of selectedSeason.episodes">
|
||||
<div class="row g-0">
|
||||
@@ -89,18 +90,25 @@
|
||||
<div class="d-flex justify-content-between">
|
||||
<h5 class="card-title">{{episode.episode_number}}. {{episode.name}}</h5>
|
||||
<div class="episode-actions">
|
||||
<button class="btn btn-sm btn-outline-primary me-2">
|
||||
<button class="btn btn-icon-only-success wh-48" (click)="markEpisodeAsWatched(episode)">
|
||||
<span class="material-symbols-outlined">check</span>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-secondary">
|
||||
<!-- <button class="btn btn-icon-only-success wh-48">
|
||||
<span class="material-symbols-outlined">info</span>
|
||||
</button>
|
||||
</button> -->
|
||||
</div>
|
||||
</div>
|
||||
<p class="card-text">{{episode.overview}}</p>
|
||||
<p class="card-text">
|
||||
<small class="text-muted">Air date: {{episode.air_date | date:'MMM dd, yyyy'}}</small>
|
||||
<small class="text-muted" *ngIf="episode.runtime"> • Runtime: {{episode.runtime}} minutes</small>
|
||||
<small class="text-muted" *ngIf="episode.air_date">
|
||||
Air date: {{episode.air_date | date:'MMM dd, yyyy'}}
|
||||
</small>
|
||||
<small class="text-muted" *ngIf="episode.runtime"> • Runtime: {{episode.runtime |
|
||||
betterMinutesFormat}}
|
||||
</small>
|
||||
<small class="text-muted" *ngIf="episode.date_first_seen">
|
||||
• Seen: {{episode.date_first_seen | date:'MMM dd, yyyy'}}
|
||||
</small>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -123,10 +131,10 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let history of watchHistory">
|
||||
<td>Episode {{history.episode_number}}</td>
|
||||
<td>{{history.date_seen | date:'MMM dd, yyyy'}}</td>
|
||||
<td>{{history.seen_with}}</td>
|
||||
<tr *ngFor="let ep of watchHistory">
|
||||
<td>Episode {{ep.episode.episode_number}}</td>
|
||||
<td>{{ep.date_seen | date:'MMM dd, yyyy'}}</td>
|
||||
<td>{{ep.seen_with}}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-link">
|
||||
<span class="material-symbols-outlined">edit</span>
|
||||
|
||||
@@ -3,7 +3,10 @@ import { EntryService } from '../../../core/services/entry.service';
|
||||
import { Season } from '../../../shared/models/season.model';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { EpisodeSeenService } from '../../../core/services/episode-seen.service';
|
||||
import { EpisodeSeenDto } from '../../../shared/models/dtos/episode-seen.dto';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { SeenModalComponent } from '../../../shared/components/modals/seen-modal/seen-modal.component';
|
||||
import { Episode } from '../../../shared/models/episode.models';
|
||||
import { EpisodeSeen } from '../../../shared/models/episode-seen.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-season-page',
|
||||
@@ -15,12 +18,13 @@ export class SeasonPageComponent implements OnInit {
|
||||
seasonNumber!: number;
|
||||
seasons: Season[] = [];
|
||||
selectedSeason!: Season;
|
||||
watchHistory: EpisodeSeenDto[] = [];
|
||||
watchHistory: EpisodeSeen[] = [];
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private entryService: EntryService,
|
||||
private episodeSeenService: EpisodeSeenService
|
||||
private episodeSeenService: EpisodeSeenService,
|
||||
private dialog: MatDialog
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -44,6 +48,7 @@ export class SeasonPageComponent implements OnInit {
|
||||
this.episodeSeenService.getEpisodeSeenByEntryId(this.entryId).subscribe({
|
||||
next: (result) => {
|
||||
this.watchHistory = result;
|
||||
console.log(this.watchHistory);
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -51,12 +56,84 @@ export class SeasonPageComponent implements OnInit {
|
||||
|
||||
posterPath(path: string | undefined) {
|
||||
if (path) {
|
||||
return `https://image.tmdb.org/t/p/w300` + path;
|
||||
return `https://image.tmdb.org/t/p/w780` + path;
|
||||
}
|
||||
|
||||
return 'assets/images/default/default-poster.png';
|
||||
}
|
||||
|
||||
markAsWatched() {}
|
||||
addToPlaylist() {}
|
||||
async markEpisodeAsWatched(episode: Episode) {
|
||||
const dialogRef = this.dialog.open(SeenModalComponent, {
|
||||
width: '400px',
|
||||
});
|
||||
|
||||
await dialogRef.afterClosed().subscribe((result) => {
|
||||
if (!result || !result.watchDate) return;
|
||||
const watchDate = result.watchDate;
|
||||
const watchedWith = result.watchedWith.split('\n').join(', ');
|
||||
|
||||
this.episodeSeenService
|
||||
.createEpisodeSeen(
|
||||
this.selectedSeason.entry_id,
|
||||
episode.id,
|
||||
watchDate,
|
||||
watchedWith
|
||||
)
|
||||
.subscribe({
|
||||
next: (episodeSeen) => {
|
||||
if (episodeSeen.date_seen > episode.date_last_seen)
|
||||
episode.date_last_seen = episodeSeen.date_seen;
|
||||
|
||||
if (episodeSeen.date_seen < episode.date_first_seen)
|
||||
episode.date_first_seen = episodeSeen.date_seen;
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(`Couldn't mark episode as seen:`, error);
|
||||
// TODO show notification
|
||||
},
|
||||
complete: () => {},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async markSeasonAsWatched() {
|
||||
const dialogRef = this.dialog.open(SeenModalComponent, {
|
||||
width: '400px',
|
||||
data: {
|
||||
hideSeenWith: true,
|
||||
title: 'Mark Season As Watched'
|
||||
}
|
||||
});
|
||||
|
||||
await dialogRef.afterClosed().subscribe((result) => {
|
||||
if (!result || !result.watchDate) return;
|
||||
const watchDate = result.watchDate;
|
||||
|
||||
this.selectedSeason.episodes.forEach((episode) => {
|
||||
const sub = this.episodeSeenService
|
||||
.createEpisodeSeen(
|
||||
this.selectedSeason.entry_id,
|
||||
episode.id,
|
||||
watchDate,
|
||||
''
|
||||
)
|
||||
.subscribe({
|
||||
next: (episodeSeen) => {
|
||||
if (episodeSeen.date_seen > episode.date_last_seen)
|
||||
episode.date_last_seen = episodeSeen.date_seen;
|
||||
|
||||
if (episodeSeen.date_seen < episode.date_first_seen)
|
||||
episode.date_first_seen = episodeSeen.date_seen;
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(`Couldn't mark episode as seen:`, error);
|
||||
// TODO show notification
|
||||
},
|
||||
complete: () => {
|
||||
sub.unsubscribe();
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -13,7 +13,7 @@ import { Season } from '../../../models/season.model';
|
||||
import { SeasonService } from '../../../../core/services/season.service';
|
||||
import { Episode } from '../../../models/episode.models';
|
||||
import { EpisodeSeenService } from '../../../../core/services/episode-seen.service';
|
||||
import { EpisodeSeenDto } from '../../../models/dtos/episode-seen.dto';
|
||||
import { EpisodeSeenCreateDto } from '../../../models/dtos/episode-seen.dto';
|
||||
|
||||
@Component({
|
||||
selector: 'app-episode-seen-modal',
|
||||
@@ -41,7 +41,7 @@ export class EpisodeSeenModalComponent {
|
||||
public entryId: number = 0;
|
||||
public watchDate: string = '';
|
||||
public watchedWith: string = '';
|
||||
public episodeSeen: EpisodeSeenDto = {} as EpisodeSeenDto;
|
||||
public episodeSeen: EpisodeSeenCreateDto = {} as EpisodeSeenCreateDto;
|
||||
public seasons: Season[] = [];
|
||||
|
||||
public selectedSeason: Season | null = {} as Season;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<div class="card border-top border-3 border-primary rounded-0" style="margin-bottom: 0 !important;">
|
||||
<div class="modal-header card-header py-3 px-4">
|
||||
<h5 class="mb-0 text-primary">Watch Details</h5>
|
||||
<h5 class="mb-0 text-primary">{{title}}</h5>
|
||||
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="card-body p-4 pt-1">
|
||||
<form class="row g-3">
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-12" *ngIf="!hideSeenWith">
|
||||
<label class="form-label">Seen With</label>
|
||||
<textarea class="form-control rounded-0" [(ngModel)]="watchedWith" [ngModelOptions]="{ standalone: true }"
|
||||
placeholder="Enter names" rows="3"></textarea>
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
animate,
|
||||
} from '@angular/animations';
|
||||
import { formatDate } from '@angular/common';
|
||||
import flatpickr from 'flatpickr';
|
||||
|
||||
@Component({
|
||||
selector: 'app-seen-modal',
|
||||
@@ -34,6 +33,9 @@ import flatpickr from 'flatpickr';
|
||||
],
|
||||
})
|
||||
export class SeenModalComponent implements OnInit {
|
||||
title: string = 'Watch Details';
|
||||
hideSeenWith: boolean = false;
|
||||
|
||||
public watchDate: string = '';
|
||||
public watchedWith: string = '';
|
||||
|
||||
@@ -43,8 +45,19 @@ export class SeenModalComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (!this.data || !this.data.watchDate) {
|
||||
if (this.data.title) {
|
||||
this.title = this.data.title;
|
||||
}
|
||||
|
||||
if (this.data.watchedWith)
|
||||
this.watchedWith = this.data.watchedWith.split(', ').join('\n');
|
||||
|
||||
if (this.data.hideSeenWith) {
|
||||
this.hideSeenWith = this.data.hideSeenWith;
|
||||
}
|
||||
|
||||
// ? no initial data was passed: populate date field with current date
|
||||
if (!this.data.watchDate) {
|
||||
this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');
|
||||
} else {
|
||||
// ? if data is passed, populate fields
|
||||
@@ -53,17 +66,7 @@ export class SeenModalComponent implements OnInit {
|
||||
'yyyy-MM-dd',
|
||||
'en-US'
|
||||
);
|
||||
this.watchedWith = this.data.watchedWith.split(', ').join('\n');
|
||||
}
|
||||
|
||||
// flatpickr('#myDatepicker', {
|
||||
// inline: true,
|
||||
// defaultDate: this.watchDate,
|
||||
// altInput: true,
|
||||
// allowInput: false,
|
||||
// altFormat: 'F j, Y',
|
||||
// dateFormat: 'Y-m-d',
|
||||
// });
|
||||
}
|
||||
|
||||
onConfirm(): void {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface EpisodeSeenDto {
|
||||
export interface EpisodeSeenCreateDto {
|
||||
id: number;
|
||||
|
||||
entryId: number;
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { Episode } from "./episode.models";
|
||||
|
||||
export interface EpisodeSeen {
|
||||
id: number;
|
||||
|
||||
entry_id: number;
|
||||
episode_id: number;
|
||||
|
||||
episode: Episode;
|
||||
|
||||
date_seen: Date;
|
||||
seen_with: string;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EpisodeSeen } from "./episode-seen.model";
|
||||
import { Season } from "./season.model";
|
||||
|
||||
export interface Episode {
|
||||
id: number;
|
||||
@@ -7,6 +8,7 @@ export interface Episode {
|
||||
imdb_id: string;
|
||||
|
||||
season_id: number;
|
||||
season: Season;
|
||||
|
||||
episodeSeen: EpisodeSeen[];
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'betterMinutesFormat',
|
||||
})
|
||||
export class BetterMinutesFormatPipe implements PipeTransform {
|
||||
transform(value: number | String): string {
|
||||
const minutes = Number.parseInt(value.toString()) || 0;
|
||||
if (minutes == 0) return `0m`;
|
||||
if (minutes < 60) return `${minutes}m`;
|
||||
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const remainingMinutes = minutes % 60;
|
||||
|
||||
if (remainingMinutes == 0) return `${hours}h`;
|
||||
|
||||
return `${hours}h${remainingMinutes}m`;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import { ToastrModule } from 'ngx-toastr';
|
||||
import { StopScrollDirective } from './directives/stop-scroll.directive';
|
||||
import { ContextMenuTriggerDirective } from './directives/context-menu-trigger.directive';
|
||||
import { ContextMenuComponent } from './components/context-menu/context-menu.component';
|
||||
import { BetterMinutesFormatPipe } from './pipes/minutes-format/bettter-minutes-format.pipe';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -38,6 +39,7 @@ import { ContextMenuComponent } from './components/context-menu/context-menu.com
|
||||
DateFormatPipe,
|
||||
FloatFormatPipe,
|
||||
MinutesFormatPipe,
|
||||
BetterMinutesFormatPipe,
|
||||
|
||||
// * directives
|
||||
StopScrollDirective,
|
||||
@@ -60,6 +62,7 @@ import { ContextMenuComponent } from './components/context-menu/context-menu.com
|
||||
DateFormatPipe,
|
||||
FloatFormatPipe,
|
||||
MinutesFormatPipe,
|
||||
BetterMinutesFormatPipe,
|
||||
|
||||
// * directives
|
||||
StopScrollDirective,
|
||||
|
||||
Reference in new issue
Block a user