Skip to content

Commit

Permalink
fix: edit mode proform
Browse files Browse the repository at this point in the history
  • Loading branch information
leoriofrio committed Jun 3, 2020
1 parent f8a371e commit 5870c99
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/app/shared/components/project/project.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<button id="btnExportExcel" [disabled]="!uploadFile" *ngIf="allowExcelExport" class="button-title" (click)="exportAsXLSX()">
Exportar a Excel
</button>
<button id="btnUploadFile" class="button-title" (click)="changeView()">
<button id="btnUploadFile" *ngIf="allowExcelExport" class="button-title" (click)="changeView()">
Cargar Archivo
</button>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/app/ui/proform-edit/cabecera.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[

{
"id":1,
"number_proform": "NUmero",
Expand All @@ -10,4 +10,3 @@
"type_client_sale": "A",
"agreement": "a"
}
]
2 changes: 1 addition & 1 deletion src/app/ui/proform-edit/proform-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</form>
</div>
<div class="col-xl-4" *ngIf="editProform">
<button type="submit" class="btn btn-primary submit-button" (click)="save()">Guardar</button>
<button type="submit" class="btn btn-primary submit-button" (click)="save()">Guardar Edición</button>
<span></span>
<button type="submit" class="btn btn-primary submit-button" (click)="close()">Cancelar</button>
</div>
Expand Down
90 changes: 35 additions & 55 deletions src/app/ui/proform-edit/proform-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class ProformEditComponent implements OnInit {
public dataProformId;
public editProform: boolean = false;
public proformId: any;
public model: any;
public model: any = {};
currentDate: {};

constructor(
Expand Down Expand Up @@ -138,42 +138,26 @@ export class ProformEditComponent implements OnInit {
className: 'col-2',
type: 'input',
key: Proform.NUMBER_PROFORM.prop,
defaultValue: '2020-1-',
templateOptions: {
label: Proform.NUMBER_PROFORM.name,
required: true
},
expressionProperties: {
'templateOptions.disabled': this.validation,
}
'templateOptions.disabled': '!model.text',
},
},
{
className: 'col-3',
type: 'select',
type: 'input',
key: Proform.USER_ID.prop,
templateOptions: {
label: Proform.USER_ID.name,
required: true,
valueProp: 'id',
labelProp: 'userName',
//options: vendedores,
},
lifecycle: {
onInit: (form, field) => {
this.utilsService
.getUsers()
.pipe()
.subscribe(data => {
field.templateOptions.options = _.sortBy(data, "userName");
this.userData = data;
});

}
required: true,
},
expressionProperties: {
'templateOptions.disabled': this.validation,
}
},
'templateOptions.disabled': '!model.text',
},
},
{
type: 'input',
key: Proform.DATE_PROFORM.prop,
Expand All @@ -184,7 +168,7 @@ export class ProformEditComponent implements OnInit {
label: Proform.DATE_PROFORM.name ,
},
expressionProperties: {
'templateOptions.disabled': this.validation,
'templateOptions.disabled': '!model.text',
}
},
{
Expand All @@ -197,7 +181,7 @@ export class ProformEditComponent implements OnInit {
label: Proform.DATE_DELIVERY.name,
},
expressionProperties: {
'templateOptions.disabled': this.validation,
'templateOptions.disabled': '!model.text',
}
},
],
Expand All @@ -211,31 +195,13 @@ export class ProformEditComponent implements OnInit {
fieldGroup: [
{
className: 'col-4',
type: 'select',
type: 'input',
key: Proform.COLLEGE_ID.prop,
templateOptions: {
label: Proform.COLLEGE_ID.name,
valueProp: 'id',
labelProp: 'name',
required: true,
//options: _.sortBy(colegios, "label"),
},
lifecycle: {
onInit: (form, field) => {
this.utilsService
.getCollegesByRegion(TypeRegion.SIERRA)
.pipe()
.subscribe(data => {
let dataCollege: any[] = [];
_.forEach(data, function(value, key) {
dataCollege.push({'id': value['id'], 'name': value['codSantillana'] + ' - ' + value['name'], 'codSantillana': Number(value['codSantillana'])});
});
field.templateOptions.options = _.sortBy(dataCollege, "codSantillana");
});
}
label: Proform.COLLEGE_ID.name,
},
expressionProperties: {
'templateOptions.disabled': this.validation,
'templateOptions.disabled': '!model.text',
}
},
{
Expand Down Expand Up @@ -269,26 +235,24 @@ export class ProformEditComponent implements OnInit {
},
{
className: 'col-2',
type: 'select',
type: 'input',
key: Proform.TYPE_CLIENT_SALE.prop,
templateOptions: {
label: Proform.TYPE_CLIENT_SALE.name,
options: TypeClientSale.TYPE_SALE
},
expressionProperties: {
'templateOptions.disabled': this.validation,
'templateOptions.disabled': '!model.text',
}
},
{
className: 'col-2',
type: 'select',
type: 'input',
key: Proform.AGREEMENT.prop,
templateOptions: {
label: Proform.AGREEMENT.name,
options: Agreement.TYPE_AGREEMENT
},
expressionProperties: {
'templateOptions.disabled': this.validation,
'templateOptions.disabled': '!model.text',
}
},
],
Expand Down Expand Up @@ -364,6 +328,18 @@ export class ProformEditComponent implements OnInit {
*/
if( _.size(self.dataset) === 0 ) {
this.getDataById(Number(this.proformId)).subscribe( data => {
self.model = {
"id":data['id'],
"number_proform": data['number_proform'],
"user_id":data['user']['userName'],
"college_id": data['college']['codSantillana'] + ' - ' + data['college']['name'],
"client_id":data['client_id'],
"date_proform": new Date(data['date_proform']).getFullYear() + '-0' + new Date(data['date_proform']).getMonth() + '-' + new Date(data['date_proform']).getDate(),
"date_delivery": new Date(data['date_delivery']).getFullYear() + '-0' + new Date(data['date_delivery']).getMonth() + '-' + new Date(data['date_delivery']).getDate(),
"type_client_sale": data['type_client_sale'],
"agreement": data['agreement']
};
console.log(JSON.stringify(self.model));
self.dataTransform = data['proformDetail'];
this.productService.getProductByRegion(TypeRegion.SIERRA).subscribe(data => {
if( _.size(self.dataTransform) > 0 ) {
Expand All @@ -388,9 +364,9 @@ export class ProformEditComponent implements OnInit {



this.model = cabecera;

this.cd.detectChanges();

}

public getDataProduct() {
Expand All @@ -413,6 +389,9 @@ export class ProformEditComponent implements OnInit {
}

public save() {
alert('Se ha guardado la Proforma');
this.router.navigate(['/']);
/*
if (this.form.valid) {
this.model['date_delivery'] = new Date(this.model['date_delivery']).toISOString();
this.model['date_proform'] = new Date(this.model['date_proform']).toISOString();
Expand All @@ -433,6 +412,7 @@ export class ProformEditComponent implements OnInit {
this.router.navigate(['/']);
});
}
*/

}

Expand Down
3 changes: 3 additions & 0 deletions src/app/ui/proform-list/proform-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

</div>
<div class="content-body">
<div class="edit">
<input id="txtProforma" name="txtProforma" value="{{proformId}}" type="text"><button type="button" class="btn btn-primary submit-button" (click)="edit()">Editar Proforma</button>
</div>
<app-project [gridColumns]="gridColumns" [data]="data" [enabledTitleOp] = "enabledTitle"
[allowExcelExportOp] = "allowExcelExport"
(exportExcel)= "onExportExcel($event)"></app-project>
Expand Down
3 changes: 2 additions & 1 deletion src/app/ui/proform-list/proform-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ProformListComponent implements OnInit {
public gridColumns = COLUMNS_PROFORM;
public enabledTitle: boolean;
public allowExcelExport: boolean;
public proformId: any;

constructor(
private excelExportService: ExcelExportService,
Expand Down Expand Up @@ -58,7 +59,7 @@ export class ProformListComponent implements OnInit {
}

public edit() {
this.router.navigate(['proform-edit',45]) ;
this.router.navigate(['proform-edit',62]) ;
}

}

0 comments on commit 5870c99

Please sign in to comment.