Front/Back: add entry settings modal
This commit is contained in:
1 parent
8724a96b81
commit
625ec3367e
15 files changed
+334
-57
No files matched your search
@@ -24,20 +24,18 @@ export class EntryService {
|
||||
}
|
||||
|
||||
// get entry by id
|
||||
getEntryById(entryId: string) {
|
||||
getEntryById(entryId: number) {
|
||||
return this.http.get<Entry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${entryId}`
|
||||
);
|
||||
}
|
||||
|
||||
// update entry
|
||||
updateEntry(entry: Entry) {
|
||||
updateEntry(entryId: number, entryData: any) {
|
||||
return this.http.put<Entry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${entry.id}`,
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${entryId}`,
|
||||
{
|
||||
favorit: entry.favorit,
|
||||
watchlist: entry.watchlist,
|
||||
hidden: entry.hidden,
|
||||
entryData: entryData,
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -69,6 +67,12 @@ export class EntryService {
|
||||
);
|
||||
}
|
||||
|
||||
syncSeries() {
|
||||
return this.http.get<Entry[]>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/sync-series`
|
||||
);
|
||||
}
|
||||
|
||||
fetchEntryCollectionById(entryId: number) {
|
||||
return this.http.get<any>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/fetch-collection`
|
||||
|
||||
@@ -7,6 +7,7 @@ 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';
|
||||
import { EntrySettingsModalComponent } from './entry-settings-modal/entry-settings-modal.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -14,6 +15,7 @@ import { MediaUploadModalComponent } from './media-upload-modal/media-upload-mod
|
||||
SeasonMainCardComponent,
|
||||
MediaModalComponent,
|
||||
MediaUploadModalComponent,
|
||||
EntrySettingsModalComponent
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<button class="btn btn-icon-only-success wh-48" (click)="showAddToListModal()">
|
||||
<button class="btn btn-icon-only-success wh-48" (click)="addToCollectionModal()">
|
||||
<span class="material-symbols-outlined">
|
||||
playlist_add
|
||||
</span>
|
||||
@@ -172,6 +172,12 @@
|
||||
image
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<button class="btn btn-icon-only-success wh-48" (click)="settingsModal()">
|
||||
<span class="material-symbols-outlined">
|
||||
settings
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<!-- End Interraction buttons -->
|
||||
</div>
|
||||
@@ -291,7 +297,7 @@
|
||||
<h3>Belong to Collection(s)</h3>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-sm btn-filter bg-transparent" type="button" style="cursor: pointer;"
|
||||
(click)="showAddToListModal()">
|
||||
(click)="addToCollectionModal()">
|
||||
<i class="bi bi-collection"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -23,6 +23,7 @@ import { EpisodeSeenModalComponent } from '../../../shared/components/modals/epi
|
||||
import { MediaModalComponent } from '../media-modal/media-modal.component';
|
||||
import { environment } from '../../../../environments/environment.prod';
|
||||
import { Collection } from '../../../shared/models/collection.model';
|
||||
import { EntrySettingsModalComponent } from '../entry-settings-modal/entry-settings-modal.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-entry-page',
|
||||
@@ -275,10 +276,14 @@ export class EntryPageComponent implements OnInit {
|
||||
toggleFavorite() {
|
||||
this.lockActions = true;
|
||||
this.entry.favorit = !this.entry.favorit;
|
||||
this.entryService.updateEntry(this.entry).subscribe({
|
||||
|
||||
const entryData = { favorit: this.entry.favorit };
|
||||
|
||||
this.entryService.updateEntry(this.entry.id, entryData).subscribe({
|
||||
next: (entry) => {
|
||||
// console.log(`Entry updated: `, entry);
|
||||
this.entry = entry;
|
||||
this.entry.isInLibrary = true;
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(`Error updating entry: `, error);
|
||||
@@ -293,10 +298,14 @@ export class EntryPageComponent implements OnInit {
|
||||
toggleHidden() {
|
||||
this.lockActions = true;
|
||||
this.entry.hidden = !this.entry.hidden;
|
||||
this.entryService.updateEntry(this.entry).subscribe({
|
||||
|
||||
const entryData = { hidden: this.entry.hidden };
|
||||
|
||||
this.entryService.updateEntry(this.entry.id, entryData).subscribe({
|
||||
next: (entry) => {
|
||||
// console.log(`Entry updated: `, entry);
|
||||
this.entry = entry;
|
||||
this.entry.isInLibrary = true;
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(`Error updating entry: `, error);
|
||||
@@ -308,7 +317,7 @@ export class EntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
showAddToListModal() {
|
||||
addToCollectionModal() {
|
||||
if (this.entry) {
|
||||
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
|
||||
width: '400px',
|
||||
@@ -320,13 +329,24 @@ export class EntryPageComponent implements OnInit {
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
// TODO update entry page collections
|
||||
// console.log('Modal Closed: ', result);
|
||||
this.entryService.getEntryById(this.entry.id).subscribe({
|
||||
next: (result) => {
|
||||
this.entry.collections = result.collections.map((c) => {
|
||||
c.mediasCount = c.medias.length;
|
||||
c.selectedBackdrop = this.getCollectionBackdropPath(c);
|
||||
|
||||
c.medias = [];
|
||||
return c;
|
||||
});
|
||||
result.collections;
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getCollectionBackdropPath(collection: Collection) {
|
||||
console.log(`collection media:`, collection.medias);
|
||||
// console.log(`collection media:`, collection.medias);
|
||||
if (collection.medias && collection.medias.length != 0) {
|
||||
const backdrops = collection.medias.filter((m) => m.type == 'backdrop');
|
||||
if (backdrops.length != 0) {
|
||||
@@ -334,7 +354,7 @@ export class EntryPageComponent implements OnInit {
|
||||
(m) => m.type == 'backdrop' && m.isSelected
|
||||
);
|
||||
|
||||
console.log(selectedBackdrops);
|
||||
// console.log(selectedBackdrops);
|
||||
let selectedBackdrop;
|
||||
if (selectedBackdrops.length != 0) {
|
||||
selectedBackdrop = selectedBackdrops[0].path;
|
||||
@@ -374,6 +394,14 @@ export class EntryPageComponent implements OnInit {
|
||||
this.entryService.refrechEntryById(this.entry.id).subscribe({
|
||||
next: (entry) => {
|
||||
this.entry = entry;
|
||||
this.entry.isInLibrary = true;
|
||||
this.entry.collections = this.entry.collections.map((c) => {
|
||||
c.mediasCount = c.medias.length;
|
||||
c.selectedBackdrop = this.getCollectionBackdropPath(c);
|
||||
|
||||
c.medias = [];
|
||||
return c;
|
||||
});
|
||||
// console.log(`Entry refreched: `, entry);
|
||||
this.toastr.success(`Movie refreshed successfuly.`, 'Success', {
|
||||
tapToDismiss: true,
|
||||
@@ -551,7 +579,11 @@ export class EntryPageComponent implements OnInit {
|
||||
next: () => {
|
||||
// console.log(`Episode seen deleted.`);
|
||||
// ? call this function to fetch the new episode-seen history
|
||||
this.getEpisodesSeenHistory();
|
||||
// this.getEpisodesSeenHistory();
|
||||
this.seenHistory = this.seenHistory.filter(
|
||||
(eps) => eps.id != episodeSeen.id
|
||||
);
|
||||
this.filterEpisodesSeenHistory();
|
||||
|
||||
// ? Updating the episodes seen progress bar in the season card
|
||||
// ? by fetching a new updated episodes list
|
||||
@@ -684,6 +716,29 @@ export class EntryPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
settingsModal() {
|
||||
const dialogRef = this.dialog.open(EntrySettingsModalComponent, {
|
||||
width: '800px',
|
||||
height: '600px',
|
||||
minHeight: '50%',
|
||||
panelClass: 'media-dialog-container',
|
||||
data: {
|
||||
entry: this.entry,
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
if (result) {
|
||||
this.entry.watchlist = result.entry.watchlist;
|
||||
this.entry.favorit = result.entry.favorit;
|
||||
this.entry.hidden = result.entry.hidden;
|
||||
this.entry.showInCalendar = result.entry.showInCalendar;
|
||||
this.entry.autoSync = result.entry.autoSync;
|
||||
} else {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// * getters
|
||||
get status() {
|
||||
return this.entry.status;
|
||||
@@ -759,4 +814,12 @@ export class EntryPageComponent implements OnInit {
|
||||
if (!this.entry.is_tvseries) return 'This is a movie';
|
||||
return 'sooon';
|
||||
}
|
||||
|
||||
fetchEntry() {
|
||||
this.entryService.getEntryById(this.entry.id).subscribe({
|
||||
next: (result) => {
|
||||
this.entry = { ...result, isInLibrary: true };
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
+40
@@ -0,0 +1,40 @@
|
||||
<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 Settings</h5>
|
||||
<button type="button" class="btn-close" aria-label="Close" (click)="onClose()"></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]="entryForm">
|
||||
<div class="col-md-12">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" id="favorit" formControlName="favorit" class="form-check-input">
|
||||
<label for="favorit" class="form-check-label">Favorit</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" id="hidden" formControlName="hidden" class="form-check-input">
|
||||
<label for="hidden" class="form-check-label">Hidden</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" id="showInCalendar" formControlName="showInCalendar" class="form-check-input">
|
||||
<label for="showInCalendar" class="form-check-label">Show in Calendar</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" id="watchlist" formControlName="watchlist" class="form-check-input">
|
||||
<label for="watchlist" class="form-check-label">Watchlist</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" id="autoSync" formControlName="autoSync" class="form-check-input">
|
||||
<label for="autoSync" class="form-check-label">Auto Sync</label>
|
||||
</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()">Confirm</button>
|
||||
<button type="button" class="btn btn-secondary px-4 rounded-0" (click)="onClose()">Cancel</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 { EntrySettingsModalComponent } from './entry-settings-modal.component';
|
||||
|
||||
describe('EntrySettingsModalComponent', () => {
|
||||
let component: EntrySettingsModalComponent;
|
||||
let fixture: ComponentFixture<EntrySettingsModalComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ EntrySettingsModalComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EntrySettingsModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import {
|
||||
MatDialogRef,
|
||||
MAT_DIALOG_DATA,
|
||||
MatDialog,
|
||||
} from '@angular/material/dialog';
|
||||
import { EntryService } from '../../../core/services/entry.service';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-entry-settings-modal',
|
||||
templateUrl: './entry-settings-modal.component.html',
|
||||
styleUrls: ['./entry-settings-modal.component.css'],
|
||||
})
|
||||
export class EntrySettingsModalComponent implements OnInit {
|
||||
entryId!: number;
|
||||
entryForm: FormGroup;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<EntrySettingsModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private formBuilder: FormBuilder,
|
||||
private entryService: EntryService
|
||||
) {
|
||||
this.entryForm = this.formBuilder.group({
|
||||
watchlist: [null],
|
||||
favorit: [null],
|
||||
hidden: [null],
|
||||
showInCalendar: [null],
|
||||
autoSync: [null],
|
||||
});
|
||||
|
||||
if (this.data && this.data.entry) {
|
||||
this.entryForm.patchValue(this.data.entry);
|
||||
this.entryId = this.data.entry.id;
|
||||
} else {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
onSubmit() {
|
||||
const entryData = this.entryForm.value;
|
||||
|
||||
this.entryService.updateEntry(this.entryId, entryData).subscribe({
|
||||
next: (result) => {
|
||||
this.dialogRef.close({ entry: result });
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onClose() {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,9 @@ export interface Entry {
|
||||
watchlist: boolean;
|
||||
favorit: boolean;
|
||||
hidden: boolean;
|
||||
showInCalendar: boolean;
|
||||
autoSync: boolean;
|
||||
|
||||
note: string;
|
||||
|
||||
is_tvseries: boolean;
|
||||
@@ -47,6 +50,7 @@ export interface Entry {
|
||||
|
||||
// * front specific fields
|
||||
isInLibrary: boolean;
|
||||
isLocked: boolean;
|
||||
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
Reference in new issue
Block a user