Loading src/app/p_product/admin/productCatalogManagement/edit-product-specs/assign-service-specification/assign-service-specification.component.ts +39 −20 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dial import { MatSort } from '@angular/material/sort'; import { MatTableDataSource } from '@angular/material/table'; import { ToastrService } from 'ngx-toastr'; import { Observable } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { map, startWith } from 'rxjs/operators' import { ProductSpecification, ProductSpecificationUpdate } from 'src/app/openApis/productCatalogManagement/models'; import { ProductSpecificationService } from 'src/app/openApis/productCatalogManagement/services'; Loading Loading @@ -47,32 +47,51 @@ export class AssignServiceSpecificationComponent implements OnInit { filteredSpecs$: Observable<ProductSpecification[]> selectedSpecs: ProductSpecification[] = [] // the subject holds the data when it arrives from the api private availableSpecsSubject = new BehaviorSubject<ProductSpecification[]>([]); ngOnInit(): void { this.listServiceSpecs() this.listServiceSpecs(); // for the filtering to work when user starts typing in the input this.filteredSpecs$ = combineLatest([ this.specInputCtrl.valueChanges.pipe(startWith('')), this.availableSpecsSubject.asObservable() ]).pipe( map(([inputValue, specs]) => { const filterValue = typeof inputValue === 'string' ? inputValue.toLowerCase() : ''; return this.performFilter(filterValue, specs); }) ); } listServiceSpecs() { this.serviceSpecService.listServiceSpecification({}).subscribe( data => this.nonSelectedSpecs = data, error => console.error(error), () => { data => { // remove the already assigned specs const initiallyAssignedIDs = this.data.productSpec.serviceSpecification.map(el => el.id); const filteredData = data.filter(spec => !initiallyAssignedIDs.includes(spec.id)); // push data into subject this.availableSpecsSubject.next(filteredData); //remove self from available spec list as well as the allready assigned specs const initiallyAssignedSpecIDs: string[] = this.data.productSpec.serviceSpecification.map(el => el.id) this.nonSelectedSpecs = this.nonSelectedSpecs.filter(spec => !initiallyAssignedSpecIDs.includes(spec.id)) this.selectedSpecs = this.data.productSpec.serviceSpecification.slice() this.dataSource.data = this.selectedSpecs this.dataSource.sort = this.sort this.selectedSpecs = this.data.productSpec.serviceSpecification.slice(); this.dataSource.data = this.selectedSpecs; this.dataSource.sort = this.sort; }, error => console.error(error) ); } this.filteredSpecs$ = this.specInputCtrl.valueChanges.pipe( startWith(null), map( (spec: string | ServiceSpecification) => typeof(spec) === 'string' ? this._filter(spec) : this.nonSelectedSpecs.slice() ) ) private performFilter(filterValue: string, specs: ProductSpecification[]): ProductSpecification[] { if (!filterValue) { return specs; } ) return specs.filter(spec => { const name = spec.name ? spec.name.toLowerCase() : ''; return name.indexOf(filterValue) !== -1; }); } selected(event: MatAutocompleteSelectedEvent): void { Loading src/app/p_product/admin/productCatalogManagement/edit-product-specs/edit-product-spec-characteristics/edit-product-spec-characteristics.component.ts +6 −6 Original line number Diff line number Diff line Loading @@ -199,13 +199,13 @@ export class EditProductSpecCharacteristicsComponent implements OnInit { productSpecCharacteristic: this.data.productSpec.productSpecCharacteristic } console.log(updateCharacteristicObj); // console.log(updateCharacteristicObj); // this.specService.patchProductSpecification({ id: this.data.productSpec.id, productSpecification: updateCharacteristicObj }).subscribe( // data => { }, // error => { console.error(error); this.toast.error("An error occurred upon updating Spec Characteristics") }, // () => { this.dialogRef.close('updated') } // ) this.specService.patchProductSpecification({ id: this.data.productSpec.id, productSpecification: updateCharacteristicObj }).subscribe( data => { }, error => { console.error(error); this.toast.error("An error occurred upon updating Spec Characteristics") }, () => { this.dialogRef.close('updated') } ) } ngOnDestroy(): void { Loading Loading
src/app/p_product/admin/productCatalogManagement/edit-product-specs/assign-service-specification/assign-service-specification.component.ts +39 −20 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dial import { MatSort } from '@angular/material/sort'; import { MatTableDataSource } from '@angular/material/table'; import { ToastrService } from 'ngx-toastr'; import { Observable } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { map, startWith } from 'rxjs/operators' import { ProductSpecification, ProductSpecificationUpdate } from 'src/app/openApis/productCatalogManagement/models'; import { ProductSpecificationService } from 'src/app/openApis/productCatalogManagement/services'; Loading Loading @@ -47,32 +47,51 @@ export class AssignServiceSpecificationComponent implements OnInit { filteredSpecs$: Observable<ProductSpecification[]> selectedSpecs: ProductSpecification[] = [] // the subject holds the data when it arrives from the api private availableSpecsSubject = new BehaviorSubject<ProductSpecification[]>([]); ngOnInit(): void { this.listServiceSpecs() this.listServiceSpecs(); // for the filtering to work when user starts typing in the input this.filteredSpecs$ = combineLatest([ this.specInputCtrl.valueChanges.pipe(startWith('')), this.availableSpecsSubject.asObservable() ]).pipe( map(([inputValue, specs]) => { const filterValue = typeof inputValue === 'string' ? inputValue.toLowerCase() : ''; return this.performFilter(filterValue, specs); }) ); } listServiceSpecs() { this.serviceSpecService.listServiceSpecification({}).subscribe( data => this.nonSelectedSpecs = data, error => console.error(error), () => { data => { // remove the already assigned specs const initiallyAssignedIDs = this.data.productSpec.serviceSpecification.map(el => el.id); const filteredData = data.filter(spec => !initiallyAssignedIDs.includes(spec.id)); // push data into subject this.availableSpecsSubject.next(filteredData); //remove self from available spec list as well as the allready assigned specs const initiallyAssignedSpecIDs: string[] = this.data.productSpec.serviceSpecification.map(el => el.id) this.nonSelectedSpecs = this.nonSelectedSpecs.filter(spec => !initiallyAssignedSpecIDs.includes(spec.id)) this.selectedSpecs = this.data.productSpec.serviceSpecification.slice() this.dataSource.data = this.selectedSpecs this.dataSource.sort = this.sort this.selectedSpecs = this.data.productSpec.serviceSpecification.slice(); this.dataSource.data = this.selectedSpecs; this.dataSource.sort = this.sort; }, error => console.error(error) ); } this.filteredSpecs$ = this.specInputCtrl.valueChanges.pipe( startWith(null), map( (spec: string | ServiceSpecification) => typeof(spec) === 'string' ? this._filter(spec) : this.nonSelectedSpecs.slice() ) ) private performFilter(filterValue: string, specs: ProductSpecification[]): ProductSpecification[] { if (!filterValue) { return specs; } ) return specs.filter(spec => { const name = spec.name ? spec.name.toLowerCase() : ''; return name.indexOf(filterValue) !== -1; }); } selected(event: MatAutocompleteSelectedEvent): void { Loading
src/app/p_product/admin/productCatalogManagement/edit-product-specs/edit-product-spec-characteristics/edit-product-spec-characteristics.component.ts +6 −6 Original line number Diff line number Diff line Loading @@ -199,13 +199,13 @@ export class EditProductSpecCharacteristicsComponent implements OnInit { productSpecCharacteristic: this.data.productSpec.productSpecCharacteristic } console.log(updateCharacteristicObj); // console.log(updateCharacteristicObj); // this.specService.patchProductSpecification({ id: this.data.productSpec.id, productSpecification: updateCharacteristicObj }).subscribe( // data => { }, // error => { console.error(error); this.toast.error("An error occurred upon updating Spec Characteristics") }, // () => { this.dialogRef.close('updated') } // ) this.specService.patchProductSpecification({ id: this.data.productSpec.id, productSpecification: updateCharacteristicObj }).subscribe( data => { }, error => { console.error(error); this.toast.error("An error occurred upon updating Spec Characteristics") }, () => { this.dialogRef.close('updated') } ) } ngOnDestroy(): void { Loading