Commit c797b756 by DESKTOP-E0VCCBD\zedan

Update

parent 223b0d20
......@@ -43,12 +43,12 @@
<tr *ngFor="let product of productList; let i = index">
<td class="text-center">{{ i + 1 }}</td>
<!-- </tr> -->
<td class="text-center">{{ product.id_product }}</td>
<td class="text-center">{{ product.product_name }}</td>
<td class="text-center">{{ product.product_amount}}</td>
<td class="text-center">{{ product.category}}</td>
<td class="text-center">{{product.status}}</td>
<td class="text-center">{{product.time_date}}</td>
<td class="text-center">{{ product.equipment_id }}</td>
<td class="text-center">{{ product.equipment_name }}</td>
<td class="text-center">{{ product.quantity_total}}</td>
<td class="text-center">{{ product.description}}</td>
<td class="text-center">{{product.location}}</td>
<td class="text-center">{{product.created_at}}</td>
<!-- <td>{{ product.product_balance}}</td> -->
<td>
......@@ -56,7 +56,7 @@
<a
href="javascript:void(0);"
class="ti-btn ti-btn-soft-secondary hs-tooltip-toggle"
(click)="addToCart(product)"
(click)="addToCart()"
>
<i class="ti ti-shopping-cart"></i>
<span
......
import { EquipmentService } from 'src/app/services/equirement.service';
import { Component } from '@angular/core';
import { EquipmentModel } from 'src/app/models/equipments.model';
@Component({
selector: 'app-product-management',
......@@ -6,57 +9,53 @@ import { Component } from '@angular/core';
styleUrls: ['./product-management.component.scss']
})
export class ProductManagementComponent {
productList: any[] = [];
disabled = '';
active: any;
get: any;
delete: any;
ngOnInit(): void {
this.productList = [
{ id_product: 101, product_name: 'Laptop', product_amount: 5, category: 'Electronics', status: 'Available', time_date: '2025-03-11 14:30' },
{ id_product: 102, product_name: 'Smartphone', product_amount: 10, category: 'Electronics', status: 'Out of Stock', time_date: '2025-03-10 12:15' },
{ id_product: 103, product_name: 'Desk Chair', product_amount: 3, category: 'Furniture', status: 'Available', time_date: '2025-03-09 09:45' }
];
}
productList: EquipmentModel[] = []
selectedProduct?: EquipmentModel
constructor(private EquipmentService: EquipmentService) { }
ngOnInit() {
this.getUser()
}
getUser() {
this.EquipmentService.getLists().subscribe(result => {
this.productList = result
})
}
getUserId() {
this.EquipmentService.getById("73079f3b-b58a-46e6-a779-20a64911e505").subscribe(result => {
console.log(result)
})
}
saveUser() {
if (this.selectedProduct) {
this.EquipmentService.save(this.selectedProduct).subscribe(result => {
console.log(result)
})
}
}
deleteUser() {
if (this.selectedProduct) {
this.EquipmentService.delete(this.selectedProduct).subscribe(result => {
console.log(result)
})
}
}
updateUser() {
if (this.selectedProduct) {
this.EquipmentService.update(this.selectedProduct).subscribe(result => {
console.log(result)
})
}
}
addToCart(){
}
// constructor(
// private http: HttpClient,
// ) {
// }
// ngOnInit(): void {
// this.getProduct();
// }
// getProduct(): void {
// this.http.get(environment.api + "/product").subscribe((result: any) => {
// console.log(result);
// this.productList = result.data;
// }, (error: HttpErrorResponse) => {
// alert(error.message);
// });
// }
// deleteProduct(id: string): void {
// this.http.delete(`${environment.api}/product/${id}`).subscribe(
// (result: any) => {
// console.log(result);
// this.getProduct();
// },
// (error: HttpErrorResponse) => {
// alert(error.message);
// }
// );
// }
addToCart(product: any) {
let cart = localStorage.getItem('cart');
let cartItems = cart ? JSON.parse(cart) : [];
cartItems.push(product);
localStorage.setItem('cart', JSON.stringify(cartItems));
}
}
......@@ -105,7 +105,7 @@
<div class="grid grid-cols-12 gap-6">
<div
class="col-span-12 md:col-span-6 xxl:col-span-3 team-box"
*ngFor="let user of projectList"
*ngFor="let pj of projectList"
>
<div class="box overflow-hidden mb-0">
<div
......@@ -136,15 +136,15 @@
<div class="space-y-2">
<div class="mt-4">
<h2 class="text-base font-semibold">
{{ user.project_name }}
{{ pj.project_name }}
</h2>
<p class="text-xs text-gray-500 dark:text-white/70">
{{ user.email }}
<p class="text-xs text-base text-gray-500 dark:text-white/70">
เริ่ม {{ pj.start_date }} สินสุด {{ pj.end_date }}
</p>
</div>
<span
class="max-w-[10rem] truncate whitespace-nowrap inline-block py-1.5 px-3 rounded-sm text-xs font-medium bg-primary/20 text-primary"
> PTT</span
> {{pj.project_desc}}</span
>
<div
class="flex space-x-1 rtl:space-x-reverse justify-center text-center"
......
import { Component, OnInit } from '@angular/core';
import { ProJectModel } from 'src/app/models/project.model';
import { ProjectService } from 'src/app/services/project.service';
@Component({
......@@ -8,22 +10,49 @@ import { Component, OnInit } from '@angular/core';
})
export class ProjectManagementComponent {
constructor() { }
projectList:any[]=[];
ngOnInit(): void {
// จำลองข้อมูลตัวอย่าง
this.projectList = [
{ id: 1, project_name: 'testtt', role: 'Admin' },
{ id: 2, project_name: 'test22', role: 'User' },
{ id: 3, project_name: '232323', role: 'Manager' }
];
}
deleteProject(){
}
selectedProject?: ProJectModel
constructor(private projectService: ProjectService) { }
ngOnInit() {
this.getProject()
}
getProject() {
this.projectService.getLists().subscribe(result => {
this.projectList = result
})
}
getProjectId() {
this.projectService.getById("73079f3b-b58a-46e6-a779-20a64911e505").subscribe(result => {
console.log(result)
})
}
saveProject() {
if (this.selectedProject) {
this.projectService.save(this.selectedProject).subscribe(result => {
console.log(result)
})
}
}
deleteProject() {
if (this.selectedProject) {
this.projectService.delete(this.selectedProject).subscribe(result => {
console.log(result)
})
}
}
updateProject() {
if (this.selectedProject) {
this.projectService.update(this.selectedProject).subscribe(result => {
console.log(result)
})
}
}
}
import { TranslateService } from "@ngx-translate/core";
import { BaseModel } from "./base.model";
export class EquipmentModel extends BaseModel {
equipment_id: string;
equipment_name: string;
description?: string;
quantity_total: number;
is_returnable: boolean;
location?: string;
created_at: string;
updated_at: string;
constructor(data?: Partial<EquipmentModel>, translateService?: TranslateService) {
super(data, translateService);
this.equipment_id = data?.equipment_id ?? '';
this.equipment_name = data?.equipment_name ?? '';
this.description = data?.description ?? '';
this.quantity_total = data?.quantity_total ?? 0;
this.is_returnable = data?.is_returnable ?? true;
this.location = data?.location ?? '';
this.created_at = data?.created_at ?? new Date().toISOString();
this.updated_at = data?.updated_at ?? new Date().toISOString();
}
}
import { TranslateService } from "@ngx-translate/core";
import { BaseModel } from "./base.model";
export class ProJectModel extends BaseModel {
project_id: string;
project_name: string;
project_desc?: string;
start_date: string;
end_date: string;
created_at: string;
updated_at: string;
constructor(data?: Partial<ProJectModel>, translateService?: TranslateService) {
super(data, translateService);
this.project_id = data?.project_id ?? '';
this.project_name = data?.project_name ?? '';
this.project_desc = data?.project_desc ?? '';
this.start_date = data?.start_date ?? new Date().toISOString();
this.end_date = data?.end_date ?? new Date().toISOString();
this.created_at = data?.created_at ?? new Date().toISOString();
this.updated_at = data?.updated_at ?? new Date().toISOString();
}
}
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { EquipmentModel } from '../models/equipments.model';
import { map, tap, switchMap, filter, reduce } from "rxjs/operators";
@Injectable({
providedIn: 'root'
})
export class EquirementService {
export class EquipmentService {
apiBaseUrl = environment.baseUrl + "/equipments";
constructor(
private http: HttpClient
) { }
getById(id: string) {
return this.http
.get<EquipmentModel>(this.apiBaseUrl + "/" + id)
.pipe(map((e) => new EquipmentModel(e)));
}
getLists() {
return this.http
.get<EquipmentModel[]>(this.apiBaseUrl)
.pipe(
map((e) => e.map((e) => new EquipmentModel(e)))
);
}
save(body: EquipmentModel) {
return this.http.post<{
"message": string,
"user": EquipmentModel
}>(this.apiBaseUrl, new EquipmentModel(body));
}
update(body: EquipmentModel) {
return this.http.put<{
"message": string,
"user": EquipmentModel
}>(this.apiBaseUrl + "/" + body.equipment_id, new EquipmentModel(body));
}
delete(body: EquipmentModel) {
return this.http.delete<{
"message": string,
"user": EquipmentModel
}>(this.apiBaseUrl + "/" + body.equipment_id);
}
constructor() { }
}
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { ProJectModel } from '../models/project.model';
import { map, tap, switchMap, filter, reduce } from "rxjs/operators";
@Injectable({
providedIn: 'root'
})
export class ProjectService {
apiBaseUrl = environment.baseUrl + "/projects";
constructor(
private http: HttpClient
) { }
getById(id: string) {
return this.http
.get<ProJectModel>(this.apiBaseUrl + "/" + id)
.pipe(map((e) => new ProJectModel(e)));
}
getLists() {
return this.http
.get<ProJectModel[]>(this.apiBaseUrl)
.pipe(
map((e) => e.map((e) => new ProJectModel(e)))
);
}
save(body: ProJectModel) {
return this.http.post<{
"message": string,
"user": ProJectModel
}>(this.apiBaseUrl, new ProJectModel(body));
}
update(body: ProJectModel) {
return this.http.put<{
"message": string,
"user": ProJectModel
}>(this.apiBaseUrl + "/" + body.project_id, new ProJectModel(body));
}
delete(body: ProJectModel) {
return this.http.delete<{
"message": string,
"user": ProJectModel
}>(this.apiBaseUrl + "/" + body.project_id);
}
constructor() { }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment