feat: add new form field components for company details and consumer management
- Implemented CompanyNameComponent, DescriptionComponent, DeviceIdComponent, EconomicCodeComponent, EmailComponent, FirstNameComponent, FiscalCodeComponent, GuildIdComponent, LastNameComponent, LegalNameComponent, LicenseStartsAtComponent, MobileComponent, MobileNumberComponent, ModelComponent, NameComponent, NationalCodeComponent, NationalIdComponent, PartnerTokenComponent, PosTypeComponent, PostalCodeComponent, ProviderIdComponent, QuantityComponent, RegistrationCodeComponent, RegistrationNumberComponent, SerialNumberComponent, SetOffComponent, SkuComponent, TerminalComponent, UnitPriceComponent, UsernameComponent. - Added field control configurations for new fields in the form. - Updated routing and branding configurations for TIS tenant. - Created consumer type models for handling individual and legal consumer data.
This commit is contained in:
+440
-339
@@ -1,387 +1,488 @@
|
||||
import { Component, OnInit, signal, ViewChild } from '@angular/core';
|
||||
import { ConfirmationService, MessageService } from 'primeng/api';
|
||||
import { Table, TableModule } from 'primeng/table';
|
||||
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, signal, ViewChild } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ConfirmationService, MessageService } from 'primeng/api';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
import { ConfirmDialogModule } from 'primeng/confirmdialog';
|
||||
import { DialogModule } from 'primeng/dialog';
|
||||
import { IconFieldModule } from 'primeng/iconfield';
|
||||
import { InputIconModule } from 'primeng/inputicon';
|
||||
import { InputNumberModule } from 'primeng/inputnumber';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
import { RadioButtonModule } from 'primeng/radiobutton';
|
||||
import { RatingModule } from 'primeng/rating';
|
||||
import { RippleModule } from 'primeng/ripple';
|
||||
import { SelectModule } from 'primeng/select';
|
||||
import { Table, TableModule } from 'primeng/table';
|
||||
import { TagModule } from 'primeng/tag';
|
||||
import { TextareaModule } from 'primeng/textarea';
|
||||
import { ToastModule } from 'primeng/toast';
|
||||
import { ToolbarModule } from 'primeng/toolbar';
|
||||
import { RatingModule } from 'primeng/rating';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
import { TextareaModule } from 'primeng/textarea';
|
||||
import { SelectModule } from 'primeng/select';
|
||||
import { RadioButtonModule } from 'primeng/radiobutton';
|
||||
import { InputNumberModule } from 'primeng/inputnumber';
|
||||
import { DialogModule } from 'primeng/dialog';
|
||||
import { TagModule } from 'primeng/tag';
|
||||
import { InputIconModule } from 'primeng/inputicon';
|
||||
import { IconFieldModule } from 'primeng/iconfield';
|
||||
import { ConfirmDialogModule } from 'primeng/confirmdialog';
|
||||
import { Product, ProductService } from '../service/product.service';
|
||||
|
||||
interface Column {
|
||||
field: string;
|
||||
header: string;
|
||||
customExportHeader?: string;
|
||||
field: string;
|
||||
header: string;
|
||||
customExportHeader?: string;
|
||||
}
|
||||
|
||||
interface ExportColumn {
|
||||
title: string;
|
||||
dataKey: string;
|
||||
title: string;
|
||||
dataKey: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-crud',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
TableModule,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
RippleModule,
|
||||
ToastModule,
|
||||
ToolbarModule,
|
||||
RatingModule,
|
||||
InputTextModule,
|
||||
TextareaModule,
|
||||
SelectModule,
|
||||
RadioButtonModule,
|
||||
InputNumberModule,
|
||||
DialogModule,
|
||||
TagModule,
|
||||
InputIconModule,
|
||||
IconFieldModule,
|
||||
ConfirmDialogModule
|
||||
],
|
||||
template: `
|
||||
<p-toolbar styleClass="mb-6">
|
||||
<ng-template #start>
|
||||
<p-button label="New" icon="pi pi-plus" severity="secondary" class="mr-2" (onClick)="openNew()" />
|
||||
<p-button severity="secondary" label="Delete" icon="pi pi-trash" outlined (onClick)="deleteSelectedProducts()" [disabled]="!selectedProducts || !selectedProducts.length" />
|
||||
</ng-template>
|
||||
selector: 'app-crud',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
TableModule,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
RippleModule,
|
||||
ToastModule,
|
||||
ToolbarModule,
|
||||
RatingModule,
|
||||
InputTextModule,
|
||||
TextareaModule,
|
||||
SelectModule,
|
||||
RadioButtonModule,
|
||||
InputNumberModule,
|
||||
DialogModule,
|
||||
TagModule,
|
||||
InputIconModule,
|
||||
IconFieldModule,
|
||||
ConfirmDialogModule,
|
||||
SharedDialogComponent,
|
||||
],
|
||||
template: `
|
||||
<p-toolbar styleClass="mb-6">
|
||||
<ng-template #start>
|
||||
<p-button
|
||||
label="New"
|
||||
icon="pi pi-plus"
|
||||
severity="secondary"
|
||||
class="mr-2"
|
||||
(onClick)="openNew()"
|
||||
/>
|
||||
<p-button
|
||||
severity="secondary"
|
||||
label="Delete"
|
||||
icon="pi pi-trash"
|
||||
outlined
|
||||
(onClick)="deleteSelectedProducts()"
|
||||
[disabled]="!selectedProducts || !selectedProducts.length"
|
||||
/>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #end>
|
||||
<p-button label="Export" icon="pi pi-upload" severity="secondary" (onClick)="exportCSV()" />
|
||||
</ng-template>
|
||||
</p-toolbar>
|
||||
<ng-template #end>
|
||||
<p-button label="Export" icon="pi pi-upload" severity="secondary" (onClick)="exportCSV()" />
|
||||
</ng-template>
|
||||
</p-toolbar>
|
||||
|
||||
<p-table
|
||||
#dt
|
||||
[value]="products()"
|
||||
[rows]="10"
|
||||
[columns]="cols"
|
||||
[paginator]="true"
|
||||
[globalFilterFields]="['name', 'country.name', 'representative.name', 'status']"
|
||||
[tableStyle]="{ 'min-width': '75rem' }"
|
||||
[(selection)]="selectedProducts"
|
||||
[rowHover]="true"
|
||||
dataKey="id"
|
||||
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} products"
|
||||
[showCurrentPageReport]="true"
|
||||
[rowsPerPageOptions]="[10, 20, 30]"
|
||||
>
|
||||
<ng-template #caption>
|
||||
<div class="flex items-center justify-between">
|
||||
<h5 class="m-0">Manage Products</h5>
|
||||
<p-iconfield>
|
||||
<p-inputicon styleClass="pi pi-search" />
|
||||
<input pInputText type="text" (input)="onGlobalFilter(dt, $event)" placeholder="Search..." />
|
||||
</p-iconfield>
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template #header>
|
||||
<tr>
|
||||
<th style="width: 3rem">
|
||||
<p-tableHeaderCheckbox />
|
||||
</th>
|
||||
<th style="min-width: 16rem">Code</th>
|
||||
<th pSortableColumn="name" style="min-width:16rem">
|
||||
Name
|
||||
<p-sortIcon field="name" />
|
||||
</th>
|
||||
<th>Image</th>
|
||||
<th pSortableColumn="price" style="min-width: 8rem">
|
||||
Price
|
||||
<p-sortIcon field="price" />
|
||||
</th>
|
||||
<th pSortableColumn="category" style="min-width:10rem">
|
||||
Category
|
||||
<p-sortIcon field="category" />
|
||||
</th>
|
||||
<th pSortableColumn="rating" style="min-width: 12rem">
|
||||
Reviews
|
||||
<p-sortIcon field="rating" />
|
||||
</th>
|
||||
<th pSortableColumn="inventoryStatus" style="min-width: 12rem">
|
||||
Status
|
||||
<p-sortIcon field="inventoryStatus" />
|
||||
</th>
|
||||
<th style="min-width: 12rem"></th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template #body let-product>
|
||||
<tr>
|
||||
<td style="width: 3rem">
|
||||
<p-tableCheckbox [value]="product" />
|
||||
</td>
|
||||
<td style="min-width: 12rem">{{ product.code }}</td>
|
||||
<td style="min-width: 16rem">{{ product.name }}</td>
|
||||
<td>
|
||||
<img [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image" [alt]="product.name" style="width: 64px" class="rounded" />
|
||||
</td>
|
||||
<td>{{ product.price | currency: 'USD' }}</td>
|
||||
<td>{{ product.category }}</td>
|
||||
<td>
|
||||
<p-rating [(ngModel)]="product.rating" [readonly]="true" />
|
||||
</td>
|
||||
<td>
|
||||
<p-tag [value]="product.inventoryStatus" [severity]="getSeverity(product.inventoryStatus)" />
|
||||
</td>
|
||||
<td>
|
||||
<p-button icon="pi pi-pencil" class="mr-2" [rounded]="true" [outlined]="true" (click)="editProduct(product)" />
|
||||
<p-button icon="pi pi-trash" severity="danger" [rounded]="true" [outlined]="true" (click)="deleteProduct(product)" />
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
<p-table
|
||||
#dt
|
||||
[value]="products()"
|
||||
[rows]="10"
|
||||
[columns]="cols"
|
||||
[paginator]="true"
|
||||
[globalFilterFields]="['name', 'country.name', 'representative.name', 'status']"
|
||||
[tableStyle]="{ 'min-width': '75rem' }"
|
||||
[(selection)]="selectedProducts"
|
||||
[rowHover]="true"
|
||||
dataKey="id"
|
||||
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} products"
|
||||
[showCurrentPageReport]="true"
|
||||
[rowsPerPageOptions]="[10, 20, 30]"
|
||||
>
|
||||
<ng-template #caption>
|
||||
<div class="flex items-center justify-between">
|
||||
<h5 class="m-0">Manage Products</h5>
|
||||
<p-iconfield>
|
||||
<p-inputicon styleClass="pi pi-search" />
|
||||
<input
|
||||
pInputText
|
||||
type="text"
|
||||
(input)="onGlobalFilter(dt, $event)"
|
||||
placeholder="Search..."
|
||||
/>
|
||||
</p-iconfield>
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template #header>
|
||||
<tr>
|
||||
<th style="width: 3rem">
|
||||
<p-tableHeaderCheckbox />
|
||||
</th>
|
||||
<th style="min-width: 16rem">Code</th>
|
||||
<th pSortableColumn="name" style="min-width:16rem">
|
||||
Name
|
||||
<p-sortIcon field="name" />
|
||||
</th>
|
||||
<th>Image</th>
|
||||
<th pSortableColumn="price" style="min-width: 8rem">
|
||||
Price
|
||||
<p-sortIcon field="price" />
|
||||
</th>
|
||||
<th pSortableColumn="category" style="min-width:10rem">
|
||||
Category
|
||||
<p-sortIcon field="category" />
|
||||
</th>
|
||||
<th pSortableColumn="rating" style="min-width: 12rem">
|
||||
Reviews
|
||||
<p-sortIcon field="rating" />
|
||||
</th>
|
||||
<th pSortableColumn="inventoryStatus" style="min-width: 12rem">
|
||||
Status
|
||||
<p-sortIcon field="inventoryStatus" />
|
||||
</th>
|
||||
<th style="min-width: 12rem"></th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template #body let-product>
|
||||
<tr>
|
||||
<td style="width: 3rem">
|
||||
<p-tableCheckbox [value]="product" />
|
||||
</td>
|
||||
<td style="min-width: 12rem">{{ product.code }}</td>
|
||||
<td style="min-width: 16rem">{{ product.name }}</td>
|
||||
<td>
|
||||
<img
|
||||
[src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image"
|
||||
[alt]="product.name"
|
||||
style="width: 64px"
|
||||
class="rounded"
|
||||
/>
|
||||
</td>
|
||||
<td>{{ product.price | currency: 'USD' }}</td>
|
||||
<td>{{ product.category }}</td>
|
||||
<td>
|
||||
<p-rating [(ngModel)]="product.rating" [readonly]="true" />
|
||||
</td>
|
||||
<td>
|
||||
<p-tag
|
||||
[value]="product.inventoryStatus"
|
||||
[severity]="getSeverity(product.inventoryStatus)"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<p-button
|
||||
icon="pi pi-pencil"
|
||||
class="mr-2"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
(click)="editProduct(product)"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
(click)="deleteProduct(product)"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
|
||||
<p-dialog [(visible)]="productDialog" [style]="{ width: '450px' }" header="Product Details" [modal]="true">
|
||||
<ng-template #content>
|
||||
<div class="flex flex-col gap-6">
|
||||
<img [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image" [alt]="product.image" class="block m-auto pb-4" *ngIf="product.image" />
|
||||
<div>
|
||||
<label for="name" class="block font-bold mb-3">Name</label>
|
||||
<input type="text" pInputText id="name" [(ngModel)]="product.name" required autofocus fluid />
|
||||
<small class="text-red-500" *ngIf="submitted && !product.name">Name is required.</small>
|
||||
</div>
|
||||
<div>
|
||||
<label for="description" class="block font-bold mb-3">Description</label>
|
||||
<textarea id="description" pTextarea [(ngModel)]="product.description" required rows="3" cols="20" fluid></textarea>
|
||||
</div>
|
||||
<shared-dialog
|
||||
[(visible)]="productDialog"
|
||||
[style]="{ width: '450px' }"
|
||||
header="Product Details"
|
||||
[modal]="true"
|
||||
>
|
||||
<ng-template #content>
|
||||
<div class="flex flex-col gap-6">
|
||||
<img
|
||||
[src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image"
|
||||
[alt]="product.image"
|
||||
class="block m-auto pb-4"
|
||||
*ngIf="product.image"
|
||||
/>
|
||||
<div>
|
||||
<label for="name" class="block font-bold mb-3">Name</label>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
id="name"
|
||||
[(ngModel)]="product.name"
|
||||
required
|
||||
autofocus
|
||||
fluid
|
||||
/>
|
||||
<small class="text-red-500" *ngIf="submitted && !product.name">Name is required.</small>
|
||||
</div>
|
||||
<div>
|
||||
<label for="description" class="block font-bold mb-3">Description</label>
|
||||
<textarea
|
||||
id="description"
|
||||
pTextarea
|
||||
[(ngModel)]="product.description"
|
||||
required
|
||||
rows="3"
|
||||
cols="20"
|
||||
fluid
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="inventoryStatus" class="block font-bold mb-3">Inventory Status</label>
|
||||
<p-select [(ngModel)]="product.inventoryStatus" inputId="inventoryStatus" [options]="statuses" optionLabel="label" optionValue="label" placeholder="Select a Status" fluid />
|
||||
</div>
|
||||
<div>
|
||||
<label for="inventoryStatus" class="block font-bold mb-3">Inventory Status</label>
|
||||
<p-select
|
||||
[(ngModel)]="product.inventoryStatus"
|
||||
inputId="inventoryStatus"
|
||||
[options]="statuses"
|
||||
optionLabel="label"
|
||||
optionValue="label"
|
||||
placeholder="Select a Status"
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="block font-bold mb-4">Category</span>
|
||||
<div class="grid grid-cols-12 gap-4">
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton id="category1" name="category" value="Accessories" [(ngModel)]="product.category" />
|
||||
<label for="category1">Accessories</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton id="category2" name="category" value="Clothing" [(ngModel)]="product.category" />
|
||||
<label for="category2">Clothing</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton id="category3" name="category" value="Electronics" [(ngModel)]="product.category" />
|
||||
<label for="category3">Electronics</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton id="category4" name="category" value="Fitness" [(ngModel)]="product.category" />
|
||||
<label for="category4">Fitness</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span class="block font-bold mb-4">Category</span>
|
||||
<div class="grid grid-cols-12 gap-4">
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton
|
||||
id="category1"
|
||||
name="category"
|
||||
value="Accessories"
|
||||
[(ngModel)]="product.category"
|
||||
/>
|
||||
<label for="category1">Accessories</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton
|
||||
id="category2"
|
||||
name="category"
|
||||
value="Clothing"
|
||||
[(ngModel)]="product.category"
|
||||
/>
|
||||
<label for="category2">Clothing</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton
|
||||
id="category3"
|
||||
name="category"
|
||||
value="Electronics"
|
||||
[(ngModel)]="product.category"
|
||||
/>
|
||||
<label for="category3">Electronics</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 col-span-6">
|
||||
<p-radiobutton
|
||||
id="category4"
|
||||
name="category"
|
||||
value="Fitness"
|
||||
[(ngModel)]="product.category"
|
||||
/>
|
||||
<label for="category4">Fitness</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-12 gap-4">
|
||||
<div class="col-span-6">
|
||||
<label for="price" class="block font-bold mb-3">Price</label>
|
||||
<p-inputnumber id="price" [(ngModel)]="product.price" mode="currency" currency="USD" locale="en-US" fluid />
|
||||
</div>
|
||||
<div class="col-span-6">
|
||||
<label for="quantity" class="block font-bold mb-3">Quantity</label>
|
||||
<p-inputnumber id="quantity" [(ngModel)]="product.quantity" fluid />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
<div class="grid grid-cols-12 gap-4">
|
||||
<div class="col-span-6">
|
||||
<label for="price" class="block font-bold mb-3">Price</label>
|
||||
<p-inputnumber
|
||||
id="price"
|
||||
[(ngModel)]="product.price"
|
||||
mode="currency"
|
||||
currency="USD"
|
||||
locale="en-US"
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
<div class="col-span-6">
|
||||
<label for="quantity" class="block font-bold mb-3">Quantity</label>
|
||||
<p-inputnumber id="quantity" [(ngModel)]="product.quantity" fluid />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #footer>
|
||||
<p-button label="Cancel" icon="pi pi-times" text (click)="hideDialog()" />
|
||||
<p-button label="Save" icon="pi pi-check" (click)="saveProduct()" />
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
<ng-template #footer>
|
||||
<p-button label="Cancel" icon="pi pi-times" text (click)="hideDialog()" />
|
||||
<p-button label="Save" icon="pi pi-check" (click)="saveProduct()" />
|
||||
</ng-template>
|
||||
</shared-dialog>
|
||||
|
||||
<p-confirmdialog [style]="{ width: '450px' }" />
|
||||
`,
|
||||
providers: [MessageService, ProductService, ConfirmationService]
|
||||
<p-confirmdialog [style]="{ width: '450px' }" />
|
||||
`,
|
||||
providers: [MessageService, ProductService, ConfirmationService],
|
||||
})
|
||||
export class Crud implements OnInit {
|
||||
productDialog: boolean = false;
|
||||
productDialog: boolean = false;
|
||||
|
||||
products = signal<Product[]>([]);
|
||||
products = signal<Product[]>([]);
|
||||
|
||||
product!: Product;
|
||||
product!: Product;
|
||||
|
||||
selectedProducts!: Product[] | null;
|
||||
selectedProducts!: Product[] | null;
|
||||
|
||||
submitted: boolean = false;
|
||||
submitted: boolean = false;
|
||||
|
||||
statuses!: any[];
|
||||
statuses!: any[];
|
||||
|
||||
@ViewChild('dt') dt!: Table;
|
||||
@ViewChild('dt') dt!: Table;
|
||||
|
||||
exportColumns!: ExportColumn[];
|
||||
exportColumns!: ExportColumn[];
|
||||
|
||||
cols!: Column[];
|
||||
cols!: Column[];
|
||||
|
||||
constructor(
|
||||
private productService: ProductService,
|
||||
private messageService: MessageService,
|
||||
private confirmationService: ConfirmationService
|
||||
) {}
|
||||
constructor(
|
||||
private productService: ProductService,
|
||||
private messageService: MessageService,
|
||||
private confirmationService: ConfirmationService,
|
||||
) {}
|
||||
|
||||
exportCSV() {
|
||||
this.dt.exportCSV();
|
||||
}
|
||||
exportCSV() {
|
||||
this.dt.exportCSV();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadDemoData();
|
||||
}
|
||||
ngOnInit() {
|
||||
this.loadDemoData();
|
||||
}
|
||||
|
||||
loadDemoData() {
|
||||
this.productService.getProducts().then((data) => {
|
||||
this.products.set(data);
|
||||
loadDemoData() {
|
||||
this.productService.getProducts().then((data) => {
|
||||
this.products.set(data);
|
||||
});
|
||||
|
||||
this.statuses = [
|
||||
{ label: 'INSTOCK', value: 'instock' },
|
||||
{ label: 'LOWSTOCK', value: 'lowstock' },
|
||||
{ label: 'OUTOFSTOCK', value: 'outofstock' },
|
||||
];
|
||||
|
||||
this.cols = [
|
||||
{ field: 'code', header: 'Code', customExportHeader: 'Product Code' },
|
||||
{ field: 'name', header: 'Name' },
|
||||
{ field: 'image', header: 'Image' },
|
||||
{ field: 'price', header: 'Price' },
|
||||
{ field: 'category', header: 'Category' },
|
||||
];
|
||||
|
||||
this.exportColumns = this.cols.map((col) => ({ title: col.header, dataKey: col.field }));
|
||||
}
|
||||
|
||||
onGlobalFilter(table: Table, event: Event) {
|
||||
table.filterGlobal((event.target as HTMLInputElement).value, 'contains');
|
||||
}
|
||||
|
||||
openNew() {
|
||||
this.product = {};
|
||||
this.submitted = false;
|
||||
this.productDialog = true;
|
||||
}
|
||||
|
||||
editProduct(product: Product) {
|
||||
this.product = { ...product };
|
||||
this.productDialog = true;
|
||||
}
|
||||
|
||||
deleteSelectedProducts() {
|
||||
this.confirmationService.confirm({
|
||||
message: 'Are you sure you want to delete the selected products?',
|
||||
header: 'Confirm',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.products.set(this.products().filter((val) => !this.selectedProducts?.includes(val)));
|
||||
this.selectedProducts = null;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Products Deleted',
|
||||
life: 3000,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
this.statuses = [
|
||||
{ label: 'INSTOCK', value: 'instock' },
|
||||
{ label: 'LOWSTOCK', value: 'lowstock' },
|
||||
{ label: 'OUTOFSTOCK', value: 'outofstock' }
|
||||
];
|
||||
hideDialog() {
|
||||
this.productDialog = false;
|
||||
this.submitted = false;
|
||||
}
|
||||
|
||||
this.cols = [
|
||||
{ field: 'code', header: 'Code', customExportHeader: 'Product Code' },
|
||||
{ field: 'name', header: 'Name' },
|
||||
{ field: 'image', header: 'Image' },
|
||||
{ field: 'price', header: 'Price' },
|
||||
{ field: 'category', header: 'Category' }
|
||||
];
|
||||
|
||||
this.exportColumns = this.cols.map((col) => ({ title: col.header, dataKey: col.field }));
|
||||
}
|
||||
|
||||
onGlobalFilter(table: Table, event: Event) {
|
||||
table.filterGlobal((event.target as HTMLInputElement).value, 'contains');
|
||||
}
|
||||
|
||||
openNew() {
|
||||
deleteProduct(product: Product) {
|
||||
this.confirmationService.confirm({
|
||||
message: 'Are you sure you want to delete ' + product.name + '?',
|
||||
header: 'Confirm',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.products.set(this.products().filter((val) => val.id !== product.id));
|
||||
this.product = {};
|
||||
this.submitted = false;
|
||||
this.productDialog = true;
|
||||
}
|
||||
|
||||
editProduct(product: Product) {
|
||||
this.product = { ...product };
|
||||
this.productDialog = true;
|
||||
}
|
||||
|
||||
deleteSelectedProducts() {
|
||||
this.confirmationService.confirm({
|
||||
message: 'Are you sure you want to delete the selected products?',
|
||||
header: 'Confirm',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.products.set(this.products().filter((val) => !this.selectedProducts?.includes(val)));
|
||||
this.selectedProducts = null;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Products Deleted',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Product Deleted',
|
||||
life: 3000,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
findIndexById(id: string): number {
|
||||
let index = -1;
|
||||
for (let i = 0; i < this.products().length; i++) {
|
||||
if (this.products()[i].id === id) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hideDialog() {
|
||||
this.productDialog = false;
|
||||
this.submitted = false;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
deleteProduct(product: Product) {
|
||||
this.confirmationService.confirm({
|
||||
message: 'Are you sure you want to delete ' + product.name + '?',
|
||||
header: 'Confirm',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.products.set(this.products().filter((val) => val.id !== product.id));
|
||||
this.product = {};
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Product Deleted',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
createId(): string {
|
||||
let id = '';
|
||||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (var i = 0; i < 5; i++) {
|
||||
id += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
getSeverity(status: string) {
|
||||
switch (status) {
|
||||
case 'INSTOCK':
|
||||
return 'success';
|
||||
case 'LOWSTOCK':
|
||||
return 'warn';
|
||||
case 'OUTOFSTOCK':
|
||||
return 'danger';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
saveProduct() {
|
||||
this.submitted = true;
|
||||
let _products = this.products();
|
||||
if (this.product.name?.trim()) {
|
||||
if (this.product.id) {
|
||||
_products[this.findIndexById(this.product.id)] = this.product;
|
||||
this.products.set([..._products]);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Product Updated',
|
||||
life: 3000,
|
||||
});
|
||||
} else {
|
||||
this.product.id = this.createId();
|
||||
this.product.image = 'product-placeholder.svg';
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Product Created',
|
||||
life: 3000,
|
||||
});
|
||||
this.products.set([..._products, this.product]);
|
||||
}
|
||||
|
||||
this.productDialog = false;
|
||||
this.product = {};
|
||||
}
|
||||
|
||||
findIndexById(id: string): number {
|
||||
let index = -1;
|
||||
for (let i = 0; i < this.products().length; i++) {
|
||||
if (this.products()[i].id === id) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
createId(): string {
|
||||
let id = '';
|
||||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (var i = 0; i < 5; i++) {
|
||||
id += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
getSeverity(status: string) {
|
||||
switch (status) {
|
||||
case 'INSTOCK':
|
||||
return 'success';
|
||||
case 'LOWSTOCK':
|
||||
return 'warn';
|
||||
case 'OUTOFSTOCK':
|
||||
return 'danger';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
saveProduct() {
|
||||
this.submitted = true;
|
||||
let _products = this.products();
|
||||
if (this.product.name?.trim()) {
|
||||
if (this.product.id) {
|
||||
_products[this.findIndexById(this.product.id)] = this.product;
|
||||
this.products.set([..._products]);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Product Updated',
|
||||
life: 3000
|
||||
});
|
||||
} else {
|
||||
this.product.id = this.createId();
|
||||
this.product.image = 'product-placeholder.svg';
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Successful',
|
||||
detail: 'Product Created',
|
||||
life: 3000
|
||||
});
|
||||
this.products.set([..._products, this.product]);
|
||||
}
|
||||
|
||||
this.productDialog = false;
|
||||
this.product = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+298
-194
@@ -1,230 +1,334 @@
|
||||
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ConfirmationService, MessageService } from 'primeng/api';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
import { DialogModule } from 'primeng/dialog';
|
||||
import { ToastModule } from 'primeng/toast';
|
||||
import { DrawerModule } from 'primeng/drawer';
|
||||
import { Popover, PopoverModule } from 'primeng/popover';
|
||||
import { ConfirmPopupModule } from 'primeng/confirmpopup';
|
||||
import { DialogModule } from 'primeng/dialog';
|
||||
import { DrawerModule } from 'primeng/drawer';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { TooltipModule } from 'primeng/tooltip';
|
||||
import { Popover, PopoverModule } from 'primeng/popover';
|
||||
import { TableModule } from 'primeng/table';
|
||||
import { ToastModule } from 'primeng/toast';
|
||||
import { TooltipModule } from 'primeng/tooltip';
|
||||
import { Product, ProductService } from '../service/product.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-overlay-demo',
|
||||
standalone: true,
|
||||
imports: [ToastModule, DialogModule, ButtonModule, DrawerModule, PopoverModule, ConfirmPopupModule, InputTextModule, FormsModule, TooltipModule, TableModule, ToastModule],
|
||||
template: ` <div class="flex flex-col md:flex-row gap-8">
|
||||
<div class="md:w-1/2">
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">Dialog</div>
|
||||
<p-dialog header="Dialog" [(visible)]="display" [breakpoints]="{ '960px': '75vw' }" [style]="{ width: '30vw' }" [modal]="true">
|
||||
<p class="leading-normal m-0">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
</p>
|
||||
<ng-template #footer>
|
||||
<p-button label="Save" (click)="close()" />
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
<p-button label="Show" [style]="{ width: 'auto' }" (click)="open()" />
|
||||
</div>
|
||||
selector: 'app-overlay-demo',
|
||||
standalone: true,
|
||||
imports: [
|
||||
ToastModule,
|
||||
DialogModule,
|
||||
ButtonModule,
|
||||
DrawerModule,
|
||||
PopoverModule,
|
||||
ConfirmPopupModule,
|
||||
InputTextModule,
|
||||
FormsModule,
|
||||
TooltipModule,
|
||||
TableModule,
|
||||
ToastModule,
|
||||
SharedDialogComponent,
|
||||
],
|
||||
template: ` <div class="flex flex-col md:flex-row gap-8">
|
||||
<div class="md:w-1/2">
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">SharedDialogComponent</div>
|
||||
<shared-dialog
|
||||
header="SharedDialogComponent"
|
||||
[(visible)]="display"
|
||||
[breakpoints]="{ '960px': '75vw' }"
|
||||
[style]="{ width: '30vw' }"
|
||||
[modal]="true"
|
||||
>
|
||||
<p class="leading-normal m-0">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
|
||||
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
||||
mollit anim id est laborum.
|
||||
</p>
|
||||
<ng-template #footer>
|
||||
<p-button label="Save" (click)="close()" />
|
||||
</ng-template>
|
||||
</shared-dialog>
|
||||
<p-button label="Show" [style]="{ width: 'auto' }" (click)="open()" />
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">Popover</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<p-button type="button" label="Show" (click)="toggleDataTable(op2, $event)" />
|
||||
<p-popover #op2 id="overlay_panel" [style]="{ width: '450px' }">
|
||||
<p-table [value]="products" selectionMode="single" [(selection)]="selectedProduct" dataKey="id" [rows]="5" [paginator]="true" (onRowSelect)="onProductSelect(op2, $event)">
|
||||
<ng-template #header>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Image</th>
|
||||
<th>Price</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template #body let-product>
|
||||
<tr [pSelectableRow]="product">
|
||||
<td>{{ product.name }}</td>
|
||||
<td><img [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image" [alt]="product.name" class="w-16 shadow-sm" /></td>
|
||||
<td>{{ product.price }}</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</p-popover>
|
||||
<p-toast />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">Tooltip</div>
|
||||
<div class="inline-flex gap-4">
|
||||
<input pInputText type="text" placeholder="Username" pTooltip="Your username" />
|
||||
<p-button type="button" label="Save" pTooltip="Click to proceed" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">Popover</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<p-button type="button" label="Show" (click)="toggleDataTable(op2, $event)" />
|
||||
<p-popover #op2 id="overlay_panel" [style]="{ width: '450px' }">
|
||||
<p-table
|
||||
[value]="products"
|
||||
selectionMode="single"
|
||||
[(selection)]="selectedProduct"
|
||||
dataKey="id"
|
||||
[rows]="5"
|
||||
[paginator]="true"
|
||||
(onRowSelect)="onProductSelect(op2, $event)"
|
||||
>
|
||||
<ng-template #header>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Image</th>
|
||||
<th>Price</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template #body let-product>
|
||||
<tr [pSelectableRow]="product">
|
||||
<td>{{ product.name }}</td>
|
||||
<td>
|
||||
<img
|
||||
[src]="
|
||||
'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image
|
||||
"
|
||||
[alt]="product.name"
|
||||
class="w-16 shadow-sm"
|
||||
/>
|
||||
</td>
|
||||
<td>{{ product.price }}</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</p-popover>
|
||||
<p-toast />
|
||||
</div>
|
||||
<div class="md:w-1/2">
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">Drawer</div>
|
||||
<p-drawer [(visible)]="visibleLeft" header="Drawer">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
</div>
|
||||
|
||||
<p-drawer [(visible)]="visibleRight" header="Drawer" position="right">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-drawer [(visible)]="visibleTop" header="Drawer" position="top">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-drawer [(visible)]="visibleBottom" header="Drawer" position="bottom">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-drawer [(visible)]="visibleFull" header="Drawer" position="full">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-button icon="pi pi-arrow-right" (click)="visibleLeft = true" [style]="{ marginRight: '0.25em' }" />
|
||||
<p-button icon="pi pi-arrow-left" (click)="visibleRight = true" [style]="{ marginRight: '0.25em' }" />
|
||||
<p-button icon="pi pi-arrow-down" (click)="visibleTop = true" [style]="{ marginRight: '0.25em' }" />
|
||||
<p-button icon="pi pi-arrow-up" (click)="visibleBottom = true" [style]="{ marginRight: '0.25em' }" />
|
||||
<p-button icon="pi pi-external-link" (click)="visibleFull = true" />
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">ConfirmPopup</div>
|
||||
<p-confirmpopup></p-confirmpopup>
|
||||
<p-button #popup (click)="confirm($event)" icon="pi pi-check" label="Confirm" class="mr-2"></p-button>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">ConfirmDialog</div>
|
||||
<p-button label="Delete" icon="pi pi-trash" severity="danger" [style]="{ width: 'auto' }" (click)="openConfirmation()" />
|
||||
<p-dialog header="Confirmation" [(visible)]="displayConfirmation" [style]="{ width: '350px' }" [modal]="true">
|
||||
<div class="flex items-center justify-center">
|
||||
<i class="pi pi-exclamation-triangle mr-4" style="font-size: 2rem"> </i>
|
||||
<span>Are you sure you want to proceed?</span>
|
||||
</div>
|
||||
<ng-template #footer>
|
||||
<p-button label="No" icon="pi pi-times" (click)="closeConfirmation()" text severity="secondary" />
|
||||
<p-button label="Yes" icon="pi pi-check" (click)="closeConfirmation()" severity="danger" outlined autofocus />
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">Tooltip</div>
|
||||
<div class="inline-flex gap-4">
|
||||
<input pInputText type="text" placeholder="Username" pTooltip="Your username" />
|
||||
<p-button type="button" label="Save" pTooltip="Click to proceed" />
|
||||
</div>
|
||||
</div>`,
|
||||
providers: [ConfirmationService, MessageService, ProductService]
|
||||
</div>
|
||||
</div>
|
||||
<div class="md:w-1/2">
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">Drawer</div>
|
||||
<p-drawer [(visible)]="visibleLeft" header="Drawer">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-drawer [(visible)]="visibleRight" header="Drawer" position="right">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-drawer [(visible)]="visibleTop" header="Drawer" position="top">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-drawer [(visible)]="visibleBottom" header="Drawer" position="bottom">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-drawer [(visible)]="visibleFull" header="Drawer" position="full">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
||||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
</p>
|
||||
</p-drawer>
|
||||
|
||||
<p-button
|
||||
icon="pi pi-arrow-right"
|
||||
(click)="visibleLeft = true"
|
||||
[style]="{ marginRight: '0.25em' }"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-arrow-left"
|
||||
(click)="visibleRight = true"
|
||||
[style]="{ marginRight: '0.25em' }"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-arrow-down"
|
||||
(click)="visibleTop = true"
|
||||
[style]="{ marginRight: '0.25em' }"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-arrow-up"
|
||||
(click)="visibleBottom = true"
|
||||
[style]="{ marginRight: '0.25em' }"
|
||||
/>
|
||||
<p-button icon="pi pi-external-link" (click)="visibleFull = true" />
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">ConfirmPopup</div>
|
||||
<p-confirmpopup></p-confirmpopup>
|
||||
<p-button
|
||||
#popup
|
||||
(click)="confirm($event)"
|
||||
icon="pi pi-check"
|
||||
label="Confirm"
|
||||
class="mr-2"
|
||||
></p-button>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="font-semibold text-xl mb-4">ConfirmDialog</div>
|
||||
<p-button
|
||||
label="Delete"
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
[style]="{ width: 'auto' }"
|
||||
(click)="openConfirmation()"
|
||||
/>
|
||||
<shared-dialog
|
||||
header="Confirmation"
|
||||
[(visible)]="displayConfirmation"
|
||||
[style]="{ width: '350px' }"
|
||||
[modal]="true"
|
||||
>
|
||||
<div class="flex items-center justify-center">
|
||||
<i class="pi pi-exclamation-triangle mr-4" style="font-size: 2rem"> </i>
|
||||
<span>Are you sure you want to proceed?</span>
|
||||
</div>
|
||||
<ng-template #footer>
|
||||
<p-button
|
||||
label="No"
|
||||
icon="pi pi-times"
|
||||
(click)="closeConfirmation()"
|
||||
text
|
||||
severity="secondary"
|
||||
/>
|
||||
<p-button
|
||||
label="Yes"
|
||||
icon="pi pi-check"
|
||||
(click)="closeConfirmation()"
|
||||
severity="danger"
|
||||
outlined
|
||||
autofocus
|
||||
/>
|
||||
</ng-template>
|
||||
</shared-dialog>
|
||||
</div>
|
||||
</div>
|
||||
</div>`,
|
||||
providers: [ConfirmationService, MessageService, ProductService],
|
||||
})
|
||||
export class OverlayDemo implements OnInit {
|
||||
images: any[] = [];
|
||||
images: any[] = [];
|
||||
|
||||
display: boolean = false;
|
||||
display: boolean = false;
|
||||
|
||||
products: Product[] = [];
|
||||
products: Product[] = [];
|
||||
|
||||
visibleLeft: boolean = false;
|
||||
visibleLeft: boolean = false;
|
||||
|
||||
visibleRight: boolean = false;
|
||||
visibleRight: boolean = false;
|
||||
|
||||
visibleTop: boolean = false;
|
||||
visibleTop: boolean = false;
|
||||
|
||||
visibleBottom: boolean = false;
|
||||
visibleBottom: boolean = false;
|
||||
|
||||
visibleFull: boolean = false;
|
||||
visibleFull: boolean = false;
|
||||
|
||||
displayConfirmation: boolean = false;
|
||||
displayConfirmation: boolean = false;
|
||||
|
||||
selectedProduct!: Product;
|
||||
selectedProduct!: Product;
|
||||
|
||||
constructor(
|
||||
private productService: ProductService,
|
||||
private confirmationService: ConfirmationService,
|
||||
private messageService: MessageService
|
||||
) {}
|
||||
constructor(
|
||||
private productService: ProductService,
|
||||
private confirmationService: ConfirmationService,
|
||||
private messageService: MessageService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.productService.getProductsSmall().then((products) => (this.products = products));
|
||||
ngOnInit() {
|
||||
this.productService.getProductsSmall().then((products) => (this.products = products));
|
||||
|
||||
this.images = [];
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos1.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos1_small.jpg',
|
||||
title: 'Sopranos 1'
|
||||
this.images = [];
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos1.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos1_small.jpg',
|
||||
title: 'Sopranos 1',
|
||||
});
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos2.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos2_small.jpg',
|
||||
title: 'Sopranos 2',
|
||||
});
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos3.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos3_small.jpg',
|
||||
title: 'Sopranos 3',
|
||||
});
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos4.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos4_small.jpg',
|
||||
title: 'Sopranos 4',
|
||||
});
|
||||
}
|
||||
|
||||
confirm(event: Event) {
|
||||
this.confirmationService.confirm({
|
||||
key: 'confirm2',
|
||||
target: event.target || new EventTarget(),
|
||||
message: 'Are you sure that you want to proceed?',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: 'Confirmed',
|
||||
detail: 'You have accepted',
|
||||
});
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos2.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos2_small.jpg',
|
||||
title: 'Sopranos 2'
|
||||
},
|
||||
reject: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Rejected',
|
||||
detail: 'You have rejected',
|
||||
});
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos3.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos3_small.jpg',
|
||||
title: 'Sopranos 3'
|
||||
});
|
||||
this.images.push({
|
||||
source: 'assets/demo/images/sopranos/sopranos4.jpg',
|
||||
thumbnail: 'assets/demo/images/sopranos/sopranos4_small.jpg',
|
||||
title: 'Sopranos 4'
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
confirm(event: Event) {
|
||||
this.confirmationService.confirm({
|
||||
key: 'confirm2',
|
||||
target: event.target || new EventTarget(),
|
||||
message: 'Are you sure that you want to proceed?',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.messageService.add({ severity: 'info', summary: 'Confirmed', detail: 'You have accepted' });
|
||||
},
|
||||
reject: () => {
|
||||
this.messageService.add({ severity: 'error', summary: 'Rejected', detail: 'You have rejected' });
|
||||
}
|
||||
});
|
||||
}
|
||||
open() {
|
||||
this.display = true;
|
||||
}
|
||||
|
||||
open() {
|
||||
this.display = true;
|
||||
}
|
||||
close() {
|
||||
this.display = false;
|
||||
}
|
||||
|
||||
close() {
|
||||
this.display = false;
|
||||
}
|
||||
toggleDataTable(op: Popover, event: any) {
|
||||
op.toggle(event);
|
||||
}
|
||||
|
||||
toggleDataTable(op: Popover, event: any) {
|
||||
op.toggle(event);
|
||||
}
|
||||
onProductSelect(op: Popover, event: any) {
|
||||
op.hide();
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: 'Product Selected',
|
||||
detail: event?.data.name,
|
||||
life: 3000,
|
||||
});
|
||||
}
|
||||
|
||||
onProductSelect(op: Popover, event: any) {
|
||||
op.hide();
|
||||
this.messageService.add({ severity: 'info', summary: 'Product Selected', detail: event?.data.name, life: 3000 });
|
||||
}
|
||||
openConfirmation() {
|
||||
this.displayConfirmation = true;
|
||||
}
|
||||
|
||||
openConfirmation() {
|
||||
this.displayConfirmation = true;
|
||||
}
|
||||
|
||||
closeConfirmation() {
|
||||
this.displayConfirmation = false;
|
||||
}
|
||||
closeConfirmation() {
|
||||
this.displayConfirmation = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user