Skip to content

Commit bee004c

Browse files
committed
Refactoring da estrutura do app.
1 parent 8d29257 commit bee004c

File tree

70 files changed

+1285
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1285
-519
lines changed

.vscode/settings.json

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

src/app/app.module.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,32 @@ import { HttpClientModule } from '@angular/common/http';
55

66
import { AppComponent } from './app.component';
77

8-
import { CoreModule } from './core/core.module';
9-
import { UIModule } from './ui/ui.module';
8+
import { CoreModule } from './modules/core/.core.module';
9+
import { UIModule } from './modules/ui/.ui.module';
1010

1111
import { AuthenticationService } from './services/authentication.service';
1212
import { LoadingService } from './services/loading.service';
13+
import { NotFoundComponent } from './modules/ui/not-found.component';
14+
import { HomePageComponent } from './routes/home/home-page.component';
1315

1416
export const appRoutes: Routes = [
1517
{
16-
path: '',
17-
loadChildren: './routes/index/index.module#IndexModule'
18+
path: 'identity',
19+
loadChildren: './routes/identity/identity.module#IdentityModule'
1820
},
1921
{
20-
path: 'login',
21-
loadChildren: './routes/login/login.module#LoginModule'
22-
},
23-
{
24-
path: 'users',
25-
loadChildren: './routes/users/users.module#UsersModule'
26-
},
27-
{
28-
path: 'not-found',
29-
loadChildren: './routes/not-found/not-found.module#NotFoundModule'
22+
path: 'dot',
23+
loadChildren: './routes/dot/dot.module#DotModule'
3024
},
25+
{ path: '', component: HomePageComponent },
26+
{ path: 'not-found', component: NotFoundComponent },
3127
{ path: '**', redirectTo: 'not-found' }
3228
];
3329

