Skip to content

Commit b4db9e5

Browse files
committed
Version final incluye colas (enturnamiento)
1 parent c52ec57 commit b4db9e5

File tree

16 files changed

+478
-356
lines changed

16 files changed

+478
-356
lines changed

classes/encuesta.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Se usa en la sección S8 del curso
2+
export class EncuestaData {
3+
4+
private labels: string[] = [];
5+
private valores: number[] = [0, 0, 0, 0];
6+
7+
constructor() { }
8+
9+
setlabels(labels: string[]) {
10+
this.labels = labels;
11+
}
12+
13+
getDataGrafica() {
14+
return [
15+
{ data: this.valores , label: 'Pregunta'}
16+
];
17+
}
18+
19+
incrementarUnidades( opcion: number, valor: number ) {
20+
this.valores[opcion] += valor;
21+
return this.getDataGrafica();
22+
}
23+
24+
}

classes/escritorios.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Se usa en la última sección ejercicio de Colas
2+
export class Escritorios {
3+
private lista: number[] = [];
4+
5+
asignar(escritorio: number) {
6+
for (const esc of this.lista) {
7+
if (esc == escritorio) {
8+
return false;
9+
}
10+
}
11+
12+
this.lista.push(escritorio);
13+
//console.log("Lista: ", this.lista);
14+
return true;
15+
}
16+
17+
desasignar(escritorio: number) {
18+
for (let i=0; i < this.lista.length; i++) {
19+
if (this.lista[i] == escritorio) {
20+
this.lista.splice(i, 1);
21+
//console.log("Lista: ", this.lista);
22+
return;
23+
}
24+
}
25+
}
26+
}

classes/grafica.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Se usa en la sección S7 del curso
2+
export class GraficaData {
3+
4+
private meses: string[] = ['enero', 'febrero', 'marzo', 'abril' ];
5+
private valores: number[] = [0, 0, 0, 0];
6+
7+
constructor() { }
8+
9+
getDataGrafica() {
10+
return [
11+
{ data: this.valores , label: 'Ventas'}
12+
];
13+
}
14+
15+
incrementarValor( mes: string, valor: number ) {
16+
mes = mes.toLowerCase().trim();
17+
18+
for( let i in this.meses ) {
19+
if ( this.meses[i] === mes ) {
20+
this.valores[i] += valor;
21+
}
22+
}
23+
24+
return this.getDataGrafica();
25+
}
26+
27+
}

classes/mapa.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Marcador } from "./marcador";
2+
3+
// Se usa en la sección S9 del curso
4+
export class Mapa {
5+
// Object declaration with Index Signature Syntax, useful to
6+
// use index search by id instead of using loops
7+
private marcadores: { [key: string]: Marcador } = {}
8+
9+
constructor() {}
10+
11+
getMarcadores() {
12+
return this.marcadores;
13+
}
14+
15+
agregarMarcador( marcador: Marcador ) {
16+
this.marcadores[ marcador.id ] = marcador;
17+
//console.log(marcador);
18+
}
19+
20+
eliminarMarcador( id: string ) {
21+
delete this.marcadores[id];
22+
return this.getMarcadores()
23+
}
24+
25+
moverMarcador( marcador: Marcador ) {
26+
this.marcadores[marcador.id].lng = marcador.lng;
27+
this.marcadores[marcador.id].lat = marcador.lat;
28+
}
29+
}

classes/marcador.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Se usa en la sección S9 del curso
2+
export class Marcador {
3+
constructor(
4+
public id: string,
5+
public nombre: string,
6+
public lng: number,
7+
public lat: number,
8+
public color?: string
9+
) {}
10+
}

classes/server.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
1-
21
import express from 'express';
32
import { SERVER_PORT } from '../global/environment';
4-
import socketIO from 'socket.io';
5-
import http from 'http';
3+
import { Server } from 'socket.io';
4+
import { createServer } from 'http';
65

76
import * as socket from '../sockets/socket';
87

