@messaia/cdk 20.2.2 → 20.2.4

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.
@@ -20008,42 +20008,63 @@ class GenericFormBaseComponent extends BaseComponent {
20008
20008
  * Loads an item by ID.
20009
20009
  * This method fetches the item if the component is in edit mode and the service endpoint is defined.
20010
20010
  *
20011
- * @param callback - A function to be called after the item has been successfully loaded.
20012
- * This function will receive the loaded item as an argument.
20013
- */
20014
- loadItem(callback) {
20011
+ * @param successCallback - A function to be called after the item has been successfully loaded.
20012
+ * This function will receive the loaded item as an argument.
20013
+ * @param errorCallback - A function to be called if an error occurs during loading.
20014
+ * This function will receive the error as an argument.
20015
+ * @param headers - Optional HTTP headers to include in the request.
20016
+ * @param handleError - Indicates whether to automatically handle and parse errors (default: true).
20017
+ * @param observeResponse - If true, the full HTTP response will be observed instead of just the body (default: false).
20018
+ */
20019
+ loadItem(successCallback, errorCallback, headers, handleError = true, observeResponse = true) {
20015
20020
  if (this.isEditMode && this.service?.endpoint) {
20016
20021
  /* Set loading state to true to indicate that an item is being loaded */
20017
20022
  this.isLoading = true;
20018
20023
  /* Trigger change detection to update the view with the loading state */
20019
20024
  this.changeDetectorRef.detectChanges();
20020
20025
  /* Call the asynchronous method to load the item */
20021
- this.loadItemAsync().subscribe({
20026
+ this.loadItemAsync(headers, handleError, observeResponse).subscribe({
20022
20027
  /* Handle the response when the item is successfully loaded */
20023
20028
  next: (item) => {
20024
20029
  /* Set loading state to false to indicate that loading has completed */
20025
20030
  this.isLoading = false;
20026
- /* Execute the callback if provided, passing the loaded item */
20027
- if (callback) {
20028
- callback(item);
20031
+ /* Execute the success callback if provided */
20032
+ if (successCallback) {
20033
+ successCallback(item);
20029
20034
  }
20030
20035
  },
20031
20036
  /* Handle any errors that occur during the loading process */
20032
- error: (error) => this.parseErrors(error)
20037
+ error: (error) => {
20038
+ /* Set loading state to false to indicate that loading has completed with error */
20039
+ this.isLoading = false;
20040
+ /* Parse the error internally */
20041
+ this.parseErrors(error);
20042
+ /* Execute the error callback if provided */
20043
+ if (errorCallback) {
20044
+ errorCallback(error);
20045
+ }
20046
+ }
20033
20047
  });
20034
20048
  }
20035
20049
  }
20036
20050
  /**
20037
20051
  * Loads an item by ID asynchronously.
20052
+ *
20053
+ * @param headers - Optional HTTP headers to include in the request.
20054
+ * @param handleError - Indicates whether to automatically handle and parse errors (default: true).
20055
+ * @param observeResponse - If true, the full HTTP response will be observed instead of just the body (default: false).
20038
20056
  * @returns An Observable of the loaded entity.
20039
20057
  */
20040
- loadItemAsync() {
20058
+ loadItemAsync(headers, handleError = true, observeResponse = true) {
20041
20059
  if (this.id) {
20060
+ /* Merge provided headers with default 'Disable-Cache' header */
20061
+ const mergedHeaders = Object.assign({ 'Disable-Cache': 'Yes' }, headers || {});
20062
+ /* Perform the GET request to load the entity */
20042
20063
  return this.service.get(this.id, Object.assign(this.query || {}, {
20043
20064
  includes: this.includes?.length ? this.includes : this.updateIncludes,
20044
20065
  projection: this.projection?.join(','),
20045
20066
  observe: 'response'
20046
- }), { 'Disable-Cache': 'Yes' }, true, true).pipe(map((response) => {
20067
+ }), mergedHeaders, handleError, observeResponse).pipe(map((response) => {
20047
20068
  /* Read permissions from the http headers */
20048
20069
  const permissions = response?.headers?.get('Permissions')?.split(';') ?? [];
20049
20070
  return {
@@ -20850,7 +20871,7 @@ class BaseInterceptor {
20850
20871
  event => {
20851
20872
  if (event instanceof HttpResponse) {
20852
20873
  /* Check for specific headers in the response */
20853
- if (req.headers.get('Show-Message')) {
20874
+ if (req.headers.get('Show-Message')?.trim().toLowerCase() == 'yes') {
20854
20875
  /* Show success messages for different types of requests */
20855
20876
  if (req.method == 'POST') {
20856
20877
  this.snackBar.open($localize `:@@snackbar.send.success:Data sent successfully.`, undefined, {
@@ -20885,6 +20906,10 @@ class BaseInterceptor {
20885
20906
  },
20886
20907
  /* Handle errors */
20887
20908
  error => {
20909
+ /* Check if the 'Show-Message' header is set to 'yes' */
20910
+ if (req.headers.get('Show-Message')?.trim().toLowerCase() != 'yes') {
20911
+ return;
20912
+ }
20888
20913
  /* Handle validation errors for status code 400 (Bad Request) */
20889
20914
  if (error.status == 400) {
20890
20915
  let message = this.parseErrors(error.error);