.
+-- 📁 app
| +-- 📁 classes
| +-- 📜 auth.ts
| +-- 📁 interceptors
| +-- 📜 credential.interceptor.ts
| +-- 📁 interfaces
| +-- 📜 order-item.ts
| +-- 📜 order.ts
| +-- 📜 permission.ts
| +-- 📜 product.ts
| +-- 📜 role.ts
| +-- 📜 user.ts
| +-- 📁 public
| +-- 📁 login
| +-- 📜 login.component.html
| +-- 📜 login.component.ts
| +-- 📁 register
| +-- 📜 register.component.html
| +-- 📜 register.component.ts
| +-- 📜 public.component.html
| +-- 📜 public.component.scss
| +-- 📜 public.component.ts
| +-- 📜 public.module.ts
| +-- 📁 secure
| +-- 📁 components
| +-- 📁 paginator
| +-- 📜 paginator.component.html
| +-- 📜 paginator.component.scss
| +-- 📜 paginator.component.ts
| +-- 📁 upload
| +-- 📜 upload.component.html
| +-- 📜 upload.component.scss
| +-- 📜 upload.component.ts
| +-- 📁 dashboard
| +-- 📜 dashboard.component.html
| +-- 📜 dashboard.component.scss
| +-- 📜 dashboard.component.ts
| +-- 📁 menu
| +-- 📜 menu.component.html
| +-- 📜 menu.component.ts
| +-- 📁 nav
| +-- 📜 nav.component.html
| +-- 📜 nav.component.ts
| +-- 📁 orders
| +-- 📜 orders.component.html
| +-- 📜 orders.component.scss
| +-- 📜 orders.component.ts
| +-- 📁 products
| +-- 📁 product-create
| +-- 📜 product-create.component.html
| +-- 📜 product-create.component.scss
| +-- 📜 product-create.component.ts
| +-- 📁 product-edit
| +-- 📜 product-edit.component.html
| +-- 📜 product-edit.component.scss
| +-- 📜 product-edit.component.ts
| +-- 📜 products.component.html
| +-- 📜 products.component.scss
| +-- 📜 products.component.ts
| +-- 📁 profile
| +-- 📜 profile.component.html
| +-- 📜 profile.component.scss
| +-- 📜 profile.component.ts
| +-- 📁 roles
| +-- 📁 role-create
| +-- 📜 role-create.component.html
| +-- 📜 role-create.component.scss
| +-- 📜 role-create.component.ts
| +-- 📁 role-edit
| +-- 📜 role-edit.component.html
| +-- 📜 role-edit.component.scss
| +-- 📜 role-edit.component.ts
| +-- 📜 roles.component.html
| +-- 📜 roles.component.scss
| +-- 📜 roles.component.ts
| +-- 📁 users
| +-- 📁 user-create
| +-- 📜 user-create.component.html
| +-- 📜 user-create.component.scss
| +-- 📜 user-create.component.ts
| +-- 📁 user-edit
| +-- 📜 user-edit.component.html
| +-- 📜 user-edit.component.scss
| +-- 📜 user-edit.component.ts
| +-- 📜 users.component.html
| +-- 📜 users.component.scss
| +-- 📜 users.component.ts
| +-- 📜 secure.component.html
| +-- 📜 secure.component.ts
| +-- 📜 secure.module.ts
| +-- 📁 services
| +-- 📜 auth.service.ts
| +-- 📜 order.service.ts
| +-- 📜 permission.sevice.ts
| +-- 📜 product.service.ts
| +-- 📜 rest.service.ts
| +-- 📜 role.service.ts
| +-- 📜 user.service.ts
| +-- 📜 app-routing.module.ts
| +-- 📜 app.component.html
| +-- 📜 app.component.ts
| +-- 📜 app.module.ts
+-- 📁 environments
| +-- 📜 environment.ts
+-- 📜 angular.json
{
"angular-admin" : {
"projectType" : " application" ,
"schematics" : {
"@schematics/angular:component" : {
"style" : " scss" ,
"skipTests" : true , // 😅
"inlineTemplate" : false ,
"inlineStyle" : false ,
},
"@schematics/angular:module" : {
"skipTests" : true
},
"@schematics/angular:service" : {
"skipTests" : true
}
}
},
"prefix" : " app" , // prefix for components..
}
event emitted in secure.component.ts
subscribed in profile.component.ts
import { EventEmitter } from "@angular/core" ;
import { User } from "../interfaces/user" ;
export class Auth {
static userEmitter = new EventEmitter < User > ( ) ;
}
adding withCredentials: true
to each http request
needs to be set in app.module.ts - providers
interceptors/credential.interceptor.ts
import { Injectable } from '@angular/core' ;
import {
HttpRequest ,
HttpHandler ,
HttpEvent ,
HttpInterceptor
} from '@angular/common/http' ;
import { Observable } from 'rxjs' ;
@Injectable ( )
export class CredentialInterceptor implements HttpInterceptor {
constructor ( ) { }
intercept ( request : HttpRequest < unknown > , next : HttpHandler ) : Observable < HttpEvent < unknown >> {
const req = request . clone ( {
withCredentials : true
} ) ;
return next . handle ( req ) ;
}
}
export interface OrderItem {
id: number ;
product_title: string ;
price: number ;
quantity: number ;
}
import { OrderItem } from "./order-item" ;
export interface Order {
id : number ;
name: string ;
email: string ;
total: number ;
order_items: OrderItem [ ] ;
}
export interface Permission {
id: number ;
name: string ;
}
export interface Product {
id: number ;
title: string ;
description: string ;
image: string ;
price: number ;
}
import { Permission } from "./permission" ;
export interface Role {
id : number ;
name: string ;
permissions ?: Permission [ ] ;
}
import { Role } from "./role" ;
export interface User {
id : number ;
first_name: string ;
last_name: string ;
email: string ;
role: Role ;
}
public/login/login.component.html
< main class ="form-signin ">
< form
(submit) ="submit() "
[formGroup] ="form " >
< h1 class ="h3 mb-3 fw-normal ">
Please signin
</ h1 >
< input
formControlName ="email "
name ="email "
type ="email "
class ="form-control "
placeholder ="Email "
required >
< input
formControlName ="password "
name ="password "
type ="password "
class ="form-control "
placeholder ="Password "
required >
< button
class ="w-100 btn btn-lg btn-primary "
type ="submit " >
Submit
</ button >
</ form >
</ main >
public/login/login.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormBuilder , FormGroup } from '@angular/forms' ;
import { Router } from '@angular/router' ;
import { AuthService } from 'src/app/services/auth.service' ;
@Component ( {
selector : 'app-login' ,
templateUrl : './login.component.html' ,
styleUrls : [ '../public.component.scss' ]
} )
export class LoginComponent implements OnInit {
form ! : FormGroup ;
constructor (
private formBuilder : FormBuilder ,
private router : Router ,
private authService : AuthService
) { }
ngOnInit ( ) : void {
this . form = this . formBuilder . group ( {
email : '' ,
password : ''
} )
}
submit ( ) {
this . authService . login ( this . form . getRawValue ( ) )
. subscribe ( ( ) => {
this . router . navigate ( [ '/' ] )
} )
}
}
public/register/register.component.html
< main class ="form-signin ">
< form
(submit) ="submit() " >
< h1 class ="h3 mb-3 fw-normal ">
Please register
</ h1 >
< input
[(ngModel)] ="firstName "
name ="first_name "
type ="text "
class ="form-control "
placeholder ="First Name "
required >
< input
[(ngModel)] ="lastName "
name ="last_name "
type ="text "
class ="form-control "
placeholder ="Last Name "
required >
< input
[(ngModel)] ="email "
name ="email "
type ="email "
class ="form-control "
placeholder ="Email "
required >
< input
[(ngModel)] ="password "
name ="password "
type ="password "
class ="form-control "
placeholder ="Password "
required >
< input
[(ngModel)] ="passwordConfirm "
name ="password_confirm "
type ="password "
class ="form-control "
placeholder ="Confirm Password "
required >
< button
class ="w-100 btn btn-lg btn-primary "
type ="submit " >
Submit
</ button >
</ form >
</ main >
public/register/register.component.ts
import { Component } from '@angular/core' ;
import { Router } from '@angular/router' ;
import { AuthService } from 'src/app/services/auth.service' ;
@Component ( {
selector : 'app-register' ,
templateUrl : './register.component.html' ,
styleUrls : [ '../public.component.scss' ]
} )
export class RegisterComponent {
firstName = '' ;
lastName = '' ;
email = '' ;
password = '' ;
passwordConfirm = '' ;
constructor (
private router : Router ,
private authService : AuthService
) { }
submit ( ) : void {
this . authService . register ( {
first_name : this . firstName ,
last_name : this . lastName ,
email : this . email ,
password : this . password ,
password_confirm : this . passwordConfirm ,
} )
. subscribe ( ( ) => this . router . navigate ( [ '/login' ] ) )
}
}
public/public.component.html
< router-outlet > </ router-outlet >
public/public.component.scss
html ,
body {
height : 100% ;
}
body {
display : flex ;
align-items : center ;
padding-top : 40px ;
padding-bottom : 40px ;
background-color : #f5f5f5 ;
}
.form-signin {
width : 100% ;
max-width : 330px ;
padding : 15px ;
margin : auto ;
}
.form-signin .checkbox {
font-weight : 400 ;
}
.form-signin .form-floating :focus-within {
z-index : 2 ;
}
.form-signin input [type = " email" ] {
margin-bottom : -1px ;
border-bottom-right-radius : 0 ;
border-bottom-left-radius : 0 ;
}
.form-signin input [type = " password" ] {
margin-bottom : 10px ;
border-top-left-radius : 0 ;
border-top-right-radius : 0 ;
}
public/public.component.ts
import { Component } from '@angular/core' ;
@Component ( {
selector : 'app-public' ,
templateUrl : './public.component.html' ,
styleUrls : [ ]
} )
export class PublicComponent { }
import { NgModule } from '@angular/core' ;
import { CommonModule } from '@angular/common' ;
import { PublicComponent } from './public.component' ;
import { LoginComponent } from './login/login.component' ;
import { RegisterComponent } from './register/register.component' ;
import { RouterModule } from '@angular/router' ;
import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
import { HttpClientModule } from '@angular/common/http' ;
@NgModule ( {
declarations : [
PublicComponent ,
LoginComponent ,
RegisterComponent
] ,
imports : [
CommonModule ,
RouterModule ,
FormsModule ,
HttpClientModule ,
ReactiveFormsModule
]
} )
export class PublicModule { }
Reusable Components | Paginator
secure/components/paginator/paginator.component.html
< nav >
< ul class ="pagination ">
< li class ="page-item ">
< span
(click) ="prev() "
class ="page-link " >
Previous
</ span >
</ li >
< li class ="page-item ">
< span
(click) ="next() "
class ="page-link " >
Next
</ span >
</ li >
</ ul >
</ nav >
secure/components/paginator/paginator.component.scss
.page-link {
cursor : pointer ;
}
secure/components/paginator/paginator.component.ts
import { Component , Input , Output , EventEmitter } from '@angular/core' ;
@Component ( {
selector : 'app-paginator' ,
templateUrl : './paginator.component.html' ,
styleUrls : [ './paginator.component.scss' ]
} )
export class PaginatorComponent {
page = 1 ;
@Input ( ) lastPage ! : number ;
@Output ( ) pageChanged = new EventEmitter < number > ( ) ;
next ( ) : void {
if ( this . page === this . lastPage ) return ;
this . page ++ ;
this . pageChanged . emit ( this . page ) ;
}
prev ( ) : void {
if ( this . page === 1 ) return ;
this . page -- ;
this . pageChanged . emit ( this . page ) ;
}
}
Reusable Components | Upload
secure/components/upload/upload.component.html
< label
class ="btn btn-primary ">
Upload
< input
(change) ="upload($any($event.target).files) "
type ="file "
name ="file "
hidden >
</ label >
secure/components/upload/upload.component.ts
import { HttpClient } from '@angular/common/http' ;
import { Component , EventEmitter , Output } from '@angular/core' ;
import { environment } from 'src/environments/environment' ;
@Component ( {
selector : 'app-upload' ,
templateUrl : './upload.component.html' ,
styleUrls : [ './upload.component.scss' ]
} )
export class UploadComponent {
@Output ( ) uploaded = new EventEmitter < string > ( ) ;
constructor (
private http : HttpClient
) { }
upload ( files ?: FileList | null ) : void {
const file = files ?. item ( 0 ) ;
if ( ! file ) return ;
const data = new FormData ( ) ;
data . append ( 'image' , file ) ;
this . http . post ( `${ environment . api } /upload` , data )
. subscribe (
( res : any ) => this . uploaded . emit ( res . url )
)
}
}
secure/dahsboard/dashboard.component.ts
< h2 > Daily Sales</ h2 >
< div id ="chart "> </ div >
secure/dahsboard/dashboard.component.ts
import { Component , OnInit } from '@angular/core' ;
import * as c3 from 'c3' ;
import { OrderService } from 'src/app/services/order.service' ;
@Component ( {
selector : 'app-dashboard' ,
templateUrl : './dashboard.component.html' ,
styleUrls : [ './dashboard.component.scss' ]
} )
export class DashboardComponent implements OnInit {
constructor (
private orderService : OrderService
) { }
ngOnInit ( ) : void {
let chart = c3 . generate ( {
bindto : '#chart' ,
data : {
x : 'x' ,
columns : [
[ 'x' ] ,
[ 'Sales' ]
] ,
types : {
Sales : 'bar'
}
} ,
axis : {
x : {
type : 'timeseries' ,
tick : {
format : '%Y-%m-%d'
}
}
}
} ) ;
this . orderService . chart ( )
. subscribe (
( res : { date : string , sum : number } [ ] ) => {
chart . load ( {
columns : [
[ 'x' , ...res . map ( r => r . date ) ] ,
[ 'Sales' , ...res . map ( r => r . sum ) ]
]
} )
}
)
}
}
Menu
secure/menu/menu.component.html
< nav id = "sidebarMenu" class = "col-md-3 col-lg-2 d-md-block bg-light sidebar collapse" >
< div class = "position-sticky pt-3" >
< ul class = "nav flex-column" >
< li class = "nav-item" >
< a
routerLink = "/dashboard"
routerLinkActive = "active"
class = "nav-link" >
< span data-feather = "home" > </ span >
Dashboard
</ a >
</ li >
< li class = "nav-item" >
< a
routerLink = "users"
routerLinkActive = "active"
class = "nav-link" >
< span data-feather = "home" > </ span >
Users
</ a >
</ li >
< li class = "nav-item" >
< a
routerLink = "roles"
routerLinkActive = "active"
class = "nav-link" >
< span data-feather = "home" > </ span >
Roles
</ a >
</ li >
< li class = "nav-item" >
< a
routerLink = "products"
routerLinkActive = "active"
class = "nav-link" >
< span data-feather = "home" > </ span >
Products
</ a >
</ li >
< li class = "nav-item" >
< a
routerLink = "orders"
routerLinkActive = "active"
class = "nav-link" >
< span data-feather = "home" > </ span >
Orders
</ a >
</ li >
</ ul >
</ div >
</ nav >
secure/menu/menu.component.ts
import { Component } from '@angular/core' ;
@Component ( {
selector : 'app-menu' ,
templateUrl : './menu.component.html' ,
styles : [
]
} )
export class MenuComponent { }
secure/nav/nav.component.html
< header class ="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow ">
< a
class ="navbar-brand col-md-3 col-lg-2 me-0 px-3 "
routerLink ="/ " >
Company name
</ a >
< nav class ="my-w my-md-0 mr-md-3 ">
< a
routerLink ="/login "
class ="p-2 text-white text-decoration-none "
(click) ="logout() " >
Sign Out
</ a >
< a
routerLink ="/profile "
class ="p-2 text-white text-decoration-none " >
{{user?.first_name}}
{{user?.last_name}}
</ a >
</ nav >
</ header >
secure/nav/nav.component.ts
import { Component , Input , OnInit } from '@angular/core' ;
import { Auth } from 'src/app/classes/auth' ;
import { User } from 'src/app/interfaces/user' ;
import { AuthService } from 'src/app/services/auth.service' ;
@Component ( {
selector : 'app-nav' ,
templateUrl : './nav.component.html' ,
styles : [
]
} )
export class NavComponent implements OnInit {
user ! : User ;
constructor (
private authService : AuthService
) { }
ngOnInit ( ) : void {
Auth . userEmitter . subscribe (
user => this . user = user
)
}
logout ( ) : void {
this . authService . logout ( ) . subscribe ( ( ) => console . log ( 'Logged out..' ) )
}
}
secure/orders/orders.component.html
< div class ="pt-3 pb-2 mb-3 border-bottom ">
< button
(click) ="export() "
class ="btn btn-sm btn-outline-secondary ">
Export CSV
</ button >
</ div >
< div class ="table-responsive ">
< table class ="table table-striped table-sm ">
< thead >
< tr >
< th > #</ th >
< th > Name</ th >
< th > Email</ th >
< th > Total</ th >
< th > Action</ th >
</ tr >
</ thead >
< tbody >
< ng-container
*ngFor ="let order of orders " >
< tr >
< td > {{order.id}}</ td >
< td > {{order.name}}</ td >
< td > {{order.email}}</ td >
< td > {{order.total | currency:"€"}}</ td >
< td >
< button
(click) ="select(order.id) "
class ="btn btn-sm btn-outline-secondary ">
View
</ button >
</ td >
</ tr >
< tr >
< td colspan ="5 ">
< div
[@tableState] ="itemState(order.id) "
class ="overflow-hidden " >
< table class ="table table-striped table-sm ">
< thead >
< tr >
< th > #</ th >
< th > Product</ th >
< th > Qty</ th >
< th > Price</ th >
</ tr >
</ thead >
< tbody >
< tr
*ngFor ="let item of order.order_items " >
< td > {{item.id}}</ td >
< td > {{item.product_title}}</ td >
< td > {{item.quantity}}</ td >
< td > {{item.price}}</ td >
</ tr >
</ tbody >
</ table >
</ div >
</ td >
</ tr >
</ ng-container >
</ tbody >
</ table >
</ div >
< app-paginator
[lastPage] ="lastPage "
(pageChanged) ="load($event) " >
</ app-paginator >
secure/orders/orders.component.ts
import { animate , state , style , transition , trigger } from '@angular/animations' ;
import { Component , OnInit } from '@angular/core' ;
import { Order } from 'src/app/interfaces/order' ;
import { OrderService } from 'src/app/services/order.service' ;
@Component ( {
selector : 'app-orders' ,
templateUrl : './orders.component.html' ,
styleUrls : [ './orders.component.scss' ] ,
animations : [
trigger ( 'tableState' , [
state ( 'show' , style ( {
maxHeight : '150px'
} ) ) ,
state ( 'hide' , style ( {
maxHeight : '0'
} ) ) ,
transition ( 'show => hide' , animate ( '500ms ease-in' ) ) ,
transition ( 'hide => show' , animate ( '500ms ease-out' ) ) ,
] )
]
} )
export class OrdersComponent implements OnInit {
orders ! : Order [ ] ;
lastPage ! : number ;
selected ! : number ;
constructor (
private orderService : OrderService
) { }
ngOnInit ( ) : void {
this . load ( ) ;
}
load ( page : number = 1 ) : void {
this . orderService . all ( page )
. subscribe (
res => {
this . orders = res . data ;
this . lastPage = res . meta . last_page ;
}
)
}
select ( id : number ) : void {
this . selected = this . selected === id ? 0 : id ;
}
itemState ( id : number ) : string {
return this . selected === id ? 'show' : 'hide' ;
}
export ( ) : void {
this . orderService . export ( )
. subscribe (
res => {
const blob = new Blob ( [ res ] , { type : 'text/csv' } ) ;
const downloadUrl = window . URL . createObjectURL ( res ) ;
const link = document . createElement ( 'a' ) ;
link . href = downloadUrl ;
link . download = 'orders.csv' ;
link . click ( ) ;
}
)
}
}
Products | Product - Create
secure/products/product-create/product-create.component.html
< form
(submit) ="submit() "
[formGroup] ="form " >
< div class ="mb-3 ">
< label > Title</ label >
< input
formControlName ="title "
name ="title "
type ="text "
class ="form-control "
placeholder ="Product Title "
required >
</ div >
< div class ="mb-3 ">
< label > Description</ label >
< textarea
formControlName ="description "
name ="description "
type ="text "
class ="form-control "
required >
</ textarea >
</ div >
< div class ="mb-3 ">
< label > Image</ label >
< div class ="input-group ">
< input
formControlName ="image "
name ="image "
type ="text "
class ="form-control "
placeholder ="Image Link "
required >
< app-upload
(uploaded) ="form.patchValue({image: $event}) " >
</ app-upload >
</ div >
</ div >
< div class ="mb-3 ">
< label > Price</ label >
< input
formControlName ="price "
name ="price "
type ="number "
class ="form-control "
placeholder ="Price "
required >
</ div >
< button
class ="btn btn-outline-secondary "
type ="submit " >
Submit
</ button >
</ form >
secure/products/product-create/product-create.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormBuilder , FormGroup } from '@angular/forms' ;
import { Router } from '@angular/router' ;
import { ProductService } from 'src/app/services/product.service' ;
@Component ( {
selector : 'app-product-create' ,
templateUrl : './product-create.component.html' ,
styleUrls : [ './product-create.component.scss' ]
} )
export class ProductCreateComponent implements OnInit {
form ! : FormGroup
constructor (
private formBuilder : FormBuilder ,
private productService : ProductService ,
private router : Router
) { }
ngOnInit ( ) : void {
this . form = this . formBuilder . group ( {
title : '' ,
description : '' ,
image : '' ,
price : 0
} ) ;
}
submit ( ) {
this . productService . create ( this . form . getRawValue ( ) )
. subscribe (
( ) => this . router . navigate ( [ '/products' ] )
)
}
}
secure/products/product-edit/product-edit.component.html
< form
(submit) ="submit() "
[formGroup] ="form " >
< div class ="mb-3 ">
< label > Title</ label >
< input
formControlName ="title "
name ="title "
type ="text "
class ="form-control "
placeholder ="Product Title "
required >
</ div >
< div class ="mb-3 ">
< label > Description</ label >
< textarea
formControlName ="description "
name ="description "
type ="text "
class ="form-control "
required >
</ textarea >
</ div >
< div class ="mb-3 ">
< label > Image</ label >
< div class ="input-group ">
< input
formControlName ="image "
name ="image "
type ="text "
class ="form-control "
placeholder ="Image Link "
required >
< app-upload
(uploaded) ="form.patchValue({image: $event}) " >
</ app-upload >
</ div >
</ div >
< div class ="mb-3 ">
< label > Price</ label >
< input
formControlName ="price "
name ="price "
type ="number "
class ="form-control "
placeholder ="Price "
required >
</ div >
< button
class ="btn btn-outline-secondary "
type ="submit " >
Submit
</ button >
</ form >
secure/products/product-edit/product-edit.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormBuilder , FormGroup } from '@angular/forms' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { ProductService } from 'src/app/services/product.service' ;
@Component ( {
selector : 'app-product-edit' ,
templateUrl : './product-edit.component.html' ,
styleUrls : [ './product-edit.component.scss' ]
} )
export class ProductEditComponent implements OnInit {
form ! : FormGroup
id ! : number ;
constructor (
private formBuilder : FormBuilder ,
private productService : ProductService ,
private router : Router ,
private route : ActivatedRoute
) { }
ngOnInit ( ) : void {
this . form = this . formBuilder . group ( {
title : '' ,
description : '' ,
image : '' ,
price : 0
} ) ;
this . id = this . route . snapshot . params . id ;
this . productService . get ( this . id )
. subscribe (
product => this . form . patchValue ( {
title : product . title ,
description : product . description ,
image : product . image ,
price : product . price
} )
)
}
submit ( ) {
this . productService . update ( this . id , this . form . getRawValue ( ) )
. subscribe (
( ) => this . router . navigate ( [ '/products' ] )
)
}
}
secure/products/products.component.html
< div class ="pt-3 pb-2 mb-3 border-bottom ">
< a
routerLink ="/products/create "
class ="btn btn-sm btn-outline-secondary ">
Add Product
</ a >
</ div >
< div class ="table-responsive ">
< table class ="table table-striped table-sm ">
< thead >
< tr >
< th > #</ th >
< th > Image</ th >
< th > Title</ th >
< th > Description</ th >
< th > Price</ th >
< th > Action</ th >
</ tr >
</ thead >
< tbody >
< tr *ngFor ="let product of products ">
< td > {{product.id}}</ td >
< td >
< img
[src] ="product.image "
[alt] ="product.title "
height ="50 " />
</ td >
< td > {{product.title}}</ td >
< td > {{product.description}}</ td >
< td > {{product.price | currency:"€"}}</ td >
< td >
< a
[routerLink] ="['/products', product.id, 'edit'] "
class ="btn btn-sm btn-outline-secondary ">
Edit
</ a >
< button
(click) ="delete(product.id) "
class ="btn btn-sm btn-outline-secondary ">
Delete
</ button >
</ td >
</ tr >
</ tbody >
</ table >
</ div >
< app-paginator
[lastPage] ="lastPage "
(pageChanged) ="load($event) " >
</ app-paginator >
secure/products/products.component.ts
import { Component , OnInit } from '@angular/core' ;
import { Product } from 'src/app/interfaces/product' ;
import { ProductService } from 'src/app/services/product.service' ;
@Component ( {
selector : 'app-products' ,
templateUrl : './products.component.html' ,
styleUrls : [ './products.component.scss' ]
} )
export class ProductsComponent implements OnInit {
products ! : Product [ ] ;
lastPage ! : number ;
constructor (
private productService : ProductService
) { }
ngOnInit ( ) : void {
this . load ( ) ;
}
load ( page : number = 1 ) : void {
this . productService . all ( page )
. subscribe (
( res : any ) => {
this . products = res . data ;
this . lastPage = res . meta . last_page ;
}
)
}
delete ( id : number ) : void {
if ( confirm ( 'Are you sure you want to delete?' ) ) {
this . productService . delete ( id ) . subscribe (
( ) => {
this . products = this . products . filter ( p => p . id !== id ) ;
}
)
}
}
}
secure/profile/profile.component.html
< h3 > Account Info</ h3 >
< form
(submit) ="updateInfo() "
[formGroup] ="infoForm " >
< input
formControlName ="first_name "
name ="first_name "
type ="text "
class ="form-control "
placeholder ="First Name "
required >
< input
formControlName ="last_name "
name ="last_name "
type ="text "
class ="form-control "
placeholder ="Last Name "
required >
< input
formControlName ="email "
name ="email "
type ="email "
class ="form-control "
placeholder ="Email "
required >
< button
class ="w-100 btn btn-lg btn-primary "
type ="submit " >
Save
</ button >
</ form >
< form
(submit) ="updatePass() "
[formGroup] ="passForm " >
< input
formControlName ="password "
name ="password "
type ="password "
class ="form-control "
placeholder ="Password "
required >
< input
formControlName ="password_confirm "
name ="password_confirm "
type ="password "
class ="form-control "
placeholder ="Confirm Password "
required >
< button
class ="w-100 btn btn-lg btn-primary "
type ="submit " >
Save
</ button >
</ form >
secure/profile/profile.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormBuilder , FormGroup } from '@angular/forms' ;
import { Auth } from 'src/app/classes/auth' ;
import { AuthService } from 'src/app/services/auth.service' ;
@Component ( {
selector : 'app-profile' ,
templateUrl : './profile.component.html' ,
styleUrls : [ './profile.component.scss' ]
} )
export class ProfileComponent implements OnInit {
infoForm ! : FormGroup ;
passForm ! : FormGroup ;
constructor (
private formBuilder : FormBuilder ,
private authService : AuthService
) { }
ngOnInit ( ) : void {
this . infoForm = this . formBuilder . group ( {
first_name : '' ,
last_name : '' ,
email : ''
} ) ;
this . passForm = this . formBuilder . group ( {
password : '' ,
password_confirm : ''
} ) ;
Auth . userEmitter . subscribe (
user => this . infoForm . patchValue ( user )
)
}
updateInfo ( ) : void {
this . authService . updateInfo ( this . infoForm . getRawValue ( ) ) . subscribe (
user => Auth . userEmitter . emit ( user )
)
}
updatePass ( ) : void {
this . authService . updatePassword ( this . passForm . getRawValue ( ) ) . subscribe (
user => Auth . userEmitter . emit ( user )
)
}
}
secure/roles/role-create/role-create.component.html
< form
(submit) ="submit() "
[formGroup] ="form " >
< div class ="mb-3 ">
< label > Role</ label >
< input
formControlName ="name "
name ="name "
type ="text "
class ="form-control "
placeholder ="Role "
required >
</ div >
< div
formArrayName ="permissions "
class ="mb-3 row " >
< label class ="col-sm-2 col-form-label "> Permission</ label >
< div class ="col-sm-10 ">
< div
*ngFor ="let permission of permissions; let i = index "
[formGroupName] ="i "
class ="form-check form-check-inline col-3 " >
< input
formControlName ="value "
name ="value "
type ="checkbox "
class ="form-check-input " >
< label
for ="value "
class ="form-check-label ">
{{permission.name}}
</ label >
</ div >
</ div >
</ div >
< button
class ="btn btn-outline-secondary "
type ="submit " >
Submit
</ button >
</ form >
secure/roles/role-create/role-create.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormArray , FormBuilder , FormGroup } from '@angular/forms' ;
import { Router } from '@angular/router' ;
import { Permission } from 'src/app/interfaces/permission' ;
import { PermissionService } from 'src/app/services/permission.service' ;
import { RoleService } from 'src/app/services/role.service' ;
@Component ( {
selector : 'app-role-create' ,
templateUrl : './role-create.component.html' ,
styleUrls : [ './role-create.component.scss' ]
} )
export class RoleCreateComponent implements OnInit {
form ! : FormGroup ;
permissions ! : Permission [ ] ;
constructor (
private formBuilder : FormBuilder ,
private permService : PermissionService ,
private roleService : RoleService ,
private router : Router
) { }
ngOnInit ( ) : void {
this . form = this . formBuilder . group ( {
name : '' ,
permissions : this . formBuilder . array ( [ ] )
} ) ;
this . permService . all ( )
. subscribe (
permissions => {
this . permissions = permissions ;
this . permissions . forEach ( p => {
this . permissionsArray . push (
this . formBuilder . group ( {
value : false ,
id : p . id
} )
)
} )
}
)
}
get permissionsArray ( ) : FormArray {
return this . form . get ( 'permissions' ) as FormArray ;
}
submit ( ) :void {
const formData = this . form . getRawValue ( ) ;
const data = {
name : formData . name ,
permissions : formData . permissions . filter ( ( p : { value : boolean ; } ) => p . value === true ) . map ( ( p : { id : any ; } ) => p . id )
} ;
this . roleService . create ( data )
. subscribe (
( ) => this . router . navigate ( [ '/roles' ] )
)
}
}
secure/roles/role-edit/role-edit.component.html
< form
(submit) ="submit() "
[formGroup] ="form " >
< div class ="mb-3 ">
< label > Role</ label >
< input
formControlName ="name "
name ="name "
type ="text "
class ="form-control "
placeholder ="Role "
required >
</ div >
< div
formArrayName ="permissions "
class ="mb-3 row " >
< label class ="col-sm-2 col-form-label "> Permission</ label >
< div class ="col-sm-10 ">
< div
*ngFor ="let permission of permissions; let i = index "
[formGroupName] ="i "
class ="form-check form-check-inline col-3 " >
< input
formControlName ="value "
name ="value "
type ="checkbox "
class ="form-check-input " >
< label
for ="value "
class ="form-check-label ">
{{permission.name}}
</ label >
</ div >
</ div >
</ div >
< button
class ="btn btn-outline-secondary "
type ="submit " >
Submit
</ button >
</ form >
secure/roles/role-edit/role-edit.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormArray , FormBuilder , FormGroup } from '@angular/forms' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Permission } from 'src/app/interfaces/permission' ;
import { Role } from 'src/app/interfaces/role' ;
import { PermissionService } from 'src/app/services/permission.service' ;
import { RoleService } from 'src/app/services/role.service' ;
@Component ( {
selector : 'app-role-edit' ,
templateUrl : './role-edit.component.html' ,
styleUrls : [ './role-edit.component.scss' ]
} )
export class RoleEditComponent implements OnInit {
form ! : FormGroup ;
permissions ! : Permission [ ] ;
id ! : number ;
constructor (
private formBuilder : FormBuilder ,
private permService : PermissionService ,
private roleService : RoleService ,
private router : Router ,
private route : ActivatedRoute
) { }
ngOnInit ( ) : void {
this . form = this . formBuilder . group ( {
name : '' ,
permissions : this . formBuilder . array ( [ ] )
} ) ;
this . permService . all ( )
. subscribe (
permissions => {
this . permissions = permissions ;
this . permissions . forEach ( p => {
this . permissionsArray . push (
this . formBuilder . group ( {
value : false ,
id : p . id
} )
)
} )
}
) ;
this . id = this . route . snapshot . params . id ;
this . roleService . get ( this . id )
. subscribe (
( role : Role ) => {
const values = this . permissions . map ( p => {
return {
value : role . permissions ?. some ( r => r . id === p . id ) ,
id : p . id
}
} ) ;
this . form . patchValue ( {
name : role . name ,
permissions : values
} ) ;
}
)
}
get permissionsArray ( ) : FormArray {
return this . form . get ( 'permissions' ) as FormArray ;
}
submit ( ) :void {
const formData = this . form . getRawValue ( ) ;
const data = {
name : formData . name ,
permissions : formData . permissions . filter ( ( p : { value : boolean ; } ) => p . value === true ) . map ( ( p : { id : any ; } ) => p . id )
} ;
this . roleService . update ( this . id , data )
. subscribe (
( ) => this . router . navigate ( [ '/roles' ] )
)
}
}
secure/roles/roles.component.html
< div class ="pt-3 pb-2 mb-3 border-bottom ">
< a
routerLink ="/roles/create "
class ="btn btn-sm btn-outline-secondary ">
Create Roll
</ a >
</ div >
< div class ="table-responsive ">
< table class ="table table-striped table-sm ">
< thead >
< tr >
< th > #</ th >
< th > Name</ th >
< th > Action</ th >
</ tr >
</ thead >
< tbody >
< tr *ngFor ="let role of roles ">
< td > {{role.id}}</ td >
< td > {{role.name}}</ td >
< td >
< a
[routerLink] ="['/roles', role.id, 'edit'] "
class ="btn btn-sm btn-outline-secondary ">
Edit
</ a >
< button
(click) ="delete(role.id) "
class ="btn btn-sm btn-outline-secondary ">
Delete
</ button >
</ td >
</ tr >
</ tbody >
</ table >
</ div >
secure/roles/roles.component.ts
import { Component , OnInit } from '@angular/core' ;
import { Role } from 'src/app/interfaces/role' ;
import { RoleService } from 'src/app/services/role.service' ;
@Component ( {
selector : 'app-roles' ,
templateUrl : './roles.component.html' ,
styleUrls : [ './roles.component.scss' ]
} )
export class RolesComponent implements OnInit {
roles ! : Role [ ] ;
constructor (
private roleService : RoleService
) { }
ngOnInit ( ) : void {
this . load ( ) ;
}
load ( ) : void {
this . roleService . all ( )
. subscribe (
roles => this . roles = roles
)
}
delete ( id : number ) : void {
if ( confirm ( 'Are you sure you want to delete?' ) ) {
this . roleService . delete ( id ) . subscribe (
( ) => {
this . roles = this . roles . filter ( u => u . id !== id ) ;
}
)
}
}
}
secure/users/user-create/user-create.component.html
< form
(submit) ="submit() "
[formGroup] ="form " >
< div class ="mb-3 ">
< label > First Name</ label >
< input
formControlName ="first_name "
name ="firstName "
type ="text "
class ="form-control "
placeholder ="First Name "
required >
</ div >
< div class ="mb-3 ">
< label > Last Name</ label >
< input
formControlName ="last_name "
name ="lastName "
type ="text "
class ="form-control "
placeholder ="Last Name "
required >
</ div >
< div class ="mb-3 ">
< label > Email</ label >
< input
formControlName ="email "
name ="email "
type ="email "
class ="form-control "
placeholder ="Email "
required >
</ div >
< div class ="mb-3 ">
< label > Role</ label >
< select
formControlName ="role_id "
name ="role_id "
class ="form-control ">
< option
*ngFor ="let role of roles "
[ngValue] ="role.id " >
{{role.name}}
</ option >
</ select >
</ div >
< button
class ="w-100 btn btn-lg btn-primary "
type ="submit " >
Submit
</ button >
</ form >
secure/users/user-create/user-create.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormBuilder , FormGroup } from '@angular/forms' ;
import { Router } from '@angular/router' ;
import { Role } from 'src/app/interfaces/role' ;
import { RoleService } from 'src/app/services/role.service' ;
import { UserService } from 'src/app/services/user.service' ;
@Component ( {
selector : 'app-user-create' ,
templateUrl : './user-create.component.html' ,
styleUrls : [ './user-create.component.scss' ]
} )
export class UserCreateComponent implements OnInit {
form ! : FormGroup ;
roles ! : Role [ ] ;
constructor (
private formBuilder : FormBuilder ,
private roleService : RoleService ,
private userService : UserService ,
private router : Router
) { }
ngOnInit ( ) : void {
this . form = this . formBuilder . group ( {
first_name : '' ,
last_name : '' ,
email : '' ,
role_id : ''
} ) ;
this . roleService . all ( ) . subscribe (
res => this . roles = res
) ;
}
submit ( ) {
this . userService . create ( this . form . getRawValue ( ) ) . subscribe (
( ) => this . router . navigate ( [ '/users' ] )
)
}
}
secure/users/user-edit/user-edit.component.html
< form
(submit) ="submit() "
[formGroup] ="form " >
< div class ="mb-3 ">
< label > First Name</ label >
< input
formControlName ="first_name "
name ="firstName "
type ="text "
class ="form-control "
placeholder ="First Name "
required >
</ div >
< div class ="mb-3 ">
< label > Last Name</ label >
< input
formControlName ="last_name "
name ="lastName "
type ="text "
class ="form-control "
placeholder ="Last Name "
required >
</ div >
< div class ="mb-3 ">
< label > Email</ label >
< input
formControlName ="email "
name ="email "
type ="email "
class ="form-control "
placeholder ="Email "
required >
</ div >
< div class ="mb-3 ">
< label > Role</ label >
< select
formControlName ="role_id "
name ="role_id "
class ="form-control ">
< option
*ngFor ="let role of roles "
[ngValue] ="role.id " >
{{role.name}}
</ option >
</ select >
</ div >
< button
class ="w-100 btn btn-lg btn-primary "
type ="submit " >
Submit
</ button >
</ form >
secure/users/user-edit/user-edit.component.ts
import { Component , OnInit } from '@angular/core' ;
import { FormBuilder , FormGroup } from '@angular/forms' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Role } from 'src/app/interfaces/role' ;
import { RoleService } from 'src/app/services/role.service' ;
import { UserService } from 'src/app/services/user.service' ;
@Component ( {
selector : 'app-user-edit' ,
templateUrl : './user-edit.component.html' ,
styleUrls : [ './user-edit.component.scss' ]
} )
export class UserEditComponent implements OnInit {
form ! : FormGroup ;
roles ! : Role [ ] ;
id ! : number ;
constructor (
private formBuilder : FormBuilder ,
private roleService : RoleService ,
private userService : UserService ,
private router : Router ,
private route : ActivatedRoute
) { }
ngOnInit ( ) : void {
this . form = this . formBuilder . group ( {
first_name : '' ,
last_name : '' ,
email : '' ,
role_id : ''
} ) ;
this . roleService . all ( ) . subscribe (
res => this . roles = res
) ;
this . id = this . route . snapshot . params . id ;
this . userService . get ( this . id )
. subscribe (
user => {
this . form . patchValue ( {
first_name : user . first_name ,
last_name : user . last_name ,
email : user . email ,
role_id : user . role . id
} ) ;
}
)
}
submit ( ) : void {
this . userService . update ( this . id , this . form . getRawValue ( ) )
. subscribe (
( ) => this . router . navigate ( [ '/users' ] )
)
}
}
secure/users/users.component.html
< div class ="pt-3 pb-2 mb-3 border-bottom ">
< a
routerLink ="/users/create "
class ="btn btn-sm btn-outline-secondary ">
Add User
</ a >
</ div >
< div class ="table-responsive ">
< table class ="table table-striped table-sm ">
< thead >
< tr >
< th > #</ th >
< th > Name</ th >
< th > Email</ th >
< th > Role</ th >
< th > Action</ th >
</ tr >
</ thead >
< tbody >
< tr *ngFor ="let user of users ">
< td > {{user.id}}</ td >
< td > {{user.first_name}} {{user.last_name}}</ td >
< td > {{user.email}}</ td >
< td > {{user.role.name}}</ td >
< td >
< a
[routerLink] ="['/users', user.id, 'edit'] "
class ="btn btn-sm btn-outline-secondary ">
Edit
</ a >
< button
(click) ="delete(user.id) "
class ="btn btn-sm btn-outline-secondary ">
Delete
</ button >
</ td >
</ tr >
</ tbody >
</ table >
</ div >
< app-paginator
[lastPage] ="lastPage "
(pageChanged) ="load($event) " >
</ app-paginator >
secure/users/users.component.ts
import { Component , OnInit } from '@angular/core' ;
import { User } from 'src/app/interfaces/user' ;
import { UserService } from 'src/app/services/user.service' ;
@Component ( {
selector : 'app-users' ,
templateUrl : './users.component.html' ,
styleUrls : [ './users.component.scss' ]
} )
export class UsersComponent implements OnInit {
users ! : User [ ] ;
lastPage ! : number ;
constructor (
private userService : UserService
) { }
ngOnInit ( ) : void {
this . load ( ) ;
}
load ( page : number = 1 ) : void {
this . userService . all ( page )
. subscribe (
( res : any ) => {
this . users = res . data ;
this . lastPage = res . meta . last_page ;
}
)
}
delete ( id : number ) : void {
if ( confirm ( 'Are you sure you want to delete?' ) ) {
this . userService . delete ( id ) . subscribe (
( ) => {
this . users = this . users . filter ( u => u . id !== id ) ;
}
)
}
}
}
secure/secure.component.html
< app-nav > </ app-nav >
< div class ="container-fluid ">
< div class ="row ">
< app-menu > </ app-menu >
< main class ="col-md-9 ms-sm-auto col-lg-10 px-md-4 ">
< router-outlet > </ router-outlet >
</ main >
</ div >
</ div >
secure/secure.component.ts
import { Component , OnInit } from '@angular/core' ;
import { Router } from '@angular/router' ;
import { Auth } from '../classes/auth' ;
import { AuthService } from '../services/auth.service' ;
@Component ( {
selector : 'app-secure' ,
templateUrl : './secure.component.html' ,
styles : [ ]
} )
export class SecureComponent implements OnInit {
constructor (
private authService : AuthService ,
private router : Router
) { }
ngOnInit ( ) : void {
this . authService . user ( ) . subscribe (
user => Auth . userEmitter . emit ( user ) ,
( ) => this . router . navigate ( [ '/login' ] )
) ;
}
}
import { NgModule } from '@angular/core' ;
import { CommonModule } from '@angular/common' ;
import { SecureComponent } from './secure.component' ;
import { MenuComponent } from './menu/menu.component' ;
import { NavComponent } from './nav/nav.component' ;
import { RouterModule } from '@angular/router' ;
import { ProfileComponent } from './profile/profile.component' ;
import { DashboardComponent } from './dashboard/dashboard.component' ;
import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
import { UsersComponent } from './users/users.component' ;
import { UserCreateComponent } from './users/user-create/user-create.component' ;
import { UserEditComponent } from './users/user-edit/user-edit.component' ;
import { RolesComponent } from './roles/roles.component' ;
import { RoleCreateComponent } from './roles/role-create/role-create.component' ;
import { RoleEditComponent } from './roles/role-edit/role-edit.component' ;
import { ProductsComponent } from './products/products.component' ;
import { PaginatorComponent } from './components/paginator/paginator.component' ;
import { ProductCreateComponent } from './products/product-create/product-create.component' ;
import { ProductEditComponent } from './products/product-edit/product-edit.component' ;
import { UploadComponent } from './components/upload/upload.component' ;
import { OrdersComponent } from './orders/orders.component' ;
@NgModule ( {
declarations : [
SecureComponent ,
MenuComponent ,
NavComponent ,
ProfileComponent ,
DashboardComponent ,
UsersComponent ,
UserCreateComponent ,
UserEditComponent ,
RolesComponent ,
RoleCreateComponent ,
RoleEditComponent ,
ProductsComponent ,
PaginatorComponent ,
ProductCreateComponent ,
ProductEditComponent ,
UploadComponent ,
OrdersComponent
] ,
imports : [
CommonModule ,
RouterModule ,
FormsModule ,
ReactiveFormsModule
]
} )
export class SecureModule { }
import { HttpClient } from '@angular/common/http' ;
import { Injectable } from '@angular/core' ;
import { Observable } from 'rxjs' ;
@Injectable ( {
providedIn : 'root'
} )
export abstract class RestService {
abstract get endpoint ( ) : string ;
constructor (
protected http :HttpClient
) { }
all ( page ?: number ) : Observable < any > {
let url = this . endpoint ;
if ( page ) url += `?page=${ page } ` ;
return this . http . get < any > ( url ) ;
}
create ( data : any ) : Observable < any > {
return this . http . post ( this . endpoint , data )
}
get ( id : number ) : Observable < any > {
return this . http . get ( `${ this . endpoint } /${ id } ` ) ;
}
update ( id : number , data : any ) : Observable < any > {
return this . http . put ( `${ this . endpoint } /${ id } ` , data ) ;
}
delete ( id : number ) : Observable < void > {
return this . http . delete < void > ( `${ this . endpoint } /${ id } ` ) ;
}
}
import { HttpClient } from '@angular/common/http' ;
import { Injectable } from '@angular/core' ;
import { Observable } from 'rxjs' ;
import { environment } from 'src/environments/environment' ;
import { User } from '../interfaces/user' ;
@Injectable ( {
providedIn : 'root'
} )
export class AuthService {
constructor (
protected http : HttpClient ,
) { }
login ( data : any ) : Observable < any > {
return this . http . post ( `${ environment . api } /login` , data )
}
register ( data : any ) : Observable < User > {
return this . http . post < User > ( `${ environment . api } /register` , data )
}
user ( ) : Observable < User > {
return this . http . get < User > ( `${ environment . api } /user` )
}
logout ( ) : Observable < void > {
return this . http . post < void > ( `${ environment . api } /logout` , { } )
}
updateInfo ( data : any ) : Observable < User > {
return this . http . put < User > ( `${ environment . api } /users/info` , data )
}
updatePassword ( data : any ) : Observable < User > {
return this . http . put < User > ( `${ environment . api } /users/password` , data )
}
}
import { Injectable } from '@angular/core' ;
import { Observable } from 'rxjs' ;
import { environment } from 'src/environments/environment' ;
import { RestService } from './rest.service' ;
@Injectable ( {
providedIn : 'root'
} )
export class OrderService extends RestService {
endpoint = `${ environment . api } /orders` ;
export ( ) : Observable < any > {
return this . http . post ( `${ environment . api } /export` , { } , { responseType : 'blob' } )
}
chart ( ) : Observable < any > {
return this . http . get ( `${ environment . api } /chart` )
}
}
services/permission.service.ts
import { Injectable } from '@angular/core' ;
import { environment } from 'src/environments/environment' ;
import { RestService } from './rest.service' ;
@Injectable ( {
providedIn : 'root'
} )
export class PermissionService extends RestService {
endpoint = `${ environment . api } /permissions`
}
services/product.service.ts
import { Injectable } from '@angular/core' ;
import { environment } from 'src/environments/environment' ;
import { RestService } from './rest.service' ;
@Injectable ( {
providedIn : 'root'
} )
export class ProductService extends RestService {
endpoint = `${ environment . api } /products`
}
import { Injectable } from '@angular/core' ;
import { environment } from 'src/environments/environment' ;
import { RestService } from './rest.service' ;
@Injectable ( {
providedIn : 'root'
} )
export class RoleService extends RestService {
endpoint = `${ environment . api } /roles` ;
}
import { Injectable } from '@angular/core' ;
import { environment } from 'src/environments/environment' ;
import { RestService } from './rest.service' ;
@Injectable ( {
providedIn : 'root'
} )
export class UserService extends RestService {
endpoint = `${ environment . api } /users` ;
}
import { NgModule } from '@angular/core' ;
import { RouterModule , Routes } from '@angular/router' ;
import { LoginComponent } from './public/login/login.component' ;
import { PublicComponent } from './public/public.component' ;
import { RegisterComponent } from './public/register/register.component' ;
import { DashboardComponent } from './secure/dashboard/dashboard.component' ;
import { OrdersComponent } from './secure/orders/orders.component' ;
import { ProductCreateComponent } from './secure/products/product-create/product-create.component' ;
import { ProductEditComponent } from './secure/products/product-edit/product-edit.component' ;
import { ProductsComponent } from './secure/products/products.component' ;
import { ProfileComponent } from './secure/profile/profile.component' ;
import { RoleCreateComponent } from './secure/roles/role-create/role-create.component' ;
import { RoleEditComponent } from './secure/roles/role-edit/role-edit.component' ;
import { RolesComponent } from './secure/roles/roles.component' ;
import { SecureComponent } from './secure/secure.component' ;
import { UserCreateComponent } from './secure/users/user-create/user-create.component' ;
import { UserEditComponent } from './secure/users/user-edit/user-edit.component' ;
import { UsersComponent } from './secure/users/users.component' ;
const routes : Routes = [
{
path : '' ,
component : SecureComponent ,
children : [
{ path : '' , redirectTo : '/dashboard' , pathMatch : 'full' } ,
{ path : 'dashboard' , component : DashboardComponent } ,
{ path : 'profile' , component : ProfileComponent } ,
{ path : 'users' , component : UsersComponent } ,
{ path : 'users/create' , component : UserCreateComponent } ,
{ path : 'users/:id/edit' , component : UserEditComponent } ,
{ path : 'roles' , component : RolesComponent } ,
{ path : 'roles/create' , component : RoleCreateComponent } ,
{ path : 'roles/:id/edit' , component : RoleEditComponent } ,
{ path : 'products' , component : ProductsComponent } ,
{ path : 'products/create' , component : ProductCreateComponent } ,
{ path : 'products/:id/edit' , component : ProductEditComponent } ,
{ path : 'orders' , component : OrdersComponent } ,
]
} ,
{
path : '' ,
component : PublicComponent ,
children : [
{ path : 'login' , component : LoginComponent } ,
{ path : 'register' , component : RegisterComponent }
]
} ,
] ;
@NgModule ( {
imports : [ RouterModule . forRoot ( routes ) ] ,
exports : [ RouterModule ]
} )
export class AppRoutingModule { }
< router-outlet > </ router-outlet >
import { Component } from '@angular/core' ;
@Component ( {
selector : 'app-root' ,
templateUrl : './app.component.html'
} )
export class AppComponent { }
import { HTTP_INTERCEPTORS } from '@angular/common/http' ;
import { NgModule } from '@angular/core' ;
import { BrowserModule } from '@angular/platform-browser' ;
import { AppRoutingModule } from './app-routing.module' ;
import { AppComponent } from './app.component' ;
import { CredentialInterceptor } from './interceptors/credential.interceptor' ;
import { PublicModule } from './public/public.module' ;
import { SecureModule } from './secure/secure.module' ;
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
@NgModule ( {
declarations : [
AppComponent ,
] ,
imports : [
BrowserModule ,
AppRoutingModule ,
SecureModule ,
PublicModule ,
BrowserAnimationsModule
] ,
providers : [
{
provide : HTTP_INTERCEPTORS ,
useClass : CredentialInterceptor ,
multi : true
}
] ,
bootstrap : [ AppComponent ] ,
} )
export class AppModule { }