This commit is contained in:
Amritanshu
2019-06-15 23:09:43 +05:30
parent 3dcf1c4c42
commit 459ab244ff
70 changed files with 2140 additions and 103 deletions

View File

@ -0,0 +1,3 @@
.example-card {
max-width: 400px;
}

View File

@ -0,0 +1,21 @@
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
<mat-card fxFlex>
<mat-card-title-group>
<mat-card-title>Product Group</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>Name</mat-label>
<input matInput #nameElement placeholder="Name" formControlName="name" (keyup.enter)="save()">
</mat-form-field>
</div>
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button (click)="save()" color="primary">Save</button>
</mat-card-actions>
</mat-card>
</div>

View File

@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ProductGroupDetailComponent} from './product-group-detail.component';
describe('ProductGroupDetailComponent', () => {
let component: ProductGroupDetailComponent;
let fixture: ComponentFixture<ProductGroupDetailComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ProductGroupDetailComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ProductGroupDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,73 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
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';
@Component({
selector: 'app-product-group-detail',
templateUrl: './product-group-detail.component.html',
styleUrls: ['./product-group-detail.component.css']
})
export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
form: FormGroup;
item: ProductGroup;
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private toaster: ToasterService,
private ser: ProductGroupService
) {
this.createForm();
}
createForm() {
this.form = this.fb.group({
name: ''
});
}
ngOnInit() {
this.route.data
.subscribe((data: { item: ProductGroup }) => {
this.showItem(data.item);
});
}
showItem(item: ProductGroup) {
this.item = item;
this.form.setValue({
name: this.item.name,
});
}
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
}, 0);
}
save() {
this.ser.saveOrUpdate(this.getItem())
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/product-groups');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
getItem(): ProductGroup {
const formModel = this.form.value;
this.item.name = formModel.name;
return this.item;
}
}