Fix: Username unique index was case sensitive and this allowed duplicate names.
Feature: Moved temporal products into their own module and reverted the products module
This commit is contained in:
@ -1,3 +0,0 @@
|
||||
.mat-radio-button ~ .mat-radio-button {
|
||||
margin-left: 16px;
|
||||
}
|
||||
|
||||
@ -1,111 +1,83 @@
|
||||
<div fxLayout="column">
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Product</mat-card-title>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Code</mat-label>
|
||||
<input matInput placeholder="Code" formControlName="code" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex="75">
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput #name placeholder="Name" formControlName="name" />
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="25">
|
||||
<mat-label>Units</mat-label>
|
||||
<input matInput placeholder="Units" formControlName="units" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Price</mat-label>
|
||||
<input matInput type="number" placeholder="Price" formControlName="price" />
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Quantity</mat-label>
|
||||
<input matInput type="number" placeholder="Quantity" formControlName="quantity" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-checkbox formControlName="hasHappyHour">Has Happy Hour?</mat-checkbox>
|
||||
<mat-checkbox formControlName="isNotAvailable">Is Not Available?</mat-checkbox>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Menu Category</mat-label>
|
||||
<mat-select placeholder="Menu Category" formControlName="menuCategory">
|
||||
<mat-option *ngFor="let mc of menuCategories" [value]="mc.id">
|
||||
{{ mc.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Sale Category</mat-label>
|
||||
<mat-select placeholder="Sale Category" formControlName="saleCategory">
|
||||
<mat-option *ngFor="let sc of saleCategories" [value]="sc.id">
|
||||
{{ sc.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="!!item.id">
|
||||
Delete
|
||||
</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-radio-group [hidden]="this.list.length === 1">
|
||||
<mat-radio-button
|
||||
class="example-radio-button"
|
||||
*ngFor="let product of list"
|
||||
[value]="this.product.versionId"
|
||||
(change)="loadProduct($event)"
|
||||
[checked]="this.item.versionId === product.versionId"
|
||||
>
|
||||
{{ !!product.validFrom ? product.validFrom : '\u221E' }} -
|
||||
{{ !!product.validTill ? product.validTill : '\u221E' }}
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Product</mat-card-title>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex="75">
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput #name placeholder="Name" formControlName="name" />
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="25">
|
||||
<mat-label>Units</mat-label>
|
||||
<input matInput placeholder="Units" formControlName="units" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Price</mat-label>
|
||||
<input matInput type="number" placeholder="Price" formControlName="price" />
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Quantity</mat-label>
|
||||
<input matInput type="number" placeholder="Quantity" formControlName="quantity" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-checkbox formControlName="hasHappyHour">Has Happy Hour?</mat-checkbox>
|
||||
<mat-checkbox formControlName="isNotAvailable">Is Not Available?</mat-checkbox>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Menu Category</mat-label>
|
||||
<mat-select placeholder="Menu Category" formControlName="menuCategory">
|
||||
<mat-option *ngFor="let mc of menuCategories" [value]="mc.id">
|
||||
{{ mc.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Sale Category</mat-label>
|
||||
<mat-select placeholder="Sale Category" formControlName="saleCategory">
|
||||
<mat-option *ngFor="let sc of saleCategories" [value]="sc.id">
|
||||
{{ sc.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="!!item.id">
|
||||
Delete
|
||||
</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatRadioChange } from '@angular/material/radio';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { MenuCategory } from '../../core/menu-category';
|
||||
@ -22,7 +21,6 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
menuCategories: MenuCategory[] = [];
|
||||
saleCategories: SaleCategory[] = [];
|
||||
item: Product = new Product();
|
||||
list: Product[] = [];
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -34,7 +32,6 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
code: { value: '', disabled: true },
|
||||
name: '',
|
||||
units: '',
|
||||
menuCategory: '',
|
||||
@ -49,21 +46,19 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as {
|
||||
items: Product[];
|
||||
item: Product;
|
||||
menuCategories: MenuCategory[];
|
||||
saleCategories: SaleCategory[];
|
||||
};
|
||||
this.menuCategories = data.menuCategories;
|
||||
this.saleCategories = data.saleCategories;
|
||||
this.list = data.items;
|
||||
this.showItem(this.list[this.list.length - 1]);
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: Product) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
code: this.item.code || '(Auto)',
|
||||
name: this.item.name || '',
|
||||
units: this.item.units || '',
|
||||
menuCategory: this.item.menuCategory ? this.item.menuCategory.id : '',
|
||||
@ -96,7 +91,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.versionId as string).subscribe(
|
||||
this.ser.delete(this.item.id as string).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/products');
|
||||
@ -138,9 +133,4 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
this.item.quantity = +formModel.quantity;
|
||||
return this.item;
|
||||
}
|
||||
|
||||
loadProduct($event: MatRadioChange) {
|
||||
const product = this.list.find((x) => x.versionId === $event.value);
|
||||
this.showItem(product as Product);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,3 +2,23 @@
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.material-icons {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.mat-column-name {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.mat-column-price,
|
||||
.mat-column-menuCategory,
|
||||
.mat-column-saleCategory,
|
||||
.mat-column-info {
|
||||
margin-left: 4px;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.mat-column-quantity {
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Yield Column -->
|
||||
<!-- Quantity Column -->
|
||||
<ng-container matColumnDef="quantity">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Quantity</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{
|
||||
|
||||
@ -111,7 +111,6 @@ export class ProductListComponent implements OnInit {
|
||||
|
||||
exportCsv() {
|
||||
const headers = {
|
||||
Code: 'code',
|
||||
Name: 'name',
|
||||
Units: 'units',
|
||||
Price: 'price',
|
||||
|
||||
@ -9,10 +9,10 @@ import { ProductService } from './product.service';
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProductResolver implements Resolve<Product[]> {
|
||||
export class ProductResolver implements Resolve<Product> {
|
||||
constructor(private ser: ProductService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<Product[]> {
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<Product> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
|
||||
@ -17,11 +17,11 @@ const serviceName = 'ProductService';
|
||||
export class ProductService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string | null): Observable<Product[]> {
|
||||
get(id: string | null): Observable<Product> {
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return this.http
|
||||
.get<Product[]>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Product[]>;
|
||||
.get<Product>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Product>;
|
||||
}
|
||||
|
||||
list(): Observable<Product[]> {
|
||||
@ -56,7 +56,7 @@ export class ProductService {
|
||||
|
||||
update(product: Product): Observable<void> {
|
||||
return this.http
|
||||
.put<Product>(`${url}/${product.versionId}`, product, httpOptions)
|
||||
.put<Product>(`${url}/${product.id}`, product, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<void>;
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ const productsRoutes: Routes = [
|
||||
permission: 'Products',
|
||||
},
|
||||
resolve: {
|
||||
items: ProductResolver,
|
||||
item: ProductResolver,
|
||||
menuCategories: MenuCategoryListResolver,
|
||||
saleCategories: SaleCategoryListResolver,
|
||||
},
|
||||
@ -45,7 +45,7 @@ const productsRoutes: Routes = [
|
||||
permission: 'Products',
|
||||
},
|
||||
resolve: {
|
||||
items: ProductResolver,
|
||||
item: ProductResolver,
|
||||
menuCategories: MenuCategoryListResolver,
|
||||
saleCategories: SaleCategoryListResolver,
|
||||
},
|
||||
|
||||
@ -11,7 +11,6 @@ import { MatOptionModule } from '@angular/material/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
|
||||
@ -36,7 +35,6 @@ import { ProductsRoutingModule } from './products-routing.module';
|
||||
MatCheckboxModule,
|
||||
ReactiveFormsModule,
|
||||
ProductsRoutingModule,
|
||||
MatRadioModule,
|
||||
],
|
||||
declarations: [ProductListComponent, ProductDetailComponent],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user