Browse Source

Merge branch 'dev' into Doc-Dynamic-Widget

pull/13269/head
malik masis 4 years ago
parent
commit
4d30566284
  1. 2
      framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/en.json
  2. 22
      npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts
  3. 14
      npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts
  4. 4
      npm/ng-packs/packages/theme-shared/src/lib/constants/validation.ts

2
framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/en.json

@ -24,6 +24,8 @@
"ThisFieldMustBeAStringOrArrayTypeWithAMinimumLengthOf{0}": "This field must be a string or array type with a minimum length of '{0}'.", "ThisFieldMustBeAStringOrArrayTypeWithAMinimumLengthOf{0}": "This field must be a string or array type with a minimum length of '{0}'.",
"ThisFieldIsNotAValidPhoneNumber.": "This field is not a valid phone number.", "ThisFieldIsNotAValidPhoneNumber.": "This field is not a valid phone number.",
"ThisFieldMustBeBetween{0}And{1}": "This field must be between {0} and {1}.", "ThisFieldMustBeBetween{0}And{1}": "This field must be between {0} and {1}.",
"ThisFieldMustBeGreaterThanOrEqual{0}":"This field must be greater than or equal to {0}.",
"ThisFieldMustBeLessOrEqual{0}":"This field must be less than or equal to {0}.",
"ThisFieldMustMatchTheRegularExpression{0}": "This field must match the regular expression '{0}'.", "ThisFieldMustMatchTheRegularExpression{0}": "This field must match the regular expression '{0}'.",
"ThisFieldIsRequired.": "This field is required.", "ThisFieldIsRequired.": "This field is required.",
"ThisFieldMustBeAStringWithAMaximumLengthOf{0}": "This field must be a string with a maximum length of {0}.", "ThisFieldMustBeAStringWithAMaximumLengthOf{0}": "This field must be a string with a maximum length of {0}.",

22
npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts

@ -1,4 +1,5 @@
import { import {
AfterViewInit,
ChangeDetectorRef, ChangeDetectorRef,
Directive, Directive,
Input, Input,
@ -8,20 +9,24 @@ import {
TemplateRef, TemplateRef,
ViewContainerRef, ViewContainerRef,
} from '@angular/core'; } from '@angular/core';
import { Subscription } from 'rxjs'; import { ReplaySubject, Subscription } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators'; import { distinctUntilChanged, take } from 'rxjs/operators';
import { PermissionService } from '../services/permission.service'; import { PermissionService } from '../services/permission.service';
@Directive({ @Directive({
selector: '[abpPermission]', selector: '[abpPermission]',
}) })
export class PermissionDirective implements OnDestroy, OnChanges { export class PermissionDirective implements OnDestroy, OnChanges, AfterViewInit {
@Input('abpPermission') condition: string | undefined; @Input('abpPermission') condition: string | undefined;
@Input('abpPermissionRunChangeDetection') runChangeDetection = true; @Input('abpPermissionRunChangeDetection') runChangeDetection = true;
subscription!: Subscription; subscription!: Subscription;
cdrSubject = new ReplaySubject();
rendered = false;
constructor( constructor(
@Optional() private templateRef: TemplateRef<any>, @Optional() private templateRef: TemplateRef<any>,
private vcRef: ViewContainerRef, private vcRef: ViewContainerRef,
@ -41,7 +46,11 @@ export class PermissionDirective implements OnDestroy, OnChanges {
this.vcRef.clear(); this.vcRef.clear();
if (isGranted) this.vcRef.createEmbeddedView(this.templateRef); if (isGranted) this.vcRef.createEmbeddedView(this.templateRef);
if (this.runChangeDetection) { if (this.runChangeDetection) {
this.cdRef.detectChanges(); if (!this.rendered) {
this.cdrSubject.next();
} else {
this.cdRef.detectChanges();
}
} else { } else {
this.cdRef.markForCheck(); this.cdRef.markForCheck();
} }
@ -55,4 +64,9 @@ export class PermissionDirective implements OnDestroy, OnChanges {
ngOnChanges() { ngOnChanges() {
this.check(); this.check();
} }
ngAfterViewInit() {
this.cdrSubject.pipe(take(1)).subscribe(() => this.cdRef.detectChanges());
this.rendered = true;
}
} }

14
npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts

@ -76,6 +76,20 @@ describe('PermissionDirective', () => {
expect(detectChanges).toHaveBeenCalled(); expect(detectChanges).toHaveBeenCalled();
}); });
it('should not call change detection before ngAfterViewInit', () => {
// hook before ngAfterViewInit
const detectChanges = jest.spyOn(cdr, 'detectChanges');
spectator.setHostInput({ condition: 'test' });
grantedPolicy$.next(true);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
directive.onInit = () => {
expect(detectChanges).not.toHaveBeenCalled();
};
expect(detectChanges).toHaveBeenCalled();
});
describe('#subscription', () => { describe('#subscription', () => {
it('should call the unsubscribe', () => { it('should call the unsubscribe', () => {
const spy = jest.fn(() => {}); const spy = jest.fn(() => {});

4
npm/ng-packs/packages/theme-shared/src/lib/constants/validation.ts

@ -2,10 +2,10 @@ export const DEFAULT_VALIDATION_BLUEPRINTS = {
creditCard: 'AbpValidation::ThisFieldIsNotAValidCreditCardNumber.', creditCard: 'AbpValidation::ThisFieldIsNotAValidCreditCardNumber.',
email: 'AbpValidation::ThisFieldIsNotAValidEmailAddress.', email: 'AbpValidation::ThisFieldIsNotAValidEmailAddress.',
invalid: 'AbpValidation::ThisFieldIsNotValid.', invalid: 'AbpValidation::ThisFieldIsNotValid.',
max: 'AbpValidation::ThisFieldMustBeBetween{0}And{1}[{{ min }},{{ max }}]', max: 'AbpValidation::ThisFieldMustBeLessOrEqual{0}[{{ max }}]',
maxlength: maxlength:
'AbpValidation::ThisFieldMustBeAStringOrArrayTypeWithAMaximumLengthOf{0}[{{ requiredLength }}]', 'AbpValidation::ThisFieldMustBeAStringOrArrayTypeWithAMaximumLengthOf{0}[{{ requiredLength }}]',
min: 'AbpValidation::ThisFieldMustBeBetween{0}And{1}[{{ min }},{{ max }}]', min: 'AbpValidation::ThisFieldMustBeGreaterThanOrEqual{0}[{{ min }}]',
minlength: minlength:
'AbpValidation::ThisFieldMustBeAStringOrArrayTypeWithAMinimumLengthOf{0}[{{ requiredLength }}]', 'AbpValidation::ThisFieldMustBeAStringOrArrayTypeWithAMinimumLengthOf{0}[{{ requiredLength }}]',
ngbDate: 'AbpValidation::ThisFieldIsNotValid.', ngbDate: 'AbpValidation::ThisFieldIsNotValid.',

Loading…
Cancel
Save