Skip to content

Commit

Permalink
feat: services
Browse files Browse the repository at this point in the history
  • Loading branch information
leoriofrio committed Aug 19, 2020
1 parent ce7dce2 commit a6e1f26
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 21,860 deletions.
4 changes: 2 additions & 2 deletions src/app/app.keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export enum AppStatusForm {
}

export namespace ApiKeys {
//export const API_URL = "http://104.210.146.134:3000/";
export const API_URL = "http://localhost:3000/";
export const API_URL = "http://104.210.146.134:3000/";
//export const API_URL = "http://localhost:3000/";
}

export namespace TitleNames {
Expand Down
50 changes: 45 additions & 5 deletions src/app/configuration/client/client.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { COLUMNS_CLIENT } from './clientColumns';
import { ProjectComponent } from '../../shared/components/project/project.component';
import { ExcelExportService } from '../../shared/service/export-excel.service';
import * as _ from 'lodash';
import { ClientService } from 'src/app/shared/service/client.service';
import { Router, ActivatedRoute } from '@angular/router';
import { forkJoin } from 'rxjs';

const dataVal = require('./client.json');
//const dataVal = require('./client.json');

@Component({
selector: 'app-client',
Expand All @@ -17,18 +20,29 @@ const dataVal = require('./client.json');
export class ClientComponent implements OnInit, TransformColumns {
@ViewChild(ProjectComponent, { static: true }) child: ProjectComponent;

public data = dataVal;
public data: any;
public gridColumns = COLUMNS_CLIENT;
public enabledTitle: boolean;
public allowExcelExport: boolean;

constructor(private excelExportService: ExcelExportService) {
constructor(
private excelExportService: ExcelExportService,
private clientService: ClientService,
private router: Router,
private route: ActivatedRoute,
) {

}

ngOnInit(): void {
const self = this;

this.enabledTitle = true;
this.allowExcelExport = true;

this.getDataClient().subscribe(data => {
self.data = data;
});
}


Expand All @@ -43,9 +57,31 @@ export class ClientComponent implements OnInit, TransformColumns {
}

public onJsonData(jsonData) {
console.log('data de Cliente es', jsonData);
let jsonEditClient: any[] = [];
let jsonAddClient: any[] = [];
let jsonFinal = this.namesToProps(jsonData);
console.log('jsonFinal', jsonFinal);
for ( const row of jsonFinal ){
if( !_.isNil(row['id']) ){
jsonEditClient.push(row);
} else {
jsonAddClient.push(row);
}
}

for ( const row of jsonAddClient )
delete row['id'];

const self = this;
forkJoin(
this.clientService.createClient(JSON.stringify(jsonAddClient)),
this.clientService.updateClient(JSON.stringify(jsonEditClient))
).subscribe( ([addClient, editClient ]) => {
alert('Se ha guardado correctamente los clientes');
this.router.navigateByUrl('/client', { skipLocationChange: true }).then(() => {
this.router.navigate(['/client']);
});
setTimeout(() => {}, 1000);
});
}

public namesToProps(json){
Expand All @@ -63,4 +99,8 @@ export class ClientComponent implements OnInit, TransformColumns {
});
}

public getDataClient() {
return this.clientService.getClientActive();
}

}
52 changes: 46 additions & 6 deletions src/app/configuration/colleges/colleges.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use strict';

import { Component, OnInit, ViewChild } from '@angular/core';
import { ClientColumns, CollegesColumns } from '../../app.keys';
import { ClientColumns, CollegesColumns, TransformColumns, TypeRegion } from '../../app.keys';
import { COLUMNS_COLLEGES } from './collegesColumns';
import { ProjectComponent } from '../../shared/components/project/project.component';
import { ExcelExportService } from '../../shared/service/export-excel.service';
import * as _ from 'lodash';
import { forkJoin } from 'rxjs';
import { CollegeService } from 'src/app/shared/service/college.service';
import { Router } from '@angular/router';

const dataVal = require('./colleges.json');
//const dataVal = require('./colleges.json');

@Component({
selector: 'app-colleges',
Expand All @@ -17,16 +20,25 @@ const dataVal = require('./colleges.json');
export class CollegesComponent implements OnInit, TransformColumns {
@ViewChild(ProjectComponent, {static: true}) child: ProjectComponent;

public data = dataVal;
public data: any;
public gridColumns = COLUMNS_COLLEGES;
public enabledTitle: boolean;
public allowExcelExport: boolean;

constructor(private excelExportService: ExcelExportService) { }
constructor(
private excelExportService: ExcelExportService,
private collegeService: CollegeService,
private router: Router,
) { }

ngOnInit(): void {
const self = this;
this.enabledTitle = true;
this.allowExcelExport = true;

this.getDataCollege().subscribe(data => {
self.data = data;
});
}

/**
Expand All @@ -45,9 +57,33 @@ export class CollegesComponent implements OnInit, TransformColumns {
}

public onJsonData(jsonData){
console.log('data de Colleges es', jsonData);
let jsonEditCollege: any[] = [];
let jsonAddCollege: any[] = [];
//console.log('data de Colleges es', jsonData);
let jsonFinal = this.namesToProps(jsonData);
console.log('jsonFinal', jsonFinal);
//console.log('jsonFinal', jsonFinal);
for ( const row of jsonFinal ){
if( !_.isNil(row['id']) ){
jsonEditCollege.push(row);
} else {
jsonAddCollege.push(row);
}
}

for ( const row of jsonAddCollege )
delete row['id'];

const self = this;
forkJoin(
this.collegeService.createCollege(JSON.stringify(jsonAddCollege)),
this.collegeService.updateCollege(JSON.stringify(jsonEditCollege))
).subscribe( ([addCollege, editCollege ]) => {
alert('Se ha guardado correctamente los colegios');
this.router.navigateByUrl('/college', { skipLocationChange: true }).then(() => {
this.router.navigate(['/college']);
});
setTimeout(() => {}, 1000);
});
}

public namesToProps(json){
Expand Down Expand Up @@ -76,4 +112,8 @@ export class CollegesComponent implements OnInit, TransformColumns {
});
}

public getDataCollege() {
return this.collegeService.getCollegeByRegion(TypeRegion.SIERRA);
}

}
Loading

0 comments on commit a6e1f26

Please sign in to comment.