From daac0666f27c088337f02b52d24d2aa8139700cd Mon Sep 17 00:00:00 2001 From: SHENGXING LU Date: Tue, 27 Jan 2026 18:30:22 +0100 Subject: [PATCH 1/2] optional characteristic with default enability implemented --- .../create-product-spec.component.html | 57 ++++---- .../create-product-spec.component.ts | 104 ++++---------- .../update-product-spec.component.html | 69 ++++------ .../update-product-spec.component.ts | 128 +++++------------- .../price-plan-drawer.component.html | 2 +- .../price-plan-drawer.component.ts | 16 ++- src/assets/i18n/en.json | 10 ++ src/assets/i18n/es.json | 8 ++ 8 files changed, 147 insertions(+), 247 deletions(-) diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html index 42c44cdc..e04f4d37 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html @@ -557,34 +557,11 @@

} @else {
- @if(!booleanCharSelected){ -
- - - -
- } @else { -
- @if(nonBooleanChars.length>0){ - - - }@else{ -
- -

There's no characteristic available.

-
- } - -
- } +
+ + +
-
+ +
+ + +
+ @if(isOptional){ +
+ + +
+ }
@if(creatingChars.length>0){ @@ -642,7 +635,7 @@

There's no char }

} - + @if(stringCharSelected){
There's no char
}
-
} @else {
- - @if(!booleanCharSelected){ -
- - - -
- } @else { -
- @if(nonBooleanChars.length>0){ - - - }@else{ -
- -

There's no characteristic available.

-
- } - -
- } +
+ + +
-
-
+ +
+ + +
+ @if(isOptional){ +
+ + +
+ }
@if(creatingChars.length>0){ @@ -754,7 +739,7 @@

There's no char }

} - + @if(stringCharSelected){
There's no char
}
-
diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts index e4405752..aa9fe196 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts @@ -89,12 +89,12 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { stringCharSelected:boolean=true; numberCharSelected:boolean=false; rangeCharSelected:boolean=false; - booleanCharSelected:boolean=false; + isOptional:boolean=false; + optionalDftTrue:boolean=false; prodChars:ProductSpecificationCharacteristic[]=[]; finishChars:ProductSpecificationCharacteristic[]=[]; creatingChars:CharacteristicValueSpecification[]=[]; showCreateChar:boolean=false; - nonBooleanChars:string[]=[]; //BUNDLE INFO: bundleChecked:boolean=false; @@ -381,28 +381,12 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { for(let i=0; i < this.prod.productSpecCharacteristic.length; i++){ const index = this.selectedISOS.findIndex(item => item.name === this.prod.productSpecCharacteristic[i].name); if (index == -1) { - const currentChar = this.prod.productSpecCharacteristic[i]; - const name = currentChar.name; - this.prodChars.push({ id: 'urn:ngsi-ld:characteristic:'+uuidv4(), name: this.prod.productSpecCharacteristic[i].name, description: this.prod.productSpecCharacteristic[i].description ? this.prod.productSpecCharacteristic[i].description : '', productSpecCharacteristicValue: this.prod.productSpecCharacteristic[i].productSpecCharacteristicValue }); - - // Check if it's not a boolean-enabled characteristic - if (!name.endsWith('- enabled')) { - // Look for a corresponding "enabled" version - const hasEnabledVersion = this.prod.productSpecCharacteristic.some( - (item: { name: string; }) => item.name === `${name} - enabled` - ); - - // Only push if there's no "- enabled" variant - if (!hasEnabledVersion) { - this.nonBooleanChars.push(name); - } - } } } } @@ -904,7 +888,6 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { this.stringCharSelected=true; this.numberCharSelected=false; this.rangeCharSelected=false; - this.booleanCharSelected=false; this.showPreview=false; this.refreshChars(); initFlowbite(); @@ -1242,7 +1225,8 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { this.stringCharSelected=true; this.numberCharSelected=false; this.rangeCharSelected=false; - this.booleanCharSelected=false; + this.isOptional=false; + this.optionalDftTrue=false; this.creatingChars=[]; } @@ -1306,36 +1290,23 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { this.stringCharSelected=true; this.numberCharSelected=false; this.rangeCharSelected=false; - this.booleanCharSelected=false; this.charsForm.reset(); }else if (event.target.value=='number'){ this.stringCharSelected=false; this.numberCharSelected=true; this.rangeCharSelected=false; - this.booleanCharSelected=false; this.charsForm.reset(); }else if (event.target.value=='range'){ this.stringCharSelected=false; this.numberCharSelected=false; this.rangeCharSelected=true; - this.booleanCharSelected=false; this.charsForm.reset(); - } else { - this.stringCharSelected=false; - this.numberCharSelected=false; - this.rangeCharSelected=false; - this.booleanCharSelected=true; - // Set default only if not already selected - if (!this.charsForm.get('name')?.value && this.nonBooleanChars.length > 0) { - this.charsForm.get('name')?.setValue(this.nonBooleanChars[0]+' - enabled'); - } } + this.isOptional=false; + this.optionalDftTrue=false; this.creatingChars=[]; } - onSelectBooleanName(event: any){ - this.charsForm.get('name')?.setValue(event.target.value+' - enabled'); - } addCharValue(){ if(this.stringCharSelected){ @@ -1419,21 +1390,8 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { } saveChar(){ - if(this.booleanCharSelected){ - this.creatingChars=[ - { - isDefault:false, - value: true as any - }, - { - isDefault:true, - value:false as any - } - ] - } - if(this.charsForm.value.name!=null){ - console.log('saving char') + // Create the main characteristic this.prodChars.push({ id: 'urn:ngsi-ld:characteristic:'+uuidv4(), name: this.charsForm.value.name, @@ -1441,35 +1399,34 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { productSpecCharacteristicValue: this.creatingChars }) - // Check if it's not a boolean-enabled characteristic - if (!this.charsForm.value.name.endsWith('- enabled')) { - // Look for a corresponding "enabled" version - const hasEnabledVersion = this.prodChars.some( - (item) => item.name === `${name} - enabled` - ); - - // Only push if there's no "- enabled" variant - if (!hasEnabledVersion) { - this.nonBooleanChars.push(this.charsForm.value.name); - } - } else { - const cleanName = this.charsForm.value.name.replace(/- enabled$/, '').trim(); - const nonBooleanIndex = this.nonBooleanChars.findIndex(item => item === cleanName); - if (nonBooleanIndex !== -1) { - console.log('eliminar boolean') - this.nonBooleanChars.splice(nonBooleanIndex, 1); - } + // create X - enabled characteristic + if(this.isOptional){ + this.prodChars.push({ + id: 'urn:ngsi-ld:characteristic:'+uuidv4(), + name: this.charsForm.value.name + ' - enabled', + description: 'Optional toggle for ' + this.charsForm.value.name, + productSpecCharacteristicValue: [ + { + isDefault: this.optionalDftTrue, + value: true as any + }, + { + isDefault: !this.optionalDftTrue, + value:false as any + } + ] + }) } } - console.log('--- value of prodChars after saving') - console.log(this.prodChars) this.charsForm.reset(); this.creatingChars=[]; this.showCreateChar=false; this.stringCharSelected=true; this.numberCharSelected=false; this.rangeCharSelected=false; + this.isOptional=false; + this.optionalDftTrue=false; this.refreshChars(); this.cdr.detectChanges(); } @@ -1479,40 +1436,19 @@ export class UpdateProductSpecComponent implements OnInit, OnDestroy { if (index !== -1) { console.log('eliminar') this.prodChars.splice(index, 1); - } - - - if(!char.name.endsWith('- enabled')){ - const nonBooleanIndex = this.nonBooleanChars.findIndex(item => item === char.name); - if (nonBooleanIndex !== -1) { - console.log('eliminar boolean') - this.nonBooleanChars.splice(nonBooleanIndex, 1); - } + } + + // If deleting a main characteristic, also delete its "- enabled" variant if it exists + if(!char.name.endsWith('- enabled')){ const relatedEnabledIndex = this.prodChars.findIndex(item => item.name === char.name+' - enabled'); if (relatedEnabledIndex !== -1) { - console.log('eliminar') + console.log('eliminar related enabled') this.prodChars.splice(relatedEnabledIndex, 1); } - } else { - const cleanName = char.name.replace(/- enabled$/, '').trim(); - const nonBooleanIndex = this.nonBooleanChars.findIndex(item => item === cleanName); - if (nonBooleanIndex == -1) { - console.log('añadir boolean') - this.nonBooleanChars.push(cleanName) - } - } - - if(this.booleanCharSelected){ - // Set default only if not already selected - if (this.nonBooleanChars.length > 0) { - this.charsForm.get('name')?.setValue(this.nonBooleanChars[0]+' - enabled'); - } else { - this.charsForm.reset(); - } } this.cdr.detectChanges(); - console.log(this.prodChars) + console.log(this.prodChars) } checkInput(value: string): boolean { diff --git a/src/app/shared/price-plan-drawer/price-plan-drawer.component.html b/src/app/shared/price-plan-drawer/price-plan-drawer.component.html index c3f3ceab..2f1c13a8 100644 --- a/src/app/shared/price-plan-drawer/price-plan-drawer.component.html +++ b/src/app/shared/price-plan-drawer/price-plan-drawer.component.html @@ -77,7 +77,7 @@
@if(canBeDisabledChars.includes(ch.id)){ } diff --git a/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts b/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts index dd56db30..d84290bd 100644 --- a/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts +++ b/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts @@ -230,14 +230,26 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy { const defaultValue = characteristic.productSpecCharacteristicValue?.find(val => val.isDefault)?.value ?? characteristic.productSpecCharacteristicValue?.find(val => val.isDefault)?.valueFrom; - + characteristicsGroup.addControl( characteristic.id, this.fb.control(defaultValue ?? null, Validators.required) ); if(!characteristic.name?.endsWith('- enabled') && this.filteredCharacteristics.some((char => char.name === characteristic.name+' - enabled'))){ this.canBeDisabledChars.push(characteristic.id) - this.disabledCharacteristics.push(characteristic.id) + + const enabledChar = this.filteredCharacteristics.find(char => char.name === characteristic.name+' - enabled'); + const defaultEnabledValue = enabledChar?.productSpecCharacteristicValue?.find(val => val.isDefault); + + if (!defaultEnabledValue) { + this.disabledCharacteristics.push(characteristic.id); + } else { + const valueStr = String(defaultEnabledValue.value).toLowerCase(); + if (valueStr === 'false') { + this.disabledCharacteristics.push(characteristic.id); + } + } + // If the default value is true, start enabled } } }); diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 8e6ae113..67389307 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -517,6 +517,10 @@ "_from": "From", "_to": "To", "_save_char": "Save characteristic", + "_make_optional": "Make this characteristic optional", + "_default_value": "Default value", + "_default_false": "Disabled by default", + "_default_true": "Enabled by default", "_resource_specs": "Resource specifications", "_service_specs": "Service specifications", "_add_prod_img": "Add product image", @@ -592,6 +596,10 @@ "_from": "From", "_to": "To", "_save_char": "Save characteristic", + "_make_optional": "Make this characteristic optional", + "_default_value": "Default value", + "_default_false": "Disabled by default", + "_default_true": "Enabled by default", "_resource_specs": "Resource specifications", "_service_specs": "Service specifications", "_add_prod_img": "Add product image", @@ -785,6 +793,7 @@ "_from": "From", "_to": "To", "_save_char": "Save characteristic", + "_make_optional": "Make this characteristic optional", "_resource_specs": "Resource specifications", "_service_specs": "Service specifications", "_add_prod_img": "Add product image", @@ -886,6 +895,7 @@ "_from": "From", "_to": "To", "_save_char": "Save characteristic", + "_make_optional": "Make this characteristic optional", "_resource_specs": "Resource specifications", "_service_specs": "Service specifications", "_add_prod_img": "Add product image", diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json index 8e6ae113..5782d397 100644 --- a/src/assets/i18n/es.json +++ b/src/assets/i18n/es.json @@ -517,6 +517,10 @@ "_from": "From", "_to": "To", "_save_char": "Save characteristic", + "_make_optional": "Make this characteristic optional", + "_default_value": "Default value", + "_default_false": "Disabled by default", + "_default_true": "Enabled by default", "_resource_specs": "Resource specifications", "_service_specs": "Service specifications", "_add_prod_img": "Add product image", @@ -592,6 +596,10 @@ "_from": "From", "_to": "To", "_save_char": "Save characteristic", + "_make_optional": "Make this characteristic optional", + "_default_value": "Default value", + "_default_false": "Disabled by default", + "_default_true": "Enabled by default", "_resource_specs": "Resource specifications", "_service_specs": "Service specifications", "_add_prod_img": "Add product image", From 51d964d5772ce29f3b554d1722148fe02b370931 Mon Sep 17 00:00:00 2001 From: SHENGXING LU Date: Tue, 27 Jan 2026 18:52:09 +0100 Subject: [PATCH 2/2] FIX: enabled chars in price component selection --- .../price-component-drawer/price-component-drawer.component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/shared/forms/offer/price-plans/price-component-drawer/price-component-drawer.component.ts b/src/app/shared/forms/offer/price-plans/price-component-drawer/price-component-drawer.component.ts index b4e0b3fa..4997f1dd 100644 --- a/src/app/shared/forms/offer/price-plans/price-component-drawer/price-component-drawer.component.ts +++ b/src/app/shared/forms/offer/price-plans/price-component-drawer/price-component-drawer.component.ts @@ -63,7 +63,8 @@ export class PriceComponentDrawerComponent implements OnInit { }, 50); for(let i=0;i certification.name === this.prodChars[i].name) && !this.prodChars[i].name.startsWith('Compliance:')) { + if (!certifications.some(certification => certification.name === this.prodChars[i].name) && !this.prodChars[i].name.startsWith('Compliance:') && + !this.prodChars[i].name.endsWith(' - enabled')) { this.filteredChars.push(this.prodChars[i]); } }