mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
#2034 falscher Drucker ausgewählt
This commit is contained in:
@@ -183,12 +183,4 @@ export class DomainPrinterService {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getDefaultPrinter({ printerType }: { printerType: 'Office' | 'Label' }): string {
|
||||
return localStorage.getItem(`Default_${printerType}_Printer`) ?? undefined;
|
||||
}
|
||||
|
||||
setDefaultPrinter({ printerType, printer }: { printerType: 'Office' | 'Label'; printer: string }): void {
|
||||
localStorage.setItem(`Default_${printerType}_Printer`, printer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,12 @@
|
||||
<ng-container *ngIf="!error">
|
||||
<div class="body">
|
||||
<ui-spinner [show]="!loaded">
|
||||
<ui-select class="select" [(ngModel)]="selectedPrinterValue">
|
||||
<ui-select-option *ngFor="let printer of printers$ | async" [label]="printer.text" [value]="printer.key"></ui-select-option>
|
||||
<ui-select class="select" [(ngModel)]="selectedPrinterKey">
|
||||
<ui-select-option
|
||||
*ngFor="let printer of printers$ | async"
|
||||
[label]="printer.description"
|
||||
[value]="printer.key"
|
||||
></ui-select-option>
|
||||
</ui-select>
|
||||
</ui-spinner>
|
||||
</div>
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
|
||||
.body {
|
||||
@apply mt-px-30 flex justify-center;
|
||||
}
|
||||
|
||||
::ng-deep ui-select-option button {
|
||||
@apply font-normal;
|
||||
}
|
||||
::ng-deep modal-print-cart ui-select-option button {
|
||||
@apply font-normal !important;
|
||||
}
|
||||
|
||||
.footer {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Printer, DomainPrinterService } from '@domain/printer';
|
||||
import { UiModalRef } from '@ui/modal';
|
||||
import { isResponseArgs } from '@utils/object';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { map, shareReplay } from 'rxjs/operators';
|
||||
import { PrintModalData } from './modal-printer.data';
|
||||
|
||||
@Component({
|
||||
@@ -13,14 +13,16 @@ import { PrintModalData } from './modal-printer.data';
|
||||
styleUrls: ['modal-printer.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class PrintModalComponent implements OnInit {
|
||||
protected selectedPrinterValue: string;
|
||||
printers$: Observable<{ key: string; text: string; selected: boolean }[]>;
|
||||
export class PrintModalComponent implements OnInit, OnDestroy {
|
||||
protected selectedPrinterKey: string;
|
||||
printers$: Observable<Printer[]>;
|
||||
|
||||
error = false;
|
||||
errorMessage = 'Der Druckauftrag konnte nicht ausgeführt werden.';
|
||||
loaded = false;
|
||||
|
||||
private subscriptions = new Subscription();
|
||||
|
||||
constructor(
|
||||
protected printerService: DomainPrinterService,
|
||||
public modalRef: UiModalRef<string, PrintModalData>,
|
||||
@@ -28,47 +30,48 @@ export class PrintModalComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadPrinters();
|
||||
this.initPrinters();
|
||||
}
|
||||
|
||||
loadPrinters() {
|
||||
ngOnDestroy() {
|
||||
this.subscriptions?.unsubscribe();
|
||||
}
|
||||
|
||||
initPrinters() {
|
||||
let printerResult$: Observable<Printer[] | { error: string }>;
|
||||
this.loaded = false;
|
||||
this.error = false;
|
||||
|
||||
if (this.modalRef.data.printerType === 'Office') {
|
||||
printerResult$ = this.printerService.getAvailableOfficePrinters();
|
||||
} else if (this.modalRef.data.printerType === 'Label') {
|
||||
printerResult$ = this.printerService.getAvailablePrinters();
|
||||
}
|
||||
this.printers$ = printerResult$.pipe(map((printers) => this.loadPrinterHelper(printers)));
|
||||
}
|
||||
|
||||
loadPrinterHelper(response: Printer[] | { error: string }): { key: string; text: string; selected: boolean }[] {
|
||||
if ((response as { error: string }).error) {
|
||||
const errorResponse = response as { error: string };
|
||||
this.error = true;
|
||||
this.errorMessage = errorResponse.error;
|
||||
} else {
|
||||
const result = response as Printer[];
|
||||
const printers = result.map((t) => {
|
||||
return { key: t.key, text: t.description, selected: t.selected };
|
||||
});
|
||||
const defaultPrinter = this.printerService.getDefaultPrinter({ printerType: this.modalRef.data.printerType });
|
||||
const selectedPrinter = printers.find((printer) => (printer.selected || defaultPrinter ? printer.key === defaultPrinter : false));
|
||||
this.selectedPrinterValue = selectedPrinter ? selectedPrinter.key : printers[0].key;
|
||||
this.printers$ = printerResult$.pipe(
|
||||
map((printers) => {
|
||||
this.loaded = true;
|
||||
if (Array.isArray(printers)) {
|
||||
return [...printers, ...printers, ...printers];
|
||||
} else {
|
||||
this.setError(printers.error);
|
||||
return [];
|
||||
}
|
||||
}),
|
||||
shareReplay()
|
||||
);
|
||||
|
||||
this.error = false;
|
||||
this.loaded = true;
|
||||
|
||||
if (!this.selectedPrinterValue) {
|
||||
this.error = true;
|
||||
this.errorMessage = 'Keine Drucker verfügbar.';
|
||||
}
|
||||
this.cdr.markForCheck();
|
||||
return printers;
|
||||
}
|
||||
return [];
|
||||
this.subscriptions.add(
|
||||
this.printers$.subscribe((printers) => {
|
||||
const defaultPrinter = printers.find((p) => p.selected);
|
||||
if (!!defaultPrinter) {
|
||||
if (!!this.modalRef?.data?.printImmediately) {
|
||||
this.print();
|
||||
}
|
||||
console.log({ defaultPrinter });
|
||||
this.selectedPrinterKey = defaultPrinter?.key || printers[0]?.key;
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
setError(errorMessage?: string) {
|
||||
@@ -81,9 +84,8 @@ export class PrintModalComponent implements OnInit {
|
||||
async print() {
|
||||
this.loaded = false;
|
||||
try {
|
||||
const printResponse = await this.modalRef.data.print(this.selectedPrinterValue);
|
||||
const printResponse = await this.modalRef.data.print(this.selectedPrinterKey);
|
||||
if (!printResponse.error) {
|
||||
this.printerService.setDefaultPrinter({ printerType: this.modalRef.data.printerType, printer: this.selectedPrinterValue });
|
||||
this.modalRef.close();
|
||||
} else {
|
||||
this.setError(printResponse.message);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export interface PrintModalData {
|
||||
printerType: 'Office' | 'Label';
|
||||
print: (printer: string) => Promise<{ error?: boolean; message?: string } | null>;
|
||||
printImmediately?: boolean;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,9 @@ export class ArticleDetailsComponent implements OnInit, OnDestroy {
|
||||
printerType: 'Label',
|
||||
print: (printer) => this.domainPrinterService.printProduct({ item, printer }).toPromise(),
|
||||
} as PrintModalData,
|
||||
config: {
|
||||
panelClass: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -318,6 +318,9 @@ export class CheckoutReviewComponent {
|
||||
printerType: 'Label',
|
||||
print: (printer) => this.domainPrinterService.printCart({ cartId: shoppingCart.id, printer }).toPromise(),
|
||||
} as PrintModalData,
|
||||
config: {
|
||||
panelClass: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,9 @@ export class CheckoutSummaryComponent {
|
||||
printerType: 'Label',
|
||||
print: (printer) => this.domainPrinterService.printOrder({ orderIds: [id], printer }).toPromise(),
|
||||
} as PrintModalData,
|
||||
config: {
|
||||
panelClass: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -145,6 +145,9 @@ export class TaskListComponent {
|
||||
})
|
||||
.toPromise(),
|
||||
} as PrintModalData,
|
||||
config: {
|
||||
panelClass: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ export class ArticleListModalComponent {
|
||||
print: (printer) =>
|
||||
this.domainPrinterService.printDisplayInfoDTOArticles({ articles, printer, title: `${this.modalRef.data.title}` }).toPromise(),
|
||||
} as PrintModalData,
|
||||
config: {
|
||||
panelClass: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ export class PdfViewerModalComponent {
|
||||
this.uiModal.open({
|
||||
content: PrintModalComponent,
|
||||
data,
|
||||
config: {
|
||||
panelClass: [],
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1047,6 +1047,9 @@ export class ProductDetailsComponent implements OnInit, OnDestroy {
|
||||
printerType: 'Office',
|
||||
print: (printer) => this.domainPrinterService.printProduct({ item: this.item, printer }).toPromise(),
|
||||
} as PrintModalData,
|
||||
config: {
|
||||
panelClass: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
:host {
|
||||
@apply block mx-auto box-border w-full bg-white p-4 rounded-card overflow-auto;
|
||||
@apply block mx-auto box-border w-full bg-white p-4 rounded-card;
|
||||
max-width: calc(100vw - 2rem);
|
||||
max-height: calc(100vh - 2rem);
|
||||
}
|
||||
|
||||
::ng-deep .cdk-overlay-pane.modal-overflow ui-modal {
|
||||
@apply overflow-auto;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ export class UiModalService {
|
||||
hasBackdrop: true,
|
||||
backdropClose: true,
|
||||
width: '917px',
|
||||
panelClass: ['modal-overflow'],
|
||||
...config,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user