@dataclouder/ngx-core 0.1.41 → 0.1.43
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,46 +1194,39 @@ 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.
|
|
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();
|
|
1203
|
+
this.loadEntityEffect = effect(() => {
|
|
1204
|
+
const entityFromInput = this.entityInput();
|
|
1205
|
+
if (entityFromInput) {
|
|
1206
|
+
this.entity.set(entityFromInput);
|
|
1207
|
+
this.patchForm(entityFromInput);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1201
1210
|
const id = this.entityId();
|
|
1202
1211
|
if (id) {
|
|
1203
|
-
|
|
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
|
-
}
|
|
1212
|
+
this.loadEntityById(id);
|
|
1214
1213
|
}
|
|
1215
|
-
else {
|
|
1216
|
-
|
|
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
|
-
}
|
|
1214
|
+
else if (!this.useFakeSave()) {
|
|
1215
|
+
this.createNewEntity();
|
|
1229
1216
|
}
|
|
1230
1217
|
}, ...(ngDevMode ? [{ debugName: "loadEntityEffect", allowSignalWrites: true }] : [{ allowSignalWrites: true }]));
|
|
1231
1218
|
}
|
|
1232
1219
|
async save() {
|
|
1233
1220
|
if (this.form.invalid) {
|
|
1234
1221
|
this.toastService?.error({ title: 'Error', subtitle: 'Form is invalid' });
|
|
1222
|
+
return undefined;
|
|
1235
1223
|
}
|
|
1236
1224
|
const entityData = { ...this.form.value, _id: this.entityId() };
|
|
1225
|
+
if (this.useFakeSave()) {
|
|
1226
|
+
this.toastService?.success({ title: 'info', subtitle: 'Se emitio el evento guardado' });
|
|
1227
|
+
this.fakeSaved.emit(entityData);
|
|
1228
|
+
return entityData;
|
|
1229
|
+
}
|
|
1237
1230
|
const result = await this.entityCommunicationService.createOrUpdate(entityData);
|
|
1238
1231
|
this.toastService?.success({ title: 'Success', subtitle: 'Entity saved successfully' });
|
|
1239
1232
|
this.entity.set(result);
|
|
@@ -1266,8 +1259,35 @@ class EntityBaseFormComponent {
|
|
|
1266
1259
|
const dirtyValues = this.getDirtyValues(this.form);
|
|
1267
1260
|
return this.entityCommunicationService.partialUpdate(this.entityId(), dirtyValues);
|
|
1268
1261
|
}
|
|
1262
|
+
async loadEntityById(id) {
|
|
1263
|
+
try {
|
|
1264
|
+
const entity = await this.entityCommunicationService.findOne(id);
|
|
1265
|
+
if (entity) {
|
|
1266
|
+
this.entity.set(entity);
|
|
1267
|
+
this.patchForm(entity);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
catch (err) {
|
|
1271
|
+
this.toastService?.error({ title: 'Error', subtitle: 'Error loading entity' });
|
|
1272
|
+
console.error('Error loading entity', err);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
async createNewEntity() {
|
|
1276
|
+
try {
|
|
1277
|
+
const newEntity = await this.entityCommunicationService.createOrUpdate({});
|
|
1278
|
+
const id = newEntity?._id || newEntity?.['id'];
|
|
1279
|
+
if (id) {
|
|
1280
|
+
// we replace the url to avoid creating a new entity when the user goes back
|
|
1281
|
+
this.router.navigate([id], { relativeTo: this.route, replaceUrl: true });
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
catch (err) {
|
|
1285
|
+
this.toastService?.error({ title: 'Error', subtitle: 'Error creating new entity' });
|
|
1286
|
+
console.error('Error creating new entity', err);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1269
1289
|
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 }); }
|
|
1290
|
+
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 }); }
|
|
1271
1291
|
}
|
|
1272
1292
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: EntityBaseFormComponent, decorators: [{
|
|
1273
1293
|
type: Directive
|