carnet updates
This commit is contained in:
parent
ca9397894e
commit
2d78a2e7f4
@ -1,6 +1,7 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import { AuthGuard } from './guards/auth.guard';
|
||||
import { AppIdGuard } from './guards/appid.guard';
|
||||
import { CarnetCleanupGuard } from './guards/carnet-cleanup.guard';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: 'login', loadComponent: () => import('./login/login.component').then(m => m.LoginComponent) },
|
||||
@ -20,10 +21,10 @@ export const routes: Routes = [
|
||||
{ path: 'table-record', loadComponent: () => import('./param/manage-table-record/manage-table-record.component').then(m => m.ManageTableRecordComponent) },
|
||||
{ path: 'param-record/:id', loadComponent: () => import('./param/manage-param-record/manage-param-record.component').then(m => m.ManageParamRecordComponent) },
|
||||
{ path: 'country-messages', loadComponent: () => import('./param/manage-country/manage-country.component').then(m => m.ManageCountryComponent) },
|
||||
{ path: 'edit-carnet/:headerid', loadComponent: () => import('./carnet/edit/edit-carnet.component').then(m => m.EditCarnetComponent) },
|
||||
{ path: 'view-carnet/:headerid', loadComponent: () => import('./carnet/view/view-carnet.component').then(m => m.ViewCarnetComponent) },
|
||||
{ path: 'add-holder', loadComponent: () => import('./holder/add/add-holder.component').then(m => m.AddHolderComponent) },
|
||||
{ path: 'edit-holder/:holderid', loadComponent: () => import('./holder/edit/edit-holder.component').then(m => m.EditHolderComponent) },
|
||||
{ path: 'edit-carnet/:headerid', loadComponent: () => import('./carnet/edit/edit-carnet.component').then(m => m.EditCarnetComponent), canDeactivate: [CarnetCleanupGuard] },
|
||||
{ path: 'view-carnet/:headerid', loadComponent: () => import('./carnet/view/view-carnet.component').then(m => m.ViewCarnetComponent), canDeactivate: [CarnetCleanupGuard] },
|
||||
{ path: 'add-holder', loadComponent: () => import('./holder/add/add-holder.component').then(m => m.AddHolderComponent), canDeactivate: [CarnetCleanupGuard] },
|
||||
{ path: 'edit-holder/:holderid', loadComponent: () => import('./holder/edit/edit-holder.component').then(m => m.EditHolderComponent), canDeactivate: [CarnetCleanupGuard] },
|
||||
{ path: '', redirectTo: 'home', pathMatch: 'full' }
|
||||
],
|
||||
canActivate: [AuthGuard, AppIdGuard]
|
||||
|
||||
@ -54,6 +54,6 @@ export class CarnetService {
|
||||
P_HEADERID: headerid
|
||||
}
|
||||
|
||||
return this.http.post<any>(`${this.apiUrl}/${this.apiDb}//ProcessCarnet`, appData);
|
||||
return this.http.patch<any>(`${this.apiUrl}/${this.apiDb}//ProcessCarnet`, appData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,8 @@ export class UserService {
|
||||
|
||||
private readonly USER_EMAIL_KEY = 'CurrentUserEmail';
|
||||
private readonly USER_DETAILS_KEY = 'CurrentUserData';
|
||||
private readonly CARNET_CLIENTID = 'carnet-clientid';
|
||||
private readonly CARNET_LOCATIONID = 'carnet-locationid';
|
||||
|
||||
private userLoggedInSubject = new BehaviorSubject<boolean>(false);
|
||||
|
||||
@ -101,12 +103,12 @@ export class UserService {
|
||||
|
||||
getUserClientid(): number {
|
||||
const userDetails = this.getUserDetails();
|
||||
return userDetails?.userDetails?.clientid ?? 0;
|
||||
return userDetails?.userDetails?.clientid ?? this.storageService.get(this.CARNET_CLIENTID) ?? 0;
|
||||
}
|
||||
|
||||
getUserLocationid(): number {
|
||||
const userDetails = this.getUserDetails();
|
||||
return userDetails?.userDetails?.locationid ?? 0;
|
||||
return userDetails?.userDetails?.locationid ?? this.storageService.get(this.CARNET_LOCATIONID) ?? 0;
|
||||
}
|
||||
|
||||
private mapToUser(data: any): User {
|
||||
|
||||
@ -38,7 +38,9 @@ export class HomeService {
|
||||
expiryDate: item.EXPDATE || null,
|
||||
orderType: item.ORDERTYPE,
|
||||
carnetStatus: item.CARNETSTATUS,
|
||||
headerid: item.HEADERID
|
||||
headerid: item.HEADERID,
|
||||
clientid: item.CLIENTID,
|
||||
locationid: item.LOCATIONID,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
38
src/app/guards/carnet-cleanup.guard.ts
Normal file
38
src/app/guards/carnet-cleanup.guard.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { CanDeactivateFn } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { StorageService } from '../core/services/common/storage.service';
|
||||
import { inject } from '@angular/core';
|
||||
|
||||
export const CarnetCleanupGuard: CanDeactivateFn<CanComponentDeactivate> = (component, currentRoute, currentState, nextState) => {
|
||||
|
||||
// If the component has a canDeactivate method, call it
|
||||
if (component.canDeactivate) {
|
||||
return component.canDeactivate();
|
||||
}
|
||||
|
||||
const storageService = inject(StorageService);
|
||||
const nextUrl = nextState.url;
|
||||
|
||||
// console.log(`Navigating away. Destination: ${nextUrl}`);
|
||||
|
||||
// If the destination URL includes 'holder/carnet', skip the cleanup and allow navigation.
|
||||
if (nextUrl.includes('edit-carnet') || nextUrl.includes('view-carnet')
|
||||
|| nextUrl.includes('add-holder') || nextUrl.includes('edit-holder')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, perform the cleanup action.
|
||||
storageService.removeItem('carnet-clientid');
|
||||
storageService.removeItem('carnet-locationid');
|
||||
|
||||
// Return true to allow the navigation to complete.
|
||||
return true;
|
||||
};
|
||||
|
||||
export interface CanComponentDeactivate {
|
||||
/**
|
||||
* An optional method that returns true to allow deactivation,
|
||||
* or false (or a Promise/Observable resolving to false) to prevent it.
|
||||
*/
|
||||
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
|
||||
}
|
||||
@ -17,6 +17,7 @@ import * as XLSX from 'xlsx';
|
||||
import { NavigationService } from '../core/services/common/navigation.service';
|
||||
import { ConfirmDialogComponent } from '../shared/components/confirm-dialog/confirm-dialog.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { StorageService } from '../core/services/common/storage.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@ -51,6 +52,7 @@ export class HomeComponent {
|
||||
private notificationService = inject(NotificationService);
|
||||
private commonService = inject(CommonService);
|
||||
private navigationService = inject(NavigationService);
|
||||
private storageService = inject(StorageService);
|
||||
private dialog = inject(MatDialog);
|
||||
|
||||
constructor(userPrefenceService: UserPreferencesService) {
|
||||
@ -166,6 +168,10 @@ export class HomeComponent {
|
||||
|
||||
processCarnet(item: any): void {
|
||||
if (item && item.headerid) {
|
||||
// set the client and location id to storage for later use in carnet processing
|
||||
this.storageService.set("carnet-clientid", item.clientid);
|
||||
this.storageService.set("carnet-locationid", item.locationid);
|
||||
|
||||
this.navigateTo(['edit-carnet', item.headerid], {
|
||||
queryParams: { applicationname: item.applicationName }
|
||||
});
|
||||
@ -176,6 +182,10 @@ export class HomeComponent {
|
||||
|
||||
viewCarnet(item: any): void {
|
||||
if (item && item.headerid) {
|
||||
// set the client and location id to storage for later use in carnet viewing
|
||||
this.storageService.set("carnet-clientid", item.clientid);
|
||||
this.storageService.set("carnet-locationid", item.locationid);
|
||||
|
||||
this.navigateTo(['view-carnet', item.headerid], {
|
||||
queryParams: { applicationname: item.applicationName }
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user