(WiP) Patch Form

This commit is contained in:
Sebastian
2020-07-30 17:01:03 +02:00
parent fd1e2bfd84
commit 5a8c6111ff
5 changed files with 83 additions and 15 deletions

View File

@@ -65,7 +65,7 @@
<app-shelf-edit-order-item
[orderItemForm]="item"
[onlyChild]="items.controls.length === 1"
[firstChild]="index === 1"
[firstChild]="index === 0"
[vatOptions]="formService.vats$ | async"
></app-shelf-edit-order-item>
</ng-container>

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormArray } from '@angular/forms';
import { Observable, of } from 'rxjs';
import { OrderItemListItemDTO, VATDTO } from '@swagger/oms';
import { OrderItemListItemDTO, VATDTO, OrderItemDTO } from '@swagger/oms';
import { DetailsFacade } from '@shelf-store/details';
import { take, filter } from 'rxjs/operators';
import { isNullOrUndefined } from 'util';
@@ -59,8 +59,6 @@ export class ShelfEditFormService {
const form = this.formBuilder.group(controlsConfig);
this.forms.set(orderNumber, form);
console.log({ controlsConfig, form: this.forms.get(orderNumber) });
return this.forms.get(orderNumber);
}
@@ -126,8 +124,9 @@ export class ShelfEditFormService {
lastName: baseOrderItem.lastName,
compartmentCode: [
{ value: baseOrderItem.compartmentCode, disabled: false },
[Validators.required],
],
orderId: [{ value: baseOrderItem.orderId, disabled: false }],
orderItemId: [{ value: baseOrderItem.orderId, disabled: false }],
orderNumber: [
{
value: baseOrderItem.orderNumber,
@@ -197,11 +196,68 @@ export class ShelfEditFormService {
}
submit(form: FormGroup): Observable<boolean> {
console.log('%cForm Submitted: ', 'color: green; font-weight: bold', form);
const patch = this.preparePatch(form);
// TODO dispatch actions to store to submit form
// TODO handle errorrs
this.detailsStoreFacade.patchOrderItems(patch);
// TODO must return boolean to indicate whether patch (update) was succesful
return of(true);
}
private preparePatch(
form: FormGroup
): {
orderId: number;
orderItemId: number;
orderItem: Partial<OrderItemDTO>;
}[] {
const items = form.get('items').value;
const patch: {
orderId: number;
orderItemId: number;
orderItem: Partial<OrderItemDTO>;
}[] = items.map(
(item: {
comment: string;
price: number;
quantity: number;
vat: number;
}) => this.mapFormItemToPatch(form, item)
);
console.log(
'%cPreparing Patch: ',
'color: green; font-weight: bold',
items
);
return patch;
}
private mapFormItemToPatch(
form: FormGroup,
item: {
comment: string;
price: number;
quantity: number;
vat: number;
}
): {
orderId: number;
orderItemId: number;
orderItem: Partial<OrderItemDTO>;
} {
return {
orderId: form.get('orderId').value,
orderItemId: form.get('orderItemId').value,
orderItem: {
...item,
order: {
data: { processingStatus: form.get('processingStatus').value },
},
},
};
}
}

View File

@@ -30,18 +30,14 @@ export class ShelfNavigationService {
this.createTab();
const path = this.getDetailsPathByCompartmentCode(compartmentCode);
// TODO we need to get info for setting breadcrumb
this.store.dispatch(new ChangeCurrentRoute(path));
this.router.navigate([path]);
this.navigateBackFromEdit(path);
}
navigateToDetailsByOrderNumber(orderNumber: string) {
this.createTab();
const path = this.getDetailsPathByCompartmentCode(orderNumber);
const path = this.getDetailsPathByOrderNumber(orderNumber);
// TODO we need to get info for setting breadcrumb
this.store.dispatch(new ChangeCurrentRoute(path));
this.router.navigate([path]);
this.navigateBackFromEdit(path);
}
navigateToEditByCompartmentCode(compartmentCode: string) {
@@ -90,6 +86,12 @@ export class ShelfNavigationService {
this.router.navigate([route]);
}
private navigateBackFromEdit(route: string) {
this.store.dispatch(new ChangeCurrentRoute(route));
this.store.dispatch(new PopLastBreadcrumbs(this.getEditBreadCrumb()));
this.router.navigate([route]);
}
private getResultListBreadcrumb(
searchQuery: string,
numberOfHits: number

View File

@@ -49,7 +49,7 @@ export class UiTextInputComponent implements ControlValueAccessor {
this.touched = true;
}
this.focussed = isFocussed;
this.cdr.detectChanges();
// this.cdr.detectChanges();
}
writeValue(val: string): void {

View File

@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { OrderItemListItemDTO } from '@swagger/oms';
import { OrderItemListItemDTO, OrderItemDTO } from '@swagger/oms';
import { Observable } from 'rxjs';
import * as actions from './details.actions';
import * as selectors from './details.selectors';
@@ -35,4 +35,14 @@ export class DetailsFacade {
fetchOrderItemsByCompartmentCode(orderNumber: string) {
this.store.dispatch(actions.fetchDetailsByOrderNumber({ orderNumber }));
}
patchOrderItems(
patch: {
orderId: number;
orderItemId: number;
orderItem: Partial<OrderItemDTO>;
}[]
) {
this.store.dispatch(actions.patchOrderItems({ patch }));
}
}