Browse Source

reformat the codes

pull/13700/head
Mahmut Gundogdu 4 years ago
parent
commit
d0ca09ed9f
  1. 22
      npm/ng-packs/packages/account/src/lib/guards/extensions.guard.ts
  2. 8
      npm/ng-packs/packages/core/src/lib/validators/username.validator.ts
  3. 74
      npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts
  4. 4
      npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form.component.ts
  5. 6
      npm/ng-packs/packages/theme-shared/extensions/src/lib/models/form-props.ts
  6. 4
      npm/ng-packs/packages/theme-shared/extensions/src/lib/models/props.ts
  7. 3
      npm/ng-packs/packages/theme-shared/extensions/src/lib/tokens/extensions.token.ts

22
npm/ng-packs/packages/account/src/lib/guards/extensions.guard.ts

@ -1,14 +1,18 @@
import {Injectable, Injector} from "@angular/core";
import {CanActivate} from "@angular/router";
import {Observable} from "rxjs";
import { Injectable, Injector } from '@angular/core';
import { CanActivate } from '@angular/router';
import { Observable } from 'rxjs';
import {
ExtensionsService,
getObjectExtensionEntitiesFromStore,
mapEntitiesToContributors, mergeWithDefaultProps
} from "@abp/ng.theme.shared/extensions";
import {ConfigStateService} from "@abp/ng.core";
import {tap, map, mapTo} from "rxjs/operators";
import {ACCOUNT_EDIT_FORM_PROP_CONTRIBUTORS, DEFAULT_ACCOUNT_FORM_PROPS} from '../tokens/extensions.token';
mapEntitiesToContributors,
mergeWithDefaultProps,
} from '@abp/ng.theme.shared/extensions';
import { ConfigStateService } from '@abp/ng.core';
import { tap, map, mapTo } from 'rxjs/operators';
import {
ACCOUNT_EDIT_FORM_PROP_CONTRIBUTORS,
DEFAULT_ACCOUNT_FORM_PROPS,
} from '../tokens/extensions.token';
import { AccountEditFormPropContributors } from '../models/config-options';
import { eAccountComponents } from '../enums/components';
@ -26,7 +30,7 @@ export class AccountExtensionsGuard implements CanActivate {
return getObjectExtensionEntitiesFromStore(configState, 'Identity').pipe(
map(entities => ({
[eAccountComponents.PersonalSettings]: entities.User,
})),
})),
mapEntitiesToContributors(configState, 'AbpIdentity'),
tap(objectExtensionContributors => {
mergeWithDefaultProps(

8
npm/ng-packs/packages/core/src/lib/validators/username.validator.ts

@ -1,9 +1,9 @@
import {AbstractControl, ValidatorFn} from '@angular/forms';
import { AbstractControl, ValidatorFn } from '@angular/forms';
import { isNullOrEmpty } from '../utils';
export interface UsernamePatternError {
usernamePattern: {
actualValue:string;
actualValue: string;
};
}
@ -14,11 +14,11 @@ export interface UsernameOptions {
const onlyLetterAndNumberRegex = /^[a-zA-Z0-9]+$/;
export function validateUsername(
{pattern}: UsernameOptions = {pattern: onlyLetterAndNumberRegex},
{ pattern }: UsernameOptions = { pattern: onlyLetterAndNumberRegex },
): ValidatorFn {
return (control: AbstractControl): UsernamePatternError | null => {
const isValid = isValidUserName(control.value, pattern);
return isValid ? null : {usernamePattern: {actualValue: control.value}};
return isValid ? null : { usernamePattern: { actualValue: control.value } };
};
}

74
npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts

@ -1,11 +1,12 @@
import {EXTENSIONS_FORM_PROP_DATA, EXTENSIONS_FORM_PROP} from './../../tokens/extensions.token';
import {ABP, AbpValidators, ConfigStateService, TrackByService} from '@abp/ng.core';
import { EXTENSIONS_FORM_PROP_DATA, EXTENSIONS_FORM_PROP } from './../../tokens/extensions.token';
import { ABP, AbpValidators, ConfigStateService, TrackByService } from '@abp/ng.core';
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef, Injector,
ElementRef,
Injector,
Input,
OnChanges,
Optional,
@ -20,17 +21,17 @@ import {
ValidatorFn,
Validators,
} from '@angular/forms';
import {NgbDateAdapter, NgbTimeAdapter} from '@ng-bootstrap/ng-bootstrap';
import {Observable, of} from 'rxjs';
import {debounceTime, distinctUntilChanged, switchMap} from 'rxjs/operators';
import {DateAdapter} from '../../adapters/date.adapter';
import {TimeAdapter} from '../../adapters/time.adapter';
import {EXTRA_PROPERTIES_KEY} from '../../constants/extra-properties';
import {ePropType} from '../../enums/props.enum';
import {FormProp} from '../../models/form-props';
import {PropData} from '../../models/props';
import {selfFactory} from '../../utils/factory.util';
import {addTypeaheadTextSuffix} from '../../utils/typeahead.util';
import { NgbDateAdapter, NgbTimeAdapter } from '@ng-bootstrap/ng-bootstrap';
import { Observable, of } from 'rxjs';
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
import { DateAdapter } from '../../adapters/date.adapter';
import { TimeAdapter } from '../../adapters/time.adapter';
import { EXTRA_PROPERTIES_KEY } from '../../constants/extra-properties';
import { ePropType } from '../../enums/props.enum';
import { FormProp } from '../../models/form-props';
import { PropData } from '../../models/props';
import { selfFactory } from '../../utils/factory.util';
import { addTypeaheadTextSuffix } from '../../utils/typeahead.util';
@Component({
selector: 'abp-extensible-form-prop',
@ -42,8 +43,8 @@ import {addTypeaheadTextSuffix} from '../../utils/typeahead.util';
useFactory: selfFactory,
deps: [[new Optional(), new SkipSelf(), ControlContainer]],
},
{provide: NgbDateAdapter, useClass: DateAdapter},
{provide: NgbTimeAdapter, useClass: TimeAdapter},
{ provide: NgbDateAdapter, useClass: DateAdapter },
{ provide: NgbTimeAdapter, useClass: TimeAdapter },
],
})
export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
@ -55,7 +56,7 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
@ViewChild('field') private fieldRef!: ElementRef<HTMLElement>;
public injectorForCustomComponent: Injector
public injectorForCustomComponent: Injector;
asterisk = '';
@ -72,13 +73,12 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
disabledFn = (data: PropData) => false;
get disabled() {
return this.disabledFn(this.data)
return this.disabledFn(this.data);
}
setTypeaheadValue(selectedOption: ABP.Option<string>) {
this.typeaheadModel = selectedOption || {key: null, value: null};
const {key, value} = this.typeaheadModel;
this.typeaheadModel = selectedOption || { key: null, value: null };
const { key, value } = this.typeaheadModel;
const [keyControl, valueControl] = this.getTypeaheadControls();
if (valueControl?.value && !value) valueControl.markAsDirty();
keyControl?.setValue(key);
@ -88,10 +88,10 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
search = (text$: Observable<string>) =>
text$
? text$.pipe(
debounceTime(300),
distinctUntilChanged(),
switchMap(text => this.prop.options(this.data, text)),
)
debounceTime(300),
distinctUntilChanged(),
switchMap(text => this.prop.options(this.data, text)),
)
: of([]);
typeaheadFormatter = (option: ABP.Option<any>) => option.key;
@ -112,13 +112,13 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
public readonly track: TrackByService,
protected configState: ConfigStateService,
groupDirective: FormGroupDirective,
private injector: Injector
private injector: Injector,
) {
this.form = groupDirective.form;
}
private getTypeaheadControls() {
const {name} = this.prop;
const { name } = this.prop;
const extraPropName = `${EXTRA_PROPERTIES_KEY}.${name}`;
const keyControl =
this.form.get(addTypeaheadTextSuffix(extraPropName)) ||
@ -139,7 +139,7 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
getComponent(prop: FormProp): string {
if (prop.template) {
return 'template'
return 'template';
}
switch (prop.type) {
case ePropType.Boolean:
@ -181,21 +181,21 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
}
}
ngOnChanges({prop, data}: SimpleChanges) {
ngOnChanges({ prop, data }: SimpleChanges) {
const currentProp = prop?.currentValue as FormProp;
const {options, readonly, disabled, validators, template} = currentProp || {};
const { options, readonly, disabled, validators, template } = currentProp || {};
if (template) {
this.injectorForCustomComponent = Injector.create({
providers: [
{
provide: EXTENSIONS_FORM_PROP,
useValue: currentProp
useValue: currentProp,
},
{
provide: EXTENSIONS_FORM_PROP_DATA,
useValue: (data?.currentValue as PropData)?.record
useValue: (data?.currentValue as PropData)?.record,
},
{provide: ControlContainer, useExisting: FormGroupDirective}
{ provide: ControlContainer, useExisting: FormGroupDirective },
],
parent: this.injector,
});
@ -214,10 +214,14 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
const [keyControl, valueControl] = this.getTypeaheadControls();
if (keyControl && valueControl)
this.typeaheadModel = {key: keyControl.value, value: valueControl.value};
this.typeaheadModel = { key: keyControl.value, value: valueControl.value };
}
}
function isRequired(validator: ValidatorFn) {
return validator === Validators.required || validator === AbpValidators.required || validator.name === 'required';
return (
validator === Validators.required ||
validator === AbpValidators.required ||
validator.name === 'required'
);
}

4
npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form.component.ts

@ -10,7 +10,7 @@ import {
SkipSelf,
ViewChildren,
} from '@angular/core';
import {ControlContainer, FormGroup, FormGroupDirective} from '@angular/forms';
import { ControlContainer, FormGroup } from '@angular/forms';
import { EXTRA_PROPERTIES_KEY } from '../../constants/extra-properties';
import { FormPropList } from '../../models/form-props';
import { ExtensionsService } from '../../services/extensions.service';
@ -62,5 +62,3 @@ export class ExtensibleFormComponent<R = any> {
@Inject(EXTENSIONS_IDENTIFIER) private identifier: string,
) {}
}

6
npm/ng-packs/packages/theme-shared/extensions/src/lib/models/form-props.ts

@ -38,8 +38,8 @@ export class FormProp<R = any> extends Prop<R> {
readonly defaultValue: boolean | number | string | Date;
readonly options: PropCallback<R, Observable<ABP.Option<any>[]>> | undefined;
readonly id: string | undefined;
readonly template? : Type<any>
readonly className?:string;
readonly template?: Type<any>;
readonly className?: string;
constructor(options: FormPropOptions<R>) {
super(
@ -50,7 +50,7 @@ export class FormProp<R = any> extends Prop<R> {
options.visible,
options.isExtra,
options.template,
options.className
options.className,
);
this.asyncValidators = options.asyncValidators || (_ => []);

4
npm/ng-packs/packages/theme-shared/extensions/src/lib/models/props.ts

@ -33,8 +33,8 @@ export abstract class Prop<R = any> {
public readonly permission: string,
public readonly visible: PropPredicate<R> = _ => true,
public readonly isExtra = false,
public readonly template? : Type<any>,
public readonly className?:string
public readonly template?: Type<any>,
public readonly className?: string,
) {
this.displayName = this.displayName || this.name;
}

3
npm/ng-packs/packages/theme-shared/extensions/src/lib/tokens/extensions.token.ts

@ -3,8 +3,7 @@ import { ActionCallback, ReadonlyActionData as ActionData } from '../models/acti
import { ExtensionsService } from '../services/extensions.service';
import { Observable } from 'rxjs';
import { ePropType } from '../enums/props.enum';
import {FormProp} from "../models/form-props";
import { PropData } from '../models/props';
import { FormProp } from '../models/form-props';
export const EXTENSIONS_IDENTIFIER = new InjectionToken<string>('EXTENSIONS_IDENTIFIER');
export type ActionKeys = Extract<'entityActions' | 'toolbarActions', keyof ExtensionsService>;

Loading…
Cancel
Save