diff --git a/matsen-tool/src/app/_views/sales/new-sale/new-sale.component.ts b/matsen-tool/src/app/_views/sales/new-sale/new-sale.component.ts
index 9fd4e06..601001a 100644
--- a/matsen-tool/src/app/_views/sales/new-sale/new-sale.component.ts
+++ b/matsen-tool/src/app/_views/sales/new-sale/new-sale.component.ts
@@ -1,35 +1,42 @@
-import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
+import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
import {
- MediaObjectService,
PartnerJsonld,
- PartnerService,
+ PartnerService, ProductJsonld,
ProductService,
SaleJsonld,
SaleService
} from "@app/core/api/v1";
import {ModalStatus} from "@app/_helpers/modal.states";
import {FormGroup} from "@angular/forms";
-import {debounceTime, distinctUntilChanged, Observable, OperatorFunction, Subscription, switchMap} from "rxjs";
+import {Subscription} from "rxjs";
import {TranslateService} from "@ngx-translate/core";
import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer";
import {saleForm} from "@app/_forms/apiForms";
import {AppHelperService} from "@app/_helpers/app-helper.service";
-import {filter, map} from "rxjs/operators";
-import {SearchInputComponent} from "@app/_components/search-input/search-input.component";
+import {SearchSelectComponent} from "@app/_components/search-select/search-select.component";
+import {MatTableDataSource} from "@angular/material/table";
+import {SearchInputColDef} from "@app/_components/search-input/search-input-col-def";
@Component({
selector: 'app-new-sale',
templateUrl: './new-sale.component.html',
styleUrl: './new-sale.component.scss'
})
-export class NewSaleComponent implements OnInit {
+export class NewSaleComponent implements OnInit, AfterViewInit {
@Input() public sale!: SaleJsonld;
@Output() public submit: EventEmitter
= new EventEmitter();
- @ViewChild('partnerSearchInput', { static: false }) $partnerSearchInput!: SearchInputComponent;
- @ViewChild('productSearchInput', { static: false }) $productSearchInput!: SearchInputComponent;
+
+ @ViewChild('partnerSearchSelect', { static: false }) partnerSearchSelect!: SearchSelectComponent;
+ @ViewChild('productSearchSelect', { static: false }) productSearchSelect!: SearchSelectComponent;
protected saleForm: FormGroup;
protected saleSub: Subscription;
+ protected partners: Array;
+ protected dataSourcePartners;
+ protected products: Array;
+ protected dataSourceProducts;
+ protected colDefPartners: SearchInputColDef[];
+ protected colDefProducts: SearchInputColDef[];
protected formatter = (apiData: any) => apiData.name;
@@ -41,23 +48,60 @@ export class NewSaleComponent implements OnInit {
protected appHelperService: AppHelperService,
) {
this.saleForm = saleForm;
-
this.saleSub = new Subscription();
+ this.partners = [];
+ this.dataSourcePartners = new MatTableDataSource(this.partners);
+ this.products = [];
+ this.dataSourceProducts = new MatTableDataSource(this.products);
+ this.colDefPartners = [
+ SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION),
+ SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'logoUrl'),
+ SearchSelectComponent.createColDef('name', 'form.name', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'),
+ ];
+ this.colDefProducts = [
+ SearchSelectComponent.createColDef('pos', 'overview.number', SearchSelectComponent.COLUMN_TYPE_POSITION),
+ SearchSelectComponent.createColDef('img', 'overview.image', SearchSelectComponent.COLUMN_TYPE_IMAGE, 'imageUrl'),
+ SearchSelectComponent.createColDef('name', 'form.product', SearchSelectComponent.COLUMN_TYPE_TEXT, 'name'),
+ ];
}
ngOnInit(): void {
this.saleForm = FormGroupInitializer.initFormGroup(this.saleForm, this.sale);
}
- fetchProducts = (term: string): Observable<{ id: any; name: any }[]> => {
- return this.productService.productsGetCollection(1, 50, term).pipe(
- map((response) => response['hydra:member'].map(product => ({id: product.id, name: product.name}))),
- );
+ ngAfterViewInit(): void {
+ this.partnerSearchSelect.getData();
+ this.productSearchSelect.getData();
}
- fetchPartners = (term: string): Observable<{ id: any; name: any }[]> => {
- return this.partnerService.partnersGetCollection(1, 50, undefined, undefined, term).pipe(
- map((response) => response['hydra:member'].map(partner => ({id: partner.id, name: partner.name}))),
+ getPartners = (term: string): void => {
+ this.partnerService.partnersGetCollection(
+ this.partnerSearchSelect.pagingComponent.getPageIndex(),
+ this.partnerSearchSelect.pagingComponent.getPageSize(),
+ undefined,
+ undefined,
+ term
+ ).subscribe(
+ data => {
+ this.partners = data['hydra:member'];
+ this.dataSourcePartners = new MatTableDataSource(this.partners);
+ this.partnerSearchSelect.setData(this.dataSourcePartners, this.partners, Number(data["hydra:totalItems"]));
+ }
+ )
+ }
+
+ getProducts = (term?: string): void => {
+ // NOTE: all products that are not assigned to partner yet
+ this.productService.productsGetCollection(
+ this.productSearchSelect.pagingComponent.getPageIndex(),
+ this.productSearchSelect.pagingComponent.getPageSize(),
+ term
+ ).subscribe(
+ data => {
+ this.products = data['hydra:member'];
+ this.dataSourceProducts = new MatTableDataSource(this.products);
+ this.productSearchSelect.setData(this.dataSourceProducts, this.products, Number(data["hydra:totalItems"]));
+ }
);
}
diff --git a/matsen-tool/src/app/_views/tasks/new-task/new-task.component.ts b/matsen-tool/src/app/_views/tasks/new-task/new-task.component.ts
index 3fd259a..7233430 100644
--- a/matsen-tool/src/app/_views/tasks/new-task/new-task.component.ts
+++ b/matsen-tool/src/app/_views/tasks/new-task/new-task.component.ts
@@ -46,9 +46,9 @@ export class NewTaskComponent implements OnInit, AfterViewInit {
protected formatter = (apiData: any) => apiData.name;
constructor(
- private taskService: TaskService,
- private userService: UserService,
- private partnerService: PartnerService,
+ protected taskService: TaskService,
+ protected userService: UserService,
+ protected partnerService: PartnerService,
protected productService: ProductService,
protected appHelperService: AppHelperService
) {