asab_webui_shell 27.2.6 → 27.2.7

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.
@@ -75,10 +75,14 @@ class Application extends _react.Component {
75
75
  // This is important to preserve 64bit numbers from the server such as IP addresses, timestamps etc.
76
76
  this.JSONParseBigInt = new Set(props === null || props === void 0 ? void 0 : props.bigint);
77
77
  this._handleKeyUp = this._handleKeyUp.bind(this);
78
+ // Clear print-ready timeout handler
79
+ this._clearPrintReadyTimeout = this._clearPrintReadyTimeout.bind(this);
80
+ this._printReadyTimeout = null;
78
81
  this.state = {
79
82
  networking: 0,
80
83
  // If more than zero, some networking activity is happening
81
- splashscreenRequestors: 0
84
+ splashscreenRequestors: 0,
85
+ printReadyIndicators: 1 // Initial value is set to 1, because we start the application with Splashscreen. When the Splashscreen is removed, the value is extracted. If value is more than zero, some print-ready activity is happening
82
86
  };
83
87
 
84
88
  // Subscribe and unsubscribe handlers for connectivity detection
@@ -254,6 +258,7 @@ class Application extends _react.Component {
254
258
  if (!networkingIndicatorOff) {
255
259
  that.pushNetworkingIndicator();
256
260
  }
261
+ that.pushPrintReadyIndicator();
257
262
  // Remove the X-Networking-Indicator header before sending to service (its only for internal use)
258
263
  config === null || config === void 0 || (_config$headers2 = config.headers) === null || _config$headers2 === void 0 || delete _config$headers2['X-Networking-Indicator'];
259
264
  config.headers['X-App'] = "webui"; // Include X-App header in every axios API request
@@ -270,7 +275,7 @@ class Application extends _react.Component {
270
275
  if (!response.config._networkingIndicatorOff) {
271
276
  that.popNetworkingIndicator();
272
277
  }
273
-
278
+ that.popPrintReadyIndicator();
274
279
  /*
275
280
  Custom flag to control JSON parsing for specific requests.
276
281
  If 'skipJsonParsing' is set to true in the request config,
@@ -314,6 +319,7 @@ class Application extends _react.Component {
314
319
  if (!((_error$config = error.config) !== null && _error$config !== void 0 && _error$config._networkingIndicatorOff)) {
315
320
  that.popNetworkingIndicator();
316
321
  }
322
+ that.popPrintReadyIndicator();
317
323
  var contentType = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.headers) === null || _error$response === void 0 ? void 0 : _error$response['content-type'];
318
324
  // Check if the response content type is 'application/json' and data is a string
319
325
  if (contentType !== null && contentType !== void 0 && contentType.startsWith('application/json') && typeof (error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) === 'string') {
@@ -416,6 +422,24 @@ class Application extends _react.Component {
416
422
  networking: prevState.networking - 1
417
423
  }));
418
424
  }
425
+
426
+ // Display and hide print-ready indication
427
+ pushPrintReadyIndicator() {
428
+ this.setState(prevState => ({
429
+ printReadyIndicators: prevState.printReadyIndicators + 1
430
+ }));
431
+ }
432
+ popPrintReadyIndicator() {
433
+ this.setState(prevState => {
434
+ var nextValue = prevState.printReadyIndicators - 1;
435
+ if (nextValue < 0) {
436
+ console.warn('printReadyIndicators would go negative, setting its value to 0. The value was:', nextValue);
437
+ }
438
+ return {
439
+ printReadyIndicators: Math.max(nextValue, 0)
440
+ };
441
+ });
442
+ }
419
443
  registerService(service) {
420
444
  if (service.Name in this.Services) {
421
445
  console.warn("Service ".concat(service.Name, " is already registered."));
@@ -448,12 +472,30 @@ class Application extends _react.Component {
448
472
 
449
473
  // Subscribe to Application.status! once PubSub is available
450
474
  this._initConnectivitySubscription();
451
-
452
475
  // Add print-landscape class to body if not present
453
476
  if (!document.body.classList.contains('print-landscape')) {
454
477
  document.body.classList.add('print-landscape');
455
478
  }
456
479
  }
480
+ componentDidUpdate(prevProps, prevState) {
481
+ if (prevState.printReadyIndicators === this.state.printReadyIndicators) {
482
+ return;
483
+ }
484
+
485
+ // Setting a print-ready attribute to the body of the application element
486
+ if (this.state.printReadyIndicators === 0) {
487
+ this._clearPrintReadyTimeout();
488
+ this._printReadyTimeout = setTimeout(() => {
489
+ if (this.state.printReadyIndicators === 0) {
490
+ document.body.setAttribute('print-ready', 'true');
491
+ this._printReadyTimeout = null;
492
+ }
493
+ }, 500); // Add 500ms delay to ensure that the print-ready attribute is set after the last print-ready indicator is popped
494
+ } else {
495
+ this._clearPrintReadyTimeout();
496
+ document.body.setAttribute('print-ready', 'false');
497
+ }
498
+ }
457
499
  componentWillUnmount() {
458
500
  document.removeEventListener("keyup", this._handleKeyUp, false);
459
501
 
@@ -462,11 +504,23 @@ class Application extends _react.Component {
462
504
  this._unsubscribeConnectivity();
463
505
  this._unsubscribeConnectivity = null;
464
506
  }
507
+ this._clearPrintReadyTimeout();
508
+ document.body.removeAttribute('print-ready');
509
+ }
510
+ _clearPrintReadyTimeout() {
511
+ if (this._printReadyTimeout !== null) {
512
+ clearTimeout(this._printReadyTimeout);
513
+ this._printReadyTimeout = null;
514
+ }
465
515
  }
466
516
 
467
517
  // Splash screen
468
518
 
469
519
  addSplashScreenRequestor(obj) {
520
+ /*
521
+ For print-ready, the initial value is set to 1, because we always start the application
522
+ with Splashscreen and therefore we dont need to increment the print-ready number here.
523
+ */
470
524
  var origLen = this.SplashscreenRequestors.size;
471
525
  this.SplashscreenRequestors.add(obj);
472
526
  if (origLen != this.SplashscreenRequestors.size) {
@@ -486,6 +540,8 @@ class Application extends _react.Component {
486
540
  if (this.SplashscreenRequestors.size == 0) {
487
541
  var splashscreen = document.getElementById('app-splashscreen'); // See public/index.html
488
542
  splashscreen === null || splashscreen === void 0 || splashscreen.classList.add("d-none");
543
+ // Decrement print-ready indicator value if no splash screen requestors are present
544
+ this.popPrintReadyIndicator();
489
545
  }
490
546
  }
491
547
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_shell",
3
- "version": "27.2.6",
3
+ "version": "27.2.7",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Shell Application",
6
6
  "contributors": [