import {Component, OnInit, TemplateRef, ElementRef, Renderer2} from '@angular/core';
import {PrintService, PrintRequest} from './print.service';
+import {StoreService} from '@eg/core/store.service';
@Component({
selector: 'eg-print',
constructor(
private renderer: Renderer2,
private elm: ElementRef,
+ private store: StoreService,
private printer: PrintService
) {}
}
dispatchPrint(printReq: PrintRequest) {
+
+ if (!printReq.text) {
+ // Sometimes the results come from an externally-parsed HTML
+ // template, other times they come from an in-page template.
+ printReq.text = this.elm.nativeElement.innerHTML;
+ }
+
+ // Retain a copy of each printed document in localStorage
+ // so it may be reprinted.
+ this.store.setLocalItem('eg.print.last_printed', {
+ content: printReq.text,
+ context: printReq.printContext,
+ content_type: printReq.contentType,
+ show_dialog: printReq.showDialog
+ });
+
if (0 /* this.hatch.isActive */) {
this.printViaHatch(printReq);
} else {
printViaHatch(printReq: PrintRequest) {
- if (!printReq.text) {
- // Sometimes the results come from an externally-parsed HTML
- // template, other times they come from an in-page template.
- printReq.text = this.elm.nativeElement.innerHTML;
- }
-
// Send a full HTML document to Hatch
const html = `<html><body>${printReq.text}</body></html>`;
import {Injectable, EventEmitter, TemplateRef} from '@angular/core';
+import {StoreService} from '@eg/core/store.service';
export interface PrintRequest {
template?: TemplateRef<any>;
text?: string;
printContext: string;
contentType?: string; // defaults to text/html
+ showDialog?: boolean;
}
@Injectable()
onPrintRequest$: EventEmitter<PrintRequest>;
- constructor() {
+ constructor(private store: StoreService) {
this.onPrintRequest$ = new EventEmitter<PrintRequest>();
}
print(printReq: PrintRequest) {
this.onPrintRequest$.emit(printReq);
}
+
+ reprintLast() {
+ const prev = this.store.getLocalItem('eg.print.last_printed');
+
+ if (prev) {
+ const req: PrintRequest = {
+ text: prev.content,
+ printContext: prev.context || 'default',
+ contentType: prev.content_type || 'text/html',
+ showDialog: Boolean(prev.show_dialog)
+ };
+
+ this.print(req);
+ }
+ }
}
<span i18n>Scan Item as Missing Pieces</span>
</a>
<div class="dropdown-divider"></div>
- <a class="dropdown-item disabled" href="/eg/staff/splash">
+ <a class="dropdown-item" (click)="reprintLast()">
<span class="material-icons">redo</span>
<span i18n>Reprint Last Receipt</span>
</a>
import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {AuthService} from '@eg/core/auth.service';
+import {PrintService} from '@eg/share/print/print.service';
@Component({
selector: 'eg-staff-nav-bar',
constructor(
private router: Router,
- private auth: AuthService
+ private auth: AuthService,
+ private printer: PrintService
) {}
ngOnInit() {
this.auth.broadcastLogout();
this.router.navigate(['/staff/login']);
}
+
+ reprintLast() {
+ this.printer.reprintLast();
+ }
}