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
@@ -5,6 +5,7 @@ import { Entry } from '../../shared/models/entry.model';
|
||||
import { EntryId } from '../../shared/models/entryId.model';
|
||||
import { EntryRating } from '../../shared/models/entryRating.model';
|
||||
import { environment } from '../../../environments/environment.prod';
|
||||
import { Media } from '../../shared/models/media.model';
|
||||
|
||||
@Injectable({
|
||||
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
|
||||
refrechEntryById(entryId: number) {
|
||||
return this.http.get<Entry>(
|
||||
|
||||
@@ -5,9 +5,16 @@ import { EntryPageComponent } from './entry-page/entry-page.component';
|
||||
import { EntriesRoutingModule } from './entries-routing.module';
|
||||
import { CommonModule } from '@angular/common';
|
||||
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({
|
||||
declarations: [EntryPageComponent, SeasonMainCardComponent],
|
||||
declarations: [
|
||||
EntryPageComponent,
|
||||
SeasonMainCardComponent,
|
||||
MediaModalComponent,
|
||||
MediaUploadModalComponent,
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
SharedModule,
|
||||
|
||||
@@ -160,6 +160,12 @@
|
||||
update
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<button class="btn btn-icon-only-success wh-48" (click)="mediaModal()">
|
||||
<span class="material-symbols-outlined">
|
||||
image
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<!-- End Interraction buttons -->
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,7 @@ import { LibraryService } from '../../../core/services/library.service';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { EntrySeen } from '../../../shared/models/entrySeen.model';
|
||||
import { EpisodeSeenModalComponent } from '../../../shared/components/modals/episode-seen-modal/episode-seen-modal.component';
|
||||
import { MediaModalComponent } from '../media-modal/media-modal.component';
|
||||
|
||||
@Component({
|
||||
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
|
||||
// ? update the watchlist page
|
||||
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');
|
||||
}
|
||||
|
||||
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
|
||||
get 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