diff --git a/backend/db/dataInitializer.js b/backend/db/dataInitializer.js index de1ba4a..33e93a1 100644 --- a/backend/db/dataInitializer.js +++ b/backend/db/dataInitializer.js @@ -1,8 +1,31 @@ +const { Sequelize } = require("sequelize"); +const Collection = require("../models/Collection"); const Genre = require("../models/Genre"); +const Media = require("../models/Media"); async function initializeData() { initializeGenres(); + + + // const collections = await Collection.findAll({ + // where: { + // posterPath: { [Sequelize.Op.notLike]: '/%' } + // } + // }); + + // collections.forEach(collection => { + // Media.create({ + // mediaable: 'collection', + // mediaableId: collection.id, + // type: 'poster', + // path: collection.posterPath, + // isLocal: true, + // isSelected: true + // }) + // }); + + // console.log(collections); } async function initializeGenres() { diff --git a/backend/models/Episode.js b/backend/models/Episode.js index f8f1492..24ddf94 100644 --- a/backend/models/Episode.js +++ b/backend/models/Episode.js @@ -17,8 +17,8 @@ const Episode = sequelize.define("episode", } }, - name: { type: DataTypes.STRING(200) }, - overview: { type: DataTypes.STRING(2000) }, + name: { type: DataTypes.STRING(500) }, + overview: { type: DataTypes.STRING(3000) }, episode_number: { type: DataTypes.INTEGER }, episode_type: { type: DataTypes.STRING(60) }, runtime: { type: DataTypes.INTEGER }, diff --git a/backend/models/Media.js b/backend/models/Media.js index 28838f1..cfdd33e 100644 --- a/backend/models/Media.js +++ b/backend/models/Media.js @@ -5,23 +5,16 @@ const Media = sequelize.define("media", { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, - // entryId: { - // type: DataTypes.INTEGER, - // references: { - // model: 'Entries', - // key: 'id' - // }, - // field: 'entry_id' - // }, - mediaable: { type: Sequelize.STRING }, mediaableId: { type: Sequelize.INTEGER, field: 'mediaable_id' }, type: { type: DataTypes.STRING(50) }, path: { type: DataTypes.STRING(200) }, + isLocal: { type: DataTypes.BOOLEAN, field: 'is_local' }, isSelected: { type: DataTypes.BOOLEAN, field: 'is_selected', defaultValue: false }, isCustom: { type: DataTypes.BOOLEAN, field: 'is_custom', defaultValue: false }, + isFavorit: { type: DataTypes.BOOLEAN, field: 'is_favorit', defaultValue: false }, } ); diff --git a/backend/models/Season.js b/backend/models/Season.js index 4269674..e56bf99 100644 --- a/backend/models/Season.js +++ b/backend/models/Season.js @@ -16,8 +16,8 @@ const Season = sequelize.define("season", } }, - name: { type: DataTypes.STRING(30) }, - overview: { type: DataTypes.STRING(1000) }, + name: { type: DataTypes.STRING(500) }, + overview: { type: DataTypes.STRING(3000) }, season_number: { type: DataTypes.INTEGER }, episode_count: { type: DataTypes.INTEGER }, air_date: { type: DataTypes.DATE }, diff --git a/backend/routes/media.routes.js b/backend/routes/media.routes.js index 81029dc..b3c861b 100644 --- a/backend/routes/media.routes.js +++ b/backend/routes/media.routes.js @@ -3,7 +3,7 @@ const path = require('path'); const fs = require('fs'); const { getSettings } = require('../services/settingsService'); -const { generatePreview, doGeneratePreview } = require('../services/mediaService'); +const { doGeneratePreview } = require('../services/mediaService'); const { logToFile } = require('../services/logService'); const mediaRouter = express.Router(); @@ -32,7 +32,7 @@ mediaRouter.get('/:category/:type/:size/:fileName', (req, res, next) => { // ? if so I make sure to change the extention to '_preview.jpg' (bcs all previews are jpg) let filePath = path.join(mediaPath, fileName); if (size == 'preview') { - const previewFileName = fileName.split('.')[0] + '_preview.jpg' + const previewFileName = fileName.split('.')[0] + (type == 'logos' ? '_preview.png' : '_preview.jpg') filePath = path.join(mediaPath, previewFileName); } diff --git a/backend/services/mediaService.js b/backend/services/mediaService.js index 1522273..d2a08d9 100644 --- a/backend/services/mediaService.js +++ b/backend/services/mediaService.js @@ -145,7 +145,7 @@ function doGeneratePreview(fileCategory, fileType, originalFileName, previewWidt const originalPath = path.join(mediaPath, originalFileName); const fileNameWithoutExt = originalFileName.split('.')[0]; - const previewFileName = fileNameWithoutExt + '_preview.jpg' + const previewFileName = fileNameWithoutExt + '_preview.jpg'; const previewPath = path.join(mediaPath, previewFileName); if (previewWidth == 0) { @@ -154,10 +154,16 @@ function doGeneratePreview(fileCategory, fileType, originalFileName, previewWidt if (fileType == 'logos') previewWidth = 300; } - return sharp(originalPath) - .resize({ width: previewWidth }) - .jpeg({ quality: previewQuality }) - .toFile(previewPath); + if (fileType == 'logos') { + return sharp(originalPath) + .resize({ width: previewWidth }) + .toFile(previewPath.replace('.jpg', '.png')); + } else { + return sharp(originalPath) + .resize({ width: previewWidth }) + .jpeg({ quality: previewQuality }) + .toFile(previewPath); + } } function getMediaFolder() { diff --git a/backend/services/models-services/entryService.js b/backend/services/models-services/entryService.js index 3319e61..5a591a7 100644 --- a/backend/services/models-services/entryService.js +++ b/backend/services/models-services/entryService.js @@ -336,14 +336,19 @@ async function refrechEntry(entryId) { { model: EntrySeen, as: 'entrySeen' }, { model: Season, as: 'seasons' }, { model: Media, as: 'medias' }, + { + model: Collection, as: 'collections', + include: [ + { model: Media, as: 'medias' } + ] + }, { model: Genre, as: 'genres', - attributes: ['id'], - through: { - attributes: [] - } } + ], + order: [ + [{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list ] }); @@ -437,7 +442,7 @@ async function refrechEntry(entryId) { await existingSeason.save(); } else { // Create a new season - await Season.create({ + existingSeason = await Season.create({ tmdb_id: seasonData.id, entry_id: oldEntry.id, name: seasonData.name, @@ -547,26 +552,46 @@ async function refrechEntry(entryId) { // + end of: refrech logic // ! returning the refreshed entry - let includes = [ - { model: EntryId, as: 'entryId' }, - { model: EntryRating, as: 'entryRating' }, - { model: EntrySeen, as: 'entrySeen' }, - { model: Season, as: 'seasons' }, - { model: Media, as: 'medias' }, - { model: Collection, as: 'collections' }, - { - model: Genre, - as: 'genres', - attributes: ['name'], - through: { - attributes: [] - } - } - ]; - if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' }); + // let includes = [ + // { model: EntryId, as: 'entryId' }, + // { model: EntryRating, as: 'entryRating' }, + // { model: EntrySeen, as: 'entrySeen' }, + // { model: Season, as: 'seasons' }, + // { model: Media, as: 'medias' }, + // { model: Collection, as: 'collections' }, + // { + // model: Genre, + // as: 'genres', + // attributes: ['name'], + // through: { + // attributes: [] + // } + // } + // ]; + // if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' }); const updatedEntry = await Entry.findByPk(entryId, { - include: includes, + include: [ + { model: EntryId, as: 'entryId' }, + { model: EntryRating, as: 'entryRating' }, + { model: EntrySeen, as: 'entrySeen' }, + { model: Season, as: 'seasons' }, + { model: Media, as: 'medias' }, + { + model: Collection, as: 'collections', + include: [ + { model: Media, as: 'medias' } + ] + }, + { + model: Genre, + as: 'genres', + attributes: ['name'], // Only fetch the genre ID + through: { + attributes: [] // Do not fetch any attributes from the join table + } + } + ], order: [ [{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list ] @@ -575,7 +600,7 @@ async function refrechEntry(entryId) { const plainEntry = updatedEntry.get({ plain: true }); plainEntry.genres = plainEntry.genres.map(genre => genre.name); - return entryData; + return plainEntry; } /** This function will refresh data of series that have the status not 'ended/canceled' and have not been refreshed today @@ -585,6 +610,7 @@ async function SyncSeriesData() { const entries = await Entry.findAll({ where: { is_tvseries: true, + autoSync: true, last_fetch: { [Op.ne]: today }, diff --git a/frontend/src/app/features/library/library-page/library-page.component.html b/frontend/src/app/features/library/library-page/library-page.component.html index 9c241b5..4eb44c9 100644 --- a/frontend/src/app/features/library/library-page/library-page.component.html +++ b/frontend/src/app/features/library/library-page/library-page.component.html @@ -19,7 +19,7 @@
-
+
-
+
Media Image diff --git a/frontend/src/app/shared/components/cards/main-card/main-card.component.html b/frontend/src/app/shared/components/cards/main-card/main-card.component.html index 06f41c2..be37b89 100644 --- a/frontend/src/app/shared/components/cards/main-card/main-card.component.html +++ b/frontend/src/app/shared/components/cards/main-card/main-card.component.html @@ -1,4 +1,5 @@ -
+
Movie Poster diff --git a/frontend/src/app/shared/components/cards/main-card/main-card.component.ts b/frontend/src/app/shared/components/cards/main-card/main-card.component.ts index 10e22ed..e3753ff 100644 --- a/frontend/src/app/shared/components/cards/main-card/main-card.component.ts +++ b/frontend/src/app/shared/components/cards/main-card/main-card.component.ts @@ -13,6 +13,7 @@ import { LibraryService } from '../../../../core/services/library.service'; import { Router } from '@angular/router'; import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal.component'; import { environment } from '../../../../../environments/environment.prod'; +import { CONTEXT_MENU_OPTIONS } from '../../../constants/context-menu-options'; @Component({ selector: 'app-main-card', @@ -251,4 +252,22 @@ export class MainCardComponent implements OnInit { if (this.entry.runtime == null) return ''; return this.entry.runtime; } + + get contextMenuOptions() { + let options = []; + + // ? 1 - is in library + if (this.entry.isInLibrary) { + if (this.entry.watchlist) { + options.push(CONTEXT_MENU_OPTIONS.removeFromWatchlist); + } else { + options.push(CONTEXT_MENU_OPTIONS.addToWatchlist); + } + } else { + // ? 2 - not in library + options.push(CONTEXT_MENU_OPTIONS.addToLibrary); + } + + return options; + } } diff --git a/frontend/src/app/shared/models/media.model.ts b/frontend/src/app/shared/models/media.model.ts index 0f4cc83..4b9a2c6 100644 --- a/frontend/src/app/shared/models/media.model.ts +++ b/frontend/src/app/shared/models/media.model.ts @@ -1,3 +1,4 @@ +import { Collection } from './collection.model'; import { Entry } from './entry.model'; export interface Media { @@ -7,12 +8,15 @@ export interface Media { mediaable: string; mediaableId: number; entry: Entry; + collection: Collection; type: string; path: string; isLocal: boolean; isSelected: boolean; + isCustom: boolean; + isFavorit: boolean; createdAt: Date; updatedAt: Date; diff --git a/frontend/src/app/shared/models/season.model.ts b/frontend/src/app/shared/models/season.model.ts index 47b1fb3..2d6ef6d 100644 --- a/frontend/src/app/shared/models/season.model.ts +++ b/frontend/src/app/shared/models/season.model.ts @@ -1,3 +1,4 @@ +import { Entry } from './entry.model'; import { Episode } from './episode.models'; export interface Season { @@ -9,6 +10,7 @@ export interface Season { imdb_id: string; entry_id: number; + entry: Entry; name: string; overview: string; diff --git a/frontend/src/app/shared/services/notification.service.ts b/frontend/src/app/shared/services/notification.service.ts deleted file mode 100644 index 1d189a1..0000000 --- a/frontend/src/app/shared/services/notification.service.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { - Injectable, - ComponentFactoryResolver, - ApplicationRef, - Injector, - EmbeddedViewRef, - ComponentRef, -} from '@angular/core'; -import { NotificationPopupComponent } from '../components/notification-popup/notification-popup.component'; - -@Injectable({ - providedIn: 'root', -}) -export class NotificationService { - private notificationComponents: ComponentRef[] = - []; - private notificationBottomMargin = 10; // Margin between notifications - private baseBottomPosition = 20; // Starting bottom position for the first notification - - constructor( - private componentFactoryResolver: ComponentFactoryResolver, - private appRef: ApplicationRef, - private injector: Injector - ) {} - - public showNotification( - title: string, - message: string, - type: string = 'alert', - timeout: number = 5000 - ): void { - // Create a component reference for the notification - const componentRef = this.componentFactoryResolver - .resolveComponentFactory(NotificationPopupComponent) - .create(this.injector); - - // Assign the message and type to the instance - componentRef.instance.title = title; - componentRef.instance.message = message; - componentRef.instance.type = type; - - // Attach the component to the application - this.appRef.attachView(componentRef.hostView); - - // Convert the component's host view into a DOM element and append it to the body - const domElem = (componentRef.hostView as EmbeddedViewRef) - .rootNodes[0] as HTMLElement; - document.body.appendChild(domElem); - - const position = - this.baseBottomPosition + - this.notificationComponents.length * - (domElem.offsetHeight + this.notificationBottomMargin); - domElem.style.bottom = `${position}px`; - domElem.style.position = 'fixed'; - domElem.style.right = '20px'; - - // Store the component reference for later removal - this.notificationComponents.push(componentRef); - - // Remove the notification after a delay - setTimeout(() => { - domElem.style.visibility = 'hidden'; - }, timeout); - - setTimeout(() => { - this.removeNotification(componentRef); - }, timeout + 1000); // Customize this value as needed - } - - // private removeNotification( - // componentRef: ComponentRef - // ): void { - // this.appRef.detachView(componentRef.hostView); - // componentRef.destroy(); - // this.notificationComponents = this.notificationComponents.filter( - // (c) => c !== componentRef - // ); - // } - - private removeNotification( - componentRef: ComponentRef - ): void { - const domElem = (componentRef.hostView as EmbeddedViewRef) - .rootNodes[0] as HTMLElement; - this.appRef.detachView(componentRef.hostView); - document.body.removeChild(domElem); // Make sure to remove the element from the body - componentRef.destroy(); - // Filter out the destroyed notification - this.notificationComponents = this.notificationComponents.filter( - (c) => c !== componentRef - ); - - // Adjust positions of remaining notifications - this.adjustPositions(); - } - - private adjustPositions(): void { - // Start from the initial position again and reposition each remaining notification - this.notificationComponents.forEach((componentRef, index) => { - const domElem = (componentRef.hostView as EmbeddedViewRef) - .rootNodes[0] as HTMLElement; - const position = - this.baseBottomPosition + - index * (domElem.offsetHeight + this.notificationBottomMargin); - domElem.style.bottom = `${position}px`; - }); - } -} diff --git a/frontend/src/app/shared/services/toast.service.ts b/frontend/src/app/shared/services/toast.service.ts new file mode 100644 index 0000000..821451e --- /dev/null +++ b/frontend/src/app/shared/services/toast.service.ts @@ -0,0 +1,43 @@ +import { Injectable } from '@angular/core'; +import { ProgressAnimationType, ToastrService } from 'ngx-toastr'; + +@Injectable({ + providedIn: 'root', +}) +export class ToastService { + constructor(private toastr: ToastrService) {} + + public show(title: string, message: string, type: string = 'success'): void { + const options = { + tapToDismiss: true, + progressBar: true, + positionClass: 'top-right', + progressAnimation: 'increasing' as ProgressAnimationType, + }; + + if (type == 'success') this.toastr.show(title, message, options); + else if (type == 'error') this.toastr.error(title, message, options); + else if (type == 'warning') this.toastr.warning(title, message, options); + else if (type == 'info') this.toastr.info(title, message, options); + } + + public showWithOptions( + title: string, + message: string, + type: string = 'success', + extraOptions: any + ): void { + const options = { + tapToDismiss: true, + progressBar: true, + positionClass: 'top-right', + progressAnimation: 'increasing' as ProgressAnimationType, + ...extraOptions, + }; + + if (type == 'success') this.toastr.success(title, message, options); + else if (type == 'error') this.toastr.error(title, message, options); + else if (type == 'warning') this.toastr.warning(title, message, options); + else if (type == 'info') this.toastr.info(title, message, options); + } +} diff --git a/frontend/src/styles.css b/frontend/src/styles.css index a7af772..8c4fe25 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -39,4 +39,37 @@ --shz-green-success: #02c27a; +} + +/* table border lines */ +[data-bs-theme=dark] body .fc-scrollgrid, +[data-bs-theme=dark] body .fc-day { + border-color: #878d96; +} + + +/* buttons */ +[data-bs-theme=dark] body .fc-button, +[data-bs-theme=dark] body .fc-today-button { + background-color: #2c3034; + border-color: #2c3034; +} + +[data-bs-theme=dark] body .fc-prev-button:hover, +[data-bs-theme=dark] body .fc-next-button:hover, +[data-bs-theme=dark] body .fc-today-button:enabled { + background-color: #383c40; + border-color: #383c40; +} + + +[data-bs-theme=dark] body .fc-today-button:disabled { + background-color: #343a40; + border-color: #343a40; +} + + +/* calendar header */ +[data-bs-theme=dark] body .fc-col-header { + background-color: #212529; } \ No newline at end of file