Commit 6bf89ab1586d737f1fb485e4de9c5ab7509a8b76
Exists in
develop
Merge branch 'develop' into 'develop'
Develop See merge request !131
Showing
2 changed files
 
Show diff stats
src/app/shared/sinonimo/sinonimo.component.html
| 1 | <div class="bg-primary rounded text-white"> | 1 | <div class="bg-primary rounded text-white"> | 
| 2 | <div class="modal-header"> | 2 | <div class="modal-header"> | 
| 3 | <img | 3 | <img | 
| 4 | draggable="false" | 4 | draggable="false" | 
| 5 | ondragstart="return false;" | 5 | ondragstart="return false;" | 
| 6 | (contextmenu)="false" | 6 | (contextmenu)="false" | 
| 7 | (click)="close()" | 7 | (click)="close()" | 
| 8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute right-0 top-0 z-index" | 8 | class="btn-effect icon-30 mt-2 mr-2 position-absolute right-0 top-0 z-index" | 
| 9 | src="assets/img/icono-cancelar-blanco.svg"> | 9 | src="assets/img/icono-cancelar-blanco.svg"> | 
| 10 | <p class="col-12 h4 px-0 align-self-center">{{ articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase() }}</p> | 10 | <p class="col-12 h4 px-0 align-self-center">{{ articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase() }}</p> | 
| 11 | </div> | 11 | </div> | 
| 12 | 12 | ||
| 13 | <div class="modal-body my-2"> | 13 | <div class="modal-body my-2"> | 
| 14 | <p class="mb-2 h4">Opcion {{currentIndex+1}}</p> | 14 | <p class="mb-2 h4">Opcion {{currentIndex+1}}</p> | 
| 15 | <p class="mb-2 h5">Cantidad restante {{sinonimos[currentIndex].cantidadRestante}}</p> | 15 | <p class="mb-2 h5">Cantidad restante {{sinonimos[currentIndex].cantidadRestante}}</p> | 
| 16 | <div class="lista-sinonimos scroll-y-visible"> | 16 | <div class="lista-sinonimos scroll-y-visible"> | 
| 17 | <div | 17 | <div | 
| 18 | class="row mx-0 mb-2 fade-in-left" | 18 | class="row mx-0 mb-2 fade-in-left" | 
| 19 | *ngFor="let articulo of sinonimos[currentIndex].productos"> | 19 | *ngFor="let articulo of sinonimos[currentIndex].productos"> | 
| 20 | <div class="col-8 p-0 my-auto h6 text-right"> | 20 | <div class="col-8 p-0 my-auto h6 text-right"> | 
| 21 | <p class="m-0 font-weight-normal"> | 21 | <p class="m-0 font-weight-normal"> | 
| 22 | {{articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase()}} | 22 | {{articulo.MKT_DESC ? articulo.MKT_DESC.toUpperCase() : articulo.DetArt.toUpperCase()}} | 
| 23 | </p> | 23 | </p> | 
| 24 | </div> | 24 | </div> | 
| 25 | <div class="col-4"> | 25 | <div class="col-4"> | 
| 26 | <div class="row mx-0 justify-content-between border border-white badge-pill"> | 26 | <div class="row mx-0 justify-content-between border border-white badge-pill"> | 
| 27 | <!-- BOTON MENOS --> | 27 | <!-- BOTON MENOS --> | 
| 28 | <div class="col-auto px-0 my-auto"> | 28 | <div class="col-auto px-0 my-auto"> | 
| 29 | <img | 29 | <img | 
| 30 | draggable="false" | 30 | draggable="false" | 
| 31 | ondragstart="return false;" | 31 | ondragstart="return false;" | 
| 32 | (contextmenu)="false" | 32 | (contextmenu)="false" | 
| 33 | class="d-block ml-auto py-2 icon-30 btn-effect" | 33 | class="d-block ml-auto py-2 icon-30 btn-effect" | 
| 34 | src="assets/img/menos-blanco.svg" | 34 | src="assets/img/menos-blanco.svg" | 
| 35 | (click)="restarCantidadSinonimo(articulo, currentIndex)"> | 35 | (click)="restarCantidadSinonimo(articulo, currentIndex)"> | 
| 36 | </div> | 36 | </div> | 
| 37 | <!-- CANTIDAD --> | 37 | <!-- CANTIDAD --> | 
| 38 | <div class="col px-0 my-auto text-white text-center"> | 38 | <div class="col px-0 my-auto text-white text-center"> | 
| 39 | <p>{{articulo.cantidad}}</p> | 39 | <p>{{articulo.cantidad}}</p> | 
| 40 | </div> | 40 | </div> | 
| 41 | <!-- BOTON MAS --> | 41 | <!-- BOTON MAS --> | 
| 42 | <div class="col-auto px-0 my-auto"> | 42 | <div class="col-auto px-0 my-auto"> | 
| 43 | <img | 43 | <img | 
| 44 | draggable="false" | 44 | draggable="false" | 
| 45 | ondragstart="return false;" | 45 | ondragstart="return false;" | 
| 46 | (contextmenu)="false" | 46 | (contextmenu)="false" | 
| 47 | class="d-block ml-auto py-2 icon-30 btn-effect" | 47 | class="d-block ml-auto py-2 icon-30 btn-effect" | 
| 48 | src="assets/img/mas-blanco.svg" | 48 | src="assets/img/mas-blanco.svg" | 
| 49 | (click)="sumarCantidadSinonimo(articulo, currentIndex)"> | 49 | (click)="sumarCantidadSinonimo(articulo, currentIndex)"> | 
| 50 | </div> | 50 | </div> | 
| 51 | </div> | 51 | </div> | 
| 52 | </div> | 52 | </div> | 
| 53 | </div> | 53 | </div> | 
| 54 | </div> | 54 | </div> | 
| 55 | 55 | ||
| 56 | </div> | 56 | </div> | 
| 57 | 57 | ||
| 58 | <div class="modal-footer"> | 58 | <div class="modal-footer"> | 
| 59 | <div | 59 | <div | 
| 60 | *ngIf="currentIndex != 0 && sinonimos.length > 1" | 60 | *ngIf="currentIndex != 0 && sinonimos.length > 1" | 
| 61 | class="d-inline-block py-1 bg-white badge-pill text-primary btn-effect mr-auto fade-in-right" | 61 | class="d-inline-block py-1 bg-white badge-pill text-primary btn-effect mr-auto fade-in-right" | 
| 62 | (click)="currentIndex = currentIndex-1"> | 62 | (click)="currentIndex = currentIndex-1"> | 
| 63 | <img | 63 | <img | 
| 64 | draggable="false" | 64 | draggable="false" | 
| 65 | ondragstart="return false;" | 65 | ondragstart="return false;" | 
| 66 | (contextmenu)="false" | 66 | (contextmenu)="false" | 
| 67 | class="icon-30 flip" | 67 | class="icon-30 flip" | 
| 68 | src="assets/img/ir-color.svg"> | 68 | src="assets/img/ir-color.svg"> | 
| 69 | VOLVER | 69 | VOLVER | 
| 70 | </div> | 70 | </div> | 
| 71 | <div | 71 | <div | 
| 72 | [ngClass]="validateNext()" | ||
| 72 | *ngIf="currentIndex != sinonimos.length-1" | 73 | *ngIf="currentIndex != sinonimos.length-1" | 
| 73 | class="d-inline-block py-1 bg-white badge-pill text-primary btn-effect ml-auto fade-in-left" | 74 | class="d-inline-block py-1 bg-white badge-pill text-primary ml-auto fade-in-left" | 
| 74 | (click)="currentIndex = currentIndex+1"> | 75 | (click)="goNext()"> | 
| 75 | SIGUIENTE | 76 | SIGUIENTE | 
| 76 | <img | 77 | <img | 
| 77 | draggable="false" | 78 | draggable="false" | 
| 78 | ondragstart="return false;" | 79 | ondragstart="return false;" | 
| 79 | (contextmenu)="false" | 80 | (contextmenu)="false" | 
| 80 | class="icon-30" | 81 | class="icon-30" | 
| 81 | src="assets/img/ir-color.svg"> | 82 | src="assets/img/ir-color.svg"> | 
| 82 | </div> | 83 | </div> | 
| 83 | <div | 84 | <div | 
| 84 | [ngClass]="validate()" | 85 | [ngClass]="validate()" | 
| 85 | *ngIf="currentIndex == sinonimos.length-1" | 86 | *ngIf="currentIndex == sinonimos.length-1" | 
| 86 | class="d-inline-block py-1 bg-white badge-pill text-primary ml-auto fade-in-left" | 87 | class="d-inline-block py-1 bg-white badge-pill text-primary ml-auto fade-in-left" | 
| 87 | (click)="continue()"> | 88 | (click)="continue()"> | 
| 88 | CONTINUAR | 89 | CONTINUAR | 
| 89 | <img | 90 | <img | 
| 90 | draggable="false" | 91 | draggable="false" | 
| 91 | ondragstart="return false;" | 92 | ondragstart="return false;" | 
| 92 | (contextmenu)="false" | 93 | (contextmenu)="false" | 
| 93 | class="icon-30" | 94 | class="icon-30" | 
| 94 | src="assets/img/ir-color.svg"> | 95 | src="assets/img/ir-color.svg"> | 
| 95 | </div> | 96 | </div> | 
| 96 | </div> | 97 | </div> | 
| 97 | </div> | 98 | </div> | 
| 98 | 99 | 
src/app/shared/sinonimo/sinonimo.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; | 
| 2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 2 | import { ISinonimo } from 'src/app/interfaces/ISinonimo'; | 
| 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 3 | import { IArticulo } from 'src/app/interfaces/IArticulo'; | 
| 4 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 4 | import { BsModalRef } from 'ngx-bootstrap/modal'; | 
| 5 | import { Subject, forkJoin } from 'rxjs'; | 5 | import { Subject, forkJoin } from 'rxjs'; | 
| 6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 6 | import { ArticuloService } from 'src/app/services/articulo/articulo.service'; | 
| 7 | import { element } from 'protractor'; | 7 | import { element } from 'protractor'; | 
| 8 | 8 | ||
| 9 | @Component({ | 9 | @Component({ | 
| 10 | selector: 'app-sinonimo', | 10 | selector: 'app-sinonimo', | 
| 11 | templateUrl: './sinonimo.component.html', | 11 | templateUrl: './sinonimo.component.html', | 
| 12 | styleUrls: ['./sinonimo.component.scss'] | 12 | styleUrls: ['./sinonimo.component.scss'] | 
| 13 | }) | 13 | }) | 
| 14 | export class SinonimoComponent implements OnInit { | 14 | export class SinonimoComponent implements OnInit { | 
| 15 | sinonimos: ISinonimo[] = []; | 15 | sinonimos: ISinonimo[] = []; | 
| 16 | isValid: boolean; | 16 | isValid: boolean; | 
| 17 | onClose: Subject<any>; | 17 | onClose: Subject<any>; | 
| 18 | articulo: IArticulo; | 18 | articulo: IArticulo; | 
| 19 | isSinonimoSelected = false; | 19 | isSinonimoSelected = false; | 
| 20 | currentIndex = 0; | 20 | currentIndex = 0; | 
| 21 | 21 | ||
| 22 | constructor( | 22 | constructor( | 
| 23 | private modalRef: BsModalRef, | 23 | private modalRef: BsModalRef, | 
| 24 | private articuloService: ArticuloService, | 24 | private articuloService: ArticuloService, | 
| 25 | ) { | 25 | ) { | 
| 26 | this.onClose = new Subject(); | 26 | this.onClose = new Subject(); | 
| 27 | } | 27 | } | 
| 28 | 28 | ||
| 29 | ngOnInit() { | 29 | ngOnInit() { | 
| 30 | for (const s of this.sinonimos) { | 30 | for (const s of this.sinonimos) { | 
| 31 | for (const a of s.productos) { | 31 | for (const a of s.productos) { | 
| 32 | a.cantidad = 0; | 32 | a.cantidad = 0; | 
| 33 | } | 33 | } | 
| 34 | } | 34 | } | 
| 35 | } | 35 | } | 
| 36 | 36 | ||
| 37 | validate() { | 37 | validate() { | 
| 38 | this.isValid = true; | 38 | this.isValid = true; | 
| 39 | for (const s of this.sinonimos) { | 39 | for (const s of this.sinonimos) { | 
| 40 | if (s.cantidadRestante > 0) { | 40 | if (s.cantidadRestante > 0) { | 
| 41 | this.isValid = false; | 41 | this.isValid = false; | 
| 42 | break; | 42 | break; | 
| 43 | } | 43 | } | 
| 44 | } | 44 | } | 
| 45 | return !this.isValid ? 'disabled' : 'btn-effect'; | 45 | return !this.isValid ? 'disabled' : 'btn-effect'; | 
| 46 | } | 46 | } | 
| 47 | 47 | ||
| 48 | validateNext() { | ||
| 49 | const sinonimo = this.sinonimos[this.currentIndex] | ||
| 50 | sinonimo.selected = (sinonimo.cantidadRestante > 0) ? false : true; | ||
| 51 | return !sinonimo.selected ? 'disabled' : 'btn-effect'; | ||
| 52 | } | ||
| 53 | |||
| 54 | goNext() { | ||
| 55 | if (!this.sinonimos[this.currentIndex].selected) return; | ||
| 56 | this.currentIndex++; | ||
| 57 | } | ||
| 58 | |||
| 48 | continue() { | 59 | continue() { | 
| 49 | if (!this.isValid) return; | 60 | if (!this.isValid) return; | 
| 50 | if (this.isSinonimoSelected) return; | 61 | if (this.isSinonimoSelected) return; | 
| 51 | this.isSinonimoSelected = true; | 62 | this.isSinonimoSelected = true; | 
| 52 | const observables = []; | 63 | const observables = []; | 
| 53 | const cantidades = []; | 64 | const cantidades = []; | 
| 54 | 65 | ||
| 55 | for (const s of this.sinonimos) { | 66 | for (const s of this.sinonimos) { | 
| 56 | for (const articulo of s.productos) { | 67 | for (const articulo of s.productos) { | 
| 57 | if (articulo.cantidad === 0) continue; | 68 | if (articulo.cantidad === 0) continue; | 
| 58 | cantidades.push(articulo.cantidad); | 69 | cantidades.push(articulo.cantidad); | 
| 59 | observables.push(this.articuloService.getById(articulo.id)); | 70 | observables.push(this.articuloService.getById(articulo.id)); | 
| 60 | } | 71 | } | 
| 61 | } | 72 | } | 
| 62 | forkJoin(observables) | 73 | forkJoin(observables) | 
| 63 | .subscribe((res: IArticulo[]) => { | 74 | .subscribe((res: IArticulo[]) => { | 
| 64 | res.forEach((articulo, i) => { | 75 | res.forEach((articulo, i) => { | 
| 65 | articulo.cantidad = cantidades[i]; | 76 | articulo.cantidad = cantidades[i]; | 
| 66 | }); | 77 | }); | 
| 67 | this.modalRef.hide(); | 78 | this.modalRef.hide(); | 
| 68 | this.onClose.next({ | 79 | this.onClose.next({ | 
| 69 | articulos: res, | 80 | articulos: res, | 
| 70 | }); | 81 | }); | 
| 71 | }, err => console.error(err)); | 82 | }, err => console.error(err)); | 
| 72 | } | 83 | } | 
| 73 | 84 | ||
| 74 | sumarCantidadSinonimo(articulo: IArticulo, i: number) { | 85 | sumarCantidadSinonimo(articulo: IArticulo, i: number) { | 
| 75 | if (this.sinonimos[i].cantidadRestante === 0) return; | 86 | if (this.sinonimos[i].cantidadRestante === 0) return; | 
| 76 | articulo.cantidad++; | 87 | articulo.cantidad++; | 
| 77 | this.sinonimos[i].cantidadRestante--; | 88 | this.sinonimos[i].cantidadRestante--; | 
| 78 | } | 89 | } | 
| 79 | 90 | ||
| 80 | restarCantidadSinonimo(articulo: IArticulo, i: number) { | 91 | restarCantidadSinonimo(articulo: IArticulo, i: number) { | 
| 81 | if (this.sinonimos[i].cantidadRestante === this.sinonimos[i].cantidad) return; | 92 | if (this.sinonimos[i].cantidadRestante === this.sinonimos[i].cantidad) return; | 
| 82 | if (articulo.cantidad === 0) return; | 93 | if (articulo.cantidad === 0) return; | 
| 83 | articulo.cantidad--; | 94 | articulo.cantidad--; | 
| 84 | this.sinonimos[i].cantidadRestante++; | 95 | this.sinonimos[i].cantidadRestante++; | 
| 85 | } | 96 | } | 
| 86 | 97 | ||
| 87 | scrollTo(index: number) { | 98 | scrollTo(index: number) { | 
| 88 | const el = document.getElementById(index.toString()); | 99 | const el = document.getElementById(index.toString()); | 
| 89 | el.scrollIntoView({ behavior: 'smooth' }); | 100 | el.scrollIntoView({ behavior: 'smooth' }); | 
| 90 | } | 101 | } | 
| 91 | 102 | ||
| 92 | close() { | 103 | close() { | 
| 93 | this.modalRef.hide(); | 104 | this.modalRef.hide(); | 
| 94 | this.onClose.next(); | 105 | this.onClose.next(); | 
| 95 | } | 106 | } | 
| 96 | 107 | ||
| 97 | } | 108 | } | 
| 98 | 109 |