Feature: Adding recipe templates to print recipes.
Feautre: Recipe export to xlsx Chore: Python 11 style type annotations Chore: Moved to sqlalchemy 2.0 Chore: Minimum python is 3.11 Fix: Fix nullability of a lot of fields in the database.
This commit is contained in:
@@ -2,7 +2,6 @@ import { DataSource } from '@angular/cdk/collections';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { MatPaginator, PageEvent } from '@angular/material/paginator';
|
||||
import { MatSort, Sort } from '@angular/material/sort';
|
||||
import * as moment from 'moment';
|
||||
import { merge, Observable } from 'rxjs';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
|
||||
@@ -27,23 +26,17 @@ export class RecipeListDatasource extends DataSource<Recipe> {
|
||||
}
|
||||
|
||||
connect(): Observable<Recipe[]> {
|
||||
const dataMutations: (
|
||||
| Observable<Recipe[]>
|
||||
| Observable<string>
|
||||
| EventEmitter<PageEvent>
|
||||
| EventEmitter<Sort>
|
||||
)[] = [
|
||||
this.dataObs.pipe(
|
||||
tap((x) => {
|
||||
this.data = x;
|
||||
}),
|
||||
),
|
||||
this.productGroupFilter.pipe(
|
||||
tap((x) => {
|
||||
this.productGroup = x;
|
||||
}),
|
||||
),
|
||||
];
|
||||
const dataMutations: (EventEmitter<PageEvent> | EventEmitter<Sort>)[] = [];
|
||||
const d = this.dataObs.pipe(
|
||||
tap((x) => {
|
||||
this.data = x;
|
||||
}),
|
||||
);
|
||||
const pg = this.productGroupFilter.pipe(
|
||||
tap((x) => {
|
||||
this.productGroup = x;
|
||||
}),
|
||||
);
|
||||
if (this.paginator) {
|
||||
dataMutations.push((this.paginator as MatPaginator).page);
|
||||
}
|
||||
@@ -51,7 +44,7 @@ export class RecipeListDatasource extends DataSource<Recipe> {
|
||||
dataMutations.push((this.sort as MatSort).sortChange);
|
||||
}
|
||||
|
||||
return merge(...dataMutations).pipe(
|
||||
return merge(d, pg, ...dataMutations).pipe(
|
||||
map(() => this.getFilteredData(this.data, this.productGroup)),
|
||||
tap((x: Recipe[]) => {
|
||||
if (this.paginator) {
|
||||
@@ -68,7 +61,7 @@ export class RecipeListDatasource extends DataSource<Recipe> {
|
||||
disconnect() {}
|
||||
|
||||
private getFilteredData(data: Recipe[], productGroup: string): Recipe[] {
|
||||
return data.filter((x: Recipe) => productGroup === '' || x.notes === productGroup);
|
||||
return data.filter((x: Recipe) => productGroup === '' || x.productGroupId === productGroup);
|
||||
}
|
||||
|
||||
private getPagedData(data: Recipe[]) {
|
||||
@@ -93,12 +86,6 @@ export class RecipeListDatasource extends DataSource<Recipe> {
|
||||
switch (sort.active) {
|
||||
case 'name':
|
||||
return compare(a.sku.name, b.sku.name, isAsc);
|
||||
case 'salePrice':
|
||||
return compare(a.salePrice, b.salePrice, isAsc);
|
||||
case 'costPrice':
|
||||
return compare(a.costPrice, b.costPrice, isAsc);
|
||||
case 'costPercentage':
|
||||
return compare(a.costPrice / a.salePrice, b.costPrice / b.salePrice, isAsc);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -108,7 +95,6 @@ export class RecipeListDatasource extends DataSource<Recipe> {
|
||||
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
|
||||
const compare = (a: string | number | Date, b: string | number | Date, isAsc: boolean) =>
|
||||
(a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
|
||||
const compareDate = (a: string, b: string, isAsc: boolean) =>
|
||||
(moment(a, 'DD-MMM-YYYY').toDate() < moment(b, 'DD-MMM-YYYY').toDate() ? -1 : 1) *
|
||||
(isAsc ? 1 : -1);
|
||||
// const compareDate = (a: string, b: string, isAsc: boolean) =>
|
||||
// (moment(a, 'DD-MMM-YYYY').toDate() < moment(b, 'DD-MMM-YYYY').toDate() ? -1 : 1) *
|
||||
// (isAsc ? 1 : -1);
|
||||
|
||||
Reference in New Issue
Block a user