@trudb/tru-common-lib 0.0.336 → 0.0.339

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.
@@ -1475,7 +1475,7 @@ class TruDataContext {
1475
1475
  this.uiNotification = uiNotification;
1476
1476
  this._pendingDeleteEntities = [];
1477
1477
  this._pendingCascadeDeleteEntities = [];
1478
- this.entityManagerChangeDetection = new Observable((observer) => {
1478
+ this.validationChangeDetection = new Observable((observer) => {
1479
1479
  this.entityManager.validationErrorsChanged.subscribe(entities => {
1480
1480
  observer.next(entities);
1481
1481
  });
@@ -4913,45 +4913,63 @@ class TruBreezeValidator {
4913
4913
  this.viewContainerRef = viewContainerRef;
4914
4914
  this.componentFactoryResolver = componentFactoryResolver;
4915
4915
  this.configModel = {};
4916
+ this.dialogRef = null;
4916
4917
  this.subs = [];
4917
- this.valErrsChanged = (entityToValidate) => {
4918
- if (true) {
4919
- this.el.nativeElement.setCustomValidity('');
4920
- let previousErrEl = this.el.nativeElement.nextElementSibling;
4921
- let previousFlagEl = this.el.nativeElement.nextElementSibling?.nextElementSibling;
4922
- if (previousErrEl?.classList.contains('invalid'))
4923
- previousErrEl.remove();
4924
- if (previousFlagEl?.classList.contains('invalid-flag'))
4925
- previousFlagEl.remove();
4926
- let msgEl, flagEl;
4927
- this.el.nativeElement.classList.remove('override-disabled-invalid');
4928
- if (this.propertyPath?.includes('/')) {
4929
- let propertyNameParts = this.propertyPath.split('/');
4930
- let targetProperty;
4931
- propertyNameParts.forEach((name) => {
4932
- if (!targetProperty) {
4933
- let targetPropertyName = 'o' + name;
4934
- targetProperty = this.entity[targetPropertyName];
4935
- }
4936
- else {
4937
- let targetPropertyName = 'o' + name;
4938
- targetProperty = targetProperty[targetPropertyName];
4939
- }
4940
- });
4941
- if (targetProperty && targetProperty.Merge_Data) {
4942
- this.mergeData = JSON.parse(targetProperty.Merge_Data);
4918
+ this.getMergeData = () => {
4919
+ if (this.config.propertyPath?.includes('/')) {
4920
+ let propertyNameParts = this.config.propertyPath.split('/');
4921
+ propertyNameParts.pop();
4922
+ let targetProperty;
4923
+ propertyNameParts.forEach((name) => {
4924
+ if (!targetProperty) {
4925
+ let targetPropertyName = 'o' + name;
4926
+ targetProperty = this.entity[targetPropertyName];
4927
+ }
4928
+ else {
4929
+ let targetPropertyName = 'o' + name;
4930
+ targetProperty = targetProperty[targetPropertyName];
4943
4931
  }
4932
+ });
4933
+ if (targetProperty && targetProperty.Merge_Data) {
4934
+ return JSON.parse(targetProperty.Merge_Data);
4944
4935
  }
4945
- else {
4946
- this.mergeData = JSON.parse(this.entity.Merge_Data);
4936
+ }
4937
+ else {
4938
+ return JSON.parse(this.entity.Merge_Data);
4939
+ }
4940
+ };
4941
+ this.addValidation = (propertyValidations) => {
4942
+ const componentFactory = this.componentFactoryResolver.resolveComponentFactory(TruValidationDialog);
4943
+ const component = this.viewContainerRef.createComponent(componentFactory, 0, this.viewContainerRef.injector);
4944
+ this.dialogRef = component;
4945
+ };
4946
+ this.removeValidation = () => {
4947
+ if (this.dialogRef) {
4948
+ this.viewContainerRef.remove(this.viewContainerRef.indexOf(this.dialogRef.instance));
4949
+ this.dialogRef = null;
4950
+ }
4951
+ };
4952
+ this.valErrsChanged = (validationObject) => {
4953
+ let validationTableName = validationObject.entity.constructor.name;
4954
+ if (this.config.rootTable === validationTableName) {
4955
+ this.mergeData = this.getMergeData();
4956
+ let addedPropertyValdations = validationObject.added.filter((v) => {
4957
+ return v.propertyName === this.config.propertyName;
4958
+ });
4959
+ let removedPropertyValdations = validationObject.removed.filter((v) => {
4960
+ return v.propertyName === this.config.propertyName;
4961
+ });
4962
+ if (addedPropertyValdations.length) {
4963
+ this.addValidation(addedPropertyValdations);
4964
+ }
4965
+ else if (!addedPropertyValdations.length && removedPropertyValdations.length) {
4966
+ this.removeValidation();
4947
4967
  }
4948
- const componentFactory = this.componentFactoryResolver.resolveComponentFactory(TruValidationDialog);
4949
- const containerRef = this.viewContainerRef.createComponent(componentFactory, 0, this.viewContainerRef.injector);
4950
4968
  }
4951
4969
  };
4952
4970
  }
4953
4971
  ngOnInit() {
4954
- this.subs.push(this.dataContext.entityManagerChangeDetection.subscribe(entities => {
4972
+ this.subs.push(this.dataContext.validationChangeDetection.subscribe(entities => {
4955
4973
  console.log(entities);
4956
4974
  this.valErrsChanged(entities);
4957
4975
  }));
@@ -4961,7 +4979,7 @@ class TruBreezeValidator {
4961
4979
  }
4962
4980
  }
4963
4981
  TruBreezeValidator.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruBreezeValidator, deps: [{ token: i0.ElementRef }, { token: TruDataContext }, { token: i0.ViewContainerRef }, { token: i0.ComponentFactoryResolver }], target: i0.ɵɵFactoryTarget.Directive });
4964
- TruBreezeValidator.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.1", type: TruBreezeValidator, selector: "[truBreezeValidator]", inputs: { entity: ["truBreezeValidator", "entity"], propertyPath: "propertyPath" }, ngImport: i0 });
4982
+ TruBreezeValidator.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.1", type: TruBreezeValidator, selector: "[truBreezeValidator]", inputs: { entity: ["truBreezeValidator", "entity"], config: "config" }, ngImport: i0 });
4965
4983
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruBreezeValidator, decorators: [{
4966
4984
  type: Directive,
4967
4985
  args: [{
@@ -4970,7 +4988,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
4970
4988
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: TruDataContext }, { type: i0.ViewContainerRef }, { type: i0.ComponentFactoryResolver }]; }, propDecorators: { entity: [{
4971
4989
  type: Input,
4972
4990
  args: ['truBreezeValidator']
4973
- }], propertyPath: [{
4991
+ }], config: [{
4974
4992
  type: Input
4975
4993
  }] } });
4976
4994