@sankhyalabs/sankhyablocks 8.3.0 → 8.4.0-dev.1
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/dist/cjs/{ConfigStorage-e9d7fa82.js → ConfigStorage-f0f89379.js} +163 -51
- package/dist/cjs/{DataFetcher-39b63a1e.js → DataFetcher-4798bac3.js} +136 -244
- package/dist/cjs/ISave-d68ce3cd.js +8 -0
- package/dist/cjs/PrintUtils-bcaeb82f.js +215 -0
- package/dist/cjs/ResourceIDUtils-5ff86aa7.js +12 -0
- package/dist/cjs/{SnkFormConfigManager-2f8eccd9.js → SnkFormConfigManager-d5fd8800.js} +19 -21
- package/dist/cjs/{auth-fetcher-d407c31c.js → auth-fetcher-f2967437.js} +2 -2
- package/dist/cjs/{dataunit-fetcher-15a7cc88.js → dataunit-fetcher-959c9a00.js} +1 -1
- package/dist/cjs/{form-config-fetcher-ab3ce222.js → form-config-fetcher-5e3d3b87.js} +66 -3
- package/dist/cjs/index-f9e81701.js +4 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{pesquisa-fetcher-96c042aa.js → pesquisa-fetcher-7973c081.js} +1 -1
- package/dist/cjs/sankhyablocks.cjs.js +1 -1
- package/dist/cjs/snk-actions-button.cjs.entry.js +19 -11
- package/dist/cjs/snk-application.cjs.entry.js +60 -44
- package/dist/cjs/snk-attach.cjs.entry.js +9 -14
- package/dist/cjs/snk-configurator.cjs.entry.js +2 -1
- package/dist/cjs/snk-crud.cjs.entry.js +28 -11
- package/dist/cjs/snk-data-exporter.cjs.entry.js +3 -2
- package/dist/cjs/{snk-data-unit-e89e07bd.js → snk-data-unit-7cc1846d.js} +5 -5
- package/dist/cjs/snk-data-unit.cjs.entry.js +1 -1
- package/dist/cjs/snk-detail-view.cjs.entry.js +17 -13
- package/dist/cjs/snk-entity-list.cjs.entry.js +0 -4
- package/dist/cjs/snk-filter-bar.cjs.entry.js +15 -17
- package/dist/cjs/snk-filter-detail.cjs.entry.js +7 -16
- package/dist/cjs/snk-filter-modal-item.cjs.entry.js +6 -19
- package/dist/cjs/snk-form-config.cjs.entry.js +7 -17
- package/dist/cjs/snk-form-view.cjs.entry.js +6 -1
- package/dist/cjs/snk-form.cjs.entry.js +13 -8
- package/dist/cjs/snk-grid-config.cjs.entry.js +6 -6
- package/dist/cjs/snk-grid.cjs.entry.js +23 -22
- package/dist/cjs/{snk-guides-viewer-8518c61b.js → snk-guides-viewer-b7b680d2.js} +19 -8
- package/dist/cjs/snk-guides-viewer.cjs.entry.js +10 -9
- package/dist/cjs/snk-personalized-filter.cjs.entry.js +14 -16
- package/dist/cjs/snk-print-selector.cjs.entry.js +2 -4
- package/dist/cjs/snk-simple-crud.cjs.entry.js +43 -85
- package/dist/cjs/snk-taskbar-custom-elements.cjs.entry.js +20 -0
- package/dist/cjs/snk-taskbar.cjs.entry.js +71 -5
- package/dist/cjs/{taskbar-elements-b98dd6e9.js → taskbar-elements-39949c7a.js} +4 -4
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/snk-actions-button/actions/index.js +3 -4
- package/dist/collection/components/snk-actions-button/snk-actions-button.js +8 -4
- package/dist/collection/components/snk-application/snk-application.js +120 -65
- package/dist/collection/components/snk-configurator/snk-configurator.js +19 -1
- package/dist/collection/components/snk-crud/snk-crud.js +44 -8
- package/dist/collection/components/snk-crud/subcomponents/snk-detail-view/snk-detail-view.js +60 -2
- package/dist/collection/components/snk-crud/subcomponents/snk-form-view.js +27 -1
- package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +65 -28
- package/dist/collection/components/snk-data-unit/snk-data-unit.js +22 -6
- package/dist/collection/components/snk-entity-list/snk-entity-list.js +0 -23
- package/dist/collection/components/snk-filter-bar/filter-item/snk-filter-detail.js +8 -13
- package/dist/collection/components/snk-filter-bar/filter-modal/snk-filter-modal.js +1 -1
- package/dist/collection/components/snk-filter-bar/filter-modal/subcomponents/snk-filter-modal-item.js +21 -16
- package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +28 -12
- package/dist/collection/components/snk-form/SnkFormConfigManager.js +17 -19
- package/dist/collection/components/snk-form/snk-form.js +46 -2
- package/dist/collection/components/snk-form/subcomponents/snk-form-config/snk-form-config.js +5 -15
- package/dist/collection/components/snk-grid/snk-grid.js +108 -16
- package/dist/collection/components/snk-grid/subcomponents/snk-grid-config/snk-grid-config.js +19 -1
- package/dist/collection/components/snk-personalized-filter/snk-personalized-filter.js +28 -12
- package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +23 -1
- package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +4 -4
- package/dist/collection/components/snk-taskbar/snk-taskbar-custom-elements.js +43 -0
- package/dist/collection/components/snk-taskbar/snk-taskbar.css +4 -0
- package/dist/collection/components/snk-taskbar/snk-taskbar.js +126 -5
- package/dist/collection/lib/configs/ConfigStorage.js +33 -44
- package/dist/collection/lib/dataUnit/InMemoryLoader.js +23 -71
- package/dist/collection/lib/http/data-fetcher/DataFetcher.js +118 -42
- package/dist/collection/lib/http/data-fetcher/fetchers/filter-bar-config-fetcher.js +0 -24
- package/dist/collection/lib/index.js +10 -0
- package/dist/collection/lib/resourceid/ResourceIDUtils.js +7 -0
- package/dist/collection/lib/utils/PrintUtils.js +18 -9
- package/dist/collection/lib/utils/urlutils.js +29 -0
- package/dist/components/ConfigStorage.js +161 -48
- package/dist/components/DataFetcher.js +137 -244
- package/dist/components/PrintUtils.js +213 -0
- package/dist/components/ResourceIDUtils.js +10 -0
- package/dist/components/SnkFormConfigManager.js +17 -19
- package/dist/components/auth-fetcher.js +1 -1
- package/dist/components/form-config-fetcher.js +64 -2
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/snk-actions-button2.js +23 -9
- package/dist/components/snk-application2.js +145 -129
- package/dist/components/snk-attach2.js +1 -8
- package/dist/components/snk-configurator2.js +3 -1
- package/dist/components/snk-crud.js +27 -8
- package/dist/components/snk-data-unit2.js +6 -5
- package/dist/components/snk-detail-view2.js +26 -10
- package/dist/components/snk-entity-list.js +0 -4
- package/dist/components/snk-filter-bar2.js +12 -12
- package/dist/components/snk-filter-detail2.js +8 -13
- package/dist/components/snk-filter-modal-item2.js +5 -16
- package/dist/components/snk-form-config2.js +5 -15
- package/dist/components/snk-form-view2.js +6 -1
- package/dist/components/snk-form.js +9 -2
- package/dist/components/snk-grid-config2.js +4 -2
- package/dist/components/snk-grid2.js +24 -17
- package/dist/components/snk-personalized-filter2.js +11 -11
- package/dist/components/snk-print-selector.js +1 -1
- package/dist/components/snk-simple-crud2.js +30 -73
- package/dist/components/snk-taskbar-custom-elements.d.ts +11 -0
- package/dist/components/snk-taskbar-custom-elements.js +35 -0
- package/dist/components/snk-taskbar2.js +81 -9
- package/dist/esm/{ConfigStorage-1090289a.js → ConfigStorage-4441aa3d.js} +162 -49
- package/dist/esm/{DataFetcher-a4ed43e7.js → DataFetcher-1618bffe.js} +137 -244
- package/dist/esm/ISave-4412b20c.js +8 -0
- package/dist/esm/PrintUtils-3e4ff0f5.js +213 -0
- package/dist/esm/ResourceIDUtils-a114189a.js +10 -0
- package/dist/esm/{SnkFormConfigManager-de537eca.js → SnkFormConfigManager-5a5f85a3.js} +19 -21
- package/dist/esm/{auth-fetcher-c53e0d6c.js → auth-fetcher-7861187e.js} +1 -1
- package/dist/esm/{dataunit-fetcher-8d0bfa4a.js → dataunit-fetcher-53c007be.js} +1 -1
- package/dist/esm/{form-config-fetcher-4065db9a.js → form-config-fetcher-2fe67341.js} +65 -3
- package/dist/esm/index-a7d3d3f1.js +4 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{pesquisa-fetcher-7460b876.js → pesquisa-fetcher-19e81fc8.js} +1 -1
- package/dist/esm/sankhyablocks.js +1 -1
- package/dist/esm/snk-actions-button.entry.js +19 -11
- package/dist/esm/snk-application.entry.js +60 -44
- package/dist/esm/snk-attach.entry.js +5 -10
- package/dist/esm/snk-configurator.entry.js +2 -1
- package/dist/esm/snk-crud.entry.js +30 -13
- package/dist/esm/snk-data-exporter.entry.js +3 -2
- package/dist/esm/{snk-data-unit-8c4d944d.js → snk-data-unit-1715d2f1.js} +5 -5
- package/dist/esm/snk-data-unit.entry.js +1 -1
- package/dist/esm/snk-detail-view.entry.js +17 -13
- package/dist/esm/snk-entity-list.entry.js +0 -4
- package/dist/esm/snk-filter-bar.entry.js +15 -17
- package/dist/esm/snk-filter-detail.entry.js +8 -17
- package/dist/esm/snk-filter-modal-item.entry.js +7 -20
- package/dist/esm/snk-form-config.entry.js +8 -18
- package/dist/esm/snk-form-view.entry.js +6 -1
- package/dist/esm/snk-form.entry.js +13 -8
- package/dist/esm/snk-grid-config.entry.js +6 -6
- package/dist/esm/snk-grid.entry.js +23 -22
- package/dist/esm/{snk-guides-viewer-cdecff6e.js → snk-guides-viewer-e4fe884d.js} +19 -8
- package/dist/esm/snk-guides-viewer.entry.js +10 -9
- package/dist/esm/snk-personalized-filter.entry.js +14 -16
- package/dist/esm/snk-print-selector.entry.js +1 -3
- package/dist/esm/snk-simple-crud.entry.js +34 -76
- package/dist/esm/snk-taskbar-custom-elements.entry.js +16 -0
- package/dist/esm/snk-taskbar.entry.js +71 -5
- package/dist/esm/{taskbar-elements-2c761819.js → taskbar-elements-0a6b8b95.js} +4 -4
- package/dist/sankhyablocks/p-0b99a775.entry.js +1 -0
- package/dist/sankhyablocks/p-1e30c376.entry.js +1 -0
- package/dist/sankhyablocks/p-1fa3acbe.entry.js +1 -0
- package/dist/sankhyablocks/p-27dbbb3a.entry.js +1 -0
- package/dist/sankhyablocks/p-29b1d77b.entry.js +11 -0
- package/dist/sankhyablocks/p-324ce41e.entry.js +1 -0
- package/dist/sankhyablocks/p-34604220.entry.js +1 -0
- package/dist/sankhyablocks/p-41820e28.entry.js +1 -0
- package/dist/sankhyablocks/p-4352324d.entry.js +1 -0
- package/dist/sankhyablocks/{p-9d18017a.js → p-449d25e0.js} +2 -2
- package/dist/sankhyablocks/p-5051a23a.entry.js +1 -0
- package/dist/sankhyablocks/p-5526ab67.js +1 -0
- package/dist/sankhyablocks/p-5b2ee1d3.js +1 -0
- package/dist/sankhyablocks/p-5da848bb.js +26 -0
- package/dist/sankhyablocks/p-6098d844.entry.js +1 -0
- package/dist/sankhyablocks/p-648a7c72.entry.js +1 -0
- package/dist/sankhyablocks/p-688dcb4c.js +1 -0
- package/dist/sankhyablocks/p-72fc257b.entry.js +1 -0
- package/dist/sankhyablocks/p-7d6eca73.entry.js +1 -0
- package/dist/sankhyablocks/p-81a7f74c.js +1 -0
- package/dist/sankhyablocks/p-8d884fab.js +1 -0
- package/dist/sankhyablocks/p-90b5d1af.entry.js +1 -0
- package/dist/sankhyablocks/p-989937ee.entry.js +1 -0
- package/dist/sankhyablocks/p-9a270401.entry.js +1 -0
- package/dist/sankhyablocks/p-9e7d65a4.js +1 -0
- package/dist/sankhyablocks/{p-b978da60.js → p-a75e892a.js} +1 -1
- package/dist/sankhyablocks/p-a81996df.js +1 -0
- package/dist/sankhyablocks/p-c555075c.entry.js +1 -0
- package/dist/sankhyablocks/{p-a2493d11.js → p-c9841939.js} +1 -1
- package/dist/sankhyablocks/p-ca1522bc.entry.js +1 -0
- package/dist/sankhyablocks/p-cbed6235.entry.js +1 -0
- package/dist/sankhyablocks/p-d4f9ee17.entry.js +1 -0
- package/dist/sankhyablocks/p-daa687aa.js +56 -0
- package/dist/sankhyablocks/p-e1cb1f0b.js +1 -0
- package/dist/sankhyablocks/p-eb1a650a.entry.js +1 -0
- package/dist/sankhyablocks/p-f784010c.entry.js +1 -0
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/dist/types/components/snk-actions-button/actions/index.d.ts +2 -1
- package/dist/types/components/snk-application/snk-application.d.ts +9 -22
- package/dist/types/components/snk-configurator/snk-configurator.d.ts +4 -0
- package/dist/types/components/snk-crud/snk-crud.d.ts +6 -0
- package/dist/types/components/snk-crud/subcomponents/snk-detail-view/snk-detail-view.d.ts +12 -0
- package/dist/types/components/snk-crud/subcomponents/snk-form-view.d.ts +5 -0
- package/dist/types/components/snk-crud/subcomponents/snk-guides-viewer.d.ts +13 -2
- package/dist/types/components/snk-data-unit/snk-data-unit.d.ts +4 -0
- package/dist/types/components/snk-entity-list/snk-entity-list.d.ts +0 -4
- package/dist/types/components/snk-filter-bar/filter-item/snk-filter-detail.d.ts +0 -3
- package/dist/types/components/snk-filter-bar/filter-modal/snk-filter-modal.d.ts +1 -1
- package/dist/types/components/snk-filter-bar/filter-modal/subcomponents/snk-filter-modal-item.d.ts +5 -4
- package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +4 -0
- package/dist/types/components/snk-form/SnkFormConfigManager.d.ts +5 -4
- package/dist/types/components/snk-form/snk-form.d.ts +9 -1
- package/dist/types/components/snk-form/subcomponents/snk-form-config/snk-form-config.d.ts +0 -2
- package/dist/types/components/snk-grid/snk-grid.d.ts +17 -1
- package/dist/types/components/snk-grid/subcomponents/snk-grid-config/snk-grid-config.d.ts +4 -0
- package/dist/types/components/snk-personalized-filter/snk-personalized-filter.d.ts +5 -1
- package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +4 -0
- package/dist/types/components/snk-taskbar/processor/taskbar-processor.d.ts +2 -2
- package/dist/types/components/snk-taskbar/snk-taskbar-custom-elements.d.ts +7 -0
- package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +27 -0
- package/dist/types/components.d.ts +203 -22
- package/dist/types/lib/configs/ConfigStorage.d.ts +11 -13
- package/dist/types/lib/dataUnit/InMemoryLoader.d.ts +2 -8
- package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +2 -2
- package/dist/types/lib/http/data-fetcher/fetchers/filter-bar-config-fetcher.d.ts +0 -1
- package/dist/types/lib/index.d.ts +11 -0
- package/dist/types/lib/resourceid/ResourceIDUtils.d.ts +3 -0
- package/dist/types/lib/utils/PrintUtils.d.ts +1 -0
- package/dist/types/lib/utils/urlutils.d.ts +14 -0
- package/package.json +2 -2
- package/react/components.d.ts +1 -0
- package/react/components.js +1 -0
- package/react/components.js.map +1 -1
- package/dist/cjs/filter-bar-config-fetcher-24548cec.js +0 -155
- package/dist/cjs/resource-fetcher-64102551.js +0 -68
- package/dist/components/filter-bar-config-fetcher.js +0 -153
- package/dist/components/resource-fetcher.js +0 -66
- package/dist/esm/filter-bar-config-fetcher-2417b8cf.js +0 -153
- package/dist/esm/resource-fetcher-45a70066.js +0 -66
- package/dist/sankhyablocks/p-0848ee4d.entry.js +0 -1
- package/dist/sankhyablocks/p-0bd9c412.js +0 -1
- package/dist/sankhyablocks/p-0fb83448.js +0 -1
- package/dist/sankhyablocks/p-10b2aedc.entry.js +0 -1
- package/dist/sankhyablocks/p-1f63dcd4.entry.js +0 -1
- package/dist/sankhyablocks/p-216b2102.entry.js +0 -1
- package/dist/sankhyablocks/p-216f081a.entry.js +0 -1
- package/dist/sankhyablocks/p-44e66c8d.js +0 -1
- package/dist/sankhyablocks/p-4514fc6a.entry.js +0 -1
- package/dist/sankhyablocks/p-50c13cc8.entry.js +0 -1
- package/dist/sankhyablocks/p-52c6b2e7.js +0 -1
- package/dist/sankhyablocks/p-564efc43.js +0 -1
- package/dist/sankhyablocks/p-5994af77.js +0 -56
- package/dist/sankhyablocks/p-6bb904bb.entry.js +0 -1
- package/dist/sankhyablocks/p-6e06175e.entry.js +0 -1
- package/dist/sankhyablocks/p-6f0795c8.entry.js +0 -1
- package/dist/sankhyablocks/p-7588f006.entry.js +0 -1
- package/dist/sankhyablocks/p-847e6c20.js +0 -17
- package/dist/sankhyablocks/p-8f3652bf.entry.js +0 -11
- package/dist/sankhyablocks/p-9471cbc9.entry.js +0 -1
- package/dist/sankhyablocks/p-a42dd503.entry.js +0 -1
- package/dist/sankhyablocks/p-b04fb9d4.js +0 -1
- package/dist/sankhyablocks/p-befbc9ee.entry.js +0 -1
- package/dist/sankhyablocks/p-c32b9d7c.entry.js +0 -1
- package/dist/sankhyablocks/p-c6380ea2.entry.js +0 -1
- package/dist/sankhyablocks/p-c6feb995.entry.js +0 -1
- package/dist/sankhyablocks/p-d7c7a289.entry.js +0 -1
- package/dist/sankhyablocks/p-de69b4b0.entry.js +0 -1
- package/dist/sankhyablocks/p-f3b7b69e.js +0 -10
- package/dist/sankhyablocks/p-f7eded3a.entry.js +0 -1
- package/dist/sankhyablocks/p-ff7383b0.entry.js +0 -1
@@ -1,6 +1,7 @@
|
|
1
|
-
import { DataType,
|
1
|
+
import { DataType, ApplicationContext, ErrorException, WarningException, ObjectUtils, StringUtils } from '@sankhyalabs/core';
|
2
2
|
import { c as createCommonjsModule, a as commonjsGlobal } from './_commonjsHelpers.js';
|
3
3
|
import { DataUnitTransient } from '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
4
|
+
import { P as PrintUtils } from './PrintUtils.js';
|
4
5
|
|
5
6
|
var browserPonyfill = createCommonjsModule(function (module, exports) {
|
6
7
|
var global = typeof self !== 'undefined' ? self : commonjsGlobal;
|
@@ -6434,6 +6435,35 @@ class UrlUtils {
|
|
6434
6435
|
return window['mock_url'];
|
6435
6436
|
return `${location.protocol}//${location.hostname}${location.port ? ":" + location.port : ""}`;
|
6436
6437
|
}
|
6438
|
+
/**
|
6439
|
+
* Extrai da URL o parâmetro que contém o resourceId da tela desejada.
|
6440
|
+
*
|
6441
|
+
*/
|
6442
|
+
static getResourceIdFromUrlToken(url) {
|
6443
|
+
try {
|
6444
|
+
const parts = url.split('/');
|
6445
|
+
const encodedValue = parts[1];
|
6446
|
+
return atob(encodedValue);
|
6447
|
+
}
|
6448
|
+
catch (error) {
|
6449
|
+
throw new Error('Erro ao obter resourceId:' + error);
|
6450
|
+
}
|
6451
|
+
}
|
6452
|
+
/**
|
6453
|
+
* Extrai da URL o parâmetro que contém o o objeto com a PK do registro específico.
|
6454
|
+
*
|
6455
|
+
*/
|
6456
|
+
static getPkObjectFromUrlToken(url) {
|
6457
|
+
try {
|
6458
|
+
const parts = url.split('/');
|
6459
|
+
const encodedObjectPart = parts[parts.length - 2];
|
6460
|
+
const decodedObjectPart = atob(encodedObjectPart);
|
6461
|
+
return JSON.parse(decodedObjectPart);
|
6462
|
+
}
|
6463
|
+
catch (error) {
|
6464
|
+
throw new Error('Erro ao obter a PK do objeto:' + error);
|
6465
|
+
}
|
6466
|
+
}
|
6437
6467
|
}
|
6438
6468
|
|
6439
6469
|
class ServiceBrokerRecaller {
|
@@ -6477,209 +6507,17 @@ class GraphQLRecaller {
|
|
6477
6507
|
}
|
6478
6508
|
}
|
6479
6509
|
|
6480
|
-
|
6481
|
-
|
6482
|
-
|
6483
|
-
}
|
6484
|
-
|
6485
|
-
|
6486
|
-
|
6487
|
-
}
|
6488
|
-
return PrintUtils.instance;
|
6489
|
-
}
|
6490
|
-
async processPendingPrinting(transactionId) {
|
6491
|
-
await this.findPendingPrints(transactionId);
|
6492
|
-
}
|
6493
|
-
async findPendingPrints(transactionId) {
|
6494
|
-
const requestBody = {
|
6495
|
-
transactionIds: [
|
6496
|
-
{
|
6497
|
-
transactionId: {
|
6498
|
-
$: transactionId
|
6499
|
-
}
|
6500
|
-
}
|
6501
|
-
]
|
6502
|
-
};
|
6503
|
-
const response = await DataFetcher.get().callServiceBroker(PrintUtils.SERVICE_FIND_PENDING_PRINTS, JSON.stringify(requestBody));
|
6504
|
-
const printJobData = this.parsePrintData(response);
|
6505
|
-
const pendingPrints = await this.processDirectPrint(printJobData);
|
6506
|
-
if (!pendingPrints.length)
|
6507
|
-
return;
|
6508
|
-
this.openSnkPrintSelector(Object.assign(Object.assign({}, printJobData), { pendingPrinters: pendingPrints }));
|
6509
|
-
}
|
6510
|
-
getLocalPrinters() {
|
6511
|
-
const localPrinters = this.appletImpressao.findLocalPrinters();
|
6512
|
-
const printers = [];
|
6513
|
-
for (const printerName of localPrinters) {
|
6514
|
-
printers.push({
|
6515
|
-
nome: printerName,
|
6516
|
-
printerUri: PrintUtils.LOCAL_SERVER_URI + printerName,
|
6517
|
-
isLocal: true
|
6518
|
-
});
|
6519
|
-
}
|
6520
|
-
return printers;
|
6521
|
-
}
|
6522
|
-
parsePrintData(payload) {
|
6523
|
-
const pendingPrintJobData = payload.pendindPrintJobData;
|
6524
|
-
if (!pendingPrintJobData)
|
6525
|
-
return undefined;
|
6526
|
-
let { printServers: { printServer }, pendingPrinters: { pendingPrinter } } = pendingPrintJobData;
|
6527
|
-
printServer = printServer ? (Array.isArray(printServer) ? printServer : [printServer]) : [];
|
6528
|
-
pendingPrinter = pendingPrinter ? (Array.isArray(pendingPrinter) ? pendingPrinter : [pendingPrinter]) : [];
|
6529
|
-
const normalizedPrintServer = printServer.map(item => {
|
6530
|
-
const printerList = Array.isArray(item.printerLocation) ? item.printerLocation : [item.printerLocation];
|
6531
|
-
return {
|
6532
|
-
printServerUri: item.printServerUri,
|
6533
|
-
printerList: printerList.map(this.normalize)
|
6534
|
-
};
|
6535
|
-
});
|
6536
|
-
const normalizedPendingPrinter = pendingPrinter.map(this.normalize);
|
6537
|
-
return {
|
6538
|
-
transactionId: pendingPrintJobData.transactionId.$,
|
6539
|
-
printServers: normalizedPrintServer,
|
6540
|
-
pendingPrinters: normalizedPendingPrinter,
|
6541
|
-
printServerActive: pendingPrintJobData.printServers.printServerActive === 'true'
|
6542
|
-
};
|
6543
|
-
}
|
6544
|
-
normalize(object) {
|
6545
|
-
const normalizedObject = {};
|
6546
|
-
Object.keys(object).forEach((key) => {
|
6547
|
-
normalizedObject[key] = PrintUtils.ENCODED_PROPERTIES.includes(key) ? window.atob(object[key].$) : object[key].$;
|
6548
|
-
});
|
6549
|
-
return normalizedObject;
|
6550
|
-
}
|
6551
|
-
processLocalPrinting(localPrintings) {
|
6552
|
-
const transactionIds = localPrintings.map((item) => item.transactionId);
|
6553
|
-
this.appletImpressao.doLocalPrinting(transactionIds.join());
|
6554
|
-
}
|
6555
|
-
async openSnkPrintSelector(printJobData) {
|
6556
|
-
let printSelector = document.querySelector('snk-print-selector');
|
6557
|
-
if (!printSelector) {
|
6558
|
-
printSelector = document.createElement('snk-print-selector');
|
6559
|
-
printSelector.setAttribute('id', StringUtils.generateUUID());
|
6560
|
-
window.document.body.appendChild(printSelector);
|
6561
|
-
}
|
6562
|
-
const { selectedPrinter, saveSubstitute } = await printSelector.openPrintSelector(printJobData);
|
6563
|
-
if (!selectedPrinter)
|
6564
|
-
return;
|
6565
|
-
const params = {
|
6566
|
-
transactionId: printJobData.transactionId,
|
6567
|
-
pendingPrinters: printJobData.pendingPrinters,
|
6568
|
-
printerUri: selectedPrinter.printerUri,
|
6569
|
-
saveSubstitutePrinters: saveSubstitute
|
6570
|
-
};
|
6571
|
-
await this.saveSubstitutePrinter(params);
|
6572
|
-
}
|
6573
|
-
async saveSubstitutePrinter(params) {
|
6574
|
-
const { transactionId, pendingPrinters, printerUri, saveSubstitutePrinters = false } = params;
|
6575
|
-
const parsedPendingPrinters = pendingPrinters.map((item) => ({
|
6576
|
-
printerUri: {
|
6577
|
-
$: item.printerUri || printerUri
|
6578
|
-
},
|
6579
|
-
originalPrinterName: {
|
6580
|
-
$: item.originalPrinterName
|
6581
|
-
},
|
6582
|
-
printJobCount: {
|
6583
|
-
$: item.printJobCount
|
6584
|
-
},
|
6585
|
-
docType: {
|
6586
|
-
$: item.docType
|
6587
|
-
},
|
6588
|
-
docTypeDescription: {
|
6589
|
-
$: item.docTypeDescription
|
6590
|
-
}
|
6591
|
-
}));
|
6592
|
-
const requestBody = {
|
6593
|
-
substitutePrintersRequest: {
|
6594
|
-
substitutePrinters: {
|
6595
|
-
pendingPrinter: parsedPendingPrinters
|
6596
|
-
},
|
6597
|
-
saveSubstitutePrinters: {
|
6598
|
-
$: saveSubstitutePrinters.toString()
|
6599
|
-
},
|
6600
|
-
transactionId: {
|
6601
|
-
$: transactionId
|
6602
|
-
}
|
6603
|
-
}
|
6604
|
-
};
|
6605
|
-
await DataFetcher.get().callServiceBroker(PrintUtils.SERVICE_SAVE_SUBSTITUTE_PRINTER, JSON.stringify(requestBody));
|
6606
|
-
}
|
6607
|
-
async processDirectPrint(printJobData) {
|
6608
|
-
const isWCRunning = this.appletImpressao.checkWebConnection();
|
6609
|
-
if (!isWCRunning) {
|
6610
|
-
return [];
|
6611
|
-
}
|
6612
|
-
const localPrinters = this.getLocalPrinters();
|
6613
|
-
if (!localPrinters.length)
|
6614
|
-
return [];
|
6615
|
-
const directPendingPrints = [];
|
6616
|
-
const pendingPrints = printJobData.pendingPrinters.filter(item => {
|
6617
|
-
const defaultPrinterName = this.getDefaultPrinterName(item.originalPrinterName);
|
6618
|
-
const isDirectPrint = !!localPrinters.find(localPrinter => localPrinter.nome === defaultPrinterName) || this.isPrinterNameAFile(defaultPrinterName);
|
6619
|
-
if (isDirectPrint) {
|
6620
|
-
directPendingPrints.push(Object.assign(Object.assign({}, item), { printerUri: PrintUtils.LOCAL_SERVER_URI + defaultPrinterName }));
|
6621
|
-
return false;
|
6622
|
-
}
|
6623
|
-
return true;
|
6624
|
-
});
|
6625
|
-
if (!directPendingPrints.length)
|
6626
|
-
return pendingPrints;
|
6627
|
-
const params = {
|
6628
|
-
transactionId: printJobData.transactionId,
|
6629
|
-
pendingPrinters: directPendingPrints
|
6630
|
-
};
|
6631
|
-
await this.saveSubstitutePrinter(params);
|
6632
|
-
return pendingPrints;
|
6633
|
-
}
|
6634
|
-
getDefaultPrinterName(printerName) {
|
6635
|
-
const defaultPrinterName = this.appletImpressao.getDefaultPrinter();
|
6636
|
-
const isDefaultPrinterName = /padr[aã]o/ig.test(printerName);
|
6637
|
-
return (defaultPrinterName && isDefaultPrinterName) ? defaultPrinterName : printerName;
|
6638
|
-
}
|
6639
|
-
isPrinterNameAFile(printerName) {
|
6640
|
-
const regExp = new RegExp("^(\w:)?[/\\\w\s]+?\.\w{3}$", "mis");
|
6641
|
-
return regExp.test(printerName);
|
6642
|
-
}
|
6643
|
-
}
|
6644
|
-
PrintUtils.SERVICE_FIND_PENDING_PRINTS = 'mge@PrintServiceSP.findPendingPrinters';
|
6645
|
-
PrintUtils.SERVICE_SAVE_SUBSTITUTE_PRINTER = 'mge@PrintServiceSP.saveSubstitutePrinter';
|
6646
|
-
PrintUtils.LOCAL_SERVER_URI = 'LOCAL:0/';
|
6647
|
-
PrintUtils.ENCODED_PROPERTIES = ['printerName', 'printerUri'];
|
6648
|
-
class AppletImpressao {
|
6649
|
-
constructor() {
|
6650
|
-
this.appletImpressao = document.getElementById('centralNotaAppletImpressao');
|
6651
|
-
}
|
6652
|
-
checkWebConnection() {
|
6653
|
-
if (!this.appletImpressao)
|
6654
|
-
return false;
|
6655
|
-
if (!this.appletImpressao.testRunningWC)
|
6656
|
-
return false;
|
6657
|
-
const isRunning = this.appletImpressao.testRunningWC();
|
6658
|
-
return !!isRunning;
|
6659
|
-
}
|
6660
|
-
findLocalPrinters() {
|
6661
|
-
if (!this.appletImpressao)
|
6662
|
-
return [];
|
6663
|
-
const localPrinters = this.appletImpressao.getLocalPrinters();
|
6664
|
-
if (!localPrinters)
|
6665
|
-
return [];
|
6666
|
-
return localPrinters.split(",");
|
6667
|
-
}
|
6668
|
-
doLocalPrinting(transactionIds) {
|
6669
|
-
if (!this.appletImpressao)
|
6670
|
-
return;
|
6671
|
-
this.appletImpressao.doLocalPrinting(transactionIds);
|
6672
|
-
}
|
6673
|
-
getDefaultPrinter() {
|
6674
|
-
if (!this.appletImpressao)
|
6675
|
-
return '';
|
6676
|
-
return this.appletImpressao.getPrintDefault();
|
6677
|
-
}
|
6678
|
-
}
|
6679
|
-
|
6510
|
+
var __asyncValues = (undefined && undefined.__asyncValues) || function (o) {
|
6511
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
6512
|
+
var m = o[Symbol.asyncIterator], i;
|
6513
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
6514
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
6515
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
6516
|
+
};
|
6680
6517
|
class DataFetcher {
|
6681
6518
|
constructor() {
|
6682
6519
|
this.GRAPHQL_PATH = `/${window.MGE_MODULE_NAME || 'mgefin-bff'}/graphql`;
|
6520
|
+
this.ready = true;
|
6683
6521
|
this.watingRequestsById = new Map();
|
6684
6522
|
}
|
6685
6523
|
static get() {
|
@@ -6690,6 +6528,9 @@ class DataFetcher {
|
|
6690
6528
|
DataFetcher.instance.resume();
|
6691
6529
|
}
|
6692
6530
|
else {
|
6531
|
+
if (ApplicationContext.getContextValue("__SNK__APPLICATION__LOADING__") === true) {
|
6532
|
+
DataFetcher.instance.pause();
|
6533
|
+
}
|
6693
6534
|
application.addEventListener('applicationLoading', () => DataFetcher.instance.pause());
|
6694
6535
|
application.addEventListener('applicationLoaded', () => DataFetcher.instance.resume());
|
6695
6536
|
}
|
@@ -6748,6 +6589,10 @@ class DataFetcher {
|
|
6748
6589
|
}
|
6749
6590
|
async callGraphQL(req) {
|
6750
6591
|
var _a;
|
6592
|
+
if (this.ready) {
|
6593
|
+
this.pause();
|
6594
|
+
window.requestAnimationFrame(() => this.resume());
|
6595
|
+
}
|
6751
6596
|
const reqKey = this.getReqKey(req);
|
6752
6597
|
req.queryID = reqKey;
|
6753
6598
|
req.values.queryID = reqKey;
|
@@ -6777,7 +6622,7 @@ class DataFetcher {
|
|
6777
6622
|
if (!this.watingRequestsById.has(reqKey)) {
|
6778
6623
|
this.watingRequestsById.set(reqKey, new WaitingRequest(req));
|
6779
6624
|
}
|
6780
|
-
return (_a = this.
|
6625
|
+
return (_a = this.watingRequestsById.get(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
|
6781
6626
|
}
|
6782
6627
|
}
|
6783
6628
|
resolveURL() {
|
@@ -6806,22 +6651,63 @@ class DataFetcher {
|
|
6806
6651
|
}
|
6807
6652
|
return false;
|
6808
6653
|
}
|
6809
|
-
|
6654
|
+
async processServiceBrokerClientEvents(processParams) {
|
6655
|
+
var _a, e_1, _b, _c, _d, e_2, _e, _f;
|
6656
|
+
const { clientEvents, serviceName, payloadJson, accept, reject } = processParams;
|
6810
6657
|
if (!(clientEvents === null || clientEvents === void 0 ? void 0 : clientEvents.length)) {
|
6811
6658
|
return;
|
6812
6659
|
}
|
6813
|
-
|
6814
|
-
|
6815
|
-
|
6816
|
-
|
6817
|
-
|
6818
|
-
|
6660
|
+
const recaller = new ServiceBrokerRecaller(serviceName, payloadJson, accept, reject);
|
6661
|
+
try {
|
6662
|
+
for (var _g = true, clientEvents_1 = __asyncValues(clientEvents), clientEvents_1_1; clientEvents_1_1 = await clientEvents_1.next(), _a = clientEvents_1_1.done, !_a;) {
|
6663
|
+
_c = clientEvents_1_1.value;
|
6664
|
+
_g = false;
|
6665
|
+
try {
|
6666
|
+
const clientEvent = _c;
|
6667
|
+
if (DataFetcher.hasClientEvent(clientEvent.id)) {
|
6668
|
+
const handlers = DataFetcher.clientEventsByID.get(clientEvent.id);
|
6669
|
+
const handlerClientEvent = {
|
6670
|
+
id: clientEvent.id,
|
6671
|
+
content: clientEvent
|
6672
|
+
};
|
6673
|
+
try {
|
6674
|
+
for (var _h = true, handlers_1 = (e_2 = void 0, __asyncValues(handlers)), handlers_1_1; handlers_1_1 = await handlers_1.next(), _d = handlers_1_1.done, !_d;) {
|
6675
|
+
_f = handlers_1_1.value;
|
6676
|
+
_h = false;
|
6677
|
+
try {
|
6678
|
+
const handler = _f;
|
6679
|
+
await handler(handlerClientEvent, recaller);
|
6680
|
+
}
|
6681
|
+
finally {
|
6682
|
+
_h = true;
|
6683
|
+
}
|
6684
|
+
}
|
6685
|
+
}
|
6686
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
6687
|
+
finally {
|
6688
|
+
try {
|
6689
|
+
if (!_h && !_d && (_e = handlers_1.return)) await _e.call(handlers_1);
|
6690
|
+
}
|
6691
|
+
finally { if (e_2) throw e_2.error; }
|
6692
|
+
}
|
6693
|
+
}
|
6694
|
+
}
|
6695
|
+
finally {
|
6696
|
+
_g = true;
|
6697
|
+
}
|
6819
6698
|
}
|
6820
|
-
}
|
6699
|
+
}
|
6700
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
6701
|
+
finally {
|
6702
|
+
try {
|
6703
|
+
if (!_g && !_a && (_b = clientEvents_1.return)) await _b.call(clientEvents_1);
|
6704
|
+
}
|
6705
|
+
finally { if (e_1) throw e_1.error; }
|
6706
|
+
}
|
6821
6707
|
}
|
6822
|
-
processPrinting(payload) {
|
6708
|
+
async processPrinting(payload) {
|
6823
6709
|
if ((payload === null || payload === void 0 ? void 0 : payload.pendingPrinting) === 'true') {
|
6824
|
-
PrintUtils.getInstance().processPendingPrinting(payload === null || payload === void 0 ? void 0 : payload.transactionId);
|
6710
|
+
await PrintUtils.getInstance().processPendingPrinting(payload === null || payload === void 0 ? void 0 : payload.transactionId);
|
6825
6711
|
}
|
6826
6712
|
if ('localPrintings' in payload) {
|
6827
6713
|
PrintUtils.getInstance().processLocalPrinting(payload === null || payload === void 0 ? void 0 : payload.localPrintings);
|
@@ -6869,11 +6755,19 @@ class DataFetcher {
|
|
6869
6755
|
http.open("POST", url, true);
|
6870
6756
|
http.withCredentials = true;
|
6871
6757
|
http.send(ObjectUtils.objectToString(payloadJson));
|
6872
|
-
http.onreadystatechange = () => {
|
6758
|
+
http.onreadystatechange = async () => {
|
6873
6759
|
var _a;
|
6874
6760
|
if (http.readyState == 4 && http.status == 200) {
|
6875
6761
|
try {
|
6876
6762
|
const jsonResp = JSON.parse(http.responseText);
|
6763
|
+
await this.processServiceBrokerClientEvents({ clientEvents: jsonResp === null || jsonResp === void 0 ? void 0 : jsonResp.clientEvents, serviceName, payloadJson, accept, reject });
|
6764
|
+
/**
|
6765
|
+
* Este trecho difere do projeto HTML5 devido à decisão de adotar uma abordagem síncrona para esta chamada. Isso é justificado pelo fato de que, no cenário em questão, a abordagem assíncrona teria impactos negativos.
|
6766
|
+
*
|
6767
|
+
* Descrição do caso de uso:
|
6768
|
+
* Ao concluir um recebimento com cartão (Movimentação Financeira), é acionado um EzDialog de confirmação. Posteriormente, a PopUp de impressão é exibida, e, ao ser cancelada, gera a invocação de um novo EzDialog.
|
6769
|
+
*/
|
6770
|
+
await this.processPrinting(jsonResp);
|
6877
6771
|
if (this.isServiceBrokerError(jsonResp)) {
|
6878
6772
|
reject(this.processServiceBrokerErrorInfo(jsonResp));
|
6879
6773
|
}
|
@@ -6886,8 +6780,6 @@ class DataFetcher {
|
|
6886
6780
|
(_a = this.application) === null || _a === void 0 ? void 0 : _a.info(jsonResp.statusMessage);
|
6887
6781
|
}
|
6888
6782
|
}
|
6889
|
-
this.proccessServiceBorkerClientEvents(jsonResp === null || jsonResp === void 0 ? void 0 : jsonResp.clientEvents, serviceName, payloadJson, accept, reject);
|
6890
|
-
this.processPrinting(jsonResp);
|
6891
6783
|
}
|
6892
6784
|
catch (err) {
|
6893
6785
|
console.warn(`Erro ao executar serviço: ${err}`);
|
@@ -6925,42 +6817,43 @@ class DataFetcher {
|
|
6925
6817
|
getQueryTemplate(re) {
|
6926
6818
|
return (re.query || "").replaceAll("$queryAlias$", re.queryID);
|
6927
6819
|
}
|
6928
|
-
getWatingRequest(reqID) {
|
6929
|
-
return this.watingRequestsById.get(reqID);
|
6930
|
-
}
|
6931
6820
|
pause() {
|
6932
6821
|
this.ready = false;
|
6933
6822
|
}
|
6934
6823
|
async resume() {
|
6935
6824
|
this.ready = true;
|
6936
6825
|
if (this.watingRequestsById.size > 0) {
|
6937
|
-
const
|
6938
|
-
this.watingRequestsById
|
6939
|
-
|
6940
|
-
|
6941
|
-
|
6942
|
-
|
6943
|
-
|
6944
|
-
|
6945
|
-
|
6946
|
-
|
6947
|
-
|
6948
|
-
|
6949
|
-
|
6950
|
-
|
6951
|
-
|
6952
|
-
|
6953
|
-
|
6826
|
+
const waitinRequests = this.watingRequestsById;
|
6827
|
+
this.watingRequestsById = new Map();
|
6828
|
+
this.executePendingRequest(waitinRequests);
|
6829
|
+
}
|
6830
|
+
}
|
6831
|
+
async executePendingRequest(watingRequestsById) {
|
6832
|
+
const requestsBatch = [];
|
6833
|
+
watingRequestsById.forEach(async (waitingReq) => {
|
6834
|
+
let query = this.getQueryTemplate(waitingReq.request);
|
6835
|
+
requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
|
6836
|
+
});
|
6837
|
+
let res = undefined;
|
6838
|
+
let dataResponse = [];
|
6839
|
+
let errorsResponse = [];
|
6840
|
+
res = await this.fecthGrapql(requestsBatch);
|
6841
|
+
dataResponse = res.data;
|
6842
|
+
errorsResponse = res.errors;
|
6843
|
+
//Reject promises with errors from query
|
6844
|
+
errorsResponse.forEach((errorResponse) => {
|
6845
|
+
Object.entries(errorResponse).forEach(([_key, val]) => {
|
6846
|
+
var _a;
|
6847
|
+
(((_a = watingRequestsById.get(val.request.variables[val.index].queryID)) === null || _a === void 0 ? void 0 : _a.reject) || Promise.reject)(new ErrorException("Falha detectada", val.message));
|
6954
6848
|
});
|
6955
|
-
|
6956
|
-
|
6957
|
-
|
6958
|
-
|
6959
|
-
|
6960
|
-
|
6849
|
+
});
|
6850
|
+
//Resolve promises with data from query
|
6851
|
+
dataResponse.forEach((data) => {
|
6852
|
+
Object.entries(data).forEach(([key, val]) => {
|
6853
|
+
var _a;
|
6854
|
+
(((_a = watingRequestsById.get(key)) === null || _a === void 0 ? void 0 : _a.resolve) || Promise.resolve)(val);
|
6961
6855
|
});
|
6962
|
-
|
6963
|
-
}
|
6856
|
+
});
|
6964
6857
|
}
|
6965
6858
|
async fecthGrapql(request) {
|
6966
6859
|
let res = undefined;
|
@@ -7079,4 +6972,4 @@ class WaitingRequest {
|
|
7079
6972
|
}
|
7080
6973
|
}
|
7081
6974
|
|
7082
|
-
export { DataFetcher as D,
|
6975
|
+
export { DataFetcher as D, UrlUtils as U, dist as d };
|
@@ -0,0 +1,213 @@
|
|
1
|
+
import { ApplicationContext, StringUtils } from '@sankhyalabs/core';
|
2
|
+
|
3
|
+
class PrintUtils {
|
4
|
+
constructor() {
|
5
|
+
this.appletImpressao = new AppletImpressao();
|
6
|
+
const application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
|
7
|
+
application.getDataFetcher().then(result => this.DataFetcher = result);
|
8
|
+
}
|
9
|
+
static getInstance() {
|
10
|
+
if (!PrintUtils.instance) {
|
11
|
+
PrintUtils.instance = new PrintUtils();
|
12
|
+
}
|
13
|
+
return PrintUtils.instance;
|
14
|
+
}
|
15
|
+
async processPendingPrinting(transactionId) {
|
16
|
+
await this.findPendingPrints(transactionId);
|
17
|
+
}
|
18
|
+
async findPendingPrints(transactionId) {
|
19
|
+
const requestBody = {
|
20
|
+
transactionIds: [
|
21
|
+
{
|
22
|
+
transactionId: {
|
23
|
+
$: transactionId
|
24
|
+
}
|
25
|
+
}
|
26
|
+
]
|
27
|
+
};
|
28
|
+
Promise.resolve(this.DataFetcher).then(async (res) => {
|
29
|
+
res = await Promise.resolve(this.DataFetcher);
|
30
|
+
while (!res || !res.application) {
|
31
|
+
res = await Promise.resolve(this.DataFetcher);
|
32
|
+
}
|
33
|
+
const response = await res.application.callServiceBroker(PrintUtils.SERVICE_FIND_PENDING_PRINTS, JSON.stringify(requestBody));
|
34
|
+
const printJobData = this.parsePrintData(response);
|
35
|
+
const pendingPrints = await this.processDirectPrint(printJobData);
|
36
|
+
if (!pendingPrints.length)
|
37
|
+
return;
|
38
|
+
this.openSnkPrintSelector(Object.assign(Object.assign({}, printJobData), { pendingPrinters: pendingPrints }));
|
39
|
+
});
|
40
|
+
}
|
41
|
+
getLocalPrinters() {
|
42
|
+
const localPrinters = this.appletImpressao.findLocalPrinters();
|
43
|
+
const printers = [];
|
44
|
+
for (const printerName of localPrinters) {
|
45
|
+
printers.push({
|
46
|
+
nome: printerName,
|
47
|
+
printerUri: PrintUtils.LOCAL_SERVER_URI + printerName,
|
48
|
+
isLocal: true
|
49
|
+
});
|
50
|
+
}
|
51
|
+
return printers;
|
52
|
+
}
|
53
|
+
parsePrintData(payload) {
|
54
|
+
const pendingPrintJobData = payload.pendindPrintJobData;
|
55
|
+
if (!pendingPrintJobData)
|
56
|
+
return undefined;
|
57
|
+
let { printServers: { printServer }, pendingPrinters: { pendingPrinter } } = pendingPrintJobData;
|
58
|
+
printServer = printServer ? (Array.isArray(printServer) ? printServer : [printServer]) : [];
|
59
|
+
pendingPrinter = pendingPrinter ? (Array.isArray(pendingPrinter) ? pendingPrinter : [pendingPrinter]) : [];
|
60
|
+
const normalizedPrintServer = printServer.map(item => {
|
61
|
+
const printerList = Array.isArray(item.printerLocation) ? item.printerLocation : [item.printerLocation];
|
62
|
+
return {
|
63
|
+
printServerUri: item.printServerUri,
|
64
|
+
printerList: printerList.map(this.normalize)
|
65
|
+
};
|
66
|
+
});
|
67
|
+
const normalizedPendingPrinter = pendingPrinter.map(this.normalize);
|
68
|
+
return {
|
69
|
+
transactionId: pendingPrintJobData.transactionId.$,
|
70
|
+
printServers: normalizedPrintServer,
|
71
|
+
pendingPrinters: normalizedPendingPrinter,
|
72
|
+
printServerActive: pendingPrintJobData.printServers.printServerActive === 'true'
|
73
|
+
};
|
74
|
+
}
|
75
|
+
normalize(object) {
|
76
|
+
const normalizedObject = {};
|
77
|
+
Object.keys(object).forEach((key) => {
|
78
|
+
normalizedObject[key] = PrintUtils.ENCODED_PROPERTIES.includes(key) ? window.atob(object[key].$) : object[key].$;
|
79
|
+
});
|
80
|
+
return normalizedObject;
|
81
|
+
}
|
82
|
+
processLocalPrinting(localPrintings) {
|
83
|
+
const transactionIds = localPrintings.map((item) => item.transactionId);
|
84
|
+
this.appletImpressao.doLocalPrinting(transactionIds.join());
|
85
|
+
}
|
86
|
+
async openSnkPrintSelector(printJobData) {
|
87
|
+
let printSelector = document.querySelector('snk-print-selector');
|
88
|
+
if (!printSelector) {
|
89
|
+
printSelector = document.createElement('snk-print-selector');
|
90
|
+
printSelector.setAttribute('id', StringUtils.generateUUID());
|
91
|
+
window.document.body.appendChild(printSelector);
|
92
|
+
}
|
93
|
+
const { selectedPrinter, saveSubstitute } = await printSelector.openPrintSelector(printJobData);
|
94
|
+
if (!selectedPrinter)
|
95
|
+
return;
|
96
|
+
const params = {
|
97
|
+
transactionId: printJobData.transactionId,
|
98
|
+
pendingPrinters: printJobData.pendingPrinters,
|
99
|
+
printerUri: selectedPrinter.printerUri,
|
100
|
+
saveSubstitutePrinters: saveSubstitute
|
101
|
+
};
|
102
|
+
await this.saveSubstitutePrinter(params);
|
103
|
+
}
|
104
|
+
async saveSubstitutePrinter(params) {
|
105
|
+
const { transactionId, pendingPrinters, printerUri, saveSubstitutePrinters = false } = params;
|
106
|
+
const parsedPendingPrinters = pendingPrinters.map((item) => ({
|
107
|
+
printerUri: {
|
108
|
+
$: item.printerUri || printerUri
|
109
|
+
},
|
110
|
+
originalPrinterName: {
|
111
|
+
$: item.originalPrinterName
|
112
|
+
},
|
113
|
+
printJobCount: {
|
114
|
+
$: item.printJobCount
|
115
|
+
},
|
116
|
+
docType: {
|
117
|
+
$: item.docType
|
118
|
+
},
|
119
|
+
docTypeDescription: {
|
120
|
+
$: item.docTypeDescription
|
121
|
+
}
|
122
|
+
}));
|
123
|
+
const requestBody = {
|
124
|
+
substitutePrintersRequest: {
|
125
|
+
substitutePrinters: {
|
126
|
+
pendingPrinter: parsedPendingPrinters
|
127
|
+
},
|
128
|
+
saveSubstitutePrinters: {
|
129
|
+
$: saveSubstitutePrinters.toString()
|
130
|
+
},
|
131
|
+
transactionId: {
|
132
|
+
$: transactionId
|
133
|
+
}
|
134
|
+
}
|
135
|
+
};
|
136
|
+
Promise.resolve(this.DataFetcher).then(async (res) => {
|
137
|
+
await res.application.callServiceBroker(PrintUtils.SERVICE_SAVE_SUBSTITUTE_PRINTER, JSON.stringify(requestBody));
|
138
|
+
});
|
139
|
+
}
|
140
|
+
async processDirectPrint(printJobData) {
|
141
|
+
const isWCRunning = this.appletImpressao.checkWebConnection();
|
142
|
+
if (!isWCRunning) {
|
143
|
+
return [];
|
144
|
+
}
|
145
|
+
const localPrinters = this.getLocalPrinters();
|
146
|
+
if (!localPrinters.length)
|
147
|
+
return [];
|
148
|
+
const directPendingPrints = [];
|
149
|
+
const pendingPrints = printJobData.pendingPrinters.filter(item => {
|
150
|
+
const defaultPrinterName = this.getDefaultPrinterName(item.originalPrinterName);
|
151
|
+
const isDirectPrint = !!localPrinters.find(localPrinter => localPrinter.nome === defaultPrinterName) || this.isPrinterNameAFile(defaultPrinterName);
|
152
|
+
if (isDirectPrint) {
|
153
|
+
directPendingPrints.push(Object.assign(Object.assign({}, item), { printerUri: PrintUtils.LOCAL_SERVER_URI + defaultPrinterName }));
|
154
|
+
return false;
|
155
|
+
}
|
156
|
+
return true;
|
157
|
+
});
|
158
|
+
if (!directPendingPrints.length)
|
159
|
+
return pendingPrints;
|
160
|
+
const params = {
|
161
|
+
transactionId: printJobData.transactionId,
|
162
|
+
pendingPrinters: directPendingPrints
|
163
|
+
};
|
164
|
+
await this.saveSubstitutePrinter(params);
|
165
|
+
return pendingPrints;
|
166
|
+
}
|
167
|
+
getDefaultPrinterName(printerName) {
|
168
|
+
const defaultPrinterName = this.appletImpressao.getDefaultPrinter();
|
169
|
+
const isDefaultPrinterName = /padr[aã]o/ig.test(printerName);
|
170
|
+
return (defaultPrinterName && isDefaultPrinterName) ? defaultPrinterName : printerName;
|
171
|
+
}
|
172
|
+
isPrinterNameAFile(printerName) {
|
173
|
+
const regExp = new RegExp("^(\w:)?[/\\\w\s]+?\.\w{3}$", "mis");
|
174
|
+
return regExp.test(printerName);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
PrintUtils.SERVICE_FIND_PENDING_PRINTS = 'mge@PrintServiceSP.findPendingPrinters';
|
178
|
+
PrintUtils.SERVICE_SAVE_SUBSTITUTE_PRINTER = 'mge@PrintServiceSP.saveSubstitutePrinter';
|
179
|
+
PrintUtils.LOCAL_SERVER_URI = 'LOCAL:0/';
|
180
|
+
PrintUtils.ENCODED_PROPERTIES = ['printerName', 'printerUri'];
|
181
|
+
class AppletImpressao {
|
182
|
+
constructor() {
|
183
|
+
this.appletImpressao = document.getElementById('centralNotaAppletImpressao');
|
184
|
+
}
|
185
|
+
checkWebConnection() {
|
186
|
+
if (!this.appletImpressao)
|
187
|
+
return false;
|
188
|
+
if (!this.appletImpressao.testRunningWC)
|
189
|
+
return false;
|
190
|
+
const isRunning = this.appletImpressao.testRunningWC();
|
191
|
+
return !!isRunning;
|
192
|
+
}
|
193
|
+
findLocalPrinters() {
|
194
|
+
if (!this.appletImpressao)
|
195
|
+
return [];
|
196
|
+
const localPrinters = this.appletImpressao.getLocalPrinters();
|
197
|
+
if (!localPrinters)
|
198
|
+
return [];
|
199
|
+
return localPrinters.split(",");
|
200
|
+
}
|
201
|
+
doLocalPrinting(transactionIds) {
|
202
|
+
if (!this.appletImpressao)
|
203
|
+
return;
|
204
|
+
this.appletImpressao.doLocalPrinting(transactionIds);
|
205
|
+
}
|
206
|
+
getDefaultPrinter() {
|
207
|
+
if (!this.appletImpressao)
|
208
|
+
return '';
|
209
|
+
return this.appletImpressao.getPrintDefault();
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
export { PrintUtils as P };
|