Skip to content

Commit f36c0b3

Browse files
committed
fix(concierge): fix printing desk QR codes (PPT-2373)
1 parent 036617e commit f36c0b3

1 file changed

Lines changed: 69 additions & 7 deletions

File tree

apps/concierge/src/app/desks/desk-qr-code-modal.component.ts

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, computed, inject } from '@angular/core';
1+
import { Component, ViewEncapsulation, computed, inject } from '@angular/core';
22
import { SettingsService } from '@placeos/common';
33
import { DesksStateService } from './desks-state.service';
44

@@ -22,15 +22,13 @@ import { IconComponent, SafePipe, TranslatePipe } from '@placeos/components';
2222
<icon>close</icon>
2323
</button>
2424
</div>
25-
<div
26-
class="flex h-[calc(100vh-5rem)] flex-wrap overflow-auto print:h-auto"
27-
>
25+
<div class="desk-qr-list flex h-[calc(100vh-5rem)] flex-wrap overflow-auto">
2826
@for (desk of desks(); track desk) {
2927
<a
3028
[href]="desk.qr_link | safe: 'url'"
3129
target="_blank"
3230
ref="noopener noreferrer"
33-
class="mx-auto flex w-[28%] flex-col items-center justify-center landscape:w-[21%] print:h-[25vh] print:landscape:h-[33.33vh]"
31+
class="desk-qr-item mx-auto flex w-[28%] flex-col items-center justify-center landscape:w-[21%]"
3432
>
3533
<div
3634
class="border-base-200 bg-base-100 mx-4 my-2 block rounded-lg border p-2"
@@ -47,7 +45,52 @@ import { IconComponent, SafePipe, TranslatePipe } from '@placeos/components';
4745
</div>
4846
</div>
4947
`,
50-
styles: [``],
48+
styles: [
49+
`
50+
.desk-qr-body-print {
51+
display: none;
52+
}
53+
54+
body.desk-qr-printing .desk-qr-body-print {
55+
display: block;
56+
}
57+
58+
@media print {
59+
@page {
60+
margin: 8mm;
61+
}
62+
63+
body.desk-qr-printing > * {
64+
display: none !important;
65+
}
66+
67+
body.desk-qr-printing .desk-qr-body-print {
68+
display: block !important;
69+
position: static;
70+
inset: auto;
71+
width: 100%;
72+
margin: 0;
73+
padding: 0;
74+
}
75+
76+
body.desk-qr-printing .desk-qr-body-print .desk-qr-list {
77+
display: grid !important;
78+
grid-template-columns: repeat(3, minmax(0, 1fr));
79+
gap: 0.25rem;
80+
height: auto !important;
81+
overflow: visible !important;
82+
}
83+
84+
body.desk-qr-printing .desk-qr-body-print .desk-qr-item {
85+
width: 100% !important;
86+
margin: 0 !important;
87+
break-inside: avoid;
88+
page-break-inside: avoid;
89+
}
90+
}
91+
`,
92+
],
93+
encapsulation: ViewEncapsulation.None,
5194
imports: [
5295
CommonModule,
5396
MatDialogModule,
@@ -61,7 +104,20 @@ export class DeskQrCodeModalComponent {
61104
private _settings = inject(SettingsService);
62105
private _state = inject(DesksStateService);
63106

64-
public readonly print = () => window.print();
107+
public print() {
108+
this.desks();
109+
const source = document.querySelector('.desk-qr-list') as HTMLElement;
110+
if (!source) return window.print();
111+
this._cleanupPrintView();
112+
const print_root = document.createElement('div');
113+
print_root.className = 'desk-qr-body-print';
114+
print_root.appendChild(source.cloneNode(true));
115+
document.body.appendChild(print_root);
116+
document.body.classList.add('desk-qr-printing');
117+
const on_after_print = () => this._cleanupPrintView();
118+
window.addEventListener('afterprint', on_after_print, { once: true });
119+
setTimeout(() => window.print(), 50);
120+
}
65121

66122
public readonly desks = computed(() =>
67123
this._state.desks().map((_) => {
@@ -84,4 +140,10 @@ export class DeskQrCodeModalComponent {
84140
item.qr_code = generateQRCode(link);
85141
return item.qr_code;
86142
}
143+
144+
private _cleanupPrintView() {
145+
document.body.classList.remove('desk-qr-printing');
146+
const print_root = document.querySelector('.desk-qr-body-print');
147+
if (print_root) print_root.remove();
148+
}
87149
}

0 commit comments

Comments
 (0)