@decaf-ts/for-angular 0.0.79 → 0.0.80

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.
@@ -25,7 +25,6 @@ import { addIcons } from 'ionicons';
25
25
  import * as allIcons from 'ionicons/icons';
26
26
  import { chevronUpOutline, chevronDownOutline, createOutline, trashOutline, addOutline, alertCircleOutline, arrowUpOutline, arrowDownOutline, searchOutline, closeOutline, chevronForwardOutline, chevronBackOutline, arrowBackOutline, arrowForwardOutline } from 'ionicons/icons';
27
27
  import { modalController } from '@ionic/core';
28
- import { getModelAndRepository as getModelAndRepository$1, ActionRoles as ActionRoles$1, ComponentEventNames as ComponentEventNames$1 } from 'src/lib/engine';
29
28
 
30
29
  const DB_ADAPTER_FLAVOUR_TOKEN = 'DbAdapterFlavour';
31
30
  /**
@@ -2044,7 +2043,13 @@ class NgxFormService {
2044
2043
  if (!parentProps.required) {
2045
2044
  parent.setErrors(null);
2046
2045
  parent.updateValueAndValidity({ emitEvent: true });
2047
- childControl.disable();
2046
+ const hasValue = parentProps.isMultiple &&
2047
+ Object.keys(childControl.value).some((key) => childControl.value[key] !== null &&
2048
+ childControl.value[key] !== undefined &&
2049
+ childControl.value[key] !== '');
2050
+ if (!hasValue) {
2051
+ childControl.disable();
2052
+ }
2048
2053
  }
2049
2054
  else {
2050
2055
  this.validateFields(childControl);
@@ -3668,8 +3673,21 @@ class NgxRepositoryDirective extends DecafComponent {
3668
3673
  this._data = {};
3669
3674
  }
3670
3675
  async initialize() {
3671
- if (this.repository && this.filter) {
3672
- this._data = await this.query(this.filter.eq(this.modelId));
3676
+ if (this.repository && this.modelId) {
3677
+ if (this.filter) {
3678
+ this._data = await this.query(this.filter.eq(this.modelId));
3679
+ if (this._data) {
3680
+ await this.refresh();
3681
+ }
3682
+ }
3683
+ else {
3684
+ // if (String(this.modelName) === this.model?.constructor.name) {
3685
+ // const model = await this.repository.read(this.modelId as PrimaryKeyType);
3686
+ // if (model) {
3687
+ // await this.refresh(model);
3688
+ // }
3689
+ // }
3690
+ }
3673
3691
  }
3674
3692
  }
3675
3693
  set context(context) {
@@ -3685,6 +3703,12 @@ class NgxRepositoryDirective extends DecafComponent {
3685
3703
  }
3686
3704
  return this._context;
3687
3705
  }
3706
+ async refresh(model) {
3707
+ if (model) {
3708
+ this.model = Model.build(model, this.modelName);
3709
+ this._data = model;
3710
+ }
3711
+ }
3688
3712
  buildCondition(attr) {
3689
3713
  if (!attr) {
3690
3714
  attr = (this.filterBy || this.pk);
@@ -3736,7 +3760,10 @@ class NgxRepositoryDirective extends DecafComponent {
3736
3760
  const handler = this.handlers?.[hook] || undefined;
3737
3761
  const model = this.buildTransactionModel(data || {}, repository, operation);
3738
3762
  if (handler && typeof handler === 'function') {
3739
- (await handler.bind(this)(model, repository, this.modelId));
3763
+ const result = (await handler.bind(this)(model, repository, this.modelId));
3764
+ if (result === false) {
3765
+ return undefined;
3766
+ }
3740
3767
  }
3741
3768
  return model;
3742
3769
  }
@@ -3799,11 +3826,13 @@ class NgxRepositoryDirective extends DecafComponent {
3799
3826
  return this.getModelPropertyType(clazz, Model.pk(clazz));
3800
3827
  }
3801
3828
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: NgxRepositoryDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
3802
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.16", type: NgxRepositoryDirective, isStandalone: true, inputs: { pk: "pk", filter: "filter", filterBy: "filterBy", start: "start", limit: "limit", sortDirection: "sortDirection", sortBy: "sortBy", indexes: "indexes", _data: "_data" }, usesInheritance: true, ngImport: i0 }); }
3829
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.16", type: NgxRepositoryDirective, isStandalone: true, inputs: { modelName: "modelName", pk: "pk", filter: "filter", filterBy: "filterBy", start: "start", limit: "limit", sortDirection: "sortDirection", sortBy: "sortBy", indexes: "indexes", _data: "_data" }, usesInheritance: true, ngImport: i0 }); }
3803
3830
  }
3804
3831
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: NgxRepositoryDirective, decorators: [{
3805
3832
  type: Directive
3806
- }], propDecorators: { pk: [{
3833
+ }], propDecorators: { modelName: [{
3834
+ type: Input
3835
+ }], pk: [{
3807
3836
  type: Input
3808
3837
  }], filter: [{
3809
3838
  type: Input
@@ -4745,7 +4774,7 @@ class NgxComponentDirective extends NgxRepositoryDirective {
4745
4774
  await this.initialize();
4746
4775
  }
4747
4776
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: NgxComponentDirective, deps: [{ token: CPTKN }, { token: CPTKN }], target: i0.ɵɵFactoryTarget.Directive }); }
4748
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.16", type: NgxComponentDirective, isStandalone: true, inputs: { enableDarkMode: "enableDarkMode", isDarkMode: "isDarkMode", name: "name", childOf: "childOf", uid: "uid", model: "model", modelName: "modelName", modelId: "modelId", formGroup: "formGroup", value: "value", mapper: "mapper", operations: "operations", operation: "operation", row: "row", col: "col", className: "className", translatable: "translatable", locale: "locale", item: "item", props: "props", route: "route", borders: "borders", isModalChild: "isModalChild", handlers: "handlers", events: "events", propsMapperFn: "propsMapperFn" }, outputs: { listenEvent: "listenEvent", refreshEvent: "refreshEvent" }, host: { properties: { "attr.id": "uid" } }, viewQueries: [{ propertyName: "component", first: true, predicate: ["component"], descendants: true, read: ElementRef, static: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); }
4777
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.16", type: NgxComponentDirective, isStandalone: true, inputs: { enableDarkMode: "enableDarkMode", isDarkMode: "isDarkMode", name: "name", childOf: "childOf", uid: "uid", model: "model", modelId: "modelId", formGroup: "formGroup", value: "value", mapper: "mapper", operations: "operations", operation: "operation", row: "row", col: "col", className: "className", translatable: "translatable", locale: "locale", item: "item", props: "props", route: "route", borders: "borders", isModalChild: "isModalChild", handlers: "handlers", events: "events", propsMapperFn: "propsMapperFn" }, outputs: { listenEvent: "listenEvent", refreshEvent: "refreshEvent" }, host: { properties: { "attr.id": "uid" } }, viewQueries: [{ propertyName: "component", first: true, predicate: ["component"], descendants: true, read: ElementRef, static: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); }
4749
4778
  }
4750
4779
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: NgxComponentDirective, decorators: [{
4751
4780
  type: Directive,
@@ -4771,8 +4800,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
4771
4800
  type: Input
4772
4801
  }], model: [{
4773
4802
  type: Input
4774
- }], modelName: [{
4775
- type: Input
4776
4803
  }], modelId: [{
4777
4804
  type: Input
4778
4805
  }], formGroup: [{
@@ -4844,7 +4871,7 @@ class NgxPageDirective extends NgxComponentDirective {
4844
4871
  * @param {boolean} [hasMenu=true] - Whether this page should display the menu
4845
4872
  * @memberOf module:lib/engine/NgxPageDirective
4846
4873
  */
