Added nav-bar to show home link and user status

This commit is contained in:
Amritanshu
2019-08-22 14:15:02 +05:30
parent 04fb6dfcab
commit 05860fb0b9
9 changed files with 82 additions and 31 deletions

View 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;
}

View 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>

View 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();
});
});

View 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()
);
}
}