Skip to content

Commit

Permalink
chore(parts): 630 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-mmaul committed Mar 21, 2024
1 parent b13ce29 commit fa49c9d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
********************************************************************************/


import { Component, Input, OnDestroy, OnInit, QueryList, ViewChildren } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Pagination } from '@core/model/pagination.model';
import { OtherPartsFacade } from '@page/other-parts/core/other-parts.facade';
import { MainAspectType } from '@page/parts/model/mainAspectType.enum';
import { AssetAsBuiltFilter, AssetAsPlannedFilter, Part } from '@page/parts/model/parts.model';
import { TableType } from '@shared/components/multi-select-autocomplete/table-type.model';
import { PartsTableComponent } from '@shared/components/parts-table/parts-table.component';
import { TableSortingUtil } from '@shared/components/table/table-sorting.util';
import { TableEventConfig, TableHeaderSort } from '@shared/components/table/table.model';
import { toAssetFilter, toGlobalSearchAssetFilter } from '@shared/helper/filter-helper';
import { setMultiSorting } from '@shared/helper/table-helper';
import { View } from '@shared/model/view.model';
import { PartDetailsFacade } from '@shared/modules/part-details/core/partDetails.facade';
import { StaticIdService } from '@shared/service/staticId.service';
import { Observable } from 'rxjs';
import {Component, Input, OnDestroy, OnInit, QueryList, ViewChildren} from '@angular/core';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {Pagination} from '@core/model/pagination.model';
import {OtherPartsFacade} from '@page/other-parts/core/other-parts.facade';
import {MainAspectType} from '@page/parts/model/mainAspectType.enum';
import {AssetAsBuiltFilter, AssetAsPlannedFilter, Part} from '@page/parts/model/parts.model';
import {TableType} from '@shared/components/multi-select-autocomplete/table-type.model';
import {PartsTableComponent} from '@shared/components/parts-table/parts-table.component';
import {TableSortingUtil} from '@shared/components/table/table-sorting.util';
import {TableEventConfig, TableHeaderSort} from '@shared/components/table/table.model';
import {containsAtleastOneFilterEntry, toAssetFilter, toGlobalSearchAssetFilter} from '@shared/helper/filter-helper';
import {setMultiSorting} from '@shared/helper/table-helper';
import {View} from '@shared/model/view.model';
import {PartDetailsFacade} from '@shared/modules/part-details/core/partDetails.facade';
import {StaticIdService} from '@shared/service/staticId.service';
import {Observable} from 'rxjs';


