Commit b5f28b1b authored by Michail Tzanatos's avatar Michail Tzanatos
Browse files

clean up characteristic selection logic and ensure proper handling of product specification values

parent 43a8ffe1
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -131,11 +131,10 @@ export class EditProductOfferingsComponent implements OnInit {
      fullSpec => {
        this.currentLinkedSpec = fullSpec;
        this.availableSpecCharacteristics = fullSpec.productSpecCharacteristic || [];
        
        if (!isInitialLoad) {
          this.selectedCharacteristics.clear();
          this.selectedCharValues.clear();
          this.selectAllCharacteristics();
          // this.selectAllCharacteristics();
        }

        if (isInitialLoad && this.offering.prodSpecCharValueUse) {
@@ -199,9 +198,9 @@ export class EditProductOfferingsComponent implements OnInit {
  onCharacteristicToggle(char: ProductSpecificationCharacteristicRes, event: MatCheckboxChange) {
    if (event.checked) {
      this.selectedCharacteristics.add(char.name);
      if (!this.selectedCharValues.has(char.name)) {
        this.selectAllValues(char);
      }
      // if (!this.selectedCharValues.has(char.name)) {
      //   this.selectAllValues(char);
      // }
    } else {
      this.selectedCharacteristics.delete(char.name);
    }
@@ -247,7 +246,7 @@ export class EditProductOfferingsComponent implements OnInit {
  selectAllCharacteristics() {
    this.availableSpecCharacteristics.forEach(c => {
      this.selectedCharacteristics.add(c.name);
      this.selectAllValues(c);
      // this.selectAllValues(c);
    });
    this.editForm.markAsDirty();
  }
@@ -292,9 +291,22 @@ export class EditProductOfferingsComponent implements OnInit {
        if (linkedSpec.version) productSpecRef.version = linkedSpec.version;
      }
      
      let characteristicsToSave: any[] = [];

      if (!this.newOffering && this.offering && this.offering.prodSpecCharValueUse) {
        const originalSpecId = this.offering.productSpecification?.id;
        const currentSpecId = linkedSpec?.id;

        if (originalSpecId === currentSpecId) {
          characteristicsToSave = this.offering.prodSpecCharValueUse;
        } else {
          characteristicsToSave = [];
        }
      }

      const updateObj: ProductOfferingCreate | ProductOfferingUpdate = {
        name: formValue.name,
        description: formValue.description,
        description: formValue.description || '',
        lifecycleStatus: formValue.lifecycleStatus,
        version: formValue.version,
        validFor: {"startDateTime": formValue.validFor.startDateTime, "endDateTime": formValue.validFor.endDateTime},
@@ -305,7 +317,7 @@ export class EditProductOfferingsComponent implements OnInit {
        isBundle: linkedSpec?.isBundle || false,
        attachment: linkedSpec?.attachment || [],
        
        prodSpecCharValueUse: [], 
        prodSpecCharValueUse: characteristicsToSave, 

        serviceCandidate: (linkedSpec && (linkedSpec as any).serviceSpecification && (linkedSpec as any).serviceSpecification.length > 0) 
          ? {