4847
- constructor(localeRoot = "NgxPageDirective", hasMenu = true) {
4874
+ constructor(localeRoot = 'NgxPageDirective', hasMenu = true) {
4848
4875
  super(localeRoot);
4849
4876
  /**
4850
4877
  * @description Page title text for the current view.
@@ -4855,7 +4882,7 @@ class NgxPageDirective extends NgxComponentDirective {
4855
4882
  * @default ''
4856
4883
  * @memberOf module:lib/engine/NgxPageDirective
4857
4884
  */
4858
- this.title = "";
4885
+ this.title = '';
4859
4886
  /**
4860
4887
  * @description Ionic menu controller service for menu management.
4861
4888
  * @summary Injected service that provides programmatic control over Ionic menu components.
@@ -4917,7 +4944,7 @@ class NgxPageDirective extends NgxComponentDirective {
4917
4944
  async initialize() {
4918
4945
  await super.initialize();
4919
4946
  // connect component to media service for color scheme toggling
4920
- this.currentRoute = this.router.url.replace("/", "");
4947
+ this.currentRoute = this.router.url.replace('/', '');
4921
4948
  if (!this.route)
4922
4949
  this.route = this.currentRoute;
4923
4950
  this.setPageTitle(this.currentRoute);
@@ -4936,23 +4963,23 @@ class NgxPageDirective extends NgxComponentDirective {
4936
4963
  .pipe(takeUntil$1(this.destroySubscriptions$), shareReplay$1(1))
4937
4964
  .subscribe(async (event) => {
4938
4965
  if (event instanceof NavigationEnd) {
4939
- const url = (event?.url || "").replace("/", "");
4966
+ const url = (event?.url || '').replace('/', '');
4940
4967
  this.currentRoute = url;
4941
4968
  if (this.hasMenu)
4942
- this.hasMenu = url !== "login" && url !== "";
4969
+ this.hasMenu = url !== 'login' && url !== '';
4943
4970
  this.title = this.pageTitle;
4944
4971
  await this.setPageTitle(url);
4945
4972
  this.changeDetectorRef.detectChanges();
4946
4973
  }
4947
4974
  if (event instanceof NavigationStart) {
4948
- const url = (event?.url || "").replace("/", "");
4975
+ const url = (event?.url || '').replace('/', '');
4949
4976
  if (this.hasMenu)
4950
- this.hasMenu = url !== "login" && url !== "";
4977
+ this.hasMenu = url !== 'login' && url !== '';
4951
4978
  removeFocusTrap();
4952
4979
  }
4953
4980
  });
4954
4981
  if (!this.route)
4955
- this.route = this.router.url.replace("/", "");
4982
+ this.route = this.router.url.replace('/', '');
4956
4983
  await this.menuController.enable(this.hasMenu);
4957
4984
  }
4958
4985
  /**
@@ -4970,13 +4997,13 @@ class NgxPageDirective extends NgxComponentDirective {
4970
4997
  */
4971
4998
  async setPageTitle(route, menu) {
4972
4999
  if (!route)
4973
- route = this.router.url.replace("/", "");
5000
+ route = this.router.url.replace('/', '');
4974
5001
  if (!menu)
4975
5002
  menu = this.menu;
4976
5003
  const activeMenu = menu.find((item) => item?.url?.includes(route));
4977
5004
  if (activeMenu) {
4978
- const label = `${(activeMenu?.title || activeMenu?.label || "").toLowerCase()}`;
4979
- const title = `${await this.translate(label ? "menu." + label : label)} ${this.appName ? `- ${this.appName}` : ""}`;
5005
+ const label = `${(activeMenu?.title || activeMenu?.label || '').toLowerCase()}`;
5006
+ const title = `${await this.translate(label ? 'menu.' + label : label)} ${this.appName ? `- ${this.appName}` : ''}`;
4980
5007
  this.titleService.setTitle(title);
4981
5008
  if (!this.title)
4982
5009
  this.title = title;
@@ -5273,41 +5300,17 @@ class NgxModelPageDirective extends NgxPageDirective {
5273
5300
  .select()
5274
5301
  .where(Condition.attribute(this.pk).eq(uid))
5275
5302
  .execute();
5276
- const data = query?.length ? (query?.length === 1 ? query[0] : query) : undefined;
5277
5303
  if (modelName === this.modelName) {
5278
5304
  const data = query?.length ? (query?.length === 1 ? query[0] : query) : undefined;
5279
5305
  model[prop] = data;
5280
5306
  this.model = Model.build({ [prop]: data }, modelName);
5281
5307
  }
5282
5308
  else {
5283
- model[parent] = {
5284
- ...model[parent],
5285
- [prop]: data,
5286
- };
5309
+ // model[parent] = {
5310
+ // ...model[parent],
5311
+ // [prop]: data,
5312
+ // };
5287
5313
  }
5288
- // if (data) {
5289
- // if (modelName === this.modelName) {
5290
- // model[prop] = data;
5291
- // this.model = Model.build({ [prop]: data }, modelName);
5292
- // } else {
5293
- // model[parent] = {
5294
- // ...model[parent],
5295
- // [prop]: data,
5296
- // };
5297
- // }
5298
- // }
5299
- // const data = query?.length ? (query?.length === 1 ? query[0] : query) : undefined;
5300
- // if (data) {
5301
- // if (modelName === this.modelName) {
5302
- // model[prop] = data;
5303
- // this.model = Model.build({ [prop]: data }, modelName);
5304
- // } else {
5305
- // model[parent] = {
5306
- // ...model[parent],
5307
- // [prop]: data,
5308
- // };
5309
- // }
5310
- // }
5311
5314
  }
5312
5315
  // this._data = model;
5313
5316
  // this.changeDetectorRef.detectChanges();
@@ -5422,6 +5425,14 @@ class NgxModelPageDirective extends NgxPageDirective {
5422
5425
  if (!this.modelId)
5423
5426
  this.modelId = data[pk];
5424
5427
  const model = await this.transactionBegin(data, repository, operation);
5428
+ if (!model) {
5429
+ return {
5430
+ success: false,
5431
+ aborted: true,
5432
+ model: null,
5433
+ message: 'Operation aborted by before hook',
5434
+ };
5435
+ }
5425
5436
  switch (operation) {
5426
5437
  case OperationKeys.CREATE:
5427
5438
  result = await (!Array.isArray(model)
@@ -5463,7 +5474,7 @@ class NgxModelPageDirective extends NgxPageDirective {
5463
5474
  .error(`Error during ${this.operation} operation: ${error instanceof Error ? error.message : error}`);
5464
5475
  message = error instanceof Error ? error.message : error;
5465
5476
  }
5466
- return { ...event, success, message, model: result };
5477
+ return { ...event, success, message, model: result, aborted: false };
5467
5478
  }
5468
5479
  async batchOperation(context, redirect = false) {
5469
5480
  const { data, repository, pk } = context.context;
@@ -7742,8 +7753,8 @@ class NgxFormDirective extends NgxParentComponentDirective {
7742
7753
  event.preventDefault();
7743
7754
  event.stopImmediatePropagation();
7744
7755
  }
7745
- this.changeDetectorRef.detectChanges();
7746
7756
  const formGroup = this.formGroup;
7757
+ this.changeDetectorRef.detectChanges();
7747
7758
  const isValid = NgxFormService.validateFields(formGroup);
7748
7759
  if (!isValid) {
7749
7760
  NgxFormService.enableAllGroupControls(formGroup);
@@ -8267,7 +8278,7 @@ let CrudFormComponent = class CrudFormComponent extends NgxFormDirective {
8267
8278
  this.options = Object.assign({}, DefaultFormReactiveOptions, { buttons: { submit: { text: this.operation.toLowerCase() } } }, this.options || {});
8268
8279
  await super.initialize();
8269
8280
  if (!this.pk && this.modelName) {
8270
- const repo = getModelAndRepository$1(this.modelName);
8281
+ const repo = getModelAndRepository(this.modelName);
8271
8282
  if (repo) {
8272
8283
  this.pk = repo.pk;
8273
8284
  }
@@ -8942,8 +8953,9 @@ let FieldsetComponent = class FieldsetComponent extends NgxFormDirective {
8942
8953
  return false;
8943
8954
  }, obj);
8944
8955
  }
8945
- if (!Array.isArray(this._data))
8956
+ if (!Array.isArray(this._data)) {
8946
8957
  this._data = resolvePath(this._data, this.childOf);
8958
+ }
8947
8959
  if (this._data) {
8948
8960
  const data = this._data || [];
8949
8961
  if ([OperationKeys.READ, OperationKeys.DELETE].includes(this.operation)) {
@@ -8965,6 +8977,28 @@ let FieldsetComponent = class FieldsetComponent extends NgxFormDirective {
8965
8977
  ];
8966
8978
  }
8967
8979
  else {
8980
+ // if (Array.isArray(data)) {
8981
+ // this.value = [];
8982
+ // const value = data.map((v) => {
8983
+ // const formGroup = this.activeFormGroup as FormGroup;
8984
+ // if (data.length > (formGroup.parent as FormArray).length)
8985
+ // NgxFormService.addGroupToParent(formGroup.parent as FormArray);
8986
+ // if (!Object.keys(this.mapper).length) this.mapper = this.getMapper(v as KeyValue);
8987
+ // Object.entries(v).forEach(([key, value]) => {
8988
+ // if (key === this.pk)
8989
+ // formGroup.addControl(key, new FormControl({ value: value, disabled: false }));
8990
+ // const control = formGroup.get(key);
8991
+ // if (control instanceof FormControl) {
8992
+ // control.setValue(value);
8993
+ // control.updateValueAndValidity();
8994
+ // formGroup.updateValueAndValidity();
8995
+ // }
8996
+ // });
8997
+ // this.activeFormGroupIndex = (formGroup.parent as FormArray).length - 1;
8998
+ // });
8999
+ // this.setValue();
9000
+ // this.changeDetectorRef.detectChanges();
9001
+ // }
8968
9002
  this.getItems(data);
8969
9003
  }
8970
9004
  }
@@ -9150,10 +9184,10 @@ let FieldsetComponent = class FieldsetComponent extends NgxFormDirective {
9150
9184
  pk: this.pk,
9151
9185
  uid: value[this.pk],
9152
9186
  },
9153
- }, ActionRoles$1.delete, this.injector);
9187
+ }, ActionRoles.delete, this.injector);
9154
9188
  await modal.present();
9155
9189
  const { role } = await modal.onDidDismiss();
9156
- if (role === ActionRoles$1.confirm)
9190
+ if (role === ActionRoles.confirm)
9157
9191
  return this.handleRemoveItem(index, true, value);
9158
9192
  return;
9159
9193
  }
@@ -9249,10 +9283,10 @@ let FieldsetComponent = class FieldsetComponent extends NgxFormDirective {
9249
9283
  this.operation === OperationKeys.UPDATE &&
9250
9284
  value[this.pk] !== undefined) {
9251
9285
  this.listenEvent.emit({
9252
- name: ComponentEventNames$1.Submit,
9286
+ name: ComponentEventNames.Submit,
9253
9287
  role: operation,
9254
9288
  component: this.componentName,
9255
- handler: this.handlers[ComponentEventNames$1.Submit] || undefined,
9289
+ handler: this.handlers[ComponentEventNames.Submit] || undefined,
9256
9290
  data: value,
9257
9291
  context: {
9258
9292
  repository: this._repository,
@@ -9310,9 +9344,11 @@ let FieldsetComponent = class FieldsetComponent extends NgxFormDirective {
9310
9344
  */
9311
9345
  setValue() {
9312
9346
  const formGroup = this.formGroup;
9313
- const value = formGroup.controls.map(({ value }) => value).filter((v) => this.hasValue(v));
9314
- this.value = value;
9315
- this.getItems(value, this.items);
9347
+ if (formGroup?.length) {
9348
+ const value = formGroup.controls.map(({ value }) => value).filter((v) => this.hasValue(v));
9349
+ this.value = value;
9350
+ this.getItems(value, this.items);
9351
+ }
9316
9352
  this.updatingItem = undefined;
9317
9353
  }
9318
9354
  getItems(value, items = []) {