Parcourir la source

logout button installed with menu for different type of user;

tags/2.037
Patrick Sun il y a 4 ans
Parent
révision
8b64593522
9 fichiers modifiés avec 112 ajouts et 21 suppressions
  1. +3
    -2
      src/app/dashboard/dashboard.component.scss
  2. +1
    -1
      src/app/loan-edit/basicinfo/basicinfo.component.html
  3. +11
    -1
      src/app/loan-edit/trail-income/trail-income.component.ts
  4. +26
    -1
      src/app/main-menu-items.ts
  5. +8
    -5
      src/app/models/api-v1-login-response.ts
  6. +6
    -4
      src/app/service/auth.service.ts
  7. +13
    -3
      src/app/top-bar/top-bar.component.html
  8. +44
    -4
      src/app/top-bar/top-bar.component.ts
  9. BIN
      src/assets/img/logout.png

+ 3
- 2
src/app/dashboard/dashboard.component.scss Voir le fichier

.container.outer{ .container.outer{
width:100%; 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; -webkit-background-size: cover;
-moz-background-size: cover; -moz-background-size: cover;
-o-background-size: cover; -o-background-size: cover;
background-size: cover; background-size: cover;
opacity:0.98;
opacity:0.98;
} }
.container.inner { .container.inner {
width: 99%; width: 99%;

+ 1
- 1
src/app/loan-edit/basicinfo/basicinfo.component.html Voir le fichier

<kendo-label [for]="Settlement" [optional]="false" text="Settlement Date"></kendo-label> <kendo-label [for]="Settlement" [optional]="false" text="Settlement Date"></kendo-label>
<kendo-datepicker #Settlement name="Settlement" <kendo-datepicker #Settlement name="Settlement"
[(ngModel)]="Loan.Settlement" [(ngModel)]="Loan.Settlement"
[min]="minSettlement" [max]="maxSettlement">
[min]="minSettlement" [max]="maxSettlement" required>
</kendo-datepicker> </kendo-datepicker>
<kendo-formhint>Date settled or expected to be settled</kendo-formhint> <kendo-formhint>Date settled or expected to be settled</kendo-formhint>
</kendo-formfield> </kendo-formfield>

+ 11
- 1
src/app/loan-edit/trail-income/trail-income.component.ts Voir le fichier



let balance = -1; let balance = -1;
let offsetBalance = -1; let offsetBalance = -1;
if ( this.Loan.PayIn.length >= 0) {
if ( this.Loan.PayIn.length > 0) {
const idx = this.Loan.PayIn.length -1; const idx = this.Loan.PayIn.length -1;
balance = this.Loan.PayIn[idx].Balance; balance = this.Loan.PayIn[idx].Balance;
offsetBalance = this.Loan.PayIn[idx].OffsetBalance; offsetBalance = this.Loan.PayIn[idx].OffsetBalance;
public saveHandler({ sender, rowIndex, formGroup, isNew }): void { public saveHandler({ sender, rowIndex, formGroup, isNew }): void {
const v = formGroup.getRawValue(); 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.showBalance) { v.Balance = -1; }
if ( !this.showOffsetBalance) { v.OffsetBalance = -1; } if ( !this.showOffsetBalance) { v.OffsetBalance = -1; }



+ 26
- 1
src/app/main-menu-items.ts Voir le fichier

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[] = [ 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'
},
];

+ 8
- 5
src/app/models/api-v1-login-response.ts Voir le fichier

// tslint:disable-next-line:class-name // tslint:disable-next-line:class-name
export class apiV1LoginResponse { export class apiV1LoginResponse {



// tslint:disable-next-line:typedef
constructor( constructor(
public login: boolean, public login: boolean,
public machineId: string, public machineId: string,
public session: string, public session: string,
public sessionExpire: number // unix timestamp
public sessionExpire: number, // unix timestamp
public role: string
) { ) {
this.login = login; this.login = login;
this.machineId = machineId; this.machineId = machineId;
this.sessionExpire = sessionExpire; this.sessionExpire = sessionExpire;
} }


// tslint:disable-next-line:typedef
public static EmptyNew(): apiV1LoginResponse{
return new apiV1LoginResponse(
false, '', '', 0, ''
);
}

public hasValidSession(): boolean { public hasValidSession(): boolean {
if (this.session === undefined || this.session === '') { if (this.session === undefined || this.session === '') {
return false; return false;
} }
} }


// tslint:disable-next-line:typedef
public hasValidMachineId(): boolean { public hasValidMachineId(): boolean {
if (this.machineId === undefined || this.machineId === '') { if (this.machineId === undefined || this.machineId === '') {
return false; return false;

+ 6
- 4
src/app/service/auth.service.ts Voir le fichier

public apiWsUrl = 'wss://svr2021.lawipac.com:8080/api/v1/ws'; public apiWsUrl = 'wss://svr2021.lawipac.com:8080/api/v1/ws';
// public apiUrl = 'https://c5016.biukop.com.au:8080/api/v1/'; // public apiUrl = 'https://c5016.biukop.com.au:8080/api/v1/';
// public apiWsUrl = 'wss://c5016.biukop.com.au:8080/api/v1/ws'; // public apiWsUrl = 'wss://c5016.biukop.com.au:8080/api/v1/ws';
public loggedIn = new apiV1LoginResponse(false, '', '', 0 );
public loggedIn = apiV1LoginResponse.EmptyNew();
loginSuccess = new EventEmitter <apiV1LoginResponse>(); loginSuccess = new EventEmitter <apiV1LoginResponse>();


constructor( private http: HttpClient , constructor( private http: HttpClient ,
sfm.login, sfm.login,
sfm.machineId, sfm.machineId,
sfm.session, sfm.session,
sfm.sessionExpire
sfm.sessionExpire,
sfm.role
); );
this.loginSuccess.emit(this.loggedIn); this.loginSuccess.emit(this.loggedIn);
// console.log ( 'auto login emit events', this.loggedIn); // console.log ( 'auto login emit events', this.loggedIn);
this.loggedIn.login = responseData.login; this.loggedIn.login = responseData.login;
this.loggedIn.machineId = responseData['Biukop-Mid']; this.loggedIn.machineId = responseData['Biukop-Mid'];
this.loggedIn.sessionExpire = responseData.sessionExpire; this.loggedIn.sessionExpire = responseData.sessionExpire;
this.loggedIn.role = responseData.role;
this.saveSessionInfo(); this.saveSessionInfo();
this.loginSuccess.emit(responseData); this.loginSuccess.emit(responseData);
}, },
error => { error => {
const fail = new apiV1LoginResponse(false, '', '', 0);
const fail = apiV1LoginResponse.EmptyNew();
this.loggedIn = fail; this.loggedIn = fail;
console.log('login error', error); console.log('login error', error);
this.loginSuccess.emit(this.loggedIn); this.loginSuccess.emit(this.loggedIn);
} }


logout(): void { logout(): void {
this.loggedIn = new apiV1LoginResponse(false, '', '', 0);
this.loggedIn = apiV1LoginResponse.EmptyNew();
localStorage.removeItem('sfm'); localStorage.removeItem('sfm');
this.loginSuccess.emit(this.loggedIn); this.loginSuccess.emit(this.loggedIn);
this.router.navigate(['/login']).then(r => { this.router.navigate(['/login']).then(r => {

+ 13
- 3
src/app/top-bar/top-bar.component.html Voir le fichier

<kendo-appbar id='topBar' *ngIf='login' class='appbar' [position]="'top'" [positionMode]="'sticky'">
<kendo-appbar id='topBar' *ngIf='login && showMenu' class='appbar' [position]="'top'" [positionMode]="'sticky'">
<kendo-appbar-section> <kendo-appbar-section>
<kendo-menu [items]="items" (select)="onSelect($event)"> <kendo-menu [items]="items" (select)="onSelect($event)">
<ng-template kendoMenuItemTemplate let-item="item"> <ng-template kendoMenuItemTemplate let-item="item">
</kendo-appbar-section> </kendo-appbar-section>
<kendo-appbar-spacer></kendo-appbar-spacer> <kendo-appbar-spacer></kendo-appbar-spacer>
<kendo-appbar-section class="actions"> <kendo-appbar-section class="actions">
<kendo-badge-container>
<kendo-badge-container *ngIf="false">
<button class="k-button k-button-clear"> <button class="k-button k-button-clear">
<kendo-icon [name]="'bell'"></kendo-icon> <kendo-icon [name]="'bell'"></kendo-icon>
</button> </button>
</kendo-appbar-section> </kendo-appbar-section>


<kendo-appbar-section> <kendo-appbar-section>
<kendo-avatar [imageSrc]="Avatar" [shape]="'circle'" [width]="'26px'" [height]="'26px'"></kendo-avatar>
<kendo-avatar [imageSrc]="Avatar" [shape]="'circle'" [width]="'26px'" [height]="'26px'" (click)="logout()"></kendo-avatar>
</kendo-appbar-section> </kendo-appbar-section>
</kendo-appbar> </kendo-appbar>



<kendo-dialog title="Please confirm" *ngIf="opened" (close)="close('cancel')" [minWidth]="250" [width]="450">
<p style="margin: 30px; text-align: center;">Are you sure you want to continue?</p>
<kendo-dialog-actions>
<button kendoButton (click)="close('no')">No</button>
<button kendoButton (click)="close('yes')" primary="true">Yes</button>
</kendo-dialog-actions>
</kendo-dialog>

+ 44
- 4
src/app/top-bar/top-bar.component.ts Voir le fichier

import {Component, OnDestroy, OnInit} from '@angular/core'; import {Component, OnDestroy, OnInit} from '@angular/core';
import {MenuService} from '../service/menu.service'; import {MenuService} from '../service/menu.service';
import {AuthService} from '../service/auth.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 {apiV1LoginResponse} from '../models/api-v1-login-response';
import {Subscription} from 'rxjs'; import {Subscription} from 'rxjs';



@Component({ @Component({
selector: 'app-top-bar', selector: 'app-top-bar',
templateUrl: './top-bar.component.html', templateUrl: './top-bar.component.html',
}) })
export class TopBarComponent implements OnInit , OnDestroy { export class TopBarComponent implements OnInit , OnDestroy {
login = false; login = false;
Avatar = './assets/img/avatar.png';
Avatar = './assets/img/logout.png';
public items: any[] = mainMenuItems; public items: any[] = mainMenuItems;
private loginSub: Subscription; 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 { ngOnInit(): void {
this.initAndSubLogin(); this.initAndSubLogin();


public initAndSubLogin(): void{ public initAndSubLogin(): void{
this.login = this.authService.loggedIn.login; 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( this.loginSub = this.authService.loginSuccess.subscribe(
(rsp: apiV1LoginResponse) => { (rsp: apiV1LoginResponse) => {
this.login = rsp.login; this.login = rsp.login;
this.selectMenuShow(rsp.role);
console.log ('topbar received auth events', rsp); 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 // check menuItem has fontawesome
public menuItemHasFontawesome(item: any): boolean { public menuItemHasFontawesome(item: any): boolean {
return item.hasOwnProperty('fa'); return item.hasOwnProperty('fa');
this.loginSub.unsubscribe(); this.loginSub.unsubscribe();
} }


public logout(): void{
this.opened = true;
}

public close(action: string): void {
this.opened = false;
if ( action === 'yes') {
this.authService.logout();
}
}
} }

BIN
src/assets/img/logout.png Voir le fichier

Avant Après
Largeur: 225  |  Hauteur: 225  |  Taille: 3.2KB

Chargement…
Annuler
Enregistrer