Product Group

This commit is contained in:
Amritanshu
2019-06-16 01:39:37 +05:30
parent 459ab244ff
commit 52e978b3b0
20 changed files with 321 additions and 174 deletions

View File

@ -9,13 +9,34 @@
fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex>
<mat-label>Name</mat-label>
<input matInput #nameElement placeholder="Name" formControlName="name" (keyup.enter)="save()">
<input matInput #nameElement placeholder="Name" formControlName="name">
</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>Discount Limit</mat-label>
<input matInput type="number" placeholder="Discount Limit" formControlName="discountLimit" class="right-align">
<span matSuffix>%</span>
</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>Group Type</mat-label>
<input matInput placeholder="Group Type" formControlName="groupType">
</mat-form-field>
</div>
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px">
<mat-checkbox formControlName="isModifierCompulsory">Is Modifier Compulsory?</mat-checkbox>
<mat-checkbox formControlName="isActive">Is Active?</mat-checkbox>
</div>
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button (click)="save()" color="primary">Save</button>
<button mat-raised-button [disabled]="item.isFixture" color="primary" (click)="save()">Save</button>
<button mat-raised-button [disabled]="item.isFixture" color="warn" (click)="confirmDelete()" *ngIf="!!item.id">Delete</button>
</mat-card-actions>
</mat-card>
</div>

View File

@ -1,10 +1,12 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from "@angular/material";
import {ProductGroupService} from '../product-group.service';
import {ProductGroup} from '../../core/product-group';
import {ActivatedRoute, Router} from '@angular/router';
import {ToasterService} from '../../core/toaster.service';
import {FormBuilder, FormGroup} from '@angular/forms';
import { ProductGroupService } from '../product-group.service';
import { ProductGroup } from '../../core/product-group';
import { ToasterService } from '../../core/toaster.service';
import { ConfirmDialogComponent } from "../../shared/confirm-dialog/confirm-dialog.component";
@Component({
selector: 'app-product-group-detail',
@ -19,6 +21,7 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
constructor(
private route: ActivatedRoute,
private router: Router,
private dialog: MatDialog,
private fb: FormBuilder,
private toaster: ToasterService,
private ser: ProductGroupService
@ -28,7 +31,11 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
createForm() {
this.form = this.fb.group({
name: ''
name: '',
discountLimit: '',
isModifierCompulsory: '',
groupType: '',
isActive: ''
});
}
@ -43,6 +50,10 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
this.item = item;
this.form.setValue({
name: this.item.name,
discountLimit: this.item.discountLimit,
isModifierCompulsory: this.item.isModifierCompulsory,
groupType: this.item.groupType,
isActive: this.item.isActive
});
}
@ -65,9 +76,39 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
);
}
delete() {
this.ser.delete(this.item.id)
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/product-groups');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Delete Product Group?', content: 'Are you sure? This cannot be undone.'}
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.delete();
}
});
}
getItem(): ProductGroup {
const formModel = this.form.value;
this.item.name = formModel.name;
this.item.discountLimit = +formModel.discountLimit;
this.item.isModifierCompulsory = formModel.isModifierCompulsory;
this.item.groupType = formModel.groupType;
this.item.isActive = formModel.isActive;
return this.item;
}
}