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

refactor product order management components to replace service order...

refactor product order management components to replace service order references with product order references, update UI elements, and enhance functionality for product specifications and order items.
parent 8e6584e9
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
import { Component, OnInit, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ServiceOrder } from 'src/app/openApis/serviceOrderingManagement/models';
import { ProductOrder } from 'src/app/openApis/productOrderingManagement/models';
import { DeleteProductSpecsComponent } from 'src/app/p_product/admin/productCatalogManagement/delete-product-specs/delete-product-specs.component';
import { ServiceOrderService } from 'src/app/openApis/serviceOrderingManagement/services';
import { ProductOrderService } from 'src/app/openApis/productOrderingManagement/services';

@Component({
  selector: 'app-delete-product-order',
@@ -12,9 +12,9 @@ import { ServiceOrderService } from 'src/app/openApis/serviceOrderingManagement/
export class DeleteProductOrderComponent implements OnInit {

  constructor(
    @Inject(MAT_DIALOG_DATA) public data: ServiceOrder,
    @Inject(MAT_DIALOG_DATA) public data: ProductOrder,
    private dialogRef: MatDialogRef<DeleteProductSpecsComponent>,
    private serviceOrderService: ServiceOrderService
    private productOrderService: ProductOrderService

  ) { }

@@ -23,7 +23,7 @@ export class DeleteProductOrderComponent implements OnInit {

  confirmDelete() { 
    // this.dialogRef.close('deleted')
    this.serviceOrderService.deleteServiceOrder(this.data.id).subscribe(
    this.productOrderService.deleteProductOrder({ id: this.data.id }).subscribe(
      data => {},
      error => {this.dialogRef.close(error); console.error(error)},
      () => this.dialogRef.close('deleted')
+1 −1
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ export class ListProductOrdersComponent implements OnInit {
  }

  handleEventClick(clickInfo: EventClickArg) {
    this.router.navigate([`services/service_order/${clickInfo.event.extendedProps.id}`]); 
    this.router.navigate([`products/product_order/${clickInfo.event.extendedProps.id}`]); 
  }

  handleEvents(events: EventApi[]) {
+7 −7
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@
        <i class="fa fa-tasks mr-2"></i>
        <span>Edit Order Item's Service Specification Characteristics</span>
    </h4> -->
    <div  *ngIf="serviceSpec && orderItem" class="service-spec-container">
    <div  *ngIf="productSpec && orderItem" class="service-spec-container">
        <div *ngIf="confSpecCharacteristics.length === 0 && nonConfSpecCharacteristics.length === 0" class="mt-3" [@fadeIn]>
            <i>This service does not contain any configurable characteristics</i>
            <i>This product does not contain any configurable characteristics</i>
        </div>

        <div formArray = "confSpecFormArray" *ngIf="confSpecCharacteristics.length > 0" [@fadeIn]>
@@ -63,7 +63,7 @@
                            <mat-label>Custom Value</mat-label>
                            <mat-select formControlName="value" multiple [compareWith]="compareFn">
                                <mat-option
                                    *ngFor="let charValue of confSpecCharacteristics[i].serviceSpecCharacteristicValue"
                                    *ngFor="let charValue of confSpecCharacteristics[i].productSpecCharacteristicValue"
                                    [value]="charValue.value">
                                    {{charValue.value.alias}}</mat-option>
                            </mat-select>
@@ -75,7 +75,7 @@
                            <mat-label>Custom Value</mat-label>
                            <mat-select formControlName="value" [compareWith]="compareFn">
                                <mat-option
                                    *ngFor="let charValue of confSpecCharacteristics[i].serviceSpecCharacteristicValue"
                                    *ngFor="let charValue of confSpecCharacteristics[i].productSpecCharacteristicValue"
                                    [value]="charValue.value">
                                    {{charValue.value.alias}}</mat-option>
                            </mat-select>
@@ -183,7 +183,7 @@
                            <mat-label>Custom Value</mat-label>
                            <mat-select formControlName="value" [compareWith]="compareFn" multiple>
                                <mat-option
                                    *ngFor="let charValue of nonConfSpecCharacteristics[i].serviceSpecCharacteristicValue"
                                    *ngFor="let charValue of nonConfSpecCharacteristics[i].productSpecCharacteristicValue"
                                    [value]="charValue.value">
                                    {{charValue.value.alias}}</mat-option>
                            </mat-select>
@@ -195,7 +195,7 @@
                            <mat-label>Custom Value</mat-label>
                            <mat-select formControlName="value" [compareWith]="compareFn">
                                <mat-option
                                    *ngFor="let charValue of nonConfSpecCharacteristics[i].serviceSpecCharacteristicValue"
                                    *ngFor="let charValue of nonConfSpecCharacteristics[i].productSpecCharacteristicValue"
                                    [value]="charValue.value">
                                    {{charValue.value.alias}}</mat-option>
                            </mat-select>
@@ -210,7 +210,7 @@
        
    </div>

    <div *ngIf="!serviceSpec" class="spinner-container">
    <div *ngIf="!productSpec" class="spinner-container">
        <mat-progress-spinner color="primary" mode="indeterminate" diameter="100"></mat-progress-spinner>
    </div>

+41 −28
Original line number Diff line number Diff line
import { Component, OnInit, Inject, Input, Output, EventEmitter } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ServiceSpecificationService } from 'src/app/openApis/serviceCatalogManagement/services';
import { ProductSpecificationService } from 'src/app/openApis/productCatalogManagement/services';
import { ToastrService } from 'ngx-toastr';
import { ServiceOrderItem } from 'src/app/openApis/serviceOrderingManagement/models';
import { ProductOrderItem } from 'src/app/openApis/productOrderingManagement/models';
import { UntypedFormArray, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
import { ServiceSpecification, ServiceSpecCharacteristic } from 'src/app/openApis/serviceCatalogManagement/models';
import { ProductSpecification, ProductSpecificationCharacteristicRes } from 'src/app/openApis/productCatalogManagement/models';
import { SortingService } from 'src/app/shared/functions/sorting.service';
import { trigger } from '@angular/animations';
import { fadeIn, simpleFade } from 'src/app/shared/animations/animations';
@@ -24,7 +24,7 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {

  constructor(
    private dialogRef: MatDialogRef<EditOrdersProductSpecCharacteristicsComponent>,
    private specService: ServiceSpecificationService,
    private specService: ProductSpecificationService,
    private toastr: ToastrService,
    private sortingService: SortingService,
    private authService: AuthService
@@ -32,29 +32,29 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {

  isAdminUser: boolean = false

  @Input() set _activeListItem(activeItem: {orderItem: ServiceOrderItem,  serviceSpec: ServiceSpecification}) {
  @Input() set _activeListItem(activeItem: {orderItem: ProductOrderItem,  productSpec: ProductSpecification}) {
    this.orderItem = activeItem.orderItem
    this.serviceSpec = activeItem.serviceSpec
    this.productSpec = activeItem.productSpec
    this.isAdminUser = this.authService.portalUserJWT.realm_access.roles.includes('ADMIN')
    this.initValuesForm()
  }
  @Output() characteristicsWasEdited = new EventEmitter<{orderItemID: string, serviceSpecChars:[]}>()
  @Output() characteristicsWasEdited = new EventEmitter<{orderItemID: string, productSpecChars:[]}>()

  orderItem: ServiceOrderItem
  serviceSpec: ServiceSpecification
  orderItem: ProductOrderItem
  productSpec: ProductSpecification
  
  confSpecFormArray = new UntypedFormArray([])
  nonConfSpecFormArray = new UntypedFormArray([])

  confSpecCharacteristics: ServiceSpecCharacteristic[] = []
  nonConfSpecCharacteristics: ServiceSpecCharacteristic[] = []
  confSpecCharacteristics: ProductSpecificationCharacteristicRes[] = []
  nonConfSpecCharacteristics: ProductSpecificationCharacteristicRes[] = []

  ngOnInit() {  }

  retrieveServiceSpec() {
    this.specService.retrieveServiceSpecification({id: this.orderItem.service.serviceSpecification.id}).subscribe(
      data => { this.serviceSpec = data },
      error => this.toastr.error("An error occurred retrieving Service Specification Characteristics information"),
  retrieveProductSpec() {
    this.specService.retrieveProductSpecification({id: this.orderItem.product.productSpecification.id}).subscribe(
      data => { this.productSpec = data },
      error => this.toastr.error("An error occurred retrieving Product Specification Characteristics information"),
      () => {
        this.initValuesForm()
      }
@@ -68,11 +68,11 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {
    const confSpecFA = this.confSpecFormArray as UntypedFormArray
    const nonConfSpecFA = this.nonConfSpecFormArray as UntypedFormArray

    this.confSpecCharacteristics = this.serviceSpec.serviceSpecCharacteristic.filter(specChar => {return specChar.configurable && this.orderItem.service.serviceCharacteristic.some( item => item.name === specChar.name) } )
    this.confSpecCharacteristics = this.productSpec.productSpecCharacteristic.filter(specChar => {return specChar.configurable && this.orderItem.product.productCharacteristic.some( item => item.name === specChar.name) } )
    this.confSpecCharacteristics.sort(this.sortingService.ascStringSortingFunctionByNameProperty())
    
    if (this.isAdminUser) {
      this.nonConfSpecCharacteristics = this.serviceSpec.serviceSpecCharacteristic.filter(specChar => {return !specChar.configurable && this.orderItem.service.serviceCharacteristic.some( item => item.name === specChar.name) })
      this.nonConfSpecCharacteristics = this.productSpec.productSpecCharacteristic.filter(specChar => {return !specChar.configurable && this.orderItem.product.productCharacteristic.some( item => item.name === specChar.name) })
      this.nonConfSpecCharacteristics.sort(this.sortingService.ascStringSortingFunctionByNameProperty())
    }

@@ -85,24 +85,37 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {
    })    
  }

  updateFormArrayItem( specChar: ServiceSpecCharacteristic, specCharList: ServiceSpecCharacteristic[]): UntypedFormGroup {
  updateFormArrayItem(specChar: ProductSpecificationCharacteristicRes, specCharList: ProductSpecificationCharacteristicRes[]): UntypedFormGroup {
    
    const orderedServiceCharacteristic = this.orderItem.service.serviceCharacteristic.find(char => char.name === specChar.name)
    const orderedServiceCharacteristic = this.orderItem.product.productCharacteristic.find(char => char.name === specChar.name);

    let charValueArray = orderedServiceCharacteristic.value
    let charValueArray = orderedServiceCharacteristic ? orderedServiceCharacteristic.value : null;

    if (['SET', 'ARRAY', 'ENUMERABLE'].includes(this.orderItem.service.serviceCharacteristic.find(char => char.name === specChar.name).valueType)) {
      charValueArray = JSON.parse(orderedServiceCharacteristic.value.value)
    if (['SET', 'ARRAY', 'ENUMERABLE'].includes(specChar.valueType)) {
      
      if (typeof charValueArray === 'string') {
        try {
          charValueArray = JSON.parse(charValueArray);
        } catch (e) {
          console.error('Error parsing JSON for characteristic:', specChar.name, e);
          charValueArray = []; 
        }
      }

      
      if (!Array.isArray(charValueArray)) {
        charValueArray = [];
      }
    }

    return new UntypedFormGroup({
      name: new UntypedFormControl(specChar.name),
      valueType: new UntypedFormControl(specChar.valueType),
      value: new UntypedFormControl(charValueArray)
    })
    });
  }

  addToArrayCharacteristicValue(characteristic: ServiceSpecCharacteristic) {
  addToArrayCharacteristicValue(characteristic: ProductSpecificationCharacteristicRes) {
    this.confSpecFormArray.value.concat(this.nonConfSpecFormArray.value).find(char => char.name === characteristic.name).value.push(
      {
        value: '',
@@ -111,7 +124,7 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {
    )
  }

  deleteFromArrayCharacteristicValue(characteristic: ServiceSpecCharacteristic, index) {
  deleteFromArrayCharacteristicValue(characteristic: ProductSpecificationCharacteristicRes, index) {
    this.confSpecFormArray.value.concat(this.nonConfSpecFormArray.value).find(char => char.name === characteristic.name).value.splice(index, 1)
  }

@@ -145,7 +158,7 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {

    this.characteristicsWasEdited.emit({
      orderItemID: this.orderItem.id,
      serviceSpecChars: editedCharsFA
      productSpecChars: editedCharsFA
    })
  }

+4 −4
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
<div class="container-fluid">
    <h4 mat-dialog-title class="shadowed mb-3">
        <i class="fa fa-tasks mr-2"></i>
        <span>Edit Specification Characteristics of Selected Order Items' allocated Services </span>
        <span>Edit Specification Characteristics of Selected Order Items' allocated Offerings </span>
    </h4>
    <!-- <div> -->
<!-- 
@@ -17,16 +17,16 @@

    <mat-tab-group (selectedTabChange)="changeTab($event)" >
        
        <mat-tab [label]="item.service.serviceSpecification.name"
        <mat-tab [label]="item.product.productSpecification.name"
            *ngFor="let item of selectedOrderItems; let itemIndex = index" > 

                <mat-dialog-content style="margin: 0;">
    
                        <!-- <app-edit-orders-product-spec-characteristics 
                        <app-edit-orders-product-spec-characteristics 
                            *ngIf="activeTabIndex === itemIndex"
                            (characteristicsWasEdited) = "orderItemCharsEdited($event)"
                            [_activeListItem]="activeListItem">
                        </app-edit-orders-product-spec-characteristics> -->
                        </app-edit-orders-product-spec-characteristics>
                    
                        <div *ngIf="activeTabIndex !== itemIndex" class="spinner-container">
                            <mat-progress-spinner color="primary" mode="indeterminate" diameter="100"></mat-progress-spinner>
Loading