Skip to content

Commit

Permalink
Product: Integrate register with API #38
Browse files Browse the repository at this point in the history
  • Loading branch information
kapit4n committed Jan 7, 2022
1 parent 9094da4 commit 16366c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
<table class="table">
<tr>
<th>Product</th>
<th>Price</th>
<th>Cost</th>
<th *ngIf="false">Category</th>
<th></th>
<th>Code</th>
<th>Category</th>
<th>Actions</th>
</tr>
<tr *ngFor="let product of products">
<td>{{product.name}}</td>
<td>{{product.price}}</td>
<td>{{product.cost}}</td>
<td *ngIf="false">{{product.category?.name}}</td>
<td>{{product.code}}</td>
<td>{{product.Category?.name}}</td>
<td>
<button class="btn" (click)="openProduct(product.id)">Edit</button> &nbsp;
<button class="btn btn-danger" (click)="removeProduct(product.id)">Delete</button>
Expand Down
22 changes: 2 additions & 20 deletions src/app/pages/reg/reg-product/reg-product.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ <h2>Register Product</h2>
</ng-template>
</div>
<div class="col-7">

<div class="form-group">
<label for="category">Category</label>
<select class="form-control" id="category" required [(ngModel)]="productInfo.categoryId" [ngModelOptions]="{standalone: true}">
<option *ngFor="let cat of categories" [value]="cat.id" >{{cat.name}}</option>
</select>
</div>

<div class="form-group">
<label for="name" i18n>Product Name</label>
<input type="text" class="form-control" id="name" value="Data"
Expand All @@ -26,26 +28,6 @@ <h2>Register Product</h2>
required [(ngModel)]="productInfo.code" [ngModelOptions]="{standalone: true}">
</div>

<div class="form-group">
<label for="price" i18n>Price</label>
<input type="text" class="form-control" id="price" value="Data"
required [(ngModel)]="productInfo.price" [ngModelOptions]="{standalone: true}">
</div>

<div class="form-group">
<label for="cost" i18n>Cost</label>
<input type="text" class="form-control" id="cost" value="Data"
required [(ngModel)]="productInfo.cost" [ngModelOptions]="{standalone: true}">
</div>


<div class="form-group">
<label for="stock" i18n>Inventory</label>
<input type="text" class="form-control" id="stock" value="Data"
required [(ngModel)]="productInfo.stock" [ngModelOptions]="{standalone: true}">
</div>


<div class="form-group">
<label for="img" i18n>Img</label>
<input type="text" class="form-control" id="img" value="Data"
Expand Down
18 changes: 13 additions & 5 deletions src/app/pages/reg/reg-product/reg-product.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";
import { ActivatedRoute } from '@angular/router';
import { IProduct, RProductService } from '../../../services/reg/r-product.service';
import {
IProduct, RProductService
} from '../../../services/reg/r-product.service';
import {
RCategoryService,
ICategory
Expand All @@ -13,7 +15,7 @@ import {
styleUrls: ['./reg-product.component.css']
})
export class RegProductComponent implements OnInit {
productInfo: IProduct;
productInfo: IProduct ;
categories: ICategory[];

constructor(private productSvc: RProductService, private router: Router,
Expand All @@ -22,9 +24,15 @@ export class RegProductComponent implements OnInit {
this.categories = [];
}

isNew() {
let id = this.route.snapshot.paramMap.get("id");
return !id && id == "new";
}

ngOnInit() {
let id = this.route.snapshot.paramMap.get("id");
if (id != "new") {
console.log(id)
if (id && id != "new") {
this.productSvc.getById(id).subscribe(product => {
this.productInfo = product;
})
Expand All @@ -36,7 +44,7 @@ export class RegProductComponent implements OnInit {

save() {
if (this.productInfo.id) {
this.productSvc.update(this.productInfo).subscribe( product => {
this.productSvc.update(this.productInfo).subscribe(product => {
this.router.navigate(['/reg/products']);
});
} else {
Expand All @@ -45,7 +53,7 @@ export class RegProductComponent implements OnInit {
});
}
}

cancel() {
this.router.navigate(['/reg/products']);
}
Expand Down

0 comments on commit 16366c3

Please sign in to comment.