From: Volker Theile Date: Fri, 1 Mar 2019 09:27:13 +0000 (+0100) Subject: mgr/dashboard: Introduce pipe to convert bool to text X-Git-Tag: v14.1.1~89^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F26507%2Fhead;p=ceph.git mgr/dashboard: Introduce pipe to convert bool to text Convert boolean values to 'Yes' or 'No' or any other value. Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html index b8d6037ca000..b5776a7e067b 100755 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html @@ -85,7 +85,7 @@ Can be updated at runtime (editable) - {{ selectedItem.can_update_at_runtime }} + {{ selectedItem.can_update_at_runtime | booleanText }} { @@ -12,7 +13,7 @@ describe('ConfigurationDetailsComponent', () => { configureTestBed({ declarations: [ConfigurationDetailsComponent], - imports: [DataTableModule, TabsModule.forRoot()], + imports: [DataTableModule, SharedModule, TabsModule.forRoot()], providers: [i18nProviders] }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html index 3ccb9cb684f0..f1ef63cb2af9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html @@ -69,7 +69,7 @@ Enabled - {{ bucket.bucket_quota.enabled ? "Yes" : "No" }} + {{ bucket.bucket_quota.enabled | booleanText }} { configureTestBed({ declarations: [RgwBucketDetailsComponent], - imports: [SharedModule, TabsModule.forRoot()] + imports: [SharedModule, TabsModule.forRoot()], + providers: [i18nProviders] }); beforeEach(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.html index 0e23d16b44e5..4a90eb45a258 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.html @@ -22,7 +22,7 @@ Suspended - {{ user.suspended ? "Yes" : "No" }} + {{ user.suspended | booleanText }} Enabled - {{ user.user_quota.enabled ? "Yes" : "No" }} + {{ user.user_quota.enabled | booleanText }} Enabled - {{ user.bucket_quota.enabled ? "Yes" : "No" }} + {{ user.bucket_quota.enabled | booleanText }} { + let pipe: BooleanTextPipe; + + configureTestBed({ + providers: [i18nProviders] + }); + + beforeEach(() => { + const i18n = TestBed.get(I18n); + pipe = new BooleanTextPipe(i18n); + }); + + it('create an instance', () => { + expect(pipe).toBeTruthy(); + }); + + it('transforms true', () => { + expect(pipe.transform(true)).toEqual('Yes'); + }); + + it('transforms true, alternative text', () => { + expect(pipe.transform(true, 'foo')).toEqual('foo'); + }); + + it('transforms 1', () => { + expect(pipe.transform(1)).toEqual('Yes'); + }); + + it('transforms false', () => { + expect(pipe.transform(false)).toEqual('No'); + }); + + it('transforms false, alternative text', () => { + expect(pipe.transform(false, 'foo', 'bar')).toEqual('bar'); + }); + + it('transforms 0', () => { + expect(pipe.transform(0)).toEqual('No'); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/boolean-text.pipe.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/boolean-text.pipe.ts new file mode 100644 index 000000000000..dba4e8bc0102 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/boolean-text.pipe.ts @@ -0,0 +1,18 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +import { I18n } from '@ngx-translate/i18n-polyfill'; + +@Pipe({ + name: 'booleanText' +}) +export class BooleanTextPipe implements PipeTransform { + constructor(private i18n: I18n) {} + + transform( + value: any, + truthyText: string = this.i18n('Yes'), + falsyText: string = this.i18n('No') + ): string { + return Boolean(value) ? truthyText : falsyText; + } +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/pipes.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/pipes.module.ts index 0e53746f9d6b..85db7a7c96f5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/pipes.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/pipes.module.ts @@ -1,6 +1,7 @@ import { CommonModule, DatePipe } from '@angular/common'; import { NgModule } from '@angular/core'; +import { BooleanTextPipe } from './boolean-text.pipe'; import { CdDatePipe } from './cd-date.pipe'; import { CephReleaseNamePipe } from './ceph-release-name.pipe'; import { CephShortVersionPipe } from './ceph-short-version.pipe'; @@ -23,6 +24,7 @@ import { UpperFirstPipe } from './upper-first.pipe'; @NgModule({ imports: [CommonModule], declarations: [ + BooleanTextPipe, DimlessBinaryPipe, DimlessBinaryPerSecondPipe, HealthColorPipe, @@ -43,6 +45,7 @@ import { UpperFirstPipe } from './upper-first.pipe'; UpperFirstPipe ], exports: [ + BooleanTextPipe, DimlessBinaryPipe, DimlessBinaryPerSecondPipe, HealthColorPipe, @@ -63,6 +66,7 @@ import { UpperFirstPipe } from './upper-first.pipe'; UpperFirstPipe ], providers: [ + BooleanTextPipe, DatePipe, CephShortVersionPipe, CephReleaseNamePipe, diff --git a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf index f8f072ddaf43..8b88098120fd 100644 --- a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf +++ b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf @@ -6228,6 +6228,20 @@ 1 + + Yes + + src/app/shared/pipes/boolean-text.pipe.ts + 1 + + + + No + + src/app/shared/pipes/boolean-text.pipe.ts + 1 + + Quality of Service