Commit c6a2b69ce66f4e97189dbf5b4b6b6da9153b9a8b
Exists in
develop
Merge branch 'develop' of git.focasoftware.com:angular/autoservicio-axion
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 | <p class="h4">Elige una opción</p> | 3 | <p class="h4 col-6 px-0 align-self-center">Eliga opciones {{sinonimos.length}}</p> | 
| 4 | <div class="col-6 text-right"> | ||
| 5 | <p *ngFor="let s of sinonimos; let i = index"> | ||
| 6 | <span | ||
| 7 | class="pr-2 btn-effect" | ||
| 8 | (click)="scrollTo(i)"> | ||
| 9 | Ir a opción {{i+1}}</span> | ||
| 10 | <i class="far fa-hand-point-left"></i> | ||
| 11 | </p> | ||
| 12 | </div> | ||
| 4 | </div> | 13 | </div> | 
| 5 | 14 | ||
| 6 | <div class="modal-body lista-sinonimos scroll-y-visible my-2 mr-2"> | 15 | <div class="modal-body lista-sinonimos scroll-y-visible my-2 mr-2"> | 
| 7 | <div *ngFor="let s of sinonimos; let i = index"> | 16 | <div *ngFor="let s of sinonimos; let i = index"> | 
| 17 | <div [id]="i"></div> | ||
| 8 | <hr [hidden]="i === 0" class="bg-white"> | 18 | <hr [hidden]="i === 0" class="bg-white"> | 
| 9 | <div *ngFor="let articulo of s.productos"> | 19 | <div *ngFor="let articulo of s.productos"> | 
| 10 | <div class="custom-control custom-checkbox"> | 20 | <div class="custom-control custom-checkbox"> | 
| 11 | <input | 21 | <input | 
| 12 | type="checkbox" | 22 | type="checkbox" | 
| 13 | class="custom-control-input" | 23 | class="custom-control-input" | 
| 14 | [(ngModel)]="articulo.seleccionado" | 24 | [(ngModel)]="articulo.seleccionado" | 
| 15 | (click)="selectSinonimo(i, articulo)" | 25 | (click)="selectSinonimo(i, articulo)" | 
| 16 | [id]="articulo.id"> | 26 | [id]="articulo.id"> | 
| 17 | <label | 27 | <label | 
| 18 | class="custom-control-label" | 28 | class="custom-control-label" | 
| 19 | [for]="articulo.id"> | 29 | [for]="articulo.id"> | 
| 20 | {{articulo.DET_LAR.toUpperCase()}} | 30 | {{articulo.DET_LAR.toUpperCase()}} | 
| 21 | </label> | 31 | </label> | 
| 22 | </div> | 32 | </div> | 
| 23 | </div> | 33 | </div> | 
| 24 | </div> | 34 | </div> | 
| 25 | </div> | 35 | </div> | 
| 26 | 36 | ||
| 27 | <div class="modal-footer"> | 37 | <div class="modal-footer"> | 
| 28 | <div | 38 | <div | 
| 29 | [ngClass]="validate()" | 39 | [ngClass]="validate()" | 
| 30 | class="d-inline-block py-1 bg-white badge-pill text-primary" | 40 | class="d-inline-block py-1 bg-white badge-pill text-primary" | 
| 31 | (click)="continue()"> | 41 | (click)="continue()"> | 
| 32 | CONTINUAR | 42 | CONTINUAR | 
| 33 | <img | 43 | <img | 
| 34 | draggable="false" | 44 | draggable="false" | 
| 35 | ondragstart="return false;" | 45 | ondragstart="return false;" | 
| 36 | (contextmenu)="false" | 46 | (contextmenu)="false" | 
| 37 | class="icon-30" | 47 | class="icon-30" | 
| 38 | src="assets/img/ir-color.svg"> | 48 | src="assets/img/ir-color.svg"> | 
| 39 | </div> | 49 | </div> | 
| 40 | </div> | 50 | </div> | 
| 41 | </div> | 51 | </div> | 
| 42 | 52 | 
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 | 8 | ||
| 8 | @Component({ | 9 | @Component({ | 
| 9 | selector: 'app-sinonimo', | 10 | selector: 'app-sinonimo', | 
| 10 | templateUrl: './sinonimo.component.html', | 11 | templateUrl: './sinonimo.component.html', | 
| 11 | styleUrls: ['./sinonimo.component.scss'] | 12 | styleUrls: ['./sinonimo.component.scss'] | 
| 12 | }) | 13 | }) | 
| 13 | export class SinonimoComponent implements OnInit { | 14 | export class SinonimoComponent implements OnInit { | 
| 14 | sinonimos: ISinonimo[] = []; | 15 | sinonimos: ISinonimo[] = []; | 
| 15 | isValid: boolean; | 16 | isValid: boolean; | 
| 16 | onClose: Subject<any>; | 17 | onClose: Subject<any>; | 
| 17 | articulosSelected: IArticulo[] = []; | 18 | articulosSelected: IArticulo[] = []; | 
| 18 | 19 | ||
| 19 | constructor( | 20 | constructor( | 
| 20 | private modalRef: BsModalRef, | 21 | private modalRef: BsModalRef, | 
| 21 | private articuloService: ArticuloService, | 22 | private articuloService: ArticuloService, | 
| 22 | ) { | 23 | ) { | 
| 23 | this.onClose = new Subject(); | 24 | this.onClose = new Subject(); | 
| 24 | this.articulosSelected.length = this.sinonimos.length; | 25 | this.articulosSelected.length = this.sinonimos.length; | 
| 25 | } | 26 | } | 
| 26 | 27 | ||
| 27 | ngOnInit() { } | 28 | ngOnInit() { } | 
| 28 | 29 | ||
| 29 | selectSinonimo(index: number, articulo: IArticulo) { | 30 | selectSinonimo(index: number, articulo: IArticulo) { | 
| 30 | for (const a of this.sinonimos[index].productos) { | 31 | for (const a of this.sinonimos[index].productos) { | 
| 31 | a.seleccionado = false; | 32 | a.seleccionado = false; | 
| 32 | } | 33 | } | 
| 33 | articulo.seleccionado = true; | 34 | articulo.seleccionado = true; | 
| 34 | this.articulosSelected[index] = articulo; | 35 | this.articulosSelected[index] = articulo; | 
| 35 | } | 36 | } | 
| 36 | 37 | ||
| 37 | validate() { | 38 | validate() { | 
| 38 | this.isValid = true; | 39 | this.isValid = true; | 
| 39 | for (const s of this.sinonimos) { | 40 | for (const s of this.sinonimos) { | 
| 40 | for (const a of s.productos) { | 41 | for (const a of s.productos) { | 
| 41 | this.isValid = (!a.seleccionado) ? false : true; | 42 | this.isValid = (!a.seleccionado) ? false : true; | 
| 42 | if (this.isValid) break; | 43 | if (this.isValid) break; | 
| 43 | } | 44 | } | 
| 44 | if (!this.isValid) break; | 45 | if (!this.isValid) break; | 
| 45 | } | 46 | } | 
| 46 | return !this.isValid ? 'disabled' : 'btn-effect'; | 47 | return !this.isValid ? 'disabled' : 'btn-effect'; | 
| 47 | } | 48 | } | 
| 48 | 49 | ||
| 49 | continue() { | 50 | continue() { | 
| 50 | if (!this.isValid) return; | 51 | if (!this.isValid) return; | 
| 51 | const ID_SINS = []; | 52 | const ID_SINS = []; | 
| 52 | const observables = []; | 53 | const observables = []; | 
| 53 | 54 | ||
| 54 | for (const articulo of this.articulosSelected) { | 55 | for (const articulo of this.articulosSelected) { | 
| 55 | ID_SINS.push(articulo.ID_SIN); | 56 | ID_SINS.push(articulo.ID_SIN); | 
| 56 | } | 57 | } | 
| 57 | 58 | ||
| 58 | for (const articulo of this.articulosSelected) { | 59 | for (const articulo of this.articulosSelected) { | 
| 59 | observables.push(this.articuloService.getById(articulo.id)); | 60 | observables.push(this.articuloService.getById(articulo.id)); | 
| 60 | } | 61 | } | 
| 61 | 62 | ||
| 62 | forkJoin(observables) | 63 | forkJoin(observables) | 
| 63 | .subscribe((res: IArticulo[]) => { | 64 | .subscribe((res: IArticulo[]) => { | 
| 64 | for (const articulo of res) { | 65 | for (const articulo of res) { | 
| 65 | for (const ID_SIN of ID_SINS) { | 66 | for (const ID_SIN of ID_SINS) { | 
| 66 | articulo.ID_SIN = ID_SIN; | 67 | articulo.ID_SIN = ID_SIN; | 
| 67 | } | 68 | } | 
| 68 | } | 69 | } | 
| 69 | this.modalRef.hide(); | 70 | this.modalRef.hide(); | 
| 70 | this.onClose.next({ | 71 | this.onClose.next({ | 
| 71 | articulos: res, | 72 | articulos: res, | 
| 72 | }); | 73 | }); | 
| 73 | }, err => console.error(err)); | 74 | }, err => console.error(err)); | 
| 74 | } | 75 | } | 
| 75 | 76 | ||
| 77 | scrollTo(index: number) { | ||
| 78 | const element = document.getElementById(index.toString()); | ||
| 79 | element.scrollIntoView({ behavior: "smooth", block: "center" }); | ||
| 80 | } | ||
| 81 | |||
| 76 | } | 82 | } | 
| 77 | 83 |