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
@@ -20,11 +20,27 @@ import { LibraryComponent } from './features/library/library.component';
|
||||
import { DynamicEntryListComponent } from './shared/components/lists/dynamic-entry-list/dynamic-entry-list.component';
|
||||
import { NotificationPopupComponent } from './shared/components/notification-popup/notification-popup.component';
|
||||
import { MainCardComponent } from './shared/components/cards/main-card/main-card.component';
|
||||
import { UserCollectionsModalComponent } from './shared/components/modals/list-selection-modal/user-collections-modal.component';
|
||||
import { FavoritComponent } from './features/favorit/favorit.component';
|
||||
import { WatchlistComponent } from './features/watchlist/watchlist.component';
|
||||
import { SharedModule } from './shared/shared.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CoreModule,
|
||||
SharedModule,
|
||||
|
||||
AppRoutingModule,
|
||||
|
||||
BrowserModule,
|
||||
BrowserAnimationsModule,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
|
||||
HttpClientModule,
|
||||
|
||||
DragDropModule,
|
||||
],
|
||||
declarations: [
|
||||
AppComponent,
|
||||
|
||||
@@ -41,21 +57,6 @@ import { WatchlistComponent } from './features/watchlist/watchlist.component';
|
||||
MainCardComponent,
|
||||
DynamicEntryListComponent,
|
||||
NotificationPopupComponent,
|
||||
UserCollectionsModalComponent,
|
||||
],
|
||||
imports: [
|
||||
CoreModule,
|
||||
CommonModule,
|
||||
|
||||
AppRoutingModule,
|
||||
|
||||
BrowserModule,
|
||||
BrowserAnimationsModule,
|
||||
HttpClientModule,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
|
||||
DragDropModule,
|
||||
],
|
||||
providers: [DatePipe],
|
||||
bootstrap: [AppComponent],
|
||||
|
||||
@@ -36,6 +36,17 @@ export class UserCollectionService {
|
||||
);
|
||||
}
|
||||
|
||||
// * PUT - update a collection
|
||||
updateCollection(
|
||||
userCollectionId: number,
|
||||
formData: FormData
|
||||
): Observable<UserCollection> {
|
||||
return this.http.put<UserCollection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}`,
|
||||
formData
|
||||
);
|
||||
}
|
||||
|
||||
// Delete a list by ID
|
||||
deleteCollection(userCollectionId: number): Observable<any> {
|
||||
return this.http.delete(
|
||||
|
||||
+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();
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
.rating {
|
||||
color: var(--shz-gold-1);
|
||||
font-size: 25px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
+12
-6
@@ -8,7 +8,7 @@
|
||||
<a href="javascript:;">
|
||||
</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">List: {{list.name}}</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Collections</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
@@ -17,18 +17,24 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h5 class="mb-0">{{list.name}}</h5>
|
||||
<button type="button" class="btn btn-primary btn-sm">
|
||||
<h5 class="mb-0">{{collection.name}}</h5>
|
||||
<button type="button" class="btn btn-primary btn-sm" (click)="openEditModal()">
|
||||
<span class="material-symbols-outlined">
|
||||
edit
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div>Created - {{createdAt}} | Updated - {{updatedAt}}</div>
|
||||
<div *ngIf="list.description != ''">{{list.description}}</div>
|
||||
<div>Created - {{createdAt}} | Updated - {{updatedAt}}
|
||||
<div class="d-flex justify-content-right rating">
|
||||
<rating [(ngModel)]="collection.user_rating" [max]="10" [readonly]="true">
|
||||
</rating>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="collection.description != ''">{{collection.description}}</div>
|
||||
<hr>
|
||||
<div>
|
||||
<app-userCollection-entry-grid [entries]="list.entries" [listId]="getListId()"></app-userCollection-entry-grid>
|
||||
<app-userCollection-entry-grid [entries]="collection.entries"
|
||||
[listId]="getListId()"></app-userCollection-entry-grid>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+56
-9
@@ -4,6 +4,8 @@ import { UserCollectionService } from '../../../../core/services/userCollection.
|
||||
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry.dto';
|
||||
import { CollectionEditModalComponent } from '../collection-edit-modal/collection-edit-modal.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-userCollection-info-page',
|
||||
@@ -12,13 +14,14 @@ import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry
|
||||
providers: [DatePipe],
|
||||
})
|
||||
export class UserCollectionInfoPageComponent implements OnInit {
|
||||
list: UserCollection = {} as UserCollection;
|
||||
collection: UserCollection = {} as UserCollection;
|
||||
createdAt: string = '';
|
||||
updatedAt: string = '';
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private listService: UserCollectionService,
|
||||
private userCollectionService: UserCollectionService,
|
||||
public dialog: MatDialog,
|
||||
private datePipe: DatePipe
|
||||
) {}
|
||||
|
||||
@@ -26,14 +29,17 @@ export class UserCollectionInfoPageComponent implements OnInit {
|
||||
const id = this.route.snapshot.paramMap.get('id');
|
||||
if (id == null) return;
|
||||
|
||||
this.listService.getCollection(id.toString()).subscribe(
|
||||
this.userCollectionService.getCollection(id.toString()).subscribe(
|
||||
(data) => {
|
||||
this.list = data as unknown as UserCollection;
|
||||
this.list.entries = this.list.entries as CollectionEntry[];
|
||||
this.collection = data as unknown as UserCollection;
|
||||
this.collection.entries = this.collection.entries as CollectionEntry[];
|
||||
|
||||
this.createdAt = this.getCreatedDate()?.toString() || '';
|
||||
this.updatedAt = this.getUpdatedAt()?.toString() || '';
|
||||
console.log(`Collection "${this.list.name}" received:`, this.list);
|
||||
console.log(
|
||||
`Collection "${this.collection.name}" received:`,
|
||||
this.collection
|
||||
);
|
||||
},
|
||||
(error) => {
|
||||
console.error('Error occurred:', error);
|
||||
@@ -42,16 +48,16 @@ export class UserCollectionInfoPageComponent implements OnInit {
|
||||
}
|
||||
|
||||
getListId() {
|
||||
return this.list.id + '';
|
||||
return this.collection.id + '';
|
||||
}
|
||||
|
||||
getCreatedDate() {
|
||||
return this.datePipe.transform(this.list.createdAt, 'dd MMMM, yyyy');
|
||||
return this.datePipe.transform(this.collection.createdAt, 'dd MMMM, yyyy');
|
||||
}
|
||||
|
||||
// TODO use a relativeDate pipe
|
||||
getUpdatedAt() {
|
||||
const updatedAt = this.list.updatedAt;
|
||||
const updatedAt = this.collection.updatedAt;
|
||||
// First, check if updatedAt is a valid date string or timestamp
|
||||
const modifiedDate = new Date(updatedAt);
|
||||
|
||||
@@ -87,4 +93,45 @@ export class UserCollectionInfoPageComponent implements OnInit {
|
||||
return this.datePipe.transform(modifiedDate, 'dd MMMM, yyyy');
|
||||
}
|
||||
}
|
||||
|
||||
openEditModal() {
|
||||
if (!this.collection) return;
|
||||
|
||||
const dialogRef = this.dialog.open(CollectionEditModalComponent, {
|
||||
width: '360px',
|
||||
data: {
|
||||
name: this.collection.name,
|
||||
description: this.collection.description,
|
||||
user_rating: this.collection.user_rating || 0,
|
||||
poster: this.collection.poster_path,
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Edit dialog opened');
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
if (result) {
|
||||
if (result.formData == null) return;
|
||||
console.log('Edit dialog closed with:', result);
|
||||
|
||||
this.userCollectionService
|
||||
.updateCollection(this.collection.id, result.formData)
|
||||
.subscribe({
|
||||
next: (userCollection) => {
|
||||
if (userCollection) {
|
||||
// TODO show confirm notification
|
||||
console.log(`User Collection updated: `, userCollection);
|
||||
this.collection = userCollection;
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error updating userCollection:', error);
|
||||
// TODO show notification
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log('Edit dialog was cancelled');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,41 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { AppRoutingModule } from '../../app-routing.module';
|
||||
import { CollectionsRoutingModule } from './collections-routing.module';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { CollectionsRoutingModule } from './collections-routing.module';
|
||||
|
||||
import { DragDropModule } from '@angular/cdk/drag-drop';
|
||||
|
||||
import { UserCollectionsPageComponent } from './user-collections/userCollections-page/userCollections-page.component';
|
||||
import { UserCollectionsListItemComponent } from './user-collections/userCollection-list-item/userCollections-list-item.component';
|
||||
import { UserCollectionEntryGridComponent } from './user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component';
|
||||
import { UserCollectionGridCardComponent } from './user-collection-info/userCollection-grid-card/userCollection-grid-card.component';
|
||||
import { UserCollectionInfoPageComponent } from './user-collection-info/userCollection-info-page/userCollection-info-page.component';
|
||||
import { UserCollectionsModalComponent } from '../../shared/components/modals/list-selection-modal/user-collections-modal.component';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { DragDropModule } from '@angular/cdk/drag-drop';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
UserCollectionEntryGridComponent,
|
||||
UserCollectionGridCardComponent,
|
||||
UserCollectionInfoPageComponent,
|
||||
|
||||
UserCollectionsPageComponent,
|
||||
UserCollectionsListItemComponent,
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
SharedModule,
|
||||
CollectionsRoutingModule,
|
||||
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
|
||||
CollectionsRoutingModule,
|
||||
|
||||
DragDropModule,
|
||||
],
|
||||
declarations: [
|
||||
// collections list page
|
||||
UserCollectionsPageComponent,
|
||||
UserCollectionsListItemComponent,
|
||||
|
||||
// collection info page
|
||||
UserCollectionInfoPageComponent,
|
||||
UserCollectionEntryGridComponent,
|
||||
UserCollectionGridCardComponent,
|
||||
UserCollectionsModalComponent,
|
||||
],
|
||||
exports: [],
|
||||
})
|
||||
export class UserCollectionsModule {}
|
||||
+6
-1
@@ -32,8 +32,13 @@ export class UserCollectionsListItemComponent {
|
||||
|
||||
getPostPath() {
|
||||
if (this.list.poster_path == null) return 'https://pic.pnnet.dev/256x256';
|
||||
if (this.list.poster_path.startsWith('/'))
|
||||
return `https://image.tmdb.org/t/p/w500` + this.list.poster_path;
|
||||
|
||||
return `https://image.tmdb.org/t/p/w500` + this.list.poster_path;
|
||||
return (
|
||||
`http://localhost:4000/api/v1/media/collections/posters/` +
|
||||
this.list.poster_path
|
||||
);
|
||||
}
|
||||
|
||||
getCreatedDate(): string {
|
||||
|
||||
+4
-1
@@ -124,7 +124,10 @@ export class UserCollectionsModalComponent implements OnInit {
|
||||
`Adding Entry ${this.entryId} to list: ${userCollection.name}`
|
||||
);
|
||||
this.listService
|
||||
.addEntryToCollection(userCollection.id, this.entryId)
|
||||
.addEntryToCollection(
|
||||
userCollection.id,
|
||||
this.entryId
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
console.log('Successfuly added Entry To Collection:', response);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
// * cards
|
||||
import { SeasonMainCardComponent } from './cards/season-main-card/season-main-card.component';
|
||||
@@ -13,15 +12,26 @@ import { DateFormatPipe } from './pipes/date-format/date-format.pipe';
|
||||
|
||||
// * other
|
||||
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';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
|
||||
RatingModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
// ? pipes
|
||||
// * pipes
|
||||
DateFormatPipe,
|
||||
|
||||
// ? components
|
||||
SeasonMainCardComponent,
|
||||
SeenModalComponent,
|
||||
CollectionEditModalComponent
|
||||
|
||||
// ? other imported components
|
||||
|
||||
@@ -33,18 +43,17 @@ import { RatingModule } from 'ngx-bootstrap/rating';
|
||||
|
||||
// ? modules
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
exports: [
|
||||
// * pipes
|
||||
DateFormatPipe,
|
||||
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
|
||||
RatingModule.forRoot(),
|
||||
],
|
||||
exports: [
|
||||
|
||||
//NotificationPopupComponent,
|
||||
DateFormatPipe,
|
||||
SeasonMainCardComponent,
|
||||
SeenModalComponent,
|
||||
|
||||
RatingModule,
|
||||
],
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user