Frontend: Entry Media Modal
- Improved filter logic. - Added toasts. - Removed MediaUploadModal for better user experience. - Synced entry media state.
This commit is contained in:
1 parent
8533076080
commit
6bf27e5519
2 files changed
+96
-43
No files matched your search
@@ -9,37 +9,40 @@
|
|||||||
<div class="nav-item-group d-flex">
|
<div class="nav-item-group d-flex">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link active" id="posters-tab" data-bs-toggle="tab" data-bs-target="#posters" type="button"
|
<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>
|
role="tab" aria-controls="posters" aria-selected="true" (click)="selectMediaType('poster')">Posters</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link" id="backdrops-tab" data-bs-toggle="tab" data-bs-target="#backdrops" type="button"
|
<button class="nav-link" id="backdrops-tab" data-bs-toggle="tab" data-bs-target="#backdrops" type="button"
|
||||||
role="tab" aria-controls="backdrops" aria-selected="false" (click)="setTab('backdrop')">Backdrops</button>
|
role="tab" aria-controls="backdrops" aria-selected="false"
|
||||||
|
(click)="selectMediaType('backdrop')">Backdrops</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link" id="logos-tab" data-bs-toggle="tab" data-bs-target="#logos" type="button" role="tab"
|
<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>
|
aria-controls="logos" aria-selected="false" (click)="selectMediaType('logo')">Logos</button>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="btn btn-primary rounded-0 p-1 bg-transparent border-0 add-btn d-flex align-items-center"
|
<button class="btn btn-primary rounded-0 p-1 bg-transparent border-0 add-btn d-flex align-items-center"
|
||||||
type="button" (click)="openUploadModal()">
|
type="button" (click)="fileInput.click()">
|
||||||
<span class="material-symbols-outlined me-1">
|
<span class="material-symbols-outlined me-1">
|
||||||
add_photo_alternate
|
add_photo_alternate
|
||||||
</span>
|
</span>
|
||||||
Add An Image
|
Add An Image
|
||||||
</button>
|
</button>
|
||||||
|
<input type="file" #fileInput style="display: none" (change)="onFileSelected($event)" hidden>
|
||||||
|
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="tab-content" id="mediaTabContent">
|
<div class="tab-content" id="mediaTabContent">
|
||||||
<div class="tab-pane fade show active" id="posters" role="tabpanel" aria-labelledby="posters-tab">
|
<div class="tab-pane fade show active" id="posters" role="tabpanel" aria-labelledby="posters-tab">
|
||||||
<div class="row row-cols-1 row-cols-md-4 g-4">
|
<div class="row row-cols-1 row-cols-md-4 g-4" *ngIf="tab == 'poster'">
|
||||||
<div class="col" *ngFor="let media of filterMedia('poster')">
|
<div class="col" *ngFor="let media of filteredMedia">
|
||||||
<div class="card image-hover-container">
|
<div class="card image-hover-container">
|
||||||
<img [src]="getPath('posters', media.path)" class="card-img-top" alt="Media Image">
|
<img [src]="getPath('posters', media.path)" class="card-img-top" alt="Media Image">
|
||||||
<div class="image-hover-overlay">
|
<div class="image-hover-overlay">
|
||||||
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media.id)">
|
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media)">
|
||||||
<span class="material-symbols-outlined">delete</span>
|
<span class="material-symbols-outlined">delete</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
||||||
@@ -54,12 +57,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade" id="backdrops" role="tabpanel" aria-labelledby="backdrops-tab">
|
<div class="tab-pane fade" id="backdrops" role="tabpanel" aria-labelledby="backdrops-tab">
|
||||||
<div class="row row-cols-1 row-cols-md-2 g-4">
|
<div class="row row-cols-1 row-cols-md-2 g-4" *ngIf="tab == 'backdrop'">
|
||||||
<div class="col" *ngFor="let media of filterMedia('backdrop')">
|
<div class="col" *ngFor="let media of filteredMedia">
|
||||||
<div class="card image-hover-container">
|
<div class="card image-hover-container">
|
||||||
<img [src]="getPath('backdrops', media.path)" class="card-img-top" alt="Media Image">
|
<img [src]="getPath('backdrops', media.path)" class="card-img-top" alt="Media Image">
|
||||||
<div class="image-hover-overlay">
|
<div class="image-hover-overlay">
|
||||||
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media.id)">
|
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media)">
|
||||||
<span class="material-symbols-outlined">delete</span>
|
<span class="material-symbols-outlined">delete</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
||||||
@@ -74,12 +77,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade" id="logos" role="tabpanel" aria-labelledby="logos-tab">
|
<div class="tab-pane fade" id="logos" role="tabpanel" aria-labelledby="logos-tab">
|
||||||
<div class="row row-cols-1 row-cols-md-2 g-4">
|
<div class="row row-cols-1 row-cols-md-2 g-4" *ngIf="tab == 'logo'">
|
||||||
<div class="col" *ngFor="let media of filterMedia('logo')">
|
<div class="col" *ngFor="let media of filteredMedia">
|
||||||
<div class="card image-hover-container">
|
<div class="card image-hover-container">
|
||||||
<img [src]="getPath('logos', media.path)" class="card-img-top" alt="Media Image">
|
<img [src]="getPath('logos', media.path)" class="card-img-top" alt="Media Image">
|
||||||
<div class="image-hover-overlay">
|
<div class="image-hover-overlay">
|
||||||
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media.id)">
|
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media)">
|
||||||
<span class="material-symbols-outlined">delete</span>
|
<span class="material-symbols-outlined">delete</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import { Entry } from '../../../shared/models/entry.model';
|
|||||||
import { MediaUploadModalComponent } from '../media-upload-modal/media-upload-modal.component';
|
import { MediaUploadModalComponent } from '../media-upload-modal/media-upload-modal.component';
|
||||||
import { EntryService } from '../../../core/services/entry.service';
|
import { EntryService } from '../../../core/services/entry.service';
|
||||||
import { ConfigService } from '../../../core/services/config.service';
|
import { ConfigService } from '../../../core/services/config.service';
|
||||||
|
import { LibraryService } from '../../../core/services/library.service';
|
||||||
|
import { ToastService } from '../../../shared/services/toast.service';
|
||||||
|
import { Media } from '../../../shared/models/media.model';
|
||||||
|
import { ConfirmModalComponent } from '../../../shared/components/modals/confirm-modal/confirm-modal.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-media-modal',
|
selector: 'app-media-modal',
|
||||||
@@ -17,19 +21,22 @@ import { ConfigService } from '../../../core/services/config.service';
|
|||||||
export class MediaModalComponent implements OnInit {
|
export class MediaModalComponent implements OnInit {
|
||||||
entry!: Entry;
|
entry!: Entry;
|
||||||
tab: string = 'poster';
|
tab: string = 'poster';
|
||||||
|
filteredMedia: Media[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public dialogRef: MatDialogRef<MediaModalComponent>,
|
public dialogRef: MatDialogRef<MediaModalComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
private entryService: EntryService,
|
private entryService: EntryService,
|
||||||
private configService: ConfigService
|
private libraryService: LibraryService,
|
||||||
|
private configService: ConfigService,
|
||||||
|
private toast: ToastService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
if (this.data && this.data.entry) {
|
if (this.data && this.data.entry) {
|
||||||
this.entry = this.data.entry;
|
this.entry = this.data.entry;
|
||||||
// console.log(this.entry.medias);
|
this.filterMedia(this.tab);
|
||||||
} else {
|
} else {
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
}
|
}
|
||||||
@@ -39,64 +46,107 @@ export class MediaModalComponent implements OnInit {
|
|||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
filterMedia(type: string) {
|
selectMediaType(type: string) {
|
||||||
return this.entry.medias.filter((media) => media.type == type);
|
this.tab = type;
|
||||||
|
this.filterMedia(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
openUploadModal() {
|
filterMedia(type: string) {
|
||||||
const dialogRef = this.dialog.open(MediaUploadModalComponent, {
|
this.filteredMedia = this.entry.medias.filter(
|
||||||
data: {
|
(media) => media.type === type
|
||||||
entryId: this.entry.id,
|
);
|
||||||
mediaType: this.tab,
|
}
|
||||||
|
|
||||||
|
onFileSelected(event: Event) {
|
||||||
|
const target = event.target as HTMLInputElement;
|
||||||
|
const file = target.files?.[0];
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append(this.tab, file);
|
||||||
|
this.entryService.addEntryMedia(this.entry.id, formData).subscribe({
|
||||||
|
next: (result) => {
|
||||||
|
this.entry.medias.unshift(result);
|
||||||
|
this.libraryService.updateEntry(this.entry);
|
||||||
|
this.filterMedia(this.tab);
|
||||||
|
this.toast.show('', `File uploaded.`, 'success');
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
// console.log(`Error uploading file: ${error}`);
|
||||||
|
this.toast.show('', `Error uploading file.`, 'error');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe((result) => {
|
|
||||||
if (result) {
|
|
||||||
this.entry.medias.push(result.data);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPath(fileType: string, filePath: string) {
|
getPath(fileType: string, filePath: string) {
|
||||||
return `${this.configService.getBackendApiUrl()}/media/entries/${fileType}/preview/${filePath}`;
|
return `${this.configService.getBackendApiUrl()}/media/entries/${fileType}/preview/${filePath}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTab(tab: string) {
|
deleteMedia(media: Media) {
|
||||||
this.tab = tab;
|
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
||||||
}
|
data: {
|
||||||
|
title: 'Delete file',
|
||||||
|
message: `Are you sure you want to delete this ${this.tab}?`,
|
||||||
|
type: 'danger',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
deleteMedia(id: number) {
|
dialogRef.afterClosed().subscribe((result) => {
|
||||||
this.entryService.deleteEntryMedia(this.entry.id, id).subscribe({
|
if (result && result.confirmed) {
|
||||||
|
this.entryService.deleteEntryMedia(this.entry.id, media.id).subscribe({
|
||||||
next: (result) => {
|
next: (result) => {
|
||||||
// TODO add confirm modal
|
this.entry.medias = this.entry.medias.filter(
|
||||||
this.entry.medias = this.entry.medias.filter((m) => m.id != id);
|
(m) => m.id != media.id
|
||||||
},
|
);
|
||||||
error: (error) => {
|
|
||||||
console.log(error);
|
// ? if the deleted media was selected, select the first one
|
||||||
},
|
if (media.isSelected) {
|
||||||
|
this.entry.medias.forEach((m) => {
|
||||||
|
if (m.type == this.tab) {
|
||||||
|
m.isSelected = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
selectMedia(media: any) {
|
this.libraryService.updateEntry(this.entry);
|
||||||
|
this.filterMedia(this.tab);
|
||||||
|
this.toast.show('', `File deleted.`, 'success');
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
this.toast.show('', `Error deleting file.`, 'error');
|
||||||
|
// console.log(`Error deleting file: ${error}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
selectMedia(media: Media) {
|
||||||
this.entryService.selectEntryMedia(this.entry.id, media.id).subscribe({
|
this.entryService.selectEntryMedia(this.entry.id, media.id).subscribe({
|
||||||
next: (result) => {
|
next: (result) => {
|
||||||
this.entry.medias.forEach((m) => {
|
this.entry.medias.forEach((m) => {
|
||||||
if (m.type == media.type) {
|
if (m.type == media.type) {
|
||||||
m.isSelected = false;
|
m.isSelected = false;
|
||||||
}
|
|
||||||
if ((m.id = result.id)) {
|
if (m.id == result.id) {
|
||||||
m.isSelected = true;
|
m.isSelected = true;
|
||||||
|
console.log(`found and selected: `, m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.libraryService.updateEntry(this.entry);
|
||||||
|
this.toast.show('', `File selected.`, 'success');
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.log(error);
|
this.toast.show('', `Error selecting file.`, 'error');
|
||||||
|
// console.log(`Error selecting file: ${error}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
expandMedia(media: any) {
|
expandMedia(media: Media) {
|
||||||
const fullSizePath = `${this.configService.getBackendApiUrl()}/media/entries/${
|
const fullSizePath = `${this.configService.getBackendApiUrl()}/media/entries/${
|
||||||
media.type
|
media.type
|
||||||
}s/original/${media.path}`;
|
}s/original/${media.path}`;
|
||||||
|
|||||||
Reference in new issue
Block a user