changes + fixes to collections related component + add filter by collection type

This commit is contained in:
X4Lo committed 2024-09-10 01:15:14 +01:00
1 parent eba9721a3c
commit 776506b232
14 files changed
+219 -129

No files matched your search

@@ -1,15 +1,15 @@
<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">Collection Details</h5>
<h5 class="mb-0 text-primary">Modify Collection Details</h5>
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
</div>
<div class="card-body p-4">
<div class="card-body p-4 pt-1">
<form class="row g-3" [formGroup]="form">
<div class="col-md-12">
<label class="form-label">Collection Name</label>
<label class="form-label">Name</label>
<input type="text" class="form-control rounded-0" formControlName="name">
<div *ngIf="form.get('name')?.invalid && form.get('name')?.touched" class="error-message">
Name is required
Collection name is required
</div>
</div>
@@ -24,15 +24,15 @@
<div class="col-md-12">
<label class="form-label">Rating</label>
<div class="d-flex justify-content-center rating">
<rating formControlName="user_rating" [max]="10" [readonly]="false">
<div class="d-flex justify-content-center rating m-0">
<rating formControlName="userRating" [max]="10" [readonly]="false">
</rating>
</div>
</div>
<div class="col-md-12">
<label class="form-label">Poster</label>
<input type="file" id="image" (change)="onFileChange($event)">
<input type="file" class="form-control" id="image" (change)="onFileChange($event)">
</div>
@@ -38,8 +38,7 @@ export class CollectionEditModalComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<CollectionEditModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private fb: FormBuilder,
private cd: ChangeDetectorRef
private fb: FormBuilder
) {}
ngOnInit() {
@@ -47,20 +46,11 @@ export class CollectionEditModalComponent implements OnInit {
this.form = this.fb.group({
name: [this.data.name, Validators.required],
description: [this.data.description],
user_rating: [this.data.user_rating],
userRating: [this.data.userRating],
poster: [null],
});
}
private markFormGroupTouched(formGroup: FormGroup) {
Object.values(formGroup.controls).forEach((control) => {
control.markAsTouched();
if (control instanceof FormGroup) {
this.markFormGroupTouched(control);
}
});
}
onFileChange(event: any) {
const file = event.target.files[0];
this.form.patchValue({ poster: file });
@@ -68,28 +58,26 @@ export class CollectionEditModalComponent implements OnInit {
}
onConfirm(): void {
if (this.form.valid) {
let formData = new FormData();
if (this.form.invalid) return this.form.markAllAsTouched();
formData.append('name', this.form.get('name')?.value);
formData.append('description', this.form.get('description')?.value || '');
formData.append(
'user_rating',
this.form.get('user_rating')?.value.toString()
);
let formData = new FormData();
// Check and append file if it exists
const posterFile = this.form.get('poster')?.value;
if (posterFile) {
formData.append('poster', posterFile);
}
formData.append('name', this.form.get('name')?.value.toString().trim());
formData.append('description', this.form.get('description')?.value || '');
formData.append(
'userRating',
this.form.get('userRating')?.value?.toString() || '0'
);
formData.append('is_poster_link', 'false');
this.dialogRef.close({ formData: formData });
} else {
this.markFormGroupTouched(this.form);
// Check and append file if it exists
const posterFile = this.form.get('poster')?.value;
if (posterFile) {
formData.append('poster', posterFile);
}
formData.append('is_poster_link', 'false');
this.dialogRef.close({ formData: formData });
}
onClose(): void {