Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: safeNullpipe support for global configuration #316

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions devui/common/safe-null.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Pipe, PipeTransform, inject } from '@angular/core';
import { DevConfigService, WithConfig } from 'ng-devui/utils';

@Pipe({
name: 'dSafeNullPipe',
})
})
export class SafeNullPipe implements PipeTransform {
transform(value: unknown, replace = '--'): unknown {
@WithConfig() private placeholder = '--';
EnochGao marked this conversation as resolved.
Show resolved Hide resolved
private devConfigService: DevConfigService = inject(DevConfigService);

transform(value: unknown, placeholder = this.placeholder): unknown {
if (typeof value === 'undefined' || value === null || value === '') {
return replace;
return placeholder;
}
return value;
}
Expand Down
3 changes: 2 additions & 1 deletion devui/utils/globalConfig/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isDefined = function (value?: any): boolean {
};
@Injectable({
providedIn: 'root',
})
})
export class DevConfigService {
private configUpdated$ = new Subject<keyof DevUIGlobalConfig>();
private config: DevUIGlobalConfig;
Expand Down Expand Up @@ -61,6 +61,7 @@ export function WithConfig<T>(propertyKey?: T | string) {
let name = this.constructor.name;
name = name.replace('Directive', '');
name = name.replace('Component', '');
name = name.replace('Pipe', '');
name = name.toLowerCase();

const componentConfig = this.devConfigService.config[name] || {};
Expand Down
2 changes: 2 additions & 0 deletions devui/utils/globalConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type TagsinputConfig = IGlobalConfig;
export type TimepickerConfig = IGlobalConfig;
export type CheckboxConfig = IGlobalConfig;
export type TypographyConfig = IGlobalConfig;
export type SafeNullConfig = { placeholder: string };
export interface DevUIGlobalConfig {
tooltip?: TooltipConfig;
dropdown?: DropdownConfig;
Expand All @@ -53,6 +54,7 @@ export interface DevUIGlobalConfig {
checkboxgroup?: CheckboxConfig;
panel?: PanelConfig;
typography?: TypographyConfig;
safenull?: SafeNullConfig;
global?: GlobalConfig;
}

Expand Down
2 changes: 1 addition & 1 deletion src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@
},
"dSafeNullPipe": {
"title": "SafeNullPipe",
"description": "When the data is '', null, undefined can be specified any character placeholder display, the default is: '--'"
"description": "When the data is '', null, undefined can be specified any character placeholder display,support for global configuration the default is: '--'"
}
},
"browserDemo": {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@
},
"dSafeNullPipe": {
"title": "空值占位管道",
"description": "当数据为 ''、null、undefined时可指定任意字符进行占位展示,默认为:'--'"
"description": "当数据为 ''、null、undefined时可指定任意字符进行占位展示,支持全局配置,默认为:'--'"
}
},
"browserDemo": {
Expand Down