8+
export default class ServerApp {
99

10-
11-
export default class Server {
12-
13-
private static _intance: Server;
10+
private static _intance: ServerApp;
1411

1512
public app: express.Application;
1613
public port: number;
1714

18-
public io: socketIO.Server;
19-
private httpServer: http.Server;
15+
public io: Server;
16+
private httpServer: any;
2017

2118

2219
private constructor() {
2320

2421
this.app = express();
2522
this.port = SERVER_PORT;
2623

27-
this.httpServer = new http.Server( this.app );
28-
this.io = socketIO( this.httpServer );
24+
this.httpServer = createServer( this.app );
25+
this.io = new Server( this.httpServer, {
26+
cors: {
27+
//origin: "http://localhost:4200",
28+
origin: true,
29+
credentials: true
30+
},
31+
} );
2932

30-
this.escucharSockets();
33+
this.listenSockets();
3134
}
3235

3336
public static get instance() {
3437
return this._intance || ( this._intance = new this() );
3538
}
3639

37-
38-
private escucharSockets() {
40+
private listenSockets() {
3941

4042
console.log('Escuchando conexiones - sockets');
4143

4244
this.io.on('connection', cliente => {
4345

44-
// Conectar cliente
45-
socket.conectarCliente( cliente, this.io );
46+
// Después de Conectar cliente
47+
socket.afterClientConnection( cliente );
48+
49+
// Escuchar eventos de usuarios
50+
socket.listenForUsuarios( cliente, this.io );
4651

47-
// Configurar usuario
48-
socket.configurarUsuario( cliente, this.io );
52+
// Escuchar eventos de mapas
53+
socket.listenForMapas( cliente );
4954

50-
// Obtener usuarios activos
51-
socket.obtenerUsuarios( cliente, this.io );
55+
socket.listenForTurnos( cliente );
5256

53-
// Mensajes
54-
socket.mensaje( cliente, this.io );
57+
// Escuchar eventos de Mensajes generales
58+
socket.listenForMensajes( cliente );
5559

56-
// Desconectar
57-
socket.desconectar( cliente, this.io );
58-
60+
// Escuchar eventos de Desconectar
61+
socket.listenForDesconectar( cliente );
5962

6063
});
6164

6265
}
6366

64-
6567
start( callback: Function ) {
6668

6769
this.httpServer.listen( this.port, callback );

classes/turno.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Se usa en la última sección ejercicio de Colas
2+
export class Turno {
3+
constructor(
4+
public turno: number,
5+
public escritorio?: number
6+
) {
7+
}
8+
}

classes/turnos.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Turno } from "./turno";
2+
3+
// Se usa en la última sección ejercicio de Colas
4+
export class Turnos {
5+
private lista: Turno[] = [];
6+
7+
constructor() {
8+
}
9+
10+
asignarTurno(escritorio: number) {
11+
//console.log('Asignando Turno Escritorio ... ', escritorio)
12+
for (let i = 0; i < this.lista.length; i++ ) {
13+
if (this.lista[i].escritorio == null) {
14+
this.lista[i].escritorio = escritorio;
15+
return this.lista[i];
16+
}
17+
}
18+
19+
return null;
20+
}
21+
22+
crearTurno() {
23+
const turno = new Turno(this.lista.length + 1);
24+
this.lista.push(turno);
25+
return turno;
26+
}
27+
28+
getTurnos() {
29+
return this.lista.filter(turno => turno.escritorio); // Solo turnos que tengan asignado escritorio
30+
}
31+
32+
inicializarTurnos() {
33+
this.lista = [];
34+
}
35+
}

classes/usuario.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
2+
// Se usa en todas las secciones del curso
33
export class Usuario {
44

55
public id: string;
@@ -9,8 +9,8 @@ export class Usuario {
99
constructor( id: string ) {
1010

1111
this.id = id;
12-
this.nombre = 'sin-nombre';
13-
this.sala = 'sin-sala';
12+
this.nombre = 'pending ...';
13+
this.sala = 'No Room';
1414

1515
}
1616

classes/usuarios-lista.ts renamed to classes/usuarios.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Usuario } from './usuario';
22

3-
4-
export class UsuariosLista {
3+
// Se usa en todas las secciones del curso
4+
export class Usuarios {
55

66
private lista: Usuario[] = [];
77

@@ -27,15 +27,14 @@ export class UsuariosLista {
2727

2828
}
2929

30-
3130
console.log('===== Actualizando usuario ====');
3231
console.log( this.lista );
3332

3433
}
3534

3635
// Obtener lista de usuarios
3736
public getLista() {
38-
return this.lista.filter( usuario => usuario.nombre !== 'sin-nombre' );
37+
return this.lista.filter( usuario => usuario.nombre !== 'pending ...' );
3938
}
4039

4140
// Obtener un usuario

index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import Server from './classes/server';
1+
import ServerApp from './classes/server';
22
import router from './routes/router';
3-
import bodyParser from 'body-parser';
3+
//import bodyParser from 'body-parser';
44
import cors from 'cors';
5+
import express from 'express';
56

67

7-
8-
const server = Server.instance;
8+
const server = ServerApp.instance;
99

1010
// BodyParser
11-
server.app.use( bodyParser.urlencoded({ extended: true }) );
12-
server.app.use( bodyParser.json() );
11+
//server.app.use( bodyParser.urlencoded({ extended: true }) );
12+
//server.app.use( bodyParser.json() );
13+
14+
server.app.use( express.urlencoded() ); // Parse URL - encoded bodies
15+
server.app.use( express.json() );
1316

1417
// CORS
1518
server.app.use( cors({ origin: true, credentials: true }) );
1619

17-
1820
// Rutas de servicios
1921
server.app.use('/', router );
2022

21-
22-
23-
2423
server.start( () => {
2524
console.log(`Servidor corriendo en el puerto ${ server.port }`);
2625
});

0 commit comments

Comments
 (0)