create consumer pos list page
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import * as _pos from './pos/pos';
|
||||
|
||||
export const pos = _pos;
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface IPosInitialValues {
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { IColumn } from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { FormBuilder, Validators } from '@angular/forms';
|
||||
import { IPosInitialValues } from './pos.model';
|
||||
|
||||
export const columns: IColumn[] = [
|
||||
// { field: 'id', header: 'شناسه', type: 'id' },
|
||||
{ field: 'name', header: 'عنوان' },
|
||||
{ field: 'serial', header: 'شماره سریال' },
|
||||
{ field: 'pos_type', header: 'نوع دستگاه' },
|
||||
{ field: 'device', header: 'دستگاه', type: 'nested', nestedPath: 'device.name' },
|
||||
{ field: 'provider', header: 'ارایهدهنده', type: 'nested', nestedPath: 'provider.name' },
|
||||
{ field: 'status', header: 'وضعیت' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
|
||||
export const initForm = (fb: FormBuilder, initialValues?: IPosInitialValues) => {
|
||||
const form = fb.group({
|
||||
name: [initialValues?.name || '', [Validators.required]],
|
||||
});
|
||||
|
||||
return form;
|
||||
};
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './apiRoutes';
|
||||
export * as CONSUMER_COMPONENTS_CONST from './components';
|
||||
export * from './menuItems.const';
|
||||
|
||||
@@ -12,6 +12,11 @@ export const CONSUMER_MENU_ITEMS = [
|
||||
icon: 'pi pi-fw pi-home',
|
||||
routerLink: ['/consumer/accounts'],
|
||||
},
|
||||
{
|
||||
label: 'پایانههای فروش',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
routerLink: ['/consumer/poses'],
|
||||
},
|
||||
{
|
||||
label: 'فعالیتهای اقتصادی',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
|
||||
@@ -31,8 +31,6 @@ export class LayoutComponent {
|
||||
});
|
||||
|
||||
ngOnInit() {
|
||||
console.log('first');
|
||||
|
||||
this.layoutService.setMenuItems(CONSUMER_MENU_ITEMS);
|
||||
this.store.getData();
|
||||
}
|
||||
|
||||
+5
-8
@@ -1,9 +1,10 @@
|
||||
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
||||
import { CONSUMER_COMPONENTS_CONST } from '@/domains/consumer/constants';
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { IPosRequest, IPosResponse } from '../../models';
|
||||
import { ConsumerPosesService } from '../../services/poses.service';
|
||||
@@ -20,13 +21,9 @@ export class ConsumerPosFormComponent extends AbstractFormDialog<IPosRequest, IP
|
||||
@Input({ required: true }) complexId!: string;
|
||||
@Input({ required: true }) posId!: string;
|
||||
|
||||
initForm = () => {
|
||||
const form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
});
|
||||
|
||||
return form;
|
||||
};
|
||||
initForm() {
|
||||
return CONSUMER_COMPONENTS_CONST.pos.initForm(this.fb, this.initialValues);
|
||||
}
|
||||
|
||||
form = this.initForm();
|
||||
|
||||
|
||||
+2
-14
@@ -1,4 +1,5 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { CONSUMER_COMPONENTS_CONST } from '@/domains/consumer/constants';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import {
|
||||
IColumn,
|
||||
@@ -20,20 +21,7 @@ export class ConsumerPosesComponent extends AbstractList<IPosResponse> {
|
||||
@Input({ required: true }) businessId!: string;
|
||||
@Input({ required: true }) complexId!: string;
|
||||
@Input() fullHeight?: boolean;
|
||||
@Input() header: IColumn[] = [
|
||||
{ field: 'id', header: 'شناسه', type: 'id' },
|
||||
{ field: 'name', header: 'عنوان' },
|
||||
{ field: 'serial', header: 'شماره سریال' },
|
||||
{ field: 'device', header: 'دستگاه', type: 'nested', nestedPath: 'device.name' },
|
||||
{ field: 'pos_type', header: 'نوع دستگاه' },
|
||||
{ field: 'provider', header: 'ارایهدهنده', type: 'nested', nestedPath: 'provider.name' },
|
||||
{ field: 'status', header: 'وضعیت' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
@Input() header: IColumn[] = CONSUMER_COMPONENTS_CONST.pos.columns;
|
||||
|
||||
private readonly service = inject(ConsumerPosesService);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
@@ -10,7 +10,7 @@ export const consumerPosesNamedRoutes: NamedRoutes<TPosesRouteNames> = {
|
||||
poses: {
|
||||
path: 'poses',
|
||||
loadComponent: () =>
|
||||
import('../../views/poses/list.component').then((m) => m.SuperAdminUserPosesComponent),
|
||||
import('../../views/poses/list.component').then((m) => m.ConsumerPosListPageComponent),
|
||||
// @ts-ignore
|
||||
meta: {
|
||||
title: 'پایانههای فروش',
|
||||
@@ -20,7 +20,7 @@ export const consumerPosesNamedRoutes: NamedRoutes<TPosesRouteNames> = {
|
||||
pos: {
|
||||
path: 'poses/:posId',
|
||||
loadComponent: () =>
|
||||
import('../../views/poses/single.component').then((m) => m.SuperAdminUserPosComponent),
|
||||
import('../../views/poses/single.component').then((m) => m.ConsumerComplexPosPageComponent),
|
||||
// @ts-ignore
|
||||
meta: {
|
||||
title: 'پایانهی فروش',
|
||||
|
||||
@@ -9,11 +9,11 @@ import { BusinessActivityStore } from '../../store/businessActivity.store';
|
||||
import { ConsumerComplexStore } from '../../store/complex.store';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-user-poses',
|
||||
selector: 'consumer-complex-pos-list-page',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [ConsumerPosesComponent],
|
||||
})
|
||||
export class SuperAdminUserPosesComponent {
|
||||
export class ConsumerPosListPageComponent {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly breadcrumbService = inject(BreadcrumbService);
|
||||
private readonly businessStore = inject(BusinessActivityStore);
|
||||
|
||||
@@ -13,7 +13,7 @@ import { ConsumerComplexStore } from '../../store/complex.store';
|
||||
import { PosStore } from '../../store/pos.store';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-user-pos',
|
||||
selector: 'consumer--complex-pos-page',
|
||||
templateUrl: './single.component.html',
|
||||
imports: [
|
||||
AppCardComponent,
|
||||
@@ -23,7 +23,7 @@ import { PosStore } from '../../store/pos.store';
|
||||
ConsumerSalesInvoicesComponent,
|
||||
],
|
||||
})
|
||||
export class SuperAdminUserPosComponent {
|
||||
export class ConsumerComplexPosPageComponent {
|
||||
private readonly businessStore = inject(BusinessActivityStore);
|
||||
private readonly complexStore = inject(ConsumerComplexStore);
|
||||
private readonly store = inject(PosStore);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<p-dialog
|
||||
[header]="preparedTitle"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '500px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,40 @@
|
||||
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
||||
import { CONSUMER_COMPONENTS_CONST } from '@/domains/consumer/constants';
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { IPosRequest, IPosResponse } from '../models';
|
||||
import { ConsumerPosesService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'consumer-pos-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class ConsumerPosFormComponent extends AbstractFormDialog<IPosRequest, IPosResponse> {
|
||||
private readonly service = inject(ConsumerPosesService);
|
||||
|
||||
@Input({ required: true }) posId!: string;
|
||||
|
||||
initForm() {
|
||||
return CONSUMER_COMPONENTS_CONST.pos.initForm(this.fb, this.initialValues);
|
||||
}
|
||||
|
||||
form = this.initForm();
|
||||
|
||||
get preparedTitle() {
|
||||
return `ویرایش پایانه فروش ${this.initialValues?.name}`;
|
||||
}
|
||||
|
||||
override ngOnChanges(): void {
|
||||
this.form = this.initForm();
|
||||
}
|
||||
|
||||
submitForm() {
|
||||
const formValue = this.form.value as IPosRequest;
|
||||
return this.service.update(this.posId, formValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@if (loading()) {
|
||||
<shared-page-loading />
|
||||
} @else {
|
||||
<router-outlet></router-outlet>
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
|
||||
import pageParamsUtils from '@/utils/page-params.utils';
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
import { ActivatedRoute, RouterOutlet } from '@angular/router';
|
||||
import { ConsumerPosStore } from '../store/pos.store';
|
||||
|
||||
@Component({
|
||||
selector: 'consumer-pos-layout',
|
||||
templateUrl: './layout.component.html',
|
||||
imports: [PageLoadingComponent, RouterOutlet],
|
||||
})
|
||||
export class ConsumerPosLayoutComponent {
|
||||
private readonly store = inject(ConsumerPosStore);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly pageParams = computed(() => pageParamsUtils(this.route));
|
||||
|
||||
readonly posId = computed(() => this.pageParams()['posId']!);
|
||||
|
||||
getData() {
|
||||
this.store.getData(this.posId());
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<app-page-data-list
|
||||
pageTitle="لیست پایانههای فروش"
|
||||
[columns]="columns"
|
||||
emptyPlaceholderTitle="پایانهی فروشی یافت نشد."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showEdit]="true"
|
||||
(onEdit)="onEditClick($event)"
|
||||
(onDetails)="toSinglePage($event)"
|
||||
>
|
||||
<ng-template #toPosLandingAction let-item>
|
||||
<p-button type="button" variant="outlined" (onClick)="toPosLanding(item.id)"> ورود به پایانه </p-button>
|
||||
</ng-template>
|
||||
</app-page-data-list>
|
||||
<consumer-pos-form
|
||||
[(visible)]="visibleForm"
|
||||
[editMode]="editMode()"
|
||||
[posId]="selectedItemForEdit()?.id || ''"
|
||||
[initialValues]="selectedItemForEdit() || undefined"
|
||||
(onSubmit)="refresh()"
|
||||
/>
|
||||
@@ -0,0 +1,78 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { CONSUMER_COMPONENTS_CONST } from '@/domains/consumer/constants';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import {
|
||||
IColumn,
|
||||
PageDataListComponent,
|
||||
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject, Input, TemplateRef, ViewChild } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { Button } from 'primeng/button';
|
||||
import { COOKIE_KEYS } from 'src/assets/constants';
|
||||
import { ConsumerPosesNamedRoutes } from '../constants';
|
||||
import { IPosResponse } from '../models';
|
||||
import { ConsumerPosesService } from '../services/main.service';
|
||||
import { ConsumerPosFormComponent } from './form.component';
|
||||
|
||||
@Component({
|
||||
selector: 'consumer-pos-list',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, ConsumerPosFormComponent, Button],
|
||||
})
|
||||
export class ConsumerPosListComponent extends AbstractList<IPosResponse> {
|
||||
@Input() fullHeight?: boolean;
|
||||
@Input() header: IColumn[] = CONSUMER_COMPONENTS_CONST.pos.columns;
|
||||
|
||||
private readonly service = inject(ConsumerPosesService);
|
||||
private readonly cookieService = inject(CookieService);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
@ViewChild('toPosLandingAction', { static: true }) toPosLandingAction!: TemplateRef<any>;
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
...this.header.filter((header) =>
|
||||
['name', 'status', 'pos_type'].includes(header.field as string),
|
||||
),
|
||||
{
|
||||
field: 'complex.business_activity',
|
||||
header: 'عنوان کسب و کار',
|
||||
type: 'nested',
|
||||
nestedPath: 'complex.business_activity.name',
|
||||
},
|
||||
{
|
||||
field: 'complex',
|
||||
header: 'عنوان فروشگاه',
|
||||
type: 'nested',
|
||||
nestedPath: 'complex.name',
|
||||
},
|
||||
{
|
||||
field: 'customAction',
|
||||
header: '',
|
||||
width: '128px',
|
||||
minWidth: '128px',
|
||||
customDataModel: this.toPosLandingAction,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
|
||||
toSinglePage(item: IPosResponse) {
|
||||
this.router.navigateByUrl(ConsumerPosesNamedRoutes.pos.meta.pagePath!(item.id));
|
||||
}
|
||||
|
||||
toPosLanding(posId: string) {
|
||||
this.cookieService.set(COOKIE_KEYS.POS_ID, '', new Date());
|
||||
this.cookieService.set(COOKIE_KEYS.POS_ID, posId, {
|
||||
sameSite: 'Lax', // or 'Strict' for same-site requests only
|
||||
secure: false,
|
||||
path: '/',
|
||||
domain: 'localhost',
|
||||
});
|
||||
window.open('/pos', '_blank');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = () => `/api/v1/consumer/poses`;
|
||||
|
||||
export const CONSUMER_POSES_API_ROUTES = {
|
||||
list: () => `${baseUrl()}`,
|
||||
single: (posId: string) => `${baseUrl()}/${posId}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,44 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TPosesRouteNames = 'poses' | 'pos';
|
||||
|
||||
const baseUrl = `/consumer/poses`;
|
||||
|
||||
export const ConsumerPosesNamedRoutes: NamedRoutes<TPosesRouteNames> = {
|
||||
poses: {
|
||||
path: 'poses',
|
||||
loadComponent: () =>
|
||||
import('../../views/list.component').then((m) => m.ConsumerPosListPageComponent),
|
||||
// @ts-ignore
|
||||
meta: {
|
||||
title: 'پایانههای فروش',
|
||||
pagePath: () => baseUrl,
|
||||
},
|
||||
},
|
||||
pos: {
|
||||
path: 'poses/:posId',
|
||||
loadComponent: () =>
|
||||
import('../../views/single.component').then((m) => m.ConsumerPosPageComponent),
|
||||
// @ts-ignore
|
||||
meta: {
|
||||
title: 'پایانهی فروش',
|
||||
pagePath: (posId: string) => `${baseUrl}/${posId}`,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const CONSUMER_POSES_ROUTES: Routes = [
|
||||
ConsumerPosesNamedRoutes.poses,
|
||||
{
|
||||
path: ConsumerPosesNamedRoutes.pos.path,
|
||||
loadComponent: () =>
|
||||
import('../../components/layout.component').then((m) => m.ConsumerPosLayoutComponent),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
loadComponent: ConsumerPosesNamedRoutes.pos.loadComponent,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
@@ -0,0 +1,18 @@
|
||||
import ISummary from '@/core/models/summary';
|
||||
|
||||
export interface IPosRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
serial: string;
|
||||
model?: string;
|
||||
status: string;
|
||||
pos_type: string;
|
||||
complex: ISummary;
|
||||
device?: ISummary;
|
||||
provider?: ISummary;
|
||||
}
|
||||
export interface IPosResponse extends IPosRawResponse {}
|
||||
|
||||
export interface IPosRequest {
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CONSUMER_POSES_API_ROUTES } from '../constants';
|
||||
import { IPosRawResponse, IPosRequest, IPosResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ConsumerPosesService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = CONSUMER_POSES_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<IPosResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IPosRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(posId: string): Observable<IPosResponse> {
|
||||
return this.http.get<IPosRawResponse>(this.apiRoutes.single(posId));
|
||||
}
|
||||
|
||||
update(posId: string, data: IPosRequest): Observable<IPosResponse> {
|
||||
return this.http.patch<IPosRawResponse>(this.apiRoutes.single(posId), data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { EntityState, EntityStore } from '@/core/state';
|
||||
import { computed, inject, Injectable } from '@angular/core';
|
||||
import { MenuItem } from 'primeng/api';
|
||||
import { catchError, finalize } from 'rxjs';
|
||||
import { consumerPosesNamedRoutes } from '../../businessActivities/constants/routes/poses';
|
||||
import { IPosResponse } from '../models';
|
||||
import { ConsumerPosesService } from '../services/main.service';
|
||||
|
||||
interface ConsumerPosState extends EntityState<IPosResponse> {
|
||||
breadcrumbItems: MenuItem[];
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ConsumerPosStore extends EntityStore<IPosResponse, ConsumerPosState> {
|
||||
private readonly service = inject(ConsumerPosesService);
|
||||
constructor() {
|
||||
super({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
breadcrumbItems: [],
|
||||
});
|
||||
}
|
||||
|
||||
breadcrumbItems = computed(() => this._state().breadcrumbItems);
|
||||
|
||||
private setBreadcrumb(posId: string) {
|
||||
this.patchState({
|
||||
breadcrumbItems: [
|
||||
{
|
||||
...consumerPosesNamedRoutes.poses.meta,
|
||||
routerLink: consumerPosesNamedRoutes.poses.meta.pagePath!(),
|
||||
},
|
||||
{
|
||||
title: this.entity()?.name,
|
||||
routerLink: consumerPosesNamedRoutes.pos.meta.pagePath!(posId),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
getData(posId: string) {
|
||||
this.patchState({ loading: true });
|
||||
this.service
|
||||
.getSingle(posId)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.patchState({ loading: false });
|
||||
}),
|
||||
catchError((error) => {
|
||||
this.setError(error);
|
||||
throw error;
|
||||
}),
|
||||
)
|
||||
.subscribe((entity) => {
|
||||
this.setEntity(entity);
|
||||
this.setBreadcrumb(posId);
|
||||
});
|
||||
}
|
||||
|
||||
override reset(): void {
|
||||
this.setState({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
breadcrumbItems: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1 @@
|
||||
<consumer-pos-list />
|
||||
@@ -0,0 +1,10 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { Component } from '@angular/core';
|
||||
import { ConsumerPosListComponent } from '../components/list.component';
|
||||
|
||||
@Component({
|
||||
selector: 'consumer-poses',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [ConsumerPosListComponent],
|
||||
})
|
||||
export class ConsumerPosListPageComponent {}
|
||||
@@ -0,0 +1,25 @@
|
||||
<div class="flex flex-col gap-6">
|
||||
<app-card-data cardTitle="اطلاعات پایانهی فروش" [editable]="true" [(editMode)]="editMode">
|
||||
<ng-template #moreAction>
|
||||
<p-button type="button" variant="outlined" (onClick)="toPosLanding()"> ورود به پایانه </p-button>
|
||||
</ng-template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="grid grid-cols-3 gap-4 items-center">
|
||||
<app-key-value label="عنوان" [value]="pos()?.name" />
|
||||
<app-key-value label="شماره سریال" [value]="pos()?.serial" />
|
||||
<app-key-value label="نوع پایانه" [value]="pos()?.pos_type" />
|
||||
<app-key-value label="نوع دستگاه" [value]="pos()?.device?.name" />
|
||||
<app-key-value label="مدل دستگاه" [value]="pos()?.model" />
|
||||
<app-key-value label="ارایهدهنده" [value]="pos()?.provider?.name" />
|
||||
</div>
|
||||
</div>
|
||||
</app-card-data>
|
||||
|
||||
<consumer-pos-form
|
||||
[(visible)]="editMode"
|
||||
[editMode]="true"
|
||||
[posId]="posId()"
|
||||
[initialValues]="pos() || undefined"
|
||||
(onSubmit)="getData()"
|
||||
/>
|
||||
</div>
|
||||
@@ -0,0 +1,55 @@
|
||||
import { BreadcrumbService } from '@/core/services';
|
||||
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
|
||||
import { Component, computed, effect, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { Button } from 'primeng/button';
|
||||
import { COOKIE_KEYS } from 'src/assets/constants';
|
||||
import { ConsumerPosFormComponent } from '../components/form.component';
|
||||
import { ConsumerPosStore } from '../store/pos.store';
|
||||
|
||||
@Component({
|
||||
selector: 'consumer-pos-page',
|
||||
templateUrl: './single.component.html',
|
||||
imports: [AppCardComponent, KeyValueComponent, Button, ConsumerPosFormComponent],
|
||||
})
|
||||
export class ConsumerPosPageComponent {
|
||||
private readonly store = inject(ConsumerPosStore);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly breadcrumbService = inject(BreadcrumbService);
|
||||
private readonly cookieService = inject(CookieService);
|
||||
|
||||
readonly posId = signal<string>(this.route.snapshot.paramMap.get('posId')!);
|
||||
editMode = signal<boolean>(false);
|
||||
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly pos = computed(() => this.store.entity());
|
||||
readonly posBreadcrumb = computed(() => this.store.breadcrumbItems());
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (this.pos()?.id) {
|
||||
this.setBreadcrumb();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getData() {
|
||||
this.store.getData(this.posId());
|
||||
}
|
||||
|
||||
setBreadcrumb() {
|
||||
this.breadcrumbService.setItems(this.posBreadcrumb());
|
||||
}
|
||||
|
||||
toPosLanding() {
|
||||
this.cookieService.set(COOKIE_KEYS.POS_ID, '', new Date());
|
||||
this.cookieService.set(COOKIE_KEYS.POS_ID, this.posId(), {
|
||||
sameSite: 'Lax', // or 'Strict' for same-site requests only
|
||||
secure: false,
|
||||
path: '/',
|
||||
domain: 'localhost',
|
||||
});
|
||||
window.open('/pos', '_blank');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Route } from '@angular/router';
|
||||
import { CONSUMER_ACCOUNTS_ROUTES } from './modules/accounts/constants';
|
||||
import { CONSUMER_BUSINESS_ACTIVITIES_ROUTES } from './modules/businessActivities/constants';
|
||||
import { CONSUMER_CUSTOMERS_ROUTES } from './modules/customers/constants';
|
||||
import { CONSUMER_POSES_ROUTES } from './modules/poses/constants';
|
||||
import { CONSUMER_SALE_INVOICES_ROUTES } from './modules/saleInvoices/constants';
|
||||
|
||||
export const CONSUMER_ROUTES = {
|
||||
@@ -17,5 +18,6 @@ export const CONSUMER_ROUTES = {
|
||||
...CONSUMER_BUSINESS_ACTIVITIES_ROUTES,
|
||||
...CONSUMER_CUSTOMERS_ROUTES,
|
||||
...CONSUMER_SALE_INVOICES_ROUTES,
|
||||
...CONSUMER_POSES_ROUTES,
|
||||
],
|
||||
} as Route;
|
||||
|
||||
@@ -32,8 +32,6 @@ export abstract class AbstractList<ResponseModel, RequestParams = null> {
|
||||
this.getDataRequest(this.requestPayload())
|
||||
?.pipe(
|
||||
finalize(() => {
|
||||
console.log('first');
|
||||
|
||||
this.loading.set(false);
|
||||
}),
|
||||
catchError((error) => {
|
||||
|
||||
Reference in New Issue
Block a user