Added checkbox in stock page
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||
import {FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
import {GetProductDto, GetSupplierDto, SuppliersService} from "../../services/api";
|
||||
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
||||
import {NzFormControlComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
||||
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-product-supplier-form',
|
||||
imports: [
|
||||
NzRowDirective,
|
||||
NzFormControlComponent,
|
||||
NzFormLabelComponent,
|
||||
ReactiveFormsModule,
|
||||
NzFlexDirective,
|
||||
NzColDirective,
|
||||
NzTableComponent,
|
||||
NzInputNumberComponent,
|
||||
NzOptionComponent,
|
||||
NzSelectComponent
|
||||
],
|
||||
templateUrl: './add-product-supplier-form.html',
|
||||
styleUrl: './add-product-supplier-form.css',
|
||||
})
|
||||
export class AddProductSupplierForm implements OnInit {
|
||||
addProductForm: FormGroup = new FormGroup({
|
||||
supplierId: new FormControl<number>(null, Validators.required),
|
||||
lines: new FormArray([], Validators.required),
|
||||
});
|
||||
|
||||
private suppliersServices = inject(SuppliersService);
|
||||
private notificationService = inject(NzNotificationService);
|
||||
|
||||
suppliers = signal<GetSupplierDto[]>([]);
|
||||
|
||||
async ngOnInit() {
|
||||
try {
|
||||
const suppliers = await firstValueFrom(this.suppliersServices.getAllSuppliersEndpoint());
|
||||
this.suppliers.set(suppliers);
|
||||
}
|
||||
catch {
|
||||
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
||||
}
|
||||
}
|
||||
|
||||
get lines(): FormArray {
|
||||
return this.addProductForm.get('lines') as FormArray;
|
||||
}
|
||||
|
||||
addProductToForm(selectedProducts: GetProductDto[]) {
|
||||
this.lines.clear();
|
||||
|
||||
selectedProducts.forEach(p => {
|
||||
this.lines.push(
|
||||
new FormGroup({
|
||||
productId: new FormControl(p.id),
|
||||
name: new FormControl(p.name),
|
||||
price: new FormControl(1, [Validators.required,Validators.min(0)])
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user