Random changes
This commit is contained in:
1 parent
7160669468
commit
0b1a1d989f
17 files changed
+192
-146
No files matched your search
@@ -1,8 +1,31 @@
|
|||||||
|
const { Sequelize } = require("sequelize");
|
||||||
|
const Collection = require("../models/Collection");
|
||||||
const Genre = require("../models/Genre");
|
const Genre = require("../models/Genre");
|
||||||
|
const Media = require("../models/Media");
|
||||||
|
|
||||||
|
|
||||||
async function initializeData() {
|
async function initializeData() {
|
||||||
initializeGenres();
|
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() {
|
async function initializeGenres() {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ const Episode = sequelize.define("episode",
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
name: { type: DataTypes.STRING(200) },
|
name: { type: DataTypes.STRING(500) },
|
||||||
overview: { type: DataTypes.STRING(2000) },
|
overview: { type: DataTypes.STRING(3000) },
|
||||||
episode_number: { type: DataTypes.INTEGER },
|
episode_number: { type: DataTypes.INTEGER },
|
||||||
episode_type: { type: DataTypes.STRING(60) },
|
episode_type: { type: DataTypes.STRING(60) },
|
||||||
runtime: { type: DataTypes.INTEGER },
|
runtime: { type: DataTypes.INTEGER },
|
||||||
|
|||||||
@@ -5,23 +5,16 @@ const Media = sequelize.define("media",
|
|||||||
{
|
{
|
||||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||||
|
|
||||||
// entryId: {
|
|
||||||
// type: DataTypes.INTEGER,
|
|
||||||
// references: {
|
|
||||||
// model: 'Entries',
|
|
||||||
// key: 'id'
|
|
||||||
// },
|
|
||||||
// field: 'entry_id'
|
|
||||||
// },
|
|
||||||
|
|
||||||
mediaable: { type: Sequelize.STRING },
|
mediaable: { type: Sequelize.STRING },
|
||||||
mediaableId: { type: Sequelize.INTEGER, field: 'mediaable_id' },
|
mediaableId: { type: Sequelize.INTEGER, field: 'mediaable_id' },
|
||||||
|
|
||||||
type: { type: DataTypes.STRING(50) },
|
type: { type: DataTypes.STRING(50) },
|
||||||
path: { type: DataTypes.STRING(200) },
|
path: { type: DataTypes.STRING(200) },
|
||||||
|
|
||||||
isLocal: { type: DataTypes.BOOLEAN, field: 'is_local' },
|
isLocal: { type: DataTypes.BOOLEAN, field: 'is_local' },
|
||||||
isSelected: { type: DataTypes.BOOLEAN, field: 'is_selected', defaultValue: false },
|
isSelected: { type: DataTypes.BOOLEAN, field: 'is_selected', defaultValue: false },
|
||||||
isCustom: { type: DataTypes.BOOLEAN, field: 'is_custom', defaultValue: false },
|
isCustom: { type: DataTypes.BOOLEAN, field: 'is_custom', defaultValue: false },
|
||||||
|
isFavorit: { type: DataTypes.BOOLEAN, field: 'is_favorit', defaultValue: false },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ const Season = sequelize.define("season",
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
name: { type: DataTypes.STRING(30) },
|
name: { type: DataTypes.STRING(500) },
|
||||||
overview: { type: DataTypes.STRING(1000) },
|
overview: { type: DataTypes.STRING(3000) },
|
||||||
season_number: { type: DataTypes.INTEGER },
|
season_number: { type: DataTypes.INTEGER },
|
||||||
episode_count: { type: DataTypes.INTEGER },
|
episode_count: { type: DataTypes.INTEGER },
|
||||||
air_date: { type: DataTypes.DATE },
|
air_date: { type: DataTypes.DATE },
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const { getSettings } = require('../services/settingsService');
|
const { getSettings } = require('../services/settingsService');
|
||||||
const { generatePreview, doGeneratePreview } = require('../services/mediaService');
|
const { doGeneratePreview } = require('../services/mediaService');
|
||||||
const { logToFile } = require('../services/logService');
|
const { logToFile } = require('../services/logService');
|
||||||
|
|
||||||
const mediaRouter = express.Router();
|
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)
|
// ? if so I make sure to change the extention to '_preview.jpg' (bcs all previews are jpg)
|
||||||
let filePath = path.join(mediaPath, fileName);
|
let filePath = path.join(mediaPath, fileName);
|
||||||
if (size == 'preview') {
|
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);
|
filePath = path.join(mediaPath, previewFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ function doGeneratePreview(fileCategory, fileType, originalFileName, previewWidt
|
|||||||
const originalPath = path.join(mediaPath, originalFileName);
|
const originalPath = path.join(mediaPath, originalFileName);
|
||||||
|
|
||||||
const fileNameWithoutExt = originalFileName.split('.')[0];
|
const fileNameWithoutExt = originalFileName.split('.')[0];
|
||||||
const previewFileName = fileNameWithoutExt + '_preview.jpg'
|
const previewFileName = fileNameWithoutExt + '_preview.jpg';
|
||||||
const previewPath = path.join(mediaPath, previewFileName);
|
const previewPath = path.join(mediaPath, previewFileName);
|
||||||
|
|
||||||
if (previewWidth == 0) {
|
if (previewWidth == 0) {
|
||||||
@@ -154,10 +154,16 @@ function doGeneratePreview(fileCategory, fileType, originalFileName, previewWidt
|
|||||||
if (fileType == 'logos') previewWidth = 300;
|
if (fileType == 'logos') previewWidth = 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileType == 'logos') {
|
||||||
|
return sharp(originalPath)
|
||||||
|
.resize({ width: previewWidth })
|
||||||
|
.toFile(previewPath.replace('.jpg', '.png'));
|
||||||
|
} else {
|
||||||
return sharp(originalPath)
|
return sharp(originalPath)
|
||||||
.resize({ width: previewWidth })
|
.resize({ width: previewWidth })
|
||||||
.jpeg({ quality: previewQuality })
|
.jpeg({ quality: previewQuality })
|
||||||
.toFile(previewPath);
|
.toFile(previewPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMediaFolder() {
|
function getMediaFolder() {
|
||||||
|
|||||||
@@ -336,14 +336,19 @@ async function refrechEntry(entryId) {
|
|||||||
{ model: EntrySeen, as: 'entrySeen' },
|
{ model: EntrySeen, as: 'entrySeen' },
|
||||||
{ model: Season, as: 'seasons' },
|
{ model: Season, as: 'seasons' },
|
||||||
{ model: Media, as: 'medias' },
|
{ model: Media, as: 'medias' },
|
||||||
|
{
|
||||||
|
model: Collection, as: 'collections',
|
||||||
|
include: [
|
||||||
|
{ model: Media, as: 'medias' }
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
model: Genre,
|
model: Genre,
|
||||||
as: 'genres',
|
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();
|
await existingSeason.save();
|
||||||
} else {
|
} else {
|
||||||
// Create a new season
|
// Create a new season
|
||||||
await Season.create({
|
existingSeason = await Season.create({
|
||||||
tmdb_id: seasonData.id,
|
tmdb_id: seasonData.id,
|
||||||
entry_id: oldEntry.id,
|
entry_id: oldEntry.id,
|
||||||
name: seasonData.name,
|
name: seasonData.name,
|
||||||
@@ -547,26 +552,46 @@ async function refrechEntry(entryId) {
|
|||||||
// + end of: refrech logic
|
// + end of: refrech logic
|
||||||
|
|
||||||
// ! returning the refreshed entry
|
// ! returning the refreshed entry
|
||||||
let includes = [
|
// 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: [
|
||||||
{ model: EntryId, as: 'entryId' },
|
{ model: EntryId, as: 'entryId' },
|
||||||
{ model: EntryRating, as: 'entryRating' },
|
{ model: EntryRating, as: 'entryRating' },
|
||||||
{ model: EntrySeen, as: 'entrySeen' },
|
{ model: EntrySeen, as: 'entrySeen' },
|
||||||
{ model: Season, as: 'seasons' },
|
{ model: Season, as: 'seasons' },
|
||||||
{ model: Media, as: 'medias' },
|
{ model: Media, as: 'medias' },
|
||||||
{ model: Collection, as: 'collections' },
|
{
|
||||||
|
model: Collection, as: 'collections',
|
||||||
|
include: [
|
||||||
|
{ model: Media, as: 'medias' }
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
model: Genre,
|
model: Genre,
|
||||||
as: 'genres',
|
as: 'genres',
|
||||||
attributes: ['name'],
|
attributes: ['name'], // Only fetch the genre ID
|
||||||
through: {
|
through: {
|
||||||
attributes: []
|
attributes: [] // Do not fetch any attributes from the join table
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
],
|
||||||
if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' });
|
|
||||||
|
|
||||||
const updatedEntry = await Entry.findByPk(entryId, {
|
|
||||||
include: includes,
|
|
||||||
order: [
|
order: [
|
||||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
[{ 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 });
|
const plainEntry = updatedEntry.get({ plain: true });
|
||||||
plainEntry.genres = plainEntry.genres.map(genre => genre.name);
|
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
|
/** 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({
|
const entries = await Entry.findAll({
|
||||||
where: {
|
where: {
|
||||||
is_tvseries: true,
|
is_tvseries: true,
|
||||||
|
autoSync: true,
|
||||||
last_fetch: {
|
last_fetch: {
|
||||||
[Op.ne]: today
|
[Op.ne]: today
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<!-- filter -->
|
<!-- filter -->
|
||||||
|
|
||||||
<div class="d-flex align-items-baseline gap-3 flex-wrap">
|
<div class="d-flex align-items-baseline gap-3 flex-wrap">
|
||||||
<div class="product-count d-flex align-items-center gap-3 gap-lg-4 mb-4 fw-medium flex-wrap font-text1">
|
<div class="product-count d-flex align-items-center gap-3 gap-lg-4 mb-3 fw-medium flex-wrap font-text1">
|
||||||
<a href="javascript:;" (click)="onEntryTypeChange(0)"><span class="me-1">All</span><span
|
<a href="javascript:;" (click)="onEntryTypeChange(0)"><span class="me-1">All</span><span
|
||||||
class="text-secondary">({{entries.length}})</span></a>
|
class="text-secondary">({{entries.length}})</span></a>
|
||||||
<a href="javascript:;" (click)="onEntryTypeChange(1)"><span class="me-1">Movies</span><span
|
<a href="javascript:;" (click)="onEntryTypeChange(1)"><span class="me-1">Movies</span><span
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
|
import { AfterViewInit, Component, OnInit } from '@angular/core';
|
||||||
import { Entry } from '../../../shared/models/entry.model';
|
import { Entry } from '../../../shared/models/entry.model';
|
||||||
import { LibraryService } from '../../../core/services/library.service';
|
import { LibraryService } from '../../../core/services/library.service';
|
||||||
import { ActivatedRoute, Event, NavigationEnd, Router } from '@angular/router';
|
import { ActivatedRoute, Event, Router } from '@angular/router';
|
||||||
import { LibraryQueryParams } from '../../../shared/models/library-query-params';
|
import { LibraryQueryParams } from '../../../shared/models/library-query-params';
|
||||||
import { SettingsService } from '../../../core/services/settings.service';
|
import { SettingsService } from '../../../core/services/settings.service';
|
||||||
import { Settings } from '../../../shared/models/settings.model';
|
import { Settings } from '../../../shared/models/settings.model';
|
||||||
import { ValueSetter } from 'date-fns/parse/_lib/Setter';
|
|
||||||
|
|
||||||
declare var $: any;
|
declare var $: any;
|
||||||
@Component({
|
@Component({
|
||||||
@@ -267,6 +266,7 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
|||||||
|
|
||||||
const formattedTitle =
|
const formattedTitle =
|
||||||
this.filterCriteria.title?.toLowerCase().trim() || '';
|
this.filterCriteria.title?.toLowerCase().trim() || '';
|
||||||
|
|
||||||
temp = await this.entries.filter((entry) => {
|
temp = await this.entries.filter((entry) => {
|
||||||
// * Type check
|
// * Type check
|
||||||
let filterType = this.filterCriteria.type - 1 == 0 ? false : true;
|
let filterType = this.filterCriteria.type - 1 == 0 ? false : true;
|
||||||
@@ -308,6 +308,10 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
|||||||
? entry.title.toLowerCase().includes(formattedTitle) ||
|
? entry.title.toLowerCase().includes(formattedTitle) ||
|
||||||
entry.original_title.toLowerCase().includes(formattedTitle)
|
entry.original_title.toLowerCase().includes(formattedTitle)
|
||||||
: true) ||
|
: true) ||
|
||||||
|
(entry.network_studio
|
||||||
|
? entry.network_studio.toLowerCase() ==
|
||||||
|
formattedTitle.replace('studio:', '')
|
||||||
|
: true) ||
|
||||||
(this.filterCriteria.genres?.length &&
|
(this.filterCriteria.genres?.length &&
|
||||||
this.filterCriteria.genres.some((genre) =>
|
this.filterCriteria.genres.some((genre) =>
|
||||||
entry.genres.includes(genre)
|
entry.genres.includes(genre)
|
||||||
@@ -319,6 +323,7 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(temp);
|
||||||
// ? sort filter
|
// ? sort filter
|
||||||
temp = await this.sortEntries(temp);
|
temp = await this.sortEntries(temp);
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade" id="logos-content" role="tabpanel">
|
<div class="tab-pane fade" id="logos-content" role="tabpanel">
|
||||||
<div class="row row-cols-1 row-cols-md-2 g-4">
|
<div class="row row-cols-1 row-cols-md-5 g-4">
|
||||||
<div class="col" *ngFor="let media of filterMedia('logo')">
|
<div class="col" *ngFor="let media of filterMedia('logo')">
|
||||||
<div class="card image-hover-container">
|
<div class="card image-hover-container">
|
||||||
<img [src]="getPath('logos', media)" class="card-img-top" alt="Media Image">
|
<img [src]="getPath('logos', media)" class="card-img-top" alt="Media Image">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="movie-card" [@fadeInOut]="animationDirection">
|
<div class="movie-card" [@fadeInOut]="animationDirection" appContextMenuTrigger
|
||||||
|
[menuOptions]="contextMenuOptions">
|
||||||
<div class="card-head">
|
<div class="card-head">
|
||||||
<img class="card-img" [src]="posterPath" alt="Movie Poster"
|
<img class="card-img" [src]="posterPath" alt="Movie Poster"
|
||||||
onerror="this.src='assets/images/default/default-poster.png'">
|
onerror="this.src='assets/images/default/default-poster.png'">
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { LibraryService } from '../../../../core/services/library.service';
|
|||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal.component';
|
import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal.component';
|
||||||
import { environment } from '../../../../../environments/environment.prod';
|
import { environment } from '../../../../../environments/environment.prod';
|
||||||
|
import { CONTEXT_MENU_OPTIONS } from '../../../constants/context-menu-options';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-main-card',
|
selector: 'app-main-card',
|
||||||
@@ -251,4 +252,22 @@ export class MainCardComponent implements OnInit {
|
|||||||
if (this.entry.runtime == null) return '';
|
if (this.entry.runtime == null) return '';
|
||||||
return this.entry.runtime;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Collection } from './collection.model';
|
||||||
import { Entry } from './entry.model';
|
import { Entry } from './entry.model';
|
||||||
|
|
||||||
export interface Media {
|
export interface Media {
|
||||||
@@ -7,12 +8,15 @@ export interface Media {
|
|||||||
mediaable: string;
|
mediaable: string;
|
||||||
mediaableId: number;
|
mediaableId: number;
|
||||||
entry: Entry;
|
entry: Entry;
|
||||||
|
collection: Collection;
|
||||||
|
|
||||||
type: string;
|
type: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
|
||||||
isLocal: boolean;
|
isLocal: boolean;
|
||||||
isSelected: boolean;
|
isSelected: boolean;
|
||||||
|
isCustom: boolean;
|
||||||
|
isFavorit: boolean;
|
||||||
|
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Entry } from './entry.model';
|
||||||
import { Episode } from './episode.models';
|
import { Episode } from './episode.models';
|
||||||
|
|
||||||
export interface Season {
|
export interface Season {
|
||||||
@@ -9,6 +10,7 @@ export interface Season {
|
|||||||
imdb_id: string;
|
imdb_id: string;
|
||||||
|
|
||||||
entry_id: number;
|
entry_id: number;
|
||||||
|
entry: Entry;
|
||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
overview: string;
|
overview: string;
|
||||||
|
|||||||
@@ -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<NotificationPopupComponent>[] =
|
|
||||||
[];
|
|
||||||
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<any>)
|
|
||||||
.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<NotificationPopupComponent>
|
|
||||||
// ): void {
|
|
||||||
// this.appRef.detachView(componentRef.hostView);
|
|
||||||
// componentRef.destroy();
|
|
||||||
// this.notificationComponents = this.notificationComponents.filter(
|
|
||||||
// (c) => c !== componentRef
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
private removeNotification(
|
|
||||||
componentRef: ComponentRef<NotificationPopupComponent>
|
|
||||||
): void {
|
|
||||||
const domElem = (componentRef.hostView as EmbeddedViewRef<any>)
|
|
||||||
.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<any>)
|
|
||||||
.rootNodes[0] as HTMLElement;
|
|
||||||
const position =
|
|
||||||
this.baseBottomPosition +
|
|
||||||
index * (domElem.offsetHeight + this.notificationBottomMargin);
|
|
||||||
domElem.style.bottom = `${position}px`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,3 +40,36 @@
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user