@dataclouder/ngx-core 0.2.2 → 0.2.3

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, Component, Injectable, inject, ChangeDetectionStrategy, output, Input, HostListener, ChangeDetectorRef, signal, Pipe, effect, ViewChild, Directive, InjectionToken, computed, Optional, Inject } from '@angular/core';
2
+ import { input, Component, Injectable, inject, ChangeDetectionStrategy, output, Input, HostListener, ChangeDetectorRef, signal, Pipe, effect, ViewChild, Directive, InjectionToken, computed, untracked, Optional, Inject } from '@angular/core';
3
3
  import * as i1 from '@angular/forms';
4
4
  import { FormBuilder, FormsModule, ReactiveFormsModule, FormControl, ControlContainer, FormGroup, FormArray } from '@angular/forms';
5
5
  import * as i2 from 'primeng/button';
@@ -1315,6 +1315,8 @@ class EntityBaseListComponent extends PaginationBase {
1315
1315
  });
1316
1316
  }
1317
1317
  async ngOnInit() {
1318
+ this.entityCommunicationService.currentMode.set('list');
1319
+ this.entityCommunicationService.currentEntity.set(undefined);
1318
1320
  await this.loadData();
1319
1321
  }
1320
1322
  async loadData() {
@@ -1425,6 +1427,8 @@ class EntityBaseListV2Component extends PaginationBase {
1425
1427
  // Initialize mongoState from PaginationBase defaults if needed
1426
1428
  this.mongoState.options.limit = this.rows();
1427
1429
  this.mongoState.options.skip = this.first();
1430
+ this.entityCommunicationService.currentMode.set('list');
1431
+ this.entityCommunicationService.currentEntity.set(undefined);
1428
1432
  await this.loadData();
1429
1433
  }
1430
1434
  async loadData() {
@@ -1618,6 +1622,10 @@ class EntityBaseFormComponent {
1618
1622
  this.entityId = computed(() => this.id() ?? this.entityIdFromUrl(), ...(ngDevMode ? [{ debugName: "entityId" }] : /* istanbul ignore next */ []));
1619
1623
  this.useFakeSave = input(false, ...(ngDevMode ? [{ debugName: "useFakeSave" }] : /* istanbul ignore next */ [])); // dont actually save if the father component that is in charge of save.
1620
1624
  this.fakeSaved = output();
1625
+ this._stateSyncEffect = effect(() => {
1626
+ untracked(() => this.entityCommunicationService.currentMode.set('form'));
1627
+ this.entityCommunicationService.currentEntity.set(this.entity());
1628
+ }, { ...(ngDevMode ? { debugName: "_stateSyncEffect" } : /* istanbul ignore next */ {}), allowSignalWrites: true });
1621
1629
  this.loadEntityEffect = effect(() => {
1622
1630
  const entityFromInput = this.entityInput();
1623
1631
  if (entityFromInput) {
@@ -1719,6 +1727,56 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
1719
1727
  type: Directive
1720
1728
  }], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], entityInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "entity", required: false }] }], useFakeSave: [{ type: i0.Input, args: [{ isSignal: true, alias: "useFakeSave", required: false }] }], fakeSaved: [{ type: i0.Output, args: ["fakeSaved"] }] } });
1721
1729
 
1730
+ class EntityBaseDetailComponent {
1731
+ constructor() {
1732
+ this.route = inject(ActivatedRoute);
1733
+ this.toastService = inject(TOAST_ALERTS_TOKEN, { optional: true });
1734
+ this.id = input(...(ngDevMode ? [undefined, { debugName: "id" }] : /* istanbul ignore next */ []));
1735
+ this.entity = signal(undefined, ...(ngDevMode ? [{ debugName: "entity" }] : /* istanbul ignore next */ []));
1736
+ this.isLoading = signal(false, ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
1737
+ this.entityIdFromUrl = toSignal(this.route.paramMap.pipe(map((params) => params.get('id') ?? undefined)));
1738
+ this.entityId = computed(() => this.id() ?? this.entityIdFromUrl(), ...(ngDevMode ? [{ debugName: "entityId" }] : /* istanbul ignore next */ []));
1739
+ this._loadEffect = effect(() => {
1740
+ const id = this.entityId();
1741
+ untracked(() => this.entityCommunicationService.currentMode.set('detail'));
1742
+ if (id) {
1743
+ this.loadEntity(id);
1744
+ }
1745
+ }, { ...(ngDevMode ? { debugName: "_loadEffect" } : /* istanbul ignore next */ {}), allowSignalWrites: true });
1746
+ }
1747
+ /** Called after the entity is successfully loaded. Override to react (e.g. load related data). */
1748
+ onEntityLoaded(_entity) { }
1749
+ async loadEntity(id) {
1750
+ try {
1751
+ this.isLoading.set(true);
1752
+ const loaded = await this.entityCommunicationService.findOne(id);
1753
+ if (loaded) {
1754
+ this.entity.set(loaded);
1755
+ this.entityCommunicationService.currentEntity.set(loaded);
1756
+ this.onEntityLoaded(loaded);
1757
+ }
1758
+ }
1759
+ catch (err) {
1760
+ this.toastService?.error({ title: 'Error', subtitle: 'Error loading entity' });
1761
+ console.error('Error loading entity', err);
1762
+ }
1763
+ finally {
1764
+ this.isLoading.set(false);
1765
+ }
1766
+ }
1767
+ reload() {
1768
+ const id = this.entityId();
1769
+ if (id) {
1770
+ this.loadEntity(id);
1771
+ }
1772
+ }
1773
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: EntityBaseDetailComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1774
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.5", type: EntityBaseDetailComponent, isStandalone: true, inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
1775
+ }
1776
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: EntityBaseDetailComponent, decorators: [{
1777
+ type: Directive
1778
+ }], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }] } });
1779
+
1722
1780
  var EModelQuality;
