carrito.component.ts
1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Component, OnInit, OnDestroy, HostListener } from '@angular/core';
import { Location } from '@angular/common';
import { ArticuloService } from 'src/app/services/articulo/articulo.service';
import { APP_SETTINGS } from 'src/etc/AppSettings';
import { Router } from '@angular/router';
import { BsModalRef } from 'ngx-bootstrap/modal/public_api';
import { InactiveScreenService } from 'src/app/services/inactive-screen/inactive-screen.service';
import { ANIMATIONS } from 'src/app/utils/animations';
@Component({
selector: 'app-carrito',
templateUrl: './carrito.component.html',
styleUrls: ['./carrito.component.scss'],
animations: [ANIMATIONS.EnterLeaveX]
})
export class CarritoComponent implements OnInit, OnDestroy {
urlImagenes = `${APP_SETTINGS.apiImagenes}/imagenes/`;
maxCantidad = 50;
modalRef: BsModalRef;
constructor(
public articuloService: ArticuloService,
private location: Location,
private router: Router,
private inactiveScreen: InactiveScreenService,
) { }
ngOnInit() {
if (!this.articuloService.carrito.length) {
this.router.navigate(['']);
return;
}
this.mediaPantalla();
}
ngOnDestroy() {
if (this.modalRef) this.modalRef.hide();
}
deleteArticulo(index: number) {
this.articuloService.deleteArticulo(index);
}
goBack() {
this.location.back();
}
@HostListener('document:click', ['$event'])
eventListener(event: Event) {
clearTimeout(this.inactiveScreen.timerReposo);
this.inactiveScreen.startTimeOutInactividad();
}
@HostListener('scroll', ['$event'])
scrollEvent(event: Event) {
clearTimeout(this.inactiveScreen.timerReposo);
this.inactiveScreen.startTimeOutInactividad();
}
mediaPantalla() {
if ($('body').hasClass('media-pantalla')) {
$(`.carrito-content`).addClass('media-pantalla').addBack('media-pantalla');
}
}
}