Commit cf4cf00f5e2ead64f6d591288340cd687d7cb1f0
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master See merge request !20
Showing
4 changed files
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.html
| ... | ... | @@ -83,7 +83,7 @@ |
| 83 | 83 | type="button" |
| 84 | 84 | class="btn btn-light btn-lg shadow-sm" |
| 85 | 85 | [routerLink]="['/inicio']"> |
| 86 | - <span class="font-weight-normal h6">Volver </span> | |
| 86 | + <span class="font-weight-normal h6 pr-2">Volver</span> | |
| 87 | 87 | <i class="fa fa-undo text-warning" aria-hidden="true"></i> |
| 88 | 88 | </button> |
| 89 | 89 | </div> |
src/app/components/busqueda-productos/busqueda-productos.component.ts
| 1 | -import { Component, OnInit, Input, ViewChild, AfterViewInit } from '@angular/core'; | |
| 1 | +import { Component, OnInit } from '@angular/core'; | |
| 2 | 2 | import { ProductoService } from 'src/app/services/producto.service'; |
| 3 | 3 | import { Producto } from 'src/app/wrappers/producto'; |
| 4 | 4 | import { appSettings } from 'src/etc/AppSettings'; |
| 5 | -import { SidebarComponent } from '../sidebar/sidebar.component'; | |
| 6 | 5 | |
| 7 | 6 | @Component({ |
| 8 | 7 | selector: 'app-busqueda-productos', |
| ... | ... | @@ -18,14 +17,9 @@ export class BusquedaProductosComponent implements OnInit { |
| 18 | 17 | private categoria: Categorias = Categorias.todos; |
| 19 | 18 | private apiUrl: string = appSettings.apiUrl; |
| 20 | 19 | |
| 21 | - productosParaCarrito : Producto[] = []; | |
| 22 | 20 | |
| 23 | 21 | constructor(private productoService: ProductoService) { } |
| 24 | 22 | |
| 25 | - // ngAfterViewInit() { | |
| 26 | - // this.sideBar.productos = []; | |
| 27 | - // } | |
| 28 | - | |
| 29 | 23 | ngOnInit() { |
| 30 | 24 | |
| 31 | 25 | this.productoService.getAll() |
| ... | ... | @@ -39,14 +33,16 @@ export class BusquedaProductosComponent implements OnInit { |
| 39 | 33 | } |
| 40 | 34 | |
| 41 | 35 | filterItems() { |
| 36 | + | |
| 42 | 37 | this.auxProductos = this.productos.filter(x => { |
| 43 | 38 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) |
| 44 | 39 | }); |
| 45 | 40 | } |
| 46 | 41 | |
| 47 | 42 | agregarAlCarrito(producto: Producto) { |
| 43 | + | |
| 48 | 44 | producto.cantidad = 1; |
| 49 | - this.productosParaCarrito.push(producto); | |
| 45 | + this.productoService.productos.push(producto); | |
| 50 | 46 | } |
| 51 | 47 | |
| 52 | 48 | } |
src/app/components/sidebar/sidebar.component.ts
| 1 | -import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; | |
| 1 | +import { Component, OnInit } from '@angular/core'; | |
| 2 | 2 | import { Producto } from 'src/app/wrappers/producto'; |
| 3 | 3 | import { appSettings } from 'src/etc/AppSettings'; |
| 4 | +import { ProductoService } from 'src/app/services/producto.service'; | |
| 4 | 5 | |
| 5 | 6 | |
| 6 | 7 | @Component({ |
| 7 | 8 | selector: 'app-sidebar', |
| 8 | 9 | templateUrl: './sidebar.component.html', |
| 9 | 10 | styleUrls: ['./sidebar.component.scss'], |
| 10 | - inputs: ['productosCarrito'] | |
| 11 | 11 | }) |
| 12 | 12 | export class SidebarComponent implements OnInit { |
| 13 | 13 | |
| ... | ... | @@ -19,9 +19,14 @@ export class SidebarComponent implements OnInit { |
| 19 | 19 | |
| 20 | 20 | public productosCarrito: Producto[] = []; |
| 21 | 21 | |
| 22 | - constructor() { } | |
| 22 | + constructor(private productoService: ProductoService) { | |
| 23 | + | |
| 24 | + this.productosCarrito = this.productoService.productos; | |
| 25 | + } | |
| 26 | + | |
| 27 | + ngOnInit() { | |
| 23 | 28 | |
| 24 | - ngOnInit() { } | |
| 29 | + } | |
| 25 | 30 | |
| 26 | 31 | getCantidadProductos() { |
| 27 | 32 | |
| ... | ... | @@ -57,7 +62,7 @@ export class SidebarComponent implements OnInit { |
| 57 | 62 | decrementarContador(index) { |
| 58 | 63 | |
| 59 | 64 | for (let i = 0; i < this.productosCarrito.length; i++) { |
| 60 | - if (i === index && this.productosCarrito[i].cantidad > 1) { | |
| 65 | + if (i === index && this.productosCarrito[i].cantidad > this.min) { | |
| 61 | 66 | this.productosCarrito[i].cantidad--; |
| 62 | 67 | this.cont--; |
| 63 | 68 | break; |
| ... | ... | @@ -75,7 +80,7 @@ export class SidebarComponent implements OnInit { |
| 75 | 80 | } |
| 76 | 81 | } |
| 77 | 82 | |
| 78 | - deleteProducto(index) { | |
| 83 | + deleteProducto(index: number) { | |
| 79 | 84 | |
| 80 | 85 | for (let i = 0; i < this.productosCarrito.length; i++) { |
| 81 | 86 | if (i === index) { |
| ... | ... | @@ -90,7 +95,7 @@ export class SidebarComponent implements OnInit { |
| 90 | 95 | |
| 91 | 96 | cleanCarrito() { |
| 92 | 97 | |
| 93 | - this.productosCarrito = []; | |
| 98 | + this.productoService.productos = this.productosCarrito = []; | |
| 94 | 99 | this.total = 0; |
| 95 | 100 | this.cont = 0; |
| 96 | 101 | } |
src/app/services/producto.service.ts
| ... | ... | @@ -2,16 +2,25 @@ import { Injectable } from '@angular/core'; |
| 2 | 2 | import { HttpClient } from '@angular/common/http'; |
| 3 | 3 | import { Observable } from 'rxjs'; |
| 4 | 4 | import { appSettings } from 'src/etc/AppSettings'; |
| 5 | +import { Producto } from '../wrappers/producto'; | |
| 5 | 6 | |
| 6 | 7 | @Injectable({ |
| 7 | 8 | providedIn: 'root' |
| 8 | 9 | }) |
| 9 | 10 | export class ProductoService { |
| 10 | 11 | |
| 12 | + productos : Producto[] = []; | |
| 13 | + | |
| 11 | 14 | constructor(private http: HttpClient) { } |
| 12 | 15 | |
| 13 | 16 | getAll(): Observable<any> { |
| 17 | + | |
| 14 | 18 | return this.http.get(`${appSettings.apiUrl}/articulos`); |
| 15 | 19 | } |
| 16 | 20 | |
| 21 | + setProductos(producto : Producto){ | |
| 22 | + | |
| 23 | + this.productos.push(producto); | |
| 24 | + } | |
| 25 | + | |
| 17 | 26 | } |