@dataclouder/ngx-core 0.1.41 → 0.1.42

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.
@@ -1194,38 +1194,23 @@ class EntityBaseFormComponent {
1194
1194
  this.router = inject(Router);
1195
1195
  this.toastService = inject(TOAST_ALERTS_TOKEN, { optional: true });
1196
1196
  this.id = input(...(ngDevMode ? [undefined, { debugName: "id" }] : []));
1197
+ this.entityInput = input(undefined, ...(ngDevMode ? [{ debugName: "entityInput", alias: 'entity' }] : [{ alias: 'entity' }]));
1197
1198
  this.entity = signal(undefined, ...(ngDevMode ? [{ debugName: "entity" }] : []));
1198
1199
  this.entityIdFromUrl = toSignal(this.route.paramMap.pipe(map((params) => params.get('id'))));
1199
1200
  this.entityId = computed(() => this.id() ?? this.entityIdFromUrl(), ...(ngDevMode ? [{ debugName: "entityId" }] : []));
1200
- this.loadEntityEffect = effect(async () => {
1201
+ this.loadEntityEffect = effect(() => {
1202
+ const entityFromInput = this.entityInput();
1203
+ if (entityFromInput) {
1204
+ this.entity.set(entityFromInput);
1205
+ this.patchForm(entityFromInput);
1206
+ return;
1207
+ }
1201
1208
  const id = this.entityId();
1202
1209
  if (id) {
1203
- try {
1204
- const entity = await this.entityCommunicationService.findOne(id);
1205
- if (entity) {
1206
- this.entity.set(entity);
1207
- this.patchForm(entity);
1208
- }
1209
- }
1210
- catch (err) {
1211
- this.toastService?.error({ title: 'Error', subtitle: 'Error loading entity' });
1212
- console.error('Error loading entity', err);
1213
- }
1210
+ this.loadEntityById(id);
1214
1211
  }
1215
1212
  else {
1216
- // if there is no id, we create a new entity
1217
- try {
1218
- const newEntity = await this.entityCommunicationService.createOrUpdate({});
1219
- const id = newEntity?._id || newEntity?.['id'];
1220
- if (id) {
1221
- // we replace the url to avoid creating a new entity when the user goes back
1222
- this.router.navigate([id], { relativeTo: this.route, replaceUrl: true });
1223
- }
1224
- }
1225
- catch (err) {
1226
- this.toastService?.error({ title: 'Error', subtitle: 'Error creating new entity' });
1227
- console.error('Error creating new entity', err);
1228
- }
1213
+ this.createNewEntity();
1229
1214
  }
1230
1215
  }, ...(ngDevMode ? [{ debugName: "loadEntityEffect", allowSignalWrites: true }] : [{ allowSignalWrites: true }]));
1231
1216
  }
@@ -1266,8 +1251,35 @@ class EntityBaseFormComponent {
1266
1251
  const dirtyValues = this.getDirtyValues(this.form);
1267
1252
  return this.entityCommunicationService.partialUpdate(this.entityId(), dirtyValues);
1268
1253
  }
1254
+ async loadEntityById(id) {
1255
+ try {
1256
+ const entity = await this.entityCommunicationService.findOne(id);
1257
+ if (entity) {
1258
+ this.entity.set(entity);
1259
+ this.patchForm(entity);
1260
+ }
1261
+ }
1262
+ catch (err) {
1263
+ this.toastService?.error({ title: 'Error', subtitle: 'Error loading entity' });
1264
+ console.error('Error loading entity', err);
1265
+ }
1266
+ }
1267
+ async createNewEntity() {
1268
+ try {
1269
+ const newEntity = await this.entityCommunicationService.createOrUpdate({});
1270
+ const id = newEntity?._id || newEntity?.['id'];
1271
+ if (id) {
1272
+ // we replace the url to avoid creating a new entity when the user goes back
1273
+ this.router.navigate([id], { relativeTo: this.route, replaceUrl: true });
1274
+ }
1275
+ }
1276
+ catch (err) {
1277
+ this.toastService?.error({ title: 'Error', subtitle: 'Error creating new entity' });
1278
+ console.error('Error creating new entity', err);
1279
+ }
1280
+ }
1269
1281
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: EntityBaseFormComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1270
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.1.6", type: EntityBaseFormComponent, isStandalone: true, inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
1282
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.1.6", type: EntityBaseFormComponent, isStandalone: true, inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, entityInput: { classPropertyName: "entityInput", publicName: "entity", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
1271
1283
  }
1272
1284
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: EntityBaseFormComponent, decorators: [{
1273
1285
  type: Directive