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

update UI elements, and enhance functionality for product offerings and order items

parent 53cf1670
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
        <i class="fa fa-tasks mr-2"></i>
        <span>Edit Order Item's Service Specification Characteristics</span>
    </h4> -->
    <div  *ngIf="productSpec && orderItem" class="service-spec-container">
    <div  *ngIf="productOffering && orderItem" class="service-spec-container">
        <div *ngIf="confSpecCharacteristics.length === 0" class="mt-3" [@fadeIn]>
            <i>This product does not contain any configurable characteristics</i>
        </div>
@@ -131,7 +131,7 @@
        
    </div>

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

+12 −12
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 { ProductSpecificationService } from 'src/app/openApis/productCatalogManagement/services';
import { ProductOfferingService } from 'src/app/openApis/productCatalogManagement/services';
import { ToastrService } from 'ngx-toastr';
import { ProductOrderItem } from 'src/app/openApis/productOrderingManagement/models';
import { UntypedFormArray, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
import { ProductSpecification, ProductSpecificationCharacteristicRes } from 'src/app/openApis/productCatalogManagement/models';
import { ProductOffering, ProductSpecificationCharacteristicRes, ProductSpecificationCharacteristicValueUseReq, ProductSpecificationCharacteristicValueUseRes } 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: ProductSpecificationService,
    private offeringService: ProductOfferingService,
    private toastr: ToastrService,
    private sortingService: SortingService,
    private authService: AuthService
@@ -32,16 +32,16 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {

  isAdminUser: boolean = false

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

  orderItem: ProductOrderItem
  productSpec: ProductSpecification
  productOffering: ProductOffering
  
  confSpecFormArray = new UntypedFormArray([])

@@ -50,8 +50,8 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {
  ngOnInit() {  }

  retrieveProductSpec() {
    this.specService.retrieveProductSpecification({id: this.orderItem.product.productSpecification.id}).subscribe(
      data => { this.productSpec = data },
    this.offeringService.retrieveProductOffering({id: this.orderItem.productOffering.id}).subscribe(
      data => { this.productOffering = data },
      error => this.toastr.error("An error occurred retrieving Product Specification Characteristics information"),
      () => {
        this.initValuesForm()
@@ -64,7 +64,7 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {

    const confSpecFA = this.confSpecFormArray as UntypedFormArray

    this.confSpecCharacteristics = this.productSpec.productSpecCharacteristic.filter(specChar => {return specChar.configurable && this.orderItem.product.productCharacteristic.some( item => item.name === specChar.name) } )
    this.confSpecCharacteristics = this.productOffering.prodSpecCharValueUse.filter(specChar => {return specChar && this.orderItem.product.productCharacteristic.some( item => item.name === specChar.name) } ) || []
    this.confSpecCharacteristics.sort(this.sortingService.ascStringSortingFunctionByNameProperty())
    
    
@@ -76,7 +76,7 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {
    
  }

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

@@ -93,7 +93,7 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {
    })
  }

  addToArrayCharacteristicValue(characteristic: ProductSpecificationCharacteristicRes) {
  addToArrayCharacteristicValue(characteristic: ProductSpecificationCharacteristicValueUseRes) {
    const charControl = this.confSpecFormArray.value.find(char => char.name === characteristic.name);
    if (charControl) {
      charControl.value.push({
@@ -103,7 +103,7 @@ export class EditOrdersProductSpecCharacteristicsComponent implements OnInit {
    }
  }

  deleteFromArrayCharacteristicValue(characteristic: ProductSpecificationCharacteristicRes, index) {
  deleteFromArrayCharacteristicValue(characteristic: ProductSpecificationCharacteristicValueUseRes, index) {
    const charControl = this.confSpecFormArray.value.find(char => char.name === characteristic.name);
    if (charControl) {
      charControl.value.splice(index, 1);
+11 −11
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MatTabChangeEvent } from '@angular/material/tabs';
import { ProductOrderItem, ProductOrderUpdate } from 'src/app/openApis/productOrderingManagement/models';
import { forkJoin } from 'rxjs';
import { ProductSpecification } from 'src/app/openApis/productCatalogManagement/models';
import { ProductSpecificationService } from 'src/app/openApis/productCatalogManagement/services';
import { ProductOffering, ProductSpecification } from 'src/app/openApis/productCatalogManagement/models';
import { ProductOfferingService, ProductSpecificationService } from 'src/app/openApis/productCatalogManagement/services';

@Component({
  selector: 'app-edit-product-order-items',
@@ -16,36 +16,36 @@ export class EditProductOrderItemsComponent implements OnInit {
  constructor(
    @Inject(MAT_DIALOG_DATA) public selectedOrderItems: ProductOrderItem[],
    private dialogRef: MatDialogRef<EditProductOrderItemsComponent>,
    private specService: ProductSpecificationService
    private offeringService: ProductOfferingService
  ) { }

  activeListItem: {
    orderItem: ProductOrderItem
    productSpec: ProductSpecification
    productOffering: ProductOffering
  }
  selectedItemsProductSpecs: ProductSpecification[]
  selectedItemsProductOfferings: ProductOffering[]
  activeTabIndex: number 

  editedOrderItems: {orderItemID: string, productSpecChars:[]}[] = []

  ngOnInit() {
    // this.activeListItem = this.selectedOrderItems[0]
    this.retrieveSpecsFromOrderItems()
    this.retrieveOfferingFromOrderItems()
  }

  retrieveSpecsFromOrderItems() {
  retrieveOfferingFromOrderItems() {
    let productSpecs$ = []
    this.selectedOrderItems.forEach( item => {
      productSpecs$.push(this.specService.retrieveProductSpecification({id: item.product.productSpecification.id}))
      productSpecs$.push(this.offeringService.retrieveProductOffering({id: item.productOffering.id}))
    })

    forkJoin(productSpecs$).subscribe(
      data => {this.selectedItemsProductSpecs = data},
      data => {this.selectedItemsProductOfferings = data},
      error => {console.error(error)},
      () => {
        this.activeListItem = {
          orderItem: this.selectedOrderItems[0],
          productSpec: this.selectedItemsProductSpecs[0]
          productOffering: this.selectedItemsProductOfferings[0]
        }
        this.activeTabIndex = 0
      }
@@ -57,7 +57,7 @@ export class EditProductOrderItemsComponent implements OnInit {
      this.activeTabIndex = event.index     
      this.activeListItem = {
        orderItem: this.selectedOrderItems[event.index],
        productSpec: this.selectedItemsProductSpecs[event.index]
        productOffering: this.selectedItemsProductOfferings[event.index]
      }
    }, 500);
  }
+2 −2
Original line number Diff line number Diff line
@@ -111,8 +111,8 @@
                                                    <i class="fas fa-cogs mr-2"></i>
                                                    A related Service Order has been created.
                                                </div>
                                                <a [routerLink]="['/services/service_order', relatedServiceOrder.id]" class="btn btn-sm btn-light text-info font-weight-bold">
                                                    View Service Order #{{relatedServiceOrder.id}} 
                                                <a [routerLink]="['/services/service_orders']" class="btn btn-sm btn-light text-info font-weight-bold">
                                                    View on Service Orders 
                                                    <i class="fas fa-arrow-right ml-1"></i>
                                                </a>
                                            </div>
+4 −59
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ export class PreviewProductOrderComponent implements OnInit {
  
  availablePriorities = ['low', 'normal', 'high']

  relatedServiceOrder: any = null;
  relatedServiceOrder: boolean = false;


  productOrder: ProductOrder
@@ -93,7 +93,7 @@ export class PreviewProductOrderComponent implements OnInit {
      this.orderID = this.activatedRoute.snapshot.params.id
      this.retrieveProductOrder()
    } else {
      this.router.navigate(['../service_orders'], { relativeTo: this.activatedRoute})
      this.router.navigate(['../product_orders'], { relativeTo: this.activatedRoute})
    }
  }

@@ -158,10 +158,10 @@ export class PreviewProductOrderComponent implements OnInit {
            this.activeListItem = this.activatedRoute.snapshot.queryParams.item
            
          }

          if (['ACKNOWLEDGED', 'INPROGRESS', 'COMPLETED', 'PARTIAL'].includes(this.productOrder.state)) {
            this.retrieveRelatedServiceOrder(this.productOrder.id);
            this.relatedServiceOrder = true;
          }

        } else {
          this.productOrderNotFound = true
        }
@@ -169,61 +169,6 @@ export class PreviewProductOrderComponent implements OnInit {
    )
  }

  retrieveRelatedServiceOrder(productOrderId: string) {
    const params: any = {
      'orderItem.service.serviceCharacteristic.value.value': productOrderId
    };

    this.serviceOrderService.listServiceOrder(params as any).subscribe(
      (orders: any[]) => {
        if (orders && orders.length > 0) {
          
          orders.sort((a, b) => {
            return new Date(b.orderDate).getTime() - new Date(a.orderDate).getTime();
          });

          this.findFirstValidOrder(orders, 0, productOrderId);

        } else {
          this.relatedServiceOrder = null;
        }
      },
      (error) => {
        console.warn("Could not retrieve related Service Order list", error);
        this.relatedServiceOrder = null;
      }
    );
  }

  findFirstValidOrder(candidates: any[], index: number, targetId: string) {
    if (index >= candidates.length) {
      this.relatedServiceOrder = null;
      return;
    }

    const candidateId = candidates[index].id;

    this.serviceOrderService.retrieveServiceOrder({ id: candidateId }).subscribe(
      (fullOrder: any) => {
        
        const isMatch = fullOrder.orderItem?.some(item => 
          item.service?.serviceCharacteristic?.some(char => 
            char.name === '_PRODUCT_ORDER_ID_' && char.value?.value === targetId
          )
        );

        if (isMatch) {
          this.relatedServiceOrder = fullOrder;
        } else {
          this.findFirstValidOrder(candidates, index + 1, targetId);
        }
      },
      (error) => {
        console.warn(`Failed to fetch details for candidate ${candidateId}`, error);
        this.findFirstValidOrder(candidates, index + 1, targetId);
      }
    );
  }

  retrieveProductInventory(serviceId:string) {
    return this.inventoryService.retrieveService({id:serviceId})
Loading