From ca9397894efae92635ee02ec1352f2ee08a5c90e Mon Sep 17 00:00:00 2001 From: Cyril Joseph Date: Mon, 4 Aug 2025 21:39:43 -0300 Subject: [PATCH] param and home updates --- .../secured-header.component.html | 2 +- src/app/core/models/param/country-message.ts | 6 + src/app/core/models/param/parameters.ts | 24 +-- src/app/core/services/home.service.ts | 22 +- src/app/home/home.component.html | 6 +- src/app/home/home.component.ts | 22 +- .../manage-country.component.html | 101 +++------ .../manage-country.component.scss | 5 +- .../manage-country.component.ts | 200 ++++++++++++------ 9 files changed, 227 insertions(+), 161 deletions(-) create mode 100644 src/app/core/models/param/country-message.ts diff --git a/src/app/common/secured-header/secured-header.component.html b/src/app/common/secured-header/secured-header.component.html index ce0ba80..8b2d83e 100644 --- a/src/app/common/secured-header/secured-header.component.html +++ b/src/app/common/secured-header/secured-header.component.html @@ -14,7 +14,7 @@ - + diff --git a/src/app/core/models/param/country-message.ts b/src/app/core/models/param/country-message.ts new file mode 100644 index 0000000..9ab703f --- /dev/null +++ b/src/app/core/models/param/country-message.ts @@ -0,0 +1,6 @@ +import { ParamProperties } from "./parameters"; + +export interface CountryMessage extends ParamProperties { + countryMessage: string | null; + isInactive: boolean; +} diff --git a/src/app/core/models/param/parameters.ts b/src/app/core/models/param/parameters.ts index f930ab6..43f174d 100644 --- a/src/app/core/models/param/parameters.ts +++ b/src/app/core/models/param/parameters.ts @@ -5,18 +5,18 @@ export interface ParamProperties { paramType: string; paramDesc: string; paramValue: string; - addlParamValue1: string | null; - addlParamValue2: string | null; - addlParamValue3: string | null; - addlParamValue4: string | null; - addlParamValue5: string | null; + addlParamValue1?: string | null; + addlParamValue2?: string | null; + addlParamValue3?: string | null; + addlParamValue4?: string | null; + addlParamValue5?: string | null; sortSeq?: number; - inactiveCodeFlag: 'Y' | 'N' | null; - inactiveDate: string | null; - createdBy: string; - dateCreated: string; - lastUpdatedBy: string | null; - lastUpdatedDate: string | null; - errorMesg: string | null; + inactiveCodeFlag?: 'Y' | 'N' | null; + inactiveDate?: string | null; + createdBy?: string; + dateCreated?: string; + lastUpdatedBy?: string | null; + lastUpdatedDate?: string | null; + errorMesg?: string | null; userId?: string; } diff --git a/src/app/core/services/home.service.ts b/src/app/core/services/home.service.ts index 4ba6f9f..76a8eb8 100644 --- a/src/app/core/services/home.service.ts +++ b/src/app/core/services/home.service.ts @@ -38,15 +38,31 @@ export class HomeService { expiryDate: item.EXPDATE || null, orderType: item.ORDERTYPE, carnetStatus: item.CARNETSTATUS, - HEADERID: item.HEADERID + headerid: item.HEADERID })); } deleteCarnet(headerid: number): Observable { - return this.http.patch(`${this.apiUrl}/${this.apiDb}/ReactivateClientContacts/${this.userService.getUserSpid()}/${headerid}/${this.userService.getUser()}`, null); + const data = { + P_USERID: this.userService.getUser(), + P_HEADERID: headerid + } + return this.http.delete(`${this.apiUrl}/${this.apiDb}/DeleteCarnet`, { body: data }); } resetCarnet(headerid: number): Observable { - return this.http.patch(`${this.apiUrl}/${this.apiDb}/ReactivateClientContacts/${this.userService.getUserSpid()}/${headerid}/${this.userService.getUser()}`, null); + const data = { + P_USERID: this.userService.getUser(), + P_HEADERID: headerid + } + return this.http.patch(`${this.apiUrl}/${this.apiDb}/ResetCarnet`, data); + } + + printCarnet(headerid: number): Observable { + const data = { + P_USERID: this.userService.getUser(), + P_HEADERID: headerid + } + return this.http.patch(`${this.apiUrl}/${this.apiDb}/UpdatePrintCarnet`, data); } } diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 72be847..32d8eb7 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -99,19 +99,19 @@ matTooltip="View"> article - - - - - + + diff --git a/src/app/param/manage-country/manage-country.component.scss b/src/app/param/manage-country/manage-country.component.scss index a564d2b..d22a3aa 100644 --- a/src/app/param/manage-country/manage-country.component.scss +++ b/src/app/param/manage-country/manage-country.component.scss @@ -12,10 +12,7 @@ } .form-container { - background-color: white; - padding: 24px; - border-radius: 8px; - margin-top: 16px; + margin-top: 0.5rem; .form-header { margin-bottom: 24px; diff --git a/src/app/param/manage-country/manage-country.component.ts b/src/app/param/manage-country/manage-country.component.ts index 8fcb78d..5d5bf2b 100644 --- a/src/app/param/manage-country/manage-country.component.ts +++ b/src/app/param/manage-country/manage-country.component.ts @@ -1,13 +1,16 @@ import { CommonModule } from '@angular/common'; import { Component, inject } from '@angular/core'; import { ReactiveFormsModule, FormGroup, Validators, FormBuilder } from '@angular/forms'; -import { finalize } from 'rxjs'; +import { finalize, forkJoin } from 'rxjs'; import { ParamProperties } from '../../core/models/param/parameters'; import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service'; import { NotificationService } from '../../core/services/common/notification.service'; import { ParamService } from '../../core/services/param/param.service'; import { AngularMaterialModule } from '../../shared/module/angular-material.module'; import { MatSelectChange } from '@angular/material/select'; +import { CountryMessage } from '../../core/models/param/country-message'; +import { MatDialog } from '@angular/material/dialog'; +import { ConfirmDialogComponent } from '../../shared/components/confirm-dialog/confirm-dialog.component'; @Component({ selector: 'app-manage-country', @@ -16,35 +19,33 @@ import { MatSelectChange } from '@angular/material/select'; styleUrl: './manage-country.component.scss' }) export class ManageCountryComponent { - isLoading: boolean = false; changeInProgress: boolean = false; - countries: ParamProperties[] = []; - currentCountryId: number | null = null; - currentCountry: ParamProperties | undefined | null = null; - currentParamid: number | null = null; + countries: CountryMessage[] = []; + countriesWithMessages: ParamProperties[] = []; + currentCountryId: number = 0; + currentCountry: CountryMessage | undefined | null = null; private paramService = inject(ParamService); private errorHandler = inject(ApiErrorHandlerService); private notificationService = inject(NotificationService); private fb = inject(FormBuilder); + private dialog = inject(MatDialog); countryForm: FormGroup; + paramReadOnlyFields: any = { + actionType: null, + action: null + }; + constructor() { this.countryForm = this.initializeForm(); } initializeForm(): FormGroup { return this.fb.group({ - paramType: ['', [Validators.required, Validators.maxLength(10)]], - paramValue: ['', [Validators.required, Validators.maxLength(20)]], - paramDesc: ['', [Validators.required, Validators.maxLength(100)]], - addlParamValue1: ['', [Validators.maxLength(20)]], - addlParamValue2: ['', [Validators.maxLength(20)]], - addlParamValue3: ['', [Validators.maxLength(20)]], - addlParamValue4: ['', [Validators.maxLength(20)]], - addlParamValue5: ['', [Validators.maxLength(20)]], + countryMessage: ['', [Validators.required]] }); } @@ -53,29 +54,31 @@ export class ManageCountryComponent { } onCountrySelectionChanged(event: MatSelectChange) { - console.log(event); this.currentCountry = this.countries.find(c => c.paramId === +event.value); - this.currentCountryId = this.currentCountry?.paramId ?? 0; + + this.currentCountryId = this.countriesWithMessages. + find(c => c.paramValue === this.currentCountry?.paramValue)?.paramId ?? 0; this.patchCountryData(); } getCountries(): void { this.isLoading = true; - this.paramService.getParameters('014').pipe(finalize(() => { + + forkJoin({ + countries: this.paramService.getParameters('002'), + countriesWithMessages: this.paramService.getParameters('014') + }).pipe(finalize(() => { this.isLoading = false; })).subscribe({ - next: (paramData: ParamProperties[]) => { - this.countries = paramData; - this.currentCountry = this.countries.find(c => c.paramValue === 'US'); - this.currentCountryId = this.currentCountry?.paramId ?? 0; - - this.patchCountryData(); + next: (results) => { + this.countries = this.joinCountriesWithMessages(results.countries, results.countriesWithMessages); + this.countriesWithMessages = results.countriesWithMessages; }, - error: (error: any) => { - let errorMessage = this.errorHandler.handleApiError(error, 'Failed to get countries'); + error: (error) => { + console.error('Error loading countries messages data', error); + let errorMessage = this.errorHandler.handleApiError(error, 'Failed to load countries messages data'); this.notificationService.showError(errorMessage); - console.error('Error loading countries :', error); } }); } @@ -86,15 +89,11 @@ export class ManageCountryComponent { } this.countryForm.patchValue({ - paramType: this.currentCountry.paramType, - paramValue: this.currentCountry.paramValue, - paramDesc: this.currentCountry.paramDesc, - addlParamValue1: this.currentCountry.addlParamValue1, - addlParamValue2: this.currentCountry.addlParamValue2, - addlParamValue3: this.currentCountry.addlParamValue3, - addlParamValue4: this.currentCountry.addlParamValue4, - addlParamValue5: this.currentCountry.addlParamValue5 + countryMessage: this.currentCountry.countryMessage }); + + this.paramReadOnlyFields.actionType = this.currentCountry.addlParamValue1; + this.paramReadOnlyFields.action = this.currentCountry.addlParamValue2; } saveRecord(): void { @@ -103,11 +102,17 @@ export class ManageCountryComponent { return; } - const paramData: ParamProperties = this.countryForm.value; - paramData.paramId = this.currentParamid ?? 0; - paramData.sortSeq = 1; + const paramData: ParamProperties = { + paramDesc: this.countryForm.value.countryMessage, + paramType: '014', + paramValue: this.currentCountry?.paramValue ?? '', + sortSeq: 1, + paramId: this.currentCountryId ?? 0 + }; - const saveObservable = this.paramService.updateParamRecord(paramData as ParamProperties); + const saveObservable = this.currentCountryId > 0 + ? this.paramService.updateParamRecord(paramData) + : this.paramService.createParamRecord(paramData); this.changeInProgress = true; saveObservable.pipe(finalize(() => { @@ -115,6 +120,7 @@ export class ManageCountryComponent { })).subscribe({ next: () => { this.notificationService.showSuccess(`Country message updated successfully`); + this.getCountries(); }, error: (error) => { let errorMessage = this.errorHandler.handleApiError(error, `Failed to update country message`); @@ -124,33 +130,103 @@ export class ManageCountryComponent { }); } - inActivateParamRecord(paramId: number): void { - this.paramService.inActivateParamRecord(paramId).subscribe( - { - next: (data: any) => { - this.notificationService.showSuccess(`Country message inactivated successfully`); - }, - error: (error: any) => { - let errorMessage = this.errorHandler.handleApiError(error, `Failed to inactivate country message`); - this.notificationService.showError(errorMessage); - console.error('Error inactivating country message:', error); - } + inActivateParamRecord(): void { + if (this.currentCountryId === 0) { + this.notificationService.showError('Not a valid country to inactivate'); + return; + } + + const dialogRef = this.dialog.open(ConfirmDialogComponent, { + width: '350px', + data: { + title: 'Inactivate Country Message', + message: 'Are you sure you want to inactivate this message?', + confirmText: 'Yes', + cancelText: 'Cancel' } - ); + }); + + dialogRef.afterClosed().subscribe(result => { + if (result) { + this.paramService.inActivateParamRecord(this.currentCountryId).subscribe( + { + next: (data: any) => { + this.notificationService.showSuccess(`Country message inactivated successfully`); + }, + error: (error: any) => { + let errorMessage = this.errorHandler.handleApiError(error, `Failed to inactivate country message`); + this.notificationService.showError(errorMessage); + console.error('Error inactivating country message:', error); + } + } + ); + } + }); } - reActivateParamRecord(paramId: number): void { - this.paramService.reActivateParamRecord(paramId).subscribe( - { - next: (data: any) => { - this.notificationService.showSuccess(`Country message reactivated successfully`); - }, - error: (error: any) => { - let errorMessage = this.errorHandler.handleApiError(error, `Failed to reactivate country message`); - this.notificationService.showError(errorMessage); - console.error('Error reactivating country message:', error); - } + reActivateParamRecord(): void { + if (this.currentCountryId === 0) { + this.notificationService.showError('Not a valid country to reactivate'); + return; + } + const dialogRef = this.dialog.open(ConfirmDialogComponent, { + width: '350px', + data: { + title: 'Reactivate Country Message', + message: 'Are you sure you want to reactivate this message?', + confirmText: 'Yes', + cancelText: 'Cancel' } - ); + }); + + dialogRef.afterClosed().subscribe(result => { + if (result) { + this.paramService.reActivateParamRecord(this.currentCountryId).subscribe( + { + next: (data: any) => { + this.notificationService.showSuccess(`Country message reactivated successfully`); + }, + error: (error: any) => { + let errorMessage = this.errorHandler.handleApiError(error, `Failed to reactivate country message`); + this.notificationService.showError(errorMessage); + console.error('Error reactivating country message:', error); + } + } + ); + } + }); + } + + joinCountriesWithMessages(countries: ParamProperties[], countryMessages: ParamProperties[]): CountryMessage[] { + // Group messages by paramvalue + const messagesByCountry = countryMessages.reduce((acc, message) => { + if (!acc[message.paramValue]) { + acc[message.paramValue] = { + messages: [], + // paramId: message.paramId, // Store one paramid from messages + isInactive: message.inactiveCodeFlag === 'N' + }; + } + acc[message.paramValue].messages.push(message.paramDesc); + return acc; + }, {} as Record); + + // Join countries with their messages + return countries.map(country => { + const countryMessages = messagesByCountry[country.paramValue] || { + messages: [], //paramId: null, + isInactive: false + }; + + return { + ...country, + countryMessage: countryMessages.messages.join(' '), + isInactive: countryMessages.isInactive, + paramType: '014', + }; + }); } } \ No newline at end of file