Commit 190d8e14a4d64dfed9c94ba8a3efd64194c1fce0
Exists in
develop
Merge branch 'develop' into 'develop'
Develop See merge request !160
Showing
2 changed files
Show diff stats
src/app/modules/carrito/carrito.component.ts
| 1 | import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy, HostListener } from '@angular/core'; |
| 2 | import { Location } from '@angular/common'; | 2 | import { Location } from '@angular/common'; |
| 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 3 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; |
| 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; | 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
| 5 | import { Router } from '@angular/router'; | 5 | import { Router } from '@angular/router'; |
| 6 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | 6 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; |
| 7 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; | 7 | import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service'; |
| 8 | import { ANIMATIONS } from 'src/app/utils/animations'; | 8 | import { ANIMATIONS } from 'src/app/utils/animations'; |
| 9 | import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; | 9 | import { ErrorFormaPagoComponent } from 'src/app/shared/error-forma-pago/error-forma-pago.component'; |
| 10 | import { ErrorStockComponent } from 'src/app/shared/error-stock/error-stock.component'; | 10 | import { ErrorStockComponent } from 'src/app/shared/error-stock/error-stock.component'; |
| 11 | 11 | ||
| 12 | @Component({ | 12 | @Component({ |
| 13 | selector: 'app-carrito', | 13 | selector: 'app-carrito', |
| 14 | templateUrl: './carrito.component.html', | 14 | templateUrl: './carrito.component.html', |
| 15 | styleUrls: ['./carrito.component.scss'], | 15 | styleUrls: ['./carrito.component.scss'], |
| 16 | animations: [ANIMATIONS.EnterLeaveX] | 16 | animations: [ANIMATIONS.EnterLeaveX] |
| 17 | }) | 17 | }) |
| 18 | export class CarritoComponent implements OnInit, OnDestroy { | 18 | export class CarritoComponent implements OnInit, OnDestroy { |
| 19 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; | 19 | urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`; |
| 20 | maxCantidad = 50; | 20 | maxCantidad = 50; |
| 21 | modalRef: BsModalRef; | 21 | modalRef: BsModalRef; |
| 22 | 22 | ||
| 23 | constructor( | 23 | constructor( |
| 24 | public articuloService: ArticuloService, | 24 | public articuloService: ArticuloService, |
| 25 | private location: Location, | 25 | private location: Location, |
| 26 | private router: Router, | 26 | private router: Router, |
| 27 | private inactiveScreen: InactiveScreenService, | 27 | private inactiveScreen: InactiveScreenService, |
| 28 | private modalService: BsModalService | 28 | private modalService: BsModalService |
| 29 | ) { } | 29 | ) { } |
| 30 | 30 | ||
| 31 | ngOnInit() { | 31 | ngOnInit() { |
| 32 | if (!this.articuloService.carrito.length) { | 32 | if (!this.articuloService.carrito.length) { |
| 33 | this.router.navigate(['']); | 33 | this.router.navigate(['']); |
| 34 | return; | 34 | return; |
| 35 | } | 35 | } |
| 36 | this.mediaPantalla(); | 36 | this.mediaPantalla(); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | ngOnDestroy() { | 39 | ngOnDestroy() { |
| 40 | if (this.modalRef) this.modalRef.hide(); | 40 | if (this.modalRef) this.modalRef.hide(); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | deleteArticulo(index: number) { | 43 | deleteArticulo(index: number) { |
| 44 | this.articuloService.deleteArticulo(index); | 44 | this.articuloService.deleteArticulo(index); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | validateCarrito() { | 47 | validateCarrito() { |
| 48 | const res = this.articuloService.validateCarrito() | 48 | const res = this.articuloService.validateCarrito(); |
| 49 | if (res.valid) { | 49 | if (res.valid) { |
| 50 | this.router.navigate(['forma-pago']); | 50 | this.router.navigate(['forma-pago']); |
| 51 | } else { | 51 | } else { |
| 52 | this.modalService.show( | 52 | this.modalService.show( |
| 53 | ErrorStockComponent, | 53 | ErrorStockComponent, |
| 54 | { | 54 | { |
| 55 | initialState: { articulo: res.articulo }, | 55 | initialState: { articulo: res.articulo }, |
| 56 | class: 'modal-dialog-centered' | 56 | class: 'modal-dialog-centered' |
| 57 | }); | 57 | }); |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | goBack() { | 61 | goBack() { |
| 62 | this.location.back(); | 62 | this.location.back(); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | @HostListener('document:click', ['$event']) | 65 | @HostListener('document:click', ['$event']) |
| 66 | eventListener(event: Event) { | 66 | eventListener(event: Event) { |
| 67 | clearTimeout(this.inactiveScreen.timerReposo); | 67 | clearTimeout(this.inactiveScreen.timerReposo); |
| 68 | this.inactiveScreen.startTimeOutInactividad(); | 68 | this.inactiveScreen.startTimeOutInactividad(); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | @HostListener('scroll', ['$event']) | 71 | @HostListener('scroll', ['$event']) |
| 72 | scrollEvent(event: Event) { | 72 | scrollEvent(event: Event) { |
| 73 | clearTimeout(this.inactiveScreen.timerReposo); | 73 | clearTimeout(this.inactiveScreen.timerReposo); |
| 74 | this.inactiveScreen.startTimeOutInactividad(); | 74 | this.inactiveScreen.startTimeOutInactividad(); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | mediaPantalla() { | 77 | mediaPantalla() { |
| 78 | if ($('body').hasClass('media-pantalla')) { | 78 | if ($('body').hasClass('media-pantalla')) { |
| 79 | $(`.carrito-content`).addClass('media-pantalla').addBack('media-pantalla'); | 79 | $(`.carrito-content`).addClass('media-pantalla').addBack('media-pantalla'); |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | 83 |
src/app/shared/error-stock/error-stock.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
| 2 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 2 | import { BsModalRef } from 'ngx-bootstrap/modal'; |
| 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; |
| 4 | 4 | ||
| 5 | @Component({ | 5 | @Component({ |
| 6 | selector: 'app-error-stock', | 6 | selector: 'app-error-stock', |
| 7 | templateUrl: './error-stock.component.html', | 7 | templateUrl: './error-stock.component.html', |
| 8 | styleUrls: ['./error-stock.component.scss'] | 8 | styleUrls: ['./error-stock.component.scss'] |
| 9 | }) | 9 | }) |
| 10 | export class ErrorStockComponent implements OnInit { | 10 | export class ErrorStockComponent implements OnInit { |
| 11 | articulo: IArticulo; | 11 | articulo: IArticulo; |
| 12 | 12 | ||
| 13 | constructor( | 13 | constructor( |
| 14 | private modalRef: BsModalRef, | 14 | public modalRef: BsModalRef, |
| 15 | ) { } | 15 | ) { } |
| 16 | 16 | ||
| 17 | ngOnInit() { } | 17 | ngOnInit() { } |
| 18 | 18 | ||
| 19 | } | 19 | } |
| 20 | 20 |