diff --git a/backend/routes/entry.routes.js b/backend/routes/entry.routes.js index a477b75..d097ff9 100644 --- a/backend/routes/entry.routes.js +++ b/backend/routes/entry.routes.js @@ -65,13 +65,15 @@ entryRouter.get('/:id', async (req, res) => { attributes: [] // Do not fetch any attributes from the join table } } + ], + order: [ + [{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list ] }); if (!entry) { // ! entry not found res.status(404).json({ message: 'Entry not found' }); } - const entryData = entry.get({ plain: true }); const genres = entryData.genres.map(genre => genre.name); @@ -172,7 +174,10 @@ entryRouter.put('/:id', async (req, res) => { if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' }); const updatedEntry = await Entry.findByPk(id, { - include: includes + include: includes, + order: [ + [{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list + ] }); const entryData = updatedEntry.get({ plain: true }); diff --git a/backend/server.js b/backend/server.js index 47a6df5..830e49d 100644 --- a/backend/server.js +++ b/backend/server.js @@ -63,12 +63,12 @@ app.use(errorHandler); app.use('/killer', killerRouter); // Start the server - +const doUpdate = false; console.log(`Syncing database schema...`); sequelize // .sync({force: true}) // will drop all tables and recreate them. - // .sync({ alter: true }) // will attempt to automatically alter tables to fit the model definitions. - .sync() + .sync({ alter: doUpdate }) // will attempt to automatically alter tables to fit the model definitions. + // .sync() .then((result) => { console.log(`Database schema synced...`); initializeData(); diff --git a/backend/services/entryService.js b/backend/services/entryService.js index 309106c..1d7e362 100644 --- a/backend/services/entryService.js +++ b/backend/services/entryService.js @@ -515,7 +515,10 @@ async function refrechEntry(entryId) { if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' }); const updatedEntry = await Entry.findByPk(entryId, { - include: includes + include: includes, + order: [ + [{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list + ] }); const entryData = updatedEntry.get({ plain: true }); diff --git a/frontend/src/app/core/services/entry-seen.service.ts b/frontend/src/app/core/services/entry-seen.service.ts index 62b2666..92a1852 100644 --- a/frontend/src/app/core/services/entry-seen.service.ts +++ b/frontend/src/app/core/services/entry-seen.service.ts @@ -22,6 +22,16 @@ export class EntrySeenService { ); } + updateEntrySeen(entrySeen: EntrySeen) { + return this.http.put( + `${this.backend_apiUrl}/${this.apiAction}/${entrySeen.id}`, + { + date_seen: entrySeen.date_seen, + seen_with: entrySeen.seen_with, + } + ); + } + // get entry seen by entry id getEntrySeenById(id: string) { return this.http.get( diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.css b/frontend/src/app/features/entry/entry-page/entry-page.component.css index 47be8ba..50f55ee 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.css +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.css @@ -15,7 +15,7 @@ } .background-wrapper::after { - content: ''; + content: ""; position: absolute; top: 0; left: 0; @@ -25,13 +25,17 @@ z-index: 2; } -[data-bs-theme=dark] .background-wrapper::after { +[data-bs-theme="dark"] .background-wrapper::after { background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 60%, #181c1f 100%); } .content-wrapper { color: #212529; - background: linear-gradient(to bottom, rgba(255, 255, 255, 0.461) 10%, #eff1f3 100%); + background: linear-gradient( + to bottom, + rgba(255, 255, 255, 0.461) 10%, + #eff1f3 100% + ); backdrop-filter: blur(10px); padding: 20px; @@ -40,17 +44,15 @@ /* box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); */ } -[data-bs-theme=dark] .content-wrapper { +[data-bs-theme="dark"] .content-wrapper { color: #a7acb1; - background: linear-gradient(to bottom, rgba(33, - 37, - 41, - 0.7) 50%, #181c1f 100%); + background: linear-gradient( + to bottom, + rgba(33, 37, 41, 0.7) 50%, + #181c1f 100% + ); - background-color: rgba(33, - 37, - 41, - 0.7); + background-color: rgba(33, 37, 41, 0.7); border: 1px solid #181c1f; } @@ -79,7 +81,6 @@ margin: 10px 0; } - .side-info .list-group-item { background-color: rgba(255, 255, 255, 0.461) !important; background-color: transparent !important; @@ -96,7 +97,7 @@ font-size: 2.9rem !important; } -[data-bs-theme=dark] .title { +[data-bs-theme="dark"] .title { color: white; } @@ -105,7 +106,7 @@ font-size: 2rem; } -[data-bs-theme=dark] .right-col .entry-actions span { +[data-bs-theme="dark"] .right-col .entry-actions span { color: white; } @@ -158,9 +159,28 @@ } .faved { - font-variation-settings: - 'FILL' 1, - 'wght' 400, - 'GRAD' 0, - 'opsz' 24 -} \ No newline at end of file + font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; +} + +.info-item { + color: var(--shz-blue-default); +} + +.info-card { + background-color: transparent; + margin-bottom: 0; +} + +hr { + color: #ffffff; +} +.info-card hr { + margin-top: 5px; +} + +.info-card .accordion .accordion-item, +.info-card .accordion .accordion-header, +.info-card .accordion .accordion-header .accordion-button { + background-color: transparent; + border-radius: 0; +} diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.html b/frontend/src/app/features/entry/entry-page/entry-page.component.html index 3e8a0de..d0c517e 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.html +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.html @@ -14,7 +14,7 @@ - --> +
-
Watch History
+
Info

+
  • + Premiere: + {{this.entry.release_date | dateFormat:'MMM dd, yyyy'}} +
  • +
  • + Next Episode: + {{nextEpisode}} +
  • +
  • + Status: + {{status}} +
  • + +
    + +
  • + First Seen: + {{entry.date_first_seen | dateFormat:'MMM dd, yyyy'}} +
  • +
  • + Last Seen: + {{entry.date_last_seen | dateFormat:'MMM dd, yyyy'}} +
  • +
    +
    + +
    +
    +
    Rating
    +
    +
  • + TMDB Rating: + {{entry.entryRating.tmdb_rating | floatFormat:1}}/10 +
  • +
  • + IMDB Rating: + {{entry.entryRating.imdb_rating | floatFormat:1}}/10 +
  • +
  • + Rotten Romatoes: + {{entry.entryRating.rotten_tomatoes_rating | floatFormat:1}}/10 +
  • +
    +
    + + +
    +
    +
    Watch History
    +
    @@ -61,7 +108,11 @@ delete_forever - + +
    diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.ts b/frontend/src/app/features/entry/entry-page/entry-page.component.ts index dda9eee..d86bbf9 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.ts +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.ts @@ -18,6 +18,7 @@ import { EpisodeSeenService } from '../../../core/services/episode-seen.service' import { SeasonService } from '../../../core/services/season.service'; import { LibraryService } from '../../../core/services/library.service'; import { ToastrService } from 'ngx-toastr'; +import { EntrySeen } from '../../../shared/models/entrySeen.model'; @Component({ selector: 'app-entry-page', @@ -125,51 +126,6 @@ export class EntryPageComponent implements OnInit { this.getEpisodesSeenHistory(); } - openEntrySeenModal() { - if (!this.entry) return; - - const dialogRef = this.dialog.open(SeenModalComponent, { - width: '360px', - }); - - dialogRef.afterClosed().subscribe((result) => { - if (result) { - // console.log('Seen dialog closed with:', result); - - if (result.watchDate == '') { - // TODO show no was passed date notification - return; - } - - let watchDate = result.watchDate; - let watchedWith = result.watchedWith.split('\n').join(', '); - - this.entrySeenService - .createEntrySeen(this.entry.id.toString(), watchDate, watchedWith) - .subscribe({ - next: (entrySeen) => { - if (entrySeen) { - // TODO show confirm notification - // console.log(`EntrySeen Added`, entrySeen); - this.entry.entrySeen.push(entrySeen); - - if (this.entry.watchlist) { - this.libraryService.refrechEntries().subscribe(); - } - } - }, - error: (error) => { - console.error('Error adding entrySeen:', error); - }, - }); - - // TODO show notification - } else { - // console.log('Seen dialog was cancelled'); - } - }); - } - onRatingChange(event: Event) { this.entryRatingsService .updateEntryRatings(this.entry.entryRating) @@ -187,6 +143,88 @@ export class EntryPageComponent implements OnInit { }); } + // ! ENTRY SEEN + openEntrySeenModal(entrySeen: EntrySeen = {} as EntrySeen) { + if (!this.entry) return; + + let oldData = {} as { watchDate: Date; watchedWith: string }; + if (entrySeen.id) { + oldData.watchDate = entrySeen.date_seen; + oldData.watchedWith = entrySeen.seen_with; + } + const dialogRef = this.dialog.open(SeenModalComponent, { + width: '360px', + data: oldData.watchDate ? oldData : {}, + }); + + dialogRef.afterClosed().subscribe((result) => { + if (result) { + if (result.watchDate == '') { + // TODO show no was passed date notification + return; + } + + let watchDate = result.watchDate; + let watchedWith = result.watchedWith.split('\n').join(', '); + + if (entrySeen.id) { + const es = { + id: entrySeen.id, + date_seen: watchDate, + seen_with: watchedWith, + } as EntrySeen; + + // * Update + this.entrySeenService.updateEntrySeen(es).subscribe({ + next: (updatedEntrySeen) => { + if (updatedEntrySeen) { + // TODO show confirm notification + // ? replace the entry-seen object with the updated one + for (let i = 0; i < this.entry.entrySeen.length; i++) { + if (this.entry.entrySeen[i].id == updatedEntrySeen.id) + this.entry.entrySeen[i] = updatedEntrySeen; + } + } + }, + error: (error) => { + console.error('Error adding entrySeen:', error); + }, + }); + } else { + // * Create + this.entrySeenService + .createEntrySeen(this.entry.id.toString(), watchDate, watchedWith) + .subscribe({ + next: (entrySeen) => { + if (entrySeen) { + // TODO show confirm notification + this.entry.entrySeen.push(entrySeen); + + // ? if the entry was in watch list creating and entry-seen would have removed it + // ? from the watchlist, so now we need to refrech libraryService in order to + // ? update the watchlist page + if (this.entry.watchlist) { + this.libraryService.refrechEntries().subscribe(); + } + } + }, + error: (error) => { + console.error('Error adding entrySeen:', error); + }, + }); + } + + // TODO show notification + } else { + // console.log('Seen dialog was cancelled'); + } + }); + } + + editEntrySeen(entrySeen: EntrySeen) { + this.openEntrySeenModal(entrySeen); + } + removeEntrySeen(id: number) { const dialogRef = this.dialog.open(ConfirmModalComponent, { width: '400px', diff --git a/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts b/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts index 0711366..343f621 100644 --- a/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts +++ b/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts @@ -43,7 +43,7 @@ export class SeenModalComponent implements OnInit { ) {} ngOnInit(): void { - if (this.data == null) { + if (this.data.watchDate == null) { // ? no initial data was passed: populate date field with current date this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US'); } else {