Added nav-bar to show home link and user status
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
<app-nav-bar></app-nav-bar>
|
||||||
<div fxLayout="column" fxLayoutAlign="center none" class="mat-app-background basic-container">
|
<div fxLayout="column" fxLayoutAlign="center none" class="mat-app-background basic-container">
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -25,6 +25,8 @@ import { CoreModule } from './core/core.module';
|
|||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
import { SharedModule } from './shared/shared.module';
|
import { SharedModule } from './shared/shared.module';
|
||||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||||
|
import { MatToolbarModule } from "@angular/material";
|
||||||
|
import { NavBarComponent } from './nav-bar/nav-bar.component';
|
||||||
|
|
||||||
registerLocaleData(enIN);
|
registerLocaleData(enIN);
|
||||||
|
|
||||||
@ -33,7 +35,8 @@ registerLocaleData(enIN);
|
|||||||
AppComponent,
|
AppComponent,
|
||||||
LoginComponent,
|
LoginComponent,
|
||||||
LogoutComponent,
|
LogoutComponent,
|
||||||
HomeComponent
|
HomeComponent,
|
||||||
|
NavBarComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
@ -41,16 +44,17 @@ registerLocaleData(enIN);
|
|||||||
BrowserAnimationsModule,
|
BrowserAnimationsModule,
|
||||||
FlexLayoutModule,
|
FlexLayoutModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
MatGridListModule,
|
|
||||||
MatCardModule,
|
|
||||||
MatMenuModule,
|
|
||||||
MatIconModule,
|
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatFormFieldModule,
|
MatCardModule,
|
||||||
MatDividerModule,
|
|
||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatSnackBarModule,
|
MatDividerModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatGridListModule,
|
||||||
|
MatIconModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
|
MatMenuModule,
|
||||||
|
MatSnackBarModule,
|
||||||
|
MatToolbarModule,
|
||||||
LayoutModule,
|
LayoutModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
|
|||||||
@ -1,10 +1,4 @@
|
|||||||
<div fxLayout="row wrap" fxLayoutGap="grid 20px">
|
<div fxLayout="row wrap" fxLayoutGap="grid 20px">
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['/', 'login']" *ngIf="!(user | async)">
|
|
||||||
<h3 class="item-name">
|
|
||||||
<mat-icon>account_box</mat-icon>
|
|
||||||
Login
|
|
||||||
</h3>
|
|
||||||
</mat-card>
|
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Guest Book')" [routerLink]="['/', 'guest-book']">
|
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Guest Book')" [routerLink]="['/', 'guest-book']">
|
||||||
<h3 class="item-name">Guest Book</h3>
|
<h3 class="item-name">Guest Book</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
@ -74,10 +68,4 @@
|
|||||||
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Users')" [routerLink]="['/', 'users']">
|
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Users')" [routerLink]="['/', 'users']">
|
||||||
<h3 class="item-name">Users</h3>
|
<h3 class="item-name">Users</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['/', 'logout']"
|
|
||||||
*ngIf="user | async as name">
|
|
||||||
<h3 class="item-name">
|
|
||||||
<mat-icon>account_box</mat-icon>
|
|
||||||
Logout {{name}}</h3>
|
|
||||||
</mat-card>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import { Component, OnInit} from '@angular/core';
|
import { Component, OnInit} from '@angular/core';
|
||||||
import { AuthService} from '../auth/auth.service';
|
import { AuthService} from '../auth/auth.service';
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { map, share } from 'rxjs/operators';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-home',
|
selector: 'app-home',
|
||||||
@ -9,15 +7,10 @@ import { map, share } from 'rxjs/operators';
|
|||||||
styleUrls: ['./home.component.css']
|
styleUrls: ['./home.component.css']
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnInit {
|
export class HomeComponent implements OnInit {
|
||||||
public user: Observable<string>;
|
|
||||||
|
|
||||||
constructor(public auth: AuthService) {
|
constructor(public auth: AuthService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.user = this.auth.userObservable.pipe(
|
|
||||||
map (x => x.isAuthenticated ? x.name : null),
|
|
||||||
share()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
bookie/src/app/nav-bar/nav-bar.component.css
Normal file
5
bookie/src/app/nav-bar/nav-bar.component.css
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.fill-remaining-space {
|
||||||
|
/* This fills the remaining space, by using flexbox.
|
||||||
|
Every toolbar row uses a flexbox row layout. */
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
15
bookie/src/app/nav-bar/nav-bar.component.html
Normal file
15
bookie/src/app/nav-bar/nav-bar.component.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<mat-toolbar>
|
||||||
|
<a mat-button [routerLink]="['/']">
|
||||||
|
<mat-icon>home</mat-icon>
|
||||||
|
Point of Sale
|
||||||
|
</a>
|
||||||
|
<span class="fill-remaining-space"></span>
|
||||||
|
<button mat-button [routerLink]="['/', 'login']" *ngIf="!(user | async)">
|
||||||
|
<mat-icon>account_box</mat-icon>
|
||||||
|
Login
|
||||||
|
</button>
|
||||||
|
<button mat-button [routerLink]="['/', 'logout']" *ngIf="user | async as name">
|
||||||
|
<mat-icon>account_box</mat-icon>
|
||||||
|
Logout {{name}}
|
||||||
|
</button>
|
||||||
|
</mat-toolbar>
|
||||||
25
bookie/src/app/nav-bar/nav-bar.component.spec.ts
Normal file
25
bookie/src/app/nav-bar/nav-bar.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { NavBarComponent } from './nav-bar.component';
|
||||||
|
|
||||||
|
describe('NavBarComponent', () => {
|
||||||
|
let component: NavBarComponent;
|
||||||
|
let fixture: ComponentFixture<NavBarComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ NavBarComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(NavBarComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
24
bookie/src/app/nav-bar/nav-bar.component.ts
Normal file
24
bookie/src/app/nav-bar/nav-bar.component.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { Observable } from "rxjs";
|
||||||
|
import { map, share } from "rxjs/operators";
|
||||||
|
import { AuthService } from "../auth/auth.service";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-nav-bar',
|
||||||
|
templateUrl: './nav-bar.component.html',
|
||||||
|
styleUrls: ['./nav-bar.component.css']
|
||||||
|
})
|
||||||
|
export class NavBarComponent implements OnInit {
|
||||||
|
public user: Observable<string>;
|
||||||
|
|
||||||
|
constructor(public auth: AuthService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.user = this.auth.userObservable.pipe(
|
||||||
|
map (x => x.isAuthenticated ? x.name : null),
|
||||||
|
share()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,10 +1,6 @@
|
|||||||
<mat-card>
|
<mat-card>
|
||||||
<mat-card-title-group>
|
<mat-card-title-group>
|
||||||
<mat-card-title>Bill</mat-card-title>
|
<mat-card-title>Bill</mat-card-title>
|
||||||
<a mat-button [routerLink]="['/']">
|
|
||||||
<mat-icon>home</mat-icon>
|
|
||||||
Main Menu
|
|
||||||
</a>
|
|
||||||
</mat-card-title-group>
|
</mat-card-title-group>
|
||||||
<mat-card-content>
|
<mat-card-content>
|
||||||
<table mat-table #table [dataSource]="dataSource" aria-label="Elements" class="mat-elevation-z8">
|
<table mat-table #table [dataSource]="dataSource" aria-label="Elements" class="mat-elevation-z8">
|
||||||
|
|||||||
Reference in New Issue
Block a user