Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 33x 33x 40x 33x 40x 2x 6x 6x 6x 1x 5x 2x 2x 1x 2x 2x 2x 2x 3x 4x 38x 2x 2x 34x 33x 33x 33x 1x 50x 10x 10x 10x 10x 45x 2x 2x 1x 1x 1x 1x 33x 6x 4x 3x 3x 33x 33x 33x 1x 1x 1x 1x 1x 33x 33x 33x 33x 33x 1x 1x 1x 33x 33x 33x 4x 4x 4x 4x 4x 4x 4x 33x 33x 4x 3x 3x 2x 2x 4x 4x 2x 4x 1x 3x 33x 1x 1x 2x 2x 33x 1x 3x 1x 1x 1x 1x 34x 34x 2x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 1x 33x 66x 67x 66x | import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { platformService } from './platform';
import { httpService } from './http';
import { Configuration, configService } from './localcfg';
import { languageService} from './language';
import { UserMode, stateService } from './state';
/**
* Represents the different views available in the application.
* - LOGIN: View login screen
* - USER: View user screen (select place)
* - PLACE: View place screen
* - GUEST: Guest (QR) access
*/
export type ViewMode = 'LOGIN' | 'USER' | 'PLACE' | 'GUEST';
/**
* Represents the different modes for editing within the application.
* - VIEW: View place activity
* - EDIT: Configure place parameters
* - CART: Creating a new ticket
*/
export type EditMode = 'VIEW' | 'EDIT' | 'CART';
/**
* Defines the structure for managing panels within the application.
*/
export type PlacePanel = {
main?: string | null,
scnd?: string | null,
args?: Record<string, any> | null,
sync?: ((...args: any[]) => any) | null
}
/**
* Enumeration for device view keys.
* Defines the keys used in the configuration object for the device view options.
*/
export enum UppViewConfiguration {
/**
* Represents the key for the device kiosk view mode.
* This determines whether the kiosk keyboard should be displayed or not
* - **Default**: `'false'`
*/
kiosk = 'kiosk',
/**
* Represents the key for the device ispos view mode.
* This determines whether the pos specific behaviour should be enabled
* - **Default**: `'false'`
*/
ispos = 'ispos'
}
/************************************/
/* VIEW SERVICE */
/************************************/
/**
* @class viewService
* @description This service is responsible for managing various view-related aspects of the application,
* including device considerations, access levels, view modes, right panel status, tab status, and service worker updates.
*/
@Injectable({
providedIn: 'root'
})
export class viewService implements OnDestroy {
private _subscriptions: Array <Subscription> = [];
private _config: Configuration | null = null;
private get configuration(){
if ((this._config == null)){
this._config = this.config.getConfiguration('VIEW');
}
return this._config;
}
/******************************/
/* DEVICE CONSIDERATIONS */
/******************************/
/**
* @description Determines if zooming is allowed on the device. Zoom is disabled on iOS Safari due to stability issues.
* @returns {boolean} True if zoom is allowed; otherwise, false.
*/
get CanZoom(): boolean{
// do not apply zoom on ios safari (keeps crashing)
return !(this.platform.LegacyMobile) || (this.platform.Browser != 'Safari');
}
/**
* @description Gets or sets the current theme of the platform. Guests can only use the dark theme.
*/
get Theme(): 'dark' | 'light' | null {
Iif (this.Access == 'GUEST'){
return 'dark'; // guest mode only supports dark theme
}
return this.platform._theme;
}
set Theme(value: 'dark' | 'light'){
if (this.Access == 'GUEST'){
return; // guest mode only supports dark theme
}
this.platform._theme = value;
}
/**
* @returns {boolean} True if the current theme is light.
*/
get LightTheme(): boolean {
return (this.Theme == 'light');
}
/**
* @returns {boolean} True if the current theme is dark.
*/
get DarkTheme(): boolean{
return (this.Theme == 'dark');
}
/**
* @description Observable that emits when the theme changes.
*/
get OnTheme(): Observable <null> {
return this.platform.OnThemeChanged;
}
/**
* @description Gets or sets the scrollbar visibility status on the platform.
*/
get Scrollbar(): boolean {
return this.platform._scrollbar;
}
set Scrollbar(value: boolean){
this.platform._scrollbar = value;
}
/**
* @returns {boolean} True if the device is mobile.
*/
get Mobile(): boolean{
return this.platform._isMobile;
}
/**
* @returns {boolean} True if the device is desktop.
*/
get Desktop(): boolean {
return this.platform._isDesktop;
}
/**
* @returns {boolean} True if the device is classified as legacy.
*/
get Legacy(): boolean {
return (this.platform._isMobile && this.platform.LegacyMobile) || (this.platform._isDesktop && this.platform.LegacyDesktop);
}
/**
* @description Gets or sets the kiosk mode status of the device.
*/
get Kiosk(): boolean {
return this.configuration.get(UppViewConfiguration.kiosk) as boolean || this.platform._isKiosk;
}
set Kiosk(value: boolean){
if (this.platform._isKiosk != value){
this.configuration.set(UppViewConfiguration.kiosk, value);
this.platform._isKiosk = value;
}
}
/**
* @description Observable that emits when kiosk mode status changes.
*/
get OnKiosk(): Observable <null>{
return this.platform.OnKioskChanged;
}
/**
* @description Gets or sets the pos mode status of the device.
*/
get IsPOS(): boolean {
return this.configuration.get(UppViewConfiguration.ispos) as boolean || false;
}
set IsPOS(value: boolean){
this.configuration.set(UppViewConfiguration.ispos, value);
}
/******************************/
/* ACCESS / VIEW */
/******************************/
private _View: ViewMode | null = null;
private _onViewChanged = new Subject<void>();
/**
* @description Observable that emits when the view changes.
*/
public OnViewChanged = this._onViewChanged.asObservable();
/**
* @description Forces a refresh by emitting a view change.
*/
async Refresh(): Promise <void> {
this._onViewChanged.next();
}
/******************************************/
/* VIEW: */
/* Determines the current view screen */
/******************************************/
/**
* @description Gets or sets the current view mode.
*/
get View(): ViewMode | null {
return this._View;
}
set View(value: ViewMode | null){
if (this._View != value){
console.info("[VIEW] New view '" + value + "' requested")
this._View = value;
this._onViewChanged.next();
}
}
/******************************************/
/* ACCESS: */
/* Determines the current user access */
/******************************************/
/**
* @description Gets or sets the current user access level.
*/
get Access(): UserMode |null {
return this.View ? this.state.Access : null;
}
set Access(value: UserMode){
this.state.Access = value;
switch(value){
case 'GUEST':
this.View = 'PLACE';
break;
case 'LOGIN':
this.View = 'LOGIN';
break;
}
}
/******************************************/
/* MODE: */
/* Determines the current edition mode */
/******************************************/
private _Mode: EditMode | null = null;
/**
* @description Gets or sets the current edit mode.
*/
get Mode(): EditMode | null {
return this._Mode;
}
set Mode(value: EditMode){
if (this.Mode != value){
this._Mode = value;
this._onViewChanged.next()
}
}
/******************************************/
/* RIGHT PANEL STATUS */
/******************************************/
private _rightdefault: string | null = null;
private _onRightChanged = new Subject<void>();
/**
* @description Observable that emits when the right panel visibility changes.
*/
public OnRightChanged = this._onRightChanged.asObservable();
/**
* @description Gets or sets the visibility of the right panel.
*/
get DefaultPanel(): string | null {
return this._rightdefault;
}
set DefaultPanel(value: string | null){
const previous = this._rightdefault
if (value != previous){
this._rightdefault = value;
this._onRightChanged.next();
}
}
/******************************************/
/* CURRENT TAB STATUS */
/******************************************/
private _maintab = new Map <EditMode, string | null> ()
private _scndtab = new Map <EditMode, string | null> ()
private _panelarg: any | null = null
private _onTabChanged = new Subject<string | null>();
/**
* @description Observable that emits when the tab changes.
*/
public OnTabChanged = this._onTabChanged.asObservable();
/**
* @description Gets or sets the primary tab.
* Setting a new tab will emit a change event.
*/
get MainTab(): string | null {
Iif (!this.Mode){
return null;
}
return this._maintab.get(this.Mode) || null;
}
SetMainTab(mode: EditMode, value: string | null){
this._maintab.set(mode, value);
if (mode == this.Mode){
this._onTabChanged.next(value);
}
}
/**
* @description Gets or sets the secondary tab.
* Setting a new tab will emit a change event.
*/
get ScndTab(): string | null {
Iif (!this.Mode){
return null;
}
return this._scndtab.get(this.Mode) || null;
}
set ScndTab(value: string | null){
Iif (!this.Mode){
return;
}
this._scndtab.set(this.Mode, value);
this._onTabChanged.next(value);
}
/**
* @description Gets or sets the secondary tab arguments.
* Setting the tab arguments will emit a change event.
*/
get PanelArg(): any | null {
return this._panelarg;
}
set PanelArg(value: any | null){
this._panelarg = value;
this._onTabChanged.next(value);
}
/******************************************/
/* PANEL CLOSE REQUEST */
/******************************************/
private _closesubscribers = 0;
private _onCloseRequest = new Subject <void> ();
/**
* @description Observable that emits when a panel close request is made.
*/
public OnCloseRequest = {
subscribe: (callback: () => void): Subscription => {
this._closesubscribers++; // increments the number of subscriptors
const subscription = this._onCloseRequest.asObservable().subscribe(callback);
// override the unsubscribe method to update the subscriber counters
const original_unsubscribe = subscription.unsubscribe;
subscription.unsubscribe = () => {
this._closesubscribers--; // release the subscriptor
original_unsubscribe.call(subscription);
};
return subscription;
}
};
private _onGrantChange = new Subject <boolean> ();
private OnGrantChange = this._onGrantChange.asObservable();
/**
* @description Emits a response to a close request.
* @param {boolean} allow - Indicates whether the close request is granted.
*/
OnCloseResponse(allow: boolean){
this._onGrantChange.next(allow);
}
/**
* @description Waits for responses from all subscribers to the close request and resolves to a boolean.
* @returns {Promise<boolean>} True if all subscribers allow the view change, otherwise false.
*/
async GrantViewChange(): Promise <boolean>{
return new Promise<boolean>((resolve) => {
if (this._closesubscribers > 0) {
const _responses: Array<boolean> = [];
const _subscription = this.OnGrantChange.subscribe((allow) => {
_responses.push(allow);
// we must wait until we have a response for each request
if (_responses.length === this._closesubscribers) {
_subscription.unsubscribe();
resolve(_responses.every((allow) => allow));
}
});
} else {
resolve(true);
}
this._onCloseRequest.next();
});
}
/******************************/
/* PLACE PANEL INFORMATION */
/******************************/
private _placepanel: PlacePanel | null = null;
/**
* @description Gets or sets the current place panel.
*/
get Panel(): PlacePanel | null{
return this._placepanel;
}
set Panel(value: PlacePanel | null){
this._placepanel = value;
}
/******************************/
/* ONLINE/OFFLINE CONTROL */
/******************************/
/**
* @returns {boolean} True if the application is online, otherwise false.
*/
get IsOnline(): boolean {
return this.http.IsOnline;
}
/**
* @description Observable that emits when the online status changes.
*/
public get OnOnline() : Observable <boolean> {
return this.http.OnOnline;
}
/******************************/
/* SERVICE WORKER UPDATES */
/******************************/
private _swupdate = false;
/**
* @description Gets or sets the service worker update status.
*/
get SwUpdate(): boolean {
return this._swupdate;
}
set SwUpdate(value: boolean){
if (value != this._swupdate){
if (value){
console.info("[UNPISPAS] Detected new service worker version!");
}
this._swupdate = value;
this._onViewChanged.next();
}
}
/******************************/
/* MAIN ENTRY POINT */
/******************************/
private CheckDevice(){
this.Kiosk = this.configuration.get(UppViewConfiguration.kiosk) as boolean || this.platform._isKiosk;
this._subscriptions.push(this.OnKiosk.subscribe(
() => {
this.Kiosk = this.platform._isKiosk;
}));
}
private async _LoadLanguages(): Promise <boolean> {
const _promises: Array <Promise<boolean>> = [];
_promises.push(this.lang.LoadModule('main'));
Iif (this.Access == 'GUEST'){
_promises.push(this.lang.LoadModule('guest'));
}
const _results = await Promise.all(_promises);
const _allok = _results.every(
(result) => {
return result === true
});
Iif (_allok){
this._onViewChanged.next();
}
return _allok;
}
/**
* @constructor
* @description Initializes the `viewService` by injecting necessary dependencies and setting up initial subscriptions.
* - **Dependencies**: Injects services for language management (`languageService`), platform-specific logic (`platformService`),
* HTTP connectivity (`httpService`), and state management (`stateService`).
* - **Device Initialization**: Waits for the platform to be ready and checks the device state (e.g., kiosk mode).
* - **Session Expiration Handling**: Subscribes to session expiration events from `stateService` to reset the view when the session expires.
* - **Close Request Subscription**: Subscribes to close requests, incrementing a counter to track the number of subscribers who respond to close events.
* - **Language Loading**: Initiates loading of necessary language modules based on the current user access level.
*
* @param {languageService} lang - Service responsible for managing language modules and localization.
* @param {platformService} platform - Service providing platform-specific information and state management.
* @param {httpService} http - Service for managing network connectivity and online status.
* @param {stateService} state - Service for managing user state and access level, including session expiration events.
*/
constructor(private lang: languageService, private platform: platformService, private http: httpService, private state: stateService, private config: configService){
this.platform.ready().then(
() => {
this.CheckDevice();
})
this._subscriptions.push(this.state.OnExpired.subscribe(
() => {
this.View = null;
}));
this._LoadLanguages();
}
/**
* @description Unsubscribes from all active subscriptions to prevent memory leaks.
*/
ngOnDestroy(){
for(const _subscription of this._subscriptions){
_subscription.unsubscribe();
}
this._subscriptions = [];
}
}
|