add confirmModal + float format pipe + moved a component

This commit is contained in:
X4Lo committed 2024-05-10 09:39:13 +01:00
1 parent 49f8cd601b
commit 1361fc7b18
12 files changed
+112 -31

No files matched your search

@@ -1,37 +0,0 @@
.list-item-1 {
padding-top: 1px;
}
.list-title {
font-size: 20px;
}
.list-line {
max-height: 105px;
border-radius: 1px;
overflow: hidden;
padding: 2px;
box-sizing: border-box;
}
.overview {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
max-height: 50px;
}
.list-line:hover {
background-color: var(--shz-light-bgh);
}
:host-context([data-bs-theme="dark"]) .list-line:hover {
background-color: var(--shz-dark-bgh);
}
.progress {
flex-grow: 1; /* Makes the progress bar expand to fill available space */
margin-right: 10px; /* Adds some space between the progress bar and the checkbox */
}
@@ -1,29 +0,0 @@
<!-- TODO mark season as seen > check box-->
<div class="d-flex align-items-start gap-2 list-line" @fadeInOut>
<img [src]="posterPath" width="70" height="105" class="" alt="Episode poster">
<div class="flex-grow-1 list-item-1">
<h6 class="mb-0 list-title">{{season.name}}</h6>
<p class="mb-0">{{season.air_date | dateFormat:'yyyy'}}</p>
<div class="d-flex align-items-center justify-content-between mb-4 mt-3" style="height: 40px;">
<div class="progress" style="height: 7px; width: 90%;"> <!-- Adjust width as needed -->
<div class="progress-bar" role="progressbar" [style]="'width:'+ episodesWatchedPercentage + '%'"
[attr.aria-valuenow]="episodesWatchedPercentage" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div style="margin-right: 5px;">
{{episodesWatchedCount}}/{{this.season.episode_count}}
</div>
<button *ngIf="episodesWatchedCount < this.season.episode_count" type="button"
class="btn btn-outline-primary rounded-pill d-flex justify-content-center align-items-center"
style="height: 30px; width: 40px; margin-right: 5px;" (click)="episodeMarkSeenClick()">
<span class="material-symbols-outlined">check</span>
</button>
<!-- <div class="form-check" style="margin-right: 5px;" *ngIf="episodesWatchedCount < this.season.episode_count">
<input class="form-check-input" type="checkbox" style="height: 20px; width: 20px;" [checked]="isChecked"
(change)="handleCheckChange()">
</div> -->
</div>
<!-- <p class="mb-0 overview">{{season.overview}}</p> -->
</div>
</div>
@@ -1,176 +0,0 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Season } from '../../models/season.model';
import { SeasonService } from '../../../core/services/season.service';
import {
trigger,
state,
style,
transition,
animate,
} from '@angular/animations';
import { Episode } from '../../models/episode.models';
import { EpisodeSeenService } from '../../../core/services/episode-seen.service';
import { MatDialog } from '@angular/material/dialog';
import { SeenModalComponent } from '../../components/modals/seen-modal/seen-modal.component';
@Component({
selector: 'app-season-main-card',
templateUrl: './season-main-card.component.html',
styleUrl: './season-main-card.component.css',
animations: [
trigger('fadeInOut', [
transition(':enter', [
// void => *
style({ opacity: 0 }),
animate('0.5s ease-in', style({ opacity: 1 })),
]),
transition(':leave', [
// * => void
animate('0.5s ease-out', style({ opacity: 0 })),
]),
]),
],
})
export class SeasonMainCardComponent implements OnInit {
@Output() episodeWatchedEvent = new EventEmitter();
@Input() season: Season = {} as Season;
isChecked: boolean = false;
isLocked: boolean = false;
constructor(
private seasonService: SeasonService,
private episodeSeenService: EpisodeSeenService,
public dialog: MatDialog
) {}
ngOnInit(): void {
this.seasonService.getSeasonEpisodes(this.season.id).subscribe({
next: (episodes) => {
console.log(`Loaded Season Episodes: `, episodes);
this.season.episodes = episodes;
},
error: (error) => {
console.log(`Couldn't fetch season episodes data:`, error);
// TODO show notification
},
});
}
get posterPath() {
if (this.season.poster_path == null)
return 'assets/images/default/default-poster.png';
return 'http://image.tmdb.org/t/p/w154/' + this.season.poster_path;
}
get episodesWatchedPercentage() {
let count = 0;
if (!this.season.episodes) return 0;
this.season.episodes.forEach((ep) => {
if (ep.date_first_seen != null) count++;
});
if (this.season.episode_count == null) return 0;
let value = (count * 100) / this.season.episode_count;
return value;
}
get episodesWatchedCount() {
let count = 0;
if (!this.season.episodes) return 0;
this.season.episodes.forEach((ep) => {
if (ep.date_first_seen != null) count++;
});
return count;
}
async episodeMarkSeenClick() {
if (this.isLocked) return;
this.isLocked = true;
let selectedEpisode = {} as Episode;
let selectedEpisodeIndex = -1;
// * starts looping from the last available episode
if (
this.season.episodes[this.season.episodes.length - 1].date_first_seen ==
null
) {
// ? untils it finds that the previous episode episode is marked as seen
// ? > in that case it chooses the current one to mark
for (let i = this.season.episodes.length - 1; i >= 0; i--) {
if (i == 0 || this.season.episodes[i - 1].date_first_seen != null) {
selectedEpisodeIndex = i;
selectedEpisode = this.season.episodes[i];
break;
}
}
} else {
// ? in case the last episode is already marked as seen but
// ? there are other before it that are not, then start from
// ? episode 1 and look for any that are not seen
for (let i = 0; i < this.season.episodes.length; i++) {
if (this.season.episodes[i].date_first_seen == null) {
selectedEpisodeIndex = i;
selectedEpisode = this.season.episodes[i];
break;
}
}
}
// + end loocking for episode
if (selectedEpisode == null) return;
if (selectedEpisode.date_first_seen != null) return;
// ? show the episode seen modal
const dialogRef = this.dialog.open(SeenModalComponent, {
width: '400px',
});
console.log('Episode seen dialog opened');
await dialogRef.afterClosed().subscribe((result) => {
if (result) {
console.log('Episode seen dialog closed with:', result);
if (result.watchDate == '') {
// TODO show no date was passed notification
this.isLocked = false;
return;
}
let watchDate = result.watchDate;
let watchedWith = result.watchedWith.split('\n').join(', ');
this.episodeSeenService
.createEpisodeSeen(
this.season.entry_id,
selectedEpisode.id,
watchDate,
watchedWith
)
.subscribe({
next: (episodeSeen) => {
console.log(`Episode marked as seen`, episodeSeen);
// TODO get actualy date_first_seen & date_last_seen for episode seen (not just place holders)
this.season.episodes[selectedEpisodeIndex].date_first_seen =
new Date();
this.season.episodes[selectedEpisodeIndex].date_last_seen =
new Date();
this.episodeWatchedEvent.emit();
// TODO show notification
},
error: (error) => {
console.log(`Couldn't mark episode as seen:`, error);
// TODO show notification
},
complete: () => {
this.isLocked = false;
},
});
} else {
console.log('Seen dialog was cancelled');
this.isLocked = false;
}
});
}
}
@@ -0,0 +1,19 @@
<div class="card border-top border-3 border-{{type}} rounded-0" style="margin-bottom: 0 !important;">
<div class="modal-header card-header py-3 px-4">
<h5 class="mb-0 text-{{type}}">{{title}}</h5>
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
</div>
<div class="card-body p-4">
<form class="row g-3">
<div class="col-md-12">
<p style="text-align: justify;">{{message}}</p>
</div>
<div class="col-md-12">
<div class="d-flex justify-content-end gap-3">
<button type="button" class="btn btn-{{type}} px-4 rounded-0" (click)="onConfirm()">Confirm</button>
<button type="button" class="btn btn-secondary px-4 rounded-0" (click)="onClose()">Cancel</button>
</div>
</div>
</form>
</div>
</div>
@@ -1,18 +1,18 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SeasonMainCardComponent } from './season-main-card.component';
import { ConfirmModalComponent } from './confirm-modal.component';
describe('SeasonMainCardComponent', () => {
let component: SeasonMainCardComponent;
let fixture: ComponentFixture<SeasonMainCardComponent>;
describe('ConfirmModalComponent', () => {
let component: ConfirmModalComponent;
let fixture: ComponentFixture<ConfirmModalComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SeasonMainCardComponent]
imports: [ConfirmModalComponent]
})
.compileComponents();
fixture = TestBed.createComponent(SeasonMainCardComponent);
fixture = TestBed.createComponent(ConfirmModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
@@ -0,0 +1,34 @@
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { FormBuilder } from '@angular/forms';
@Component({
selector: 'app-confirm-modal',
templateUrl: './confirm-modal.component.html',
styleUrl: './confirm-modal.component.css',
})
export class ConfirmModalComponent implements OnInit {
title: string = 'Confirm your action';
message: string = 'Are you sure?';
type: string = 'dangger';
constructor(
public dialogRef: MatDialogRef<ConfirmModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any
) {}
ngOnInit() {
if (this.data == null) return;
this.title = this.data.title;
this.message = this.data.message;
this.type = this.data.type;
}
onConfirm(): void {
this.dialogRef.close({ confirmed: true });
}
onClose(): void {
this.dialogRef.close();
}
}
@@ -0,0 +1,8 @@
import { FloatFormatPipe } from './float-format.pipe';
describe('FloatFormatPipe', () => {
it('create an instance', () => {
const pipe = new FloatFormatPipe();
expect(pipe).toBeTruthy();
});
});
@@ -0,0 +1,12 @@
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'floatFormat',
})
export class FloatFormatPipe implements PipeTransform {
transform(value: number, toFixed: number): unknown {
if (!value) return 0;
return value.toFixed(toFixed);
}
}
+9 -18
View File
@@ -1,11 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
// * cards
import { SeasonMainCardComponent } from './cards/season-main-card/season-main-card.component';
// * modals
import { SeenModalComponent } from './components/modals/seen-modal/seen-modal.component';
import { ConfirmModalComponent } from './components/modals/confirm-modal/confirm-modal.component';
// * pipes
import { DateFormatPipe } from './pipes/date-format/date-format.pipe';
@@ -14,46 +13,38 @@ import { DateFormatPipe } from './pipes/date-format/date-format.pipe';
import { RatingModule } from 'ngx-bootstrap/rating';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CollectionEditModalComponent } from '../features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component';
import { FloatFormatPipe } from './pipes/float-format/float-format.pipe';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
RatingModule.forRoot(),
],
declarations: [
// * pipes
DateFormatPipe,
FloatFormatPipe,
// ? components
SeasonMainCardComponent,
SeenModalComponent,
CollectionEditModalComponent
CollectionEditModalComponent,
ConfirmModalComponent,
// ? other imported components
// NotificationPopupComponent,
// MainCardComponent,
// DynamicEntryListComponent,
// NotificationPopupComponent,
// ListSelectionModalComponent,
// ? modules
],
exports: [
// * pipes
DateFormatPipe,
FloatFormatPipe,
FormsModule,
ReactiveFormsModule,
//NotificationPopupComponent,
SeasonMainCardComponent,
SeenModalComponent,
ConfirmModalComponent,
RatingModule,
],
})