diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 9da46ab..bb4748b 100755 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -17,7 +17,7 @@ const routes: Routes = [ @NgModule({ imports: [RouterModule.forRoot(routes)], - providers: [{provide: APP_BASE_HREF, useValue: '/' + (window.location.pathname.split('/')[1] || '')}], + providers: [], exports: [RouterModule] }) export class AppRoutingModule { } diff --git a/src/app/app.type.ts b/src/app/app.type.ts index 91960b2..fe69b17 100644 --- a/src/app/app.type.ts +++ b/src/app/app.type.ts @@ -26,6 +26,11 @@ export type GridRecord = { route?: string; } + export interface DataType { + label: any, + value: any; + } + export interface IProform { id: number; number_proform: string; @@ -75,4 +80,6 @@ export type GridRecord = { "sale_training": 0 }; + + \ No newline at end of file diff --git a/src/app/shared/service/utils.service.spec.ts b/src/app/shared/service/utils.service.spec.ts new file mode 100644 index 0000000..d70aee3 --- /dev/null +++ b/src/app/shared/service/utils.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { UtilsService } from './utils.service'; + +describe('UtilsService', () => { + let service: UtilsService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(UtilsService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/shared/service/utils.service.ts b/src/app/shared/service/utils.service.ts new file mode 100644 index 0000000..69ec918 --- /dev/null +++ b/src/app/shared/service/utils.service.ts @@ -0,0 +1,43 @@ +import { Injectable } from '@angular/core'; +import {HttpHeaders, HttpClient} from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { ApiKeys } from 'src/app/app.keys'; + +const httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json; charset=utf-8' + }) +}; + +@Injectable({ + providedIn: 'root' +}) +export class UtilsService { + private baseUrl: string; + + constructor( + private http: HttpClient + ) { + this.baseUrl = ApiKeys.API_URL; + } + + public getProductByRegion(region: string) { + const url = this.baseUrl+`product/`+region.toString(); + return this.http.get(url); + } + + public getUsers() { + const url = this.baseUrl+`users`; + return this.http.get(url); + } + + public getCollegesByRegion(region: string) { + const url = this.baseUrl+`college/`+region.toString(); + return this.http.get(url); + } + + public getClientsAll() { + const url = this.baseUrl+`client/all`; + return this.http.get(url); + } +} diff --git a/src/app/ui/proform-add/proform-add.component.ts b/src/app/ui/proform-add/proform-add.component.ts index cd2be27..428e402 100644 --- a/src/app/ui/proform-add/proform-add.component.ts +++ b/src/app/ui/proform-add/proform-add.component.ts @@ -9,17 +9,17 @@ import { ExcelExportService } from 'src/app/shared/service/export-excel.service' import * as _ from 'lodash'; import { of as observableOf } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { GridRecord, IProform, IProformDetail, MODEL_DETAIL } from 'src/app/app.type'; +import { GridRecord, IProform, IProformDetail, MODEL_DETAIL, DataType } from 'src/app/app.type'; import Handsontable from 'handsontable'; import { ProformService } from '../../shared/service/proform.service'; import { Router } from '@angular/router'; import { ProductService } from 'src/app/shared/service/product.service'; -import { map } from 'rxjs/operators'; +import { UtilsService } from 'src/app/shared/service/utils.service'; +import { map, switchMap } from 'rxjs/operators'; const dataVal = require('./proformList.json'); -const vendedores = require('./vendedores.json'); const clientes = require('./clientes.json'); const colegios = require('./colegios.json'); @@ -32,6 +32,10 @@ const colegios = require('./colegios.json'); export class ProformAddComponent implements OnInit { @ViewChild(ProjectComponent, {static: true}) child: ProjectComponent; @ViewChild('container') container: ElementRef; + + public userData: any; + public collegeDataType: DataType ; + public listCollegeDataType: DataType[]; public data: any; public dataOfBank: any[] = []; @@ -48,31 +52,47 @@ export class ProformAddComponent implements OnInit { public dataService: any; public dataProduct: any; public dataProformId; - currentDate: {}; + public currentDate: {}; + public form = new FormGroup({}); + public model = {}; + public options = {}; constructor( private excelExportService: ExcelExportService, private route: ActivatedRoute, private proformService: ProformService, private productService: ProductService, + private utilsService: UtilsService, private router: Router ) { - + const self = this; this.data = dataVal; this.dataOfBank = dataVal; for (let value = 0; value < this.dataOfBank.length; value++) { let row = this.dataOfBank[value]; //this.dataset.push(row); }; + /* this.productService.getProductByRegion(TypeRegion.SIERRA).subscribe(product => { - this.dataProduct = product; + self.dataProduct = product; }); + */ + + + + } ngOnInit() { + const self = this; this.enabledTitle = false; this.allowExcelExport = false; + this.getDataProduct().subscribe(data => { + self.dataProduct = data; + }); + console.log(this.dataProduct); + this.currentDate = new Date(); this.route.queryParams.subscribe( @@ -94,12 +114,11 @@ export class ProformAddComponent implements OnInit { resizable: true }; - } + - form = new FormGroup({}); - model = {}; + } - options = {}; + public formFields: FormlyFieldConfig[] = [ @@ -157,7 +176,21 @@ export class ProformAddComponent implements OnInit { templateOptions: { label: Proform.USER_ID.name, required: true, - options: vendedores, + 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; + }); + + } }, expressionProperties: { 'templateOptions.disabled': this.validation, @@ -204,7 +237,19 @@ export class ProformAddComponent implements OnInit { key: Proform.COLLEGE_ID.prop, templateOptions: { label: Proform.COLLEGE_ID.name, - options: _.sortBy(colegios, "label"), + valueProp: 'id', + labelProp: 'name', + //options: _.sortBy(colegios, "label"), + }, + lifecycle: { + onInit: (form, field) => { + this.utilsService + .getCollegesByRegion(TypeRegion.SIERRA) + .pipe() + .subscribe(data => { + field.templateOptions.options = _.sortBy(data, "name"); + }); + } }, expressionProperties: { 'templateOptions.disabled': this.validation, @@ -216,7 +261,19 @@ export class ProformAddComponent implements OnInit { key: Proform.CLIENT_ID.prop, templateOptions: { label: Proform.CLIENT_ID.name, - options: _.sortBy(clientes, "label"), + valueProp: 'id', + labelProp: 'name', + //options: _.sortBy(clientes, "label"), + }, + lifecycle: { + onInit: (form, field) => { + this.utilsService + .getClientsAll() + .pipe() + .subscribe(data => { + field.templateOptions.options = _.sortBy(data, "name"); + }); + } }, expressionProperties: { 'templateOptions.disabled': this.validation, @@ -361,6 +418,10 @@ export class ProformAddComponent implements OnInit { } + public getDataProduct() { + return this.productService.getProductByRegion(TypeRegion.SIERRA); + } + public matchProduct(description: string, product: any[]): number | undefined { let productObj = _.find(product, (x) => x.description === description); if (_.isNil(productObj)) { diff --git a/src/app/ui/proform-edit/proform-edit.component.ts b/src/app/ui/proform-edit/proform-edit.component.ts index c3de638..006e853 100644 --- a/src/app/ui/proform-edit/proform-edit.component.ts +++ b/src/app/ui/proform-edit/proform-edit.component.ts @@ -280,6 +280,7 @@ export class ProformEditComponent implements OnInit { }); } + console.log(self.dataTransform); this.model = cabecera; this.cd.detectChanges(); @@ -364,7 +365,7 @@ export class ProformEditComponent implements OnInit { const idProform = (document.getElementById("txtProforma")).value; - +/* this.getDataById(Number(idProform)).subscribe( data => { self.dataTransform = data['proformDetail']; if( _.size(self.dataTransform) > 0 ) { @@ -375,11 +376,11 @@ export class ProformEditComponent implements OnInit { }; } }); +*/ + //this.ngOnInit(); - this.ngOnInit(); - - console.log('Edit', self.dataset); + console.log('Edit', this.dataset); /* const idProform = 45;