Skip to content

Commit

Permalink
refact(RUP-308): Aplicar prototipo de edición a formulas (#2605)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarianoCampetella authored Mar 29, 2022
1 parent 9d368db commit 0e7f0f2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/app/modules/rup/components/core/rup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class RUPComponent implements OnInit, AfterViewInit, OnDestroy {
@Input() vistaHUDS = false;
@Input() params: any;
@Input() style: any;
@Input() habilitado: any;

public mensaje: any = {};

Expand Down Expand Up @@ -100,6 +101,7 @@ export class RUPComponent implements OnInit, AfterViewInit, OnDestroy {
componentReference.instance['paciente'] = this.paciente;
componentReference.instance['params'] = this.params;
componentReference.instance['style'] = this.style;
componentReference.instance['habilitado'] = this.habilitado;

// Event bubbling
componentReference.instance['change'].subscribe(value => {
Expand Down Expand Up @@ -283,7 +285,7 @@ export class RUPComponent implements OnInit, AfterViewInit, OnDestroy {

get isValid() {
if (this.rupInstance) {
return (!this.rupInstance.formulario || !this.rupInstance.formulario.touched || (!this.rupInstance.formulario.invalid) ) && this.rupInstance.onValidate();
return (!this.rupInstance.formulario || !this.rupInstance.formulario.touched || (!this.rupInstance.formulario.invalid)) && this.rupInstance.onValidate();
}
return true;
}
Expand Down Expand Up @@ -316,7 +318,7 @@ export class RUPComponent implements OnInit, AfterViewInit, OnDestroy {
for (let i = 0; i < this.registro.registros.length; i++) {
const concepto = this.registro.registros[i].concepto;
const requerido = requeridos[i];
const elementoRUP = this.registro.registros[i].elementoRUP ? this.elementosRUPService.getById(this.registro.registros[i].elementoRUP): null;
const elementoRUP = this.registro.registros[i].elementoRUP ? this.elementosRUPService.getById(this.registro.registros[i].elementoRUP) : null;
if (requerido && requerido.concepto.conceptId === concepto.conceptId) {
requerido.elementoRUP = elementoRUP || requerido.elementoRUP;
response.push(requerido);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class FormulaBaseComponent extends RUPComponent implements OnInit {
public formulaProvider: FormulaBaseService;
public resultado;
public hasRules = false;
public habilitado = false;
public valorManual: Boolean = false;

ngOnInit() {
Expand Down Expand Up @@ -62,7 +63,8 @@ export class FormulaBaseComponent extends RUPComponent implements OnInit {
this.addFact('value', this.registro.valor);
}

changeValorManual() {
changeValorManual(valor) {
this.valorManual = valor;
if (this.valorManual) {
this.registro.valorManual = true;
this.registro.registros.map(reg => reg.valor = null);
Expand Down
102 changes: 63 additions & 39 deletions src/app/modules/rup/components/elementos/FormulaBase.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,69 @@
<!-- Moléculas -->
<ng-container *ngIf="elementoRUP.requeridos?.length">
<div class="row" [ngClass]="{'d-flex justify-content-start': soloValores}">
<div *ngIf="params?.valorEditable && !soloValores" class="col-12">
<!-- En caso de que la molécula permita edición manual del valor del registro -->
<plex-bool type="slide" label="Introducir el valor manualmente" [(ngModel)]="valorManual" name="boolValorManual" (change)="changeValorManual()"></plex-bool>
</div>
<ng-container *ngIf="!valorManual">
<ng-container *ngFor="let item of elementoRUP.requeridos; let i = index">
<div *ngIf="item.elementoRUP"
class="col-{{ item.style.columns }} mr-{{ item.style?.offset ? item.style.offset : '0' }}">
<rup [ngClass]="{'readonly': valorManual}" [elementoRUP]="item.elementoRUP" [paciente]="paciente" [params]="item.params"
[prestacion]="prestacion" [registro]="registro.registros[i]" [soloValores]="soloValores"
(change)="emitChange2()" (ejecutarAccion)="emitEjecutarAccion($event)">
</rup>
</div>
<plex-wrapper class="w-100">
<plex-grid cols="2">
<ng-container *ngIf="!valorManual">
<ng-container *ngFor="let item of elementoRUP.requeridos; let i = index">
<div *ngIf="item.elementoRUP" class="pr-3">
<rup [ngClass]="{'readonly': valorManual}" [elementoRUP]="item.elementoRUP"
[paciente]="paciente" [params]="item.params" [prestacion]="prestacion"
[registro]="registro.registros[i]" [soloValores]="soloValores" (change)="emitChange2()"
(ejecutarAccion)="emitEjecutarAccion($event)" [habilitado]="valorManual">
</rup>
</div>
</ng-container>
</ng-container>
<ng-container *ngIf="valorManual">
<ng-container *ngFor="let item of elementoRUP.requeridos; let i = index">
<div *ngIf="item.elementoRUP" class="pr-3">
<rup [ngClass]="{'readonly': !valorManual}" [elementoRUP]="item.elementoRUP"
[paciente]="paciente" [params]="item.params" [prestacion]="prestacion"
[registro]="registro.registros[i]" [soloValores]="soloValores" (change)="emitChange2()"
(ejecutarAccion)="emitEjecutarAccion($event)" [habilitado]="valorManual">
</rup>
</div>
</ng-container>
</ng-container>
</ng-container>

<div class="col-{{ elementoRUP.style.columns }}">
<label class="form-control-label text-capitalize-first"> {{ registro.concepto.term}} </label>

<!-- Campo para ingreso manual del valor del registro -->
<plex-float *ngIf="valorManual && !soloValores" placeholder="Ingrese un valor" [(ngModel)]="registro.valor"
label='' name="valorCalculo" [readonly]="soloValores" (change)="emitChange2()">
</plex-float>

<!-- Valor/resultado del cálculo -->
<ng-container *ngIf="!valorManual || soloValores">
<p>
<ng-container *ngIf="!hasRules">
{{ registro.valor }}
</ng-container>
<plex-badge [type]="mensaje.type" *ngIf="mensaje?.texto">
{{ mensaje.texto }}
<plex-button *ngIf="mensaje.add && !soloValores" (click)="addConcepto(mensaje.add)"
title="Registrar">
<plex-icon name="plus"></plex-icon>
<div>
<div class="d-flex align-items-center w-100">
<div class="w-100">
<label> {{ registro.concepto.term}} </label>
<!-- Valor/resultado del cálculo -->
<ng-container *ngIf="soloValores">
<p>
<ng-container *ngIf="!hasRules">
{{registro.valor}}
</ng-container>
<plex-badge [type]="mensaje.type" *ngIf="mensaje?.texto">
{{ mensaje.texto }}
<plex-button *ngIf="mensaje.add && !soloValores" (click)="addConcepto(mensaje.add)"
title="Registrar">
<plex-icon name="plus"></plex-icon>
</plex-button>
</plex-badge>
</p>
</ng-container>
<!-- Campo para ingreso manual del valor del registro -->
<plex-float *ngIf="!soloValores && valorManual" placeholder="Ingrese un valor"
[(ngModel)]="registro.valor" label='' name="valorCalculo" [readonly]="soloValores"
(change)="emitChange2()" [disabled]="!valorManual">
</plex-float>
<plex-float *ngIf="!soloValores && !valorManual" [(ngModel)]="registro.valor" required="true"
[disabled]="true">
</plex-float>
</div>
<div class="d-flex align-items-start mt-2">
<plex-button *ngIf="!valorManual && !soloValores" type="warning" icon="pencil"
(click)="changeValorManual(true)" tooltip="Agregar manualmente"
tooltipPosition="left">
</plex-button>
</plex-badge>
</p>
</ng-container>
</div>
</div>
<plex-button *ngIf="valorManual && !soloValores" class="mr-1" type="danger" icon="close"
(click)="changeValorManual(false)">
</plex-button>
</div>
</div>
</div>
</plex-grid>
</plex-wrapper>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class ValorFechaComponent extends RUPComponent implements OnInit {
get DateFormat() {
switch (this.params.type) {
case 'date':
return moment(this.registro.valor).format('DD/MM/YYYY');
return (this.registro.valor) ? moment(this.registro.valor).format('DD/MM/YYYY') : 'Sin fecha';
case 'datetime':
return moment(this.registro.valor).format('DD/MM/YYYY hh:mm');
return (this.registro.valor) ? moment(this.registro.valor).format('DD/MM/YYYY hh:mm') : 'Sin fecha';
case 'time':
return moment(this.registro.valor).format('hh:mm');
return (this.registro.valor) ? moment(this.registro.valor).format('hh:mm') : 'Sin hora';
default:
break;
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/modules/rup/components/elementos/valorFecha.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<div class="row flex-column">
<div class="col-12">
<ng-container *ngIf="!soloValores; else showSoloValores">
<plex-datetime [(ngModel)]="registro.valor" [label]="params?.title || registro.concepto.term" name="DateValue" [type]="params?.type || 'date'" [required]="params?.required || false" (change)="onChange()">
<plex-datetime [(ngModel)]="registro.valor" [label]="params?.title || registro.concepto.term"
name="DateValue" [type]="params?.type || 'date'"
[required]="params?.required || !habilitado" (change)="onChange()"
[readonly]="habilitado">
</plex-datetime>
</ng-container>
<ng-template #showSoloValores>
Expand Down

0 comments on commit 0e7f0f2

Please sign in to comment.