rename model list to usercollection & fixed redlated errors

This commit is contained in:
X4Lo committed 2024-04-06 08:56:16 +00:00
1 parent 60b517500f
commit b48b395574
37 files changed
+2479 -1210

No files matched your search

@@ -1,5 +1,5 @@
import { Component, Input, OnInit } from '@angular/core';
import { ListSelectionModalComponent } from '../../modals/list-selection-modal/list-selection-modal.component';
import { UserCollectionsModalComponent } from '../../modals/list-selection-modal/user-collections-modal.component';
import { MatDialog } from '@angular/material/dialog';
import { trigger, transition, style, animate } from '@angular/animations';
import { Entry } from '../../../models/entry.model';
@@ -86,7 +86,7 @@ export class MainCardComponent implements OnInit {
showAddToListModal() {
if (this.entry) {
const dialogRef = this.dialog.open(ListSelectionModalComponent, {
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
width: '400px',
height: '55%',
data: {
@@ -1,21 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ListSelectionModalComponent } from './list-selection-modal.component';
describe('ListSelectionModalComponent', () => {
let component: ListSelectionModalComponent;
let fixture: ComponentFixture<ListSelectionModalComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ListSelectionModalComponent]
});
fixture = TestBed.createComponent(ListSelectionModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -38,7 +38,7 @@
<div data-simplebar class="simplebar-content-wrapper">
<div class="list-group">
<label *ngFor="let list of listsToShow" class="list-group-item">
<label *ngFor="let list of userCollectionsToShow" class="list-group-item">
<input class="form-check-input me-1" type="checkbox" [value]="list.id"
(change)="onSelectionChange(list, $event)" [checked]="list.isChecked">
{{ list.name }}
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UserCollectionsModalComponent } from './user-collections-modal.component';
describe('UserCollectionsModalComponent', () => {
let component: UserCollectionsModalComponent;
let fixture: ComponentFixture<UserCollectionsModalComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [UserCollectionsModalComponent]
});
fixture = TestBed.createComponent(UserCollectionsModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -1,10 +1,10 @@
import { Component, Inject, Input, OnInit, ViewChild } from '@angular/core';
import { FormControl } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ListService } from '../../../../core/services/list.service';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { NotificationPopupComponent } from '../../notification-popup/notification-popup.component';
import { NotificationService } from '../../../services/notification.service';
import { UserCollection } from '../../../../shared/models/userCollection.model';
import { UserCollection } from '../../../models/userCollection.model';
import {
trigger,
@@ -15,9 +15,9 @@ import {
} from '@angular/animations';
@Component({
selector: 'app-list-selection-modal',
templateUrl: './list-selection-modal.component.html',
styleUrls: ['./list-selection-modal.component.css'],
selector: 'app-user-collections-modal',
templateUrl: './user-collections-modal.component.html',
styleUrls: ['./user-collections-modal.component.css'],
animations: [
trigger('fadeInOut', [
state('in', style({ opacity: 1 })),
@@ -36,20 +36,20 @@ import {
]),
],
})
export class ListSelectionModalComponent implements OnInit {
export class UserCollectionsModalComponent implements OnInit {
@Input() entryId: number = 0;
@ViewChild(NotificationPopupComponent)
notificationComponent!: NotificationPopupComponent;
searchControl = new FormControl('');
showAddButton: boolean = false;
lists: UserCollection[] = [];
listsToShow: UserCollection[] = [];
userCollections: UserCollection[] = [];
userCollectionsToShow: UserCollection[] = [];
constructor(
public dialogRef: MatDialogRef<ListSelectionModalComponent>,
public dialogRef: MatDialogRef<UserCollectionsModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private listService: ListService,
private listService: UserCollectionService,
private notificationService: NotificationService
) {}
@@ -64,17 +64,19 @@ export class ListSelectionModalComponent implements OnInit {
getLists() {
this.listService.getLists().subscribe({
next: (l) => {
l.forEach((list) => {
next: (c) => {
c.forEach((collection) => {
if (
list.listEntries.some((entry) => entry.entry_id == this.entryId)
collection.userCollectionEntries.some(
(entry) => entry.entry_id == this.entryId
)
) {
list.isChecked = true;
collection.isChecked = true;
}
});
this.lists = l;
this.listsToShow = this.lists;
this.userCollections = c;
this.userCollectionsToShow = this.userCollections;
this.applyFilter(this.searchControl.value);
},
error: (error) => {
@@ -85,18 +87,18 @@ export class ListSelectionModalComponent implements OnInit {
applyFilter(filterValue: string | null) {
if (filterValue == null) {
this.listsToShow = [...this.lists]; // Show all lists if filter is cleared or null
this.showAddButton = false; // Assuming you want to hide the button when there's no filter
this.userCollectionsToShow = [...this.userCollections];
this.showAddButton = false;
return;
}
const normalizedFilter = filterValue.toLowerCase().trim();
this.listsToShow = this.lists.filter((list) =>
this.userCollectionsToShow = this.userCollections.filter((list) =>
list.name.toLowerCase().trim().includes(normalizedFilter)
);
this.showAddButton = this.listsToShow.length === 0;
this.showAddButton = this.userCollectionsToShow.length === 0;
}
createList() {
@@ -113,17 +115,23 @@ export class ListSelectionModalComponent implements OnInit {
return this.showAddButton;
}
onSelectionChange(list: UserCollection, event: Event): void {
onSelectionChange(userCollection: UserCollection, event: Event): void {
const inputElement = event.target as HTMLInputElement;
const isChecked = inputElement.checked;
if (isChecked || isChecked == null) {
console.log(`Adding Entry ${this.entryId} to list: ${list.name}`);
console.log(
`Adding Entry ${this.entryId} to list: ${userCollection.name}`
);
this.listService
.addEntryToList(list.id, this.entryId, list.listEntries.length + 1)
.addEntryToList(
userCollection.id,
this.entryId,
userCollection.userCollectionEntries.length + 1
)
.subscribe({
next: (response) => {
console.log('Success:', response);
console.log('Successfuly added Entry To Collection:', response);
this.getLists();
this.showNotification(
'Entry Added',
@@ -137,9 +145,11 @@ export class ListSelectionModalComponent implements OnInit {
},
});
} else {
console.log(`Removing Entry ${this.entryId} from list: ${list.name}`);
console.log(
`Removing Entry ${this.entryId} from list: ${userCollection.name}`
);
this.listService
.removeEntryFromList(list.id.toString(), this.entryId)
.removeEntryFromList(userCollection.id.toString(), this.entryId)
.subscribe({
next: (_) => {
this.showNotification(