Skip to content

Commit

Permalink
Control de errores, validaciones, guard
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbobbio1@gmail.com committed Nov 9, 2018
1 parent febc233 commit 77879bd
Show file tree
Hide file tree
Showing 30 changed files with 334 additions and 167 deletions.
8 changes: 3 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
//Angular
//Modules
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { PagesModule } from './pages/pages.module';
import { ServiceModule } from './services/service.module';

//Routes
import { APP_ROUTES } from './app.routes';

//Modules
import { PagesModule } from './pages/pages.module';
import { ServiceModule } from './services/service.module';

//Components
import { AppComponent } from './app.component';
import { LoginComponent } from './auth/login.component';
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Routes,RouterModule } from '@angular/router';

import { LoginComponent } from './auth/login.component';
import { RegisterComponent } from './auth/register.component';
import { NopagefoundComponent } from './shared/nopagefound/nopagefound.component';
import { NopagefoundComponent } from './components/nopagefound/nopagefound.component';

const appRoutes:Routes = [
{ path: 'login', component:LoginComponent },
Expand Down
6 changes: 4 additions & 2 deletions src/app/auth/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NgForm } from "@angular/forms";
import { UserService } from "../services/service.index";
import { User } from "../models/user.model";
import { environment } from "../../environments/environment.prod";
import { element } from "protractor";
import { Title } from "@angular/platform-browser";

