-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates pedido-actions-bar component to reuse its functionality in pe…
…didos and ver-pedido components.
- Loading branch information
1 parent
c344cd3
commit cbe5009
Showing
8 changed files
with
235 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/app/components/pedido-actions-bar/pedido-actions-bar.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<ul class="list-inline mb-0 text-center d-inline-block"> | ||
<li class="list-inline-item" *ngIf="!hiddenButtonsValues['show']"> | ||
<a class="btn btn-primary fake-cursor" ngbPopover="Ver Detalle" triggers="mouseenter:mouseleave" placement="left" | ||
(click)="verPedido()"> | ||
<fa-icon [icon]="['far', 'eye']"></fa-icon> | ||
</a> | ||
</li> | ||
<li class="list-inline-item" *ngIf="!hiddenButtonsValues['download']"> | ||
<button class="btn btn-primary" (click)="downloadPedidoPdf(pedido)" placement="left" ngbPopover="Descargar Archivo" triggers="mouseenter:mouseleave"> | ||
<fa-icon [icon]="['fas', 'file-download']"></fa-icon> | ||
</button> | ||
</li> | ||
<li class="list-inline-item" *ngIf="puedeEditarPedido && !hiddenButtonsValues['edit']"> | ||
<a class="btn btn-primary fake-cursor" ngbPopover="Editar" triggers="mouseenter:mouseleave" placement="left" | ||
(click)="editarPedido()"> | ||
<fa-icon [icon]="['fas', 'pen']"></fa-icon> | ||
</a> | ||
</li> | ||
<li class="list-inline-item" *ngIf="!hiddenButtonsValues['clone']"> | ||
<a class="btn btn-primary fake-cursor" ngbPopover="Clonar" triggers="mouseenter:mouseleave" placement="left" | ||
(click)="clonarPedido()"> | ||
<fa-icon [icon]="['fas', 'copy']"></fa-icon> | ||
</a> | ||
</li> | ||
<li class="list-inline-item" *ngIf="puedeEliminarPedido && !hiddenButtonsValues['delete']"> | ||
<a class="btn btn-primary fake-cursor" ngbPopover="Cancelar" triggers="mouseenter:mouseleave" placement="left" | ||
(click)="cancelarPedido()"> | ||
<fa-icon [icon]="['fas', 'times']"></fa-icon> | ||
</a> | ||
</li> | ||
<li class="list-inline-item" *ngIf="puedeFacturarPedido && !hiddenButtonsValues['invoice']"> | ||
<a class="btn btn-primary fake-cursor" ngbPopover="Facturar" triggers="mouseenter:mouseleave" placement="left" | ||
(click)="facturarPedido()"> | ||
<fa-icon [icon]="['fas', 'cash-register']"></fa-icon> | ||
</a> | ||
</li> | ||
<li class="list-inline-item" *ngIf="puedeVerFacturas && !hiddenButtonsValues['show-invoice']"> | ||
<a class="btn btn-primary fake-cursor" ngbPopover="Ver Facturas" triggers="mouseenter:mouseleave" placement="left" | ||
(click)="verFacturas()"> | ||
<fa-icon [icon]="['fas', 'link']"></fa-icon> | ||
</a> | ||
</li> | ||
</ul> |
140 changes: 140 additions & 0 deletions
140
src/app/components/pedido-actions-bar/pedido-actions-bar.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { AuthService } from './../../services/auth.service'; | ||
import { finalize } from 'rxjs/operators'; | ||
import { PedidosService } from './../../services/pedidos.service'; | ||
import { LoadingOverlayService } from './../../services/loading-overlay.service'; | ||
import { StorageKeys, StorageService } from './../../services/storage.service'; | ||
import { MensajeModalType } from './../mensaje-modal/mensaje-modal.component'; | ||
import { MensajeService } from './../../services/mensaje.service'; | ||
import { Router } from '@angular/router'; | ||
import { Rol } from './../../models/rol'; | ||
import { EstadoPedido } from './../../models/estado-pedido'; | ||
import { Pedido } from './../../models/pedido'; | ||
import { Component, OnInit, Input } from '@angular/core'; | ||
|
||
type PedidoActionButtonName = 'show'|'download'|'edit'|'clone'|'delete'|'invoice'|'show-invoice'; | ||
|
||
@Component({ | ||
selector: 'app-pedido-actions-bar', | ||
templateUrl: './pedido-actions-bar.component.html' | ||
}) | ||
export class PedidoActionsBarComponent implements OnInit { | ||
private pPedido: Pedido; | ||
@Input() set pedido(value: Pedido) { this.pPedido = value; } | ||
get pedido(): Pedido { return this.pPedido; } | ||
|
||
private pHiddenButtons: PedidoActionButtonName[] = []; | ||
@Input() set hiddenButtons(value: PedidoActionButtonName[]) { this.pHiddenButtons = value; } | ||
get hiddenButtons(): PedidoActionButtonName[] { return this.pHiddenButtons; } | ||
|
||
hiddenButtonsValues = { | ||
'show': false, | ||
'download': false, | ||
'edit': false, | ||
'clone': false, | ||
'delete': false, | ||
'invoice': false, | ||
'show-invoice': false, | ||
} | ||
|
||
allowedRolesToDelete: Rol[] = [ Rol.ADMINISTRADOR, Rol.ENCARGADO, Rol.VENDEDOR ]; | ||
hasRolToDelete = false; | ||
|
||
allowedRolesToEdit: Rol[] = [ Rol.ADMINISTRADOR, Rol.ENCARGADO, Rol.VENDEDOR ]; | ||
hasRolToEdit = false; | ||
|
||
puedeEliminarPedido = false; | ||
puedeEditarPedido = false; | ||
puedeFacturarPedido = false; | ||
puedeVerFacturas = false; | ||
|
||
constructor(private router: Router, | ||
private authService: AuthService, | ||
private mensajeService: MensajeService, | ||
private loadingOverlayService: LoadingOverlayService, | ||
private pedidosService: PedidosService, | ||
private storageService: StorageService) { | ||
this.hasRolToDelete = this.authService.userHasAnyOfTheseRoles(this.allowedRolesToDelete); | ||
this.hasRolToEdit = this.authService.userHasAnyOfTheseRoles(this.allowedRolesToEdit); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.puedeEliminarPedido = this.hasRolToDelete && this.pedido.estado === EstadoPedido.ABIERTO; | ||
this.puedeEditarPedido = this.hasRolToEdit && this.pedido.estado === EstadoPedido.ABIERTO; | ||
this.puedeFacturarPedido = this.hasRolToEdit && this.pedido.estado === EstadoPedido.ABIERTO; | ||
this.puedeVerFacturas = [EstadoPedido.CERRADO].indexOf(this.pedido.estado) >= 0; | ||
|
||
Object.keys(this.hiddenButtonsValues).forEach((k: PedidoActionButtonName) => { | ||
this.hiddenButtonsValues[k] = this.hiddenButtons.indexOf(k) >= 0; | ||
}); | ||
} | ||
|
||
verPedido() { | ||
this.router.navigate(['/pedidos/ver', this.pedido.idPedido]); | ||
} | ||
|
||
cancelarPedido() { | ||
if (!this.puedeEliminarPedido) { | ||
this.mensajeService.msg('No posee permiso para cancelar un pedido.', MensajeModalType.ERROR); | ||
return; | ||
} | ||
|
||
const msg = `¿Está seguro que desea cancelar el pedido #${this.pedido.nroPedido}?`; | ||
|
||
this.mensajeService.msg(msg, MensajeModalType.CONFIRM).then((result) => { | ||
if (result) { | ||
this.loadingOverlayService.activate(); | ||
this.pedidosService.cancelarPedido(this.pedido.idPedido) | ||
.pipe(finalize(() => this.loadingOverlayService.deactivate())) | ||
.subscribe({ | ||
next: () => { location.reload(); }, | ||
error: err => this.mensajeService.msg(`Error: ${err.error}`, MensajeModalType.ERROR), | ||
}) | ||
; | ||
} | ||
}, () => { return; }); | ||
} | ||
|
||
editarPedido() { | ||
if (!this.puedeEditarPedido) { | ||
this.mensajeService.msg('No posee permiso para editar un pedido.', MensajeModalType.ERROR); | ||
return; | ||
} | ||
this.storageService.removeItem(StorageKeys.PEDIDO_EDITAR); | ||
this.router.navigate(['/pedidos/editar', this.pedido.idPedido]); | ||
} | ||
|
||
clonarPedido() { | ||
this.storageService.removeItem(StorageKeys.PEDIDO_NUEVO); | ||
this.router.navigate(['/pedidos/nuevo'], { queryParams: { idToClone: this.pedido.idPedido }}); | ||
} | ||
|
||
facturarPedido() { | ||
if (!this.puedeFacturarPedido) { | ||
this.mensajeService.msg('No posee permiso para facturar un pedido.', MensajeModalType.ERROR); | ||
return; | ||
} | ||
this.storageService.removeItem(StorageKeys.PEDIDO_FACTURAR); | ||
this.router.navigate(['/facturas-venta/de-pedido', this.pedido.idPedido]); | ||
} | ||
|
||
verFacturas() { | ||
if (this.puedeVerFacturas) { | ||
this.router.navigate(['/facturas-venta'], { queryParams: { nroPedido: this.pedido.nroPedido }}); | ||
} | ||
} | ||
|
||
downloadPedidoPdf() { | ||
this.loadingOverlayService.activate(); | ||
this.pedidosService.getPedidoPdf(this.pedido.idPedido) | ||
.pipe(finalize(() => this.loadingOverlayService.deactivate())) | ||
.subscribe({ | ||
next: (res) => { | ||
const file = new Blob([res], {type: 'application/pdf'}); | ||
const fileURL = URL.createObjectURL(file); | ||
window.open(fileURL, '_blank'); | ||
}, | ||
error: () => this.mensajeService.msg('Error al generar el reporte', MensajeModalType.ERROR), | ||
}) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.