From 32de137611eff55f04b51cf9a3064060b0ee9f88 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Sun, 30 Jul 2017 12:29:30 -0300 Subject: [PATCH] demo meetup --- src/app/app-routing.module.ts | 20 +++++++++++++++- src/app/app.component.html | 12 ---------- src/app/app.module.ts | 18 +++++++++++--- src/app/bla/bla-routing.module.ts | 10 ++++++++ src/app/bla/bla.module.ts | 13 +++++++++++ src/app/http-usuario.service.spec.ts | 15 ++++++++++++ src/app/http-usuario.service.ts | 14 +++++++++++ src/app/my-guard.guard.spec.ts | 15 ++++++++++++ src/app/my-guard.guard.ts | 12 ++++++++++ src/app/usuario/usuario.component.css | 0 src/app/usuario/usuario.component.html | 8 +++++++ src/app/usuario/usuario.component.spec.ts | 25 ++++++++++++++++++++ src/app/usuario/usuario.component.ts | 26 +++++++++++++++++++++ src/app/usuario2/usuario2.component.css | 0 src/app/usuario2/usuario2.component.html | 3 +++ src/app/usuario2/usuario2.component.spec.ts | 25 ++++++++++++++++++++ src/app/usuario2/usuario2.component.ts | 15 ++++++++++++ src/app/vendas/home/home.component.css | 0 src/app/vendas/home/home.component.html | 3 +++ src/app/vendas/home/home.component.spec.ts | 25 ++++++++++++++++++++ src/app/vendas/home/home.component.ts | 15 ++++++++++++ src/app/vendas/vendas.module.ts | 14 +++++++++++ 22 files changed, 272 insertions(+), 16 deletions(-) create mode 100644 src/app/bla/bla-routing.module.ts create mode 100644 src/app/bla/bla.module.ts create mode 100644 src/app/http-usuario.service.spec.ts create mode 100644 src/app/http-usuario.service.ts create mode 100644 src/app/my-guard.guard.spec.ts create mode 100644 src/app/my-guard.guard.ts create mode 100644 src/app/usuario/usuario.component.css create mode 100644 src/app/usuario/usuario.component.html create mode 100644 src/app/usuario/usuario.component.spec.ts create mode 100644 src/app/usuario/usuario.component.ts create mode 100644 src/app/usuario2/usuario2.component.css create mode 100644 src/app/usuario2/usuario2.component.html create mode 100644 src/app/usuario2/usuario2.component.spec.ts create mode 100644 src/app/usuario2/usuario2.component.ts create mode 100644 src/app/vendas/home/home.component.css create mode 100644 src/app/vendas/home/home.component.html create mode 100644 src/app/vendas/home/home.component.spec.ts create mode 100644 src/app/vendas/home/home.component.ts create mode 100644 src/app/vendas/vendas.module.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 5b7d25b..4f7043a 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,10 +1,28 @@ +import { MyGuardGuard } from './my-guard.guard'; +import { HomeComponent } from './vendas/home/home.component'; +import { Usuario2Component } from './usuario2/usuario2.component'; +import { UsuarioComponent } from './usuario/usuario.component'; import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; const routes: Routes = [ { path: '', - children: [] + canActivate: [MyGuardGuard], + children: [ + { + path: 'usuario', + component: UsuarioComponent, + }, + { + path: 'usuario2', + component: Usuario2Component + }, + { + path: 'vendas', + component: HomeComponent + } + ] } ]; diff --git a/src/app/app.component.html b/src/app/app.component.html index 84369a3..44a259b 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -5,17 +5,5 @@

-

Here are some links to help you start:

- diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2c3ba29..9f48b5d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,18 +1,30 @@ +import { HttpUsuarioService } from './http-usuario.service'; +import { MyGuardGuard } from './my-guard.guard'; +import { VendasModule } from './vendas/vendas.module'; import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { HttpClientModule } from '@angular/common/http'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; +import { UsuarioComponent } from './usuario/usuario.component'; +import { Usuario2Component } from './usuario2/usuario2.component'; @NgModule({ declarations: [ - AppComponent + AppComponent, + UsuarioComponent, + Usuario2Component ], imports: [ BrowserModule, - AppRoutingModule + AppRoutingModule, + VendasModule, + HttpClientModule, + FormsModule ], - providers: [], + providers: [MyGuardGuard, HttpUsuarioService], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/src/app/bla/bla-routing.module.ts b/src/app/bla/bla-routing.module.ts new file mode 100644 index 0000000..d161b91 --- /dev/null +++ b/src/app/bla/bla-routing.module.ts @@ -0,0 +1,10 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +const routes: Routes = []; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class BlaRoutingModule { } diff --git a/src/app/bla/bla.module.ts b/src/app/bla/bla.module.ts new file mode 100644 index 0000000..bce0106 --- /dev/null +++ b/src/app/bla/bla.module.ts @@ -0,0 +1,13 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +import { BlaRoutingModule } from './bla-routing.module'; + +@NgModule({ + imports: [ + CommonModule, + BlaRoutingModule + ], + declarations: [] +}) +export class BlaModule { } diff --git a/src/app/http-usuario.service.spec.ts b/src/app/http-usuario.service.spec.ts new file mode 100644 index 0000000..86a1da4 --- /dev/null +++ b/src/app/http-usuario.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { HttpUsuarioService } from './http-usuario.service'; + +describe('HttpUsuarioService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [HttpUsuarioService] + }); + }); + + it('should be created', inject([HttpUsuarioService], (service: HttpUsuarioService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/http-usuario.service.ts b/src/app/http-usuario.service.ts new file mode 100644 index 0000000..ec558be --- /dev/null +++ b/src/app/http-usuario.service.ts @@ -0,0 +1,14 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; + +@Injectable() +export class HttpUsuarioService { + + constructor(private http: HttpClient) { + } + + obterUsuarios() { + return this.http.get('https://demo-gama.herokuapp.com/user'); + } + +} diff --git a/src/app/my-guard.guard.spec.ts b/src/app/my-guard.guard.spec.ts new file mode 100644 index 0000000..40648ba --- /dev/null +++ b/src/app/my-guard.guard.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, async, inject } from '@angular/core/testing'; + +import { MyGuardGuard } from './my-guard.guard'; + +describe('MyGuardGuard', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [MyGuardGuard] + }); + }); + + it('should ...', inject([MyGuardGuard], (guard: MyGuardGuard) => { + expect(guard).toBeTruthy(); + })); +}); diff --git a/src/app/my-guard.guard.ts b/src/app/my-guard.guard.ts new file mode 100644 index 0000000..25486b5 --- /dev/null +++ b/src/app/my-guard.guard.ts @@ -0,0 +1,12 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; + +@Injectable() +export class MyGuardGuard implements CanActivate { + canActivate( + next: ActivatedRouteSnapshot, + state: RouterStateSnapshot): Observable | Promise | boolean { + return true; + } +} diff --git a/src/app/usuario/usuario.component.css b/src/app/usuario/usuario.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/usuario/usuario.component.html b/src/app/usuario/usuario.component.html new file mode 100644 index 0000000..aa335ef --- /dev/null +++ b/src/app/usuario/usuario.component.html @@ -0,0 +1,8 @@ +Teste Async 2 +
+

+ Meu documento é {{usuario.documento}} +

+ +{{name}} +
diff --git a/src/app/usuario/usuario.component.spec.ts b/src/app/usuario/usuario.component.spec.ts new file mode 100644 index 0000000..afd7caa --- /dev/null +++ b/src/app/usuario/usuario.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { UsuarioComponent } from './usuario.component'; + +describe('UsuarioComponent', () => { + let component: UsuarioComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ UsuarioComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(UsuarioComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/usuario/usuario.component.ts b/src/app/usuario/usuario.component.ts new file mode 100644 index 0000000..937cf29 --- /dev/null +++ b/src/app/usuario/usuario.component.ts @@ -0,0 +1,26 @@ +import { HttpUsuarioService } from './../http-usuario.service'; +import { Component, OnInit } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import 'rxjs/add/operator/toPromise'; + +@Component({ + selector: 'app-usuario', + templateUrl: './usuario.component.html', + styleUrls: ['./usuario.component.css'] +}) +export class UsuarioComponent implements OnInit { + + usuarios = this.httpUsuario.obterUsuarios(); + name = 'Carlao'; + + constructor(private httpUsuario: HttpUsuarioService) { + } + + meuMetodo(event) { + console.log(event); + } + + ngOnInit() { + } + +} diff --git a/src/app/usuario2/usuario2.component.css b/src/app/usuario2/usuario2.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/usuario2/usuario2.component.html b/src/app/usuario2/usuario2.component.html new file mode 100644 index 0000000..7084688 --- /dev/null +++ b/src/app/usuario2/usuario2.component.html @@ -0,0 +1,3 @@ +

+ usuario2 works! +

diff --git a/src/app/usuario2/usuario2.component.spec.ts b/src/app/usuario2/usuario2.component.spec.ts new file mode 100644 index 0000000..b60672a --- /dev/null +++ b/src/app/usuario2/usuario2.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { Usuario2Component } from './usuario2.component'; + +describe('Usuario2Component', () => { + let component: Usuario2Component; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ Usuario2Component ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(Usuario2Component); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/usuario2/usuario2.component.ts b/src/app/usuario2/usuario2.component.ts new file mode 100644 index 0000000..367eead --- /dev/null +++ b/src/app/usuario2/usuario2.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-usuario2', + templateUrl: './usuario2.component.html', + styleUrls: ['./usuario2.component.css'] +}) +export class Usuario2Component implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/vendas/home/home.component.css b/src/app/vendas/home/home.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/vendas/home/home.component.html b/src/app/vendas/home/home.component.html new file mode 100644 index 0000000..afc16a3 --- /dev/null +++ b/src/app/vendas/home/home.component.html @@ -0,0 +1,3 @@ +

+ home works! +

diff --git a/src/app/vendas/home/home.component.spec.ts b/src/app/vendas/home/home.component.spec.ts new file mode 100644 index 0000000..86774ae --- /dev/null +++ b/src/app/vendas/home/home.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HomeComponent } from './home.component'; + +describe('HomeComponent', () => { + let component: HomeComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ HomeComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(HomeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/vendas/home/home.component.ts b/src/app/vendas/home/home.component.ts new file mode 100644 index 0000000..33fd770 --- /dev/null +++ b/src/app/vendas/home/home.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-home', + templateUrl: './home.component.html', + styleUrls: ['./home.component.css'] +}) +export class HomeComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/vendas/vendas.module.ts b/src/app/vendas/vendas.module.ts new file mode 100644 index 0000000..9ea5eac --- /dev/null +++ b/src/app/vendas/vendas.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { HomeComponent } from './home/home.component'; + +@NgModule({ + imports: [ + CommonModule + ], + exports: [ + HomeComponent + ], + declarations: [HomeComponent] +}) +export class VendasModule { }