diff --git a/backend/routes/userCollectionRoutes.js b/backend/routes/userCollectionRoutes.js index 3cef401..b39e4e5 100644 --- a/backend/routes/userCollectionRoutes.js +++ b/backend/routes/userCollectionRoutes.js @@ -4,6 +4,9 @@ const UserCollectionEntry = require('../models/UserCollectionEntry'); const Entry = require('../models/Entry'); const EntryId = require('../models/EntryId'); const EntryRating = require('../models/EntryRating'); +const Season = require('../models/Season'); +const Genre = require('../models/Genre'); + const { Sequelize } = require('sequelize'); const router = express.Router(); const multer = require('multer'); @@ -46,7 +49,9 @@ router.get('/:id', async (req, res) => { as: 'entries', include: [ { model: EntryId, as: 'entryId' }, - { model: EntryRating, as: 'entryRating' } + { model: EntryRating, as: 'entryRating' }, + { model: Season, as: 'seasons' }, + { model: Genre, as: 'genres' }, ], through: { model: UserCollectionEntry, @@ -57,7 +62,13 @@ router.get('/:id', async (req, res) => { }); if (userCollection) { - res.status(200).json(userCollection); + const collectionData = userCollection.get({ plain: true }); + for (let i = 0; i < collectionData.entries.length; i++) { + const genres = collectionData.entries[i].genres.map(genre => genre.name); + collectionData.entries[i].genres = genres + } + + res.status(200).json(collectionData); } else { res.status(404).json({ message: 'UserCollection not found' }); } diff --git a/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.css b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.html b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.html new file mode 100644 index 0000000..26c9904 --- /dev/null +++ b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.html @@ -0,0 +1,42 @@ + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + TitleTypeGenresRatingReleasedDate SeenAction
+
+
+
+
\ No newline at end of file diff --git a/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.spec.ts b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.spec.ts new file mode 100644 index 0000000..4fe239d --- /dev/null +++ b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CollectionEntryTableComponent } from './collection-entry-table.component'; + +describe('CollectionEntryTableComponent', () => { + let component: CollectionEntryTableComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [CollectionEntryTableComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(CollectionEntryTableComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.ts b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.ts new file mode 100644 index 0000000..40dfb41 --- /dev/null +++ b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.ts @@ -0,0 +1,49 @@ +import { Component, Input } from '@angular/core'; +import { Entry } from '../../../../shared/models/entry.model'; +import { + CdkDragDrop, + CdkDragEnd, + CdkDragStart, + moveItemInArray, +} from '@angular/cdk/drag-drop'; +import { + animate, + state, + style, + transition, + trigger, +} from '@angular/animations'; + +@Component({ + selector: 'app-collection-entry-table', + templateUrl: './collection-entry-table.component.html', + styleUrl: './collection-entry-table.component.css', + animations: [ + trigger('animateDestroy', [ + state('void', style({ opacity: '0' })), + transition('* => void', animate('300ms ease')), + ]), + ], +}) +export class CollectionEntryTableComponent { + @Input() entries: Entry[] = []; + @Input() listId: string = ''; + + refrechEventReceiver() { + console.log('event recieved'); + } + + drop(event: CdkDragDrop) { + moveItemInArray(this.entries, event.previousIndex, event.currentIndex); + } + + dragStart(event: CdkDragStart): void { + event.source.element.nativeElement.classList.add('custom-dragging-class'); + } + + dragEnd(event: CdkDragEnd): void { + event.source.element.nativeElement.classList.remove( + 'custom-dragging-class' + ); + } +} diff --git a/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.css b/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.html b/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.html new file mode 100644 index 0000000..b55e174 --- /dev/null +++ b/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.html @@ -0,0 +1,44 @@ + + + + +
+
+ +
+
+ {{entry.title}} +

{{entry.seasons.length}} + Season{{entry.seasons.length + > 1 ? 's' : ''}}

+
+
+ +{{entry.is_tvseries ? 'Series' : 'Movie'}} + +
+ {{genre}} +
+ + +
+ {{entry.entryRating.tmdb_rating | + floatFormat:1}} +
+ + +{{entry.release_date | dateFormat:'MMM dd, yyyy '}} +{{entry.date_first_seen | dateFormat:'MMM dd, yyyy '}} + + + \ No newline at end of file diff --git a/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.spec.ts b/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.spec.ts new file mode 100644 index 0000000..a4bfa7a --- /dev/null +++ b/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CollectionTableLineComponent } from './collection-table-line.component'; + +describe('CollectionTableLineComponent', () => { + let component: CollectionTableLineComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [CollectionTableLineComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(CollectionTableLineComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.ts b/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.ts new file mode 100644 index 0000000..2670620 --- /dev/null +++ b/frontend/src/app/features/collections/user-collection-info/collection-table-line/collection-table-line.component.ts @@ -0,0 +1,110 @@ +import { + Component, + EventEmitter, + Input, + OnInit, + Output, + ViewEncapsulation, +} from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import { LibraryService } from '../../../../core/services/library.service'; +import { Entry } from '../../../../shared/models/entry.model'; +import { trigger, transition, style, animate } from '@angular/animations'; +import { UserCollectionService } from '../../../../core/services/userCollection.service'; +import { Router } from '@angular/router'; +import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component'; + +@Component({ + selector: 'tr [app-collection-table-line]', + templateUrl: './collection-table-line.component.html', + styleUrl: './collection-table-line.component.css', + encapsulation: ViewEncapsulation.None, + animations: [ + trigger('fadeInOut', [ + transition(':enter', [ + style({ opacity: 0 }), + animate('0.5s ease-out', style({ opacity: 1 })), + ]), + transition(':leave', [animate('0.5s ease-in', style({ opacity: 0 }))]), + ]), + ], +}) +export class CollectionTableLineComponent implements OnInit { + @Input() entry!: Entry; + @Input() listId: string = ''; + @Output() refrechEvent = new EventEmitter(); + + constructor( + private libraryService: LibraryService, + private userCollectionService: UserCollectionService, + public dialog: MatDialog, + private router: Router + ) {} + + ngOnInit(): void { + + } + + get releaseYear(): number { + return new Date(this.entry.release_date).getFullYear(); + } + + get formattedRate(): string { + return this.entry.entryRating.tmdb_rating.toFixed(1); + } + + getTmdbLink() { + let type = this.entry.is_tvseries ? 'tv' : 'movie'; + return `https://www.themoviedb.org/${type}/${this.entry.entryId.tmdb_id}`; + } + + getPostPath() { + if (this.entry.poster_path == null) return 'https://pic.pnnet.dev/256x256'; + + return `https://image.tmdb.org/t/p/w500` + this.entry.poster_path; + } + + removeEntryFromList() { + const dialogRef = this.dialog.open(ConfirmModalComponent, { + width: '400px', + data: { + title: 'Confirmation', + message: `Are you sure you want to remove ${this.entry.title} from this collection?`, + type: 'danger', + }, + }); + + dialogRef.afterClosed().subscribe((result) => { + if (result) { + if (result.confirmed != true) return; + + this.userCollectionService + .removeEntryFromCollection(this.listId, this.entry.id) + .subscribe({ + next: (response) => { + // TODO confirm notification + + console.log('Entry successfully removed from list.', response); + this.entry.id = 0; + this.entry.isInLibrary = false; + }, + error: (error) => { + // TODO error notification + console.error('Error removing entry from list:', error); + }, + }); + } + }); + } + + // ? EVENTS + cardClick() { + if (this.entry.isInLibrary) + this.router.navigate([`/entries/${this.entry.id}`]); + } + + // ? EVENT EMITTER + emitRefrechEvent() { + this.refrechEvent.emit(); + } +} diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html index 2d28a28..5ced002 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html @@ -26,7 +26,7 @@
  • Edit
  • -
  • Change order
  • +
  • Switch View
  • Delete
  • @@ -39,9 +39,16 @@
    {{collection.description}}

    -
    + +
    + + +
    + +
    \ No newline at end of file diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts index f882d7a..9dc5c25 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts @@ -19,6 +19,8 @@ export class UserCollectionInfoPageComponent implements OnInit { createdAt: string = ''; updatedAt: string = ''; + viewMode: string = 'grid'; + constructor( private route: ActivatedRoute, private userCollectionService: UserCollectionService, @@ -65,7 +67,7 @@ export class UserCollectionInfoPageComponent implements OnInit { // Check if the date is invalid if (isNaN(modifiedDate.getTime())) { - console.error('Invalid date:', updatedAt); + // console.error('Invalid date:', updatedAt); // Handle invalid date, perhaps return a fallback message or undefined return 'Date not available'; } @@ -109,7 +111,6 @@ export class UserCollectionInfoPageComponent implements OnInit { }, }); - dialogRef.afterClosed().subscribe((result) => { if (result) { if (result.formData == null) return; @@ -120,7 +121,7 @@ export class UserCollectionInfoPageComponent implements OnInit { next: (userCollection) => { if (userCollection) { // TODO confirm notification - console.log(`User Collection updated: `, userCollection); + // console.log(`User Collection updated: `, userCollection); this.collection = userCollection; } }, @@ -133,7 +134,10 @@ export class UserCollectionInfoPageComponent implements OnInit { }); } - changeOrder() {} + switchViewMode() { + this.viewMode = this.viewMode == 'grid' ? 'table' : 'grid'; + } + deleteCollection() { if (!this.collection) return; diff --git a/frontend/src/app/features/collections/user-collections.module.ts b/frontend/src/app/features/collections/user-collections.module.ts index 88c6017..31dbda6 100644 --- a/frontend/src/app/features/collections/user-collections.module.ts +++ b/frontend/src/app/features/collections/user-collections.module.ts @@ -12,6 +12,8 @@ import { UserCollectionGridCardComponent } from './user-collection-info/userColl 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 { CollectionEntryTableComponent } from './user-collection-info/collection-entry-table/collection-entry-table.component'; +import { CollectionTableLineComponent } from './user-collection-info/collection-table-line/collection-table-line.component'; @NgModule({ imports: [ @@ -32,8 +34,14 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; // collection info page UserCollectionInfoPageComponent, + UserCollectionEntryGridComponent, UserCollectionGridCardComponent, + + CollectionEntryTableComponent, + CollectionTableLineComponent, + + UserCollectionsModalComponent, ], exports: [], diff --git a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts index 63fb949..e8afd02 100644 --- a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts +++ b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts @@ -43,7 +43,7 @@ export class UserCollectionsPageComponent implements OnInit { getCollections() { this.collectionsService.getCollections().subscribe({ next: (l) => { - console.log(`Loaded ${l.length} lists.`); + // console.log(`Loaded ${l.length} lists.`); this.collections = l; this.collectionsToShow = this.collections; this.applyFilter();