From 8b64593522725f5930ebc7e836ed5d8088c4f19e Mon Sep 17 00:00:00 2001 From: Patrick Sun Date: Sun, 21 Mar 2021 11:14:08 +1100 Subject: [PATCH] logout button installed with menu for different type of user; --- src/app/dashboard/dashboard.component.scss | 5 +- .../basicinfo/basicinfo.component.html | 2 +- .../trail-income/trail-income.component.ts | 12 ++++- src/app/main-menu-items.ts | 27 +++++++++- src/app/models/api-v1-login-response.ts | 13 +++-- src/app/service/auth.service.ts | 10 ++-- src/app/top-bar/top-bar.component.html | 16 ++++-- src/app/top-bar/top-bar.component.ts | 48 ++++++++++++++++-- src/assets/img/logout.png | Bin 0 -> 3268 bytes 9 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 src/assets/img/logout.png diff --git a/src/app/dashboard/dashboard.component.scss b/src/app/dashboard/dashboard.component.scss index 9d406af..175cb18 100644 --- a/src/app/dashboard/dashboard.component.scss +++ b/src/app/dashboard/dashboard.component.scss @@ -1,11 +1,12 @@ .container.outer{ width:100%; - background: url('../../assets/img/body_bg.jpg') no-repeat center center fixed; + max-width:100vw; + background: url('../../assets/img/body_bg.jpg') no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; - opacity:0.98; + opacity:0.98; } .container.inner { width: 99%; diff --git a/src/app/loan-edit/basicinfo/basicinfo.component.html b/src/app/loan-edit/basicinfo/basicinfo.component.html index 122a7b7..0f99ca4 100644 --- a/src/app/loan-edit/basicinfo/basicinfo.component.html +++ b/src/app/loan-edit/basicinfo/basicinfo.component.html @@ -68,7 +68,7 @@ + [min]="minSettlement" [max]="maxSettlement" required> Date settled or expected to be settled diff --git a/src/app/loan-edit/trail-income/trail-income.component.ts b/src/app/loan-edit/trail-income/trail-income.component.ts index 2efa892..441e49b 100644 --- a/src/app/loan-edit/trail-income/trail-income.component.ts +++ b/src/app/loan-edit/trail-income/trail-income.component.ts @@ -46,7 +46,7 @@ export class TrailIncomeComponent implements OnInit { let balance = -1; let offsetBalance = -1; - if ( this.Loan.PayIn.length >= 0) { + if ( this.Loan.PayIn.length > 0) { const idx = this.Loan.PayIn.length -1; balance = this.Loan.PayIn[idx].Balance; offsetBalance = this.Loan.PayIn[idx].OffsetBalance; @@ -85,6 +85,16 @@ export class TrailIncomeComponent implements OnInit { public saveHandler({ sender, rowIndex, formGroup, isNew }): void { const v = formGroup.getRawValue(); + if ( this.Loan.Lender === '') { + this.errorOccurred.emit('Lender should not be empty'); + return; + } + + if ( this.Loan.LenderLoanNumber === '') { + this.errorOccurred.emit('Lender Identification should not be empty'); + return; + } + if ( !this.showBalance) { v.Balance = -1; } if ( !this.showOffsetBalance) { v.OffsetBalance = -1; } diff --git a/src/app/main-menu-items.ts b/src/app/main-menu-items.ts index 3e3f0fa..30aae20 100644 --- a/src/app/main-menu-items.ts +++ b/src/app/main-menu-items.ts @@ -1,4 +1,4 @@ -import { faChartArea, faChartPie, faIdCard, faIdCardAlt, faMoneyCheck, faUniversity, faUserCircle } from '@fortawesome/free-solid-svg-icons'; +import { faChartArea, faIdCard, faIdCardAlt, faMoneyCheck, faUniversity, faUserCircle } from '@fortawesome/free-solid-svg-icons'; export const mainMenuItems: any[] = [ { @@ -60,3 +60,28 @@ export const mainMenuItems: any[] = [ ] } ]; + + +export const brokerMenuItems: any[] = [ + { + text: 'broker', + fa: faUniversity, + url: './#canvas' + }, +]; + +export const userMenuItems: any[] = [ + { + text: 'user', + fa: faUniversity, + url: './#canvas' + }, +]; + +export const peopleMenuItems: any[] = [ + { + text: 'people', + fa: faUniversity, + url: './#canvas' + }, +]; diff --git a/src/app/models/api-v1-login-response.ts b/src/app/models/api-v1-login-response.ts index 7a0a109..c9314a7 100644 --- a/src/app/models/api-v1-login-response.ts +++ b/src/app/models/api-v1-login-response.ts @@ -3,13 +3,12 @@ // tslint:disable-next-line:class-name export class apiV1LoginResponse { - - // tslint:disable-next-line:typedef constructor( public login: boolean, public machineId: string, public session: string, - public sessionExpire: number // unix timestamp + public sessionExpire: number, // unix timestamp + public role: string ) { this.login = login; this.machineId = machineId; @@ -17,7 +16,12 @@ export class apiV1LoginResponse { this.sessionExpire = sessionExpire; } - // tslint:disable-next-line:typedef + public static EmptyNew(): apiV1LoginResponse{ + return new apiV1LoginResponse( + false, '', '', 0, '' + ); + } + public hasValidSession(): boolean { if (this.session === undefined || this.session === '') { return false; @@ -26,7 +30,6 @@ export class apiV1LoginResponse { } } - // tslint:disable-next-line:typedef public hasValidMachineId(): boolean { if (this.machineId === undefined || this.machineId === '') { return false; diff --git a/src/app/service/auth.service.ts b/src/app/service/auth.service.ts index 5dfc821..c6cfc3c 100644 --- a/src/app/service/auth.service.ts +++ b/src/app/service/auth.service.ts @@ -10,7 +10,7 @@ export class AuthService { public apiWsUrl = 'wss://svr2021.lawipac.com:8080/api/v1/ws'; // public apiUrl = 'https://c5016.biukop.com.au:8080/api/v1/'; // public apiWsUrl = 'wss://c5016.biukop.com.au:8080/api/v1/ws'; - public loggedIn = new apiV1LoginResponse(false, '', '', 0 ); + public loggedIn = apiV1LoginResponse.EmptyNew(); loginSuccess = new EventEmitter (); constructor( private http: HttpClient , @@ -28,7 +28,8 @@ export class AuthService { sfm.login, sfm.machineId, sfm.session, - sfm.sessionExpire + sfm.sessionExpire, + sfm.role ); this.loginSuccess.emit(this.loggedIn); // console.log ( 'auto login emit events', this.loggedIn); @@ -56,11 +57,12 @@ export class AuthService { this.loggedIn.login = responseData.login; this.loggedIn.machineId = responseData['Biukop-Mid']; this.loggedIn.sessionExpire = responseData.sessionExpire; + this.loggedIn.role = responseData.role; this.saveSessionInfo(); this.loginSuccess.emit(responseData); }, error => { - const fail = new apiV1LoginResponse(false, '', '', 0); + const fail = apiV1LoginResponse.EmptyNew(); this.loggedIn = fail; console.log('login error', error); this.loginSuccess.emit(this.loggedIn); @@ -70,7 +72,7 @@ export class AuthService { } logout(): void { - this.loggedIn = new apiV1LoginResponse(false, '', '', 0); + this.loggedIn = apiV1LoginResponse.EmptyNew(); localStorage.removeItem('sfm'); this.loginSuccess.emit(this.loggedIn); this.router.navigate(['/login']).then(r => { diff --git a/src/app/top-bar/top-bar.component.html b/src/app/top-bar/top-bar.component.html index 60ebf68..2e97527 100644 --- a/src/app/top-bar/top-bar.component.html +++ b/src/app/top-bar/top-bar.component.html @@ -1,4 +1,4 @@ - + @@ -10,7 +10,7 @@ - + @@ -20,6 +20,16 @@ - + + + + + +

Are you sure you want to continue?

+ + + + +
diff --git a/src/app/top-bar/top-bar.component.ts b/src/app/top-bar/top-bar.component.ts index ad4c0d4..bf6d5c2 100644 --- a/src/app/top-bar/top-bar.component.ts +++ b/src/app/top-bar/top-bar.component.ts @@ -1,10 +1,11 @@ import {Component, OnDestroy, OnInit} from '@angular/core'; import {MenuService} from '../service/menu.service'; import {AuthService} from '../service/auth.service'; -import {mainMenuItems} from '../main-menu-items'; +import {brokerMenuItems, mainMenuItems, peopleMenuItems, userMenuItems} from '../main-menu-items'; import {apiV1LoginResponse} from '../models/api-v1-login-response'; import {Subscription} from 'rxjs'; + @Component({ selector: 'app-top-bar', templateUrl: './top-bar.component.html', @@ -12,11 +13,16 @@ import {Subscription} from 'rxjs'; }) export class TopBarComponent implements OnInit , OnDestroy { login = false; - Avatar = './assets/img/avatar.png'; + Avatar = './assets/img/logout.png'; public items: any[] = mainMenuItems; private loginSub: Subscription; + public showMenu = true; + + public opened = false; - constructor(private menuService: MenuService, private authService: AuthService,) { } + constructor(private menuService: MenuService, + private authService: AuthService) { + } ngOnInit(): void { this.initAndSubLogin(); @@ -24,15 +30,39 @@ export class TopBarComponent implements OnInit , OnDestroy { public initAndSubLogin(): void{ this.login = this.authService.loggedIn.login; - console.log('subscribe auto login'); + this.selectMenuShow(this.authService.loggedIn.role); + // console.log('subscribe auto login', this.authService.loggedIn); this.loginSub = this.authService.loginSuccess.subscribe( (rsp: apiV1LoginResponse) => { this.login = rsp.login; + this.selectMenuShow(rsp.role); console.log ('topbar received auth events', rsp); } ); } + private selectMenuShow(role: string): void { + this.showMenu = true; + switch ( role ){ + case 'admin': + this.items = mainMenuItems; + break; + case 'broker': + this.items = brokerMenuItems; + break; + case 'user': + this.items = userMenuItems; + break; + case 'people': + this.items = peopleMenuItems; + break; + + default: + this.showMenu = false; + } + + } + // check menuItem has fontawesome public menuItemHasFontawesome(item: any): boolean { return item.hasOwnProperty('fa'); @@ -57,4 +87,14 @@ export class TopBarComponent implements OnInit , OnDestroy { this.loginSub.unsubscribe(); } + public logout(): void{ + this.opened = true; + } + + public close(action: string): void { + this.opened = false; + if ( action === 'yes') { + this.authService.logout(); + } + } } diff --git a/src/assets/img/logout.png b/src/assets/img/logout.png new file mode 100644 index 0000000000000000000000000000000000000000..2e3e7587bca729b52fe0d8b626a7d31dd1af96d0 GIT binary patch literal 3268 zcmV;#3_J6QP)N#*R`ai2Jt%~*J&L!Z2X+2hWs)pwAxYHpn|lFCVSp+3OUu5g|;^7ikg({Gl{ zQ=HFV`~CRX>%++8tGC>azTcSg`0JF*Pww~RhqX|#*@29@SzleXK3lEYSzz*VoulbX79g{)S-(x-;APm8c$w#=T<-@>E8e$3pu*5b>l z#E8h-v6#4Vm&9U)xJG%ZJBhzT+33iVyJGqS4dDO)3&lx9K~#90<(++h;;ItIF&1jN zO;;m6Bx&NBR&8xuwYA%O?>XoFzpWEZ)o31ofjsE_{n`EK@)d@GnE?3zH``*)s6W_6{%L1iV*l&Xl z-k~+}wFAYSLD-*{LTQbA{XxfOvz>9;ok71hwyJJEOP1ds=nXNt7-d5r^!*w`(%!S{ zB`r>j5_|4*ub#uz8FspIcn8RCXXsRob1wSi!G>lQrRhD@s3Yn4xnZlr`-Zd|&*OSP zTK>Q^72`!R%|Q*O9j7-_-hD@5d)BMgBAt=jD2{K(*l3WW>5(GM_UnkuPE_brE1qykh)Ao=k62n(GK1V7VO_35V{n6h5cl zEx!XJncaQ~L)CXnw!pYBc8l&tI`XRH+cA2hLY<>CtFQyV5%H|Rk=koiWr1;-jb1@~ zbX4FPTSV9{W~4e(yK1z9%xM85HJn4M=86fsW7UAYPMrWlL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