1723
1781
  (function (EModelQuality) {
1724
1782
  EModelQuality["FAST"] = "fast";
@@ -3196,7 +3254,6 @@ class HttpCoreService {
3196
3254
  }
3197
3255
  async deleteHttp({ service, host }) {
3198
3256
  this.isLoading.set(true);
3199
- debugger;
3200
3257
  try {
3201
3258
  const url = this.getHostUrl(host) + '/' + service;
3202
3259
  const response$ = this.httpClient.delete(url).pipe(catchError(this.handleRequestError.bind(this)));
@@ -3537,6 +3594,9 @@ class HttpCoreService {
3537
3594
  const subtitle = appException?.explanation || 'Please try again later';
3538
3595
  this.toastService.error({ title: errorMessage, subtitle });
3539
3596
  }
3597
+ else if (error.status === 0) {
3598
+ this.toastService.error({ title: 'No server connection', subtitle: 'Please check your network and try again, or verify that the server is running at ' + error?.url });
3599
+ }
3540
3600
  // Set the last error, not sure if this is still neeed, to keep track of the last error.
3541
3601
  if (appException) {
3542
3602
  this.lastError.set({
@@ -3548,8 +3608,8 @@ class HttpCoreService {
3548
3608
  }
3549
3609
  else {
3550
3610
  this.lastError.set({
3551
- error_message: error.message || 'An error occurred',
3552
- explanation: 'Please try again later',
3611
+ error_message: error.status === 0 ? 'No server connection' : error.message || 'An error occurred',
3612
+ explanation: error.status === 0 ? 'Please check your network and try again.' : 'Please try again later',
3553
3613
  status: error.status,
3554
3614
  });
3555
3615
  }
@@ -3658,6 +3718,8 @@ class EntityCommunicationService {
3658
3718
  constructor(serviceName) {
3659
3719
  this.serviceName = serviceName;
3660
3720
  this.httpService = inject(HttpCoreService);
3721
+ this.currentEntity = signal(undefined, ...(ngDevMode ? [{ debugName: "currentEntity" }] : /* istanbul ignore next */ []));
3722
+ this.currentMode = signal(undefined, ...(ngDevMode ? [{ debugName: "currentMode" }] : /* istanbul ignore next */ []));
3661
3723
  // this.customHost = customHost;
3662
3724
  }
3663
3725
  findAll(query = {}) {
@@ -4071,5 +4133,5 @@ const CharacterEventActions = [
4071
4133
  * Generated bundle index. Do not edit.
4072
4134
  */
4073
4135
 
4074
- export { APP_CONFIG, AppConfigService, AudioNotificationService, AudioSpeed, AudioSpeedReverse, CharacterEventActions, ChatUserSettings, ConfirmComponent, ConfirmService, DCFilterBarComponent, DCProgressToastComponent, DcAuditableViewerComponent, DcExtensionsViewerComponent, DcLearnableFormComponent, DcLearnableViewerComponent, DcManageableFormComponent, DcManageableViewerComponent, DcReactionsViewerComponent, DcTagsFormComponent, EModelQuality, EmptyStateComponent, EntityBaseFormComponent, EntityBaseListComponent, EntityBaseListV2Component, EntityCommunicationService, FlagPipe, FormUtilsService, GetPathPipe, HTTP_CORE_CONFIG, HttpCoreService, IAIModel, LANGUAGES, LangDescTranslation, LoadingBarComponent, LoadingBarService, MobileService, ModelQualityOptions, MoodState, MoodStateOptions, OptionValue, PaginationBase, PromptService, QuickTableComponent, SUPPORTED_LANGUAGES, TOAST_ALERTS_TOKEN, ToastAlertsAbstractService, UiStateService, availibleFilters, extractJsonFromString, formatCamelCaseString, getLangDesc, getSupportedLanguageOptions, provideToastAlert, sortOptions, sortTypes };
4136
+ export { APP_CONFIG, AppConfigService, AudioNotificationService, AudioSpeed, AudioSpeedReverse, CharacterEventActions, ChatUserSettings, ConfirmComponent, ConfirmService, DCFilterBarComponent, DCProgressToastComponent, DcAuditableViewerComponent, DcExtensionsViewerComponent, DcLearnableFormComponent, DcLearnableViewerComponent, DcManageableFormComponent, DcManageableViewerComponent, DcReactionsViewerComponent, DcTagsFormComponent, EModelQuality, EmptyStateComponent, EntityBaseDetailComponent, EntityBaseFormComponent, EntityBaseListComponent, EntityBaseListV2Component, EntityCommunicationService, FlagPipe, FormUtilsService, GetPathPipe, HTTP_CORE_CONFIG, HttpCoreService, IAIModel, LANGUAGES, LangDescTranslation, LoadingBarComponent, LoadingBarService, MobileService, ModelQualityOptions, MoodState, MoodStateOptions, OptionValue, PaginationBase, PromptService, QuickTableComponent, SUPPORTED_LANGUAGES, TOAST_ALERTS_TOKEN, ToastAlertsAbstractService, UiStateService, availibleFilters, extractJsonFromString, formatCamelCaseString, getLangDesc, getSupportedLanguageOptions, provideToastAlert, sortOptions, sortTypes };
4075
4137
  //# sourceMappingURL=dataclouder-ngx-core.mjs.map