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

+2 -2
View File
@@ -26,7 +26,7 @@ import { LibraryComponent } from './features/library/library.component';
import { DynamicEntryListComponent } from './shared/components/lists/dynamic-entry-list/dynamic-entry-list.component';
import { NotificationPopupComponent } from './shared/components/notification-popup/notification-popup.component';
import { MainCardComponent } from './shared/components/cards/main-card/main-card.component';
import { ListSelectionModalComponent } from './shared/components/modals/list-selection-modal/list-selection-modal.component';
import { UserCollectionsModalComponent } from './shared/components/modals/list-selection-modal/user-collections-modal.component';
@NgModule({
declarations: [
@@ -42,7 +42,7 @@ import { ListSelectionModalComponent } from './shared/components/modals/list-sel
MainCardComponent,
DynamicEntryListComponent,
NotificationPopupComponent,
ListSelectionModalComponent,
UserCollectionsModalComponent,
],
imports: [
CoreModule,
@@ -17,29 +17,20 @@
<div class="card-header d-lg-none">
<div class="position-relative">
<input class="form-control rounded-5 px-5 mobile-search-control" type="text" placeholder="Search">
<span
class="material-icons-outlined position-absolute ms-3 translate-middle-y start-0 top-50">search</span>
<span
class="material-icons-outlined position-absolute me-3 translate-middle-y end-0 top-50 mobile-search-close">close</span>
</div>
<span class="material-icons-outlined position-absolute ms-3 translate-middle-y start-0 top-50">search</span>
<span class="material-icons-outlined position-absolute me-3 translate-middle-y end-0 top-50 mobile-search-close">close</span>
</div>
</div>
<div class="card-body search-content">
<div class="card-body search-content ps ps--active-y">
<p class="search-title">Recent Searches</p>
<div class="d-flex align-items-start flex-wrap gap-2 kewords-wrapper">
<a href="javascript:;" class="kewords"><span>Angular Template</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Dashboard</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Admin Template</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Bootstrap 5 Admin</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Html eCommerce</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Sass</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>laravel 9</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Angular Template</span><i class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Dashboard</span><i class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Admin Template</span><i class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Bootstrap 5 Admin</span><i class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Html eCommerce</span><i class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Sass</span><i class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>laravel 9</span><i class="material-icons-outlined fs-6">search</i></a>
</div>
<hr>
<p class="search-title">Tutorials</p>
@@ -77,7 +68,7 @@
<div class="search-list d-flex flex-column gap-2">
<div class="search-list-item d-flex align-items-center gap-3">
<div class="memmber-img">
<img src="https://picsum.photos/32/32" width="32" height="32" class="rounded-circle" alt="">
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
</div>
<div class="">
<h5 class="mb-0 search-list-title ">Andrew Stark</h5>
@@ -86,7 +77,7 @@
<div class="search-list-item d-flex align-items-center gap-3">
<div class="memmber-img">
<img src="https://picsum.photos/32/32" width="32" height="32" class="rounded-circle" alt="">
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
</div>
<div class="">
<h5 class="mb-0 search-list-title ">Snetro Jhonia</h5>
@@ -95,7 +86,7 @@
<div class="search-list-item d-flex align-items-center gap-3">
<div class="memmber-img">
<img src="https://picsum.photos/32/32" width="32" height="32" class="rounded-circle" alt="">
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
</div>
<div class="">
<h5 class="mb-0 search-list-title">Michle Clark</h5>
@@ -103,7 +94,7 @@
</div>
</div>
</div>
<div class="ps__rail-x" style="left: 0px; bottom: 0px;"><div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div></div><div class="ps__rail-y" style="top: 0px; right: 0px; height: 389px;"><div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 281px;"></div></div></div>
<div class="card-footer text-center bg-transparent">
<a href="javascript:;" class="btn w-100">See All Search Results</a>
</div>
@@ -74,13 +74,13 @@
<div class="menu-title">Watchlist</div>
</a>
</li>
<li routerLink="/lists" routerLinkActive="mm-active">
<li routerLink="/user-collections" routerLinkActive="mm-active">
<a>
<div class="parent-icon"><span class="material-symbols-outlined">
format_list_bulleted
</span>
</div>
<div class="menu-title">Lists</div>
<div class="menu-title">Collections</div>
</a>
</li>
+4 -3
View File
@@ -4,19 +4,20 @@ import { CommonModule } from '@angular/common';
import { TmdbService } from './services/tmdb.service';
import { LibraryService } from './services/library.service';
import { EntryService } from './services/entry.service';
import { ListService } from './services/list.service';
import { UserCollectionService } from './services/userCollection.service';
import { ToggleService } from './services/toggle.service';
import { SidebarComponent } from './components/sidebar/sidebar.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { RouterModule } from '@angular/router';
@NgModule({
declarations: [SidebarComponent, NavbarComponent],
imports: [CommonModule],
imports: [CommonModule, RouterModule],
providers: [
TmdbService,
LibraryService,
EntryService,
ListService,
UserCollectionService,
ToggleService,
],
exports: [SidebarComponent, NavbarComponent],
@@ -1,65 +0,0 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { UserCollection } from '../../shared/models/userCollection.model';
import { ListEntry } from '../../shared/models/listEntry.model';
import { Entry } from '../../shared/models/entry.model';
@Injectable({
providedIn: 'root',
})
export class ListService {
private backend_apiUrl = 'http://localhost:4000/api/v1';
constructor(private http: HttpClient) {}
// get all lists
getLists(): Observable<UserCollection[]> {
return this.http.get<UserCollection[]>(`${this.backend_apiUrl}/lists`);
}
// get a list by id
getList(id: string) {
return this.http.get<UserCollection[]>(`${this.backend_apiUrl}/lists/${id}`);
}
// Create a new list
createList(list: UserCollection): Observable<UserCollection> {
return this.http.post<UserCollection>(`${this.backend_apiUrl}/lists`, list);
}
// Delete a list by ID
deleteList(id: number): Observable<any> {
return this.http.delete(`${this.backend_apiUrl}/lists/${id}`);
}
// Add an entry to a list
addEntryToList(
listId: number,
entryId: number,
order: number
): Observable<ListEntry> {
return this.http.post<ListEntry>(
`${this.backend_apiUrl}/lists/${listId}/entries/${entryId}`,
{ order: order }
);
}
// Update an entry's order in a list
updateEntryOrder(
listId: number,
entryId: number,
newOrder: number
): Observable<any> {
return this.http.patch(
`${this.backend_apiUrl}/lists/${listId}/entries/${entryId}/order`,
{ newOrder }
);
}
// Remove an entry from a list
removeEntryFromList(listId: string, entryId: number): Observable<Entry> {
return this.http.delete<Entry>(
`${this.backend_apiUrl}/lists/${listId}/entries/${entryId}`
);
}
}
@@ -0,0 +1,79 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { UserCollection } from '../../shared/models/userCollection.model';
import { UserCollectionEntry } from '../../shared/models/userCollectionEntry.model';
import { Entry } from '../../shared/models/entry.model';
@Injectable({
providedIn: 'root',
})
export class UserCollectionService {
private backend_apiUrl = 'http://localhost:4000/api/v1';
private apiAction = 'user-collections';
constructor(private http: HttpClient) {}
// get all lists
getLists(): Observable<UserCollection[]> {
return this.http.get<UserCollection[]>(
`${this.backend_apiUrl}/${this.apiAction}`
);
}
// get a list by id
getList(userCollectionId: string) {
return this.http.get<UserCollection[]>(
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}`
);
}
// Create a new list
createList(userCollection: UserCollection): Observable<UserCollection> {
return this.http.post<UserCollection>(
`${this.backend_apiUrl}/${this.apiAction}`,
userCollection
);
}
// Delete a list by ID
deleteList(userCollectionId: number): Observable<any> {
return this.http.delete(
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}`
);
}
// Add an entry to a list
addEntryToList(
userCollectionId: number,
entryId: number,
order: number
): Observable<UserCollectionEntry> {
return this.http.post<UserCollectionEntry>(
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`,
{ order: order }
);
}
// Update an entry's order in a list
updateEntryOrder(
userCollectionId: string,
entryId: number,
newOrder: number
): Observable<any> {
return this.http.patch(
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}/order`,
{ newOrder }
);
}
// Remove an entry from a list
removeEntryFromList(
userCollectionId: string,
entryId: number
): Observable<Entry> {
return this.http.delete<Entry>(
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`
);
}
}
@@ -3,7 +3,7 @@ import { MatDialog } from '@angular/material/dialog';
import { LibraryService } from '../../../../core/services/library.service';
import { Entry } from '../../../../shared/models/entry.model';
import { trigger, transition, style, animate } from '@angular/animations';
import { ListService } from '../../../../core/services/list.service';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
@Component({
selector: 'app-userCollection-grid-card',
@@ -26,7 +26,7 @@ export class UserCollectionGridCardComponent {
constructor(
private libraryService: LibraryService,
private listService: ListService,
private listService: UserCollectionService,
public dialog: MatDialog
) {}
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ListService } from '../../../../core/services/list.service';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { UserCollection } from '../../../../shared/models/userCollection.model';
import { Entry } from '../../../../shared/models/entry.model';
import { DatePipe } from '@angular/common';
@@ -18,7 +18,7 @@ export class UserCollectionInfoPageComponent {
constructor(
private route: ActivatedRoute,
private listService: ListService,
private listService: UserCollectionService,
private datePipe: DatePipe
) {}
@@ -3,7 +3,7 @@
<div class="flex-grow-1 list-item-1">
<h6 class="mb-0 list-title" (click)="redirectTo()">{{list.name}}</h6>
<p class="mb-0">Created: {{getCreatedDate() | dateFormat}}</p>
<p class="mb-0">Contains: {{list.listEntries.length}} title(s)</p>
<p class="mb-0">Contains: {{list.userCollectionEntries.length}} title(s)</p>
</div>
<!-- <div class="form-check form-check-inline me-0">
<input class="form-check-input ms-0" type="checkbox">
@@ -1,6 +1,6 @@
import { Component, Input} from '@angular/core';
import { UserCollection } from '../../../../shared/models/userCollection.model';
import { ListService } from '../../../../core/services/list.service';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { Router } from '@angular/router';
import { trigger, transition, style, animate } from '@angular/animations';
@@ -25,7 +25,7 @@ import { trigger, transition, style, animate } from '@angular/animations';
export class UserCollectionsListItemComponent {
@Input() list!: UserCollection;
constructor(private listService: ListService, private router: Router) {}
constructor(private listService: UserCollectionService, private router: Router) {}
getPostPath() {
if (this.list.poster_path == null) return 'https://pic.pnnet.dev/256x256';
@@ -40,7 +40,7 @@ export class UserCollectionsListItemComponent {
}
redirectTo(): void {
this.router.navigate([`/lists/${this.list.id}`]);
this.router.navigate([`/user-collections/${this.list.id}`]);
}
deleteList() {
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { UserCollection } from '../../../../shared/models/userCollection.model';
import { ListService } from '../../../../core/services/list.service';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
@Component({
selector: 'app-userCollections-page',
@@ -16,7 +16,7 @@ export class UserCollectionsPageComponent implements OnInit {
lists: UserCollection[] = [];
listsToShow: UserCollection[] = [];
constructor(private listService: ListService) {}
constructor(private listService: UserCollectionService) {}
ngOnInit() {
this.getLists();
@@ -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(
@@ -0,0 +1,11 @@
export interface EpisodeSeen {
id: number;
episode_id: number;
date_seen: Date;
seen_with: string;
createdAt: Date;
updatedAt: Date;
}
@@ -1,5 +1,5 @@
import { Entry } from './entry.model';
import { ListEntry } from './listEntry.model';
import { UserCollectionEntry } from './userCollectionEntry.model';
export interface UserCollection {
id: number;
@@ -10,7 +10,7 @@ export interface UserCollection {
poster_path: string;
listEntries: ListEntry[];
userCollectionEntries: UserCollectionEntry[];
entries: Entry[];
changed: boolean;
isChecked: boolean;
@@ -1,5 +1,5 @@
export interface ListEntry {
list_id: number;
export interface UserCollectionEntry {
user_collection_id: number;
entry_id: number;
order: number;
+1 -1
View File
@@ -4,7 +4,7 @@ import { NotificationPopupComponent } from './components/notification-popup/noti
import { DateFormatPipe } from './pipes/date-format/date-format.pipe';
import { MainCardComponent } from './components/cards/main-card/main-card.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ListSelectionModalComponent } from './components/modals/list-selection-modal/list-selection-modal.component';
import { UserCollectionsModalComponent } from './components/modals/list-selection-modal/user-collections-modal.component';
@NgModule({
declarations: [