Files
psp_panel/src/app/domains/pos/layouts/layout.component.ts
T

173 lines
4.9 KiB
TypeScript
Raw Normal View History

2026-03-29 18:07:10 +03:30
import { AuthService } from '@/core';
import { LayoutService } from '@/layout/service/layout.service';
2026-03-18 13:35:57 +03:30
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import { CommonModule } from '@angular/common';
import {
AfterViewInit,
Component,
TemplateRef,
ViewChild,
computed,
inject,
signal,
} from '@angular/core';
2026-05-10 09:44:30 +03:30
import { RouterLinkWithHref, RouterOutlet } from '@angular/router';
import { MenuItem } from 'primeng/api';
import { Button, ButtonDirective } from 'primeng/button';
import { Card } from 'primeng/card';
import { Menu } from 'primeng/menu';
2026-05-10 09:44:30 +03:30
import { finalize } from 'rxjs';
2026-03-29 18:07:10 +03:30
import images from 'src/assets/images';
import { PosInfoStore, PosProfileStore } from '../store';
2026-05-10 09:44:30 +03:30
import { DeviceInfoStore } from '../store/device.store';
import { PosChooseCardsComponent } from './choose-pos.component';
import { PosMainMenuSidebarComponent } from './mainMenuSidebar/main-menu-sidebar.component';
2026-03-18 13:35:57 +03:30
@Component({
selector: 'pos-layout',
templateUrl: './layout.component.html',
imports: [
PageLoadingComponent,
RouterOutlet,
ButtonDirective,
Card,
PosChooseCardsComponent,
Button,
PosMainMenuSidebarComponent,
Menu,
CommonModule,
2026-05-10 09:44:30 +03:30
RouterLinkWithHref,
],
2026-03-18 13:35:57 +03:30
})
export class PosLayoutComponent implements AfterViewInit {
2026-03-18 13:35:57 +03:30
constructor() {}
2026-05-10 09:44:30 +03:30
// private readonly nativeBridgeService = inject(NativeBridgeService);
// private readonly toastService = inject(ToastService);
@ViewChild('topbarStart', { static: true }) topbarStart!: TemplateRef<any>;
@ViewChild('topbarCenter', { static: true }) topbarCenter!: TemplateRef<any>;
@ViewChild('topbarEnd', { static: true }) topbarEnd!: TemplateRef<any>;
2026-03-18 13:35:57 +03:30
2026-04-23 01:22:44 +03:30
private readonly posProfileStore = inject(PosProfileStore);
private readonly posInfoStore = inject(PosInfoStore);
2026-05-10 09:44:30 +03:30
private readonly deviceInfoStore = inject(DeviceInfoStore);
2026-03-29 18:07:10 +03:30
private readonly authService = inject(AuthService);
private readonly layoutService = inject(LayoutService);
mainMenuVisible = signal(false);
2026-03-18 13:35:57 +03:30
2026-04-23 01:22:44 +03:30
readonly posProfileLoading = computed(() => this.posProfileStore.loading());
readonly posProfile = computed(() => this.posProfileStore.entity());
readonly posProfileError = computed(() => this.posProfileStore.error());
readonly posInfoLoading = computed(() => this.posInfoStore.loading());
readonly posInfo = computed(() => this.posInfoStore.entity());
readonly posInfoError = computed(() => this.posInfoStore.error());
readonly loading = computed(() => this.posProfileLoading());
readonly error = computed(() => this.posProfileError());
2026-03-29 18:07:10 +03:30
2026-05-10 09:44:30 +03:30
readonly deviceInfo = computed(() => this.deviceInfoStore.entity());
logout = () => {
this.authService.logout();
};
profileMenuItems: MenuItem[] = [
{
label: 'راهنمای سامانه',
icon: 'pi pi-question-circle',
disabled: true,
},
{
label: 'خروج',
icon: 'pi pi-sign-out',
command: this.logout,
},
];
2026-03-29 18:07:10 +03:30
placeholderLogo = images.placeholders.logo;
now = new Date();
private touchStartY = 0;
private pulling = false;
pullDistance = signal(0);
readonly pullThreshold = 80;
2026-03-18 13:35:57 +03:30
2026-05-10 09:44:30 +03:30
homeRouteLink = '/pos';
async getData() {
await this.layoutService.changeFullPageLoading(true);
await this.deviceInfoStore.getData();
await this.posProfileStore.getData().subscribe({
next: () => {
2026-05-10 09:44:30 +03:30
this.posInfoStore
.getData()
.pipe(
finalize(() => {
this.layoutService.changeFullPageLoading(false);
}),
)
.subscribe();
},
});
2026-03-18 13:35:57 +03:30
}
toggleMenu() {
this.mainMenuVisible.update((v) => !v);
}
onChoosePos() {
this.getData();
}
2026-03-18 13:35:57 +03:30
ngOnInit() {
this.layoutService.changeIsFullPage(true);
2026-03-18 13:35:57 +03:30
this.getData();
}
ngAfterViewInit() {
this.layoutService.setTopbarStartSlot(this.topbarStart);
this.layoutService.setTopbarCenterSlot(this.topbarCenter);
this.layoutService.setTopbarEndSlot(this.topbarEnd);
}
ngOnDestroy() {
this.layoutService.changeIsFullPage(false);
this.layoutService.setTopbarStartSlot(null);
this.layoutService.setTopbarCenterSlot(null);
this.layoutService.setTopbarEndSlot(null);
}
onTouchStart(event: TouchEvent) {
if (window.scrollY > 0 || event.touches.length !== 1) return;
this.touchStartY = event.touches[0].clientY;
this.pulling = true;
}
onTouchMove(event: TouchEvent) {
if (!this.pulling) return;
const delta = event.touches[0].clientY - this.touchStartY;
if (delta <= 0) {
this.pullDistance.set(0);
return;
}
const damped = Math.min(delta * 0.5, 140);
this.pullDistance.set(damped);
event.preventDefault();
}
onTouchEnd() {
if (!this.pulling) return;
const shouldRefresh = this.pullDistance() >= this.pullThreshold;
this.pulling = false;
this.pullDistance.set(0);
if (shouldRefresh) {
this.layoutService.changeIsFullPage(true);
this.getData();
}
}
2026-03-18 13:35:57 +03:30
}