fix(ref): align io8.ref product component with CE V2 logic

This commit is contained in:
Azmat-7860
2026-11-04 23:37:58 +05:30
parent 7605927b90
commit d8d0eb85cb
2 changed files with 23 additions and 18 deletions
@@ -24,8 +24,10 @@
<div *ngIf="error; else loadingSpinner">{{error}}</div> <div *ngIf="error; else loadingSpinner">{{error}}</div>
</clr-dg-placeholder> </clr-dg-placeholder>
<!-- COLUMN HEADERS --> <!-- DYNAMIC COLUMN HEADERS -->
{{LIST_ITEMS}} <clr-dg-column *ngFor="let col of getColumns()" [clrDgField]="col">
<ng-container *clrDgHideableColumn="{hidden: false}">{{ col | titlecase }}</ng-container>
</clr-dg-column>
<clr-dg-column> <clr-dg-column>
<ng-container *clrDgHideableColumn="{hidden: false}"> <ng-container *clrDgHideableColumn="{hidden: false}">
@@ -33,11 +35,11 @@
</ng-container> </ng-container>
</clr-dg-column> </clr-dg-column>
<!-- DATA ROWS --> <!-- DYNAMIC DATA ROWS -->
<clr-dg-row *clrDgItems="let item of items" [clrDgItem]="item"> <clr-dg-row *clrDgItems="let item of items" [clrDgItem]="item">
<clr-dg-cell>{{item.name}}</clr-dg-cell> <clr-dg-cell *ngFor="let col of getColumns()">
<clr-dg-cell>{{item.description}}</clr-dg-cell> {{ item[col] }}
<clr-dg-cell>{{item.active}}</clr-dg-cell> </clr-dg-cell>
<clr-dg-cell> <clr-dg-cell>
<span style="cursor: pointer; margin-right: 10px;" (click)="onEdit(item)" title="Edit"> <span style="cursor: pointer; margin-right: 10px;" (click)="onEdit(item)" title="Edit">
@@ -67,7 +69,7 @@
<clr-modal [(clrModalOpen)]="modalAdd" [clrModalSize]="'lg'" [clrModalStaticBackdrop]="true"> <clr-modal [(clrModalOpen)]="modalAdd" [clrModalSize]="'lg'" [clrModalStaticBackdrop]="true">
<h3 class="modal-title">Add Product</h3> <h3 class="modal-title">Add Product</h3>
<div class="modal-body"> <div class="modal-body">
<form [formGroup]="entryForm"> <form #addForm="ngForm">
<div class="clr-row"> <div class="clr-row">
{{FORM_FIELDS}} {{FORM_FIELDS}}
</div> </div>
@@ -83,7 +85,7 @@
<clr-modal [(clrModalOpen)]="modalEdit" [clrModalSize]="'lg'" [clrModalStaticBackdrop]="true"> <clr-modal [(clrModalOpen)]="modalEdit" [clrModalSize]="'lg'" [clrModalStaticBackdrop]="true">
<h3 class="modal-title">Edit Product (ID: {{rowSelected.id}})</h3> <h3 class="modal-title">Edit Product (ID: {{rowSelected.id}})</h3>
<div class="modal-body" *ngIf="rowSelected"> <div class="modal-body" *ngIf="rowSelected">
<form> <form #editForm="ngForm">
<div class="clr-row"> <div class="clr-row">
{{FORM_FIELDS}} {{FORM_FIELDS}}
</div> </div>
@@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { ProductService } from './Product.service'; import { ProductService } from './Product.service';
import { ApiRequestService } from 'src/app/services/api/api-request.service';
@Component({ @Component({
selector: 'app-Product', selector: 'app-Product',
@@ -14,27 +14,30 @@ export class ProductComponent implements OnInit {
modaldelete = false; modaldelete = false;
modalEdit = false; modalEdit = false;
modalAdd = false; modalAdd = false;
public entryForm: FormGroup;
loading = false; loading = false;
items: any[] = []; items: any[] = [];
selected: any[] = []; selected: any[] = [];
error: string; error: string;
/* {{RELATION_DECLARATIONS}} */
constructor( constructor(
private mainService: ProductService, private mainService: ProductService,
private apiRequest: ApiRequestService,
private toastr: ToastrService, private toastr: ToastrService,
private _fb: FormBuilder,
private router: Router, private router: Router,
private route: ActivatedRoute private route: ActivatedRoute
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getData(); this.getData();
this.entryForm = this._fb.group({ /* {{RELATION_LOADERS}} */
name: [null], }
description: [null],
active: [true] getColumns(): string[] {
}); if (!this.items || this.items.length === 0) {
return [];
}
return Object.keys(this.items[0]).filter(k => k !== 'id');
} }
getData() { getData() {
@@ -52,7 +55,7 @@ export class ProductComponent implements OnInit {
} }
goToAdd() { goToAdd() {
this.entryForm.reset({ active: true }); this.rowSelected = {};
this.modalAdd = true; this.modalAdd = true;
} }
@@ -78,7 +81,7 @@ export class ProductComponent implements OnInit {
onCreate() { onCreate() {
this.modalAdd = false; this.modalAdd = false;
this.mainService.create(this.entryForm.value).subscribe(() => { this.mainService.create(this.rowSelected).subscribe(() => {
this.toastr.success('Added successfully'); this.toastr.success('Added successfully');
this.getData(); this.getData();
}, (error) => { }, (error) => {