Skip to content

Commit

Permalink
Página ver lista - Remover producto de la lista
Browse files Browse the repository at this point in the history
- Ahora al seleccionar un producto, este se elimina de la lista. Solo cuando se muestran los productos pendientes o finalizados, si el filtro es mostrar todos, no remueve el producto de la lista.
  • Loading branch information
nmarulo committed Nov 29, 2024
1 parent 9827005 commit f4cdd57
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div class="d-flex py-2">
<p-checkbox styleClass="mr-2"
[binary]="true"
(onChange)="selectedEvent(response)"
checkboxIcon="fas fa-check"
formControlName="selected"/>
<div class="text-truncate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class ProductListComponent implements OnChanges {

@Output() deleteProduct = new EventEmitter<ProductShoppingList>();

@Output() removeProductList = new EventEmitter<ProductShoppingList>();

productListForm = this.formBuilder.nonNullable.group({
productsForm: this.formBuilder.array<FormGroup<{
selected: FormControl<boolean>;
Expand Down Expand Up @@ -99,4 +101,7 @@ export class ProductListComponent implements OnChanges {
this.deleteProduct.emit(response);
}

selectedEvent(response: ProductShoppingList) {
this.removeProductList.emit(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

<app-product-list [shoppingList]="shoppingListRes()"
(updateProduct)="updateProductEvent($event)"
(deleteProduct)="deleteProductEvent($event)"/>
(deleteProduct)="deleteProductEvent($event)"
(removeProductList)="removeProductListEvent($event)"/>

</ng-container>
</app-page>
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class ShoppingListComponent {

isNew = signal(false);

private currentSelectedProductOption = signal<string>('');

@Input()
set id(id: number) {
if (id) {
Expand Down Expand Up @@ -226,6 +228,8 @@ export class ShoppingListComponent {
selected: $event
};

this.currentSelectedProductOption.set($event);

this.shoppingListsService.findAllProducts(this.shoppingListRes().id, request)
.pipe(
tap(shoppingList => {
Expand All @@ -241,4 +245,21 @@ export class ShoppingListComponent {
)
.subscribe();
}

removeProductListEvent($event: ProductShoppingList) {
if (this.currentSelectedProductOption() === 'ALL') {
return;
}

this.shoppingListRes.update(value => ({
...value,
productList: {
...value.productList,
content: value.productList
.content
.filter(product => product.product.id !== $event.product.id)
}
})
);
}
}

0 comments on commit f4cdd57

Please sign in to comment.