diff --git a/src/app/app.keys.ts b/src/app/app.keys.ts index 88b75c3..0625395 100644 --- a/src/app/app.keys.ts +++ b/src/app/app.keys.ts @@ -212,4 +212,9 @@ export const FilesType = { export const ValidatesPattern = { alphanumeric: "[a-zA-Z0-9\\s]+" +} + +export declare interface TransformColumns { + + namesToProps(json): any; } \ No newline at end of file diff --git a/src/app/configuration/client/client.component.ts b/src/app/configuration/client/client.component.ts index 39db843..97187b1 100644 --- a/src/app/configuration/client/client.component.ts +++ b/src/app/configuration/client/client.component.ts @@ -1,7 +1,7 @@ 'use strict'; import { Component, OnInit, ViewChild } from '@angular/core'; -import { ClientColumns } from '../../app.keys'; +import { ClientColumns, TransformColumns } from '../../app.keys'; import { COLUMNS_CLIENT } from './clientColumns'; import { ProjectComponent } from '../../shared/components/project/project.component'; import { ExcelExportService } from '../../shared/service/export-excel.service'; @@ -14,7 +14,7 @@ const dataVal = require('./client.json'); templateUrl: './client.component.html', styleUrls: ['./client.component.scss'] }) -export class ClientComponent implements OnInit { +export class ClientComponent implements OnInit, TransformColumns { @ViewChild(ProjectComponent, { static: true }) child: ProjectComponent; public data = dataVal; @@ -48,6 +48,23 @@ export class ClientComponent implements OnInit { public onJsonData(jsonData) { console.log('data de Cliente es', jsonData); + let jsonFinal = this.namesToProps(jsonData); + console.log('jsonFinal', jsonFinal); + } + + public namesToProps(json){ + return json.map(key => { + let res = {}; + res[`${ClientColumns.ID.prop}`] = key[ClientColumns.ID.name]; + res[`${ClientColumns.COD_CLIENT.prop}`] = key[ClientColumns.COD_CLIENT.name]; + res[`${ClientColumns.PROVINCE.prop}`] = key[ClientColumns.PROVINCE.name]; + res[`${ClientColumns.CITY.prop}`] = key[ClientColumns.CITY.name]; + res[`${ClientColumns.NAME.prop}`] = key[ClientColumns.NAME.name]; + res[`${ClientColumns.NICKNAME.prop}`] = key[ClientColumns.NICKNAME.name]; + res[`${ClientColumns.TYPE.prop}`] = key[ClientColumns.TYPE.name]; + res[`${ClientColumns.STATUS.prop}`] = key[ClientColumns.STATUS.name]; + return res; + }); } } diff --git a/src/app/configuration/colleges/colleges.component.ts b/src/app/configuration/colleges/colleges.component.ts index 1d5edcd..f0f659e 100644 --- a/src/app/configuration/colleges/colleges.component.ts +++ b/src/app/configuration/colleges/colleges.component.ts @@ -1,7 +1,7 @@ 'use strict'; import { Component, OnInit, ViewChild } from '@angular/core'; -import { ClientColumns } from '../../app.keys'; +import { ClientColumns, CollegesColumns } from '../../app.keys'; import { COLUMNS_COLLEGES } from './collegesColumns'; import { ProjectComponent } from '../../shared/components/project/project.component'; import { ExcelExportService } from '../../shared/service/export-excel.service'; @@ -14,7 +14,7 @@ const dataVal = require('./colleges.json'); templateUrl: './colleges.component.html', styleUrls: ['./colleges.component.css'] }) -export class CollegesComponent implements OnInit { +export class CollegesComponent implements OnInit, TransformColumns { @ViewChild(ProjectComponent, {static: true}) child: ProjectComponent; public data = dataVal; @@ -46,6 +46,34 @@ export class CollegesComponent implements OnInit { public onJsonData(jsonData){ console.log('data de Colleges es', jsonData); + let jsonFinal = this.namesToProps(jsonData); + console.log('jsonFinal', jsonFinal); + } + + public namesToProps(json){ + return json.map(key => { + let res = {}; + res[`${CollegesColumns.ID.prop}`] = key[CollegesColumns.ID.name]; + res[`${CollegesColumns.COD_SANTILLANA.prop}`] = key[CollegesColumns.COD_SANTILLANA.name]; + res[`${CollegesColumns.COD_INSTITUTO.prop}`] = key[CollegesColumns.COD_INSTITUTO.name]; + res[`${CollegesColumns.STATUS.prop}`] = key[CollegesColumns.STATUS.name]; + res[`${CollegesColumns.DELEGATE_TEXT.prop}`] = key[CollegesColumns.DELEGATE_TEXT.name]; + res[`${CollegesColumns.DELEGATE_ENGLISH.prop}`] = key[CollegesColumns.DELEGATE_ENGLISH.name]; + res[`${CollegesColumns.DELEGATE_SHARED.prop}`] = key[CollegesColumns.DELEGATE_SHARED.name]; + res[`${CollegesColumns.PROVINCE.prop}`] = key[CollegesColumns.PROVINCE.name]; + res[`${CollegesColumns.CANTON.prop}`] = key[CollegesColumns.CANTON.name]; + res[`${CollegesColumns.PARISH.prop}`] = key[CollegesColumns.PARISH.name]; + + res[`${CollegesColumns.NAME.prop}`] = key[CollegesColumns.NAME.name]; + res[`${CollegesColumns.ADDRESS.prop}`] = key[CollegesColumns.ADDRESS.name]; + res[`${CollegesColumns.NIVEL.prop}`] = key[CollegesColumns.NIVEL.name]; + res[`${CollegesColumns.TYPE.prop}`] = key[CollegesColumns.TYPE.name]; + res[`${CollegesColumns.SCHOOL_SYSTEM.prop}`] = key[CollegesColumns.SCHOOL_SYSTEM.name]; + res[`${CollegesColumns.MODALITY.prop}`] = key[CollegesColumns.MODALITY.name]; + res[`${CollegesColumns.SCHOOL_DAY.prop}`] = key[CollegesColumns.SCHOOL_DAY.name]; + res[`${CollegesColumns.REGION_ID.prop}`] = key[CollegesColumns.REGION_ID.name]; + return res; + }); } } diff --git a/src/app/configuration/product/product.component.ts b/src/app/configuration/product/product.component.ts index ad7ff9d..ea2a3f8 100644 --- a/src/app/configuration/product/product.component.ts +++ b/src/app/configuration/product/product.component.ts @@ -1,7 +1,7 @@ 'use strict'; import { Component, OnInit, ViewChild } from '@angular/core'; -import { ProductColumns, TypeRegion } from '../../app.keys'; +import { ProductColumns, TypeRegion, TransformColumns } from '../../app.keys'; import { ProjectComponent } from '../../shared/components/project/project.component'; import { COLUMNS_PRODUCT, COLUMNS_PINNED_TOP_DATA } from './productColumns'; import { ExcelExportService } from '../../shared/service/export-excel.service'; @@ -15,7 +15,7 @@ import { ProductService } from 'src/app/shared/service/product.service'; templateUrl: './product.component.html', styleUrls: ['./product.component.scss'] }) -export class ProductComponent implements OnInit { +export class ProductComponent implements OnInit, TransformColumns { @ViewChild(ProjectComponent, {static: true}) child: ProjectComponent; @@ -79,12 +79,31 @@ export class ProductComponent implements OnInit { } public onJsonData(jsonData){ - console.log('data de Producto es', JSON.stringify(jsonData)); - return this.productService.createProduct('1', JSON.stringify(jsonData)); + console.log('data de Producto es', JSON.stringify(jsonData)); + let jsonFinal = this.namesToProps(jsonData); + console.log('jsonFinal', jsonFinal); + return this.productService.createProduct('1', JSON.stringify(jsonFinal)); } public getDataProduct() { return this.productService.getProductByRegion(TypeRegion.SIERRA); } + public namesToProps(json){ + return json.map(key => { + let res = {}; + res[`${ProductColumns.ID.prop}`] = key[ProductColumns.ID.name]; + res[`${ProductColumns.COD.prop}`] = key[ProductColumns.COD.name]; + res[`${ProductColumns.SUBLINE.prop}`] = key[ProductColumns.SUBLINE.name]; + res[`${ProductColumns.DESCRIPTION.prop}`] = key[ProductColumns.DESCRIPTION.name]; + res[`${ProductColumns.SERIE.prop}`] = key[ProductColumns.SERIE.name]; + res[`${ProductColumns.NIVEL.prop}`] = key[ProductColumns.NIVEL.name]; + res[`${ProductColumns.DEGREE.prop}`] = key[ProductColumns.DEGREE.name]; + res[`${ProductColumns.BUSINESS_LINE.prop}`] = key[ProductColumns.BUSINESS_LINE.name]; + res[`${ProductColumns.ISBN.prop}`] = key[ProductColumns.ISBN.name]; + res[`${ProductColumns.REGION.prop}`] = key[ProductColumns.REGION.name]; + return res; + }); + } + } diff --git a/src/app/shared/service/import-excel.service.ts b/src/app/shared/service/import-excel.service.ts index 8a7e87d..6e23115 100644 --- a/src/app/shared/service/import-excel.service.ts +++ b/src/app/shared/service/import-excel.service.ts @@ -39,4 +39,5 @@ export class ExcelImportService { } }); } + }