Removed IsModifierCompulsory from MenuCategory as it is now not needed and minimum in ModifierCategory set to non-zero to achieve the same.
Fix: DiscountLimit was not scaled to 100 in MenuCategory detail. So it is now chaled in the json and scaled back in the frontend for the list as that was not supposed to be scaled. Feature: Modifier is now done Fix: In product save, it was checking menu_category second time again instead of sale_category
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ModifierService } from '../modifier.service';
|
||||
import { Modifier } from '../../core/modifier';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ModifierCategory } from "../../core/modifier-category";
|
||||
|
||||
@Component({
|
||||
selector: 'app-modifier-detail',
|
||||
templateUrl: './modifier-detail.component.html',
|
||||
styleUrls: ['./modifier-detail.component.css']
|
||||
})
|
||||
export class ModifierDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('name', { static: true }) nameElement: ElementRef;
|
||||
form: FormGroup;
|
||||
modifierCategories: ModifierCategory[];
|
||||
item: Modifier;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: ModifierService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
showInBill: '',
|
||||
price: '',
|
||||
modifierCategory: ''
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Modifier, modifierCategories: ModifierCategory[] }) => {
|
||||
this.modifierCategories = data.modifierCategories;
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: Modifier) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name || '',
|
||||
showInBill: this.item.showInBill,
|
||||
price: this.item.price || '',
|
||||
modifierCategory: this.item.modifierCategory.id ? this.item.modifierCategory.id : ''
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/modifiers');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/modifiers');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Modifier?', content: 'Are you sure? This cannot be undone.'}
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): Modifier {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.showInBill = formModel.showInBill;
|
||||
this.item.price = +formModel.price;
|
||||
this.item.modifierCategory.id = formModel.modifierCategory;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user