Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
<input data-cy="offerVersion" id="prod-version" type="text" [formControl]="versionControl"
class="mb-2 bg-gray-50 dark:bg-secondary-300 border border-gray-300 dark:border-secondary-200 dark:text-white text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
}
@if (extBillingEnabledControl) {
<div class="mb-2 flex items-center gap-3">
<label class="font-bold text-lg dark:text-white">{{ 'CREATE_OFFER._ext_billing' | translate }}</label>
<input data-cy="extBillingToggle" type="checkbox" [formControl]="extBillingEnabledControl"
class="w-4 h-4 text-primary-100 bg-gray-100 border-gray-300 rounded focus:ring-primary-100 dark:focus:ring-primary-50 dark:ring-offset-gray-800 dark:bg-gray-700 dark:border-gray-600"/>
</div>
}
@if (extBillingEnabledControl?.value && plaSpecIdControl) {
<label for="plaSpecId" class="font-bold text-lg dark:text-white">{{ 'CREATE_OFFER._pla_spec_id' | translate }}</label>
<input data-cy="plaSpecId" id="plaSpecId" type="url" [formControl]="plaSpecIdControl"
class="bg-gray-50 dark:bg-secondary-300 border border-gray-300 dark:border-secondary-200 dark:text-white text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
[class.border-red-500]="plaSpecIdControl.invalid && plaSpecIdControl.touched"
placeholder="https://external-billing-engine.example.com"/>
@if (plaSpecIdControl.invalid && plaSpecIdControl.touched) {
<p class="text-red-500 text-sm mt-1 mb-2">{{ 'CREATE_OFFER._pla_spec_id_required' | translate }}</p>
}
}
@if (statusControl && formType === 'update') {
<label class="font-bold text-lg col-span-2 dark:text-white">{{ 'CREATE_OFFER._status' | translate }}</label>
<app-status-selector [formControl]="statusControl"></app-status-selector>
Expand Down
43 changes: 41 additions & 2 deletions src/app/shared/forms/offer/general-info/general-info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface GeneralInfo {
status: string;
description: string;
version: string;
extBillingEnabled: boolean;
plaSpecId: string;
}

@Component({
Expand Down Expand Up @@ -69,23 +71,48 @@ export class GeneralInfoComponent implements OnInit, OnDestroy {
return control instanceof FormControl ? control : null;
}

get extBillingEnabledControl(): FormControl | null {
const control = this.formGroup.get('extBillingEnabled');
return control instanceof FormControl ? control : null;
}

get plaSpecIdControl(): FormControl | null {
const control = this.formGroup.get('plaSpecId');
return control instanceof FormControl ? control : null;
}

ngOnInit() {
console.log('📝 Initializing form in', this.formType, 'mode');
this.isEditMode = this.formType === 'update';

if (this.isEditMode && this.data) {
console.log('Initializing form in update mode with data:', this.data);
const existingPlaSpecId = this.data.pricingLogicAlgorithm?.[0]?.plaSpecId ?? '';
this.formGroup.addControl('name', new FormControl<string>(this.data.name, [Validators.required, Validators.maxLength(100), noWhitespaceValidator]));
this.formGroup.addControl('status', new FormControl<string>(this.data.lifecycleStatus));
this.formGroup.addControl('description', new FormControl<string>(this.data.description, Validators.maxLength(100000)));
this.formGroup.addControl('version', new FormControl<string>(this.data.version, [Validators.required,Validators.pattern('^-?[0-9]\\d*(\\.\\d*)?$'), noWhitespaceValidator]));

this.formGroup.addControl('extBillingEnabled', new FormControl<boolean>(!!existingPlaSpecId));
this.formGroup.addControl('plaSpecId', new FormControl<string>(existingPlaSpecId, !!existingPlaSpecId ? [Validators.required] : []));

this.formGroup.get('extBillingEnabled')!.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((enabled: boolean) => {
const plaControl = this.formGroup.get('plaSpecId')!;
if (enabled) {
plaControl.setValidators([Validators.required]);
} else {
plaControl.clearValidators();
}
plaControl.updateValueAndValidity();
});

// Store original value only in edit mode
this.originalValue = {
name: this.data.name,
status: this.data.lifecycleStatus,
description: this.data.description,
version: this.data.version
version: this.data.version,
extBillingEnabled: !!existingPlaSpecId,
plaSpecId: existingPlaSpecId
};
console.log('📝 Original value stored:', this.originalValue);
} else {
Expand All @@ -94,6 +121,18 @@ export class GeneralInfoComponent implements OnInit, OnDestroy {
this.formGroup.addControl('status', new FormControl<string>('Active', [Validators.required]));
this.formGroup.addControl('description', new FormControl<string>(''));
this.formGroup.addControl('version', new FormControl<string>('0.1', [Validators.required,Validators.pattern('^-?[0-9]\\d*(\\.\\d*)?$'), noWhitespaceValidator]));
this.formGroup.addControl('extBillingEnabled', new FormControl<boolean>(false));
this.formGroup.addControl('plaSpecId', new FormControl<string>(''));

this.formGroup.get('extBillingEnabled')!.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((enabled: boolean) => {
const plaControl = this.formGroup.get('plaSpecId')!;
if (enabled) {
plaControl.setValidators([Validators.required]);
} else {
plaControl.clearValidators();
}
plaControl.updateValueAndValidity();
});
}

// Subscribe to form changes only in edit mode
Expand Down
11 changes: 9 additions & 2 deletions src/app/shared/forms/offer/offer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,6 @@ export class OfferComponent implements OnInit, OnDestroy{
units: component.newValue.usageUnit
};

priceComp['@baseType'] = "ProductOfferingPrice";
priceComp['@schemaLocation'] = "https://raw.githubusercontent.com/laraminones/tmf-new-schemas/main/UsageSpecId.json";
(priceComp as any).usageSpecId = component.newValue.usageSpecId;

console.log('----- here')
Expand Down Expand Up @@ -705,6 +703,10 @@ export class OfferComponent implements OnInit, OnDestroy{
bundledProductOffering: this.offersBundle,
place: [],
version: generalInfo.version,
...(generalInfo.extBillingEnabled && generalInfo.plaSpecId ? {
pricingLogicAlgorithm: [{ name: 'external billing', plaSpecId: generalInfo.plaSpecId }]
} : {}),

category: categories,
productOfferingPrice: prices,
validFor: {
Expand Down Expand Up @@ -818,6 +820,11 @@ export class OfferComponent implements OnInit, OnDestroy{
basePayload.description = change.currentValue.description;
basePayload.version = change.currentValue.version;
basePayload.lifecycleStatus = change.currentValue.status;
if (change.currentValue.extBillingEnabled && change.currentValue.plaSpecId) {
basePayload.pricingLogicAlgorithm = [{ name: 'external billing', plaSpecId: change.currentValue.plaSpecId }];
} else if (change.originalValue.extBillingEnabled && !change.currentValue.extBillingEnabled) {
basePayload.pricingLogicAlgorithm = [];
}
break;

case 'productSpecification':
Expand Down
5 changes: 5 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,9 @@
"_name": "Name",
"_description": "Description",
"_version": "Version",
"_ext_billing": "Set external billing",
"_pla_spec_id": "External billing engine URL",
"_pla_spec_id_required": "External billing engine URL is required",
"_preview": "Preview",
"_show_preview": "Show preview",
"_next": "Next",
Expand Down Expand Up @@ -1936,6 +1939,8 @@
"_name": "Name",
"_description": "Description",
"_version": "Version",
"_ext_billing": "Set external billing",
"_pla_spec_id": "External billing engine URL",
"_preview": "Preview",
"_show_preview": "Show preview",
"_next": "Next",
Expand Down
5 changes: 5 additions & 0 deletions src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,9 @@
"_name": "Name",
"_description": "Description",
"_version": "Version",
"_ext_billing": "Set external billing",
"_pla_spec_id": "External billing engine URL",
"_pla_spec_id_required": "External billing engine URL is required",
"_preview": "Preview",
"_show_preview": "Show preview",
"_next": "Next",
Expand Down Expand Up @@ -1936,6 +1939,8 @@
"_name": "Name",
"_description": "Description",
"_version": "Version",
"_ext_billing": "Set external billing",
"_pla_spec_id": "External billing engine URL",
"_preview": "Preview",
"_show_preview": "Show preview",
"_next": "Next",
Expand Down
Loading