From a8d13cc1fb41f3e5b55ebf73950b7274ed6fd65c Mon Sep 17 00:00:00 2001
From: FyloZ
Date: Wed, 1 Dec 2021 20:41:26 -0500
Subject: [PATCH] Start updating inventory
---
src/app/modules/material/material.module.ts | 8 +-
.../pages/inventory/inventory.component.html | 106 +++++++-----------
.../pages/inventory/inventory.component.sass | 11 +-
.../pages/inventory/inventory.component.ts | 34 ++++--
.../shared/components/tables/tables.ts | 17 ++-
5 files changed, 91 insertions(+), 85 deletions(-)
diff --git a/src/app/modules/material/material.module.ts b/src/app/modules/material/material.module.ts
index 2b934b2..d4f2fc2 100644
--- a/src/app/modules/material/material.module.ts
+++ b/src/app/modules/material/material.module.ts
@@ -9,6 +9,9 @@ import {EditComponent} from './pages/edit/edit.component';
import {RecipesModule} from '../recipes/recipes.module'
import {MatSortModule} from '@angular/material/sort'
import {FormsModule} from '@angular/forms'
+import {CreTablesModule} from '../shared/components/tables/tables.module'
+import {CreInputsModule} from '../shared/components/inputs/inputs.module'
+import {CreButtonsModule} from '../shared/components/buttons/buttons.module'
@NgModule({
@@ -19,7 +22,10 @@ import {FormsModule} from '@angular/forms'
SharedModule,
RecipesModule,
MatSortModule,
- FormsModule
+ FormsModule,
+ CreTablesModule,
+ CreInputsModule,
+ CreButtonsModule
]
})
export class MaterialModule {
diff --git a/src/app/modules/material/pages/inventory/inventory.component.html b/src/app/modules/material/pages/inventory/inventory.component.html
index dd49bc1..aef4f3a 100644
--- a/src/app/modules/material/pages/inventory/inventory.component.html
+++ b/src/app/modules/material/pages/inventory/inventory.component.html
@@ -1,47 +1,34 @@
@@ -51,19 +38,18 @@
- 0"
- mat-table
- matSort
class="mx-auto"
- [dataSource]="dataSource">
+ [data]="dataSource"
+ [columns]="columns">
- Code |
+ Code |
{{material.name}} |
- Type de produit |
+ Type de produit |
{{material.materialType.name}} |
@@ -75,9 +61,7 @@
|
- |
+
diff --git a/src/app/modules/material/pages/inventory/inventory.component.sass b/src/app/modules/material/pages/inventory/inventory.component.sass
index 20ded20..5867821 100644
--- a/src/app/modules/material/pages/inventory/inventory.component.sass
+++ b/src/app/modules/material/pages/inventory/inventory.component.sass
@@ -1,8 +1,9 @@
-.input-group-append button
- border-radius: 0 4px 4px 0
-
mat-select
margin-top: 4px
-.form-control
- width: 6rem
+.input-group
+ cre-input
+ width: 6rem
+
+ .input-group-append button
+ border-radius: 0 4px 4px 0
diff --git a/src/app/modules/material/pages/inventory/inventory.component.ts b/src/app/modules/material/pages/inventory/inventory.component.ts
index a6d8794..2c08589 100644
--- a/src/app/modules/material/pages/inventory/inventory.component.ts
+++ b/src/app/modules/material/pages/inventory/inventory.component.ts
@@ -12,6 +12,9 @@ import {MatTableDataSource} from '@angular/material/table'
import {MaterialTypeService} from '../../../material-type/service/material-type.service'
import {InventoryService} from '../../service/inventory.service'
import {AppState} from '../../../shared/app-state'
+import {FormControl} from '@angular/forms'
+import {map} from 'rxjs/operators'
+import {CreInputEntry} from '../../../shared/components/inputs/inputs'
@Component({
selector: 'cre-list',
@@ -22,7 +25,9 @@ export class InventoryComponent extends ErrorHandlingComponent {
@ViewChild(MatSort) sort: MatSort
materials: Material[] | null = []
- materialTypes$ = this.materialTypeService.all
+ materialTypesEntries$ = this.materialTypeService.all.pipe(map(materialTypes => {
+ return materialTypes.map(materialType => new CreInputEntry(materialType.id, materialType.name))
+ }))
dataSource: MatTableDataSource
columns = ['name', 'materialType', 'quantity', 'addQuantity', 'lowQuantityIcon', 'simdutIcon', 'editButton', 'openSimdutButton']
@@ -31,8 +36,12 @@ export class InventoryComponent extends ErrorHandlingComponent {
units = UNIT_MILLILITER
lowQuantityThreshold = 100 // TEMPORARY will be in the application settings
- materialTypeFilter = 1
- materialNameFilter = ''
+
+ materialTypeFilterControl = new FormControl()
+ materialNameFilterControl = new FormControl()
+
+ private materialTypeFilter = 1
+ private materialNameFilter = ''
constructor(
private materialService: MaterialService,
@@ -60,6 +69,16 @@ export class InventoryComponent extends ErrorHandlingComponent {
true,
1
)
+
+ this.subscribe(
+ this.materialTypeFilterControl.valueChanges,
+ filter => this.materialTypeFilter = filter
+ )
+
+ this.subscribe(
+ this.materialNameFilterControl.valueChanges,
+ filter => this.materialNameFilter = filter
+ )
}
setupDataSource(): MatTableDataSource {
@@ -83,10 +102,6 @@ export class InventoryComponent extends ErrorHandlingComponent {
return this.dataSource
}
- filterDataSource() {
- this.dataSource.filter = 'filter'
- }
-
isLowQuantity(material: Material) {
return this.getQuantity(material) < this.lowQuantityThreshold
}
@@ -118,6 +133,11 @@ export class InventoryComponent extends ErrorHandlingComponent {
)
}
+ get filter(): string {
+ // Uses private UTF-8 char to separate the two fields, change if a better method is found
+ return `${this.materialTypeFilter}${this.materialNameFilter}`
+ }
+
get canEditMaterial(): boolean {
return this.accountService.hasPermission(Permission.EDIT_MATERIALS)
}
diff --git a/src/app/modules/shared/components/tables/tables.ts b/src/app/modules/shared/components/tables/tables.ts
index 25e3394..6d4d7ca 100644
--- a/src/app/modules/shared/components/tables/tables.ts
+++ b/src/app/modules/shared/components/tables/tables.ts
@@ -13,6 +13,8 @@ import {
} from '@angular/core'
import {MatColumnDef, MatHeaderRowDef, MatRowDef, MatTable, MatTableDataSource} from '@angular/material/table'
+type CreTableData = T[] | MatTableDataSource
+
@Directive({
selector: '[creInteractiveCell]'
})
@@ -66,7 +68,7 @@ export class CreTable implements AfterContentInit {
this.dataSource.filter = filter
}
- @Input() set data(data: T[]) {
+ @Input() set data(data: CreTableData) {
this.setupDataSource(data)
}
@@ -80,9 +82,16 @@ export class CreTable implements AfterContentInit {
this.headerRowDefs.forEach(headerRowDef => this.table.addHeaderRowDef(headerRowDef))
}
- private setupDataSource(data: T[]) {
- this.dataSource = new MatTableDataSource(data)
- this.dataSource.filterPredicate = (t, filter) => this.filterFn(t, filter)
+ private setupDataSource(data: CreTableData) {
+ if (data instanceof MatTableDataSource) {
+ this.dataSource = data
+ } else {
+ this.dataSource = new MatTableDataSource(data)
+ }
+
+ if (this.filterFn) {
+ this.dataSource.filterPredicate = (t, filter) => this.filterFn(t, filter)
+ }
}
onRowHover(index: number) {