implemented UserCollection edit modal + custom collection poster + media access route
This commit is contained in:
1 parent
0ff3c49ca6
commit
e8c4fba943
17 files changed
+499
-73
No files matched your search
+9
@@ -0,0 +1,9 @@
|
||||
.rating {
|
||||
color: var(--shz-gold-1);
|
||||
font-size: 25px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: var(--shx-red-danger);
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<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>
|
||||
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<form class="row g-3" [formGroup]="form">
|
||||
<div class="col-md-12">
|
||||
<label class="form-label">Collection 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
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<label class="form-label">Description</label>
|
||||
<textarea class="form-control rounded-0" formControlName="description" placeholder="Enter a description..."
|
||||
rows="3"></textarea>
|
||||
<div *ngIf="form.get('description')?.invalid && form.get('description')?.touched" class="error-message">
|
||||
Description is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
</rating>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<label class="form-label">Poster</label>
|
||||
<input type="file" id="image" (change)="onFileChange($event)">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="d-md-flex d-grid align-items-center gap-3">
|
||||
<button type="button" class="btn btn-primary px-4 rounded-0" (click)="onConfirm()">OK</button>
|
||||
<button type="button" class="btn btn-secondary px-4 rounded-0" (click)="onClose()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CollectionEditModalComponent } from './collection-edit-modal.component';
|
||||
|
||||
describe('CollectionEditModalComponent', () => {
|
||||
let component: CollectionEditModalComponent;
|
||||
let fixture: ComponentFixture<CollectionEditModalComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [CollectionEditModalComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CollectionEditModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
|
||||
import {
|
||||
trigger,
|
||||
state,
|
||||
style,
|
||||
transition,
|
||||
animate,
|
||||
} from '@angular/animations';
|
||||
|
||||
@Component({
|
||||
selector: 'app-collection-edit-modal',
|
||||
templateUrl: './collection-edit-modal.component.html',
|
||||
styleUrl: './collection-edit-modal.component.css',
|
||||
animations: [
|
||||
trigger('fadeInOut', [
|
||||
state('in', style({ opacity: 1 })),
|
||||
transition(':enter', [style({ opacity: 0 }), animate(600)]),
|
||||
transition(':leave', [animate(600, style({ opacity: 0 }))]),
|
||||
]),
|
||||
trigger('scaleInOut', [
|
||||
transition(':enter', [
|
||||
state('in', style({ opacity: 1 })),
|
||||
style({ transform: 'scale(0)' }),
|
||||
animate('200ms ease-in-out', style({ transform: 'scale(1)' })),
|
||||
]),
|
||||
transition(':leave', [
|
||||
animate('200ms ease-in-out', style({ transform: 'scale(0)' })),
|
||||
]),
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class CollectionEditModalComponent implements OnInit {
|
||||
form!: FormGroup;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<CollectionEditModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private fb: FormBuilder,
|
||||
private cd: ChangeDetectorRef
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.data == null) return;
|
||||
this.form = this.fb.group({
|
||||
name: [this.data.name, Validators.required],
|
||||
description: [this.data.description],
|
||||
user_rating: [this.data.user_rating],
|
||||
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 });
|
||||
this.form.get('poster')?.updateValueAndValidity();
|
||||
}
|
||||
|
||||
onConfirm(): void {
|
||||
if (this.form.valid) {
|
||||
let formData = new FormData();
|
||||
|
||||
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()
|
||||
);
|
||||
|
||||
// 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 });
|
||||
} else {
|
||||
this.markFormGroupTouched(this.form);
|
||||
}
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user