3430
@NgModule({
3531
declarations: [
36-
AppComponent
32+
AppComponent,
33+
HomePageComponent
3734
],
3835
imports: [
3936
BrowserModule,

src/app/core/core.module.ts renamed to src/app/modules/core/.core.module.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { NgModule, LOCALE_ID, Optional, SkipSelf, ModuleWithProviders } from '@angular/core';
22
import { HTTP_INTERCEPTORS } from '@angular/common/http';
33

4-
import { AuthenticationGuardComponent } from './authentication-guard.component';
5-
import { HttpBackendInterceptorComponent } from './http-backend-interceptor.component';
6-
import { HttpBearerInterceptorComponent } from './http-bearer-interceptor.component';
7-
import { HttpLoaderInterceptorComponent } from './http-loader-interceptor.component';
4+
import { HttpBackendInterceptor } from './http-backend.interceptor';
5+
import { HttpBearerInterceptor } from './http-bearer.interceptor';
6+
import { HttpLoaderInterceptor } from './http-loader.interceptor';
7+
8+
import { AuthenticationGuard } from './authentication.guard';
89

910
@NgModule({})
1011
export class CoreModule {
@@ -21,10 +22,10 @@ export class CoreModule {
2122
// O SISTEMA VAI CARREGAR ISSO TUDO. EM TODOS OS MODULOS.
2223
providers: [
2324
{ provide: LOCALE_ID, useValue: 'pt-BR' },
24-
{ provide: HTTP_INTERCEPTORS, useClass: HttpLoaderInterceptorComponent, multi: true },
25-
{ provide: HTTP_INTERCEPTORS, useClass: HttpBearerInterceptorComponent, multi: true },
26-
{ provide: HTTP_INTERCEPTORS, useClass: HttpBackendInterceptorComponent, multi: true },
27-
AuthenticationGuardComponent,
25+
{ provide: HTTP_INTERCEPTORS, useClass: HttpLoaderInterceptor, multi: true },
26+
{ provide: HTTP_INTERCEPTORS, useClass: HttpBearerInterceptor, multi: true },
27+
{ provide: HTTP_INTERCEPTORS, useClass: HttpBackendInterceptor, multi: true },
28+
AuthenticationGuard
2829
]
2930
}
3031
}

src/app/core/authentication-guard.component.ts renamed to src/app/modules/core/authentication.guard.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Injectable } from '@angular/core';
22
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
3-
import { AuthenticationService } from '../services/authentication.service';
3+
import { AuthenticationService } from '../../services/authentication.service';
44

55
@Injectable()
6-
export class AuthenticationGuardComponent implements CanActivate {
6+
export class AuthenticationGuard implements CanActivate {
77

88
constructor(
99
private router: Router,
@@ -21,7 +21,7 @@ export class AuthenticationGuardComponent implements CanActivate {
2121
}
2222
}
2323

24-
this.router.navigate(['/login'], {
24+
this.router.navigate(['/identity'], {
2525
queryParams: {
2626
returnUrl: state.url
2727
}

src/app/core/http-backend-interceptor.component.ts renamed to src/app/modules/core/http-backend.interceptor.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { Injectable } from '@angular/core';
22
import { HttpRequest, HttpResponse, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
33
import { Observable, of, throwError } from 'rxjs';
44
import { delay, mergeMap, materialize, dematerialize } from 'rxjs/operators';
5-
import { Jwt } from '../domain/Jwt';
5+
import { Jwt } from '../../domain/jwt';
66

77
@Injectable()
8-
export class HttpBackendInterceptorComponent implements HttpInterceptor {
8+
export class HttpBackendInterceptor implements HttpInterceptor {
99
constructor() { }
1010

1111
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
12-
if (req.url.endsWith('/login') ||
12+
if (req.url.endsWith('/identity') ||
1313
req.url.endsWith('/users') ||
1414
req.url.endsWith('/error')) {
1515

1616
return of(null).pipe(mergeMap(() => {
17-
if (req.url.endsWith('/login') && req.method === 'POST') {
17+
if (req.url.endsWith('/identity') && req.method === 'POST') {
1818
var data = new Date();
1919
data.setDate(data.getDate() + 1);
2020

@@ -68,7 +68,7 @@ export class HttpBackendInterceptorComponent implements HttpInterceptor {
6868
return next.handle(req);
6969
}))
7070
.pipe(materialize())
71-
.pipe(delay(5000))
71+
.pipe(delay(500))
7272
.pipe(dematerialize());
7373
}
7474
}

src/app/core/http-bearer-interceptor.component.ts renamed to src/app/modules/core/http-bearer.interceptor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/c
33
import { Observable } from 'rxjs';
44

55
@Injectable()
6-
export class HttpBearerInterceptorComponent implements HttpInterceptor {
6+
export class HttpBearerInterceptor implements HttpInterceptor {
77
constructor() {}
88

99
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

src/app/core/http-loader-interceptor.component.ts renamed to src/app/modules/core/http-loader.interceptor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Injectable } from '@angular/core';
22
import { HttpRequest, HttpHandler, HttpInterceptor, HttpResponse } from '@angular/common/http';
33
import { tap, catchError } from 'rxjs/operators';
44

5-
import { LoadingService } from '../services/loading.service';
5+
import { LoadingService } from '../../services/loading.service';
66

77
@Injectable()
8-
export class HttpLoaderInterceptorComponent implements HttpInterceptor {
8+
export class HttpLoaderInterceptor implements HttpInterceptor {
99
private requests = 0;
1010

1111
constructor(private loadingService: LoadingService) { }

src/app/modules/ui/.ui.module.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { RouterModule } from '@angular/router';
4+
5+
import { LayoutComponent } from './layout.component';
6+
import { HeaderComponent } from './header.component';
7+
import { FooterComponent } from './footer.component';
8+
import { BreadcrumbComponent } from './breadcrumb.component';
9+
import { NotFoundComponent } from './not-found.component';
10+
11+
@NgModule({
12+
imports: [
13+
CommonModule,
14+
RouterModule
15+
],
16+
declarations: [
17+
LayoutComponent,
18+
HeaderComponent,
19+
FooterComponent,
20+
BreadcrumbComponent,
21+
NotFoundComponent
22+
],
23+
exports: [
24+
LayoutComponent,
25+
HeaderComponent,
26+
FooterComponent,
27+
BreadcrumbComponent,
28+
NotFoundComponent
29+
]
30+
})
31+
export class UIModule { }
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-breadcrumb',
5+
template: `
6+
<div class="row">
7+
<div class="col-12">
8+
<div class="page-title-box">
9+
<div class="page-title-right">
10+
<ol class="breadcrumb m-0">
11+
<li class="breadcrumb-item"><a href="javascript: void(0);">Hyper</a></li>
12+
<li class="breadcrumb-item"><a href="javascript: void(0);">Forms</a></li>
13+
<li class="breadcrumb-item active">Form Elements</li>
14+
</ol>
15+
</div>
16+
<h4 class="page-title">Form Elements</h4>
17+
</div>
18+
</div>
19+
</div>
20+
`,
21+
styles: []
22+
})
23+
export class BreadcrumbComponent {
24+
25+
constructor() { }
26+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-footer',
5+
template: `
6+
<nav class="navbar navbar-dark bg-dark mt-5 fixed-bottom">
7+
<div class="navbar-expand m-auto navbar-text">
8+
9+
</div>
10+
</nav>
11+
`,
12+
styles: []
13+
})
14+
export class FooterComponent {
15+
16+
constructor() { }
17+
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Component } from '@angular/core';
2+
import { Router } from '@angular/router';
3+
import { AuthenticationService } from '../../services/authentication.service';
4+
import { Jwt } from '../../domain/jwt';
5+
6+
@Component({
7+
selector: 'app-header',
8+
template: `
9+
10+
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-5">
11+
<a class="navbar-brand" routerLink="/">Application Bootstrap</a>
12+
13+
<div id="navbarNavDropdown" class="navbar-collapse collapse">
14+
<ul class="navbar-nav mr-auto">
15+
<ng-container *ngIf="!logged">
16+
<a class="nav-item nav-link" routerLink="/identity" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">Log In</a>
17+
</ng-container>
18+
<ng-container *ngIf="logged">
19+
<a class="nav-item nav-link" routerLink="/dot/{{ username }}" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">~/{{ username }}</a>
20+
</ng-container>
21+
</ul>
22+
<ul class="navbar-nav">
23+
<ng-container *ngIf="logged">
24+
<a class="nav-item nav-link" (click)="logout()" href="javascript:void(0)">Log Off</a>
25+
</ng-container>
26+
</ul>
27+
</div>
28+
</nav>
29+
`,
30+
styles: []
31+
})
32+
export class HeaderComponent {
33+
public logged: Boolean = false;
34+
public username: String = '';
35+
36+
constructor(
37+
private router: Router,
38+
private authenticationService: AuthenticationService) {
39+
40+
this.authenticationService.jwt
41+
.subscribe((jwt: Jwt) => {
42+
if (jwt) {
43+
this.logged = true;
44+
this.username = jwt.Username;
45+
} else {
46+
this.logged = false;
47+
this.username = '';
48+
}
49+
});
50+
}
51+
52+
logout(): void {
53+
this.authenticationService.revoke();
54+
55+
this.router.navigate(['/']);
56+
}
57+
}

src/app/ui/layout/layout.component.ts renamed to src/app/modules/ui/layout.component.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import { LoadingService } from '../../services/loading.service';
33

44
@Component({
55
selector: 'app-layout',
6-
templateUrl: './layout.component.html',
7-
styleUrls: ['./layout.component.css']
6+
template: `
7+
<ng-container *ngIf="loadingService.loading | async;">
8+
<div class="loading">Loading&#8230;</div>
9+
</ng-container>
10+
11+
<ng-content></ng-content>
12+
`,
13+
styles: []
814
})
915
export class LayoutComponent {
1016
constructor(public loadingService: LoadingService) { }
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component, ViewEncapsulation } from '@angular/core';
2+
3+
@Component({
4+
selector: 'not-found-page',
5+
template: `
6+
<app-header></app-header>
7+
<div class="container">
8+
These are not the droids you are looking for...
9+
</div>
10+
<app-footer></app-footer>
11+
`,
12+
styles: []
13+
})
14+
15+
export class NotFoundComponent {
16+
title = 'Not found';
17+
18+
constructor() { }
19+
}

src/app/routes/users/users.module.ts renamed to src/app/routes/dot/dot.module.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { NgModule } from '@angular/core';
22
import { RouterModule, Routes } from '@angular/router';
3+
import { UIModule } from '../../modules/ui/.ui.module';
34

45
export const appRoutes: Routes = [
56
{
67
path: '',
7-
loadChildren: './index/users-index.module#UsersIndexModule'
8+
loadChildren: './mine/dot-mine.module#DotMineModule'
89
},
910
{
1011
path: ':username',
11-
loadChildren: './myself/users-myself.module#UsersMyselfModule'
12+
loadChildren: './myself/dot-myself.module#DotMyselfModule'
1213
},
1314
];
1415

@@ -24,7 +25,8 @@ export const appRoutes: Routes = [
2425

2526
@NgModule({
2627
imports: [
28+
UIModule,
2729
RouterModule.forChild(appRoutes)
2830
]
2931
})
30-
export class UsersModule { }
32+
export class DotModule { }
File renamed without changes.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import { NgModule } from '@angular/core';
3+
import { RouterModule, Routes } from '@angular/router';
4+
5+
import { UIModule } from '../../../modules/ui/.ui.module';
6+
7+
import { AuthenticationGuard } from '../../../modules/core/authentication.guard';
8+
9+
import { DotMinePageComponent } from './mine-page/dot-mine-page.component';
10+
import { DotMineListComponent } from './mine-list/dot-mine-list.component';
11+
import { DotMineFormComponent } from './mine-form/dot-mine-form.component';
12+
import { DotMineFilterComponent } from './mine-filter/dot-mine-filter.component';
13+
import { DotMineEditComponent } from './mine-edit/dot-mine-edit.component';
14+
import { DotMineAddComponent } from './mine-add/dot-mine-add.component';
15+
16+
17+
const appRoutes: Routes = [
18+
{ path: '', component: DotMinePageComponent, canActivate: [AuthenticationGuard] },
19+
];
20+
21+
@NgModule({
22+
declarations: [
23+
DotMinePageComponent,
24+
DotMineListComponent,
25+
DotMineFormComponent,
26+
DotMineFilterComponent,
27+
DotMineEditComponent,
28+
DotMineAddComponent
29+
],
30+
imports: [
31+
UIModule,
32+
RouterModule.forChild(appRoutes)
33+
]
34+
})
35+
export class DotMineModule { }

0 commit comments

Comments
 (0)