Skip to content

Commit

Permalink
feat: change services info
Browse files Browse the repository at this point in the history
  • Loading branch information
leoriofrio committed Jun 2, 2020
1 parent 4739893 commit 45dfaec
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
7 changes: 7 additions & 0 deletions src/app/app.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export type GridRecord = {
route?: string;
}

export interface DataType {
label: any,
value: any;
}

export interface IProform {
id: number;
number_proform: string;
Expand Down Expand Up @@ -75,4 +80,6 @@ export type GridRecord = {
"sale_training": 0
};




16 changes: 16 additions & 0 deletions src/app/shared/service/utils.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
43 changes: 43 additions & 0 deletions src/app/shared/service/utils.service.ts
Original file line number Diff line number Diff line change
@@ -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<any>(url);
}

public getUsers() {
const url = this.baseUrl+`users`;
return this.http.get<any>(url);
}

public getCollegesByRegion(region: string) {
const url = this.baseUrl+`college/`+region.toString();
return this.http.get<any>(url);
}

public getClientsAll() {
const url = this.baseUrl+`client/all`;
return this.http.get<any>(url);
}
}
87 changes: 74 additions & 13 deletions src/app/ui/proform-add/proform-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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[] = [];
Expand All @@ -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(
Expand All @@ -94,12 +114,11 @@ export class ProformAddComponent implements OnInit {
resizable: true
};

}

form = new FormGroup({});
model = {};
}

options = {};



public formFields: FormlyFieldConfig[] = [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
9 changes: 5 additions & 4 deletions src/app/ui/proform-edit/proform-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export class ProformEditComponent implements OnInit {

});
}
console.log(self.dataTransform);

this.model = cabecera;
this.cd.detectChanges();
Expand Down Expand Up @@ -364,7 +365,7 @@ export class ProformEditComponent implements OnInit {


const idProform = (<HTMLInputElement>document.getElementById("txtProforma")).value;

/*
this.getDataById(Number(idProform)).subscribe( data => {
self.dataTransform = data['proformDetail'];
if( _.size(self.dataTransform) > 0 ) {
Expand All @@ -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;
Expand Down

0 comments on commit 45dfaec

Please sign in to comment.