{{ country.paramDesc }}
@@ -17,76 +17,33 @@
- Param Type
-
-
- Param Type is required
-
-
- Maximum 10 characters allowed
-
-
-
-
- Description
-
-
- Param Description is required
-
-
- Maximum 100 characters allowed
-
-
-
-
-
-
-
-
- Additional Value 1
-
-
- Maximum 20 characters allowed
+ Message
+
+
+ Message is required
-
-
-
-
- Additional Value 2
-
-
- Maximum 20 characters allowed
-
-
-
-
- Additional Value 3
-
-
- Maximum 20 characters allowed
-
-
-
-
-
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