implemented collection entries reorder (for table view)
This commit is contained in:
1 parent
ec45cd342f
commit
78399912f7
5 files changed
+45
-55
No files matched your search
+19
-1
@@ -13,6 +13,7 @@ import {
|
|||||||
transition,
|
transition,
|
||||||
trigger,
|
trigger,
|
||||||
} from '@angular/animations';
|
} from '@angular/animations';
|
||||||
|
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-collection-entry-table',
|
selector: 'app-collection-entry-table',
|
||||||
@@ -27,7 +28,9 @@ import {
|
|||||||
})
|
})
|
||||||
export class CollectionEntryTableComponent {
|
export class CollectionEntryTableComponent {
|
||||||
@Input() entries: Entry[] = [];
|
@Input() entries: Entry[] = [];
|
||||||
@Input() listId: string = '';
|
@Input() collectionId: string = '';
|
||||||
|
|
||||||
|
constructor(private userCollectionService: UserCollectionService) {}
|
||||||
|
|
||||||
refrechEventReceiver() {
|
refrechEventReceiver() {
|
||||||
console.log('event recieved');
|
console.log('event recieved');
|
||||||
@@ -35,6 +38,21 @@ export class CollectionEntryTableComponent {
|
|||||||
|
|
||||||
drop(event: CdkDragDrop<any[]>) {
|
drop(event: CdkDragDrop<any[]>) {
|
||||||
moveItemInArray(this.entries, event.previousIndex, event.currentIndex);
|
moveItemInArray(this.entries, event.previousIndex, event.currentIndex);
|
||||||
|
|
||||||
|
if (event.previousIndex != event.currentIndex) {
|
||||||
|
this.userCollectionService
|
||||||
|
.updateEntryOrder(
|
||||||
|
this.collectionId,
|
||||||
|
this.entries[event.currentIndex].id,
|
||||||
|
event.currentIndex
|
||||||
|
)
|
||||||
|
.subscribe({
|
||||||
|
next: () => {},
|
||||||
|
error: (error) => {
|
||||||
|
console.log(`Error changing order of entries!`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart(event: CdkDragStart): void {
|
dragStart(event: CdkDragStart): void {
|
||||||
|
|||||||
+6
-4
@@ -1,5 +1,7 @@
|
|||||||
<div class="movies-container" cdkDropList [cdkDropListData]="entries" (cdkDropListDropped)="drop($any($event))">
|
<div class="movies-container">
|
||||||
<app-userCollection-grid-card cdkDrag *ngFor="let entry of entries" [entry]="entry" [listId]="listId"
|
<ng-container *ngFor="let entry of entries">
|
||||||
(refrechEvent)="refrechEventReceiver()">
|
<app-userCollection-grid-card [entry]="entry" [collectionId]="collectionId" (refrechEvent)="refrechEventReceiver()"
|
||||||
</app-userCollection-grid-card>
|
@animateDestroy>
|
||||||
|
</app-userCollection-grid-card>
|
||||||
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
+14
-20
@@ -1,36 +1,30 @@
|
|||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { Entry } from '../../../../shared/models/entry.model';
|
import { Entry } from '../../../../shared/models/entry.model';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CdkDragDrop,
|
animate,
|
||||||
CdkDragEnd,
|
state,
|
||||||
CdkDragStart,
|
style,
|
||||||
moveItemInArray,
|
transition,
|
||||||
} from '@angular/cdk/drag-drop';
|
trigger,
|
||||||
|
} from '@angular/animations';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-userCollection-entry-grid',
|
selector: 'app-userCollection-entry-grid',
|
||||||
templateUrl: './userCollection-entry-grid.component.html',
|
templateUrl: './userCollection-entry-grid.component.html',
|
||||||
styleUrls: ['./userCollection-entry-grid.component.css'],
|
styleUrls: ['./userCollection-entry-grid.component.css'],
|
||||||
|
animations: [
|
||||||
|
trigger('animateDestroy', [
|
||||||
|
state('void', style({ opacity: '0' })),
|
||||||
|
transition('* => void', animate('300ms ease')),
|
||||||
|
]),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class UserCollectionEntryGridComponent {
|
export class UserCollectionEntryGridComponent {
|
||||||
@Input() entries: Entry[] = [];
|
@Input() entries: Entry[] = [];
|
||||||
@Input() listId: string = '';
|
@Input() collectionId: string = '';
|
||||||
|
|
||||||
refrechEventReceiver() {
|
refrechEventReceiver() {
|
||||||
console.log('event recieved');
|
console.log('event recieved');
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(event: CdkDragDrop<any[]>) {
|
|
||||||
moveItemInArray(this.entries, event.previousIndex, event.currentIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
dragStart(event: CdkDragStart): void {
|
|
||||||
event.source.element.nativeElement.classList.add('custom-dragging-class');
|
|
||||||
}
|
|
||||||
|
|
||||||
dragEnd(event: CdkDragEnd): void {
|
|
||||||
event.source.element.nativeElement.classList.remove(
|
|
||||||
'custom-dragging-class'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+4
-28
@@ -1,4 +1,4 @@
|
|||||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { LibraryService } from '../../../../core/services/library.service';
|
import { LibraryService } from '../../../../core/services/library.service';
|
||||||
import { Entry } from '../../../../shared/models/entry.model';
|
import { Entry } from '../../../../shared/models/entry.model';
|
||||||
@@ -21,9 +21,9 @@ import { ConfirmModalComponent } from '../../../../shared/components/modals/conf
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class UserCollectionGridCardComponent {
|
export class UserCollectionGridCardComponent implements OnInit {
|
||||||
@Input() entry!: Entry;
|
@Input() entry!: Entry;
|
||||||
@Input() listId: string = '';
|
@Input() collectionId: string = '';
|
||||||
@Output() refrechEvent = new EventEmitter();
|
@Output() refrechEvent = new EventEmitter();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -34,15 +34,6 @@ export class UserCollectionGridCardComponent {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
|
|
||||||
next: (e) => {
|
|
||||||
if (e != null) {
|
|
||||||
e.isInLibrary = true;
|
|
||||||
this.entry = e;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: (error) => {},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get releaseYear(): number {
|
get releaseYear(): number {
|
||||||
@@ -64,21 +55,6 @@ export class UserCollectionGridCardComponent {
|
|||||||
return `https://image.tmdb.org/t/p/w500` + this.entry.poster_path;
|
return `https://image.tmdb.org/t/p/w500` + this.entry.poster_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
addEntry(tmdb_id: string, is_tvserie: boolean) {
|
|
||||||
console.log('Adding Entry To Library.');
|
|
||||||
this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
|
|
||||||
next: (entry) => {
|
|
||||||
if (entry != null) {
|
|
||||||
entry.isInLibrary = true;
|
|
||||||
this.entry = entry;
|
|
||||||
this.libraryService.getAllEntries(true);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: (error) => {
|
|
||||||
console.error('Error adding entry:', error);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
removeEntryFromList() {
|
removeEntryFromList() {
|
||||||
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
||||||
@@ -95,7 +71,7 @@ export class UserCollectionGridCardComponent {
|
|||||||
if (result.confirmed != true) return;
|
if (result.confirmed != true) return;
|
||||||
|
|
||||||
this.userCollectionService
|
this.userCollectionService
|
||||||
.removeEntryFromCollection(this.listId, this.entry.id)
|
.removeEntryFromCollection(this.collectionId, this.entry.id)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
// TODO confirm notification
|
// TODO confirm notification
|
||||||
|
|||||||
+2
-2
@@ -42,13 +42,13 @@
|
|||||||
<!-- ! grid -->
|
<!-- ! grid -->
|
||||||
<div *ngIf="viewMode == 'grid'">
|
<div *ngIf="viewMode == 'grid'">
|
||||||
<app-userCollection-entry-grid [entries]="collection.entries"
|
<app-userCollection-entry-grid [entries]="collection.entries"
|
||||||
[listId]="getListId()"></app-userCollection-entry-grid>
|
[collectionId]="getListId()"></app-userCollection-entry-grid>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ! table -->
|
<!-- ! table -->
|
||||||
<div *ngIf="viewMode == 'table'">
|
<div *ngIf="viewMode == 'table'">
|
||||||
<app-collection-entry-table [entries]="collection.entries"
|
<app-collection-entry-table [entries]="collection.entries"
|
||||||
[listId]="getListId()"></app-collection-entry-table>
|
[collectionId]="getListId()"></app-collection-entry-table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Reference in new issue
Block a user