add entry media upload menu
This commit is contained in:
1 parent
4c318fb569
commit
c46309e458
14 files changed
+616
-2
No files matched your search
@@ -13,6 +13,7 @@ const EntrySeen = require('../models/EntrySeen');
|
|||||||
const Season = require('../models/Season');
|
const Season = require('../models/Season');
|
||||||
const Media = require('../models/Media');
|
const Media = require('../models/Media');
|
||||||
const Episode = require('../models/Episode');
|
const Episode = require('../models/Episode');
|
||||||
|
const { entryPicturesUpload } = require('../services/mutlerStorageLocations');
|
||||||
|
|
||||||
// ! /entries
|
// ! /entries
|
||||||
|
|
||||||
@@ -304,6 +305,101 @@ entryRouter.get('/:id/refrech', async (req, res, next) => {
|
|||||||
// res.status(201).json(entryData);
|
// res.status(201).json(entryData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const upload = entryPicturesUpload.fields([
|
||||||
|
{ name: 'poster', maxCount: 1 },
|
||||||
|
{ name: 'backdrop', maxCount: 1 },
|
||||||
|
{ name: 'logo', maxCount: 1 }
|
||||||
|
]);
|
||||||
|
entryRouter.post('/:id/media', upload, async (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
if (req.files) {
|
||||||
|
|
||||||
|
const entry = await Entry.findByPk(id);
|
||||||
|
if (!entry) {
|
||||||
|
return res.status(404).json({ message: 'Entry not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const posterPath = req.files.poster ? req.files.poster[0].filename : null;
|
||||||
|
if (posterPath) {
|
||||||
|
const createdMedia = await Media.create({
|
||||||
|
entry_id: id,
|
||||||
|
type: 'poster',
|
||||||
|
path: posterPath,
|
||||||
|
is_local: true,
|
||||||
|
is_selected: false,
|
||||||
|
});
|
||||||
|
return res.status(200).json(createdMedia);
|
||||||
|
}
|
||||||
|
|
||||||
|
const backdropPath = req.files.backdrop ? req.files.backdrop[0].filename : null;
|
||||||
|
if (backdropPath) {
|
||||||
|
const createdMedia = await Media.create({
|
||||||
|
entry_id: id,
|
||||||
|
type: 'backdrop',
|
||||||
|
path: backdropPath,
|
||||||
|
is_local: true,
|
||||||
|
is_selected: false,
|
||||||
|
});
|
||||||
|
return res.status(200).json(createdMedia);
|
||||||
|
}
|
||||||
|
|
||||||
|
const logoPath = req.files.logo ? req.files.logo[0].filename : null;
|
||||||
|
if (logoPath) {
|
||||||
|
const createdMedia = await Media.create({
|
||||||
|
entry_id: id,
|
||||||
|
type: 'logo',
|
||||||
|
path: logoPath,
|
||||||
|
is_local: true,
|
||||||
|
is_selected: false,
|
||||||
|
});
|
||||||
|
return res.status(200).json(createdMedia);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
entryRouter.put('/:entryId/media/:mediaId', upload, async (req, res) => {
|
||||||
|
const entryId = req.params.entryId;
|
||||||
|
const mediaId = req.params.mediaId;
|
||||||
|
|
||||||
|
const entry = await Entry.findByPk(entryId);
|
||||||
|
if (!entry) {
|
||||||
|
return res.status(404).json({ message: 'Entry not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const media = await Media.findByPk(mediaId);
|
||||||
|
if (!media) {
|
||||||
|
return res.status(404).json({ message: 'Media not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
await Media.update(
|
||||||
|
{ is_selected: false },
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
entry_id: entryId,
|
||||||
|
type: media.type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const updatedMedia = await media.update({ is_selected: true });
|
||||||
|
|
||||||
|
return res.status(200).json(updatedMedia);
|
||||||
|
});
|
||||||
|
|
||||||
|
entryRouter.delete('/:entryId/media/:mediaId', async (req, res) => {
|
||||||
|
const mediaId = req.params.mediaId;
|
||||||
|
|
||||||
|
// const media = await Media.findByPk(mediaId);
|
||||||
|
// if (!media) {
|
||||||
|
// return res.status(404).json({ message: 'Media not found' });
|
||||||
|
// }
|
||||||
|
|
||||||
|
await Media.destroy({ where: { id: mediaId } })
|
||||||
|
|
||||||
|
res.status(200).json();
|
||||||
|
});
|
||||||
|
|
||||||
// * DELETE - ENTRY BY ID
|
// * DELETE - ENTRY BY ID
|
||||||
entryRouter.delete('/:id', async (req, res) => {
|
entryRouter.delete('/:id', async (req, res) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
const multer = require('multer');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
const path = require('path');
|
||||||
|
const { getSettings } = require('./settingsService');
|
||||||
|
|
||||||
|
// ? users
|
||||||
|
const entryPicturesUpload = multer({
|
||||||
|
storage:
|
||||||
|
multer.diskStorage({
|
||||||
|
destination: function (req, file, cb) {
|
||||||
|
let folder = 'posters';
|
||||||
|
if (file.fieldname == 'banner') folder = 'backdrops';
|
||||||
|
if (file.fieldname == 'logo') folder = 'logos';
|
||||||
|
|
||||||
|
const settings = getSettings();
|
||||||
|
const dataPath = settings.userDataPath;
|
||||||
|
|
||||||
|
cb(null, path.join(dataPath, 'images', 'entries', folder));
|
||||||
|
},
|
||||||
|
filename: function (req, file, cb) {
|
||||||
|
const uniqueFilename = uuidv4();
|
||||||
|
const extension = file.originalname.split('.').pop();
|
||||||
|
cb(null, `${uniqueFilename}.${extension}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entryPicturesUpload,
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import { Entry } from '../../shared/models/entry.model';
|
|||||||
import { EntryId } from '../../shared/models/entryId.model';
|
import { EntryId } from '../../shared/models/entryId.model';
|
||||||
import { EntryRating } from '../../shared/models/entryRating.model';
|
import { EntryRating } from '../../shared/models/entryRating.model';
|
||||||
import { environment } from '../../../environments/environment.prod';
|
import { environment } from '../../../environments/environment.prod';
|
||||||
|
import { Media } from '../../shared/models/media.model';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@@ -41,6 +42,26 @@ export class EntryService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addEntryMedia(entryId: number, data: FormData): Observable<Media> {
|
||||||
|
return this.http.post<Media>(
|
||||||
|
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/media`,
|
||||||
|
data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectEntryMedia(entryId: number, mediaId: number): Observable<Media> {
|
||||||
|
return this.http.put<Media>(
|
||||||
|
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/media/${mediaId}`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteEntryMedia(entryId: number, mediaId: number): Observable<void> {
|
||||||
|
return this.http.delete<void>(
|
||||||
|
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/media/${mediaId}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// update entry
|
// update entry
|
||||||
refrechEntryById(entryId: number) {
|
refrechEntryById(entryId: number) {
|
||||||
return this.http.get<Entry>(
|
return this.http.get<Entry>(
|
||||||
|
|||||||
@@ -5,9 +5,16 @@ import { EntryPageComponent } from './entry-page/entry-page.component';
|
|||||||
import { EntriesRoutingModule } from './entries-routing.module';
|
import { EntriesRoutingModule } from './entries-routing.module';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { SeasonMainCardComponent } from './season-main-card/season-main-card.component';
|
import { SeasonMainCardComponent } from './season-main-card/season-main-card.component';
|
||||||
|
import { MediaModalComponent } from './media-modal/media-modal.component';
|
||||||
|
import { MediaUploadModalComponent } from './media-upload-modal/media-upload-modal.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [EntryPageComponent, SeasonMainCardComponent],
|
declarations: [
|
||||||
|
EntryPageComponent,
|
||||||
|
SeasonMainCardComponent,
|
||||||
|
MediaModalComponent,
|
||||||
|
MediaUploadModalComponent,
|
||||||
|
],
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
SharedModule,
|
SharedModule,
|
||||||
|
|||||||
@@ -160,6 +160,12 @@
|
|||||||
update
|
update
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button class="btn btn-icon-only-success wh-48" (click)="mediaModal()">
|
||||||
|
<span class="material-symbols-outlined">
|
||||||
|
image
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<!-- End Interraction buttons -->
|
<!-- End Interraction buttons -->
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { LibraryService } from '../../../core/services/library.service';
|
|||||||
import { ToastrService } from 'ngx-toastr';
|
import { ToastrService } from 'ngx-toastr';
|
||||||
import { EntrySeen } from '../../../shared/models/entrySeen.model';
|
import { EntrySeen } from '../../../shared/models/entrySeen.model';
|
||||||
import { EpisodeSeenModalComponent } from '../../../shared/components/modals/episode-seen-modal/episode-seen-modal.component';
|
import { EpisodeSeenModalComponent } from '../../../shared/components/modals/episode-seen-modal/episode-seen-modal.component';
|
||||||
|
import { MediaModalComponent } from '../media-modal/media-modal.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-entry-page',
|
selector: 'app-entry-page',
|
||||||
@@ -205,7 +206,7 @@ export class EntryPageComponent implements OnInit {
|
|||||||
// ? from the watchlist, so now we need to refrech libraryService in order to
|
// ? from the watchlist, so now we need to refrech libraryService in order to
|
||||||
// ? update the watchlist page
|
// ? update the watchlist page
|
||||||
if (this.entry.watchlist) {
|
if (this.entry.watchlist) {
|
||||||
this.libraryService.refrechEntries().subscribe();
|
this.libraryService.refreshEntries().subscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -608,6 +609,26 @@ export class EntryPageComponent implements OnInit {
|
|||||||
window.open(poster, '_blank');
|
window.open(poster, '_blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mediaModal() {
|
||||||
|
const dialogRef = this.dialog.open(MediaModalComponent, {
|
||||||
|
width: '800px',
|
||||||
|
height: '600px',
|
||||||
|
minHeight: '50%',
|
||||||
|
panelClass: 'media-dialog-container',
|
||||||
|
data: {
|
||||||
|
entry: this.entry,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogRef.afterClosed().subscribe((result) => {
|
||||||
|
if (result) {
|
||||||
|
// TODO show notification
|
||||||
|
} else {
|
||||||
|
// console.log('Seen dialog was cancelled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// * getters
|
// * getters
|
||||||
get status() {
|
get status() {
|
||||||
return this.entry.status;
|
return this.entry.status;
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
.media-dialog-container {
|
||||||
|
height: 100%;
|
||||||
|
padding-bottom: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-dialog-main {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
width: 100%;
|
||||||
|
height: 100% !important;
|
||||||
|
overflow-y: auto !important;
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-body {
|
||||||
|
height: auto !important;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-dialog-main #posters .card-img-top {
|
||||||
|
height: auto;
|
||||||
|
/* Height should adjust to maintain aspect ratio */
|
||||||
|
width: 100%;
|
||||||
|
aspect-ratio: 2 / 3;
|
||||||
|
/* Using the aspect-ratio property to specify a 2:3 ratio */
|
||||||
|
object-fit: cover;
|
||||||
|
/* Crop to cover the area of the container */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Banner images */
|
||||||
|
.media-dialog-main #banners .card-img-top {
|
||||||
|
height: auto;
|
||||||
|
width: 100%;
|
||||||
|
aspect-ratio: 8 / 3;
|
||||||
|
/* An example ratio for wide banners */
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Logo images */
|
||||||
|
.media-dialog-main #logos .card-img-top {
|
||||||
|
height: auto;
|
||||||
|
width: 100%;
|
||||||
|
aspect-ratio: 2 / 1;
|
||||||
|
/* More wide than tall for logos */
|
||||||
|
object-fit: contain;
|
||||||
|
/* Ensure the entire logo is visible */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.media-dialog-main .card .card-img-top {
|
||||||
|
display: block;
|
||||||
|
/* Ensure images are block elements to fill space correctly */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ! media hover buttons */
|
||||||
|
.image-hover-container {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
/* Ensures no overflow outside the container */
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-hover-container img {
|
||||||
|
width: 100%;
|
||||||
|
display: block;
|
||||||
|
transition: transform 0.3s ease;
|
||||||
|
transform-origin: center;
|
||||||
|
/* Ensures scaling is centered */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.image-hover-overlay {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
/* Semi-transparent overlay */
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-hover-container:hover .image-hover-overlay {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.image-hover-container:hover img {
|
||||||
|
/* transform: scale(1.05); */
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-icon {
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
font-size: 24px;
|
||||||
|
/* Adjust size as needed */
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-icon:hover {
|
||||||
|
color: var(--shz-gold-1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<!-- Entry Media Modal Component -->
|
||||||
|
<div class="card border-top border-3 border-primary rounded-0 media-dialog-main mb-0">
|
||||||
|
<div class="modal-header card-header py-3 px-4">
|
||||||
|
<h5 class="mb-0 text-primary">Entry Media</h5>
|
||||||
|
<button type="button" class="btn-close" aria-label="Close" (click)="onClose()"></button>
|
||||||
|
</div>
|
||||||
|
<div class="card-body p-4">
|
||||||
|
<ul class="nav nav-tabs mb-2 d-flex justify-content-between align-items-center" id="mediaTab" role="tablist">
|
||||||
|
<div class="nav-item-group d-flex">
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="nav-link active" id="posters-tab" data-bs-toggle="tab" data-bs-target="#posters" type="button"
|
||||||
|
role="tab" aria-controls="posters" aria-selected="true" (click)="setTab('poster')">Posters</button>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="nav-link" id="banners-tab" data-bs-toggle="tab" data-bs-target="#banners" type="button"
|
||||||
|
role="tab" aria-controls="banners" aria-selected="false" (click)="setTab('backdrop')">Banners</button>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="nav-link" id="logos-tab" data-bs-toggle="tab" data-bs-target="#logos" type="button" role="tab"
|
||||||
|
aria-controls="logos" aria-selected="false"(click)="setTab('logo')">Logos</button>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="btn btn-primary rounded-0 p-1 bg-transparent border-0" type="button" (click)="openUploadModal()">
|
||||||
|
<span class="material-symbols-outlined">
|
||||||
|
add_photo_alternate
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content" id="mediaTabContent">
|
||||||
|
<div class="tab-pane fade show active" id="posters" role="tabpanel" aria-labelledby="posters-tab">
|
||||||
|
<div class="row row-cols-1 row-cols-md-3 g-4">
|
||||||
|
<div class="col" *ngFor="let media of filterMedia('poster')">
|
||||||
|
<div class="card image-hover-container">
|
||||||
|
<img [src]="getPath('/posters/' + media.path)" class="card-img-top" alt="Media Image">
|
||||||
|
<div class="image-hover-overlay">
|
||||||
|
<button class="btn btn-icon" (click)="deleteMedia(media.id)">
|
||||||
|
<span class="material-symbols-outlined">delete</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-icon" (click)="selectMedia(media)">
|
||||||
|
<span class="material-symbols-outlined">check_circle</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-icon" (click)="expandMedia(media)">
|
||||||
|
<span class="material-symbols-outlined">zoom_out_map</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade" id="banners" role="tabpanel" aria-labelledby="banners-tab">
|
||||||
|
<div class="row row-cols-1 row-cols-md-3 g-4">
|
||||||
|
<div class="col" *ngFor="let media of filterMedia('backdrop')">
|
||||||
|
<div class="card">
|
||||||
|
<img [src]="getPath('/backdrops/' + media.path)" class="card-img-top" alt="Poster">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade" id="logos" role="tabpanel" aria-labelledby="logos-tab">
|
||||||
|
<div class="row row-cols-1 row-cols-md-3 g-4">
|
||||||
|
<div class="col" *ngFor="let media of filterMedia('logo')">
|
||||||
|
<div class="card">
|
||||||
|
<img [src]="getPath('/logos/' + media.path)" class="card-img-top" alt="Poster">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* tslint:disable:no-unused-variable */
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { DebugElement } from '@angular/core';
|
||||||
|
|
||||||
|
import { MediaModalComponent } from './media-modal.component';
|
||||||
|
|
||||||
|
describe('MediaModalComponent', () => {
|
||||||
|
let component: MediaModalComponent;
|
||||||
|
let fixture: ComponentFixture<MediaModalComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ MediaModalComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(MediaModalComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import { Component, Inject, OnInit } from '@angular/core';
|
||||||
|
import {
|
||||||
|
MatDialogRef,
|
||||||
|
MAT_DIALOG_DATA,
|
||||||
|
MatDialog,
|
||||||
|
} from '@angular/material/dialog';
|
||||||
|
import { Entry } from '../../../shared/models/entry.model';
|
||||||
|
import { environment } from '../../../../environments/environment.prod';
|
||||||
|
import { MediaUploadModalComponent } from '../media-upload-modal/media-upload-modal.component';
|
||||||
|
import { EntryService } from '../../../core/services/entry.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-media-modal',
|
||||||
|
templateUrl: './media-modal.component.html',
|
||||||
|
styleUrls: ['./media-modal.component.css'],
|
||||||
|
})
|
||||||
|
export class MediaModalComponent implements OnInit {
|
||||||
|
entry!: Entry;
|
||||||
|
tab: string = 'poster';
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public dialogRef: MatDialogRef<MediaModalComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||||
|
private dialog: MatDialog,
|
||||||
|
private entryService: EntryService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
if (this.data && this.data.entry) {
|
||||||
|
this.entry = this.data.entry;
|
||||||
|
} else {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onClose(): void {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
filterMedia(type: string) {
|
||||||
|
return this.entry.medias.filter((media) => media.type == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
openUploadModal() {
|
||||||
|
const dialogRef = this.dialog.open(MediaUploadModalComponent, {
|
||||||
|
data: {
|
||||||
|
entryId: this.entry.id,
|
||||||
|
mediaType: this.tab,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogRef.afterClosed().subscribe((result) => {
|
||||||
|
if (result) {
|
||||||
|
this.entry.medias.push(result.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getPath(mediaEnd: string) {
|
||||||
|
return environment.API_URL + '/media/entries' + mediaEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTab(tab: string) {
|
||||||
|
this.tab = tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteMedia(id: number) {
|
||||||
|
this.entryService.deleteEntryMedia(this.entry.id, id).subscribe({
|
||||||
|
next: (result) => {
|
||||||
|
// TODO add confirm modal
|
||||||
|
this.entry.medias = this.entry.medias.filter((m) => m.id != id);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
selectMedia(media: any) {
|
||||||
|
this.entryService.selectEntryMedia(this.entry.id, media.id).subscribe({
|
||||||
|
next: (result) => {
|
||||||
|
this.entry.medias.forEach((m) => {
|
||||||
|
if (m.type == media.type) {
|
||||||
|
m.is_selected = false;
|
||||||
|
}
|
||||||
|
if ((m.id = result.id)) {
|
||||||
|
m.is_selected = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
expandMedia(media: any) {
|
||||||
|
// Implementation to expand or view media in a larger view
|
||||||
|
}
|
||||||
|
}
|
||||||
Whitespace-only changes.
@@ -0,0 +1,29 @@
|
|||||||
|
<div class="dialog-mod card border-top border-3 border-primary rounded-0"
|
||||||
|
style="margin-bottom: 0 !important; max-width: 800px; margin: auto;">
|
||||||
|
<div class="modal-header card-header py-3 px-4">
|
||||||
|
<h5 class="mb-0 text-primary">Media Upload</h5>
|
||||||
|
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="card-body p-4 pt-0">
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<form class="row g-3" [formGroup]="fileForm" enctype="multipart/form-data">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="file" id="file" name="file" class="form-control" (change)="onFileChange($event)">
|
||||||
|
<div *ngIf="fileForm.get('file')?.invalid && fileForm.get('file')?.touched"
|
||||||
|
class="text-danger">
|
||||||
|
File is required
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="col-12 mt-3 d-flex justify-content-end gap-3">
|
||||||
|
<button type="button" class="btn btn-primary px-4 rounded-0" (click)="onSubmit()">Confirmer</button>
|
||||||
|
<button type="button" class="btn btn-secondary px-4 rounded-0" (click)="onClose()">Annuler</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
/* tslint:disable:no-unused-variable */
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { DebugElement } from '@angular/core';
|
||||||
|
|
||||||
|
import { MediaUploadModalComponent } from './media-upload-modal.component';
|
||||||
|
|
||||||
|
describe('MediaUploadModalComponent', () => {
|
||||||
|
let component: MediaUploadModalComponent;
|
||||||
|
let fixture: ComponentFixture<MediaUploadModalComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ MediaUploadModalComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(MediaUploadModalComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { Component, Inject, OnInit } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||||
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||||
|
import { EntryService } from '../../../core/services/entry.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-media-upload-modal',
|
||||||
|
templateUrl: './media-upload-modal.component.html',
|
||||||
|
styleUrls: ['./media-upload-modal.component.css'],
|
||||||
|
})
|
||||||
|
export class MediaUploadModalComponent implements OnInit {
|
||||||
|
fileForm: FormGroup;
|
||||||
|
mediaType!: string;
|
||||||
|
entryId!: number;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public dialogRef: MatDialogRef<MediaUploadModalComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
private entryService: EntryService
|
||||||
|
) {
|
||||||
|
this.fileForm = this.formBuilder.group({
|
||||||
|
file: [null],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
if (this.data && this.data.mediaType && this.data.entryId) {
|
||||||
|
this.mediaType = this.data.mediaType;
|
||||||
|
this.entryId = this.data.entryId;
|
||||||
|
} else {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onFileChange(event: any) {
|
||||||
|
const file = event.target.files[0];
|
||||||
|
this.fileForm.patchValue({ file: file });
|
||||||
|
this.fileForm.get('file')?.updateValueAndValidity();
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit() {
|
||||||
|
if (!this.fileForm.valid) return;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
const fileValue = this.fileForm.get('file')?.value;
|
||||||
|
if (fileValue) formData.append(this.mediaType, fileValue);
|
||||||
|
|
||||||
|
this.entryService.addEntryMedia(this.entryId, formData).subscribe({
|
||||||
|
next: (result) => {
|
||||||
|
this.dialogRef.close({ data: result });
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onClose() {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user