@dataclouder/ngx-core 0.1.42 → 0.1.44

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.
@@ -1198,6 +1198,8 @@ class EntityBaseFormComponent {
1198
1198
  this.entity = signal(undefined, ...(ngDevMode ? [{ debugName: "entity" }] : []));
1199
1199
  this.entityIdFromUrl = toSignal(this.route.paramMap.pipe(map((params) => params.get('id'))));
1200
1200
  this.entityId = computed(() => this.id() ?? this.entityIdFromUrl(), ...(ngDevMode ? [{ debugName: "entityId" }] : []));
1201
+ this.useFakeSave = input(false, ...(ngDevMode ? [{ debugName: "useFakeSave" }] : [])); // dont actually save if the father component that is in charge of save.
1202
+ this.fakeSaved = output();
1201
1203
  this.loadEntityEffect = effect(() => {
1202
1204
  const entityFromInput = this.entityInput();
1203
1205
  if (entityFromInput) {
@@ -1209,16 +1211,23 @@ class EntityBaseFormComponent {
1209
1211
  if (id) {
1210
1212
  this.loadEntityById(id);
1211
1213
  }
1212
- else {
1214
+ else if (!this.useFakeSave()) {
1213
1215
  this.createNewEntity();
1214
1216
  }
1215
1217
  }, ...(ngDevMode ? [{ debugName: "loadEntityEffect", allowSignalWrites: true }] : [{ allowSignalWrites: true }]));
1218
+ this.defaultNewObject = {};
1216
1219
  }
1217
1220
  async save() {
1218
1221
  if (this.form.invalid) {
1219
1222
  this.toastService?.error({ title: 'Error', subtitle: 'Form is invalid' });
1223
+ return undefined;
1220
1224
  }
1221
1225
  const entityData = { ...this.form.value, _id: this.entityId() };
1226
+ if (this.useFakeSave()) {
1227
+ this.toastService?.success({ title: 'info', subtitle: 'Se emitio el evento guardado' });
1228
+ this.fakeSaved.emit(entityData);
1229
+ return entityData;
1230
+ }
1222
1231
  const result = await this.entityCommunicationService.createOrUpdate(entityData);
1223
1232
  this.toastService?.success({ title: 'Success', subtitle: 'Entity saved successfully' });
1224
1233
  this.entity.set(result);
@@ -1265,8 +1274,9 @@ class EntityBaseFormComponent {
1265
1274
  }
1266
1275
  }
1267
1276
  async createNewEntity() {
1277
+ // object is always empty, if you want a default data, set defaultNewObject
1268
1278
  try {
1269
- const newEntity = await this.entityCommunicationService.createOrUpdate({});
1279
+ const newEntity = await this.entityCommunicationService.createOrUpdate(this.defaultNewObject);
1270
1280
  const id = newEntity?._id || newEntity?.['id'];
1271
1281
  if (id) {
1272
1282
  // we replace the url to avoid creating a new entity when the user goes back
@@ -1279,7 +1289,7 @@ class EntityBaseFormComponent {
1279
1289
  }
1280
1290
  }
1281
1291
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: EntityBaseFormComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
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 }); }
1292
+ 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 }, useFakeSave: { classPropertyName: "useFakeSave", publicName: "useFakeSave", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { fakeSaved: "fakeSaved" }, ngImport: i0 }); }
1283
1293
  }
1284
1294
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: EntityBaseFormComponent, decorators: [{
1285
1295
  type: Directive