@sumaris-net/ngx-components 18.6.32 → 18.6.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/doc/changelog.md +2 -2
- package/esm2022/src/app/shared/functions.mjs +7 -1
- package/esm2022/src/app/shared/print/print.service.mjs +38 -14
- package/fesm2022/sumaris-net.ngx-components.mjs +42 -12
- package/fesm2022/sumaris-net.ngx-components.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/shared/functions.d.ts +6 -0
- package/src/app/shared/print/print.service.d.ts +30 -7
- package/src/assets/manifest.json +1 -1
|
@@ -670,6 +670,12 @@ function sleep(ms) {
|
|
|
670
670
|
function isPromise(value) {
|
|
671
671
|
return typeof value?.['then'] === 'function' && typeof value?.['catch'] === 'function';
|
|
672
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* Rounds a numeric value to two decimal places.
|
|
675
|
+
*
|
|
676
|
+
* @param {number | undefined | null} value - The value to be rounded. Can be a number, undefined, or null.
|
|
677
|
+
* @return {number} The rounded value with two decimal places if the input value is a valid number; otherwise, returns the input value.
|
|
678
|
+
*/
|
|
673
679
|
function round(value) {
|
|
674
680
|
if (isNotNilOrNaN(value)) {
|
|
675
681
|
return Math.round((value + Number.EPSILON) * 100) / 100;
|
|
@@ -27707,7 +27713,7 @@ class PrintService {
|
|
|
27707
27713
|
translate;
|
|
27708
27714
|
storage;
|
|
27709
27715
|
document;
|
|
27710
|
-
|
|
27716
|
+
_printId = 0;
|
|
27711
27717
|
constructor(toastController, translate, storage, document) {
|
|
27712
27718
|
this.toastController = toastController;
|
|
27713
27719
|
this.translate = translate;
|
|
@@ -27715,7 +27721,7 @@ class PrintService {
|
|
|
27715
27721
|
this.document = document;
|
|
27716
27722
|
}
|
|
27717
27723
|
nextJobId() {
|
|
27718
|
-
return ++this.
|
|
27724
|
+
return ++this._printId;
|
|
27719
27725
|
}
|
|
27720
27726
|
/**
|
|
27721
27727
|
* Extracts and returns the job ID from a given URL.
|
|
@@ -27726,16 +27732,22 @@ class PrintService {
|
|
|
27726
27732
|
getJobId(url) {
|
|
27727
27733
|
url = url || window.location.href;
|
|
27728
27734
|
const matches = url.match(/print-id=(\d+)/);
|
|
27729
|
-
return
|
|
27735
|
+
return matches?.[1] || undefined;
|
|
27730
27736
|
}
|
|
27731
|
-
|
|
27737
|
+
/**
|
|
27738
|
+
* Determines whether the provided URL or the current page's URL contains
|
|
27739
|
+
* a specific query parameter, indicating it's a printing-related URL.
|
|
27740
|
+
*
|
|
27741
|
+
* @param {string} [url] - The optional URL to check. If not provided, the current page's URL is used.
|
|
27742
|
+
* @param {string} [queryParam='print-id'] - The query parameter to look for, defaulting to 'print-id'.
|
|
27743
|
+
* @return {boolean} Returns true if the query parameter is found in the URL; otherwise, false.
|
|
27744
|
+
*/
|
|
27745
|
+
isPrintingUrl(url, queryParam = 'print-id') {
|
|
27732
27746
|
let query;
|
|
27733
27747
|
if (isNotNilOrBlank(url))
|
|
27734
27748
|
query = new URL(url).search;
|
|
27735
27749
|
query = query || window.location.search || '?';
|
|
27736
|
-
return
|
|
27737
|
-
// For compatibility
|
|
27738
|
-
query.indexOf('print-pdf') !== -1);
|
|
27750
|
+
return query.indexOf(queryParam) !== -1;
|
|
27739
27751
|
}
|
|
27740
27752
|
async printElement(element, opts) {
|
|
27741
27753
|
if (!element)
|
|
@@ -27749,18 +27761,35 @@ class PrintService {
|
|
|
27749
27761
|
const iframe = this.createPrintIframeByHtml(html, opts);
|
|
27750
27762
|
return this.printIframe(iframe, opts);
|
|
27751
27763
|
}
|
|
27764
|
+
/**
|
|
27765
|
+
* Prints the content of a URL by rendering it in an iframe.
|
|
27766
|
+
*
|
|
27767
|
+
* @param {string} url The URL of the content to print. This parameter is required.
|
|
27768
|
+
* @param {Omit<PrintOptions, 'style'>} [opts] Optional settings for printing, excluding the 'style' option.
|
|
27769
|
+
* @return {Promise<number>} A promise that resolves to the ID of the print job.
|
|
27770
|
+
*/
|
|
27752
27771
|
async printUrl(url, opts) {
|
|
27753
27772
|
if (isNilOrBlank(url))
|
|
27754
27773
|
throw new Error("Missing required 'url' argument");
|
|
27774
|
+
const jobId = opts?.id ?? this.nextJobId();
|
|
27755
27775
|
// Create iframe
|
|
27756
|
-
const iframe = this.createPrintIframeByUrl(url,
|
|
27776
|
+
const iframe = this.createPrintIframeByUrl(url, { id: jobId });
|
|
27777
|
+
// Launch the print job
|
|
27757
27778
|
return this.printIframe(iframe, opts);
|
|
27758
27779
|
}
|
|
27780
|
+
/**
|
|
27781
|
+
* Prints the content of the specified iframe element.
|
|
27782
|
+
*
|
|
27783
|
+
* @param {HTMLIFrameElement} iframe - The iframe element whose content needs to be printed. Must be a valid and loaded iframe element.
|
|
27784
|
+
* @param {PrintOptions} [opts] - Optional parameters for the print operation, which may include options for toast messages and job configuration.
|
|
27785
|
+
* @return {Promise<number>} A promise that resolves to the unique ID of the print job.
|
|
27786
|
+
* @throws Will throw an error if the required 'iframe' argument is missing or invalid.
|
|
27787
|
+
*/
|
|
27759
27788
|
async printIframe(iframe, opts) {
|
|
27760
27789
|
if (!iframe)
|
|
27761
27790
|
throw new Error("Missing required 'iframe' argument");
|
|
27762
|
-
const
|
|
27763
|
-
const toastId = `printing-${
|
|
27791
|
+
const jobId = opts?.id ?? this.nextJobId();
|
|
27792
|
+
const toastId = `printing-${jobId}`;
|
|
27764
27793
|
const showLoadingToast = opts?.showToast !== false;
|
|
27765
27794
|
if (showLoadingToast)
|
|
27766
27795
|
await this.showToast({
|
|
@@ -27770,9 +27799,10 @@ class PrintService {
|
|
|
27770
27799
|
});
|
|
27771
27800
|
try {
|
|
27772
27801
|
// Wait end of iframe load
|
|
27773
|
-
await this.waitIdle(iframe, { id:
|
|
27802
|
+
await this.waitIdle(iframe, { id: jobId });
|
|
27774
27803
|
// Print (and wait end of print)
|
|
27775
27804
|
await this.print(iframe);
|
|
27805
|
+
return jobId;
|
|
27776
27806
|
}
|
|
27777
27807
|
catch (err) {
|
|
27778
27808
|
console.error('[print-service] Failed to create hidden iframe', err);
|
|
@@ -27897,7 +27927,7 @@ class PrintService {
|
|
|
27897
27927
|
}
|
|
27898
27928
|
async waitIdle(iframe, opts) {
|
|
27899
27929
|
// Wait job finished
|
|
27900
|
-
const printId = opts?.id || this.
|
|
27930
|
+
const printId = opts?.id || this._printId;
|
|
27901
27931
|
await waitForTrue(timer(500, 500).pipe(mergeMap$1(() => this.isLoaded(printId))), { timeout: opts?.timeout });
|
|
27902
27932
|
// Wait end of iframe load
|
|
27903
27933
|
await new Promise((resolve, reject) => {
|