declare function initPlugins();
declare const gapi: any;
Expand All @@ -19,12 +19,14 @@ export class LoginComponent implements OnInit {
remember: boolean = false;
auth2: any;

constructor(public router: Router, public _userService: UserService) {}
constructor(public router: Router, public _userService: UserService, public titlePage:Title) {}

ngOnInit() {
initPlugins();
this.googleInit();

this.titlePage.setTitle(`${environment.name} - Login`);

this.email = localStorage.getItem("email") || "";
if (this.email.length > 1) {
this.remember = true;
Expand Down
7 changes: 5 additions & 2 deletions src/app/auth/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { FormGroup, FormControl, Validators } from "@angular/forms";
import { UserService } from "../services/service.index";
import { User } from '../models/user.model';
import { Router } from '@angular/router';

import swal from 'sweetalert';
import { Title } from "@angular/platform-browser";
import { environment } from "../../environments/environment";
declare function initPlugins();

@Component({
Expand All @@ -15,9 +16,11 @@ declare function initPlugins();
export class RegisterComponent implements OnInit {
form: FormGroup;

constructor(public _userService:UserService, public router:Router) {
constructor(public _userService:UserService, public router:Router, public titlePage:Title) {
initPlugins();

this.titlePage.setTitle(`${environment.name} - Register`);

this.form = new FormGroup(
{
name: new FormControl(null, Validators.required),
Expand Down
53 changes: 53 additions & 0 deletions src/app/components/components.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//Modules
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';

//Graphics Angular
import { ChartsModule } from 'ng2-charts';

//Components
import { NopagefoundComponent } from '../components/nopagefound/nopagefound.component';
import { HeaderComponent } from '../components/header/header.component';
import { SidebarComponent } from '../components/sidebar/sidebar.component';
import { BreadcumbsComponent } from '../components/breadcumbs/breadcumbs.component';
import { IncrementorComponent } from '../components/incrementor/incrementor.component';
import { ModalUploadComponent } from '../components/modal-upload/modal-upload.component';
import { GraphicDonutComponent } from '../components/graphic-donut/graphic-donut.component';
import { GraphicBarComponent } from '../components/graphic-bar/graphic-bar.component';
import { PipesModule } from '../pipes/pipes.module';

@NgModule({
imports:[
RouterModule,
CommonModule,
PipesModule,
FormsModule,
ChartsModule
],
declarations:[
NopagefoundComponent,
HeaderComponent,
SidebarComponent,
BreadcumbsComponent,
IncrementorComponent,
ModalUploadComponent,
GraphicDonutComponent,
GraphicBarComponent,
],
exports:[
NopagefoundComponent,
HeaderComponent,
SidebarComponent,
BreadcumbsComponent,
IncrementorComponent,
ModalUploadComponent,
GraphicDonutComponent,
GraphicBarComponent,
]
})

export class ComponentsModule{

}
5 changes: 5 additions & 0 deletions src/app/components/graphic-bar/graphic-bar.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h4>{{title}}</h4>

<div style="display:block">
<canvas baseChart [datasets]="barChartData" [labels]="barChartLabels" chartType="bar"></canvas>
</div>
19 changes: 19 additions & 0 deletions src/app/components/graphic-bar/graphic-bar.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, OnInit, Input } from '@angular/core';

@Component({
selector: 'app-graphic-bar',
templateUrl: './graphic-bar.component.html',
styles: []
})
export class GraphicBarComponent implements OnInit {

@Input('chartLabels') barChartLabels:string[] = [];
@Input('chartData') barChartData:number[] = [];
@Input() title:string;

constructor() { }

ngOnInit() {
}

}
Original file line number Diff line number Diff line change
@@ -1,51 +1,27 @@
<header class="topbar">
<nav class="navbar top-navbar navbar-expand-md navbar-light">
<!-- ============================================================== -->
<!-- Logo -->
<!-- ============================================================== -->
<div class="navbar-header">
<a class="navbar-brand" href="index.html">
<!-- Logo icon --><b>
<!--You can put here icon as well // <i class="wi wi-sunset"></i> //-->
<!-- Dark Logo icon -->
<b>
<img src="assets/images/logo-icon.png" alt="homepage" class="dark-logo" />
<!-- Light Logo icon -->
<img src="assets/images/logo-light-icon.png" alt="homepage" class="light-logo" />
</b>
<!--End Logo icon -->
<!-- Logo text --><span>
<!-- dark Logo text -->
<span>
<img src="assets/images/logo-text.png" alt="homepage" class="dark-logo" />
<!-- Light Logo text -->
<img src="assets/images/logo-light-text.png" class="light-logo" alt="homepage" /></span> </a>
</div>
<!-- ============================================================== -->
<!-- End Logo -->
<!-- ============================================================== -->
<div class="navbar-collapse">
<!-- ============================================================== -->
<!-- toggle and nav items -->
<!-- ============================================================== -->
<ul class="navbar-nav mr-auto">
<!-- This is -->
<li class="nav-item"> <a class="nav-link nav-toggler hidden-md-up waves-effect waves-dark" href="javascript:void(0)"><i class="ti-menu"></i></a> </li>
<li class="nav-item"> <a class="nav-link sidebartoggler hidden-sm-down waves-effect waves-dark" href="javascript:void(0)"><i class="ti-menu"></i></a> </li>
<li class="nav-item hidden-sm-down"></li>
</ul>
<!-- ============================================================== -->
<!-- User profile and search -->
<!-- ============================================================== -->
<ul class="navbar-nav my-lg-0">
<!-- ============================================================== -->
<!-- Search -->
<!-- ============================================================== -->
<li class="nav-item hidden-xs-down search-box"> <a class="nav-link hidden-sm-down waves-effect waves-dark" href="javascript:void(0)"><i class="ti-search"></i></a>
<form class="app-search">
<input type="text" class="form-control" placeholder="Search & enter"> <a class="srh-btn"><i class="ti-close"></i></a> </form>
<div class="app-search">
<input #input (keyup.enter)="search(input.value)" type="text" class="form-control" placeholder="Search and Enter"> <a class="srh-btn"><i class="ti-close"></i></a>
</div>
</li>
<!-- ============================================================== -->
<!-- Messages -->
<!-- ============================================================== -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle waves-effect waves-dark" href="" id="2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="mdi mdi-email"></i>
<div class="notify"> <span class="heartbit"></span> <span class="point"></span> </div>
Expand All @@ -57,25 +33,21 @@
</li>
<li>
<div class="message-center">
<!-- Message -->
<a href="#">
<div class="user-img"> <img src="assets/images/users/1.jpg" alt="user" class="img-circle"> <span class="profile-status online pull-right"></span> </div>
<div class="mail-contnet">
<h5>Pavan kumar</h5> <span class="mail-desc">Just see the my admin!</span> <span class="time">9:30 AM</span> </div>
</a>
<!-- Message -->
<a href="#">
<div class="user-img"> <img src="assets/images/users/2.jpg" alt="user" class="img-circle"> <span class="profile-status busy pull-right"></span> </div>
<div class="mail-contnet">
<h5>Sonu Nigam</h5> <span class="mail-desc">I've sung a song! See you at</span> <span class="time">9:10 AM</span> </div>
</a>
<!-- Message -->
<a href="#">
<div class="user-img"> <img src="assets/images/users/3.jpg" alt="user" class="img-circle"> <span class="profile-status away pull-right"></span> </div>
<div class="mail-contnet">
<h5>Arijit Sinh</h5> <span class="mail-desc">I am a singer!</span> <span class="time">9:08 AM</span> </div>
</a>
<!-- Message -->
<a href="#">
<div class="user-img"> <img src="assets/images/users/4.jpg" alt="user" class="img-circle"> <span class="profile-status offline pull-right"></span> </div>
<div class="mail-contnet">
Expand All @@ -89,12 +61,6 @@ <h5>Pavan kumar</h5> <span class="mail-desc">Just see the my admin!</span> <span
</ul>
</div>
</li>
<!-- ============================================================== -->
<!-- End Messages -->
<!-- ============================================================== -->
<!-- ============================================================== -->
<!-- Profile -->
<!-- ============================================================== -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle waves-effect waves-dark" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img src="{{ user.img | image }}" alt="user" class="profile-pic" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { UserService } from '../../services/service.index';
import { User } from '../../models/user.model';
import { Router } from '@angular/router';

@Component({
selector: 'app-header',
Expand All @@ -11,10 +12,14 @@ export class HeaderComponent implements OnInit {

user:User

constructor(public _userService:UserService) { }
constructor(public _userService:UserService, public router:Router) { }

ngOnInit() {
this.user = this._userService.user;
}

search(term:string){
this.router.navigate(['/search',term])
}

}
18 changes: 18 additions & 0 deletions src/app/components/nopagefound/nopagefound.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.error-box {
height: 100%;
position: fixed;
background: url(../../../assets/images/background/error-bg.jpg) no-repeat center center #fff;
width: 100%; }
.error-box .footer {
width: 100%;
left: 0px;
right: 0px; }

.error-body {
padding-top: 5%; }
.error-body h1 {
font-size: 210px;
font-weight: 900;
text-shadow: 4px 4px 0 #ffffff, 6px 6px 0 #263238;
line-height: 210px; }

10 changes: 10 additions & 0 deletions src/app/components/nopagefound/nopagefound.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<section id="wrapper" class="error-page">
<div class="error-box">
<div class="error-body text-center">
<h1>404</h1>
<h3 class="text-uppercase">Page Not Found !</h3>
<p class="text-muted m-t-30 m-b-30">Do you find a mouse</p>
<a routerLink="/login" class="btn btn-info btn-rounded waves-effect waves-light m-b-40">Back to Login</a> </div>
<footer class="footer text-center">© {{year}} Admin Pro.</footer>
</div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ declare function initPlugins();
@Component({
selector: 'app-nopagefound',
templateUrl: './nopagefound.component.html',
styles: []
styleUrls: ["./nopagefound.component.css"]
})
export class NopagefoundComponent implements OnInit {

year:number = new Date().getFullYear();

constructor() { }

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SidebarComponent implements OnInit {

ngOnInit() {
this.user = this._userService.user;
this._sidebarService.getMenu();
}

}
18 changes: 18 additions & 0 deletions src/app/guards/admin.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { UserService } from '../services/user/user.service';

@Injectable()
export class AdminGuard implements CanActivate {

constructor(public _userService:UserService, public router:Router){}

canActivate(){

if(this._userService.user.role === 'ADMIN_ROLE') return true;
else{
this._userService.logout();
return false;
}
}
}
4 changes: 2 additions & 2 deletions src/app/pages/graphic/graphic.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<div class="col-6">
<div class="card">
<div class="card-body">
<app-graphic-donut [chartLabels]="graficos.grafico3.labels" [chartData]="graficos.grafico3.data" [title]="graficos.grafico3.leyenda"></app-graphic-donut>
<app-graphic-bar [chartLabels]="graficos.grafico3.labels" [chartData]="graficos.grafico3.data" [title]="graficos.grafico3.leyenda"></app-graphic-bar>
</div>
</div>
</div>

<div class="col-6">
<div class="card">
<div class="card-body">
<app-graphic-donut [chartLabels]="graficos.grafico4.labels" [chartData]="graficos.grafico4.data" [title]="graficos.grafico4.leyenda"></app-graphic-donut>
<app-graphic-bar [chartLabels]="graficos.grafico4.labels" [chartData]="graficos.grafico4.data" [title]="graficos.grafico4.leyenda"></app-graphic-bar>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 77879bd

Please sign in to comment.