Convert boolean values to 'Yes' or 'No' or any other value.
Signed-off-by: Volker Theile <vtheile@suse.com>
<tr>
<td i18n
class="bold col-sm-1">Can be updated at runtime (editable)</td>
- <td class="col-sm-3">{{ selectedItem.can_update_at_runtime }}</td>
+ <td class="col-sm-3">{{ selectedItem.can_update_at_runtime | booleanText }}</td>
</tr>
<tr>
<td i18n
import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
import { DataTableModule } from '../../../../shared/datatable/datatable.module';
+import { SharedModule } from '../../../../shared/shared.module';
import { ConfigurationDetailsComponent } from './configuration-details.component';
describe('ConfigurationDetailsComponent', () => {
configureTestBed({
declarations: [ConfigurationDetailsComponent],
- imports: [DataTableModule, TabsModule.forRoot()],
+ imports: [DataTableModule, SharedModule, TabsModule.forRoot()],
providers: [i18nProviders]
});
<tr>
<td i18n
class="bold col-sm-1">Enabled</td>
- <td class="col-sm-3">{{ bucket.bucket_quota.enabled ? "Yes" : "No" }}</td>
+ <td class="col-sm-3">{{ bucket.bucket_quota.enabled | booleanText }}</td>
</tr>
<tr>
<td i18n
import { TabsModule } from 'ngx-bootstrap/tabs';
-import { configureTestBed } from '../../../../testing/unit-test-helper';
+import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { SharedModule } from '../../../shared/shared.module';
import { RgwBucketDetailsComponent } from './rgw-bucket-details.component';
configureTestBed({
declarations: [RgwBucketDetailsComponent],
- imports: [SharedModule, TabsModule.forRoot()]
+ imports: [SharedModule, TabsModule.forRoot()],
+ providers: [i18nProviders]
});
beforeEach(() => {
<tr>
<td i18n
class="bold col-sm-1">Suspended</td>
- <td class="col-sm-3">{{ user.suspended ? "Yes" : "No" }}</td>
+ <td class="col-sm-3">{{ user.suspended | booleanText }}</td>
</tr>
<tr>
<td i18n
<tr>
<td i18n
class="bold col-sm-1">Enabled</td>
- <td class="col-sm-3">{{ user.user_quota.enabled ? "Yes" : "No" }}</td>
+ <td class="col-sm-3">{{ user.user_quota.enabled | booleanText }}</td>
</tr>
<tr>
<td i18n
<tr>
<td i18n
class="bold col-sm-1">Enabled</td>
- <td class="col-sm-3">{{ user.bucket_quota.enabled ? "Yes" : "No" }}</td>
+ <td class="col-sm-3">{{ user.bucket_quota.enabled | booleanText }}</td>
</tr>
<tr>
<td i18n
--- /dev/null
+import { TestBed } from '@angular/core/testing';
+import { configureTestBed, i18nProviders } from '../../../testing/unit-test-helper';
+
+import { I18n } from '@ngx-translate/i18n-polyfill';
+
+import { BooleanTextPipe } from './boolean-text.pipe';
+
+describe('BooleanTextPipe', () => {
+ 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');
+ });
+});
--- /dev/null
+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;
+ }
+}
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';
@NgModule({
imports: [CommonModule],
declarations: [
+ BooleanTextPipe,
DimlessBinaryPipe,
DimlessBinaryPerSecondPipe,
HealthColorPipe,
UpperFirstPipe
],
exports: [
+ BooleanTextPipe,
DimlessBinaryPipe,
DimlessBinaryPerSecondPipe,
HealthColorPipe,
UpperFirstPipe
],
providers: [
+ BooleanTextPipe,
DatePipe,
CephShortVersionPipe,
CephReleaseNamePipe,
<context context-type="linenumber">1</context>
</context-group>
</trans-unit>
+ <trans-unit id="4f20f2d5a6882190892e58b85f6ccbedfa737952" datatype="html">
+ <source>Yes</source>
+ <context-group purpose="location">
+ <context context-type="sourcefile">src/app/shared/pipes/boolean-text.pipe.ts</context>
+ <context context-type="linenumber">1</context>
+ </context-group>
+ </trans-unit>
+ <trans-unit id="3d3ae7deebc5949b0c1c78b9847886a94321d9fd" datatype="html">
+ <source>No</source>
+ <context-group purpose="location">
+ <context context-type="sourcefile">src/app/shared/pipes/boolean-text.pipe.ts</context>
+ <context context-type="linenumber">1</context>
+ </context-group>
+ </trans-unit>
<trans-unit id="8fd98fb2a0f24ba72cde0787dd3f02cfc17de469" datatype="html">
<source>Quality of Service</source>
<context-group purpose="location">