@Component({
Expand Down Expand Up @@ -134,7 +134,7 @@ export class CustomerPartsComponent implements OnInit, OnDestroy {
pageSizeValue = pageSize;
}

if (this.assetAsBuiltFilter && Object.keys(this.assetAsBuiltFilter).filter(key => this.assetAsBuiltFilter[key].length).length) {
if (this.assetAsBuiltFilter && containsAtleastOneFilterEntry(this.assetAsBuiltFilter)) {
this.otherPartsFacade.setCustomerPartsAsBuilt(0, pageSizeValue, this.tableCustomerAsBuiltSortList, toAssetFilter(this.assetAsBuiltFilter, true));
} else {
this.otherPartsFacade.setCustomerPartsAsBuilt(page, pageSizeValue, this.tableCustomerAsBuiltSortList);
Expand All @@ -150,7 +150,7 @@ export class CustomerPartsComponent implements OnInit, OnDestroy {
pageSizeValue = pageSize;
}

if (this.assetsAsPlannedFilter && Object.keys(this.assetsAsPlannedFilter).filter(key => this.assetsAsPlannedFilter[key].length).length) {
if (this.assetsAsPlannedFilter && containsAtleastOneFilterEntry(this.assetsAsPlannedFilter)) {
this.otherPartsFacade.setCustomerPartsAsPlanned(0, pageSizeValue, this.tableCustomerAsPlannedSortList, toAssetFilter(this.assetsAsPlannedFilter, true));
} else {
this.otherPartsFacade.setCustomerPartsAsPlanned(page, pageSizeValue, this.tableCustomerAsPlannedSortList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
********************************************************************************/


import { Component, Input, OnDestroy, OnInit, QueryList, ViewChildren } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Pagination } from '@core/model/pagination.model';
import { OtherPartsFacade } from '@page/other-parts/core/other-parts.facade';
import { MainAspectType } from '@page/parts/model/mainAspectType.enum';
import { AssetAsBuiltFilter, AssetAsPlannedFilter, Part } from '@page/parts/model/parts.model';
import { TableType } from '@shared/components/multi-select-autocomplete/table-type.model';
import { PartsTableComponent } from '@shared/components/parts-table/parts-table.component';
import { TableSortingUtil } from '@shared/components/table/table-sorting.util';
import { TableEventConfig, TableHeaderSort } from '@shared/components/table/table.model';
import { toAssetFilter, toGlobalSearchAssetFilter } from '@shared/helper/filter-helper';
import { setMultiSorting } from '@shared/helper/table-helper';
import { NotificationType } from '@shared/model/notification.model';
import { View } from '@shared/model/view.model';
import { PartDetailsFacade } from '@shared/modules/part-details/core/partDetails.facade';
import { StaticIdService } from '@shared/service/staticId.service';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import {Component, Input, OnDestroy, OnInit, QueryList, ViewChildren} from '@angular/core';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {Pagination} from '@core/model/pagination.model';
import {OtherPartsFacade} from '@page/other-parts/core/other-parts.facade';
import {MainAspectType} from '@page/parts/model/mainAspectType.enum';
import {AssetAsBuiltFilter, AssetAsPlannedFilter, Part} from '@page/parts/model/parts.model';
import {TableType} from '@shared/components/multi-select-autocomplete/table-type.model';
import {PartsTableComponent} from '@shared/components/parts-table/parts-table.component';
import {TableSortingUtil} from '@shared/components/table/table-sorting.util';
import {TableEventConfig, TableHeaderSort} from '@shared/components/table/table.model';
import {containsAtleastOneFilterEntry, toAssetFilter, toGlobalSearchAssetFilter} from '@shared/helper/filter-helper';
import {setMultiSorting} from '@shared/helper/table-helper';
import {NotificationType} from '@shared/model/notification.model';
import {View} from '@shared/model/view.model';
import {PartDetailsFacade} from '@shared/modules/part-details/core/partDetails.facade';
import {StaticIdService} from '@shared/service/staticId.service';
import {BehaviorSubject, Observable, Subject} from 'rxjs';

@Component({
selector: 'app-supplier-parts',
Expand Down Expand Up @@ -141,7 +141,7 @@ export class SupplierPartsComponent implements OnInit, OnDestroy {
if (pageSize !== 0) {
pageSizeValue = pageSize;
}
if (this.assetAsBuiltFilter && Object.keys(this.assetAsBuiltFilter).filter(key => this.assetAsBuiltFilter[key].length).length) {
if (this.assetAsBuiltFilter && containsAtleastOneFilterEntry(this.assetAsBuiltFilter)) {
this.otherPartsFacade.setSupplierPartsAsBuilt(0, pageSizeValue, this.tableSupplierAsBuiltSortList, toAssetFilter(this.assetAsBuiltFilter, true));
} else {
this.otherPartsFacade.setSupplierPartsAsBuilt(page, pageSizeValue, this.tableSupplierAsBuiltSortList);
Expand All @@ -158,7 +158,7 @@ export class SupplierPartsComponent implements OnInit, OnDestroy {
pageSizeValue = pageSize;
}

if (this.assetsAsPlannedFilter && Object.keys(this.assetsAsPlannedFilter).filter(key => this.assetsAsPlannedFilter[key].length).length) {
if (this.assetsAsPlannedFilter && containsAtleastOneFilterEntry(this.assetsAsPlannedFilter)) {
this.otherPartsFacade.setSupplierPartsAsPlanned(0, pageSizeValue, this.tableSupplierAsPlannedSortList, toAssetFilter(this.assetsAsPlannedFilter, true));
} else {
this.otherPartsFacade.setSupplierPartsAsPlanned(page, pageSizeValue, this.tableSupplierAsPlannedSortList);
Expand Down
92 changes: 46 additions & 46 deletions frontend/src/app/modules/page/parts/presentation/parts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { AfterViewInit, Component, OnDestroy, OnInit, QueryList, ViewChildren } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Pagination } from '@core/model/pagination.model';
import { RoleService } from '@core/user/role.service';
import { PartsFacade } from '@page/parts/core/parts.facade';
import { resetMultiSelectionAutoCompleteComponent } from '@page/parts/core/parts.helper';
import { MainAspectType } from '@page/parts/model/mainAspectType.enum';
import { AssetAsBuiltFilter, AssetAsPlannedFilter, Part } from '@page/parts/model/parts.model';
import { BomLifecycleSize } from '@shared/components/bom-lifecycle-activator/bom-lifecycle-activator.model';
import { TableType } from '@shared/components/multi-select-autocomplete/table-type.model';
import { PartsTableComponent } from '@shared/components/parts-table/parts-table.component';
import { TableEventConfig, TableHeaderSort } from '@shared/components/table/table.model';
import { ToastService } from '@shared/components/toasts/toast.service';
import { toAssetFilter, toGlobalSearchAssetFilter } from '@shared/helper/filter-helper';
import { setMultiSorting } from '@shared/helper/table-helper';
import { NotificationType } from '@shared/model/notification.model';
import { View } from '@shared/model/view.model';
import { PartDetailsFacade } from '@shared/modules/part-details/core/partDetails.facade';
import { BomLifecycleSettingsService, UserSettingView } from '@shared/service/bom-lifecycle-settings.service';
import { StaticIdService } from '@shared/service/staticId.service';
import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import {AfterViewInit, Component, OnDestroy, OnInit, QueryList, ViewChildren} from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {Pagination} from '@core/model/pagination.model';
import {RoleService} from '@core/user/role.service';
import {PartsFacade} from '@page/parts/core/parts.facade';
import {resetMultiSelectionAutoCompleteComponent} from '@page/parts/core/parts.helper';
import {MainAspectType} from '@page/parts/model/mainAspectType.enum';
import {AssetAsBuiltFilter, AssetAsPlannedFilter, Part} from '@page/parts/model/parts.model';
import {BomLifecycleSize} from '@shared/components/bom-lifecycle-activator/bom-lifecycle-activator.model';
import {TableType} from '@shared/components/multi-select-autocomplete/table-type.model';
import {PartsTableComponent} from '@shared/components/parts-table/parts-table.component';
import {TableEventConfig, TableHeaderSort} from '@shared/components/table/table.model';
import {ToastService} from '@shared/components/toasts/toast.service';
import {containsAtleastOneFilterEntry, toAssetFilter, toGlobalSearchAssetFilter} from '@shared/helper/filter-helper';
import {setMultiSorting} from '@shared/helper/table-helper';
import {NotificationType} from '@shared/model/notification.model';
import {View} from '@shared/model/view.model';
import {PartDetailsFacade} from '@shared/modules/part-details/core/partDetails.facade';
import {BomLifecycleSettingsService, UserSettingView} from '@shared/service/bom-lifecycle-settings.service';
import {StaticIdService} from '@shared/service/staticId.service';
import {BehaviorSubject, combineLatest, Observable, Subject} from 'rxjs';
import {map} from 'rxjs/operators';


@Component({
Expand Down Expand Up @@ -94,10 +94,10 @@ export class PartsComponent implements OnInit, OnDestroy, AfterViewInit {
this.tableAsPlannedSortList = [];

window.addEventListener('keydown', (event) => {
this.ctrlKeyState = setMultiSorting(event);
this.ctrlKeyState = setMultiSorting(event);
});
window.addEventListener('keyup', (event) => {
this.ctrlKeyState = setMultiSorting(event);
this.ctrlKeyState = setMultiSorting(event);
});
}

Expand All @@ -108,6 +108,7 @@ export class PartsComponent implements OnInit, OnDestroy, AfterViewInit {

assetAsBuiltFilter: AssetAsBuiltFilter;
assetsAsPlannedFilter: AssetAsPlannedFilter;

public ngOnInit(): void {
this.partsFacade.setPartsAsBuilt();
this.partsFacade.setPartsAsPlanned();
Expand Down Expand Up @@ -143,14 +144,14 @@ export class PartsComponent implements OnInit, OnDestroy, AfterViewInit {
}

refreshPartsOnPublish(message: string) {
if(message) {
this.toastService.error(message);
} else {
this.toastService.success("requestPublishAssets.success")
this.partsFacade.setPartsAsBuilt();
this.partsFacade.setPartsAsPlanned();
this.partsTableComponents.map(component => component.clearAllRows())
}
if (message) {
this.toastService.error(message);
} else {
this.toastService.success("requestPublishAssets.success")
this.partsFacade.setPartsAsBuilt();
this.partsFacade.setPartsAsPlanned();
this.partsTableComponents.map(component => component.clearAllRows())
}
}

private resetFilterAndShowToast() {
Expand All @@ -171,8 +172,8 @@ export class PartsComponent implements OnInit, OnDestroy, AfterViewInit {
public onSelectItem($event: Record<string, unknown>): void {
this.partDetailsFacade.selectedPart = $event as unknown as Part;
let tableData = {};
for(let component of this.partsTableComponents) {
tableData[component.tableType+"_PAGE"] = component.pageIndex;
for (let component of this.partsTableComponents) {
tableData[component.tableType + "_PAGE"] = component.pageIndex;
}
this.router.navigate([`parts/${$event?.id}`], {queryParams: tableData})
}
Expand All @@ -184,8 +185,7 @@ export class PartsComponent implements OnInit, OnDestroy, AfterViewInit {
if (pageSize !== 0) {
pageSizeValue = pageSize;
}
//if any filter is applied
if (this.assetAsBuiltFilter && Object.keys(this.assetAsBuiltFilter).filter(key => this.assetAsBuiltFilter[key].length).length) {
if (this.assetAsBuiltFilter && containsAtleastOneFilterEntry(this.assetAsBuiltFilter)) {
this.partsFacade.setPartsAsBuilt(0, pageSizeValue, this.tableAsBuiltSortList, toAssetFilter(this.assetAsBuiltFilter, true));
} else {
this.partsFacade.setPartsAsBuilt(page, pageSizeValue, this.tableAsBuiltSortList);
Expand All @@ -194,15 +194,15 @@ export class PartsComponent implements OnInit, OnDestroy, AfterViewInit {
}

public onAsPlannedTableConfigChange({page, pageSize, sorting}: TableEventConfig): void {
this.setTableSortingList(sorting, MainAspectType.AS_PLANNED);
this.currentPartTablePage['AS_PLANNED_OWN_PAGE'] = page;
this.setTableSortingList(sorting, MainAspectType.AS_PLANNED);
this.currentPartTablePage['AS_PLANNED_OWN_PAGE'] = page;

let pageSizeValue = this.DEFAULT_PAGE_SIZE;
if (pageSize !== 0) {
pageSizeValue = pageSize;
}

if (this.assetsAsPlannedFilter && Object.keys(this.assetsAsPlannedFilter).filter(key => this.assetsAsPlannedFilter[key].length).length) {
if (this.assetsAsPlannedFilter && containsAtleastOneFilterEntry(this.assetsAsPlannedFilter)) {
this.partsFacade.setPartsAsPlanned(0, pageSizeValue, this.tableAsPlannedSortList, toAssetFilter(this.assetsAsPlannedFilter, true));
} else {
this.partsFacade.setPartsAsPlanned(page, pageSizeValue, this.tableAsPlannedSortList);
Expand Down Expand Up @@ -260,12 +260,12 @@ export class PartsComponent implements OnInit, OnDestroy, AfterViewInit {
}
}

private setupPageByUrlParams(params: Params ) {
if(!params) {
return;
}
this.onAsBuiltTableConfigChange({page: params['AS_BUILT_OWN_PAGE'], pageSize: 50, sorting: null});
this.onAsPlannedTableConfigChange({page: params['AS_PLANNED_OWN_PAGE'], pageSize: 50, sorting: null});
private setupPageByUrlParams(params: Params) {
if (!params) {
return;
}
this.onAsBuiltTableConfigChange({page: params['AS_BUILT_OWN_PAGE'], pageSize: 50, sorting: null});
this.onAsPlannedTableConfigChange({page: params['AS_PLANNED_OWN_PAGE'], pageSize: 50, sorting: null});
}

protected readonly UserSettingView = UserSettingView;
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/app/modules/shared/helper/filter-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
import {HttpParams} from '@angular/common/http';
import { HttpParams } from '@angular/common/http';
import {
AssetAsBuiltFilter,
AssetAsPlannedFilter,
FilterOperator,
getFilterOperatorValue,
} from '@page/parts/model/parts.model';
import {NotificationFilter} from '../../../mocks/services/investigations-mock/investigations.model';
import { NotificationFilter } from '../../../mocks/services/investigations-mock/investigations.model';

export const DATE_FILTER_KEYS = [ 'manufacturingDate', 'functionValidFrom', 'functionValidUntil', 'validityPeriodFrom', 'validityPeriodTo', 'createdDate', 'targetDate', 'creationDate', 'endDate' ];

Expand Down Expand Up @@ -200,3 +200,9 @@ export function provideFilterListForNotifications( filter?: NotificationFilter,

return filterList;
}

export function containsAtleastOneFilterEntry(filter: AssetAsBuiltFilter | AssetAsPlannedFilter): boolean {
return Object.keys(filter)
.filter(key => filter[key].length)
.length > 0
}

0 comments on commit fa49c9d

Please sign in to comment.