changed style for list selection modal + fixed functions
This commit is contained in:
1 parent
bcf1cd3cec
commit
cd4514fd2d
4 files changed
+282
No files matched your search
+36
@@ -0,0 +1,36 @@
|
|||||||
|
.modal-content {
|
||||||
|
padding: 20px 20px 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-body {
|
||||||
|
padding-right: 5px;
|
||||||
|
padding-left: 5px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-footer {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-input {
|
||||||
|
padding-right: 10px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplebar-content-wrapper {
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplebar-content-wrapper {
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-lists {
|
||||||
|
height: 100%;
|
||||||
|
background-color: var(--bs-body-bg) !important;
|
||||||
|
border-right: 1px solid var(--bs-border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-lists .btn {
|
||||||
|
color: var(--bs-border-color);
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
<!-- <h2 mat-dialog-title>Choose a list</h2>
|
||||||
|
<mat-dialog-content>
|
||||||
|
<mat-form-field appearance="fill">
|
||||||
|
<mat-label>List Name</mat-label>
|
||||||
|
<input [formControl]="searchControl" matInput>
|
||||||
|
</mat-form-field>
|
||||||
|
<mat-dialog-actions align="center" *ngIf="doShowAddButton()">
|
||||||
|
<button mat-button (click)="createList()" *ngIf="doShowAddButton()">Create List</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
|
<mat-selection-list #shoes (selectionChange)="onSelectionChange($event)">
|
||||||
|
<mat-list-option *ngFor="let list of listsToShow" [value]="list.id" checkboxPosition="before">
|
||||||
|
{{list.name}}
|
||||||
|
</mat-list-option>
|
||||||
|
</mat-selection-list>
|
||||||
|
</mat-dialog-content>
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-button [mat-dialog-close]="true">OK</button>
|
||||||
|
<button mat-button mat-dialog-close>Cancel</button>
|
||||||
|
</mat-dialog-actions> -->
|
||||||
|
<div class="modal-content user-lists">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h2 class="modal-title">Choose a list</h2>
|
||||||
|
<button type="button" class="btn-close" (click)="closeDialog()"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal Body -->
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="input-group mb-3 ">
|
||||||
|
<!-- <label for="listNameInput" class="form-label">List Name</label> -->
|
||||||
|
<input type="text" class="form-control" id="listNameInput" [formControl]="searchControl"
|
||||||
|
placeholder="List name..." @scaleInOut>
|
||||||
|
<button class="btn btn-success growing-width-element" type="button" *ngIf="doShowAddButton()" (click)="createList()" @scaleInOut>Create
|
||||||
|
List</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="d-grid gap-2" *ngIf="doShowAddButton()">
|
||||||
|
</div>
|
||||||
|
<div data-simplebar class="simplebar-content-wrapper">
|
||||||
|
<div class="list-group">
|
||||||
|
|
||||||
|
<label *ngFor="let list of listsToShow" 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 }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal Footer -->
|
||||||
|
<div class="modal-footer">
|
||||||
|
<div class="btn-group">
|
||||||
|
<!-- <button type="button" class="btn btn-secondary" (click)="closeDialog()">Cancel</button> -->
|
||||||
|
<button type="button" class="btn btn-primary" (click)="confirmSelection()">OK</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
+168
@@ -0,0 +1,168 @@
|
|||||||
|
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 { List } from '../../../shared/models/list.model';
|
||||||
|
import { NotificationPopupComponent } from '../../../shared/notification-popup/notification-popup.component';
|
||||||
|
import { NotificationService } from '../../../shared/services/notification.service';
|
||||||
|
import {
|
||||||
|
trigger,
|
||||||
|
state,
|
||||||
|
style,
|
||||||
|
transition,
|
||||||
|
animate,
|
||||||
|
} from '@angular/animations';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-list-selection-modal',
|
||||||
|
templateUrl: './list-selection-modal.component.html',
|
||||||
|
styleUrls: ['./list-selection-modal.component.css'],
|
||||||
|
animations: [
|
||||||
|
trigger('fadeInOut', [
|
||||||
|
state('in', style({ opacity: 1 })),
|
||||||
|
transition(':enter', [style({ opacity: 0 }), animate(600)]),
|
||||||
|
transition(':leave', [animate(600, style({ opacity: 0 }))]),
|
||||||
|
]),
|
||||||
|
trigger('scaleInOut', [
|
||||||
|
transition(':enter', [
|
||||||
|
state('in', style({ opacity: 1 })),
|
||||||
|
style({ transform: 'scale(0)' }),
|
||||||
|
animate('200ms ease-in-out', style({ transform: 'scale(1)' })),
|
||||||
|
]),
|
||||||
|
transition(':leave', [
|
||||||
|
animate('200ms ease-in-out', style({ transform: 'scale(0)' })),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
export class ListSelectionModalComponent implements OnInit {
|
||||||
|
@Input() entryId: number = 0;
|
||||||
|
@ViewChild(NotificationPopupComponent)
|
||||||
|
notificationComponent!: NotificationPopupComponent;
|
||||||
|
searchControl = new FormControl('');
|
||||||
|
showAddButton: boolean = false;
|
||||||
|
|
||||||
|
lists: List[] = [];
|
||||||
|
listsToShow: List[] = [];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public dialogRef: MatDialogRef<ListSelectionModalComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||||
|
private listService: ListService,
|
||||||
|
private notificationService: NotificationService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.entryId = this.data.entryId;
|
||||||
|
this.getLists();
|
||||||
|
|
||||||
|
this.searchControl.valueChanges.subscribe((value) => {
|
||||||
|
this.applyFilter(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getLists() {
|
||||||
|
this.listService.getLists().subscribe({
|
||||||
|
next: (l) => {
|
||||||
|
l.forEach((list) => {
|
||||||
|
if (
|
||||||
|
list.listEntries.some((entry) => entry.entry_id == this.entryId)
|
||||||
|
) {
|
||||||
|
list.isChecked = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.lists = l;
|
||||||
|
this.listsToShow = this.lists;
|
||||||
|
this.applyFilter(this.searchControl.value);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log("Counldn't get lists from backend.");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedFilter = filterValue.toLowerCase().trim();
|
||||||
|
|
||||||
|
this.listsToShow = this.lists.filter((list) =>
|
||||||
|
list.name.toLowerCase().trim().includes(normalizedFilter)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.showAddButton = this.listsToShow.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
createList() {
|
||||||
|
const listName = this.searchControl.value; // string
|
||||||
|
|
||||||
|
let myNewList = { name: listName } as List;
|
||||||
|
|
||||||
|
this.listService.createList(myNewList).subscribe(async (list) => {
|
||||||
|
await this.getLists();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
doShowAddButton(): boolean {
|
||||||
|
return this.showAddButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelectionChange(list: List, 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}`);
|
||||||
|
this.listService
|
||||||
|
.addEntryToList(list.id, this.entryId, list.listEntries.length + 1)
|
||||||
|
.subscribe({
|
||||||
|
next: (response) => {
|
||||||
|
console.log('Success:', response);
|
||||||
|
this.getLists();
|
||||||
|
this.showNotification(
|
||||||
|
'Entry Added',
|
||||||
|
'Entry added successfully',
|
||||||
|
'success'
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
this.showNotification('Error', 'Failed to add entry', 'error');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(`Removing Entry ${this.entryId} from list: ${list.name}`);
|
||||||
|
this.listService.removeEntryFromList(list.id, this.entryId).subscribe({
|
||||||
|
next: (_) => {
|
||||||
|
this.showNotification(
|
||||||
|
'Entry Removed',
|
||||||
|
'Entry removed successfully',
|
||||||
|
'success'
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error('Error removing entry:', error);
|
||||||
|
this.showNotification('Error', 'Failed to remove entry', 'error');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closeDialog(): void {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmSelection(): void {
|
||||||
|
this.dialogRef.close(/* Optionally pass back some data */);
|
||||||
|
}
|
||||||
|
|
||||||
|
showNotification(title: string, message: string, type: string): void {
|
||||||
|
// this.notificationComponent.showNotification(message, type);
|
||||||
|
this.notificationService.showNotification(title, message, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user