Merge pull request #8485 from vvlladd28/improvement/decorators/coercion
Added decorators to coercion input component value
This commit is contained in:
commit
81b4459687
@ -93,6 +93,10 @@ import * as NospacePipe from '@shared/pipe/nospace.pipe';
|
||||
import * as SelectableColumnsPipe from '@shared/pipe/selectable-columns.pipe';
|
||||
import * as KeyboardShortcutPipe from '@shared/pipe/keyboard-shortcut.pipe';
|
||||
|
||||
import * as coercion from '@shared/decorators/coercion';
|
||||
import * as enumerable from '@shared/decorators/enumerable';
|
||||
import * as TbInject from '@shared/decorators/tb-inject';
|
||||
|
||||
import * as FooterComponent from '@shared/components/footer.component';
|
||||
import * as LogoComponent from '@shared/components/logo.component';
|
||||
import * as FooterFabButtonsComponent from '@shared/components/footer-fab-buttons.component';
|
||||
@ -384,6 +388,10 @@ class ModulesMap implements IModulesMap {
|
||||
'@shared/pipe/selectable-columns.pipe': SelectableColumnsPipe,
|
||||
'@shared/pipe/keyboard-shortcut.pipe': KeyboardShortcutPipe,
|
||||
|
||||
'@shared/decorators/coercion': coercion,
|
||||
'@shared/decorators/enumerable': enumerable,
|
||||
'@shared/decorators/tb-inject': TbInject,
|
||||
|
||||
'@shared/components/footer.component': FooterComponent,
|
||||
'@shared/components/logo.component': LogoComponent,
|
||||
'@shared/components/footer-fab-buttons.component': FooterFabButtonsComponent,
|
||||
|
||||
@ -30,7 +30,7 @@ import {
|
||||
} from '@angular/core';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { AlarmFilterConfig } from '@shared/models/query/query.models';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
||||
import { TemplatePortal } from '@angular/cdk/portal';
|
||||
import {
|
||||
|
||||
@ -30,7 +30,7 @@ import {
|
||||
ViewContainerRef
|
||||
} from '@angular/core';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
||||
import { TemplatePortal } from '@angular/cdk/portal';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
@ -37,7 +37,7 @@ import { MatStepper } from '@angular/material/stepper';
|
||||
import { MatButtonToggle, MatButtonToggleGroup } from '@angular/material/button-toggle';
|
||||
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
|
||||
import { MediaBreakpoints } from '@shared/models/constants';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
export interface ToggleHeaderOption {
|
||||
name: string;
|
||||
|
||||
@ -32,7 +32,7 @@ import { AppState } from '@app/core/core.state';
|
||||
import { Subject } from 'rxjs';
|
||||
import { NonConfirmedNotificationEscalation } from '@shared/models/notification.models';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-escalations-component',
|
||||
|
||||
@ -19,7 +19,7 @@ import { ClipboardService } from 'ngx-clipboard';
|
||||
import { TooltipPosition } from '@angular/material/tooltip';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ThemePalette } from '@angular/material/core';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-copy-button',
|
||||
|
||||
@ -39,7 +39,7 @@ import { EntityService } from '@core/http/entity.service';
|
||||
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
|
||||
import { Authority } from '@shared/models/authority.enum';
|
||||
import { isEqual } from '@core/utils';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-entity-autocomplete',
|
||||
|
||||
@ -27,7 +27,7 @@ import { MatAutocomplete } from '@angular/material/autocomplete';
|
||||
import { MatChipGrid } from '@angular/material/chips';
|
||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
import { SubscriptSizing } from '@angular/material/form-field';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
interface EntityTypeInfo {
|
||||
name: string;
|
||||
|
||||
@ -39,7 +39,7 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
import { SHARED_MODULE_TOKEN } from '@shared/components/tokens';
|
||||
import { deepClone, guid, isDefinedAndNotNull } from '@core/utils';
|
||||
import { Observable, of, ReplaySubject } from 'rxjs';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
let defaultMarkdownStyle;
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ import { alarmSeverityTranslations } from '@shared/models/alarm.models';
|
||||
import tinycolor from 'tinycolor2';
|
||||
import { StateObject } from '@core/api/widget-api.models';
|
||||
import { objToBase64URI } from '@core/utils';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-notification',
|
||||
|
||||
@ -40,7 +40,7 @@ import {
|
||||
} from '@home/pages/notification/template/template-notification-dialog.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-template-autocomplete',
|
||||
|
||||
@ -58,7 +58,7 @@ import {
|
||||
import { distinctUntilChanged, take, takeUntil } from 'rxjs/operators';
|
||||
import { isNotEmptyStr, onParentScrollOrWindowResize } from '@core/utils';
|
||||
import { animate, AnimationBuilder, AnimationMetadata, style } from '@angular/animations';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
export type TbPopoverTrigger = 'click' | 'focus' | 'hover' | null;
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida
|
||||
import { MatChipInputEvent } from '@angular/material/chips';
|
||||
import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes';
|
||||
import { FloatLabelType, MatFormFieldAppearance, SubscriptSizing } from '@angular/material/form-field';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-string-items-list',
|
||||
|
||||
@ -19,7 +19,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { TimeInterval, TimeService } from '@core/services/time.service';
|
||||
import { coerceNumberProperty } from '@angular/cdk/coercion';
|
||||
import { SubscriptSizing } from '@angular/material/form-field';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-timeinterval',
|
||||
|
||||
@ -53,7 +53,7 @@ import { deepClone, isDefinedAndNotNull } from '@core/utils';
|
||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
||||
import { ComponentPortal } from '@angular/cdk/portal';
|
||||
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
// @dynamic
|
||||
@Component({
|
||||
|
||||
108
ui-ngx/src/app/shared/decorators/coercion.ts
Normal file
108
ui-ngx/src/app/shared/decorators/coercion.ts
Normal file
@ -0,0 +1,108 @@
|
||||
///
|
||||
/// Copyright © 2016-2023 The Thingsboard Authors
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
|
||||
import {
|
||||
coerceArray as coerceArrayAngular,
|
||||
coerceBooleanProperty,
|
||||
coerceCssPixelValue as coerceCssPixelValueAngular,
|
||||
coerceNumberProperty,
|
||||
coerceStringArray as coerceStringArrayAngular
|
||||
} from '@angular/cdk/coercion';
|
||||
|
||||
export const coerceBoolean = () => (target: any, key: string): void => {
|
||||
const getter = function() {
|
||||
return this['__' + key];
|
||||
};
|
||||
|
||||
const setter = function(next: any) {
|
||||
this['__' + key] = coerceBooleanProperty(next);
|
||||
};
|
||||
|
||||
Object.defineProperty(target, key, {
|
||||
get: getter,
|
||||
set: setter,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const coerceNumber = () => (target: any, key: string): void => {
|
||||
const getter = function(): number {
|
||||
return this['__' + key];
|
||||
};
|
||||
|
||||
const setter = function(next: any) {
|
||||
this['__' + key] = coerceNumberProperty(next);
|
||||
};
|
||||
|
||||
Object.defineProperty(target, key, {
|
||||
get: getter,
|
||||
set: setter,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const coerceCssPixelValue = () => (target: any, key: string): void => {
|
||||
const getter = function(): string {
|
||||
return this['__' + key];
|
||||
};
|
||||
|
||||
const setter = function(next: any) {
|
||||
this['__' + key] = coerceCssPixelValueAngular(next);
|
||||
};
|
||||
|
||||
Object.defineProperty(target, key, {
|
||||
get: getter,
|
||||
set: setter,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const coerceArray = () => (target: any, key: string): void => {
|
||||
const getter = function(): any[] {
|
||||
return this['__' + key];
|
||||
};
|
||||
|
||||
const setter = function(next: any) {
|
||||
this['__' + key] = coerceArrayAngular(next);
|
||||
};
|
||||
|
||||
Object.defineProperty(target, key, {
|
||||
get: getter,
|
||||
set: setter,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const coerceStringArray = (separator?: string | RegExp) => (target: any, key: string): void => {
|
||||
const getter = function(): string[] {
|
||||
return this['__' + key];
|
||||
};
|
||||
|
||||
const setter = function(next: any) {
|
||||
this['__' + key] = coerceStringArrayAngular(next, separator);
|
||||
};
|
||||
|
||||
Object.defineProperty(target, key, {
|
||||
get: getter,
|
||||
set: setter,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
};
|
||||
@ -14,21 +14,6 @@
|
||||
/// limitations under the License.
|
||||
///
|
||||
|
||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
|
||||
export const coerceBoolean = () => (target: any, key: string): void => {
|
||||
const getter = function() {
|
||||
return this['__' + key];
|
||||
};
|
||||
|
||||
const setter = function(next: any) {
|
||||
this['__' + key] = coerceBooleanProperty(next);
|
||||
};
|
||||
|
||||
Object.defineProperty(target, key, {
|
||||
get: getter,
|
||||
set: setter,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
};
|
||||
export * from './coercion';
|
||||
export * from './enumerable';
|
||||
export * from './tb-inject';
|
||||
@ -15,6 +15,7 @@
|
||||
///
|
||||
|
||||
export * from './components/public-api';
|
||||
export * from './decorators/public-api';
|
||||
export * from './models/public-api';
|
||||
export * from './pipe/public-api';
|
||||
export * from './shared.module';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user