Skip to content

Commit 223b039

Browse files
committed
Fin sección 5
1 parent 319757b commit 223b039

19 files changed

Lines changed: 228 additions & 18 deletions

src/app/app-routing.module.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule, Routes } from '@angular/router';
3+
4+
import { LoginComponent } from './pages/login/login.component';
5+
import { MensajesComponent } from './pages/mensajes/mensajes.component';
6+
import { UsuarioGuard } from './guards/usuario.guard';
7+
8+
const appRoutes: Routes = [
9+
{ path: '', component: LoginComponent},
10+
{ path: 'mensajes', component: MensajesComponent, canActivate: [UsuarioGuard]},
11+
{ path: '**', component: LoginComponent}
12+
];
13+
14+
@NgModule({
15+
imports: [ RouterModule.forRoot(appRoutes) ],
16+
exports: [ RouterModule ]
17+
})
18+
export class AppRoutingModule { }

src/app/app.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
<app-chat></app-chat>
1+
<!-- <app-chat></app-chat> -->
2+
<router-outlet></router-outlet>
23

34
<app-footer></app-footer>
5+

src/app/app.component.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { WebsocketService } from './services/websocket.service';
3+
import { ChatService } from './services/chat.service';
34

45
@Component({
5-
selector: 'app-root',
6-
templateUrl: './app.component.html',
7-
styleUrls: ['./app.component.css']
6+
selector: 'app-root',
7+
templateUrl: './app.component.html',
8+
styleUrls: ['./app.component.css']
89
})
9-
export class AppComponent{
10+
export class AppComponent implements OnInit{
1011

11-
constructor(public wsService: WebsocketService){}
12+
constructor(public wsService: WebsocketService,
13+
public chatService: ChatService) { }
14+
15+
ngOnInit(): void {
16+
this.chatService.getMessagesPrivate().subscribe( msg => {
17+
console.log(msg)
18+
});
19+
}
1220

1321

1422
}

src/app/app.module.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@ import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
import { environment } from '../environments/environment'
44

5+
import { FormsModule } from '@angular/forms';
6+
import { AppRoutingModule } from './app-routing.module';
7+
58
// Sockets
69
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
710
const config: SocketIoConfig = { url: environment.socketURL, options: {} };
811

912
import { AppComponent } from './app.component';
1013
import { FooterComponent } from './components/footer/footer.component';
1114
import { ChatComponent } from './components/chat/chat.component';
12-
import { FormsModule } from '@angular/forms';
15+
import { ListaUsuariosComponent } from './components/lista-usuarios/lista-usuarios.component';
16+
import { LoginComponent } from './pages/login/login.component';
17+
import { MensajesComponent } from './pages/mensajes/mensajes.component';
1318

1419

1520
@NgModule({
1621
declarations: [
1722
AppComponent,
1823
FooterComponent,
1924
ChatComponent,
25+
ListaUsuariosComponent,
26+
LoginComponent,
27+
MensajesComponent,
2028
],
2129
imports: [
2230
BrowserModule,
31+
FormsModule,
2332
SocketIoModule.forRoot(config),
24-
FormsModule
33+
AppRoutingModule
2534
],
2635
providers: [],
2736
bootstrap: [AppComponent]

src/app/classes/usuario.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class Usuario {
2+
3+
public nombre: string;
4+
5+
constructor(nombre: string){
6+
this.nombre = nombre;
7+
}
8+
9+
}
10+
11+
export interface Mensaje {
12+
de: string;
13+
cuerpo: string;
14+
}

src/app/components/chat/chat.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ChatComponent implements OnInit, OnDestroy {
3737
setTimeout(() => {
3838
this.elemento.scrollTop = this.elemento.scrollHeight;
3939
}, 50);
40-
})
40+
});
4141
}
4242

4343
enviar(){

src/app/components/lista-usuarios/lista-usuarios.component.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>lista-usuarios works!</p>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-lista-usuarios',
5+
templateUrl: './lista-usuarios.component.html',
6+
styleUrls: ['./lista-usuarios.component.css']
7+
})
8+
export class ListaUsuariosComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit(): void {
13+
}
14+
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { UsuarioGuard } from './usuario.guard';
4+
5+
describe('UsuarioGuardGuard', () => {
6+
let guard: UsuarioGuard;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
guard = TestBed.inject(UsuarioGuard);
11+
});
12+
13+
it('should be created', () => {
14+
expect(guard).toBeTruthy();
15+
});
16+
});

0 commit comments

Comments
 (0)